[gedit] Port time plugin to gsettings



commit e7fde455f6415b0fc1dcdf7ae2dbb4070694cf62
Author: Ignacio Casal Quinteiro <icq gnome org>
Date:   Sat May 8 11:58:16 2010 +0200

    Port time plugin to gsettings

 plugins/time/Makefile.am                     |   10 +++
 plugins/time/gedit-time-plugin.c             |  108 ++++++++++---------------
 plugins/time/org.gnome.gedit.time.gschema.in |    6 ++
 3 files changed, 59 insertions(+), 65 deletions(-)
---
diff --git a/plugins/time/Makefile.am b/plugins/time/Makefile.am
index c532f7d..f935a66 100644
--- a/plugins/time/Makefile.am
+++ b/plugins/time/Makefile.am
@@ -16,6 +16,11 @@ libtime_la_SOURCES = \
 libtime_la_LDFLAGS = $(PLUGIN_LIBTOOL_FLAGS)
 libtime_la_LIBADD  = $(GEDIT_LIBS)
 
+gsettingsschema_in_files = org.gnome.gedit.time.gschema.in
+gsettingsschema_DATA = $(gsettingsschema_in_files:.gschema.in=.gschema.xml)
+org.gnome.gedit.time.gschema.xml: org.gnome.gedit.time.gschema.in
+	gsettings-schema-convert -f $< -o $@
+
 uidir = $(GEDIT_PLUGINS_DATA_DIR)/time
 ui_DATA = \
 	gedit-time-dialog.ui				\
@@ -27,6 +32,11 @@ plugin_in_files = time.gedit-plugin.desktop.in
 
 plugin_DATA = $(plugin_in_files:.gedit-plugin.desktop.in=.gedit-plugin)
 
+if GSETTINGS_SCHEMAS_INSTALL
+install-data-hook:
+	$(GLIB_COMPILE_SCHEMAS) $(gsettingsschemadir)
+endif
+
 EXTRA_DIST = $(ui_DATA) $(plugin_in_files)
 
 CLEANFILES = $(plugin_DATA)
diff --git a/plugins/time/gedit-time-plugin.c b/plugins/time/gedit-time-plugin.c
index 3531bca..d11057c 100644
--- a/plugins/time/gedit-time-plugin.c
+++ b/plugins/time/gedit-time-plugin.c
@@ -33,8 +33,6 @@
 #include <string.h>
 #include <time.h>
 
-#include <gconf/gconf-client.h>
-
 #include "gedit-time-plugin.h"
 #include <gedit/gedit-app.h>
 
@@ -52,11 +50,11 @@
 #define WINDOW_DATA_KEY "GeditTimePluginWindowData"
 #define MENU_PATH "/MenuBar/EditMenu/EditOps_4"
 
-/* gconf keys */
-#define TIME_BASE_KEY		"/apps/gedit-2/plugins/time"
-#define PROMPT_TYPE_KEY		TIME_BASE_KEY "/prompt_type"
-#define SELECTED_FORMAT_KEY	TIME_BASE_KEY "/selected_format"
-#define CUSTOM_FORMAT_KEY	TIME_BASE_KEY "/custom_format"
+/* gsettings keys */
+#define TIME_BASE_SETTINGS	"org.gnome.gedit.plugins.time"
+#define PROMPT_TYPE_KEY		"prompt-type"
+#define SELECTED_FORMAT_KEY	"selected-format"
+#define CUSTOM_FORMAT_KEY	"custom-format"
 
 #define DEFAULT_CUSTOM_FORMAT "%d/%m/%Y %H:%M:%S"
 
@@ -155,7 +153,7 @@ typedef enum
 
 struct _GeditTimePluginPrivate
 {
-	GConfClient *gconf_client;
+	GSettings *settings;
 };
 
 GEDIT_PLUGIN_REGISTER_TYPE(GeditTimePlugin, gedit_time_plugin)
@@ -193,26 +191,23 @@ gedit_time_plugin_init (GeditTimePlugin *plugin)
 
 	plugin->priv = GEDIT_TIME_PLUGIN_GET_PRIVATE (plugin);
 
-	plugin->priv->gconf_client = gconf_client_get_default ();
-
-	gconf_client_add_dir (plugin->priv->gconf_client,
-			      TIME_BASE_KEY,
-			      GCONF_CLIENT_PRELOAD_ONELEVEL,
-			      NULL);
+	plugin->priv->settings = g_settings_new (TIME_BASE_SETTINGS);
 }
 
 static void
-gedit_time_plugin_finalize (GObject *object)
+gedit_time_plugin_dispose (GObject *object)
 {
 	GeditTimePlugin *plugin = GEDIT_TIME_PLUGIN (object);
 
-	gedit_debug_message (DEBUG_PLUGINS, "GeditTimePlugin finalizing");
-
-	gconf_client_suggest_sync (plugin->priv->gconf_client, NULL);
+	gedit_debug_message (DEBUG_PLUGINS, "GeditTimePlugin disposing");
 
-	g_object_unref (G_OBJECT (plugin->priv->gconf_client));
+	if (plugin->priv->settings != NULL)
+	{
+		g_object_unref (plugin->priv->settings);
+		plugin->priv->settings = NULL;
+	}
 
-	G_OBJECT_CLASS (gedit_time_plugin_parent_class)->finalize (object);
+	G_OBJECT_CLASS (gedit_time_plugin_parent_class)->dispose (object);
 }
 
 static void
@@ -221,7 +216,15 @@ free_window_data (WindowData *data)
 	g_return_if_fail (data != NULL);
 
 	g_object_unref (data->action_group);
-	g_free (data);
+	g_slice_free (WindowData, data);
+}
+
+static void
+free_action_data (ActionData *data)
+{
+	g_return_if_fail (data != NULL);
+
+	g_slice_free (ActionData, data);
 }
 
 static void
