seahorse r2742 - in trunk: . gkr



Author: nnielsen
Date: Sun Feb  1 22:12:59 2009
New Revision: 2742
URL: http://svn.gnome.org/viewvc/seahorse?rev=2742&view=rev

Log:
Add 'lock' and 'unlock' commands to password keyrings.

Modified:
   trunk/ChangeLog
   trunk/gkr/seahorse-gkr-keyring-commands.c
   trunk/gkr/seahorse-gkr-keyring-commands.h

Modified: trunk/gkr/seahorse-gkr-keyring-commands.c
==============================================================================
--- trunk/gkr/seahorse-gkr-keyring-commands.c	(original)
+++ trunk/gkr/seahorse-gkr-keyring-commands.c	Sun Feb  1 22:12:59 2009
@@ -34,8 +34,9 @@
 
 #include <glib/gi18n.h>
 
-enum {
-	PROP_0
+struct _SeahorseGkrKeyringCommandsPrivate {
+	GtkAction *action_lock;
+	GtkAction *action_unlock;
 };
 
 G_DEFINE_TYPE (SeahorseGkrKeyringCommands, seahorse_gkr_keyring_commands, SEAHORSE_TYPE_COMMANDS);
@@ -43,6 +44,8 @@
 static const char* UI_KEYRING = ""\
 "<ui>"\
 "	<popup name='KeyPopup'>"\
+"		<menuitem action='keyring-lock'/>"\
+"		<menuitem action='keyring-unlock'/>"\
 "		<menuitem action='keyring-password'/>"\
 "	</popup>"\
 "</ui>";
@@ -66,6 +69,82 @@
 };
 
 static void
+on_keyring_unlock_done (GnomeKeyringResult result, gpointer user_data)
+{
+	SeahorseView *view;
+
+	if (result != GNOME_KEYRING_RESULT_OK &&
+	    result != GNOME_KEYRING_RESULT_DENIED &&
+	    result != GNOME_KEYRING_RESULT_CANCELLED) {
+		view = seahorse_commands_get_view (SEAHORSE_COMMANDS (user_data));
+		seahorse_util_show_error (GTK_WIDGET (seahorse_view_get_window (view)),
+		                          _("Couldn't unlock keyring"),
+		                          gnome_keyring_result_to_message (result));
+	}
+}
+
+static void 
+on_keyring_unlock (GtkAction *action, SeahorseGkrKeyringCommands *self)
+{
+	SeahorseView *view;
+	SeahorseGkrKeyring *keyring;
+	GList *keys, *l;
+
+	g_return_if_fail (SEAHORSE_IS_GKR_KEYRING_COMMANDS (self));
+	g_return_if_fail (GTK_IS_ACTION (action));
+
+	view = seahorse_commands_get_view (SEAHORSE_COMMANDS (self));
+	keys = seahorse_view_get_selected_matching (view, &keyring_predicate);
+
+	for (l = keys; l; l = g_list_next (l)) {
+		keyring = SEAHORSE_GKR_KEYRING (l->data);
+		g_return_if_fail (SEAHORSE_IS_GKR_KEYRING (l->data));
+		gnome_keyring_unlock (seahorse_gkr_keyring_get_name (l->data), NULL, 
+		                      on_keyring_unlock_done, g_object_ref (self), g_object_unref);
+	}
+	
+	g_list_free (keys);
+}
+
+static void
+on_keyring_lock_done (GnomeKeyringResult result, gpointer user_data)
+{
+	SeahorseView *view;
+
+	if (result != GNOME_KEYRING_RESULT_OK &&
+	    result != GNOME_KEYRING_RESULT_DENIED &&
+	    result != GNOME_KEYRING_RESULT_CANCELLED) {
+		view = seahorse_commands_get_view (SEAHORSE_COMMANDS (user_data));
+		seahorse_util_show_error (GTK_WIDGET (seahorse_view_get_window (view)),
+		                          _("Couldn't lock keyring"),
+		                          gnome_keyring_result_to_message (result));
+	}
+}
+
+static void 
+on_keyring_lock (GtkAction *action, SeahorseGkrKeyringCommands *self)
+{
+	SeahorseView *view;
+	SeahorseGkrKeyring *keyring;
+	GList *keys, *l;
+
+	g_return_if_fail (SEAHORSE_IS_GKR_KEYRING_COMMANDS (self));
+	g_return_if_fail (GTK_IS_ACTION (action));
+
+	view = seahorse_commands_get_view (SEAHORSE_COMMANDS (self));
+	keys = seahorse_view_get_selected_matching (view, &keyring_predicate);
+
+	for (l = keys; l; l = g_list_next (l)) {
+		keyring = SEAHORSE_GKR_KEYRING (l->data);
+		g_return_if_fail (SEAHORSE_IS_GKR_KEYRING (l->data));
+		gnome_keyring_lock (seahorse_gkr_keyring_get_name (l->data), 
+		                    on_keyring_lock_done, g_object_ref (self), g_object_unref);
+	}
+	
+	g_list_free (keys);
+}
+
+static void
 on_change_password_done (GnomeKeyringResult result, gpointer user_data)
 {
 	SeahorseView *view;
@@ -99,13 +178,47 @@
 		gnome_keyring_change_password (seahorse_gkr_keyring_get_name (l->data), NULL, NULL,
 		                               on_change_password_done, g_object_ref (self), g_object_unref);
 	}
