VnBatch renombrado a VnSet
This commit is contained in:
parent
1a2d0bdee0
commit
b6f58de70d
|
@ -14,8 +14,7 @@ public class Vn.[+FormClassName+] : Vn.Form
|
|||
|
||||
}
|
||||
|
||||
// Main routine of the [+FormClassName+] Form.
|
||||
public override void open (Gtk.Builder builder)
|
||||
public override void open ()
|
||||
{
|
||||
|
||||
}
|
||||
|
|
|
@ -14,7 +14,6 @@ public class Vn.[+ClassName+] : Vn.Mod
|
|||
|
||||
}
|
||||
|
||||
// Main routine of the [+ClassName+] Module.
|
||||
public override void activate ()
|
||||
{
|
||||
|
||||
|
|
|
@ -15,7 +15,7 @@ libgladevn_la_LDFLAGS = -avoid-version
|
|||
libgladevn_la_SOURCES = \
|
||||
glade-vn.h \
|
||||
glade-vn.c \
|
||||
glade-vn-batch.c \
|
||||
glade-vn-set.c \
|
||||
glade-db-model.c \
|
||||
glade-db-model-editor.h \
|
||||
glade-db-model-editor.c \
|
||||
|
|
|
@ -683,6 +683,7 @@ static void glade_list_eprop_create_input (GladeListEProp * obj, GtkWidget * box
|
|||
gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scroll), GTK_SHADOW_IN);
|
||||
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scroll),
|
||||
GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
|
||||
g_object_set (G_OBJECT (scroll), "height-request", 50, NULL);
|
||||
gtk_box_pack_start (GTK_BOX (box), scroll, TRUE, TRUE, 0);
|
||||
|
||||
obj->view = GTK_TREE_VIEW (gtk_tree_view_new ());
|
||||
|
@ -747,7 +748,7 @@ void glade_db_model_write_widget (GladeWidgetAdaptor * adaptor,
|
|||
glade_property_write (prop, context, node);
|
||||
|
||||
GWA_GET_CLASS (G_TYPE_OBJECT)->write_widget (adaptor, widget, context, node);
|
||||
//FIXME
|
||||
|
||||
prop = glade_widget_get_property (widget, "links");
|
||||
// Custom tag for the "links" property, e.g.:
|
||||
// <links>
|
||||
|
@ -794,7 +795,7 @@ void glade_db_model_write_widget (GladeWidgetAdaptor * adaptor,
|
|||
}
|
||||
|
||||
prop = glade_widget_get_property (widget, "batch");
|
||||
// Custom tag for the "links" property, e.g.:
|
||||
// Custom tag for the "batch" property, e.g.:
|
||||
// <batch>
|
||||
// <holder id="name" param="param1"/>
|
||||
// </batch>
|
||||
|
|
|
@ -55,18 +55,18 @@ static void glade_eprop_model_name_changed (GladeProject * project,
|
|||
static GladeWidget * glade_model_create (GladeProperty * prop)
|
||||
{
|
||||
gboolean use = FALSE;
|
||||
VnBatch * batch;
|
||||
VnSet * batch;
|
||||
GladeWidget * batch_w;
|
||||
GladeProject * project = glade_widget_get_project (glade_property_get_widget (prop));
|
||||
const GList * l, * n, * objects = glade_project_get_objects (project);
|
||||
|
||||
for (n = objects; n; n = n->next)
|
||||
if (VN_IS_BATCH (n->data))
|
||||
if (VN_IS_SET (n->data))
|
||||
{
|
||||
batch = n->data;
|
||||
use = TRUE;
|
||||
|
||||
for (l = vn_batch_get_objects (batch); l; l = l->next)
|
||||
for (l = vn_set_get_objects (batch); l; l = l->next)
|
||||
if (!DB_IS_MODEL (l->data))
|
||||
{
|
||||
use = FALSE;
|
||||
|
@ -80,7 +80,7 @@ static GladeWidget * glade_model_create (GladeProperty * prop)
|
|||
if (!use)
|
||||
{
|
||||
batch_w = glade_command_create
|
||||
(glade_widget_adaptor_get_by_type (VN_TYPE_BATCH), NULL, NULL, project);
|
||||
(glade_widget_adaptor_get_by_type (VN_TYPE_SET), NULL, NULL, project);
|
||||
glade_widget_set_name (batch_w, "models");
|
||||
}
|
||||
else
|
||||
|
@ -92,72 +92,59 @@ static GladeWidget * glade_model_create (GladeProperty * prop)
|
|||
|
||||
/*
|
||||
* glade_eprop_model_show_dialog:
|
||||
* @button:(allow-none): a #GtkButton or @NULL
|
||||
* @object: a #GladeEditorPropery or a #GladeWidget
|
||||
* @button:(allow-none): a #GtkButton
|
||||
* @eprop: a #GladeEditorPropery
|
||||
*
|
||||
* Opens a dialog to edit a #DbModel.
|
||||
* Can be called by a #GladeEditorProperty or by the "edit" action of a
|
||||
* #GladeWidgetAdaptor directly (in which case @button is %NULL and @obj is a
|
||||
* #GladeWidget).
|
||||
* Opens the dialog to edit the properties of a #DbModel.
|
||||
**/
|
||||
static void glade_eprop_model_show_dialog (GtkButton * button, GObject * object)
|
||||
static void glade_eprop_model_show_dialog (GtkButton * button, GladeEditorProperty * eprop)
|
||||
{
|
||||
gboolean created = FALSE;
|
||||
GObject * o;
|
||||
GtkWidget * box;
|
||||
GtkDialog * dialog;
|
||||
GladeWidget * widget;
|
||||
GladeWidgetAdaptor * adaptor;
|
||||
GladeEditable * editor;
|
||||
GladeProperty * p = NULL;
|
||||
GladeEditorProperty * eprop = NULL;
|
||||
GladeProperty * p = glade_editor_property_get_property (eprop);
|
||||
GObject * o = g_value_get_object (glade_property_inline_value (p));
|
||||
|
||||
if (GLADE_IS_EDITOR_PROPERTY (object))
|
||||
if (o && DB_IS_MODEL (o))
|
||||
widget = glade_widget_get_from_gobject (o);
|
||||
else
|
||||
{
|
||||
eprop = GLADE_EDITOR_PROPERTY (object);
|
||||
p = glade_editor_property_get_property (eprop);
|
||||
o = g_value_get_object (glade_property_inline_value (p));
|
||||
GValue val = G_VALUE_INIT;
|
||||
|
||||
if (o && DB_IS_MODEL (o))
|
||||
widget = glade_widget_get_from_gobject (o);
|
||||
else
|
||||
glade_command_push_group
|
||||
(_("Create and set a model for a DbModelHolder"));
|
||||
|
||||
widget = glade_model_create (p);
|
||||
created = TRUE;
|
||||
g_value_init (&val, DB_TYPE_MODEL);
|
||||
g_value_set_object (&val, glade_widget_get_object (widget));
|
||||
glade_command_set_property_value (p, &val);
|
||||
g_value_unset (&val);
|
||||
|
||||
glade_command_pop_group ();
|
||||
|
||||
glade_project_selection_set (glade_widget_get_project (widget),
|
||||
glade_widget_get_object (glade_property_get_widget (p)),
|
||||
TRUE);
|
||||
|
||||
if (!GLADE_EPROP_MODEL (eprop)->connected)
|
||||
{
|
||||
GValue val = G_VALUE_INIT;
|
||||
|
||||
glade_command_push_group
|
||||
(_("Create and set a model for a DbModelHolder"));
|
||||
|
||||
widget = glade_model_create (p);
|
||||
created = TRUE;
|
||||
g_value_init (&val, DB_TYPE_MODEL);
|
||||
g_value_set_object (&val, glade_widget_get_object (widget));
|
||||
glade_command_set_property_value (p, &val);
|
||||
g_value_unset (&val);
|
||||
|
||||
glade_command_pop_group ();
|
||||
|
||||
glade_project_selection_set (glade_widget_get_project (widget),
|
||||
glade_widget_get_object (glade_property_get_widget (p)),
|
||||
TRUE);
|
||||
|
||||
if (!GLADE_EPROP_MODEL (eprop)->connected)
|
||||
{
|
||||
g_signal_connect (glade_widget_get_project
|
||||
(glade_property_get_widget (p)), "widget-name-changed",
|
||||
G_CALLBACK (glade_eprop_model_name_changed), eprop);
|
||||
GLADE_EPROP_MODEL (eprop)->connected = TRUE;
|
||||
}
|
||||
g_signal_connect (glade_widget_get_project
|
||||
(glade_property_get_widget (p)), "widget-name-changed",
|
||||
G_CALLBACK (glade_eprop_model_name_changed), eprop);
|
||||
GLADE_EPROP_MODEL (eprop)->connected = TRUE;
|
||||
}
|
||||
}
|
||||
else
|
||||
widget = GLADE_WIDGET (object);
|
||||
|
||||
adaptor = glade_widget_get_adaptor (widget);
|
||||
editor = glade_widget_adaptor_create_editable (adaptor, GLADE_PAGE_GENERAL);
|
||||
glade_editable_load (editor, widget);
|
||||
|
||||
dialog = GTK_DIALOG (gtk_dialog_new_with_buttons
|
||||
(eprop ? _("Model configuration") : _("Model properties configuration")
|
||||
(_("Model configuration")
|
||||
,GTK_WINDOW (glade_app_get_window ())
|
||||
,GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT
|
||||
,_("OK"), GTK_RESPONSE_OK
|
||||
|
@ -166,11 +153,7 @@ static void glade_eprop_model_show_dialog (GtkButton * button, GObject * object)
|
|||
,NULL
|
||||
));
|
||||
gtk_dialog_set_default_response (dialog, GTK_RESPONSE_OK);
|
||||
gtk_window_set_default_size (GTK_WINDOW (dialog), 400, 300);
|
||||
|
||||
if (!eprop)
|
||||
gtk_widget_hide (gtk_dialog_get_widget_for_response
|
||||
(dialog, GTK_RESPONSE_REJECT));
|
||||
gtk_window_set_default_size (GTK_WINDOW (dialog), 600, 500);
|
||||
|
||||
box = gtk_alignment_new (0,0,1,1);
|
||||
gtk_alignment_set_padding (GTK_ALIGNMENT (box), 8, 8, 8, 8);
|
||||
|
@ -183,23 +166,15 @@ static void glade_eprop_model_show_dialog (GtkButton * button, GObject * object)
|
|||
{
|
||||
case GTK_RESPONSE_OK:
|
||||
{
|
||||
if (eprop)
|
||||
{
|
||||
gtk_entry_set_text (GTK_ENTRY (GLADE_EPROP_MODEL (eprop)->entry),
|
||||
glade_widget_get_name (widget));
|
||||
GLADE_EPROP_MODEL (eprop)->widget = widget;
|
||||
}
|
||||
|
||||
gtk_entry_set_text (GTK_ENTRY (GLADE_EPROP_MODEL (eprop)->entry),
|
||||
glade_widget_get_name (widget));
|
||||
GLADE_EPROP_MODEL (eprop)->widget = widget;
|
||||
break;
|
||||
}
|
||||
case GTK_RESPONSE_REJECT:
|
||||
{
|
||||
if (eprop)
|
||||
{
|
||||
glade_command_set_property (p, NULL);
|
||||
GLADE_EPROP_MODEL (eprop)->widget = NULL;
|
||||
}
|
||||
|
||||
glade_command_set_property (p, NULL);
|
||||
GLADE_EPROP_MODEL (eprop)->widget = NULL;
|
||||
break;
|
||||
}
|
||||
case GTK_RESPONSE_CANCEL:
|
||||
|
@ -209,8 +184,8 @@ static void glade_eprop_model_show_dialog (GtkButton * button, GObject * object)
|
|||
GList * list = g_list_append (NULL, widget);
|
||||
GladeWidget * batch = glade_widget_get_parent (widget);
|
||||
|
||||
if (vn_batch_get_length
|
||||
VN_BATCH (glade_widget_get_object (batch)) == 1)
|
||||
if (vn_set_get_length
|
||||
VN_SET (glade_widget_get_object (batch)) == 1)
|
||||
list = g_list_prepend (list, batch);
|
||||
|
||||
glade_command_delete (list);
|
||||
|
|
|
@ -17,36 +17,36 @@
|
|||
|
||||
#include "glade-vn.h"
|
||||
|
||||
void glade_vn_batch_add_child (GladeWidgetAdaptor * adaptor,
|
||||
VnBatch * group, GObject * child)
|
||||
void glade_vn_set_add_child (GladeWidgetAdaptor * adaptor,
|
||||
VnSet * group, GObject * child)
|
||||
{
|
||||
if (G_IS_OBJECT (child))
|
||||
vn_batch_add (group, child);
|
||||
vn_set_add (group, child);
|
||||
}
|
||||
|
||||
void glade_vn_batch_remove_child (GladeWidgetAdaptor * adaptor,
|
||||
VnBatch * group, GObject * child)
|
||||
void glade_vn_set_remove_child (GladeWidgetAdaptor * adaptor,
|
||||
VnSet * group, GObject * child)
|
||||
{
|
||||
if (G_IS_OBJECT (child))
|
||||
vn_batch_remove (group, child);
|
||||
vn_set_remove (group, child);
|
||||
}
|
||||
|
||||
void glade_vn_batch_replace_child (GladeWidgetAdaptor * adaptor,
|
||||
void glade_vn_set_replace_child (GladeWidgetAdaptor * adaptor,
|
||||
GObject * container, GObject * current, GObject * new)
|
||||
{
|
||||
VnBatch * group = VN_BATCH (container);
|
||||
glade_vn_batch_remove_child (adaptor, group, current);
|
||||
glade_vn_batch_add_child (adaptor, group, new);
|
||||
VnSet * group = VN_SET (container);
|
||||
glade_vn_set_remove_child (adaptor, group, current);
|
||||
glade_vn_set_add_child (adaptor, group, new);
|
||||
}
|
||||
|
||||
GList * glade_vn_batch_get_children (GladeWidgetAdaptor * adaptor,
|
||||
VnBatch * group)
|
||||
GList * glade_vn_set_get_children (GladeWidgetAdaptor * adaptor,
|
||||
VnSet * group)
|
||||
{
|
||||
return vn_batch_get_objects_list (group);
|
||||
return vn_set_get_objects_list (group);
|
||||
}
|
||||
|
||||
gboolean glade_vn_batch_add_verify (GladeWidgetAdaptor * adaptor,
|
||||
VnBatch * container, GObject * child, gboolean user_feedback)
|
||||
gboolean glade_vn_set_add_verify (GladeWidgetAdaptor * adaptor,
|
||||
VnSet * container, GObject * child, gboolean user_feedback)
|
||||
{
|
||||
if (G_IS_OBJECT (child))
|
||||
return TRUE;
|
||||
|
|
|
@ -0,0 +1,69 @@
|
|||
/*
|
||||
* Copyright (C) 2013 - 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 "glade-vn.h"
|
||||
|
||||
void glade_vn_set_add_child (GladeWidgetAdaptor * adaptor,
|
||||
VnSet * group, GObject * child)
|
||||
{
|
||||
if (G_IS_OBJECT (child))
|
||||
vn_set_add (group, child);
|
||||
}
|
||||
|
||||
void glade_vn_set_remove_child (GladeWidgetAdaptor * adaptor,
|
||||
VnSet * group, GObject * child)
|
||||
{
|
||||
if (G_IS_OBJECT (child))
|
||||
vn_set_remove (group, child);
|
||||
}
|
||||
|
||||
void glade_vn_set_replace_child (GladeWidgetAdaptor * adaptor,
|
||||
GObject * container, GObject * current, GObject * new)
|
||||
{
|
||||
VnSet * group = VN_SET (container);
|
||||
glade_vn_set_remove_child (adaptor, group, current);
|
||||
glade_vn_set_add_child (adaptor, group, new);
|
||||
}
|
||||
|
||||
GList * glade_vn_set_get_children (GladeWidgetAdaptor * adaptor,
|
||||
VnSet * group)
|
||||
{
|
||||
return vn_set_get_objects_list (group);
|
||||
}
|
||||
|
||||
gboolean glade_vn_set_add_verify (GladeWidgetAdaptor * adaptor,
|
||||
VnSet * container, GObject * child, gboolean user_feedback)
|
||||
{
|
||||
if (G_IS_OBJECT (child))
|
||||
return TRUE;
|
||||
|
||||
if (user_feedback)
|
||||
{
|
||||
GladeWidgetAdaptor * object_adaptor =
|
||||
glade_widget_adaptor_get_by_type (G_TYPE_OBJECT);
|
||||
|
||||
glade_util_ui_message (glade_app_get_window ()
|
||||
,GLADE_UI_INFO
|
||||
,NULL
|
||||
,"Only objects of type %s can be added to objects of type %s."
|
||||
,glade_widget_adaptor_get_name (object_adaptor)
|
||||
,glade_widget_adaptor_get_name (adaptor)
|
||||
);
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
14
glade/vn.xml
14
glade/vn.xml
|
@ -193,12 +193,12 @@
|
|||
<glade-widget-class name="VnCalendar" generic-name="calendar" title="Date Field" icon-name="widget-gtk-calendar"/>
|
||||
<glade-widget-class name="VnDateChooser" generic-name="date-chooser" title="Date Chooser" icon-name="widget-gtk-calendar"/>
|
||||
|
||||
<glade-widget-class name="VnBatch" generic-name="batch" toplevel="True" title="Group of objects" icon-name="widget-gtk-vbuttonbox">
|
||||
<add-child-function>glade_vn_batch_add_child</add-child-function>
|
||||
<remove-child-function>glade_vn_batch_remove_child</remove-child-function>
|
||||
<replace-child-function>glade_vn_batch_replace_child</replace-child-function>
|
||||
<get-children-function>glade_vn_batch_get_children</get-children-function>
|
||||
<add-child-verify-function>glade_vn_batch_add_verify</add-child-verify-function>
|
||||
<glade-widget-class name="VnSet" generic-name="set" toplevel="True" title="Group of objects" icon-name="widget-gtk-vbuttonbox">
|
||||
<add-child-function>glade_vn_set_add_child</add-child-function>
|
||||
<remove-child-function>glade_vn_set_remove_child</remove-child-function>
|
||||
<replace-child-function>glade_vn_set_replace_child</replace-child-function>
|
||||
<get-children-function>glade_vn_set_get_children</get-children-function>
|
||||
<add-child-verify-function>glade_vn_set_add_verify</add-child-verify-function>
|
||||
</glade-widget-class>
|
||||
</glade-widget-classes>
|
||||
|
||||
|
@ -221,7 +221,7 @@
|
|||
</glade-widget-group>
|
||||
|
||||
<glade-widget-group name="vn-toplevels" title="Data Widgets">
|
||||
<glade-widget-class-ref name="VnBatch"/>
|
||||
<glade-widget-class-ref name="VnSet"/>
|
||||
<glade-widget-class-ref name="VnHandler"/>
|
||||
<glade-widget-class-ref name="VnEntry"/>
|
||||
<glade-widget-class-ref name="VnLabel"/>
|
||||
|
|
|
@ -16,6 +16,7 @@ vn_include_HEADERS = \
|
|||
vn-grid-model.h \
|
||||
vn-grid.h \
|
||||
vn-handler.h \
|
||||
vn-set.h \
|
||||
vn-batch.h \
|
||||
field/field.h \
|
||||
column/column.h
|
||||
|
@ -42,7 +43,7 @@ libvn_files = \
|
|||
vn-grid-model.c \
|
||||
vn-grid.c \
|
||||
vn-handler.c \
|
||||
vn-batch.c
|
||||
vn-set.c
|
||||
glade_files = \
|
||||
$(top_srcdir)/vn/glade/vn-iterator.h \
|
||||
$(top_srcdir)/vn/glade/vn-iterator.c \
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
*/
|
||||
|
||||
#include "vn-form.h"
|
||||
#include "vn-batch.h"
|
||||
#include "vn-set.h"
|
||||
|
||||
G_DEFINE_ABSTRACT_TYPE (VnForm, vn_form, GTK_TYPE_ALIGNMENT);
|
||||
|
||||
|
@ -43,15 +43,15 @@ void vn_form_open (VnForm * obj)
|
|||
if (gtk_builder_add_from_file (obj->builder, file, &err))
|
||||
{
|
||||
const GList * m;
|
||||
VnBatch * models = VN_BATCH (gtk_builder_get_object (obj->builder, "models"));
|
||||
VnSet * models = VN_SET (gtk_builder_get_object (obj->builder, "models"));
|
||||
|
||||
if (models)
|
||||
for (m = vn_batch_get_objects (models); m; m = m->next)
|
||||
for (m = vn_set_get_objects (models); m; m = m->next)
|
||||
db_model_set_conn (m->data, obj->conn);
|
||||
|
||||
gtk_builder_connect_signals (obj->builder, obj);
|
||||
|
||||
VN_FORM_GET_CLASS (obj)->open (obj, obj->builder, NULL);
|
||||
VN_FORM_GET_CLASS (obj)->open (obj);
|
||||
gtk_container_add (GTK_CONTAINER (obj), vn_form_get (obj, "main"));
|
||||
gtk_widget_show_all (GTK_WIDGET (obj));
|
||||
|
||||
|
|
10
vn/vn-form.h
10
vn/vn-form.h
|
@ -32,8 +32,8 @@ typedef struct _VnFormClass VnFormClass;
|
|||
|
||||
typedef GType (* VnFormGetTypeFunc) ();
|
||||
typedef void (* VnFormOpenFunc) (VnForm * obj, GtkBuilder * builder, gpointer user_data);
|
||||
/*typedef void (* VnFormActivateFunc) (VnForm * obj);
|
||||
typedef void (* VnFormDeactivateFunc) (VnForm * obj);*/
|
||||
typedef void (* VnFormActivateFunc) (VnForm * obj);
|
||||
typedef void (* VnFormDeactivateFunc) (VnForm * obj);
|
||||
|
||||
struct _VnForm
|
||||
{
|
||||
|
@ -57,10 +57,10 @@ struct _VnFormClass
|
|||
{
|
||||
GtkAlignmentClass parent;
|
||||
/*< public >*/
|
||||
void (* open) (VnForm * obj, GtkBuilder * builder, gpointer user_data);
|
||||
void (* open) (VnForm * obj);
|
||||
const GActionEntry * (* get_actions) (VnForm * obj, gint * size);
|
||||
/* void (* activate) (VnForm * obj);
|
||||
void (* deactivate) (VnForm * obj);*/
|
||||
void (* activate) (VnForm * obj);
|
||||
void (* deactivate) (VnForm * obj);
|
||||
};
|
||||
|
||||
GType vn_form_get_type ();
|
||||
|
|
|
@ -0,0 +1,149 @@
|
|||
/*
|
||||
* 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;
|
||||
}
|
|
@ -0,0 +1,60 @@
|
|||
/*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
#ifndef VN_SET_H
|
||||
#define VN_SET_H
|
||||
|
||||
#include <db/db.h>
|
||||
#include <gtk/gtk.h>
|
||||
|
||||
#define VN_TYPE_SET (vn_set_get_type ())
|
||||
#define VN_SET(obj) (G_TYPE_CHECK_INSTANCE_CAST (obj, VN_TYPE_SET, VnSet))
|
||||
#define VN_IS_SET(obj) (G_TYPE_CHECK_INSTANCE_TYPE (obj, VN_TYPE_SET))
|
||||
#define VN_SET_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST (klass, VN_TYPE_SET, VnSetClass))
|
||||
#define VN_IS_SET_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE (klass, VN_TYPE_SET))
|
||||
#define VN_SET_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS (obj, VN_TYPE_SET, VnSetClass))
|
||||
|
||||
typedef struct _VnSet VnSet;
|
||||
typedef struct _VnSetClass VnSetClass;
|
||||
|
||||
/**
|
||||
* VnSet:
|
||||
* @objects: (element-type GObject):
|
||||
**/
|
||||
struct _VnSet
|
||||
{
|
||||
GObject parent;
|
||||
GList * objects;
|
||||
guint count;
|
||||
};
|
||||
|
||||
struct _VnSetClass
|
||||
{
|
||||
GObjectClass parent;
|
||||
};
|
||||
|
||||
GType vn_set_get_type ();
|
||||
|
||||
void vn_set_add (VnSet * obj
|
||||
,GObject * child);
|
||||
void vn_set_remove (VnSet * obj
|
||||
,GObject * child);
|
||||
const GList * vn_set_get_objects (VnSet * obj);
|
||||
GList * vn_set_get_objects_list (VnSet * obj);
|
||||
guint vn_set_get_length (VnSet * obj);
|
||||
|
||||
#endif
|
Reference in New Issue