2013-10-11 23:07:35 +00:00
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2014-02-11 12:16:39 +00:00
|
|
|
static void vn_batch_buildable_interface_init (GtkBuildableIface * iface);
|
|
|
|
|
|
|
|
G_DEFINE_TYPE_WITH_CODE (VnBatch, vn_batch, G_TYPE_OBJECT,
|
|
|
|
G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE,
|
|
|
|
vn_batch_buildable_interface_init)
|
|
|
|
);
|
|
|
|
|
2013-10-11 23:07:35 +00:00
|
|
|
//+++++++++++++++++++++++++++++++++++++++++++++++++++ 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);
|
2013-10-14 12:08:06 +00:00
|
|
|
obj->count++;
|
2013-10-11 23:07:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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);
|
2013-10-14 12:08:06 +00:00
|
|
|
obj->count--;
|
2013-10-11 23:07:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2013-10-14 12:08:06 +00:00
|
|
|
* vn_batch_get_objects_list:
|
2013-10-11 23:07:35 +00:00
|
|
|
* @obj: a #VnBatch
|
|
|
|
*
|
2013-12-13 09:07:52 +00:00
|
|
|
* Returns all the #GObject<!-- -->s in @obj, copying the list. This method is
|
|
|
|
* mainly for internal use, use vn_batch_get_objects() instead if you don't need
|
|
|
|
* to do further use of the list of objects.
|
2013-10-11 23:07:35 +00:00
|
|
|
*
|
|
|
|
* Return value: (transfer container) (element-type GObject): a #GList with all
|
|
|
|
* the objects, that must be freed with #g_list_free
|
|
|
|
**/
|
2013-10-14 12:08:06 +00:00
|
|
|
GList * vn_batch_get_objects_list (VnBatch * obj)
|
2013-10-11 23:07:35 +00:00
|
|
|
{
|
|
|
|
g_return_val_if_fail (VN_IS_BATCH (obj), NULL);
|
|
|
|
|
|
|
|
return g_list_copy (obj->objects);
|
|
|
|
}
|
|
|
|
|
2013-10-14 12:08:06 +00:00
|
|
|
/**
|
|
|
|
* vn_batch_get_objects:
|
|
|
|
* @obj: a #VnBatch
|
|
|
|
*
|
|
|
|
* 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_batch_get_objects (VnBatch * obj)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (VN_IS_BATCH (obj), NULL);
|
|
|
|
|
|
|
|
return obj->objects;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* vn_batch_get_length:
|
|
|
|
* @obj: a #VnBatch
|
|
|
|
*
|
|
|
|
* Returns the number of childs currently contained in @obj.
|
|
|
|
*
|
|
|
|
* Return value: the number of childs
|
|
|
|
**/
|
|
|
|
guint vn_batch_get_length (VnBatch * obj)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (VN_IS_BATCH (obj), 0);
|
|
|
|
|
|
|
|
return obj->count;
|
|
|
|
}
|
|
|
|
|
2013-10-11 23:07:35 +00:00
|
|
|
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;
|
2013-10-14 12:08:06 +00:00
|
|
|
obj->count = 0;
|
2013-10-11 23:07:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void vn_batch_finalize (VnBatch * obj)
|
|
|
|
{
|
2013-12-13 09:07:52 +00:00
|
|
|
GObjectClass * parent = g_type_class_peek_parent (VN_BATCH_GET_CLASS (obj));
|
2013-10-11 23:07:35 +00:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|