[seahorse] Fix issues filtering on personal, trusted, and any items



commit 721e4d33294d7e77df5014348b8989c5cfd40959
Author: Stef Walter <stefw collabora co uk>
Date:   Tue Nov 29 13:45:03 2011 +0100

    Fix issues filtering on personal, trusted, and any items

 pkcs11/seahorse-certificate.c |   51 +++++++++++++++++++++++++++---
 src/seahorse-key-manager.c    |   68 ++++++++++++++++++++++++-----------------
 2 files changed, 86 insertions(+), 33 deletions(-)
---
diff --git a/pkcs11/seahorse-certificate.c b/pkcs11/seahorse-certificate.c
index a10b6ed..00091aa 100644
--- a/pkcs11/seahorse-certificate.c
+++ b/pkcs11/seahorse-certificate.c
@@ -44,7 +44,8 @@ static const gulong REQUIRED_ATTRS[] = {
 	CKA_VALUE,
 	CKA_ID,
 	CKA_LABEL,
-	CKA_CLASS
+	CKA_CLASS,
+	CKA_CERTIFICATE_CATEGORY
 };
 
 enum {
@@ -66,6 +67,7 @@ struct _SeahorseCertificatePrivate {
 	GtkActionGroup *actions;
 	SeahorsePrivateKey *private_key;
 	GIcon *icon;
+	guint flags;
 };
 
 static void   seahorse_certificate_certificate_iface           (GcrCertificateIface *iface);
@@ -108,6 +110,7 @@ seahorse_certificate_init (SeahorseCertificate *self)
 	self->pv = (G_TYPE_INSTANCE_GET_PRIVATE (self, SEAHORSE_TYPE_CERTIFICATE, SeahorseCertificatePrivate));
 	self->pv->actions = seahorse_pkcs11_object_actions_instance ();
 	self->pv->value = NULL;
+	self->pv->flags = G_MAXUINT;
 }
 
 static void
@@ -146,6 +149,39 @@ seahorse_certificate_finalize (GObject *obj)
 	G_OBJECT_CLASS (seahorse_certificate_parent_class)->finalize (obj);
 }
 
