4
* Copyright (C) 2010 Stefan Walter
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU Lesser General Public License as
8
* published by the Free Software Foundation; either version 2.1 of
9
* the License, or (at your option) any later version.
11
* This program is distributed in the hope that it will be useful, but
12
* WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
* Lesser General Public License for more details.
16
* You should have received a copy of the GNU Lesser General Public
17
* License along with this program; if not, write to the Free Software
18
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
24
#include "gcr-collection.h"
27
* SECTION:gcr-collection
28
* @title: GcrCollection
29
* @short_description: A collection of objects.
31
* A #GcrCollection is used to group a set of objects. This is an abstract
32
* interface which can be used to determine which objects show up in a selector
33
* or other user interface element.
35
* Use gcr_simple_collection_new() to create a concrete implementation of this
36
* interface which you can add objects to.
42
* A #GcrCollection is used to group a set of objects.
51
static guint signals[LAST_SIGNAL] = { 0 };
54
typedef GcrCollectionIface GcrCollectionInterface;
56
G_DEFINE_INTERFACE (GcrCollection, gcr_collection, G_TYPE_OBJECT);
59
gcr_collection_default_init (GcrCollectionIface *iface)
61
static volatile gsize initialized = 0;
63
if (g_once_init_enter (&initialized)) {
66
* GcrCollection::added:
67
* @self: the collection
68
* @object: (type GLib.Object): object that was added
70
* This signal is emitted when an object is added to the collection.
72
signals[ADDED] = g_signal_new ("added", GCR_TYPE_COLLECTION,
73
G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GcrCollectionIface, added),
74
NULL, NULL, g_cclosure_marshal_VOID__OBJECT,
75
G_TYPE_NONE, 1, G_TYPE_OBJECT);
78
* GcrCollection::removed:
79
* @self: the collection
80
* @object: (type GLib.Object): object that was removed
82
* This signal is emitted when an object is removed from the collection.
84
signals[REMOVED] = g_signal_new ("removed", GCR_TYPE_COLLECTION,
85
G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GcrCollectionIface, removed),
86
NULL, NULL, g_cclosure_marshal_VOID__OBJECT,
87
G_TYPE_NONE, 1, G_TYPE_OBJECT);
89
g_once_init_leave (&initialized, 1);
93
/* -----------------------------------------------------------------------------
99
* gcr_collection_get_length:
100
* @self: The collection
102
* Get the number of objects in this collection.
104
* Returns: The number of objects.
107
gcr_collection_get_length (GcrCollection *self)
109
g_return_val_if_fail (GCR_IS_COLLECTION (self), 0);
110
g_return_val_if_fail (GCR_COLLECTION_GET_INTERFACE (self)->get_length, 0);
111
return GCR_COLLECTION_GET_INTERFACE (self)->get_length (self);
115
* gcr_collection_get_objects:
116
* @self: The collection
118
* Get a list of the objects in this collection.
120
* Returns: (transfer container) (element-type GLib.Object): a list of the objects
121
* in this collection, which should be freed with g_list_free()
124
gcr_collection_get_objects (GcrCollection *self)
126
g_return_val_if_fail (GCR_IS_COLLECTION (self), 0);
127
g_return_val_if_fail (GCR_COLLECTION_GET_INTERFACE (self)->get_objects, 0);
128
return GCR_COLLECTION_GET_INTERFACE (self)->get_objects (self);
132
* gcr_collection_contains:
133
* @self: the collection
134
* @object: object to check
136
* Check whether the collection contains an object or not.
138
* Returns: whether the collection contains this object
141
gcr_collection_contains (GcrCollection *self,
144
g_return_val_if_fail (GCR_IS_COLLECTION (self), FALSE);
145
g_return_val_if_fail (G_IS_OBJECT (object), FALSE);
146
g_return_val_if_fail (GCR_COLLECTION_GET_INTERFACE (self)->contains, FALSE);
147
return GCR_COLLECTION_GET_INTERFACE (self)->contains (self, object);
151
* gcr_collection_emit_added:
152
* @self: The collection
153
* @object: The object that was added
155
* Emit the #GcrCollection::added signal for the given object. This function
156
* is used by implementors of this interface.
159
gcr_collection_emit_added (GcrCollection *self, GObject *object)
161
g_return_if_fail (GCR_IS_COLLECTION (self));
162
g_signal_emit (self, signals[ADDED], 0, object);
166
* gcr_collection_emit_removed:
167
* @self: The collection
168
* @object: The object that was removed
170
* Emit the #GcrCollection::removed signal for the given object. This function
171
* is used by implementors of this interface.
174
gcr_collection_emit_removed (GcrCollection *self, GObject *object)
176
g_return_if_fail (GCR_IS_COLLECTION (self));
177
g_signal_emit (self, signals[REMOVED], 0, object);