113 lines
2.7 KiB
C
113 lines
2.7 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-batch.h"
|
|
|
|
/**
|
|
* SECTION: vn-batch
|
|
* @Short_description: a group of objects
|
|
* @Title: VnBatch
|
|
*
|
|
* A group of GObjects.
|
|
*/
|
|
|
|
//+++++++++++++++++++++++++++++++++++++++++++++++++++ Methods
|
|
|
|
/**
|
|
* vn_batch_add:
|
|
* @obj: a #VnBatch
|
|
* @child: a #GObject
|
|
*
|
|
* Adds a child identified whith @id to the group.
|
|
**/
|
|
void vn_batch_add (VnBatch * obj, GObject * child)
|
|
{
|
|
g_return_if_fail (VN_IS_BATCH (obj));
|
|
g_return_if_fail (G_IS_OBJECT (child));
|
|
|
|
obj->objects = g_list_prepend (obj->objects, child);
|
|
}
|
|
|
|
/**
|
|
* vn_batch_remove:
|
|
* @obj: a #VnBatch
|
|
* @child: a #GObject contained by @obj
|
|
*
|
|
* Removes a child from the group.
|
|
**/
|
|
void vn_batch_remove (VnBatch * obj, GObject * child)
|
|
{
|
|
g_return_if_fail (VN_IS_BATCH (obj));
|
|
|
|
obj->objects = g_list_remove (obj->objects, child);
|
|
}
|
|
|
|
/**
|
|
* vn_batch_get_objects:
|
|
* @obj: a #VnBatch
|
|
*
|
|
* Returns all the #GObject<!-- -->s in @obj.
|
|
*
|
|
* Return value: (transfer container) (element-type GObject): a #GList with all
|
|
* the objects, that must be freed with #g_list_free
|
|
**/
|
|
GList * vn_batch_get_objects (VnBatch * obj)
|
|
{
|
|
g_return_val_if_fail (VN_IS_BATCH (obj), NULL);
|
|
|
|
return g_list_copy (obj->objects);
|
|
}
|
|
|
|
static void vn_batch_buildable_add_child (GtkBuildable * obj,
|
|
GtkBuilder * builder, GObject * child, const gchar * type)
|
|
{
|
|
vn_batch_add (VN_BATCH (obj), child);
|
|
}
|
|
|
|
//+++++++++++++++++++++++++++++++++++++++++++++++++++ Class
|
|
|
|
static void vn_batch_init (VnBatch * obj)
|
|
{
|
|
obj->objects = NULL;
|
|
}
|
|
|
|
static void vn_batch_finalize (VnBatch * obj)
|
|
{
|
|
GObjectClass * parent;
|
|
parent = g_type_class_peek_parent (VN_BATCH_GET_CLASS (obj));
|
|
|
|
g_list_free (obj->objects);
|
|
|
|
parent->finalize (G_OBJECT (obj));
|
|
}
|
|
|
|
static void vn_batch_class_init (VnBatchClass * klass)
|
|
{
|
|
GObjectClass * k = G_OBJECT_CLASS (klass);
|
|
k->finalize = (GObjectFinalizeFunc) vn_batch_finalize;
|
|
}
|
|
|
|
static void vn_batch_buildable_interface_init (GtkBuildableIface * iface)
|
|
{
|
|
iface->add_child = vn_batch_buildable_add_child;
|
|
}
|
|
|
|
G_DEFINE_TYPE_WITH_CODE (VnBatch, vn_batch, G_TYPE_OBJECT,
|
|
G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE,
|
|
vn_batch_buildable_interface_init)
|
|
);
|