+static guint
+calc_is_personal_and_trusted (SeahorseCertificate *self)
+{
+	gulong category = 0;
+	gboolean is_ca;
+
+	/* If a matching private key, then this is personal*/
+	if (self->pv->private_key)
+		return SEAHORSE_FLAG_PERSONAL | SEAHORSE_FLAG_TRUSTED;
+
+	if (gck_attributes_find_ulong (self->pv->attributes, CKA_CERTIFICATE_CATEGORY, &category)) {
+		if (category == 2)
+			return 0;
+		else if (category == 1)
+			return SEAHORSE_FLAG_PERSONAL;
+	}
+
+	if (gcr_certificate_get_basic_constraints (GCR_CERTIFICATE (self), &is_ca, NULL))
+		return is_ca ? 0 : SEAHORSE_FLAG_PERSONAL;
+
+	return SEAHORSE_FLAG_PERSONAL;
+}
+
+static void
+ensure_flags (SeahorseCertificate *self)
+{
+	if (self->pv->flags != G_MAXUINT)
+		return;
+
+	self->pv->flags = SEAHORSE_FLAG_EXPORTABLE |
+	                  calc_is_personal_and_trusted (self);
+}
+
 static void
 seahorse_certificate_get_property (GObject *obj,
                                    guint prop_id,
@@ -162,8 +198,8 @@ seahorse_certificate_get_property (GObject *obj,
 		g_value_set_boxed (value, self->pv->attributes);
 		break;
 	case PROP_FLAGS:
-		g_value_set_flags (value, SEAHORSE_FLAG_PERSONAL |
-		                          SEAHORSE_FLAG_EXPORTABLE);
+		ensure_flags (self);
+		g_value_set_flags (value, self->pv->flags);
 		break;
 	case PROP_ACTIONS:
 		g_value_set_object (value, self->pv->actions);
@@ -312,10 +348,15 @@ seahorse_certificate_get_description (SeahorseCertificate *self)
 {
 	g_return_val_if_fail (SEAHORSE_IS_CERTIFICATE (self), NULL);
 
+	ensure_flags (self);
+
 	if (self->pv->private_key)
-		return _("Certificate and Key");
+		return _("Personal certificate and key");
 
-	return _("Certificate");
+	if (self->pv->flags & SEAHORSE_FLAG_PERSONAL)
+		return _("Personal certificate");
+	else
+		return _("Certificate");
 }
 
 SeahorsePrivateKey *
diff --git a/src/seahorse-key-manager.c b/src/seahorse-key-manager.c
index 33650af..2ed6ff7 100644
--- a/src/seahorse-key-manager.c
+++ b/src/seahorse-key-manager.c
@@ -64,6 +64,7 @@ void           on_keymanager_import_button              (GtkButton* button,
 
 struct _SeahorseKeyManagerPrivate {
 	GtkActionGroup* view_actions;
+	GtkRadioAction *show_action;
 	GtkEntry* filter_entry;
 	SeahorsePredicate pred;
 	SeahorseSidebar *sidebar;
@@ -361,16 +362,13 @@ on_delete_event (GtkWidget* widget, GdkEvent* event, SeahorseKeyManager* self)
 	return TRUE;
 }
 
-static void
-on_view_show_changed (GtkRadioAction *action,
-                      GtkRadioAction *current,
-                      gpointer user_data)
+static const gchar *
+update_view_filter (SeahorseKeyManager *self)
 {
-	SeahorseKeyManager *self = SEAHORSE_KEY_MANAGER (user_data);
 	const gchar *value = "";
 	gint radio;
 
-	radio = gtk_radio_action_get_current_value (action);
+	radio = gtk_radio_action_get_current_value (self->pv->show_action);
 	switch (radio) {
 	case SHOW_PERSONAL:
 		self->pv->pred.flags = SEAHORSE_FLAG_PERSONAL;
@@ -387,6 +385,17 @@ on_view_show_changed (GtkRadioAction *action,
 	}
 
 	seahorse_key_manager_store_refilter (self->pv->store);
+	return value;
+}
+
+
+static void
+on_view_show_changed (GtkRadioAction *action,
+                      GtkRadioAction *current,
+                      gpointer user_data)
+{
+	SeahorseKeyManager *self = SEAHORSE_KEY_MANAGER (user_data);
+	const gchar *value = update_view_filter (self);
 	g_settings_set_string (self->pv->settings, "item-filter", value);
 }
 
@@ -395,7 +404,7 @@ on_item_filter_changed (GSettings *settings,
                         const gchar *key,
                         gpointer user_data)
 {
-	GtkAction* action = GTK_ACTION (user_data);
+	SeahorseKeyManager *self = SEAHORSE_KEY_MANAGER (user_data);
 	gchar *value;
 	gint radio;
 
@@ -407,9 +416,9 @@ on_item_filter_changed (GSettings *settings,
 	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);
+		radio = -1;
+	gtk_radio_action_set_current_value (self->pv->show_action, radio);
+	update_view_filter (self);
 	g_free (value);
 }
 
@@ -585,9 +594,25 @@ seahorse_key_manager_constructed (GObject *object)
 
 	G_OBJECT_CLASS (seahorse_key_manager_parent_class)->constructed (object);
 
+	gtk_window_set_title (seahorse_viewer_get_window (SEAHORSE_VIEWER (self)), _("Passwords and Keys"));
+
 	self->pv->collection = setup_sidebar (self);
 
-	gtk_window_set_title (seahorse_viewer_get_window (SEAHORSE_VIEWER (self)), _("Passwords and Keys"));
+	/* Init key list & selection settings */
+	self->pv->view = GTK_TREE_VIEW (seahorse_widget_get_widget (SEAHORSE_WIDGET (self), "key-list"));
+	g_return_if_fail (self->pv->view != NULL);
+
+	selection = gtk_tree_view_get_selection (self->pv->view);
+	gtk_tree_selection_set_mode (selection, GTK_SELECTION_MULTIPLE);
+	g_signal_connect (selection, "changed", G_CALLBACK (on_view_selection_changed), self);
+	gtk_widget_realize (GTK_WIDGET (self->pv->view));
+
+	/* 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);
+
 
 	actions = gtk_action_group_new ("general");
 	gtk_action_group_set_translation_domain (actions, GETTEXT_PACKAGE);
@@ -597,14 +622,16 @@ 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,
+	                                    G_N_ELEMENTS (VIEW_RADIO_ACTIONS), -1,
 	                                    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);
+	self->pv->show_action = GTK_RADIO_ACTION (action);
 
 	/* Notify us when settings change */
 	g_signal_connect_object (self->pv->settings, "changed::item-filter",
-	                         G_CALLBACK (on_item_filter_changed), action, 0);
+	                         G_CALLBACK (on_item_filter_changed), self, 0);
+	on_item_filter_changed (self->pv->settings, "item-filter", self);
 
 	/* close event */
 	g_signal_connect_object (seahorse_widget_get_toplevel (SEAHORSE_WIDGET (self)), 
@@ -685,21 +712,6 @@ seahorse_key_manager_constructed (GObject *object)
 	                         G_CALLBACK (on_filter_changed), self, 0);
 
 
-	/* Init key list & selection settings */
-	self->pv->view = GTK_TREE_VIEW (seahorse_widget_get_widget (SEAHORSE_WIDGET (self), "key-list"));
-	g_return_if_fail (self->pv->view != NULL);
-
-	selection = gtk_tree_view_get_selection (self->pv->view);
-	gtk_tree_selection_set_mode (selection, GTK_SELECTION_MULTIPLE);
-	g_signal_connect (selection, "changed", G_CALLBACK (on_view_selection_changed), self);
-	gtk_widget_realize (GTK_WIDGET (self->pv->view));
-
-	/* 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 */
 	gtk_widget_grab_focus (GTK_WIDGET (self->pv->view));
 	g_signal_emit_by_name (self, "selection-changed");



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