|
Packit |
b00eeb |
/*
|
|
Packit |
b00eeb |
* gnome-keyring
|
|
Packit |
b00eeb |
*
|
|
Packit |
b00eeb |
* Copyright (C) 2010 Stefan Walter
|
|
Packit |
b00eeb |
*
|
|
Packit |
b00eeb |
* This program is free software; you can redistribute it and/or modify
|
|
Packit |
b00eeb |
* it under the terms of the GNU Lesser General Public License as
|
|
Packit |
b00eeb |
* published by the Free Software Foundation; either version 2.1 of
|
|
Packit |
b00eeb |
* the License, or (at your option) any later version.
|
|
Packit |
b00eeb |
*
|
|
Packit |
b00eeb |
* This program is distributed in the hope that it will be useful, but
|
|
Packit |
b00eeb |
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit |
b00eeb |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Packit |
b00eeb |
* Lesser General Public License for more details.
|
|
Packit |
b00eeb |
*
|
|
Packit |
b00eeb |
* You should have received a copy of the GNU Lesser General Public
|
|
Packit |
b00eeb |
* License along with this program; if not, see <http://www.gnu.org/licenses/>.
|
|
Packit |
b00eeb |
*/
|
|
Packit |
b00eeb |
|
|
Packit |
b00eeb |
#include "config.h"
|
|
Packit |
b00eeb |
|
|
Packit |
b00eeb |
#include "gcr-collection.h"
|
|
Packit |
b00eeb |
|
|
Packit |
b00eeb |
/**
|
|
Packit |
b00eeb |
* SECTION:gcr-collection
|
|
Packit |
b00eeb |
* @title: GcrCollection
|
|
Packit |
b00eeb |
* @short_description: A collection of objects.
|
|
Packit |
b00eeb |
*
|
|
Packit |
b00eeb |
* A #GcrCollection is used to group a set of objects. This is an abstract
|
|
Packit |
b00eeb |
* interface which can be used to determine which objects show up in a selector
|
|
Packit |
b00eeb |
* or other user interface element.
|
|
Packit |
b00eeb |
*
|
|
Packit |
b00eeb |
* Use gcr_simple_collection_new() to create a concrete implementation of this
|
|
Packit |
b00eeb |
* interface which you can add objects to.
|
|
Packit |
b00eeb |
*/
|
|
Packit |
b00eeb |
|
|
Packit |
b00eeb |
/**
|
|
Packit |
b00eeb |
* GcrCollection:
|
|
Packit |
b00eeb |
*
|
|
Packit |
b00eeb |
* A #GcrCollection is used to group a set of objects.
|
|
Packit |
b00eeb |
*/
|
|
Packit |
b00eeb |
|
|
Packit |
b00eeb |
enum {
|
|
Packit |
b00eeb |
ADDED,
|
|
Packit |
b00eeb |
REMOVED,
|
|
Packit |
b00eeb |
LAST_SIGNAL,
|
|
Packit |
b00eeb |
};
|
|
Packit |
b00eeb |
|
|
Packit |
b00eeb |
static guint signals[LAST_SIGNAL] = { 0 };
|
|
Packit |
b00eeb |
|
|
Packit |
b00eeb |
|
|
Packit |
b00eeb |
typedef GcrCollectionIface GcrCollectionInterface;
|
|
Packit |
b00eeb |
|
|
Packit |
b00eeb |
G_DEFINE_INTERFACE (GcrCollection, gcr_collection, G_TYPE_OBJECT);
|
|
Packit |
b00eeb |
|
|
Packit |
b00eeb |
static void
|
|
Packit |
b00eeb |
gcr_collection_default_init (GcrCollectionIface *iface)
|
|
Packit |
b00eeb |
{
|
|
Packit |
b00eeb |
static volatile gsize initialized = 0;
|
|
Packit |
b00eeb |
|
|
Packit |
b00eeb |
if (g_once_init_enter (&initialized)) {
|
|
Packit |
b00eeb |
|
|
Packit |
b00eeb |
/**
|
|
Packit |
b00eeb |
* GcrCollection::added:
|
|
Packit |
b00eeb |
* @self: the collection
|
|
Packit |
b00eeb |
* @object: (type GObject.Object): object that was added
|
|
Packit |
b00eeb |
*
|
|
Packit |
b00eeb |
* This signal is emitted when an object is added to the collection.
|
|
Packit |
b00eeb |
*/
|
|
Packit |
b00eeb |
signals[ADDED] = g_signal_new ("added", GCR_TYPE_COLLECTION,
|
|
Packit |
b00eeb |
G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GcrCollectionIface, added),
|
|
Packit |
b00eeb |
NULL, NULL, g_cclosure_marshal_VOID__OBJECT,
|
|
Packit |
b00eeb |
G_TYPE_NONE, 1, G_TYPE_OBJECT);
|
|
Packit |
b00eeb |
|
|
Packit |
b00eeb |
/**
|
|
Packit |
b00eeb |
* GcrCollection::removed:
|
|
Packit |
b00eeb |
* @self: the collection
|
|
Packit |
b00eeb |
* @object: (type GObject.Object): object that was removed
|
|
Packit |
b00eeb |
*
|
|
Packit |
b00eeb |
* This signal is emitted when an object is removed from the collection.
|
|
Packit |
b00eeb |
*/
|
|
Packit |
b00eeb |
signals[REMOVED] = g_signal_new ("removed", GCR_TYPE_COLLECTION,
|
|
Packit |
b00eeb |
G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GcrCollectionIface, removed),
|
|
Packit |
b00eeb |
NULL, NULL, g_cclosure_marshal_VOID__OBJECT,
|
|
Packit |
b00eeb |
G_TYPE_NONE, 1, G_TYPE_OBJECT);
|
|
Packit |
b00eeb |
|
|
Packit |
b00eeb |
g_once_init_leave (&initialized, 1);
|
|
Packit |
b00eeb |
}
|
|
Packit |
b00eeb |
}
|
|
Packit |
b00eeb |
|
|
Packit |
b00eeb |
/* -----------------------------------------------------------------------------
|
|
Packit |
b00eeb |
* PUBLIC
|
|
Packit |
b00eeb |
*/
|
|
Packit |
b00eeb |
|
|
Packit |
b00eeb |
|
|
Packit |
b00eeb |
/**
|
|
Packit |
b00eeb |
* gcr_collection_get_length:
|
|
Packit |
b00eeb |
* @self: The collection
|
|
Packit |
b00eeb |
*
|
|
Packit |
b00eeb |
* Get the number of objects in this collection.
|
|
Packit |
b00eeb |
*
|
|
Packit |
b00eeb |
* Returns: The number of objects.
|
|
Packit |
b00eeb |
*/
|
|
Packit |
b00eeb |
guint
|
|
Packit |
b00eeb |
gcr_collection_get_length (GcrCollection *self)
|
|
Packit |
b00eeb |
{
|
|
Packit |
b00eeb |
g_return_val_if_fail (GCR_IS_COLLECTION (self), 0);
|
|
Packit |
b00eeb |
g_return_val_if_fail (GCR_COLLECTION_GET_INTERFACE (self)->get_length, 0);
|
|
Packit |
b00eeb |
return GCR_COLLECTION_GET_INTERFACE (self)->get_length (self);
|
|
Packit |
b00eeb |
}
|
|
Packit |
b00eeb |
|
|
Packit |
b00eeb |
/**
|
|
Packit |
b00eeb |
* gcr_collection_get_objects:
|
|
Packit |
b00eeb |
* @self: The collection
|
|
Packit |
b00eeb |
*
|
|
Packit |
b00eeb |
* Get a list of the objects in this collection.
|
|
Packit |
b00eeb |
*
|
|
Packit |
b00eeb |
* Returns: (transfer container) (element-type GObject.Object): a list of the objects
|
|
Packit |
b00eeb |
* in this collection, which should be freed with g_list_free()
|
|
Packit |
b00eeb |
*/
|
|
Packit |
b00eeb |
GList*
|
|
Packit |
b00eeb |
gcr_collection_get_objects (GcrCollection *self)
|
|
Packit |
b00eeb |
{
|
|
Packit |
b00eeb |
g_return_val_if_fail (GCR_IS_COLLECTION (self), 0);
|
|
Packit |
b00eeb |
g_return_val_if_fail (GCR_COLLECTION_GET_INTERFACE (self)->get_objects, 0);
|
|
Packit |
b00eeb |
return GCR_COLLECTION_GET_INTERFACE (self)->get_objects (self);
|
|
Packit |
b00eeb |
}
|
|
Packit |
b00eeb |
|
|
Packit |
b00eeb |
/**
|
|
Packit |
b00eeb |
* gcr_collection_contains:
|
|
Packit |
b00eeb |
* @self: the collection
|
|
Packit |
b00eeb |
* @object: object to check
|
|
Packit |
b00eeb |
*
|
|
Packit |
b00eeb |
* Check whether the collection contains an object or not.
|
|
Packit |
b00eeb |
*
|
|
Packit |
b00eeb |
* Returns: whether the collection contains this object
|
|
Packit |
b00eeb |
*/
|
|
Packit |
b00eeb |
gboolean
|
|
Packit |
b00eeb |
gcr_collection_contains (GcrCollection *self,
|
|
Packit |
b00eeb |
GObject *object)
|
|
Packit |
b00eeb |
{
|
|
Packit |
b00eeb |
g_return_val_if_fail (GCR_IS_COLLECTION (self), FALSE);
|
|
Packit |
b00eeb |
g_return_val_if_fail (G_IS_OBJECT (object), FALSE);
|
|
Packit |
b00eeb |
g_return_val_if_fail (GCR_COLLECTION_GET_INTERFACE (self)->contains, FALSE);
|
|
Packit |
b00eeb |
return GCR_COLLECTION_GET_INTERFACE (self)->contains (self, object);
|
|
Packit |
b00eeb |
}
|
|
Packit |
b00eeb |
|
|
Packit |
b00eeb |
/**
|
|
Packit |
b00eeb |
* gcr_collection_emit_added:
|
|
Packit |
b00eeb |
* @self: The collection
|
|
Packit |
b00eeb |
* @object: The object that was added
|
|
Packit |
b00eeb |
*
|
|
Packit |
b00eeb |
* Emit the #GcrCollection::added signal for the given object. This function
|
|
Packit |
b00eeb |
* is used by implementors of this interface.
|
|
Packit |
b00eeb |
*/
|
|
Packit |
b00eeb |
void
|
|
Packit |
b00eeb |
gcr_collection_emit_added (GcrCollection *self, GObject *object)
|
|
Packit |
b00eeb |
{
|
|
Packit |
b00eeb |
g_return_if_fail (GCR_IS_COLLECTION (self));
|
|
Packit |
b00eeb |
g_signal_emit (self, signals[ADDED], 0, object);
|
|
Packit |
b00eeb |
}
|
|
Packit |
b00eeb |
|
|
Packit |
b00eeb |
/**
|
|
Packit |
b00eeb |
* gcr_collection_emit_removed:
|
|
Packit |
b00eeb |
* @self: The collection
|
|
Packit |
b00eeb |
* @object: The object that was removed
|
|
Packit |
b00eeb |
*
|
|
Packit |
b00eeb |
* Emit the #GcrCollection::removed signal for the given object. This function
|
|
Packit |
b00eeb |
* is used by implementors of this interface.
|
|
Packit |
b00eeb |
*/
|
|
Packit |
b00eeb |
void
|
|
Packit |
b00eeb |
gcr_collection_emit_removed (GcrCollection *self, GObject *object)
|
|
Packit |
b00eeb |
{
|
|
Packit |
b00eeb |
g_return_if_fail (GCR_IS_COLLECTION (self));
|
|
Packit |
b00eeb |
g_signal_emit (self, signals[REMOVED], 0, object);
|
|
Packit |
b00eeb |
}
|