[seahorse/refactor: 28/33] Make filtering work by text, personal, trusted and all.



commit eea1e460c0e5b858c5804850c348ce86893e56d1
Author: Stef Walter <stefw collabora co uk>
Date:   Fri Oct 14 09:25:56 2011 +0200

    Make filtering work by text, personal, trusted and all.

 data/org.gnome.seahorse.manager.gschema.xml |   15 +++--
 gkr/seahorse-gkr-item.c                     |    2 +-
 gkr/seahorse-gkr-keyring.c                  |    3 +-
 libseahorse/Makefile.am                     |    2 +-
 libseahorse/seahorse-key-manager-store.c    |   15 ++++--
 libseahorse/seahorse-key-manager-store.h    |    3 +
 libseahorse/seahorse-object.c               |   41 --------------
 libseahorse/seahorse-predicate.c            |   74 ++++++++++++++++++++++++++
 libseahorse/seahorse-predicate.h            |    7 +--
 libseahorse/seahorse-types.c                |   27 +++++++++-
 libseahorse/seahorse-types.h                |   12 +++--
 libseahorse/seahorse-viewer.c               |    1 -
 pgp/seahorse-gpgme-key.c                    |   13 +++--
 pgp/seahorse-keyserver-results.c            |    2 +
 pkcs11/seahorse-certificate.c               |   10 ++++
 src/seahorse-key-manager.c                  |   76 +++++++++++++++++++--------
 ssh/seahorse-ssh-key.c                      |   10 +++-
 17 files changed, 217 insertions(+), 96 deletions(-)
---
diff --git a/data/org.gnome.seahorse.manager.gschema.xml b/data/org.gnome.seahorse.manager.gschema.xml
index 77b2a1a..b6fa3f8 100644
--- a/data/org.gnome.seahorse.manager.gschema.xml
+++ b/data/org.gnome.seahorse.manager.gschema.xml
@@ -1,6 +1,6 @@
 <schemalist>
 	<schema id="org.gnome.seahorse.manager" path="/apps/seahorse/listing/">
-		<key name="show-sidebar" type="b">
+		<key name="sidebar-visible" type="b">
 			<default>false</default>
 			<summary>Show places sidebar</summary>
 			<description>Show places sidebar in seahorse.</description>
@@ -11,16 +11,19 @@
 			<description>Filter which items to show. If empty, show all items, if
 			'personal' show personal keys, if 'trusted' show trusted.</description>
 		</key>
-		<key name="sort-by" type="s">
-			<default>'name'</default>
-			<summary>The column to sort the seahorse keys by</summary>
-			<description>Specify the column to sort the seahorse key manager main window by. Columns are: 'name', 'id', 'validity', 'expires', 'trust', and 'type'. Put a '-' in front of the column name to sort in descending order.</description>
-		</key>
 		<key name="sidebar-width" type="i">
 			<default>148</default>
 			<summary>Width of the side pane</summary>
 			<description>The default width of the side pane.</description>
 		</key>
+
+		<!-- Unused, remove once stable -->
+
+		<key name="sort-by" type="s">
+			<default>'name'</default>
+			<summary>The column to sort the seahorse keys by</summary>
+			<description>Specify the column to sort the seahorse key manager main window by. Columns are: 'name', 'id', 'validity', 'expires', 'trust', and 'type'. Put a '-' in front of the column name to sort in descending order.</description>
+		</key>
 		<key name="show-validity" type="b">
 			<default>false</default>
 			<summary>Show validity column</summary>
diff --git a/gkr/seahorse-gkr-item.c b/gkr/seahorse-gkr-item.c
index 11b04cf..b6ca1a8 100644
--- a/gkr/seahorse-gkr-item.c
+++ b/gkr/seahorse-gkr-item.c
@@ -711,7 +711,7 @@ seahorse_gkr_item_realize (SeahorseGkrItem *self)
 	              "label", info->label,
 	              "icon", icon,
 	              "markup", markup,