+	
+	g_list_free (keys);
 }
 
 static const GtkActionEntry ENTRIES_KEYRING[] = {
+	{ "keyring-lock", NULL, N_ ("Lock"), "",
+	  N_("Lock the password storage keyring so a master password is required to unlock it."), G_CALLBACK (on_keyring_lock) },
+	{ "keyring-unlock", NULL, N_ ("Unlock"), "",
+	  N_("Unlock the password storage keyring with a master password so it is available for use."), G_CALLBACK (on_keyring_unlock) },
 	{ "keyring-password", NULL, N_ ("Change Password"), "",
 	  N_("Change the unlock password of the password storage keyring"), G_CALLBACK (on_keyring_password) }
 };
 
+static void
+on_view_selection_changed (SeahorseView *view, SeahorseGkrKeyringCommands *self)
+{
+	GnomeKeyringInfo *info;
+	gboolean locked = FALSE;
+	gboolean unlocked = FALSE;
+	GList *keys, *l;
+	
+	g_return_if_fail (SEAHORSE_IS_VIEW (view));
+	g_return_if_fail (SEAHORSE_IS_GKR_KEYRING_COMMANDS (self));
+	
+	keys = seahorse_view_get_selected_matching (view, &keyring_predicate);
+	for (l = keys; l; l = g_list_next (l)) {
+		info = seahorse_gkr_keyring_get_info (l->data);
+		if (info != NULL) {
+			if (gnome_keyring_info_get_is_locked (info))
+				locked = TRUE;
+			else 
+				unlocked = TRUE;
+		}
+	}
+	
+	g_list_free (keys);
+	
+	gtk_action_set_sensitive (self->pv->action_lock, unlocked);
+	gtk_action_set_sensitive (self->pv->action_unlock, locked);
+}
+
 /* -----------------------------------------------------------------------------
  * OBJECT 
  */
