diff options
-rw-r--r-- | docs/reference/gcr/gcr-sections.txt | 5 | ||||
-rw-r--r-- | gcr/gcr-collection.c | 18 | ||||
-rw-r--r-- | gcr/gcr-collection.h | 10 | ||||
-rw-r--r-- | gcr/gcr-deprecated.h | 4 | ||||
-rw-r--r-- | gcr/gcr-gnupg-collection.c | 17 | ||||
-rw-r--r-- | gcr/gcr-simple-collection.c | 14 | ||||
-rw-r--r-- | gcr/gcr-simple-collection.h | 3 |
7 files changed, 63 insertions, 8 deletions
diff --git a/docs/reference/gcr/gcr-sections.txt b/docs/reference/gcr/gcr-sections.txt index e69ad898..46a6a921 100644 --- a/docs/reference/gcr/gcr-sections.txt +++ b/docs/reference/gcr/gcr-sections.txt @@ -228,10 +228,11 @@ GCR_TYPE_COMPARABLE <SECTION> <FILE>gcr-collection</FILE> GcrCollection -gcr_collection_emit_added -gcr_collection_emit_removed gcr_collection_get_length gcr_collection_get_objects +gcr_collection_contains +gcr_collection_emit_added +gcr_collection_emit_removed <SUBSECTION Standard> gcr_collection_get_type GCR_COLLECTION diff --git a/gcr/gcr-collection.c b/gcr/gcr-collection.c index 5493bbcf..aa7a60f7 100644 --- a/gcr/gcr-collection.c +++ b/gcr/gcr-collection.c @@ -142,6 +142,24 @@ gcr_collection_get_objects (GcrCollection *self) } /** + * gcr_collection_contains: + * @self: the collection + * + * Check whether the collection contains an object or not. + * + * Returns: whether the collection contains this object + */ +gboolean +gcr_collection_contains (GcrCollection *self, + GObject *object) +{ + g_return_val_if_fail (GCR_IS_COLLECTION (self), FALSE); + g_return_val_if_fail (G_IS_OBJECT (object), FALSE); + g_return_val_if_fail (GCR_COLLECTION_GET_INTERFACE (self)->contains, FALSE); + return GCR_COLLECTION_GET_INTERFACE (self)->contains (self, object); +} + +/** * gcr_collection_emit_added: * @self: The collection * @object: The object that was added diff --git a/gcr/gcr-collection.h b/gcr/gcr-collection.h index 4e572c6d..2616394c 100644 --- a/gcr/gcr-collection.h +++ b/gcr/gcr-collection.h @@ -45,9 +45,12 @@ struct _GcrCollectionIface { void (*removed) (GcrCollection *self, GObject *object); /* virtual */ - guint (*get_length) (GcrCollection *self); + guint (*get_length) (GcrCollection *self); - GList* (*get_objects) (GcrCollection *self); + GList* (*get_objects) (GcrCollection *self); + + gboolean (*contains) (GcrCollection *self, + GObject *object); /*< private >*/ gpointer dummy1; @@ -65,6 +68,9 @@ guint gcr_collection_get_length (GcrCollection *self); GList* gcr_collection_get_objects (GcrCollection *self); +gboolean gcr_collection_contains (GcrCollection *self, + GObject *object); + void gcr_collection_emit_added (GcrCollection *self, GObject *object); diff --git a/gcr/gcr-deprecated.h b/gcr/gcr-deprecated.h index bb886298..3eb0a62c 100644 --- a/gcr/gcr-deprecated.h +++ b/gcr/gcr-deprecated.h @@ -35,6 +35,7 @@ #include "gcr-importer.h" #include "gcr-parser.h" +#include "gcr-simple-collection.h" #include "gcr-viewer.h" #ifndef GCR_DISABLE_DEPRECATED @@ -54,6 +55,9 @@ void gcr_importer_set_parser (GcrImporter *self GQuark gcr_error_get_domain (void) G_GNUC_CONST; +gboolean gcr_simple_collection_contains (GcrSimpleCollection *self, + GObject *object); + #endif /* GCR_DISABLE_DEPRECATED */ G_END_DECLS diff --git a/gcr/gcr-gnupg-collection.c b/gcr/gcr-gnupg-collection.c index 9a64ebdf..26405a47 100644 --- a/gcr/gcr-gnupg-collection.c +++ b/gcr/gcr-gnupg-collection.c @@ -169,11 +169,28 @@ gcr_gnupg_collection_real_get_objects (GcrCollection *coll) return g_hash_table_get_values (self->pv->items); } +static gboolean +gcr_gnupg_collection_real_contains (GcrCollection *collection, + GObject *object) +{ + GcrGnupgCollection *self = GCR_GNUPG_COLLECTION (collection); + GcrGnupgKey *key; + + if (!GCR_IS_GNUPG_KEY (object)) + return FALSE; + key = g_hash_table_lookup (self->pv->items, + _gcr_gnupg_key_get_keyid (GCR_GNUPG_KEY (object))); + if (key != NULL && G_OBJECT (key) == object) + return TRUE; + return FALSE; +} + static void _gcr_collection_iface (GcrCollectionIface *iface) { iface->get_length = gcr_gnupg_collection_real_get_length; iface->get_objects = gcr_gnupg_collection_real_get_objects; + iface->contains = gcr_gnupg_collection_real_contains; } /** diff --git a/gcr/gcr-simple-collection.c b/gcr/gcr-simple-collection.c index fe0788f0..17e1f1c7 100644 --- a/gcr/gcr-simple-collection.c +++ b/gcr/gcr-simple-collection.c @@ -22,6 +22,7 @@ #include "config.h" #include "gcr-collection.h" +#include "gcr-deprecated.h" #include "gcr-internal.h" #include "gcr-simple-collection.h" @@ -119,11 +120,20 @@ gcr_simple_collection_real_get_objects (GcrCollection *coll) return g_hash_table_get_keys (self->pv->items); } +static gboolean +gcr_simple_collection_real_contains (GcrCollection *collection, + GObject *object) +{ + GcrSimpleCollection *self = GCR_SIMPLE_COLLECTION (collection); + return g_hash_table_lookup (self->pv->items, object) ? TRUE : FALSE; +} + static void gcr_collection_iface (GcrCollectionIface *iface) { iface->get_length = gcr_simple_collection_real_get_length; iface->get_objects = gcr_simple_collection_real_get_objects; + iface->contains = gcr_simple_collection_real_contains; } /* ----------------------------------------------------------------------------- @@ -187,6 +197,8 @@ gcr_simple_collection_remove (GcrSimpleCollection *self, GObject *object) * * Check if the collection contains a certain object. * + * Deprecated: use gcr_collection_contains() instead + * * Returns: %TRUE if the collection contains the object. */ gboolean @@ -194,5 +206,5 @@ gcr_simple_collection_contains (GcrSimpleCollection *self, GObject *object) { g_return_val_if_fail (GCR_IS_SIMPLE_COLLECTION (self), FALSE); g_return_val_if_fail (G_IS_OBJECT (object), FALSE); - return g_hash_table_lookup (self->pv->items, object) ? TRUE : FALSE; + return gcr_collection_contains (GCR_COLLECTION (self), object); } diff --git a/gcr/gcr-simple-collection.h b/gcr/gcr-simple-collection.h index 3ee0947a..52def96e 100644 --- a/gcr/gcr-simple-collection.h +++ b/gcr/gcr-simple-collection.h @@ -61,9 +61,6 @@ void gcr_simple_collection_add (GcrSimpleColl void gcr_simple_collection_remove (GcrSimpleCollection *self, GObject *object); -gboolean gcr_simple_collection_contains (GcrSimpleCollection *self, - GObject *object); - G_END_DECLS #endif /* __GCR_SIMPLE_COLLECTION_H__ */ |