-	              "flags", SEAHORSE_FLAG_DELETABLE,
+	              "flags", SEAHORSE_FLAG_DELETABLE | SEAHORSE_FLAG_PERSONAL,
 	              NULL);
 	g_object_unref (icon);
 	g_free (markup);
diff --git a/gkr/seahorse-gkr-keyring.c b/gkr/seahorse-gkr-keyring.c
index 0dc116a..8a83ba4 100644
--- a/gkr/seahorse-gkr-keyring.c
+++ b/gkr/seahorse-gkr-keyring.c
@@ -135,7 +135,7 @@ seahorse_gkr_keyring_realize (SeahorseGkrKeyring *self)
 	              "label", name,
 	              "nickname", self->pv->keyring_name,
 	              "identifier", "",
-	              "flags", SEAHORSE_FLAG_DELETABLE,
+	              "flags", SEAHORSE_FLAG_DELETABLE | SEAHORSE_FLAG_PERSONAL,
 	              "icon", icon,
 	              "usage", SEAHORSE_USAGE_OTHER,
 	              NULL);
@@ -350,7 +350,6 @@ seahorse_gkr_keyring_constructed (GObject *obj)
 	G_OBJECT_CLASS (seahorse_gkr_keyring_parent_class)->constructed (obj);
 
 	g_return_if_fail (self->pv->keyring_name);
-	g_object_set (self, "usage", SEAHORSE_USAGE_NONE, NULL);
 }
 
 static void
diff --git a/libseahorse/Makefile.am b/libseahorse/Makefile.am
index 0909c3b..b9ae7e1 100644
--- a/libseahorse/Makefile.am
+++ b/libseahorse/Makefile.am
@@ -42,7 +42,7 @@ libseahorse_la_SOURCES = \
 	seahorse-object-model.c seahorse-object-model.h \
 	seahorse-object-widget.c seahorse-object-widget.h \
 	seahorse-passphrase.c seahorse-passphrase.h \
-	seahorse-predicate.h \
+	seahorse-predicate.c seahorse-predicate.h \
 	seahorse-prefs.c seahorse-prefs.h \
 	seahorse-preferences.c seahorse-preferences.h \
 	seahorse-progress.c seahorse-progress.h \
diff --git a/libseahorse/seahorse-key-manager-store.c b/libseahorse/seahorse-key-manager-store.c
index a141dc2..b2b2677 100644
--- a/libseahorse/seahorse-key-manager-store.c
+++ b/libseahorse/seahorse-key-manager-store.c
@@ -168,14 +168,20 @@ on_filter_visible (GObject *obj,
 	return ret;
 }
 
+void
+seahorse_key_manager_store_refilter (SeahorseKeyManagerStore* self)
+{
+	GcrCollection *collection = gcr_collection_model_get_collection (GCR_COLLECTION_MODEL (self));
+	seahorse_collection_refresh (SEAHORSE_COLLECTION (collection));
+}
+
 /* Refilter the tree */
 static gboolean
 refilter_now (gpointer user_data)
 {
 	SeahorseKeyManagerStore* self = SEAHORSE_KEY_MANAGER_STORE (user_data);
-	GcrCollection *collection = gcr_collection_model_get_collection (GCR_COLLECTION_MODEL (self));
-	seahorse_collection_refresh (SEAHORSE_COLLECTION (collection));
 	self->priv->filter_stag = 0;
+	seahorse_key_manager_store_refilter (self);
 	return FALSE;
 }
 