@@ -143,31 +256,48 @@
 static GObject* 
 seahorse_gkr_keyring_commands_constructor (GType type, guint n_props, GObjectConstructParam *props) 
 {
-	GObject *obj = G_OBJECT_CLASS (seahorse_gkr_keyring_commands_parent_class)->constructor (type, n_props, props);
-	SeahorseCommands *base = NULL;
+	SeahorseGkrKeyringCommands *self = SEAHORSE_GKR_KEYRING_COMMANDS (G_OBJECT_CLASS (seahorse_gkr_keyring_commands_parent_class)->constructor (type, n_props, props));
 	GtkActionGroup *actions;
 	SeahorseView *view;
 	
-	if (obj) {
-		base = SEAHORSE_COMMANDS (obj);
-		view = seahorse_commands_get_view (base);
-		g_return_val_if_fail (view, NULL);
-		seahorse_view_register_commands (view, &keyring_predicate, base);
-
-		actions = gtk_action_group_new ("pgp");
-		gtk_action_group_set_translation_domain (actions, GETTEXT_PACKAGE);
-		gtk_action_group_add_actions (actions, ENTRIES_KEYRING, G_N_ELEMENTS (ENTRIES_KEYRING), obj);
-		seahorse_view_register_ui (view, &keyring_predicate, UI_KEYRING, actions);
-		g_object_unref (actions);
-	}
+	g_return_val_if_fail (SEAHORSE_IS_GKR_KEYRING_COMMANDS (self), NULL);
+	
+	view = seahorse_commands_get_view (SEAHORSE_COMMANDS (self));
+	g_return_val_if_fail (view, NULL);
+	seahorse_view_register_commands (view, &keyring_predicate, SEAHORSE_COMMANDS (self));
+
+	actions = gtk_action_group_new ("gkr-keyring");
+	gtk_action_group_set_translation_domain (actions, GETTEXT_PACKAGE);
+	gtk_action_group_add_actions (actions, ENTRIES_KEYRING, G_N_ELEMENTS (ENTRIES_KEYRING), self);
+	seahorse_view_register_ui (view, &keyring_predicate, UI_KEYRING, actions);
+	self->pv->action_lock = g_object_ref (gtk_action_group_get_action (actions, "keyring-lock"));
+	self->pv->action_unlock = g_object_ref (gtk_action_group_get_action (actions, "keyring-unlock"));
+	g_object_unref (actions);
+	
+	/* Watch and wait for selection changes and diddle lock/unlock */ 
+	g_signal_connect (view, "selection-changed", G_CALLBACK (on_view_selection_changed), self);
 
-	return obj;
+	return G_OBJECT (self);
 }
 
 static void
 seahorse_gkr_keyring_commands_init (SeahorseGkrKeyringCommands *self)
 {
+	self->pv = G_TYPE_INSTANCE_GET_PRIVATE (self, SEAHORSE_TYPE_GKR_KEYRING_COMMANDS, SeahorseGkrKeyringCommandsPrivate);
+}
 
+static void
+seahorse_gkr_keyring_commands_finalize (GObject *obj)
+{
+	SeahorseGkrKeyringCommands *self = SEAHORSE_GKR_KEYRING_COMMANDS (obj);
+
+	g_object_unref (self->pv->action_lock);
+	self->pv->action_lock = NULL;
+	
+	g_object_unref (self->pv->action_unlock);
+	self->pv->action_unlock = NULL;
+	
+	G_OBJECT_CLASS (seahorse_gkr_keyring_commands_parent_class)->finalize (obj);
 }
 
 static void
@@ -180,9 +310,12 @@
 	seahorse_gkr_keyring_commands_parent_class = g_type_class_peek_parent (klass);
 
 	gobject_class->constructor = seahorse_gkr_keyring_commands_constructor;
+	gobject_class->finalize = seahorse_gkr_keyring_commands_finalize;
 
 	cmd_class->show_properties = seahorse_gkr_keyring_commands_show_properties;
 	cmd_class->delete_objects = seahorse_gkr_keyring_commands_delete_objects;
+	
+	g_type_class_add_private (gobject_class, sizeof (SeahorseGkrKeyringCommandsPrivate));
 
 	/* Setup the predicate for these commands */
 	keyring_predicate.type = SEAHORSE_TYPE_GKR_KEYRING;

Modified: trunk/gkr/seahorse-gkr-keyring-commands.h
==============================================================================
--- trunk/gkr/seahorse-gkr-keyring-commands.h	(original)
+++ trunk/gkr/seahorse-gkr-keyring-commands.h	Sun Feb  1 22:12:59 2009
@@ -39,6 +39,7 @@
     
 struct _SeahorseGkrKeyringCommands {
 	SeahorseCommands parent;
+	SeahorseGkrKeyringCommandsPrivate *pv;
 };
 
 struct _SeahorseGkrKeyringCommandsClass {



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