@@ -254,8 +257,8 @@ impl_activate (GeditPlugin *plugin,
 
 	gedit_debug (DEBUG_PLUGINS);
 
-	data = g_new (WindowData, 1);
-	action_data = g_new (ActionData, 1);
+	data = g_slice_new (WindowData);
+	action_data = g_slice_new (ActionData);
 
 	action_data->plugin = GEDIT_TIME_PLUGIN (plugin);
 	action_data->window = window;
@@ -269,7 +272,7 @@ impl_activate (GeditPlugin *plugin,
 				      	   action_entries,
 				      	   G_N_ELEMENTS (action_entries),
 				      	   action_data,
-				      	   (GDestroyNotify) g_free);
+				      	   (GDestroyNotify) free_action_data);
 
 	gtk_ui_manager_insert_action_group (manager, data->action_group, -1);
 
@@ -332,9 +335,8 @@ get_prompt_type (GeditTimePlugin *plugin)
 	gchar *prompt_type;
 	GeditTimePluginPromptType res;
 
-	prompt_type = gconf_client_get_string (plugin->priv->gconf_client,
-			        	       PROMPT_TYPE_KEY,
-					       NULL);
+	prompt_type = g_settings_get_string (plugin->priv->settings,
+			        	     PROMPT_TYPE_KEY);
 
 	if (prompt_type == NULL)
 		return PROMPT_SELECTED_FORMAT;
@@ -359,13 +361,6 @@ set_prompt_type (GeditTimePlugin           *plugin,
 {
 	const gchar * str;
 
-	if (!gconf_client_key_is_writable (plugin->priv->gconf_client,
-					   PROMPT_TYPE_KEY,
-					   NULL))
-	{
-		return;
-	}
-
 	switch (prompt_type)
 	{
 		case USE_SELECTED_FORMAT:
@@ -381,10 +376,9 @@ set_prompt_type (GeditTimePlugin           *plugin,
 			str = "PROMPT_SELECTED_FORMAT";
 	}
 
-	gconf_client_set_string (plugin->priv->gconf_client,
-				 PROMPT_TYPE_KEY,
-		       		 str,
-		       		 NULL);
+	g_settings_set_string (plugin->priv->settings,
+			       PROMPT_TYPE_KEY,
+		       	       str);
 }
 
 /* The selected format in the list */
@@ -393,9 +387,8 @@ get_selected_format (GeditTimePlugin *plugin)
 {
 	gchar *sel_format;
 
-	sel_format = gconf_client_get_string (plugin->priv->gconf_client,
-					      SELECTED_FORMAT_KEY,
-					      NULL);
+	sel_format = g_settings_get_string (plugin->priv->settings,
+					    SELECTED_FORMAT_KEY);
 
 	return sel_format ? sel_format : g_strdup (formats [0]);
 }
@@ -406,17 +399,9 @@ set_selected_format (GeditTimePlugin *plugin,
 {
 	g_return_if_fail (format != NULL);
 
-	if (!gconf_client_key_is_writable (plugin->priv->gconf_client,
-					   SELECTED_FORMAT_KEY,
-					   NULL))
-	{
-		return;
-	}
-
-	gconf_client_set_string (plugin->priv->gconf_client,
-				 SELECTED_FORMAT_KEY,
-		       		 format,
-		       		 NULL);
+	g_settings_set_string (plugin->priv->settings,
+			       SELECTED_FORMAT_KEY,
+		       	       format);
 }
 
 /* the custom format in the entry */
@@ -425,9 +410,8 @@ get_custom_format (GeditTimePlugin *plugin)
 {
 	gchar *format;
 
-	format = gconf_client_get_string (plugin->priv->gconf_client,
-					  CUSTOM_FORMAT_KEY,
-					  NULL);
+	format = g_settings_get_string (plugin->priv->settings,
+					CUSTOM_FORMAT_KEY);
 
 	return format ? format : g_strdup (DEFAULT_CUSTOM_FORMAT);
 }
@@ -438,15 +422,9 @@ set_custom_format (GeditTimePlugin *plugin,
 {
 	g_return_if_fail (format != NULL);
 
-	if (!gconf_client_key_is_writable (plugin->priv->gconf_client,
-					   CUSTOM_FORMAT_KEY,
-					   NULL))
-		return;
-
-	gconf_client_set_string (plugin->priv->gconf_client,
-				 CUSTOM_FORMAT_KEY,
-		       		 format,
-		       		 NULL);
+	g_settings_set_string (plugin->priv->settings,
+			       CUSTOM_FORMAT_KEY,
+		       	       format);
 }
 
 static gchar *
@@ -1262,7 +1240,7 @@ gedit_time_plugin_class_init (GeditTimePluginClass *klass)
 	GObjectClass *object_class = G_OBJECT_CLASS (klass);
 	GeditPluginClass *plugin_class = GEDIT_PLUGIN_CLASS (klass);
 
-	object_class->finalize = gedit_time_plugin_finalize;
+	object_class->dispose = gedit_time_plugin_dispose;
 
 	plugin_class->activate = impl_activate;
 	plugin_class->deactivate = impl_deactivate;
diff --git a/plugins/time/org.gnome.gedit.time.gschema.in b/plugins/time/org.gnome.gedit.time.gschema.in
new file mode 100644
index 0000000..afc7783
--- /dev/null
+++ b/plugins/time/org.gnome.gedit.time.gschema.in
@@ -0,0 +1,6 @@
+schema org.gnome.gedit.plugins.time:
+  path /apps/gedit/plugins/time
+
+  key prompt-type = @s 'USE_SELECTED_FORMAT'
+  key selected-format = @s ''
+  key custom-format = @s ''



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]