150 lines
3.5 KiB
C
150 lines
3.5 KiB
C
/*
|
|
* Copyright (C) 2012 - Juan Ferrer Toribio
|
|
*
|
|
* This program is free software: you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License as published by
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
#include "vn-set.h"
|
|
|
|
/**
|
|
* SECTION: vn-set
|
|
* @Short_description: a group of objects
|
|
* @Title: VnSet
|
|
*
|
|
* A group of GObjects.
|
|
*/
|
|
|
|
static void vn_set_buildable_interface_init (GtkBuildableIface * iface);
|
|
|
|
G_DEFINE_TYPE_WITH_CODE (VnSet, vn_set, G_TYPE_OBJECT,
|
|
G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE,
|
|
vn_set_buildable_interface_init)
|
|
);
|
|
|
|
//+++++++++++++++++++++++++++++++++++++++++++++++++++ Methods
|
|
|
|
/**
|
|
* vn_set_add:
|
|
* @obj: a #VnSet
|
|
* @child: a #GObject
|
|
*
|
|
* Adds a child identified whith @id to the group.
|
|
**/
|
|
void vn_set_add (VnSet * obj, GObject * child)
|
|
{
|
|
g_return_if_fail (VN_IS_SET (obj));
|
|
g_return_if_fail (G_IS_OBJECT (child));
|
|
|
|
obj->objects = g_list_prepend (obj->objects, child);
|
|
obj->count++;
|
|
}
|
|
|
|
/**
|
|
* vn_set_remove:
|
|
* @obj: a #VnSet
|
|
* @child: a #GObject contained by @obj
|
|
*
|
|
* Removes a child from the group.
|
|
**/
|
|
void vn_set_remove (VnSet * obj, GObject * child)
|
|
{
|
|
g_return_if_fail (VN_IS_SET (obj));
|
|
|
|
obj->objects = g_list_remove (obj->objects, child);
|
|
obj->count--;
|
|
}
|
|
|
|
/**
|
|
* vn_set_get_objects_list:
|
|
* @obj: a #VnSet
|
|
*
|
|
* Returns all the #GObject<!-- -->s in @obj, copying the list. This method is
|
|
* mainly for internal use, use vn_set_get_objects() instead if you don't need
|
|
* to do further use of the list of objects.
|
|
*
|
|
* Return value: (transfer container) (element-type GObject): a #GList with all
|
|
* the objects, that must be freed with #g_list_free
|
|
**/
|
|
GList * vn_set_get_objects_list (VnSet * obj)
|
|
{
|
|
g_return_val_if_fail (VN_IS_SET (obj), NULL);
|
|
|
|
return g_list_copy (obj->objects);
|
|
}
|
|
|
|
/**
|
|
* vn_set_get_objects:
|
|
* @obj: a #VnSet
|
|
*
|
|
* Returns all the #GObject<!-- -->s in @obj.
|
|
*
|
|
* Return value: (transfer none) (element-type GObject): a #GList with all
|
|
* the objects, that must not be freed
|
|
**/
|
|
const GList * vn_set_get_objects (VnSet * obj)
|
|
{
|
|
g_return_val_if_fail (VN_IS_SET (obj), NULL);
|
|
|
|
return obj->objects;
|
|
}
|
|
|
|
/**
|
|
* vn_set_get_length:
|
|
* @obj: a #VnSet
|
|
*
|
|
* Returns the number of childs currently contained in @obj.
|
|
*
|
|
* Return value: the number of childs
|
|
**/
|
|
guint vn_set_get_length (VnSet * obj)
|
|
{
|
|
g_return_val_if_fail (VN_IS_SET (obj), 0);
|
|
|
|
return obj->count;
|
|
}
|
|
|
|
static void vn_set_buildable_add_child (GtkBuildable * obj,
|
|
GtkBuilder * builder, GObject * child, const gchar * type)
|
|
{
|
|
vn_set_add (VN_SET (obj), child);
|
|
}
|
|
|
|
//+++++++++++++++++++++++++++++++++++++++++++++++++++ Class
|
|
|
|
static void vn_set_init (VnSet * obj)
|
|
{
|
|
obj->objects = NULL;
|
|
obj->count = 0;
|
|
}
|
|
|
|
static void vn_set_finalize (VnSet * obj)
|
|
{
|
|
GObjectClass * parent = g_type_class_peek_parent (VN_SET_GET_CLASS (obj));
|
|
|
|
g_list_free (obj->objects);
|
|
|
|
parent->finalize (G_OBJECT (obj));
|
|
}
|
|
|
|
static void vn_set_class_init (VnSetClass * klass)
|
|
{
|
|
GObjectClass * k = G_OBJECT_CLASS (klass);
|
|
k->finalize = (GObjectFinalizeFunc) vn_set_finalize;
|
|
}
|
|
|
|
static void vn_set_buildable_interface_init (GtkBuildableIface * iface)
|
|
{
|
|
iface->add_child = vn_set_buildable_add_child;
|
|
}
|