time: Migrate to GSettings
This commit is contained in:
parent
0a745cb559
commit
f2b686d6f6
|
@ -27,10 +27,17 @@ plugin_in_files = time.pluma-plugin.desktop.in
|
||||||
|
|
||||||
plugin_DATA = $(plugin_in_files:.pluma-plugin.desktop.in=.pluma-plugin)
|
plugin_DATA = $(plugin_in_files:.pluma-plugin.desktop.in=.pluma-plugin)
|
||||||
|
|
||||||
EXTRA_DIST = $(ui_DATA) $(plugin_in_files)
|
@INTLTOOL_XML_NOMERGE_RULE@
|
||||||
|
gsettings_SCHEMAS = org.mate.pluma.plugins.time.gschema.xml
|
||||||
|
@GSETTINGS_RULES@
|
||||||
|
|
||||||
CLEANFILES = $(plugin_DATA)
|
%.gschema.xml.in: %.gschema.xml.in.in Makefile
|
||||||
DISTCLEANFILES = $(plugin_DATA)
|
$(AM_V_GEN) $(SED) -e 's^\@GETTEXT_PACKAGE\@^$(GETTEXT_PACKAGE)^g' < $< > $@
|
||||||
|
|
||||||
|
EXTRA_DIST = $(ui_DATA) $(plugin_in_files) $(gsettings_SCHEMAS_in_in)
|
||||||
|
|
||||||
|
CLEANFILES = $(plugin_DATA) $(gsettings_SCHEMAS_in) $(gsettings_SCHEMASn)
|
||||||
|
DISTCLEANFILES = $(plugin_DATA) $(gsettings_SCHEMAS_in) $(gsettings_SCHEMAS)
|
||||||
|
|
||||||
|
|
||||||
-include $(top_srcdir)/git.mk
|
-include $(top_srcdir)/git.mk
|
||||||
|
|
|
@ -0,0 +1,23 @@
|
||||||
|
<?xml version="1.0"?>
|
||||||
|
<schemalist gettext-domain="@GETTEXT_PACKAGE@">
|
||||||
|
<enum id="org.mate.pluma.plugins.time.PromptType">
|
||||||
|
<value nick="prompt-selected-format" value="0"/>
|
||||||
|
<value nick="prompt-custom-format" value="1"/>
|
||||||
|
<value nick="use-selected-format" value="2"/>
|
||||||
|
<value nick="use-custom-format" value="3"/>
|
||||||
|
</enum>
|
||||||
|
<schema id="org.mate.pluma.plugins.time" path="/org/mate/pluma/plugins/time/">
|
||||||
|
<key name="prompt-type" enum="org.mate.pluma.plugins.time.PromptType">
|
||||||
|
<default>'prompt-selected-format'</default>
|
||||||
|
<_summary>Prompt type</_summary>
|
||||||
|
</key>
|
||||||
|
<key name="selected-format" type="s">
|
||||||
|
<default>'%c'</default>
|
||||||
|
<_summary>Selected format</_summary>
|
||||||
|
</key>
|
||||||
|
<key name="custom-format" type="s">
|
||||||
|
<default>'%d/%m/%Y %H:%M:%S'</default>
|
||||||
|
<_summary>Custom format</_summary>
|
||||||
|
</key>
|
||||||
|
</schema>
|
||||||
|
</schemalist>
|
|
@ -33,14 +33,13 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
|
||||||
#include <mateconf/mateconf-client.h>
|
|
||||||
|
|
||||||
#include "pluma-time-plugin.h"
|
#include "pluma-time-plugin.h"
|
||||||
#include <pluma/pluma-help.h>
|
#include <pluma/pluma-help.h>
|
||||||
|
|
||||||
#include <glib/gi18n-lib.h>
|
#include <glib/gi18n-lib.h>
|
||||||
#include <glib.h>
|
#include <glib.h>
|
||||||
#include <gmodule.h>
|
#include <gmodule.h>
|
||||||
|
#include <gio/gio.h>
|
||||||
|
|
||||||
#include <pluma/pluma-debug.h>
|
#include <pluma/pluma-debug.h>
|
||||||
#include <pluma/pluma-utils.h>
|
#include <pluma/pluma-utils.h>
|
||||||
|
@ -52,11 +51,11 @@
|
||||||
#define WINDOW_DATA_KEY "PlumaTimePluginWindowData"
|
#define WINDOW_DATA_KEY "PlumaTimePluginWindowData"
|
||||||
#define MENU_PATH "/MenuBar/EditMenu/EditOps_4"
|
#define MENU_PATH "/MenuBar/EditMenu/EditOps_4"
|
||||||
|
|
||||||
/* mateconf keys */
|
/* GSettings keys */
|
||||||
#define TIME_BASE_KEY "/apps/pluma/plugins/time"
|
#define TIME_SCHEMA "org.mate.pluma.plugins.time"
|
||||||
#define PROMPT_TYPE_KEY TIME_BASE_KEY "/prompt_type"
|
#define PROMPT_TYPE_KEY "prompt-type"
|
||||||
#define SELECTED_FORMAT_KEY TIME_BASE_KEY "/selected_format"
|
#define SELECTED_FORMAT_KEY "selected-format"
|
||||||
#define CUSTOM_FORMAT_KEY TIME_BASE_KEY "/custom_format"
|
#define CUSTOM_FORMAT_KEY "custom-format"
|
||||||
|
|
||||||
#define DEFAULT_CUSTOM_FORMAT "%d/%m/%Y %H:%M:%S"
|
#define DEFAULT_CUSTOM_FORMAT "%d/%m/%Y %H:%M:%S"
|
||||||
|
|
||||||
|
@ -155,7 +154,7 @@ typedef enum
|
||||||
|
|
||||||
struct _PlumaTimePluginPrivate
|
struct _PlumaTimePluginPrivate
|
||||||
{
|
{
|
||||||
MateConfClient *mateconf_client;
|
GSettings *settings;
|
||||||
};
|
};
|
||||||
|
|
||||||
PLUMA_PLUGIN_REGISTER_TYPE(PlumaTimePlugin, pluma_time_plugin)
|
PLUMA_PLUGIN_REGISTER_TYPE(PlumaTimePlugin, pluma_time_plugin)
|
||||||
|
@ -193,12 +192,7 @@ pluma_time_plugin_init (PlumaTimePlugin *plugin)
|
||||||
|
|
||||||
plugin->priv = PLUMA_TIME_PLUGIN_GET_PRIVATE (plugin);
|
plugin->priv = PLUMA_TIME_PLUGIN_GET_PRIVATE (plugin);
|
||||||
|
|
||||||
plugin->priv->mateconf_client = mateconf_client_get_default ();
|
plugin->priv->settings = g_settings_new (TIME_SCHEMA);
|
||||||
|
|
||||||
mateconf_client_add_dir (plugin->priv->mateconf_client,
|
|
||||||
TIME_BASE_KEY,
|
|
||||||
MATECONF_CLIENT_PRELOAD_ONELEVEL,
|
|
||||||
NULL);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -208,9 +202,7 @@ pluma_time_plugin_finalize (GObject *object)
|
||||||
|
|
||||||
pluma_debug_message (DEBUG_PLUGINS, "PlumaTimePlugin finalizing");
|
pluma_debug_message (DEBUG_PLUGINS, "PlumaTimePlugin finalizing");
|
||||||
|
|
||||||
mateconf_client_suggest_sync (plugin->priv->mateconf_client, NULL);
|
g_object_unref (G_OBJECT (plugin->priv->settings));
|
||||||
|
|
||||||
g_object_unref (G_OBJECT (plugin->priv->mateconf_client));
|
|
||||||
|
|
||||||
G_OBJECT_CLASS (pluma_time_plugin_parent_class)->finalize (object);
|
G_OBJECT_CLASS (pluma_time_plugin_parent_class)->finalize (object);
|
||||||
}
|
}
|
||||||
|
@ -329,62 +321,27 @@ impl_update_ui (PlumaPlugin *plugin,
|
||||||
static PlumaTimePluginPromptType
|
static PlumaTimePluginPromptType
|
||||||
get_prompt_type (PlumaTimePlugin *plugin)
|
get_prompt_type (PlumaTimePlugin *plugin)
|
||||||
{
|
{
|
||||||
gchar *prompt_type;
|
PlumaTimePluginPromptType prompt_type;
|
||||||
PlumaTimePluginPromptType res;
|
|
||||||
|
|
||||||
prompt_type = mateconf_client_get_string (plugin->priv->mateconf_client,
|
prompt_type = g_settings_get_enum (plugin->priv->settings,
|
||||||
PROMPT_TYPE_KEY,
|
PROMPT_TYPE_KEY);
|
||||||
NULL);
|
|
||||||
|
|
||||||
if (prompt_type == NULL)
|
return prompt_type;
|
||||||
return PROMPT_SELECTED_FORMAT;
|
|
||||||
|
|
||||||
if (strcmp (prompt_type, "USE_SELECTED_FORMAT") == 0)
|
|
||||||
res = USE_SELECTED_FORMAT;
|
|
||||||
else if (strcmp (prompt_type, "USE_CUSTOM_FORMAT") == 0)
|
|
||||||
res = USE_CUSTOM_FORMAT;
|
|
||||||
else if (strcmp (prompt_type, "PROMPT_CUSTOM_FORMAT") == 0)
|
|
||||||
res = PROMPT_CUSTOM_FORMAT;
|
|
||||||
else
|
|
||||||
res = PROMPT_SELECTED_FORMAT;
|
|
||||||
|
|
||||||
g_free (prompt_type);
|
|
||||||
|
|
||||||
return res;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
set_prompt_type (PlumaTimePlugin *plugin,
|
set_prompt_type (PlumaTimePlugin *plugin,
|
||||||
PlumaTimePluginPromptType prompt_type)
|
PlumaTimePluginPromptType prompt_type)
|
||||||
{
|
{
|
||||||
const gchar * str;
|
if (!g_settings_is_writable (plugin->priv->settings,
|
||||||
|
PROMPT_TYPE_KEY))
|
||||||
if (!mateconf_client_key_is_writable (plugin->priv->mateconf_client,
|
|
||||||
PROMPT_TYPE_KEY,
|
|
||||||
NULL))
|
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (prompt_type)
|
g_settings_set_enum (plugin->priv->settings,
|
||||||
{
|
|
||||||
case USE_SELECTED_FORMAT:
|
|
||||||
str = "USE_SELECTED_FORMAT";
|
|
||||||
break;
|
|
||||||
case USE_CUSTOM_FORMAT:
|
|
||||||
str = "USE_CUSTOM_FORMAT";
|
|
||||||
break;
|
|
||||||
case PROMPT_CUSTOM_FORMAT:
|
|
||||||
str = "PROMPT_CUSTOM_FORMAT";
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
str = "PROMPT_SELECTED_FORMAT";
|
|
||||||
}
|
|
||||||
|
|
||||||
mateconf_client_set_string (plugin->priv->mateconf_client,
|
|
||||||
PROMPT_TYPE_KEY,
|
PROMPT_TYPE_KEY,
|
||||||
str,
|
prompt_type);
|
||||||
NULL);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* The selected format in the list */
|
/* The selected format in the list */
|
||||||
|
@ -393,9 +350,8 @@ get_selected_format (PlumaTimePlugin *plugin)
|
||||||
{
|
{
|
||||||
gchar *sel_format;
|
gchar *sel_format;
|
||||||
|
|
||||||
sel_format = mateconf_client_get_string (plugin->priv->mateconf_client,
|
sel_format = g_settings_get_string (plugin->priv->settings,
|
||||||
SELECTED_FORMAT_KEY,
|
SELECTED_FORMAT_KEY);
|
||||||
NULL);
|
|
||||||
|
|
||||||
return sel_format ? sel_format : g_strdup (formats [0]);
|
return sel_format ? sel_format : g_strdup (formats [0]);
|
||||||
}
|
}
|
||||||
|
@ -406,17 +362,15 @@ set_selected_format (PlumaTimePlugin *plugin,
|
||||||
{
|
{
|
||||||
g_return_if_fail (format != NULL);
|
g_return_if_fail (format != NULL);
|
||||||
|
|
||||||
if (!mateconf_client_key_is_writable (plugin->priv->mateconf_client,
|
if (!g_settings_is_writable (plugin->priv->settings,
|
||||||
SELECTED_FORMAT_KEY,
|
SELECTED_FORMAT_KEY))
|
||||||
NULL))
|
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
mateconf_client_set_string (plugin->priv->mateconf_client,
|
g_settings_set_string (plugin->priv->settings,
|
||||||
SELECTED_FORMAT_KEY,
|
SELECTED_FORMAT_KEY,
|
||||||
format,
|
format);
|
||||||
NULL);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* the custom format in the entry */
|
/* the custom format in the entry */
|
||||||
|
@ -425,9 +379,8 @@ get_custom_format (PlumaTimePlugin *plugin)
|
||||||
{
|
{
|
||||||
gchar *format;
|
gchar *format;
|
||||||
|
|
||||||
format = mateconf_client_get_string (plugin->priv->mateconf_client,
|
format = g_settings_get_string (plugin->priv->settings,
|
||||||
CUSTOM_FORMAT_KEY,
|
CUSTOM_FORMAT_KEY);
|
||||||
NULL);
|
|
||||||
|
|
||||||
return format ? format : g_strdup (DEFAULT_CUSTOM_FORMAT);
|
return format ? format : g_strdup (DEFAULT_CUSTOM_FORMAT);
|
||||||
}
|
}
|
||||||
|
@ -438,15 +391,13 @@ set_custom_format (PlumaTimePlugin *plugin,
|
||||||
{
|
{
|
||||||
g_return_if_fail (format != NULL);
|
g_return_if_fail (format != NULL);
|
||||||
|
|
||||||
if (!mateconf_client_key_is_writable (plugin->priv->mateconf_client,
|
if (!g_settings_is_writable (plugin->priv->settings,
|
||||||
CUSTOM_FORMAT_KEY,
|
CUSTOM_FORMAT_KEY))
|
||||||
NULL))
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
mateconf_client_set_string (plugin->priv->mateconf_client,
|
g_settings_set_string (plugin->priv->settings,
|
||||||
CUSTOM_FORMAT_KEY,
|
CUSTOM_FORMAT_KEY,
|
||||||
format,
|
format);
|
||||||
NULL);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static gchar *
|
static gchar *
|
||||||
|
|
Loading…
Reference in New Issue