[seahorse/refactor: 4/33] Implement GcrCollection contains virtual method.



commit 977e4b48f6413b6f3566a4a64b4a90cef062aa1c
Author: Stef Walter <stefw collabora co uk>
Date:   Tue Sep 6 09:09:53 2011 +0200

    Implement GcrCollection contains virtual method.

 gkr/seahorse-gkr-keyring.c        |   14 ++++++++++++++
 libseahorse/seahorse-collection.c |   19 +++++++++----------
 libseahorse/seahorse-collection.h |    3 ---
 pgp/seahorse-pgp-key.c            |   11 +++++++++++
 src/seahorse-key-manager.c        |    3 ++-
 5 files changed, 36 insertions(+), 14 deletions(-)
---
diff --git a/gkr/seahorse-gkr-keyring.c b/gkr/seahorse-gkr-keyring.c
index d85cccd..3412eea 100644
--- a/gkr/seahorse-gkr-keyring.c
+++ b/gkr/seahorse-gkr-keyring.c
@@ -502,11 +502,25 @@ seahorse_gkr_keyring_get_objects (GcrCollection *collection)
 	return g_hash_table_get_values (self->pv->items);
 }
 
+static gboolean
+seahorse_gkr_keyring_contains (GcrCollection *collection,
+                               GObject *object)
+{
+	SeahorseGkrKeyring *self = SEAHORSE_GKR_KEYRING (collection);
+	guint32 item_id;
+
+	if (!SEAHORSE_IS_GKR_ITEM (object))
+		return FALSE;
+	item_id = seahorse_gkr_item_get_item_id (SEAHORSE_GKR_ITEM (object));
+	return g_hash_table_lookup (self->pv->items, GUINT_TO_POINTER (item_id)) ? TRUE : FALSE;
+}
+
 static void
 seahorse_keyring_collection_iface (GcrCollectionIface *iface)
 {
 	iface->get_length = seahorse_gkr_keyring_get_length;
 	iface->get_objects = seahorse_gkr_keyring_get_objects;
+	iface->contains = seahorse_gkr_keyring_contains;
 }
 
 /* -----------------------------------------------------------------------------
diff --git a/libseahorse/seahorse-collection.c b/libseahorse/seahorse-collection.c
index eed6424..f24faad 100644
--- a/libseahorse/seahorse-collection.c
+++ b/libseahorse/seahorse-collection.c
@@ -255,11 +255,20 @@ seahorse_collection_get_objects (GcrCollection *collection)
 	return objs;
 }
 
+static gboolean
+seahorse_collection_contains (GcrCollection *collection,
+                              GObject *object)
+{
+	SeahorseCollection *self = SEAHORSE_COLLECTION (collection);
+	return g_hash_table_lookup (self->pv->objects, object) ? TRUE : FALSE;
+}
+
 static void
 seahorse_collection_iface_init (GcrCollectionIface *iface)
 {
 	iface->get_length = seahorse_collection_get_length;
 	iface->get_objects = seahorse_collection_get_objects;
+	iface->contains = seahorse_collection_contains;
 }
 
 SeahorseCollection *
@@ -276,16 +285,6 @@ seahorse_collection_new_for_predicate (SeahorsePredicate *pred,
 	return collection;
 }
 
-gboolean
-seahorse_collection_has_object (SeahorseCollection *self,
-                                SeahorseObject *object)
-{
-	if (g_hash_table_lookup (self->pv->objects, object))
-		return TRUE;
-
-	return FALSE;
-}
-
 void
 seahorse_collection_refresh (SeahorseCollection *self)
 {
diff --git a/libseahorse/seahorse-collection.h b/libseahorse/seahorse-collection.h
index ad8c004..6b20eb7 100644
--- a/libseahorse/seahorse-collection.h
+++ b/libseahorse/seahorse-collection.h
@@ -56,9 +56,6 @@ SeahorseCollection * seahorse_collection_new_for_predicate    (SeahorsePredicate
 
 SeahorsePredicate *  seahorse_collection_get_predicate        (SeahorseCollection *self);
 
-gboolean             seahorse_collection_has_object           (SeahorseCollection *self,
-                                                               SeahorseObject *object);
-
 void                 seahorse_collection_refresh              (SeahorseCollection *self);
 
 #endif /* __SEAHORSE_COLLECTION_H__ */
diff --git a/pgp/seahorse-pgp-key.c b/pgp/seahorse-pgp-key.c
index dc39574..e3d23c7 100644
--- a/pgp/seahorse-pgp-key.c
+++ b/pgp/seahorse-pgp-key.c
@@ -398,11 +398,22 @@ seahorse_pgp_key_collection_get_objects (GcrCollection *collection)
 	return g_list_copy (self->pv->uids ? self->pv->uids->next : NULL);
 }
 
+static gboolean
+seahorse_pgp_key_collection_contains (GcrCollection *collection,
+                                      GObject *object)
+{
+	SeahorsePgpKey *self = SEAHORSE_PGP_KEY (collection);
+
+	/* First UID is displayed as the key itself */
+	return g_list_find (self->pv->uids ? self->pv->uids->next : NULL, object) != NULL;
+}
+
 static void
 seahorse_pgp_key_collection_iface_init (GcrCollectionIface *iface)
 {
 	iface->get_length = seahorse_pgp_key_collection_get_length;
 	iface->get_objects = seahorse_pgp_key_collection_get_objects;
+	iface->contains = seahorse_pgp_key_collection_contains;
 }
 
 
diff --git a/src/seahorse-key-manager.c b/src/seahorse-key-manager.c
index ff923c0..8577c65 100644
--- a/src/seahorse-key-manager.c
+++ b/src/seahorse-key-manager.c
@@ -139,7 +139,8 @@ get_tab_for_object (SeahorseKeyManager* self, SeahorseObject* obj)
 	
 	for (i = 0; i < TAB_NUM_TABS; ++i) {
 		TabInfo* tab = &self->pv->tabs[i];
-		if (seahorse_collection_has_object (tab->collection, obj))
+		if (gcr_collection_contains (GCR_COLLECTION (tab->collection),
+		                             G_OBJECT (obj)))
 			return tab;
 	}
 	



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