[evolution/wip/gsettings: 2/7] Migrate SA extension to GSettings



commit fa4a42d741fade66d51857fb2653e27e347aef80
Author: Rodrigo Moya <rodrigo gnome-db org>
Date:   Tue Nov 1 17:26:07 2011 +0100

    Migrate SA extension to GSettings

 data/evolution.convert                        |    3 +
 data/org.gnome.evolution.mail.gschema.xml.in  |   15 +++
 modules/mail/em-mailer-prefs.c                |  115 ++++++++++++-------------
 modules/mail/em-mailer-prefs.h                |    4 +-
 modules/spamassassin/evolution-spamassassin.c |   38 +++------
 5 files changed, 86 insertions(+), 89 deletions(-)
---
diff --git a/data/evolution.convert b/data/evolution.convert
index 780ba56..992286f 100644
--- a/data/evolution.convert
+++ b/data/evolution.convert
@@ -132,6 +132,9 @@ junk-empty-on-exit-days = /apps/evolution/mail/junk/empty_on_exit_days
 junk-lookup-addressbook = /apps/evolution/mail/junk/lookup_addressbook
 junk-lookup-addressbook-local-only = /apps/evolution/mail/junk/lookup_addressbook_local_only
 junk-sa-local-only = /apps/evolution/mail/junk/sa/local_only
+junk-sa-spamc-binary = /apps/evolution/mail/junk/sa/spamc_binary
+junk-sa-spamd-binary = /apps/evolution/mail/junk/sa/spamd_binary
+junk-sa-socket-path = "/apps/evolution/mail/junk/sa/socket_path
 junk-sa-use-daemon = /apps/evolution/mail/junk/sa/use_daemon
 labels = /apps/evolution/mail/labels
 layout = /apps/evolution/mail/display/layout
diff --git a/data/org.gnome.evolution.mail.gschema.xml.in b/data/org.gnome.evolution.mail.gschema.xml.in
index 35092cc..30884ae 100644
--- a/data/org.gnome.evolution.mail.gschema.xml.in
+++ b/data/org.gnome.evolution.mail.gschema.xml.in
@@ -500,11 +500,26 @@
       <_summary>Use only local spam tests.</_summary>
       <_description>Use only the local spam tests (no DNS).</_description>
     </key>
+    <key name="junk-sa-socket-path" type="s">
+      <default>''</default>
+      <_summary>Socket path for SpamAssassin</_summary>
+      <_description>Socket path for SpamAssassin</_description>
+    </key>
     <key name="junk-sa-use-daemon" type="b">
       <default>true</default>
       <_summary>Use SpamAssassin daemon and client</_summary>
       <_description>Use SpamAssassin daemon and client (spamc/spamd).</_description>
     </key>
+    <key name="junk-sa-spamc-binary" type="s">
+      <default>'spamc'</default>
+      <_summary>SpamAssassin client binary</_summary>
+      <_description>SpamAssassin client binary</_description>
+    </key>
+    <key name="junk-sa-spamd-binary" type="s">
+      <default>'spamd'</default>
+      <_summary>SpamAssassin daemon binary</_summary>
+      <_description>SpamAssassin daemon binary</_description>
+    </key>
     <key name="junk-lookup-addressbook" type="b">
       <default>false</default>
       <_summary>Determines whether to lookup in address book for sender email</_summary>
diff --git a/modules/mail/em-mailer-prefs.c b/modules/mail/em-mailer-prefs.c
index 290e189..b04c35b 100644
--- a/modules/mail/em-mailer-prefs.c
+++ b/modules/mail/em-mailer-prefs.c
@@ -33,8 +33,6 @@
 #include <gtkhtml/gtkhtml-properties.h>
 #include <libxml/tree.h>
 
-#include <gconf/gconf-client.h>
-
 #include "libedataserverui/e-cell-renderer-color.h"
 
 #include <e-util/e-util.h>
@@ -106,13 +104,7 @@ em_mailer_prefs_finalize (GObject *object)
 
 	g_object_unref (prefs->builder);
 
