[seahorse/refactor: 24/33] Allow showing and hiding the places sidebar



commit 10ce87c7ce9af5fbc8c04ab4f2c926d08456074e
Author: Stef Walter <stefw collabora co uk>
Date:   Thu Oct 13 09:43:38 2011 +0200

    Allow showing and hiding the places sidebar
    
     * If places sidebar is hidden then show all items in the same
       view.

 data/org.gnome.seahorse.manager.gschema.xml |   39 ++++--
 libseahorse/seahorse-viewer.c               |    2 -
 pgp/seahorse-keyserver-results.c            |   36 ------
 src/seahorse-key-manager.c                  |  144 ++++++++++------------
 src/seahorse-key-manager.ui                 |   11 +-
 src/seahorse-sidebar.c                      |  179 ++++++++++++++++++++-------
 src/seahorse-sidebar.h                      |    5 +
 7 files changed, 234 insertions(+), 182 deletions(-)
---
diff --git a/data/org.gnome.seahorse.manager.gschema.xml b/data/org.gnome.seahorse.manager.gschema.xml
index 20579bd..77b2a1a 100644
--- a/data/org.gnome.seahorse.manager.gschema.xml
+++ b/data/org.gnome.seahorse.manager.gschema.xml
@@ -1,34 +1,45 @@
 <schemalist>
 	<schema id="org.gnome.seahorse.manager" path="/apps/seahorse/listing/">
+		<key name="show-sidebar" type="b">
+			<default>false</default>
+			<summary>Show places sidebar</summary>
+			<description>Show places sidebar in seahorse.</description>
+		</key>
+		<key name="item-filter" type="s">
+			<default>"personal"</default>
+			<summary>Which items to show</summary>
+			<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>
 		<key name="show-validity" type="b">
 			<default>false</default>
 			<summary>Show validity column</summary>
-			<description>Controls the visibility of the expires column for the key manager.</description>
+			<description>No longer in use.</description>
 		</key>
 		<key name="show-expiry" type="b">
 			<default>false</default>
 			<summary>Show expiry column</summary>
-			<description>Controls the visibility of the expiry column for the key manager.</description>
+			<description>No longer in use.</description>
 		</key>
 		<key name="show-trust" type="b">
 			<default>false</default>
 			<summary>Show trust column</summary>
-			<description>Controls the visibility of the trust column for the key manager.</description>
+			<description>No longer in use.</description>
 		</key>
 		<key name="show-type" type="b">
 			<default>false</default>
 			<summary>Show type column</summary>
-			<description>Controls the visibility of the type column for the key manager.</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>
+			<description>No longer in use.</description>
 		</key>
 	</schema>
 </schemalist>
