aboutsummaryrefslogtreecommitdiffstats
path: root/mail/e-mail-label-list-store.c
diff options
context:
space:
mode:
authorRodrigo Moya <rodrigo@gnome-db.org>2011-10-26 23:54:50 +0800
committerRodrigo Moya <rodrigo@gnome-db.org>2011-10-26 23:54:50 +0800
commit9744056c5e69227abdcdd55c4bffb674b29bd765 (patch)
treed0b54f23e6fd42a2887f01af3bb41f5c2552fa67 /mail/e-mail-label-list-store.c
parent8d001181fbaf1350764e75c28f61e1ae3498dbb3 (diff)
downloadgsoc2013-evolution-9744056c5e69227abdcdd55c4bffb674b29bd765.tar
gsoc2013-evolution-9744056c5e69227abdcdd55c4bffb674b29bd765.tar.gz
gsoc2013-evolution-9744056c5e69227abdcdd55c4bffb674b29bd765.tar.bz2
gsoc2013-evolution-9744056c5e69227abdcdd55c4bffb674b29bd765.tar.lz
gsoc2013-evolution-9744056c5e69227abdcdd55c4bffb674b29bd765.tar.xz
gsoc2013-evolution-9744056c5e69227abdcdd55c4bffb674b29bd765.tar.zst
gsoc2013-evolution-9744056c5e69227abdcdd55c4bffb674b29bd765.zip
More GSettings migration
Diffstat (limited to 'mail/e-mail-label-list-store.c')
-rw-r--r--mail/e-mail-label-list-store.c105
1 files changed, 94 insertions, 11 deletions
diff --git a/mail/e-mail-label-list-store.c b/mail/e-mail-label-list-store.c
index f604893bb3..e9f9c4b509 100644
--- a/mail/e-mail-label-list-store.c
+++ b/mail/e-mail-label-list-store.c
@@ -27,10 +27,10 @@
#include <glib/gi18n.h>
#include <camel/camel.h>
-#include "e-util/gconf-bridge.h"
struct _EMailLabelListStorePrivate {
GHashTable *tag_index;
+ GSettings *mail_settings;
};
static struct {
@@ -160,24 +160,107 @@ mail_label_list_store_finalize (GObject *object)
priv = E_MAIL_LABEL_LIST_STORE (object)->priv;
g_hash_table_destroy (priv->tag_index);
+ if (priv->mail_settings != NULL) {
+ g_object_unref (priv->mail_settings);
+ priv->mail_settings = NULL;
+ }
/* Chain up to parent's finalize() method. */
G_OBJECT_CLASS (parent_class)->finalize (object);
}
+
+static void labels_settings_changed_cb (GSettings *settings, const gchar *key, gpointer user_data);
+
+static void
+labels_model_changed_cb (GtkTreeModel *model,
+ GtkTreePath *path,
+ GtkTreeIter *iter,
+ gpointer user_data)
+{
+ EMailLabelListStore *store;
+ GtkTreeIter iter;
+ GPtrArray *array;
+ gboolean res;
+
+ store = E_MAIL_LABEL_LIST_STORE (user_data);
+
+ /* Make sure we don't enter an infinite synchronizing loop */
+ g_signal_handlers_block_by_func (store->priv->mail_settings, labels_settings_changed_cb, store);
+
+ /* Build list to store in GSettings */
+ array = g_ptr_array_new ();
+ res = gtk_tree_model_get_iter_first (GTK_TREE_MODEL (store), &iter);
+ while (res) {
+ gchar *string;
+
+ gtk_tree_model_get (GTK_TREE_MODEL (store), &iter,
+ 0, &string, -1);
+ g_ptr_array_add (array, string);
+
+ res = gtk_tree_model_iter_next (GTK_TREE_MODEL (store), &iter);
+ }
+
+ g_ptr_array_add (array, NULL);
+ g_settings_set_strv (store->priv->mail_settings, "labels", array->pdata);
+
+ g_ptr_array_free (array, TRUE);
+ g_signal_handlers_unblock_by_func (store->priv->mail_settings, labels_settings_changed_cb, store);
+}
+
+static void
+labels_settings_changed_cb (GSettings *settings,
+ const gchar *key,
+ gpointer user_data)
+{
+ EMailLabelListStore *store;
+ gchar **strv;
+ gint i;
+
+ store = E_MAIL_LABEL_LIST_STORE (user_data);
+
+ /* Make sure we don't enter an infinite synchronizing loop */
+ g_signal_handlers_block_by_func (store, labels_model_changed_cb, store);
+
+ gtk_list_store_clear (GTK_LIST_STORE (store));
+
+ strv = g_settings_get_strv (store->priv->mail_settings, "labels");
+ for (i = 0; strv[i] != NULL; i++) {
+ GtkTreeIter iter;
+
+ gtk_list_store_insert_with_values (GTK_LIST_STORE (store),
+ &iter, -1,
+ 0, strv[i],
+ -1);
+ }
+
+ g_strfreev (strv);
+
+ g_signal_handlers_unblock_by_func (store, labels_model_changed_cb, store);
+}
+
static void
mail_label_list_store_constructed (GObject *object)
{
EMailLabelListStore *store;
- GConfBridge *bridge;
- const gchar *key;
store = E_MAIL_LABEL_LIST_STORE (object);
- bridge = gconf_bridge_get ();
- key = "/apps/evolution/mail/labels";
- gconf_bridge_bind_string_list_store (
- bridge, key, GTK_LIST_STORE (store));
+ /* Connect to GSettings' change notifications */
+ store->priv->mail_settings = g_settings_new ("org.gnome.evolution.mail");
+ g_signal_connect (store->priv->mail_settings, "changed::labels",
+ G_CALLBACK (labels_settings_changed_cb), store);
+ labels_settings_changed_cb (store->priv->mail_settings, "labels", store);
+
+ /* Connect to ListStore change notifications */
+ g_signal_connect (store, "row-inserted",
+ G_CALLBACK (labels_model_changed_cb), store);
+ g_signal_connect (store, "row-changed",
+ G_CALLBACK (labels_model_changed_cb), store);
+ g_signal_connect (store, "row-deleted",
+ G_CALLBACK (labels_model_changed_cb), store);
+ g_signal_connect (store, "rows-reordered",
+ G_CALLBACK (labels_model_changed_cb), store);
mail_label_list_store_ensure_defaults (store);
@@ -245,10 +328,10 @@ mail_label_list_store_init (EMailLabelListStore *store)
/* XXX While it may seem awkward to cram the label name and color
* into a single string column, we do it for the benefit of
- * letting GConfBridge keep the model in sync with GConf.
+ * letting GSettings keep the model in sync.
*
* XXX There's a valid argument to be made that this information
- * doesn't belong in GConf in the first place. A key file
+ * doesn't belong in GSettings in the first place. A key file
* under $(user_data_dir)/mail would work better. */
gtk_list_store_set_column_types (GTK_LIST_STORE (store), 1, &type);
}
@@ -404,7 +487,7 @@ e_mail_label_list_store_get_tag (EMailLabelListStore *store,
strv = g_strsplit_set (encoded, ":|", 3);
/* XXX I guess for historical reasons the default label tags have
- * a "$Label" prefix, but the default list in GConf doesn't
+ * a "$Label" prefix, but the default list in GSettings doesn't
* include tags. That's why the <tag> part is optional.
* So if we're missing the <tag> part, look it up in the
* hard-coded default list above.
@@ -431,7 +514,7 @@ e_mail_label_list_store_get_tag (EMailLabelListStore *store,
}
}
- /* XXX Still no luck? The label list in GConf must be screwed up.
+ /* XXX Still no luck? The label list in GSettings must be screwed up.
* We must not return NULL because the tag is used as a key in
* the index hash table, so generate a tag from the name. */
if (result == NULL)