[libcryptui] Port to Glib GSettings



commit 8b0b1a3a0449c541077b3f61390161706517e0fc
Author: Stef Walter <stefw collabora co uk>
Date:   Thu Jul 28 10:40:03 2011 +0200

    Port to Glib GSettings
    
     * Remove some unused code in the process, and cleanup some
       related code.

 .gitignore                                     |    1 +
 configure.ac                                   |    7 +-
 daemon/Makefile.am                             |    2 -
 daemon/seahorse-context.c                      |  113 ------
 daemon/seahorse-daemon.c                       |    5 -
 daemon/seahorse-gconf.c                        |  439 ------------------------
 daemon/seahorse-gconf.h                        |   80 -----
 daemon/seahorse-pgp-keysets.c                  |   79 -----
 daemon/seahorse-pgp-keysets.h                  |   33 --
 daemon/seahorse-service-crypto.c               |   24 +-
 daemon/seahorse-set.c                          |    1 -
 daemon/seahorse-util.c                         |    1 -
 daemon/seahorse-widget.c                       |   70 ----
 data/Makefile.am                               |   29 +-
 data/cryptui.schemas.in                        |  211 ------------
 data/org.gnome.seahorse.recipients.convert     |    6 +
 data/org.gnome.seahorse.recipients.gschema.xml |    9 +
 libcryptui/cryptui-key-chooser.c               |  130 ++++----
 libcryptui/cryptui-key-store.c                 |   15 +-
 libcryptui/cryptui-priv.h                      |   23 --
 libcryptui/cryptui.c                           |  199 -----------
 reference/Makefile.am                          |    2 +-
 22 files changed, 116 insertions(+), 1363 deletions(-)
---
diff --git a/.gitignore b/.gitignore
index 1a811a8..2c1fa72 100644
--- a/.gitignore
+++ b/.gitignore
@@ -9,6 +9,7 @@
 ~*
 tmp-*
 *~
+*.valid
 
 /configure.lineno
 /Makefile
diff --git a/configure.ac b/configure.ac
index 2c0e121..1d9ebc8 100644
--- a/configure.ac
+++ b/configure.ac
@@ -31,7 +31,6 @@ AC_PROG_CC
 AC_PROG_CXX
 AC_PROG_INTLTOOL([0.35.0])
 AM_PROG_LIBTOOL
-AM_GCONF_SOURCE_2
 GNOME_DOC_INIT
 GTK_DOC_CHECK([1.9])
 
@@ -50,7 +49,9 @@ PKG_CHECK_MODULES(GTK, gtk+-3.0 >= $GTK_REQUIRED)
 AC_SUBST(GTK_CFLAGS)
 AC_SUBST(GTK_LIBS)
 
-PKG_CHECK_MODULES(SEAHORSE, gmodule-2.0 gio-2.0 gconf-2.0 gthread-2.0 gtk+-3.0 >= $GTK_REQUIRED)
+PKG_CHECK_MODULES(SEAHORSE, gmodule-2.0 gio-2.0 gthread-2.0 gtk+-3.0 >= $GTK_REQUIRED)
+
+GLIB_GSETTINGS
 
 AC_MSG_CHECKING([for some Win32 platform])
 case "$host" in
@@ -283,7 +284,7 @@ AC_SUBST(LIBCRYPTUI_LT_RELEASE)
 LIBCRYPTUI_MAJOR=$LIBCRYPTUI_CURRENT.$LIBCRYPTUI_REVISION
 AC_SUBST(LIBCRYPTUI_MAJOR)
 
-PKG_CHECK_MODULES(LIBCRYPTUI, gtk+-3.0 >= $GTK_REQUIRED gconf-2.0)
+PKG_CHECK_MODULES(LIBCRYPTUI, gtk+-3.0 >= $GTK_REQUIRED)
 
 cryptuitargetlib=libcryptui.la
 AC_SUBST(cryptuitargetlib)
diff --git a/daemon/Makefile.am b/daemon/Makefile.am
index d214559..6198091 100644
--- a/daemon/Makefile.am
+++ b/daemon/Makefile.am
@@ -44,7 +44,6 @@ seahorse_daemon_SOURCES = \
 	seahorse-object-list.c seahorse-object-list.h \
 	seahorse-pgp.c seahorse-pgp.h \
 	seahorse-pgp-key.c seahorse-pgp-key.h \
-	seahorse-pgp-keysets.c seahorse-pgp-keysets.h \
 	seahorse-pgp-module.c seahorse-pgp-module.h \
 	seahorse-pgp-signature.c seahorse-pgp-signature.h \
 	seahorse-pgp-subkey.c seahorse-pgp-subkey.h \
@@ -53,7 +52,6 @@ seahorse_daemon_SOURCES = \
 	seahorse-service.c seahorse-service.h \
 	seahorse-service-keyset.c seahorse-service-crypto.c \
 	seahorse-context.c seahorse-context.h \
-	seahorse-gconf.c seahorse-gconf.h \
 	seahorse-gtkstock.c seahorse-gtkstock.h \
 	seahorse-libdialogs.h \
 	seahorse-notification.c \
diff --git a/daemon/seahorse-context.c b/daemon/seahorse-context.c
index 7ba4f1f..7a44423 100644
--- a/daemon/seahorse-context.c
+++ b/daemon/seahorse-context.c
@@ -27,7 +27,6 @@
 #include <libintl.h>
 
 #include "seahorse-context.h"
-#include "seahorse-gconf.h"
 #include "seahorse-libdialogs.h"
 #include "seahorse-marshal.h"
 #include "seahorse-transfer-operation.h"