diff --git a/libseahorse/seahorse-viewer.c b/libseahorse/seahorse-viewer.c
index 06f3d06..d49e9bd 100644
--- a/libseahorse/seahorse-viewer.c
+++ b/libseahorse/seahorse-viewer.c
@@ -171,10 +171,8 @@ static const GtkActionEntry UI_ENTRIES[] = {
 	{ "edit-menu", NULL, N_("_Edit") },
 	{ "view-menu", NULL, N_("_View") },
 	{ "help-menu", NULL, N_("_Help") },
-#if defined (WITH_KEYSERVER) || defined (WITH_SHARING)
 	{ "app-preferences", GTK_STOCK_PREFERENCES, N_("Prefere_nces"), NULL,
 	  N_("Change preferences for this program"), G_CALLBACK (on_app_preferences) },
-#endif
 	{ "app-about", GTK_STOCK_ABOUT, NULL, NULL,
 	  N_("About this program"), G_CALLBACK (on_app_about) },
 	{ "help-show", GTK_STOCK_HELP, N_("_Contents"), "F1",
diff --git a/pgp/seahorse-keyserver-results.c b/pgp/seahorse-keyserver-results.c
index 59ba31a..8df16c9 100644
--- a/pgp/seahorse-keyserver-results.c
+++ b/pgp/seahorse-keyserver-results.c
@@ -136,38 +136,6 @@ on_key_list_popup_menu (GtkTreeView* view, SeahorseKeyserverResults* self)
 }
 
 /**
-* action:
-* self: The result object to expand the nodes in
-*
-* Expands all the nodes in the view of the object
-*
-**/
-static void
-on_view_expand_all (GtkAction* action, SeahorseKeyserverResults* self)
-{
-	g_return_if_fail (SEAHORSE_IS_KEYSERVER_RESULTS (self));
-	g_return_if_fail (GTK_IS_ACTION (action));
-	gtk_tree_view_expand_all (self->pv->view);
-}
-
-
-/**
-* action:
-* self: The result object to collapse the nodes in
-*
-* Collapses all the nodes in the view of the object
-*
-**/
-static void
-on_view_collapse_all (GtkAction* action, SeahorseKeyserverResults* self)
-
-{
-	g_return_if_fail (SEAHORSE_IS_KEYSERVER_RESULTS (self));
-	g_return_if_fail (GTK_IS_ACTION (action));
-	gtk_tree_view_collapse_all (self->pv->view);
-}
-
-/**
 * action: the closing action or NULL
 * self: The SeahorseKeyServerResults widget to destroy
 *
@@ -274,10 +242,6 @@ static const GtkActionEntry GENERAL_ENTRIES[] = {
 	{ "remote-menu", NULL, N_("_Remote") },
 	{ "app-close", GTK_STOCK_CLOSE, NULL, "<control>W",
 	  N_("Close this window"), G_CALLBACK (on_app_close) },
-	{ "view-expand-all", GTK_STOCK_ADD, N_("_Expand All"), NULL,
-	  N_("Expand all listings"), G_CALLBACK (on_view_expand_all) },
-	{ "view-collapse-all", GTK_STOCK_REMOVE, N_("_Collapse All"), NULL,
-	  N_("Collapse all listings"), G_CALLBACK (on_view_collapse_all) }
 };
 
 static const GtkActionEntry SERVER_ENTRIES[] = {
diff --git a/src/seahorse-key-manager.c b/src/seahorse-key-manager.c
index a49c6d2..f7e3f2f 100644
--- a/src/seahorse-key-manager.c
+++ b/src/seahorse-key-manager.c
@@ -38,6 +38,12 @@
 
 #include <glib/gi18n.h>
 
+enum {
+	SHOW_ANY,
+	SHOW_PERSONAL,
+	SHOW_TRUSTED,
+};
+
 void           on_keymanager_row_activated              (GtkTreeView* view,
                                                          GtkTreePath* path,
                                                          GtkTreeViewColumn* column,
@@ -356,65 +362,34 @@ on_delete_event (GtkWidget* widget, GdkEvent* event, SeahorseKeyManager* self)
 	return TRUE;
 }
 
-static void 
-on_view_type_activate (GtkToggleAction* action, SeahorseKeyManager* self) 
-{
-	g_return_if_fail (SEAHORSE_IS_KEY_MANAGER (self));
-	g_return_if_fail (GTK_IS_TOGGLE_ACTION (action));
-	g_settings_set_boolean (self->pv->settings, "show-type", gtk_toggle_action_get_active (action));
-}
-
-
-static void 
-on_view_expires_activate (GtkToggleAction* action, SeahorseKeyManager* self) 
-{
-	g_return_if_fail (SEAHORSE_IS_KEY_MANAGER (self));
-	g_return_if_fail (GTK_IS_TOGGLE_ACTION (action));
-	g_settings_set_boolean (self->pv->settings, "show-expiry", gtk_toggle_action_get_active (action));
-}
-
-
-static void 
-on_view_validity_activate (GtkToggleAction* action, SeahorseKeyManager* self) 
-{
-	g_return_if_fail (SEAHORSE_IS_KEY_MANAGER (self));
-	g_return_if_fail (GTK_IS_TOGGLE_ACTION (action));
-	g_settings_set_boolean (self->pv->settings, "show-validity", gtk_toggle_action_get_active (action));
-}
-
-static void 
-on_view_trust_activate (GtkToggleAction* action, SeahorseKeyManager* self) 
-{
-	g_return_if_fail (SEAHORSE_IS_KEY_MANAGER (self));
-	g_return_if_fail (GTK_IS_TOGGLE_ACTION (action));
-	g_settings_set_boolean (self->pv->settings, "show-trust", gtk_toggle_action_get_active (action));
-}
-
 static void
-on_manager_settings_changed (GSettings *settings, const gchar *key, gpointer user_data)
+on_manager_settings_changed (GSettings *settings,
+                             const gchar *key,
+                             gpointer user_data)
 {
 	SeahorseKeyManager *self = SEAHORSE_KEY_MANAGER (user_data);
-	GtkToggleAction* action;
-	const gchar* name;
-
-	if (g_str_equal (key, "show-trust"))
-		name = "view-trust";
-	else if (g_str_equal (key, "show-type"))
-		name = "view-type";
-	else if (g_str_equal (key, "show-expiry"))
-		name = "view-expires";
-	else if (g_str_equal (key, "show-validity"))
-		name = "view-validity";
-	else
-		return;
-
-	action = GTK_TOGGLE_ACTION (gtk_action_group_get_action (self->pv->view_actions, name));
-	g_return_if_fail (action != NULL);
-
-	gtk_toggle_action_set_active (action, g_settings_get_boolean (settings, key));
+	GtkAction* action;
+	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);
+	}
 }
 
-static const GtkActionEntry GENERAL_ENTRIES[] = {
+static const GtkActionEntry GENERAL_ACTIONS[] = {
 	{ "remote-menu", NULL, N_("_Remote") }, 
 	{ "app-quit", GTK_STOCK_QUIT, NULL, "<control>Q", 
 	  N_("Close this program"), G_CALLBACK (on_app_quit) }, 
@@ -426,15 +401,18 @@ static const GtkActionEntry GENERAL_ENTRIES[] = {
 	  N_("Import from the clipboard"), G_CALLBACK (on_key_import_clipboard) }
 };
 
-static const GtkToggleActionEntry VIEW_ENTRIES[] = {
-	{ "view-type", NULL, N_("T_ypes"), NULL, N_("Show type column"), 
-	  G_CALLBACK (on_view_type_activate), FALSE }, 
-	{ "view-expires", NULL, N_("_Expiry"), NULL, N_("Show expiry column"), 
-	  G_CALLBACK (on_view_expires_activate), FALSE }, 
-	{ "view-trust", NULL, N_("_Trust"), NULL, N_("Show owner trust column"), 
-	  G_CALLBACK (on_view_trust_activate), FALSE}, 
-	{ "view-validity", NULL, N_("_Validity"), NULL, N_("Show validity column"), 
-	  G_CALLBACK (on_view_validity_activate), FALSE }
+static const GtkToggleActionEntry SIDEBAR_ACTIONS[] = {
+	{ "view-places", NULL, N_("P_laces"), NULL,
+	  N_("Show places sidebar"), NULL, FALSE },
+};
+
+static const GtkRadioActionEntry VIEW_RADIO_ACTIONS[] = {
+	{ "view-personal", NULL, N_("Show _personal"), NULL,
+	  N_("Only show personal keys, certificates and passwords"), SHOW_PERSONAL },
+	{ "view-trusted", NULL, N_("Show _trusted"), NULL,
+	  N_("Only show trusted keys, certificates and passwords"), SHOW_TRUSTED },
+	{ "view-any", NULL, N_("_Show _any"), NULL,
+	  N_("Show all keys, certificates and passwords"), SHOW_ANY },
 };
 
 /* -----------------------------------------------------------------------------
@@ -508,18 +486,31 @@ static GcrCollection *
 setup_sidebar (SeahorseKeyManager *self)
 {
 	SeahorseSidebar *sidebar;
-	GtkWidget *widget;
+	GtkWidget *area, *panes;
+	GtkActionGroup *actions;
+	GtkAction *action;
 
 	sidebar = seahorse_sidebar_new ();
-	widget = seahorse_widget_get_widget (SEAHORSE_WIDGET (self), "sidebar-area");
-	gtk_container_add (GTK_CONTAINER (widget), GTK_WIDGET (sidebar));
+	area = seahorse_widget_get_widget (SEAHORSE_WIDGET (self), "sidebar-area");
+	gtk_container_add (GTK_CONTAINER (area), GTK_WIDGET (sidebar));
 	gtk_widget_show (GTK_WIDGET (sidebar));
 
 	self->pv->sidebar_width = g_settings_get_int (self->pv->settings, "sidebar-width");
-	widget = seahorse_widget_get_widget (SEAHORSE_WIDGET (self), "sidebar-panes");
-	gtk_paned_set_position (GTK_PANED (widget), self->pv->sidebar_width);
+	panes = seahorse_widget_get_widget (SEAHORSE_WIDGET (self), "sidebar-panes");
+	gtk_paned_set_position (GTK_PANED (panes), self->pv->sidebar_width);
 	g_signal_connect (sidebar, "size_allocate", G_CALLBACK (on_sidebar_panes_size_allocate), self);
 
+	actions = gtk_action_group_new ("sidebar");
+	gtk_action_group_set_translation_domain (actions, GETTEXT_PACKAGE);
+	gtk_action_group_add_toggle_actions (actions, SIDEBAR_ACTIONS,
+	                                     G_N_ELEMENTS (SIDEBAR_ACTIONS), 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);
+	seahorse_viewer_include_actions (SEAHORSE_VIEWER (self), actions);
+	g_object_unref (actions);
+
 	return seahorse_sidebar_get_collection (sidebar);
 }
 
@@ -528,7 +519,6 @@ seahorse_key_manager_constructed (GObject *object)
 {
 	SeahorseKeyManager *self = SEAHORSE_KEY_MANAGER (object);
 	GtkActionGroup* actions;
-	GtkToggleAction* action;
 	GtkTargetList* targets;
 	GtkTreeSelection *selection;
 	GtkWidget* widget;
@@ -541,22 +531,16 @@ seahorse_key_manager_constructed (GObject *object)
 	
 	actions = gtk_action_group_new ("general");
 	gtk_action_group_set_translation_domain (actions, GETTEXT_PACKAGE);
-	gtk_action_group_add_actions (actions, GENERAL_ENTRIES, G_N_ELEMENTS (GENERAL_ENTRIES), self);
+	gtk_action_group_add_actions (actions, GENERAL_ACTIONS, G_N_ELEMENTS (GENERAL_ACTIONS), self);
 	seahorse_viewer_include_actions (SEAHORSE_VIEWER (self), actions);
 
 	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_toggle_actions (self->pv->view_actions, VIEW_ENTRIES, G_N_ELEMENTS (VIEW_ENTRIES), self);
-	action = GTK_TOGGLE_ACTION (gtk_action_group_get_action (self->pv->view_actions, "view-type"));
-	gtk_toggle_action_set_active (action, g_settings_get_boolean (self->pv->settings, "show-type"));
-	action = GTK_TOGGLE_ACTION (gtk_action_group_get_action (self->pv->view_actions, "view-expires"));
-	gtk_toggle_action_set_active (action, g_settings_get_boolean (self->pv->settings, "show-expiry"));
-	action = GTK_TOGGLE_ACTION (gtk_action_group_get_action (self->pv->view_actions, "view-trust"));
-	gtk_toggle_action_set_active (action, g_settings_get_boolean (self->pv->settings, "show-trust"));
-	action = GTK_TOGGLE_ACTION (gtk_action_group_get_action (self->pv->view_actions, "view-validity"));
-	gtk_toggle_action_set_active (action, g_settings_get_boolean (self->pv->settings, "show-validity"));
+	gtk_action_group_add_radio_actions (self->pv->view_actions, VIEW_RADIO_ACTIONS,
+	                                    G_N_ELEMENTS (VIEW_RADIO_ACTIONS),
+	                                    SHOW_PERSONAL, NULL, NULL);
 	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);
 
diff --git a/src/seahorse-key-manager.ui b/src/seahorse-key-manager.ui
index 2527dd1..7dbb80c 100644
--- a/src/seahorse-key-manager.ui
+++ b/src/seahorse-key-manager.ui
@@ -20,15 +20,16 @@
 		<placeholder name="RemoteMenu">
 		</placeholder>
 		<menu name="View" action="view-menu">
-			<menuitem action="view-type"/>
-			<menuitem action="view-expires"/>
-			<menuitem action="view-trust"/>
-			<menuitem action="view-validity"/>
+			<menuitem action="view-places"/>
+			<separator/>
+			<menuitem action="view-personal"/>
+			<menuitem action="view-trusted"/>
+			<menuitem action="view-any"/>
 		</menu>
 		<menu name="Help" action="help-menu">
 			<menuitem action="help-show"/>
 			<menuitem action="app-about"/>
-		</menu> 
+		</menu>
 
 	</menubar>
   
diff --git a/src/seahorse-sidebar.c b/src/seahorse-sidebar.c
index 9bfed4d..30e87a6 100644
--- a/src/seahorse-sidebar.c
+++ b/src/seahorse-sidebar.c
@@ -32,6 +32,12 @@
 
 #include <glib/gi18n.h>
 
+typedef enum {
+	SEAHORSE_SIDEBAR_MODE_COMBINED,
+	SEAHORSE_SIDEBAR_MODE_CHECKED,
+	SEAHORSE_SIDEBAR_MODE_SELECTED
+} SeahorseSidebarMode;
+
 struct _SeahorseSidebar {
 	GtkScrolledWindow parent;
 
@@ -39,6 +45,7 @@ struct _SeahorseSidebar {
 
 	GtkListStore *store;
 	GPtrArray *backends;
+	SeahorseSidebarMode mode;
 	GHashTable *checked;
 	GcrUnionCollection *objects;
 	GcrCollection *selected;
@@ -52,7 +59,8 @@ struct _SeahorseSidebarClass {
 
 enum {
 	PROP_0,
-	PROP_COLLECTION
+	PROP_COLLECTION,
+	PROP_COMBINED
 };
 
 typedef enum {
@@ -94,10 +102,11 @@ seahorse_sidebar_init (SeahorseSidebar *self)
 	self->backends = g_ptr_array_new_with_free_func (g_object_unref);
 	self->checked = g_hash_table_new (g_direct_hash, g_direct_equal);
 	self->objects = GCR_UNION_COLLECTION (gcr_union_collection_new ());
+	self->mode = SEAHORSE_SIDEBAR_MODE_SELECTED;
 }
 
 static void
-next_or_append_row (GtkListStore *store,
+next_or_append_row (SeahorseSidebar *self,
                     GtkTreeIter *iter,
                     const gchar *category,
                     GcrCollection *collection)
@@ -119,18 +128,18 @@ next_or_append_row (GtkListStore *store,
 	/* A marker that tells us the iter is not yet valid */
 	if (iter->stamp == GPOINTER_TO_INT (iter) && iter->user_data3 == iter &&
 	    iter->user_data2 == iter && iter->user_data == iter) {
-		if (!gtk_tree_model_get_iter_first (GTK_TREE_MODEL (store), iter))
-			gtk_list_store_append (store, iter);
+		if (!gtk_tree_model_get_iter_first (GTK_TREE_MODEL (self->store), iter))
+			gtk_list_store_append (self->store, iter);
 		return;
 	}
 
-	if (!gtk_tree_model_iter_next (GTK_TREE_MODEL (store), iter)) {
-		gtk_list_store_append (store, iter);
+	if (!gtk_tree_model_iter_next (GTK_TREE_MODEL (self->store), iter)) {
+		gtk_list_store_append (self->store, iter);
 		return;
 	}
 
 	for (;;) {
-		gtk_tree_model_get (GTK_TREE_MODEL (store), iter,
+		gtk_tree_model_get (GTK_TREE_MODEL (self->store), iter,
 		                    SIDEBAR_CATEGORY, &row_category,
 		                    SIDEBAR_COLLECTION, &row_collection,
 		                    -1);
@@ -143,8 +152,9 @@ next_or_append_row (GtkListStore *store,
 		if (found)
 			return;
 
-		if (!gtk_list_store_remove (store, iter)) {
-			gtk_list_store_append (store, iter);
+		g_hash_table_remove (self->checked, row_collection);
+		if (!gtk_list_store_remove (self->store, iter)) {
+			gtk_list_store_append (self->store, iter);
 			return;
 		}
 	}
@@ -174,7 +184,7 @@ update_backend (SeahorseSidebar *self,
 	              "description", &tooltip,
 	              NULL);
 
-	next_or_append_row (self->store, iter, category, GCR_COLLECTION (backend));
+	next_or_append_row (self, iter, category, GCR_COLLECTION (backend));
 	gtk_list_store_set (self->store, iter,
 	                    SIDEBAR_ROW_TYPE, TYPE_BACKEND,
 	                    SIDEBAR_CATEGORY, category,
@@ -199,7 +209,7 @@ update_backend (SeahorseSidebar *self,
 		spec = g_object_class_find_property (G_OBJECT_GET_CLASS (l->data), "label");
 		g_return_if_fail (spec != NULL);
 
-		next_or_append_row (self->store, iter, category, l->data);
+		next_or_append_row (self, iter, category, l->data);
 		gtk_list_store_set (self->store, iter,
 		                    SIDEBAR_ROW_TYPE, TYPE_PLACE,
 		                    SIDEBAR_CATEGORY, category,
@@ -220,6 +230,42 @@ update_backend (SeahorseSidebar *self,
 }
 
 static void
+update_objects_in_collection (SeahorseSidebar *self)
+{
+	GList *collections;
+	gboolean include;
+	gboolean have;
+	GList *l;
+	guint i;
+
+	for (i = 0; i < self->backends->len; i++) {
+		collections = gcr_collection_get_objects (self->backends->pdata[i]);
+		for (l = collections; l != NULL; l = g_list_next (l)) {
+			switch (self->mode) {
+			case SEAHORSE_SIDEBAR_MODE_COMBINED:
+				include = TRUE;
+				break;
+			case SEAHORSE_SIDEBAR_MODE_CHECKED:
+				include = (g_hash_table_lookup (self->checked, l->data) != NULL);
+				break;
+			case SEAHORSE_SIDEBAR_MODE_SELECTED:
+				include = (l->data == self->selected);
+				break;
+			default:
+				g_assert_not_reached ();
+			}
+
+			have = gcr_union_collection_have (self->objects, l->data);
+			if (include && !have)
+				gcr_union_collection_add (self->objects, l->data);
+			else if (!include && have)
+				gcr_union_collection_remove (self->objects, l->data);
+		}
+		g_list_free (collections);
+	}
+}
+
+static void
 update_objects_for_selection (SeahorseSidebar *self,
                               GtkTreeSelection *selection)
 {
@@ -233,14 +279,10 @@ update_objects_for_selection (SeahorseSidebar *self,
 		                    -1);
 
 	if (selected != self->selected) {
-		if (self->selected && g_hash_table_size (self->checked) == 0)
-			gcr_union_collection_remove (self->objects, self->selected);
-
 		g_clear_object (&self->selected);
 		self->selected = selected ? g_object_ref (selected) : NULL;
-
-		if (self->selected && g_hash_table_size (self->checked) == 0)
-			gcr_union_collection_add (self->objects, self->selected);
+		if (self->mode == SEAHORSE_SIDEBAR_MODE_SELECTED)
+			update_objects_in_collection (self);
 	}
 
 	g_clear_object (&selected);
@@ -252,19 +294,10 @@ update_objects_for_checked (SeahorseSidebar *self,
 {
 	g_hash_table_insert (self->checked, place, place);
 
-	/* The first check ... */
-	if (g_hash_table_size (self->checked) == 1) {
-
-		/* ... but the currently checked one was selected so leave same */
-		if (self->selected == place)
-			return;
-
-		/* ... something else was selected, so update */
-		else if (self->selected)
-			gcr_union_collection_remove (self->objects, self->selected);
-	}
-
-	gcr_union_collection_add (self->objects, place);
+	if (self->mode == SEAHORSE_SIDEBAR_MODE_SELECTED)
+		self->mode = SEAHORSE_SIDEBAR_MODE_CHECKED;
+	if (self->mode != SEAHORSE_SIDEBAR_MODE_COMBINED)
+		update_objects_in_collection (self);
 }
 
 static void
@@ -274,25 +307,37 @@ update_objects_for_unchecked (SeahorseSidebar *self,
 	if (!g_hash_table_remove (self->checked, place))
 		g_assert_not_reached ();
 
-	/* No more checks ... */
-	if (g_hash_table_size (self->checked) == 0) {
-
-		/* ... but the currently unchecked one is selected so leave same ... */
-		if (self->selected == place)
-			return;
+	if (self->mode == SEAHORSE_SIDEBAR_MODE_CHECKED &&
+	    g_hash_table_size (self->checked) == 0)
+		self->mode = SEAHORSE_SIDEBAR_MODE_SELECTED;
+	if (self->mode != SEAHORSE_SIDEBAR_MODE_COMBINED)
+		update_objects_in_collection (self);
+}
 
-		/* ... something else is selected, so update */
-		else if (self->selected)
-			gcr_union_collection_add (self->objects, self->selected);
+static void
+update_objects_for_combine (SeahorseSidebar *self)
+{
+	if (self->mode != SEAHORSE_SIDEBAR_MODE_COMBINED) {
+		self->mode = SEAHORSE_SIDEBAR_MODE_COMBINED;
+		update_objects_in_collection (self);
 	}
+}
 
-	gcr_union_collection_remove (self->objects, place);
+static void
+update_objects_for_uncombine (SeahorseSidebar *self)
+{
+	if (self->mode == SEAHORSE_SIDEBAR_MODE_COMBINED) {
+		if (g_hash_table_size (self->checked) > 0)
+			self->mode = SEAHORSE_SIDEBAR_MODE_CHECKED;
+		else
+			self->mode = SEAHORSE_SIDEBAR_MODE_SELECTED;
+		update_objects_in_collection (self);
+	}
 }
 
 static void
 update_places (SeahorseSidebar *self)
 {
-	GtkTreeSelection *selection;
 	GtkTreeIter iter;
 	guint i;
 
@@ -304,8 +349,7 @@ update_places (SeahorseSidebar *self)
 		update_backend (self, GCR_COLLECTION (self->backends->pdata[i]), &iter);
 
 	/* Update selection */
-	selection = gtk_tree_view_get_selection (self->tree_view);
-	update_objects_for_selection (self, selection);
+	update_objects_in_collection (self);
 }
 
 static gboolean
@@ -490,11 +534,11 @@ on_backend_changed (GObject *obj,
 
 static void
 on_place_added (GcrCollection *places,
-                GObject *object,
+                GObject *place,
                 gpointer user_data)
 {
 	SeahorseSidebar *self = SEAHORSE_SIDEBAR (user_data);
-	g_signal_connect (object, "notify", G_CALLBACK (on_place_changed), self);
+	g_signal_connect (place, "notify", G_CALLBACK (on_place_changed), self);
 	update_places_later (self);
 }
 
@@ -732,6 +776,27 @@ seahorse_sidebar_get_property (GObject *obj,
 	case PROP_COLLECTION:
 		g_value_set_object (value, seahorse_sidebar_get_collection (self));
 		break;
+	case PROP_COMBINED:
+		g_value_set_boolean (value, seahorse_sidebar_get_combined (self));
+		break;
+	default:
+		G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, prop_id, pspec);
+		break;
+	}
+}
+
+static void
+seahorse_sidebar_set_property (GObject *obj,
+                               guint prop_id,
+                               const GValue *value,
+                               GParamSpec *pspec)
+{
+	SeahorseSidebar *self = SEAHORSE_SIDEBAR (obj);
+
+	switch (prop_id) {
+	case PROP_COMBINED:
+		seahorse_sidebar_set_combined (self, g_value_get_boolean (value));
+		break;
 	default:
 		G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, prop_id, pspec);
 		break;
@@ -786,10 +851,15 @@ seahorse_sidebar_class_init (SeahorseSidebarClass *klass)
 	gobject_class->dispose = seahorse_sidebar_dispose;
 	gobject_class->finalize = seahorse_sidebar_finalize;
 	gobject_class->get_property = seahorse_sidebar_get_property;
+	gobject_class->set_property = seahorse_sidebar_set_property;
 
 	g_object_class_install_property (gobject_class, PROP_COLLECTION,
 	        g_param_spec_object ("collection", "Collection", "Collection of objects sidebar represents",
 	                             GCR_TYPE_COLLECTION, G_PARAM_READABLE));
+
+	g_object_class_install_property (gobject_class, PROP_COMBINED,
+	        g_param_spec_boolean ("combined", "Combined", "Collection shows all objects combined",
+	                              FALSE, G_PARAM_READWRITE));
 }
 
 SeahorseSidebar *
@@ -805,3 +875,22 @@ seahorse_sidebar_get_collection (SeahorseSidebar *self)
 	g_return_val_if_fail (SEAHORSE_IS_SIDEBAR (self), NULL);
 	return GCR_COLLECTION (self->objects);
 }
+
+gboolean
+seahorse_sidebar_get_combined (SeahorseSidebar *self)
+{
+	g_return_val_if_fail (SEAHORSE_IS_SIDEBAR (self), FALSE);
+	return self->mode == SEAHORSE_SIDEBAR_MODE_COMBINED;
+}
+
+void
+seahorse_sidebar_set_combined (SeahorseSidebar *self,
+                               gboolean combined)
+{
+	g_return_if_fail (SEAHORSE_IS_SIDEBAR (self));
+	if (combined)
+		update_objects_for_combine (self);
+	else
+		update_objects_for_uncombine (self);
+	g_object_notify (G_OBJECT (self), "combined");
+}
diff --git a/src/seahorse-sidebar.h b/src/seahorse-sidebar.h
index 1bf994e..48b57ef 100644
--- a/src/seahorse-sidebar.h
+++ b/src/seahorse-sidebar.h
@@ -40,6 +40,11 @@ GType                        seahorse_sidebar_get_type           (void);
 
 SeahorseSidebar *            seahorse_sidebar_new                (void);
 
+gboolean                     seahorse_sidebar_get_combined       (SeahorseSidebar *self);
+
+void                         seahorse_sidebar_set_combined       (SeahorseSidebar *self,
+                                                                  gboolean combined);
+
 GcrCollection *              seahorse_sidebar_get_collection     (SeahorseSidebar *self);
 
 #endif /* __SEAHORSE_SIDEBAR_H__ */



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