@@ -622,18 +628,17 @@ seahorse_key_manager_store_class_init (SeahorseKeyManagerStoreClass *klass)
 SeahorseKeyManagerStore*
 seahorse_key_manager_store_new (GcrCollection *collection,
                                 GtkTreeView *view,
+                                SeahorsePredicate *pred,
                                 GSettings *settings)
 {
 	SeahorseKeyManagerStore *self;
 	GtkTreeViewColumn *col;
-	SeahorsePredicate *pred;
 	SeahorseCollection *filtered;
 	GtkCellRenderer *renderer;
 	gchar *sort_by;
 	guint last;
 
-	pred = g_new0 (SeahorsePredicate, 1);
-	filtered = seahorse_collection_new_for_predicate (collection, pred, g_free);
+	filtered = seahorse_collection_new_for_predicate (collection, pred, NULL);
 	pred->custom = on_filter_visible;
 
 	self = g_object_new (SEAHORSE_TYPE_KEY_MANAGER_STORE,
diff --git a/libseahorse/seahorse-key-manager-store.h b/libseahorse/seahorse-key-manager-store.h
index 610189f..2a7ca5d 100644
--- a/libseahorse/seahorse-key-manager-store.h
+++ b/libseahorse/seahorse-key-manager-store.h
@@ -60,6 +60,7 @@ GType                      seahorse_key_manager_store_get_type               (vo
 
 SeahorseKeyManagerStore*   seahorse_key_manager_store_new                    (GcrCollection *collection,
                                                                               GtkTreeView *view,
+                                                                              SeahorsePredicate *pred,
                                                                               GSettings *settings);
 
 GObject *                  seahorse_key_manager_store_get_object_from_path   (GtkTreeView *view,
@@ -74,4 +75,6 @@ GList*                     seahorse_key_manager_store_get_selected_objects   (Gt
 
 GObject *                  seahorse_key_manager_store_get_selected_object    (GtkTreeView *view);
 
+void                       seahorse_key_manager_store_refilter               (SeahorseKeyManagerStore* self);
+
 #endif /* __SEAHORSE_KEY_MANAGER_STORE_H__ */
diff --git a/libseahorse/seahorse-object.c b/libseahorse/seahorse-object.c
index 4dc84cf..794d9cb 100644
--- a/libseahorse/seahorse-object.c
+++ b/libseahorse/seahorse-object.c
@@ -532,44 +532,3 @@ seahorse_object_get_flags (SeahorseObject *self)
 	g_return_val_if_fail (SEAHORSE_IS_OBJECT (self), 0);
 	return self->pv->flags;	
 }
-
-/**
- * seahorse_predicate_match:
- * @self: the object to test
- * @obj: The predicate to match
- *
- * matches a seahorse object and a predicate
- *
- * Returns: FALSE if predicate does not match the #SeahorseObject, TRUE else
- */
-gboolean
-seahorse_predicate_match (SeahorsePredicate *self,
-                          GObject* obj)
-{
-	SeahorseObjectPrivate *pv;
-
-	g_return_val_if_fail (G_IS_OBJECT (obj), FALSE);
-
-	/* Check all the fields */
-	if (self->type != 0 && !G_TYPE_CHECK_INSTANCE_TYPE (obj, self->type))
-		return FALSE;
-
-	if (SEAHORSE_IS_OBJECT (obj)) {
-		g_return_val_if_fail (SEAHORSE_IS_OBJECT (obj), FALSE);
-		pv = SEAHORSE_OBJECT (obj)->pv;
-		if (self->usage != 0 && self->usage != pv->usage)
-			return FALSE;
-		if (self->flags != 0 && (self->flags & pv->flags) == 0)
-			return FALSE;
-		if (self->nflags != 0 && (self->nflags & pv->flags) != 0)
-			return FALSE;
-		if (self->source != NULL && self->source != pv->source)
-			return FALSE;
-	}
-
-	/* And any custom stuff */
-	if (self->custom != NULL && !self->custom (obj, self->custom_target))
-		return FALSE;
-
-	return TRUE;
-}
diff --git a/libseahorse/seahorse-predicate.c b/libseahorse/seahorse-predicate.c
new file mode 100644
index 0000000..ad102fd
--- /dev/null
+++ b/libseahorse/seahorse-predicate.c
@@ -0,0 +1,74 @@
+/*
+ * Seahorse
+ *
+ * Copyright (C) 2008 Stefan Walter
+ * Copyright (C) 2011 Collabora Ltd.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+ * 02111-1307, USA.
+ */
+
+#include "config.h"
+
+#include "seahorse-object.h"
+#include "seahorse-predicate.h"
+#include "seahorse-source.h"
+
+#include "string.h"
+
+#include <glib/gi18n.h>
+
+/**
+ * seahorse_predicate_match:
+ * @self: the object to test
+ * @obj: The predicate to match
+ *
+ * matches a seahorse object and a predicate
+ *
+ * Returns: FALSE if predicate does not match the #SeahorseObject, TRUE else
+ */
+gboolean
+seahorse_predicate_match (SeahorsePredicate *pred,
+                          GObject* obj)
+{
+
+	g_return_val_if_fail (G_IS_OBJECT (obj), FALSE);
+
+	/* Check all the fields */
+	if (pred->type != 0 && !G_TYPE_CHECK_INSTANCE_TYPE (obj, pred->type))
+		return FALSE;
+
+	if (pred->usage != 0) {
+		SeahorseUsage usage = 0;
+		g_object_get (obj, "usage", &usage, NULL);
+		if (pred->usage != usage)
+			return FALSE;
+	}
+
+	if (pred->flags != 0 || pred->nflags != 0) {
+		SeahorseFlags flags = 0;
+		g_object_get (obj, "flags", &flags, NULL);
+		if (pred->flags != 0 && (pred->flags & flags) == 0)
+			return FALSE;
+		if (pred->nflags != 0 && (pred->nflags & flags) != 0)
+			return FALSE;
+	}
+
+	/* And any custom stuff */
+	if (pred->custom != NULL && !pred->custom (obj, pred->custom_target))
+		return FALSE;
+
+	return TRUE;
+}
diff --git a/libseahorse/seahorse-predicate.h b/libseahorse/seahorse-predicate.h
index 3fa78bb..1c8be77 100644
--- a/libseahorse/seahorse-predicate.h
+++ b/libseahorse/seahorse-predicate.h
@@ -37,14 +37,13 @@ typedef struct _SeahorsePredicate SeahorsePredicate;
 struct _SeahorsePredicate {
 	GType type;
 	SeahorseUsage usage;
-	guint flags;
-	guint nflags;
-	SeahorseSource *source;
+	SeahorseFlags flags;
+	SeahorseFlags nflags;
 	SeahorsePredicateFunc custom;
 	gpointer custom_target;
 };
 
-gboolean           seahorse_predicate_match         (SeahorsePredicate *self,
+gboolean           seahorse_predicate_match         (SeahorsePredicate *pred,
                                                      GObject *obj);
 
 #endif /* __SEAHORSE_PREDICATE_H__ */
diff --git a/libseahorse/seahorse-types.c b/libseahorse/seahorse-types.c
index 4f412d2..6475359 100644
--- a/libseahorse/seahorse-types.c
+++ b/libseahorse/seahorse-types.c
@@ -23,7 +23,8 @@
 
 #include "seahorse-types.h"
 
-GType seahorse_usage_get_type (void) 
+GType
+seahorse_usage_get_type (void)
 {
 	static GType seahorse_usage_type_id = 0;
 	if (!seahorse_usage_type_id) {
@@ -41,3 +42,27 @@ GType seahorse_usage_get_type (void)
 	}
 	return seahorse_usage_type_id;
 }
+
+GType
+seahorse_flags_get_type (void)
+{
+	static GType etype = 0;
+	if (G_UNLIKELY(etype == 0)) {
+		static const GFlagsValue values[] = {
+			{ SEAHORSE_FLAG_NONE, "SEAHORSE_FLAG_NONE", "none" },
+			{ SEAHORSE_FLAG_IS_VALID, "SEAHORSE_FLAG_IS_VALID", "is-valid" },
+			{ SEAHORSE_FLAG_CAN_ENCRYPT, "SEAHORSE_FLAG_CAN_ENCRYPT", "can-encrypt" },
+			{ SEAHORSE_FLAG_CAN_SIGN, "SEAHORSE_FLAG_CAN_SIGN", "can-sign" },
+			{ SEAHORSE_FLAG_EXPIRED, "SEAHORSE_FLAG_EXPIRED", "expired" },
+			{ SEAHORSE_FLAG_REVOKED, "SEAHORSE_FLAG_REVOKED", "revoked" },
+			{ SEAHORSE_FLAG_DISABLED, "SEAHORSE_FLAG_DISABLED", "disabled" },
+			{ SEAHORSE_FLAG_TRUSTED, "SEAHORSE_FLAG_TRUSTED", "trusted" },
+			{ SEAHORSE_FLAG_PERSONAL, "SEAHORSE_FLAG_PERSONAL", "personal" },
+			{ SEAHORSE_FLAG_EXPORTABLE, "SEAHORSE_FLAG_EXPORTABLE", "exportable" },
+			{ SEAHORSE_FLAG_DELETABLE, "SEAHORSE_FLAG_DELETABLE", "deletable" },
+			{ 0, NULL, NULL }
+		};
+		etype = g_flags_register_static (g_intern_static_string ("SeahorseFlags"), values);
+	}
+	return etype;
+}
diff --git a/libseahorse/seahorse-types.h b/libseahorse/seahorse-types.h
index dece1ab..f8ce4be 100644
--- a/libseahorse/seahorse-types.h
+++ b/libseahorse/seahorse-types.h
@@ -30,8 +30,6 @@ G_BEGIN_DECLS
 
 #define SEAHORSE_TYPE_USAGE (seahorse_usage_get_type ())
 
-GType seahorse_location_get_type (void);
-
 /* Again, never change these values */
 typedef enum  {
 	SEAHORSE_USAGE_NONE = 0,
@@ -43,9 +41,12 @@ typedef enum  {
 	SEAHORSE_USAGE_OTHER = 10
 } SeahorseUsage;
 
-GType seahorse_usage_get_type (void);
+GType seahorse_usage_get_type (void) G_GNUC_CONST;
+
+#define SEAHORSE_TYPE_FLAGS (seahorse_flags_get_type ())
 
 typedef enum {
+	SEAHORSE_FLAG_NONE = 0,
 	SEAHORSE_FLAG_IS_VALID =    0x00000001,
 	SEAHORSE_FLAG_CAN_ENCRYPT = 0x00000002,
 	SEAHORSE_FLAG_CAN_SIGN =    0x00000004,
@@ -53,11 +54,12 @@ typedef enum {
 	SEAHORSE_FLAG_REVOKED =     0x00000200,
 	SEAHORSE_FLAG_DISABLED =    0x00000400,
 	SEAHORSE_FLAG_TRUSTED =     0x00001000,
+	SEAHORSE_FLAG_PERSONAL =    0x00002000,
 	SEAHORSE_FLAG_EXPORTABLE =  0x00100000,
 	SEAHORSE_FLAG_DELETABLE =   0x10000000
-} SeahorseKeyFlags;
+} SeahorseFlags;
 
-#define SEAHORSE_TAG_INVALID               0
+GType seahorse_flags_get_type (void) G_GNUC_CONST;
 
 G_END_DECLS
 
diff --git a/libseahorse/seahorse-viewer.c b/libseahorse/seahorse-viewer.c
index d49e9bd..d413323 100644
--- a/libseahorse/seahorse-viewer.c
+++ b/libseahorse/seahorse-viewer.c
@@ -416,7 +416,6 @@ on_key_delete (GtkAction* action, SeahorseViewer* self)
 	for (l = objects; l; l = g_list_next (l)) {
 		GObject* object = l->data;
 
-		/* TODO: Need to rework this for PKCS#11 keys */
 		if (SEAHORSE_IS_OBJECT (object) &&
 		    seahorse_object_get_usage (SEAHORSE_OBJECT (object)) == SEAHORSE_USAGE_PRIVATE_KEY) {
 			gchar* prompt = g_strdup_printf (_("%s is a private key. Are you sure you want to proceed?"),
diff --git a/pgp/seahorse-gpgme-key.c b/pgp/seahorse-gpgme-key.c
index 01a255a..81c62a2 100644
--- a/pgp/seahorse-gpgme-key.c
+++ b/pgp/seahorse-gpgme-key.c
@@ -339,15 +339,18 @@ seahorse_gpgme_key_realize (SeahorseGpgmeKey *self)
 	    !self->pv->pubkey->expired)
 		flags |= SEAHORSE_FLAG_TRUSTED;
 
-	g_object_set (self, "flags", flags, NULL);
-
 	/* The type */
-	if (self->pv->seckey)
+	if (self->pv->seckey) {
 		usage = SEAHORSE_USAGE_PRIVATE_KEY;
-	else
+		flags |= SEAHORSE_FLAG_PERSONAL;
+	} else {
 		usage = SEAHORSE_USAGE_PUBLIC_KEY;
+	}
 
-	g_object_set (self, "usage", usage, NULL);
+	g_object_set (self,
+	              "usage", usage,
+	              "flags", flags,
+	              NULL);
 
 	seahorse_pgp_key_realize (SEAHORSE_PGP_KEY (self));
 }
diff --git a/pgp/seahorse-keyserver-results.c b/pgp/seahorse-keyserver-results.c
index 8df16c9..a9800ff 100644
--- a/pgp/seahorse-keyserver-results.c
+++ b/pgp/seahorse-keyserver-results.c
@@ -50,6 +50,7 @@ enum {
 
 struct _SeahorseKeyserverResultsPrivate {
 	char *search_string;
+	SeahorsePredicate pred;
 	GtkTreeView *view;
 	GcrSimpleCollection *collection;
 	GtkActionGroup *import_actions;
@@ -364,6 +365,7 @@ seahorse_keyserver_results_constructor (GType type, guint n_props, GObjectConstr
 
 	self->pv->store = seahorse_key_manager_store_new (GCR_COLLECTION (self->pv->collection),
 	                                                  self->pv->view,
+	                                                  &self->pv->pred,
 	                                                  self->pv->settings);
 	on_view_selection_changed (selection, self);
 
diff --git a/pkcs11/seahorse-certificate.c b/pkcs11/seahorse-certificate.c
index 5715b54..db151bb 100644
--- a/pkcs11/seahorse-certificate.c
+++ b/pkcs11/seahorse-certificate.c
@@ -26,6 +26,7 @@
 #include "seahorse-pkcs11-helpers.h"
 #include "seahorse-pkcs11.h"
 #include "seahorse-token.h"
+#include "seahorse-types.h"
 
 #include "seahorse-util.h"
 #include "seahorse-validity.h"
@@ -46,6 +47,7 @@ enum {
 	PROP_0,
 	PROP_SOURCE,
 	PROP_ATTRIBUTES,
+	PROP_FLAGS,
 };
 
 struct _SeahorseCertificatePrivate {
@@ -110,6 +112,10 @@ seahorse_certificate_get_property (GObject *obj,
 	case PROP_ATTRIBUTES:
 		g_value_set_boxed (value, self->pv->attributes);
 		break;
+	case PROP_FLAGS:
+		g_value_set_flags (value, SEAHORSE_FLAG_PERSONAL |
+		                          SEAHORSE_FLAG_EXPORTABLE);
+		break;
 	default:
 		gcr_certificate_mixin_get_property (obj, prop_id, value, pspec);
 		break;
@@ -164,6 +170,10 @@ seahorse_certificate_class_init (SeahorseCertificateClass *klass)
 	         g_param_spec_object ("source", "source", "source", SEAHORSE_TYPE_TOKEN,
 	                              G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_READABLE));
 
+	g_object_class_install_property (gobject_class, PROP_FLAGS,
+	         g_param_spec_flags ("flags", "flags", "flags", SEAHORSE_TYPE_FLAGS, SEAHORSE_FLAG_NONE,
+	                              G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_READABLE));
+
 	g_object_class_override_property (gobject_class, PROP_ATTRIBUTES, "attributes");
 
 	gcr_certificate_mixin_class_init (gobject_class);
diff --git a/src/seahorse-key-manager.c b/src/seahorse-key-manager.c
index f7e3f2f..bf639ea 100644
--- a/src/seahorse-key-manager.c
+++ b/src/seahorse-key-manager.c
@@ -70,6 +70,7 @@ enum {
 struct _SeahorseKeyManagerPrivate {
 	GtkActionGroup* view_actions;
 	GtkEntry* filter_entry;
+	SeahorsePredicate pred;
 
 	GtkTreeView* view;
 	GcrCollection *collection; /* owned by the sidebar */
@@ -363,30 +364,55 @@ on_delete_event (GtkWidget* widget, GdkEvent* event, SeahorseKeyManager* self)
 }
 
 static void
-on_manager_settings_changed (GSettings *settings,
-                             const gchar *key,
-                             gpointer user_data)
+on_view_show_changed (GtkRadioAction *action,
+                      GtkRadioAction *current,
+                      gpointer user_data)
 {
 	SeahorseKeyManager *self = SEAHORSE_KEY_MANAGER (user_data);
-	GtkAction* action;
-	gchar *value;
+	const gchar *value;
 	gint radio;
 
-	if (g_str_equal (key, "item-filter")) {
-		action = gtk_action_group_get_action (self->pv->view_actions, "view-any");
-		value = g_settings_get_string (settings, key);
-		if (value == NULL || g_str_equal (value, ""))
-			radio = SHOW_ANY;
-		else if (g_str_equal (value, "personal"))
-			radio = SHOW_PERSONAL;
-		else if (g_str_equal (value, "trusted"))
-			radio = SHOW_TRUSTED;
-		else
-			action = NULL;
-		if (action != NULL)
-			gtk_radio_action_set_current_value (GTK_RADIO_ACTION (action), radio);
-		g_free (value);
+	radio = gtk_radio_action_get_current_value (action);
+	switch (radio) {
+	case SHOW_PERSONAL:
+		self->pv->pred.flags = SEAHORSE_FLAG_PERSONAL;
+		value = "personal";
+		break;
+	case SHOW_TRUSTED:
+		self->pv->pred.flags = SEAHORSE_FLAG_TRUSTED;
+		value = "trusted";
+		break;
+	case SHOW_ANY:
+		self->pv->pred.flags = 0;
+		value = "";
+		break;
 	}
+
+	seahorse_key_manager_store_refilter (self->pv->store);
+	g_settings_set_string (self->pv->settings, "item-filter", value);
+}
+
+static void
+on_item_filter_changed (GSettings *settings,
+                        const gchar *key,
+                        gpointer user_data)
+{
+	GtkAction* action = GTK_ACTION (user_data);
+	gchar *value;
+	gint radio;
+
+	value = g_settings_get_string (settings, key);
+	if (value == NULL || g_str_equal (value, ""))
+		radio = SHOW_ANY;
+	else if (g_str_equal (value, "personal"))
+		radio = SHOW_PERSONAL;
+	else if (g_str_equal (value, "trusted"))
+		radio = SHOW_TRUSTED;
+	else
+		action = NULL;
+	if (action != NULL)
+		gtk_radio_action_set_current_value (GTK_RADIO_ACTION (action), radio);
+	g_free (value);
 }
 
 static const GtkActionEntry GENERAL_ACTIONS[] = {
@@ -507,7 +533,7 @@ setup_sidebar (SeahorseKeyManager *self)
 	action = gtk_action_group_get_action (actions, "view-places");
 	g_object_bind_property (action, "active", area, "visible", G_BINDING_DEFAULT);
 	g_object_bind_property (action, "active", sidebar, "combined", G_BINDING_INVERT_BOOLEAN);
-	g_settings_bind (self->pv->settings, "show-sidebar", action, "active", G_BINDING_BIDIRECTIONAL);
+	g_settings_bind (self->pv->settings, "sidebar-visible", action, "active", G_BINDING_BIDIRECTIONAL);
 	seahorse_viewer_include_actions (SEAHORSE_VIEWER (self), actions);
 	g_object_unref (actions);
 
@@ -522,6 +548,7 @@ seahorse_key_manager_constructed (GObject *object)
 	GtkTargetList* targets;
 	GtkTreeSelection *selection;
 	GtkWidget* widget;
+	GtkAction *action;
 
 	G_OBJECT_CLASS (seahorse_key_manager_parent_class)->constructed (object);
 
@@ -537,12 +564,14 @@ seahorse_key_manager_constructed (GObject *object)
 	self->pv->view_actions = gtk_action_group_new ("view");
 	gtk_action_group_set_translation_domain (self->pv->view_actions, GETTEXT_PACKAGE);
 	gtk_action_group_add_radio_actions (self->pv->view_actions, VIEW_RADIO_ACTIONS,
-	                                    G_N_ELEMENTS (VIEW_RADIO_ACTIONS),
-	                                    SHOW_PERSONAL, NULL, NULL);
+	                                    G_N_ELEMENTS (VIEW_RADIO_ACTIONS), SHOW_PERSONAL,
+	                                    G_CALLBACK (on_view_show_changed), self);
+	action = gtk_action_group_get_action (self->pv->view_actions, "view-personal");
 	seahorse_viewer_include_actions (SEAHORSE_VIEWER (self), self->pv->view_actions);
 
 	/* Notify us when settings change */
-	g_signal_connect_object (self->pv->settings, "changed", G_CALLBACK (on_manager_settings_changed), self, 0);
+	g_signal_connect_object (self->pv->settings, "changed",
+	                         G_CALLBACK (on_item_filter_changed), action, 0);
 
 	/* close event */
 	g_signal_connect_object (seahorse_widget_get_toplevel (SEAHORSE_WIDGET (self)), 
@@ -635,6 +664,7 @@ seahorse_key_manager_constructed (GObject *object)
 	/* Add new key store and associate it */
 	self->pv->store = seahorse_key_manager_store_new (self->pv->collection,
 	                                                  self->pv->view,
+	                                                  &self->pv->pred,
 	                                                  self->pv->settings);
 
 	/* Set focus to the current key list */
diff --git a/ssh/seahorse-ssh-key.c b/ssh/seahorse-ssh-key.c
index 5121f00..1d2fb96 100644
--- a/ssh/seahorse-ssh-key.c
+++ b/ssh/seahorse-ssh-key.c
@@ -71,6 +71,7 @@ changed_key (SeahorseSSHKey *self)
 {
 	SeahorseObject *obj = SEAHORSE_OBJECT (self);
 	SeahorseUsage usage;
+	SeahorseFlags flags;
 	const gchar *display = NULL;
 	gchar *identifier;
 	gchar *simple = NULL;
@@ -109,10 +110,14 @@ changed_key (SeahorseSSHKey *self)
 		return;
 	} 
 
+	flags = SEAHORSE_FLAG_EXPORTABLE | SEAHORSE_FLAG_DELETABLE;
+
 	if (self->keydata->privfile) {
 		usage = SEAHORSE_USAGE_PRIVATE_KEY;
+		flags |= SEAHORSE_FLAG_PERSONAL | SEAHORSE_FLAG_TRUSTED;
 		icon = g_themed_icon_new (GCR_ICON_KEY_PAIR);
 	} else {
+		flags = 0;
 		usage = SEAHORSE_USAGE_PUBLIC_KEY;
 		icon = g_themed_icon_new (GCR_ICON_KEY);
 	}
@@ -127,6 +132,9 @@ changed_key (SeahorseSSHKey *self)
 
 	identifier = seahorse_ssh_key_calc_identifier (self->keydata->fingerprint);
 
+	if (self->keydata->authorized)
+		flags |= SEAHORSE_FLAG_TRUSTED;
+
 	g_object_set (obj,
 	              "markup", markup,
 	              "label", display,
@@ -134,7 +142,7 @@ changed_key (SeahorseSSHKey *self)
 	              "usage", usage,
 	              "nickname", simple,
 	              "identifier", identifier,
-	              "flags", (self->keydata->authorized ? SEAHORSE_FLAG_TRUSTED : 0) | SEAHORSE_FLAG_EXPORTABLE | SEAHORSE_FLAG_DELETABLE,
+	              "flags", flags,
 	              NULL);
 	g_object_unref (icon);
 	g_free (identifier);



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