@@ -74,7 +73,6 @@ struct _SeahorseContextPrivate {
     GSList *sources;                        /* Sources which add keys to this context */
     GHashTable *objects_by_source;          /* See explanation above */
     GHashTable *objects_by_type;            /* See explanation above */
-    guint notify_id;                        /* Notify for GConf watch */
     SeahorseMultiOperation *refresh_ops;    /* Operations for refreshes going on */
     gboolean in_destruction;                /* In destroy signal */
 };
@@ -181,11 +179,6 @@ seahorse_context_dispose (GObject *gobject)
     }
     g_slist_free (objects);
 
-    /* Gconf notification */
-    if (sctx->pv->notify_id)
-        seahorse_gconf_unnotify (sctx->pv->notify_id);
-    sctx->pv->notify_id = 0;
-
     /* Release all the sources */
     for (l = sctx->pv->sources; l; l = g_slist_next (l))
         g_object_unref (SEAHORSE_SOURCE (l->data));
@@ -997,42 +990,6 @@ seahorse_context_remove_object (SeahorseContext *sctx, SeahorseObject *sobj)
     }
 }
 
-
-/* -----------------------------------------------------------------------------
- * DEPRECATED 
- */
-
-/**
- * seahorse_context_get_default_key:
- * @sctx: Current #SeahorseContext
- *
- * Returns: the secret key that's the default key
- *
- * Deprecated: No replacement
- */
-SeahorseObject*
-seahorse_context_get_default_key (SeahorseContext *sctx)
-{
-    SeahorseObject *sobj = NULL;
-    gchar *id;
-    
-    if (!sctx)
-        sctx = seahorse_context_for_app ();
-    g_return_val_if_fail (SEAHORSE_IS_CONTEXT (sctx), NULL);
-
-    /* TODO: All of this needs to take multiple key types into account */
-    
-    id = seahorse_gconf_get_string (SEAHORSE_DEFAULT_KEY);
-    if (id != NULL && id[0]) {
-        GQuark keyid = g_quark_from_string (id);
-        sobj = seahorse_context_find_object (sctx, keyid, SEAHORSE_LOCATION_LOCAL);
-    }
-    
-    g_free (id);
-    
-    return sobj;
-}
-
 /**
  * seahorse_context_refresh_auto:
  * @sctx: A #SeahorseContext (can be NULL)
@@ -1070,68 +1027,6 @@ seahorse_context_refresh_auto (SeahorseContext *sctx)
 }
 
 /**
- * seahorse_context_search_remote:
- * @sctx: A #SeahorseContext (can be NULL)
- * @search: a keyword (name, email address...) to search for
- *
- * Searches for the key matching @search o the remote servers
- *
- * Returns: The created search operation
- */
-SeahorseOperation*
-seahorse_context_search_remote (SeahorseContext *sctx, const gchar *search)
-{
-    SeahorseSource *ks;
-    SeahorseMultiOperation *mop = NULL;
-    SeahorseOperation *op = NULL;
-    GSList *l, *names;
-    GHashTable *servers = NULL;
-    gchar *uri;
-
-    if (!sctx)
-        sctx = seahorse_context_for_app ();
-    g_return_val_if_fail (SEAHORSE_IS_CONTEXT (sctx), NULL);
-
-    /* Get a list of all selected key servers */
-    names = seahorse_gconf_get_string_list (LASTSERVERS_KEY);
-    if (names) {
-        servers = g_hash_table_new (g_str_hash, g_str_equal);
-        for (l = names; l; l = g_slist_next (l))
-            g_hash_table_insert (servers, l->data, GINT_TO_POINTER (TRUE));
-    }
-
-    for (l = sctx->pv->sources; l; l = g_slist_next (l)) {
-        ks = SEAHORSE_SOURCE (l->data);
-
-        if (seahorse_source_get_location (ks) != SEAHORSE_LOCATION_REMOTE)
-            continue;
-
-        if (servers) {
-            g_object_get (ks, "uri", &uri, NULL);
-            if (!g_hash_table_lookup (servers, uri)) {
-                g_free (uri);
-                continue;
-            }
-
-            g_free (uri);
-        }
-
-        if (mop == NULL && op != NULL) {
-            mop = seahorse_multi_operation_new ();
-            seahorse_multi_operation_take (mop, op);
-        }
-
-        op = seahorse_source_search (ks, search);
-
-        if (mop != NULL)
-            seahorse_multi_operation_take (mop, op);
-    }
-
-    seahorse_util_string_slist_free (names);
-    return mop ? SEAHORSE_OPERATION (mop) : op;
-}
-
-/**
  * seahorse_context_transfer_objects:
  * @sctx: The #SeahorseContext (can be NULL)
  * @objects: the objects to import
@@ -1366,14 +1261,6 @@ seahorse_context_discover_objects (SeahorseContext *sctx, GQuark ktype,
         g_object_unref (op);
     }
 
-    /* Start a discover process on all todiscover */
-    if (seahorse_gconf_get_boolean (AUTORETRIEVE_KEY) && todiscover) {
-        op = seahorse_context_retrieve_objects (sctx, ktype, todiscover, NULL);
-
-        /* Running operations ref themselves */
-        g_object_unref (op);
-    }
-
     /* Add unknown objects for all these */
     sksrc = seahorse_context_find_source (sctx, ktype, SEAHORSE_LOCATION_MISSING);
     for (l = todiscover; l; l = g_slist_next (l)) {
diff --git a/daemon/seahorse-daemon.c b/daemon/seahorse-daemon.c
index 0454d22..b15edb1 100644
--- a/daemon/seahorse-daemon.c
+++ b/daemon/seahorse-daemon.c
@@ -23,7 +23,6 @@
 
 #include "seahorse-context.h"
 #include "seahorse-daemon.h"
-#include "seahorse-gconf.h"
 #include "seahorse-gtkstock.h"
 #include "seahorse-pgp-module.h"
 #include "seahorse-secure-memory.h"
@@ -257,10 +256,6 @@ int main(int argc, char* argv[])
     seahorse_unix_signal_register (SIGINT, unix_signal);
     seahorse_unix_signal_register (SIGTERM, unix_signal);
 
-    /* Force gconf to reconnect after daemonizing */
-    if (!daemon_no_daemonize)
-        seahorse_gconf_disconnect ();
-
     /* We log to the syslog */
     prepare_logging ();
 
diff --git a/daemon/seahorse-service-crypto.c b/daemon/seahorse-service-crypto.c
index c766ad2..346579d 100644
--- a/daemon/seahorse-service-crypto.c
+++ b/daemon/seahorse-service-crypto.c
@@ -27,7 +27,6 @@
 #include "seahorse-gpgme-operation.h"
 #include "seahorse-libdialogs.h"
 #include "seahorse-object.h"
-#include "seahorse-gconf.h"
 #include "seahorse-util.h"
 #include "seahorse-service.h"
 
@@ -304,7 +303,9 @@ crypto_encrypt_generic (SeahorseServiceCrypto *crypto,
     gpgme_data_t plain, cipher;
     gpgme_error_t gerr;
     gboolean ret = TRUE;
-    
+    GSettings *settings;
+    gchar *keyid;
+
     /* 
      * TODO: Once we support different kinds of keys that support encryption
      * then all this logic will need to change. 
@@ -364,12 +365,19 @@ crypto_encrypt_generic (SeahorseServiceCrypto *crypto,
     gpgme_set_textmode (pop->gctx, textmode);
     gpgme_set_armor (pop->gctx, ascii_armor);
 
-    /* Add the default key if set and necessary */
-    if (seahorse_gconf_get_boolean (ENCRYPTSELF_KEY)) {
-        skey = SEAHORSE_OBJECT (seahorse_context_get_default_key (SCTX_APP ()));
-        if (SEAHORSE_IS_PGP_KEY (skey))
-            recipkeys = g_list_append (recipkeys, skey);
-    }
+	/* Add the default key if set and necessary */
+	settings = g_settings_new ("org.gnome.crypto.pgp");
+	if (g_settings_get_boolean (settings, "encrypt-to-self")) {
+		keyid = g_settings_get_string (settings, "default-key");
+		if (keyid && keyid[0]) {
+			skey = seahorse_context_find_object (NULL, g_quark_from_string (keyid),
+			                                     SEAHORSE_LOCATION_LOCAL);
+			if (SEAHORSE_IS_PGP_KEY (skey))
+				recipkeys = g_list_append (recipkeys, skey);
+		}
+		g_free (keyid);
+	}
+	g_object_unref (settings);
 
     /* Make keys into the right format for GPGME */
     recips = keylist_to_keys (recipkeys);
diff --git a/daemon/seahorse-set.c b/daemon/seahorse-set.c
index a6d325a..222599a 100644
--- a/daemon/seahorse-set.c
+++ b/daemon/seahorse-set.c
@@ -21,7 +21,6 @@
 
 #include "seahorse-set.h"
 #include "seahorse-marshal.h"
-#include "seahorse-gconf.h"
 
 enum {
     PROP_0,
diff --git a/daemon/seahorse-util.c b/daemon/seahorse-util.c
index 5989163..978df5f 100644
--- a/daemon/seahorse-util.c
+++ b/daemon/seahorse-util.c
@@ -22,7 +22,6 @@
 
 #include "config.h"
 
-#include "seahorse-gconf.h"
 #include "seahorse-object.h"
 #include "seahorse-pgp-module.h"
 #include "seahorse-util.h"
diff --git a/daemon/seahorse-widget.c b/daemon/seahorse-widget.c
index 8b40614..009cda8 100644
--- a/daemon/seahorse-widget.c
+++ b/daemon/seahorse-widget.c
@@ -27,7 +27,6 @@
 #include <glib/gi18n.h>
 
 #include "seahorse-widget.h"
-#include "seahorse-gconf.h"
 #include "seahorse-gtkstock.h"
 
 /**
@@ -67,10 +66,6 @@ static void     object_get_property (GObject                *object,
                                      GValue                 *value,
                                      GParamSpec             *pspec);
                                      
-static GObject* seahorse_widget_constructor (GType                  type, 
-                                             guint                  n_props, 
-                                             GObjectConstructParam* props);                    
-
 /* signal functions */
 G_MODULE_EXPORT void on_widget_closed   (GtkWidget             *widget,
                                               SeahorseWidget        *swidget);
@@ -130,7 +125,6 @@ class_init (SeahorseWidgetClass *klass)
 	parent_class = g_type_class_peek_parent (klass);
 	gobject_class = G_OBJECT_CLASS (klass);
 	
-	gobject_class->constructor = seahorse_widget_constructor;
 	gobject_class->dispose = object_dispose;
 	gobject_class->finalize = object_finalize;
 	gobject_class->set_property = object_set_property;
@@ -171,47 +165,6 @@ object_init (SeahorseWidget *swidget)
 	                        G_CALLBACK (context_destroyed), swidget);
 }
 
-/**
-* type: the #GType to construct
-* n_props: number of properties
-* props: properties
-*
-*
-*
-* Returns the initialised object
-**/
-static GObject*  
-seahorse_widget_constructor (GType type, guint n_props, GObjectConstructParam* props)
-{
-    SeahorseWidget *swidget;
-    GObject *obj;
-    
-    GtkWindow *window;
-    gint width, height;
-    gchar *widthkey, *heightkey;
-    
-    obj = G_OBJECT_CLASS (parent_class)->constructor (type, n_props, props);
-    swidget = SEAHORSE_WIDGET (obj);
-
-    /* Load window size for windows that aren't dialogs */
-    window = GTK_WINDOW (seahorse_widget_get_toplevel (swidget));
-    if (!GTK_IS_DIALOG (window)) {
-	    widthkey = g_strdup_printf ("%s%s%s", WINDOW_SIZE, swidget->name, "_width");
-	    width = seahorse_gconf_get_integer (widthkey);
-    
-	    heightkey = g_strdup_printf ("%s%s%s", WINDOW_SIZE, swidget->name, "_height");
-	    height = seahorse_gconf_get_integer (heightkey);
-
-	    if (width > 0 && height > 0)
-		    gtk_window_resize (window, width, height);
-
-	    g_free (widthkey);
-	    g_free (heightkey);
-    }
-    
-    return obj;
-}
-
 static void
 object_dispose (GObject *object)
 {
@@ -596,29 +549,6 @@ seahorse_widget_set_sensitive (SeahorseWidget *swidget, const char *identifier,
 void
 seahorse_widget_destroy (SeahorseWidget *swidget)
 {
-    GtkWidget *widget;
-    gchar *widthkey, *heightkey;
-    gint width, height;
-
-    g_return_if_fail (swidget != NULL && SEAHORSE_IS_WIDGET (swidget));
-    widget = seahorse_widget_get_toplevel (swidget);
-    
-    /* Don't save window size for dialogs */
-    if (!GTK_IS_DIALOG (widget)) {
-
-	    /* Save window size */
-	    gtk_window_get_size (GTK_WINDOW (widget), &width, &height);
-    
-	    widthkey = g_strdup_printf ("%s%s%s", WINDOW_SIZE, swidget->name, "_width");
-	    seahorse_gconf_set_integer (widthkey, width);
-    
-	    heightkey = g_strdup_printf ("%s%s%s", WINDOW_SIZE, swidget->name, "_height");
-	    seahorse_gconf_set_integer (heightkey, height);
-    
-	    g_free (widthkey);
-	    g_free (heightkey);
-    }
-    
     /* Destroy Widget */
     if (!swidget->destroying) {
         swidget->destroying = TRUE;
diff --git a/data/Makefile.am b/data/Makefile.am
index d6e2d44..51ad51c 100644
--- a/data/Makefile.am
+++ b/data/Makefile.am
@@ -1,22 +1,15 @@
- INTLTOOL_SCHEMAS_RULE@
 
-schemasdir = $(GCONF_SCHEMA_FILE_DIR)
-schemas_in_files = cryptui.schemas.in
-schemas_DATA = $(schemas_in_files:.schemas.in=.schemas)
+gsettings_SCHEMAS = \
+	org.gnome.seahorse.recipients.gschema.xml
 
-if GCONF_SCHEMAS_INSTALL
-install-data-local:
-	@GCONF_CONFIG_SOURCE=$(GCONF_SCHEMA_CONFIG_SOURCE) gconftool-2 \
-		--makefile-install-rule $(schemas_DATA) || \
-		(echo ;\
-		echo "*****************************************************"; \
-		echo "Installation of schemas failed, install them manually"; \
-		echo "*****************************************************";)
-	@true
-else
-install-data-local:
-endif
+ GSETTINGS_RULES@
 
-EXTRA_DIST = $(schemas_in_files)
+convert_DATA = \
+	org.gnome.seahorse.recipients.convert
 
-CLEANFILES = $(schemas_DATA)
+convertdir = \
+	$(datarootdir)/GConf/gsettings
+
+EXTRA_DIST = \
+	$(convert_DATA) \
+	$(gsettings_SCHEMAS)
\ No newline at end of file
diff --git a/data/org.gnome.seahorse.recipients.convert b/data/org.gnome.seahorse.recipients.convert
new file mode 100644
index 0000000..710d955
--- /dev/null
+++ b/data/org.gnome.seahorse.recipients.convert
@@ -0,0 +1,6 @@
+[org.gnome.seahorse.recipients]
+show-validity = /apps/seahorse/listing/show_validity
+show-expiry = /apps/seahorse/listing/show_expires
+show-trust = /apps/seahorse/listing/show_trust
+show-type = /apps/seahorse/listing/show_type
+sort-by = /apps/seahorse/listing/sort_by
\ No newline at end of file
diff --git a/data/org.gnome.seahorse.recipients.gschema.xml b/data/org.gnome.seahorse.recipients.gschema.xml
new file mode 100644
index 0000000..0a423f0
--- /dev/null
+++ b/data/org.gnome.seahorse.recipients.gschema.xml
@@ -0,0 +1,9 @@
+<schemalist>
+	<schema id="org.gnome.seahorse.recipients" path="/apps/seahorse/recipients/">
+		<key name="sort-by" type="s">
+			<default>'name'</default>
+			<summary>The column to sort the recipients keys by</summary>
+			<description>Specify the column to sort the key recipaients window by. Columns are: 'name', 'id'. Put a '-' in front of the column name to sort in descending order.</description>
+		</key>
+	</schema>
+</schemalist>
diff --git a/libcryptui/cryptui-key-chooser.c b/libcryptui/cryptui-key-chooser.c
index d98a51e..358e625 100644
--- a/libcryptui/cryptui-key-chooser.c
+++ b/libcryptui/cryptui-key-chooser.c
@@ -43,7 +43,6 @@ enum {
 
 struct _CryptUIKeyChooserPriv {
     guint                   mode;
-    guint                   enforce_prefs : 1;
     gboolean                initialized : 1;
     
     CryptUIKeyset           *ckset;
@@ -51,7 +50,8 @@ struct _CryptUIKeyChooserPriv {
     GtkTreeView             *keylist;
     GtkComboBox             *keycombo;
     GtkCheckButton          *signercheck;
-    
+    GSettings               *settings;
+
     GtkComboBox             *filtermode;
     GtkEntry                *filtertext;
 };
@@ -63,30 +63,6 @@ static guint signals[LAST_SIGNAL] = { 0 };
  * INTERNAL
  */
 
-static gchar* 
-get_keyset_value (CryptUIKeyset *keyset, const gchar *key)
-{
-    gchar *gconf, *value;
-    g_return_val_if_fail (keyset, NULL);
-    
-    gconf = g_strconcat (key, "_", cryptui_keyset_get_keytype (keyset), NULL);
-    value = _cryptui_gconf_get_string (gconf);
-    g_free (gconf);
-    
-    return value;
-}
-
-static void
-set_keyset_value (CryptUIKeyset *keyset, const gchar *key, const gchar *value)
-{
-    gchar *gconf;
-    g_return_if_fail (keyset);
-    
-    gconf = g_strconcat (key, "_", cryptui_keyset_get_keytype (keyset), NULL);
-    _cryptui_gconf_set_string (gconf, value ? value : "");
-    g_free (gconf);
-}
-
 static gboolean 
 recipients_filter (CryptUIKeyset *ckset, const gchar *key, gpointer user_data)
 {
@@ -131,30 +107,33 @@ recipients_changed (GtkWidget *widget, CryptUIKeyChooser *chooser)
 static void
 signer_changed (GtkWidget *widget, CryptUIKeyChooser *chooser)
 {
-    g_assert (chooser->priv->keycombo);
-    
-    if (chooser->priv->enforce_prefs) {
-        set_keyset_value (cryptui_key_combo_get_keyset (chooser->priv->keycombo), 
-                          SEAHORSE_LASTSIGNER_KEY, 
-                          cryptui_key_combo_get_key (chooser->priv->keycombo));
-    }
-    
-    g_signal_emit (chooser, signals[CHANGED], 0);
+	const gchar *signer;
+
+	g_assert (chooser->priv->keycombo);
+
+	if (chooser->priv->settings) {
+		signer = cryptui_key_combo_get_key (chooser->priv->keycombo);
+		g_settings_set_string (chooser->priv->settings, "last-signer",
+		                       signer ? signer : "");
+	}
+
+	g_signal_emit (chooser, signals[CHANGED], 0);
 }
 
 static void
 signer_toggled (GtkWidget *widget, CryptUIKeyChooser *chooser)
 {
-    g_assert (chooser->priv->signercheck);
-    
-    if (chooser->priv->enforce_prefs) {
-        set_keyset_value ((CryptUIKeyset *) g_object_get_data ((GObject*) (chooser->priv->signercheck), "ckset"), 
-                          SEAHORSE_LASTSIGNER_KEY, 
-                          (gchar*) g_object_get_data ((GObject*) (chooser->priv->signercheck), "key"));
-    }
-    
-    g_signal_emit (chooser, signals[CHANGED], 0);
-    
+	const gchar *signer;
+
+	g_assert (chooser->priv->signercheck);
+
+	if (chooser->priv->settings) {
+		signer = g_object_get_data ((GObject*) (chooser->priv->signercheck), "key");
+		g_settings_set_string (chooser->priv->settings, "last-signer",
+		                       signer ? signer : "");
+	}
+
+	g_signal_emit (chooser, signals[CHANGED], 0);
 }
 
 static void
@@ -304,15 +283,16 @@ cryptui_key_chooser_init (CryptUIKeyChooser *chooser)
 {
     /* init private vars */
     chooser->priv = g_new0 (CryptUIKeyChooserPriv, 1);
-    chooser->priv->enforce_prefs = TRUE;
 }
 
-static GObject*  
-cryptui_key_chooser_constructor (GType type, guint n_props, GObjectConstructParam* props)
+static void
+cryptui_key_chooser_constructed (GObject *obj)
 {
-    GObject *obj = G_OBJECT_CLASS (cryptui_key_chooser_parent_class)->constructor (type, n_props, props);
     CryptUIKeyChooser *chooser = CRYPTUI_KEY_CHOOSER (obj);
-    
+    gchar *value;
+
+    G_OBJECT_CLASS (cryptui_key_chooser_parent_class)->constructed (obj);
+
     /* Set the spacing for this box */
     gtk_box_set_spacing (GTK_BOX (obj), 6);
     gtk_container_set_border_width (GTK_CONTAINER (obj), 6);
@@ -326,11 +306,10 @@ cryptui_key_chooser_constructor (GType type, guint n_props, GObjectConstructPara
     if (chooser->priv->mode & CRYPTUI_KEY_CHOOSER_SIGNER) {
         construct_signer (chooser, GTK_BOX (obj));
         
-        if (chooser->priv->enforce_prefs && chooser->priv->keycombo) {
-            gchar *id = get_keyset_value (cryptui_key_combo_get_keyset (chooser->priv->keycombo), 
-                                          SEAHORSE_LASTSIGNER_KEY);
-            cryptui_key_combo_set_key (chooser->priv->keycombo, id);
-            g_free (id);
+        if (chooser->priv->settings && chooser->priv->keycombo) {
+            value = g_settings_get_string (chooser->priv->settings, "last-signer");
+            cryptui_key_combo_set_key (chooser->priv->keycombo, value);
+            g_free (value);
         }
     }
 
@@ -345,7 +324,6 @@ cryptui_key_chooser_constructor (GType type, guint n_props, GObjectConstructPara
         gtk_widget_grab_focus (GTK_WIDGET (chooser->priv->signercheck));
         
     chooser->priv->initialized = TRUE;
-    return obj;
 }
 
 /* dispose of all our internal references */
@@ -371,6 +349,7 @@ cryptui_key_chooser_finalize (GObject *gobject)
     CryptUIKeyChooser *chooser = CRYPTUI_KEY_CHOOSER (gobject);
     
     g_assert (chooser->priv->ckset == NULL);
+    g_clear_object (&chooser->priv->settings);
     g_free (chooser->priv);
     
     G_OBJECT_CLASS (cryptui_key_chooser_parent_class)->finalize (gobject);
@@ -394,9 +373,14 @@ cryptui_key_chooser_set_property (GObject *gobject, guint prop_id,
         break;
     
     case PROP_ENFORCE_PREFS:
-        chooser->priv->enforce_prefs = g_value_get_boolean (value);
+        if (g_value_get_boolean (value)) {
+            if (!chooser->priv->settings)
+                chooser->priv->settings = g_settings_new ("org.gnome.crypto.pgp");
+        } else {
+            g_clear_object (&chooser->priv->settings);
+        }
         break;
-    
+
     default:
         break;
     }
@@ -418,7 +402,7 @@ cryptui_key_chooser_get_property (GObject *gobject, guint prop_id,
         break;
     
     case PROP_ENFORCE_PREFS:
-        g_value_set_boolean (value, chooser->priv->enforce_prefs);
+        g_value_set_boolean (value, chooser->priv->settings != NULL);
         break;
     
     default:
@@ -434,7 +418,7 @@ cryptui_key_chooser_class_init (CryptUIKeyChooserClass *klass)
     cryptui_key_chooser_parent_class = g_type_class_peek_parent (klass);
     gclass = G_OBJECT_CLASS (klass);
 
-    gclass->constructor = cryptui_key_chooser_constructor;
+    gclass->constructed = cryptui_key_chooser_constructed;
     gclass->dispose = cryptui_key_chooser_dispose;
     gclass->finalize = cryptui_key_chooser_finalize;
     gclass->set_property = cryptui_key_chooser_set_property;
@@ -450,7 +434,7 @@ cryptui_key_chooser_class_init (CryptUIKeyChooserClass *klass)
     
     g_object_class_install_property (gclass, PROP_ENFORCE_PREFS,
         g_param_spec_boolean ("enforce-prefs", "Enforce User Preferences", "Enforce user preferences",
-                              TRUE, G_PARAM_READWRITE));
+                              TRUE, G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
     
     signals[CHANGED] = g_signal_new ("changed", CRYPTUI_TYPE_KEY_CHOOSER, 
                 G_SIGNAL_RUN_FIRST, G_STRUCT_OFFSET (CryptUIKeyChooserClass, changed),
@@ -493,7 +477,7 @@ cryptui_key_chooser_new (CryptUIKeyset *ckset, CryptUIKeyChooserMode mode)
 gboolean
 cryptui_key_chooser_get_enforce_prefs (CryptUIKeyChooser *chooser)
 {
-    return chooser->priv->enforce_prefs;
+    return chooser->priv->settings != NULL;
 }
 
 /**
@@ -511,7 +495,7 @@ void
 cryptui_key_chooser_set_enforce_prefs (CryptUIKeyChooser *chooser,
                                        gboolean enforce_prefs)
 {
-    chooser->priv->enforce_prefs = enforce_prefs;
+	g_object_set (chooser, "enforce-prefs", enforce_prefs, NULL);
 }
 
 /**
@@ -543,12 +527,15 @@ cryptui_key_chooser_get_recipients (CryptUIKeyChooser *chooser)
     CryptUIKeyset *keyset;
     GList *recipients;
     const gchar *key;
-    
+    gchar *value;
+
     g_return_val_if_fail (chooser->priv->keylist != NULL, NULL);
     recipients = cryptui_key_list_get_selected_keys (chooser->priv->keylist);
-    
-    if (!chooser->priv->enforce_prefs || 
-        !_cryptui_gconf_get_boolean (SEAHORSE_ENCRYPTSELF_KEY))
+
+    if (!chooser->priv->settings)
+        return recipients;
+
+    if (!g_settings_get_boolean (chooser->priv->settings, "encrypt-to-self"))
         return recipients;
 
     /* If encrypt to self, then add that key */
@@ -561,9 +548,10 @@ cryptui_key_chooser_get_recipients (CryptUIKeyChooser *chooser)
     
     /* Lookup the default key */
     if (key == NULL) {
-        gchar *gval = get_keyset_value (keyset, SEAHORSE_DEFAULT_KEY);
-        if (gval != NULL)
-            key = _cryptui_keyset_get_internal_keyid (keyset, gval);
+        value = g_settings_get_string (chooser->priv->settings, "default-key");
+        if (value != NULL && value[0] != '\0')
+            key = _cryptui_keyset_get_internal_keyid (keyset, value);
+        g_free (value);
     }
     
     /* Use first secret key */
@@ -583,7 +571,7 @@ cryptui_key_chooser_get_recipients (CryptUIKeyChooser *chooser)
         g_warning ("Encrypt to self is set, but no personal keys can be found");
     else
         recipients = g_list_prepend (recipients, (gpointer)key);
-    
+
     return recipients;
 }
 
diff --git a/libcryptui/cryptui-key-store.c b/libcryptui/cryptui-key-store.c
index 27bbe52..941837e 100644
--- a/libcryptui/cryptui-key-store.c
+++ b/libcryptui/cryptui-key-store.c
@@ -49,7 +49,8 @@ static const GType col_types[] = {
 
 struct _CryptUIKeyStorePriv {
     gboolean                    initialized;
-    
+    GSettings                   *settings;
+
     GHashTable                  *rows;
     GtkTreeModelFilter          *filter;
     GtkTreeStore                *store;
@@ -433,7 +434,7 @@ load_sort_order (CryptUIKeyStore *ckstore)
     const gchar *name;
 
     if (ckstore->priv->sortable)
-        sort = _cryptui_gconf_get_string (SEAHORSE_RECIPIENTS_SORT_KEY);
+        sort = g_settings_get_string (ckstore->priv->settings, "sort-by");
     
     name = sort ? sort : "";
     
@@ -481,7 +482,7 @@ sort_changed (GtkTreeSortable *sort, CryptUIKeyStore *ckstore)
     }
     
     x = g_strconcat (ord == GTK_SORT_DESCENDING ? "-" : "", name ? name : "", NULL);
-    _cryptui_gconf_set_string (SEAHORSE_RECIPIENTS_SORT_KEY, x);
+    g_settings_set_string (ckstore->priv->settings, "sort-by", x);
     g_free (x);
 }
 
@@ -494,7 +495,8 @@ cryptui_key_store_init (CryptUIKeyStore *ckstore)
 {
     /* init private vars */
     ckstore->priv = g_new0 (CryptUIKeyStorePriv, 1);
-    
+    ckstore->priv->settings = g_settings_new ("org.gnome.seahorse.recipients");
+
     /* Our key -> row ref mapping */
     ckstore->priv->rows = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, 
                                                  (GDestroyNotify)gtk_tree_row_reference_free);
@@ -566,7 +568,8 @@ cryptui_key_store_finalize (GObject *gobject)
     g_object_unref (ckstore->priv->store);
     g_object_unref (ckstore->priv->filter);
     g_hash_table_destroy (ckstore->priv->rows);
-     
+    g_object_unref (ckstore->priv->settings);
+
     /* Allocated in property setter */
     g_free (ckstore->priv->search_text); 
     g_free (ckstore->priv->none_option);
@@ -608,6 +611,7 @@ cryptui_key_store_set_property (GObject *gobject, guint prop_id,
     /* Sortable columns */
     case PROP_SORTABLE:
         ckstore->priv->sortable = g_value_get_boolean (value);
+        load_sort_order (ckstore);
         break;
     
     /* Display and use the check boxes */
@@ -653,7 +657,6 @@ cryptui_key_store_get_property (GObject *gobject, guint prop_id,
     
     case PROP_SORTABLE:
         g_value_set_boolean (value, ckstore->priv->sortable);
-        load_sort_order (ckstore);
         break;
     
     case PROP_USE_CHECKS:
diff --git a/libcryptui/cryptui-priv.h b/libcryptui/cryptui-priv.h
index 43118f5..54e323e 100644
--- a/libcryptui/cryptui-priv.h
+++ b/libcryptui/cryptui-priv.h
@@ -22,9 +22,6 @@
 #ifndef __CRYPTUI_PRIV_H__
 #define __CRYPTUI_PRIV_H__
 
-#include <gconf/gconf.h>
-#include <gconf/gconf-client.h>
-
 /* 
  * Used internally by libcryptui. 
  */
@@ -33,29 +30,9 @@
 #error "This header shouldn't be included outside of the libcryptui build."
 #endif
 
-#include <gconf/gconf.h>
-
 #include "cryptui.h"
 #include "cryptui-defines.h"
 
-/* cryptui.c ---------------------------------------------------------------- */
-
-gboolean        _cryptui_gconf_get_boolean          (const char *key);
-
-gchar*          _cryptui_gconf_get_string           (const char *key);
-
-void            _cryptui_gconf_set_string           (const char *key, const char *value);
-
-guint           _cryptui_gconf_notify               (const char *key, 
-                                                     GConfClientNotifyFunc notification_callback,
-                                                     gpointer callback_data);
-
-void            _cryptui_gconf_notify_lazy          (const char *key, 
-                                                     GConfClientNotifyFunc notification_callback,
-                                                     gpointer callback_data, gpointer lifetime);
-                                                     
-void            _cryptui_gconf_unnotify             (guint notification_id);
-
 /* cryptui-keyset.c --------------------------------------------------------- */
 
 const gchar*    _cryptui_keyset_get_internal_keyid  (CryptUIKeyset *ckset,
diff --git a/libcryptui/cryptui.c b/libcryptui/cryptui.c
index eb12f16..dd513f5 100644
--- a/libcryptui/cryptui.c
+++ b/libcryptui/cryptui.c
@@ -25,7 +25,6 @@
 #include <string.h>
 #include <stdlib.h>
 
-#include <gconf/gconf-client.h>
 #include <dbus/dbus-glib-bindings.h>
 
 #include "cryptui.h"
@@ -277,201 +276,3 @@ cryptui_need_to_get_keys ()
         g_spawn_async (NULL, argv, NULL, G_SPAWN_SEARCH_PATH, NULL, NULL, NULL, NULL);
     }
 }
-
-/* -----------------------------------------------------------------------------
- * GCONF HELPERS 
- */
-
-static GConfClient *global_gconf_client = NULL;
-
-static void
-global_client_free (void)
-{
-    if (global_gconf_client == NULL)
-        return;
-    
-    gconf_client_remove_dir (global_gconf_client, SEAHORSE_DESKTOP_KEYS, NULL);
-    g_object_unref (global_gconf_client);
-    global_gconf_client = NULL;
-}
-
-static gboolean
-handle_error (GError **error)
-{
-    g_return_val_if_fail (error != NULL, FALSE);
-
-    if (*error != NULL) {
-        g_warning ("GConf error:\n  %s", (*error)->message);
-        g_error_free (*error);
-        *error = NULL;
-        return TRUE;
-    }
-
-    return FALSE;
-}
-
-static GConfClient*
-get_global_client (void)
-{
-    GError *error = NULL;
-    
-    if (global_gconf_client != NULL)
-        return global_gconf_client;
-    
-    global_gconf_client = gconf_client_get_default ();
-    if (global_gconf_client) {
-        gconf_client_add_dir (global_gconf_client, SEAHORSE_DESKTOP_KEYS, 
-                                  GCONF_CLIENT_PRELOAD_NONE, &error);
-        handle_error (&error);
-    }
-
-    atexit (global_client_free);
-    return global_gconf_client;
-}
-
-/**
- * _cryptui_gconf_get_boolean:
- * @key: a gconf key/path
- *
- * A private library function that gets a boolean from a gconf key.
- *
- * Returns: The boolean stored at the key location or FALSE if an error
- *          occured.
- */
-gboolean
-_cryptui_gconf_get_boolean (const char *key)
-{
-    GConfClient *client = get_global_client ();
-    gboolean result;
-    GError *error = NULL;
-    
-    g_return_val_if_fail (key != NULL, FALSE);
-    g_return_val_if_fail (client != NULL, FALSE);
-    
-    result = gconf_client_get_bool (client, key, &error);
-    return handle_error (&error) ? FALSE : result;
-}
-
-/**
- * _cryptui_gconf_get_string:
- * @key: a gconf key/path
- *
- * A private library function that gets a string from a gconf key.
- *
- * Returns: The string stored at the key location or the null string if an error
- *          occured.
- */
-char *
-_cryptui_gconf_get_string (const char *key)
-{
-    char *result;
-    GConfClient *client;
-    GError *error = NULL;
-    
-    g_return_val_if_fail (key != NULL, NULL);
-    
-    client = get_global_client ();
-    g_return_val_if_fail (client != NULL, NULL);
-    
-    result = gconf_client_get_string (client, key, &error);
-    return handle_error (&error) ? g_strdup ("") : result;
-}
-
-/**
- * _cryptui_gconf_set_string:
- * @key: a gconf key/path
- * @string_value: a text string
- *
- * A private library function that sets a gconf key to the string given.
- */
-void
-_cryptui_gconf_set_string (const char *key, const char *string_value)
-{
-    GConfClient *client = get_global_client ();
-    GError *error = NULL;
-
-    g_return_if_fail (key != NULL);
-    g_return_if_fail (client != NULL);
-    
-    gconf_client_set_string (client, key, string_value, &error);
-    handle_error (&error);
-}
-
-/**
- * _cryptui_gconf_notify:
- * @key: a gconf key/path
- * @notification_callback: function to be called by the notification
- * @callback_data: data to be passed to the callback function
- *
- * A private library convenience function that creates a gconf notification
- * on a specified gconf key.
- *
- * Returns: the gconf notification id
- */
-guint
-_cryptui_gconf_notify (const char *key, GConfClientNotifyFunc notification_callback,
-                       gpointer callback_data)
-{
-    GConfClient *client = get_global_client ();
-    guint notification_id;
-    GError *error = NULL;
-    
-    g_return_val_if_fail (key != NULL, 0);
-    g_return_val_if_fail (notification_callback != NULL, 0);
-    g_return_val_if_fail (client != NULL, 0);
-    
-    notification_id = gconf_client_notify_add (client, key, notification_callback,
-                                               callback_data, NULL, &error);
-    return handle_error (&error) ? notification_id : 0;
-}
-
-static void
-internal_gconf_unnotify (gpointer data)
-{
-    guint notify_id = GPOINTER_TO_INT (data);
-    _cryptui_gconf_unnotify (notify_id);
-}
-
-/**
- * _cryptui_gconf_notify_lazy:
- * @key: a gconf key/path
- * @notification_callback: function to be called by the notification
- * @callback_data: data to be passed to the callback function
- * @lifetime: the object whose destruction will end the notification
- *
- * A private library convenience function that creates a gconf notification
- * on a specified gconf key and automatically removes the notification when an
- * object is destroyed.
- */
-void
-_cryptui_gconf_notify_lazy (const char *key, GConfClientNotifyFunc notification_callback,
-                            gpointer callback_data, gpointer lifetime)
-{
-    guint notification_id;
-    gchar *t;
-    
-    notification_id = _cryptui_gconf_notify (key, notification_callback, callback_data);
-    if (notification_id != 0) {
-        t = g_strdup_printf ("_cryutui-gconf-notify-lazy-%d", notification_id);
-        g_object_set_data_full (G_OBJECT (lifetime), t, 
-                GINT_TO_POINTER (notification_id), internal_gconf_unnotify);
-    }
-}
-
-/**
- * _crytpui_gconf_unnotify:
- * @notification_id: a current gconf notification id
- *
- * A private library function to remove a gconf notification.
- */
-void
-_cryptui_gconf_unnotify (guint notification_id)
-{
-    GConfClient *client = get_global_client ();
-    g_return_if_fail (client != NULL);
-
-    if (notification_id == 0)
-        return;
-
-    gconf_client_notify_remove (client, notification_id);
-}
diff --git a/reference/Makefile.am b/reference/Makefile.am
index 9d6e0fc..641db7c 100644
--- a/reference/Makefile.am
+++ b/reference/Makefile.am
@@ -1 +1 @@
-SUBDIRS = libcryptui
\ No newline at end of file
+SUBDIRS = libcryptui



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