-	if (prefs->labels_change_notify_id) {
-		gconf_client_notify_remove (prefs->gconf, prefs->labels_change_notify_id);
-
-		prefs->labels_change_notify_id = 0;
-	}
-
-	g_object_unref (prefs->gconf);
+	g_object_unref (prefs->settings);
 
 	/* Chain up to parent's finalize() method. */
 	G_OBJECT_CLASS (em_mailer_prefs_parent_class)->finalize (object);
@@ -130,7 +122,7 @@ em_mailer_prefs_class_init (EMMailerPrefsClass *class)
 static void
 em_mailer_prefs_init (EMMailerPrefs *preferences)
 {
-	preferences->gconf = gconf_client_get_default ();
+	preferences->settings = g_settings_new ("org.gnome.evolution.mail");
 }
 
 enum {
@@ -142,13 +134,16 @@ static void
 jh_tree_refill (EMMailerPrefs *prefs)
 {
 	GtkListStore *store = prefs->junk_header_list_store;
-	GSList *l, *cjh = gconf_client_get_list (prefs->gconf, "/apps/evolution/mail/junk/custom_header", GCONF_VALUE_STRING, NULL);
+	gchar **strv;
+	gint i;
+
+	strv = g_settings_get_strv (prefs->settings, "junk-custom-header");
 
 	gtk_list_store_clear (store);
 
-	for (l = cjh; l; l = l->next) {
+	for (i = 0; strv[i] != NULL; i++) {
 		GtkTreeIter iter;
-		gchar **tokens = g_strsplit (l->data, "=", 2);
+		gchar **tokens = g_strsplit (strv[i], "=", 2);
 
 		gtk_list_store_append (store, &iter);
 		gtk_list_store_set (
@@ -159,8 +154,7 @@ jh_tree_refill (EMMailerPrefs *prefs)
 		g_strfreev (tokens);
 	}
 
-	g_slist_foreach (cjh, (GFunc) g_free, NULL);
-	g_slist_free (cjh);
+	g_strfreev (strv);
 }
 
 static void
@@ -191,7 +185,6 @@ jh_add_cb (GtkWidget *widget,
 	GtkBuilder *builder = gtk_builder_new ();
 	gchar *tok;
 	const gchar *name, *value;
-	GSList *list;
 
 	e_load_ui_builder_definition (builder, "mail-config.ui");
 	dialog = e_builder_get_widget (builder, "add-custom-junk-header");
@@ -205,16 +198,24 @@ jh_add_cb (GtkWidget *widget,
 		G_CALLBACK (jh_dialog_entry_changed_cb), builder);
 
 	if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT) {
+		gchar **strv;
+		GPtrArray *array;
+		gint i;
+
 		name = gtk_entry_get_text (GTK_ENTRY (e_builder_get_widget (builder, "junk-header-name")));
 		value = gtk_entry_get_text (GTK_ENTRY (e_builder_get_widget (builder, "junk-header-content")));
 
-		list = gconf_client_get_list (prefs->gconf, "/apps/evolution/mail/junk/custom_header", GCONF_VALUE_STRING, NULL);
+		strv = g_settings_get_strv (prefs->settings, "junk-custom-header");
+		array = g_ptr_array_new ();
+		for (i = 0; strv[i] != NULL; i++)
+			g_ptr_array_add (array, strv[i]);
 		tok = g_strdup_printf ("%s=%s", name, value);
-		list = g_slist_append (list, tok);
-		gconf_client_set_list (prefs->gconf, "/apps/evolution/mail/junk/custom_header", GCONF_VALUE_STRING, list, NULL);
+		g_ptr_array_add (array, tok);
+		g_ptr_array_add (array, NULL);
+		g_settings_set_strv (prefs->settings, "junk-custom-header", array->pdata);
 
-		g_slist_foreach (list, (GFunc) g_free, NULL);
-		g_slist_free (list);
+		g_ptr_array_free (array, TRUE);
+		g_strfreev (strv);
 	}
 
 	g_object_unref (builder);
@@ -237,38 +238,32 @@ jh_remove_cb (GtkWidget *widget,
 	selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (prefs->junk_header_tree));
 	if (gtk_tree_selection_get_selected (selection, &model, &iter)) {
 		gchar *name = NULL, *value = NULL;
-		GSList *prev = NULL, *node, *list = gconf_client_get_list (prefs->gconf, "/apps/evolution/mail/junk/custom_header", GCONF_VALUE_STRING, NULL);
+		gchar **strv;
+		GPtrArray *array = g_ptr_array_new ();
+		gint i;
+
+		strv = g_settings_get_strv (prefs->settings, "junk-custom-header");
 		gtk_tree_model_get (model, &iter, JH_LIST_COLUMN_NAME, &name, JH_LIST_COLUMN_VALUE, &value, -1);
-		node = list;
-		while (node) {
+		for (i = 0; strv[i] != NULL; i++) {
 			gchar *test;
 			gint len = strlen (name);
-			test = strncmp (node->data, name, len) == 0 ? (gchar *) node->data + len : NULL;
+			test = strncmp (strv[i], name, len) == 0 ? (gchar *) strv[i] + len : NULL;
 
 			if (test) {
 				test++;
 				if (strcmp (test, value) == 0)
-					break;
+					continue;
 			}
 
-			prev = node;
-			node = node->next;
+			g_ptr_array_add (array, strv[i]);
 		}
 
-		if (prev && !node) {
-			/* Not found. So what? */
-		} else if (prev && node) {
-			prev->next = node->next;
-			g_free (node->data);
-		} else if (!prev && node) {
-			list = list->next;
-			g_free (node->data);
-		}
+		g_ptr_array_add (array, NULL);
 
-		gconf_client_set_list (prefs->gconf, "/apps/evolution/mail/junk/custom_header", GCONF_VALUE_STRING, list, NULL);
+		g_settings_set_strv (prefs->settings, "junk-custom-header", array->pdata);
 
-		g_slist_foreach (list, (GFunc) g_free, NULL);
-		g_slist_free (list);
+		g_strfreev (strv);
+		g_ptr_array_free (array, TRUE);
 		g_free (name);
 		g_free (value);
 
@@ -494,7 +489,7 @@ toggle_button_toggled (GtkToggleButton *toggle,
 	const gchar *key;
 
 	key = g_object_get_data ((GObject *) toggle, "key");
-	gconf_client_set_bool (prefs->gconf, key, gtk_toggle_button_get_active (toggle), NULL);
+	g_settings_set_boolean (prefs->settings, key, gtk_toggle_button_get_active (toggle));
 }
 
 static void
@@ -531,7 +526,7 @@ toggle_button_init (EMMailerPrefs *prefs,
 {
 	gboolean bool;
 
-	bool = gconf_client_get_bool (prefs->gconf, key, NULL);
+	bool = g_settings_get_boolean (prefs->settings, key);
 	gtk_toggle_button_set_active (toggle, not ? !bool : bool);
 
 	if (toggled) {
@@ -539,7 +534,7 @@ toggle_button_init (EMMailerPrefs *prefs,
 		g_signal_connect (toggle, "toggled", toggled, prefs);
 	}
 
-	if (!gconf_client_key_is_writable (prefs->gconf, key, NULL))
+	if (!g_settings_is_writable (prefs->settings, key)
 		gtk_widget_set_sensitive ((GtkWidget *) toggle, FALSE);
 }
 
@@ -553,10 +548,10 @@ trash_days_changed (GtkComboBox *combo_box,
 	g_return_if_fail (index >= 0);
 	g_return_if_fail (index < G_N_ELEMENTS (empty_trash_frequency));
 
-	gconf_client_set_int (
-		prefs->gconf,
-		"/apps/evolution/mail/trash/empty_on_exit_days",
-		empty_trash_frequency[index].days, NULL);
+	g_settings_set_int (
+		prefs->settings,
+		"trash-empty-on-exit-days",
+		empty_trash_frequency[index].days);
 }
 
 static void
@@ -567,9 +562,9 @@ emmp_empty_trash_init (EMMailerPrefs *prefs,
 	GtkListStore *store;
 	GtkTreeIter iter;
 
-	days = gconf_client_get_int (
-		prefs->gconf,
-		"/apps/evolution/mail/trash/empty_on_exit_days", NULL);
+	days = g_settings_get_int (
+		prefs->settings,
+		"trash-empty-on-exit-days");
 
 	store = GTK_LIST_STORE (gtk_combo_box_get_model (combo_box));
 	gtk_list_store_clear (store);
@@ -601,10 +596,10 @@ junk_days_changed (GtkComboBox *combo_box,
 	g_return_if_fail (index >= 0);
 	g_return_if_fail (index < G_N_ELEMENTS (empty_trash_frequency));
 
-	gconf_client_set_int (
-		prefs->gconf,
-		"/apps/evolution/mail/junk/empty_on_exit_days",
-		empty_trash_frequency[index].days, NULL);
+	g_settings_set_int (
+		prefs->settings,
+		"junk-empty-on-exit-days",
+		empty_trash_frequency[index].days);
 }
 
 static void
@@ -615,9 +610,9 @@ emmp_empty_junk_init (EMMailerPrefs *prefs,
 	GtkListStore *store;
 	GtkTreeIter iter;
 
-	days = gconf_client_get_int (
-		prefs->gconf,
-		"/apps/evolution/mail/junk/empty_on_exit_days", NULL);
+	days = g_settings_get_int (
+		prefs->settings,
+		"junk-empty-on-exit-days");
 
 	store = GTK_LIST_STORE (gtk_combo_box_get_model (combo_box));
 	gtk_list_store_clear (store);
@@ -652,7 +647,7 @@ http_images_changed (GtkWidget *widget,
 	else
 		policy = E_MAIL_IMAGE_LOADING_POLICY_NEVER;
 
-	gconf_client_set_int (prefs->gconf, "/apps/evolution/mail/display/load_http_images", policy, NULL);
+	g_settings_set_int (prefs->settings, "load-http-images", policy);
 }
 
 static GtkWidget *
@@ -870,9 +865,9 @@ em_mailer_prefs_construct (EMMailerPrefs *prefs,
 	/* HTML Mail tab */
 
 	/* Loading Images */
-	locked = !gconf_client_key_is_writable (prefs->gconf, "/apps/evolution/mail/display/load_http_images", NULL);
+	locked = !g_settings_is_writable (prefs->settings, "load-http-images");
 
-	val = gconf_client_get_int (prefs->gconf, "/apps/evolution/mail/display/load_http_images", NULL);
+	val = g_settings_get_int (prefs->settings, "load-http-images");
 	prefs->images_never = GTK_TOGGLE_BUTTON (e_builder_get_widget (prefs->builder, "radImagesNever"));
 	gtk_toggle_button_set_active (prefs->images_never, val == E_MAIL_IMAGE_LOADING_POLICY_NEVER);
 	if (locked)
diff --git a/modules/mail/em-mailer-prefs.h b/modules/mail/em-mailer-prefs.h
index 35ebec3..eee2d24 100644
--- a/modules/mail/em-mailer-prefs.h
+++ b/modules/mail/em-mailer-prefs.h
@@ -24,7 +24,6 @@
 #define EM_MAILER_PREFS_H
 
 #include <gtk/gtk.h>
-#include <gconf/gconf-client.h>
 #include <shell/e-shell.h>
 #include <widgets/misc/e-preferences-window.h>
 
@@ -56,7 +55,7 @@ struct _EMMailerPrefs {
 	GtkVBox parent_object;
 
 	GtkBuilder *builder;
-	GConfClient *gconf;
+	GSettings *settings;
 
 	/* General tab */
 
@@ -81,7 +80,6 @@ struct _EMMailerPrefs {
 	GtkWidget *label_remove;
 	GtkWidget *label_tree;
 	GtkListStore *label_list_store;
-	guint labels_change_notify_id; /* mail_config's notify id */
 
 	/* Headers tab */
 	GtkButton *add_header;
diff --git a/modules/spamassassin/evolution-spamassassin.c b/modules/spamassassin/evolution-spamassassin.c
index b578acf..a628753 100644
--- a/modules/spamassassin/evolution-spamassassin.c
+++ b/modules/spamassassin/evolution-spamassassin.c
@@ -25,7 +25,6 @@
 
 #include <shell/e-shell.h>
 #include <e-util/e-mktemp.h>
-#include <e-util/gconf-bridge.h>
 #include <mail/e-mail-junk-filter.h>
 
 /* Standard GObject macros */
@@ -1074,7 +1073,7 @@ e_spam_assassin_class_init (ESpamAssassinClass *class)
 	junk_filter_class->available = spam_assassin_available;
 	junk_filter_class->new_config_widget = spam_assassin_new_config_widget;
 
-	/* XXX Argh, the boolean sense of the GConf key is inverted from
+	/* XXX Argh, the boolean sense of the GSettings key is inverted from
 	 *     that of the checkbox widget.  The checkbox wording is more
 	 *     natural, but GConfBridge doesn't support transform functions
 	 *     so the property has to match the sense of the GConf key. */
@@ -1146,36 +1145,23 @@ e_spam_assassin_interface_init (CamelJunkFilterInterface *interface)
 static void
 e_spam_assassin_init (ESpamAssassin *extension)
 {
+	GSettings *settings;
+
 	extension->socket_path_mutex = g_mutex_new ();
 
 	/* XXX Once we move to GSettings these probably don't
 	 *     need to be properties anymore.  GConfBridge is
 	 *     just easier to deal with than GConfClient. */
 
-	gconf_bridge_bind_property (
-		gconf_bridge_get (),
-		"/apps/evolution/mail/junk/sa/local_only",
-		G_OBJECT (extension), "local-only");
-
-	gconf_bridge_bind_property (
-		gconf_bridge_get (),
-		"/apps/evolution/mail/junk/sa/spamc_binary",
-		G_OBJECT (extension), "spamc-binary");
-
-	gconf_bridge_bind_property (
-		gconf_bridge_get (),
-		"/apps/evolution/mail/junk/sa/spamd_binary",
-		G_OBJECT (extension), "spamd-binary");
-
-	gconf_bridge_bind_property (
-		gconf_bridge_get (),
-		"/apps/evolution/mail/junk/sa/socket_path",
-		G_OBJECT (extension), "socket-path");
-
-	gconf_bridge_bind_property (
-		gconf_bridge_get (),
-		"/apps/evolution/mail/junk/sa/use_daemon",
-		G_OBJECT (extension), "use-daemon");
+	settings = g_settings_new ("org.gnome.evolution.mail");
+
+	g_settings_bind (settings, "junk-sa-local-only", G_OBJECT (extension), "local-only", G_SETTINGS_BIND_DEFAULT);
+	g_settings_bind (settings, "junk-sa-spamc-binary", G_OBJECT (extension), "spamc-binary", G_SETTINGS_BIND_DEFAULT);
+	g_settings_bind (settings, "junk-sa-spamd-binary", G_OBJECT (extension), "spamd-binary", G_SETTINGS_BIND_DEFAULT);
+	g_settings_bind (settings, "junk-sa-socjet-path", G_OBJECT (extension), "socket-path", G_SETTINGS_BIND_DEFAULT);
+	g_settings_bind (settings, "junk-sa-use-daemon", G_OBJECT (extension), "use-daemon", G_SETTINGS_BIND_DEFAULT);
+
+	g_object_unref (settings);
 
 	if (extension->spamc_binary == NULL)
 		extension->spamc_binary = g_strdup (SPAMC_BINARY);



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