This repository has been archived on 2024-07-15. You can view files and clone it, but cannot push or open issues or pull requests.
hedera/vn/glade/vn-batch.c

139 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-batch.h"
static void vn_batch_buildable_interface_init (GtkBuildableIface * iface);
G_DEFINE_TYPE_WITH_CODE (VnBatch, vn_batch, SQL_TYPE_BATCH,
G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE,
vn_batch_buildable_interface_init)
);
/* GtkBuildable custom tag implementation:
* <items>
* <item id="identifier" param="param-id"/>
* ...
* </items>
*/
typedef struct
{
GtkBuilder * builder;
SqlBatch * batch;
GSList * ids;
GSList * params;
}
VnBatchData;
//+++++++++++++++++++++++++++++++++++++++++++++++++++ GtkBuildable
static void vn_batch_start_element (GMarkupParseContext * context,
const gchar * element, const gchar ** names,
const gchar ** values, gpointer data, GError ** err)
{
guint i;
VnBatchData * d = data;
if (!g_strcmp0 (element, "item"))
{
for (i = 0; names[i]; i++)
if (!g_strcmp0 (names[i], "id"))
d->ids = g_slist_prepend (d->ids, g_strdup (values[i]));
else if (!g_strcmp0 (names[i], "param"))
d->params = g_slist_prepend (d->params, g_strdup (values[i]));
}
}
static const GMarkupParser vn_batch_parser =
{
vn_batch_start_element
};
static gboolean vn_batch_buildable_custom_tag_start (GtkBuildable * buildable,
GtkBuilder * builder, GObject * child, const gchar * tag,
GMarkupParser * parser, gpointer * data)
{
if (child)
return FALSE;
if (!g_strcmp0 (tag, "items"))
{
VnBatchData * data_ptr = g_slice_new (VnBatchData);
data_ptr->builder = builder;
data_ptr->batch = SQL_BATCH (buildable);
data_ptr->ids = NULL;
data_ptr->params = NULL;
*data = data_ptr;
*parser = vn_batch_parser;
return TRUE;
}
else
g_warning ("Unknown custom batch tag: %s", tag);
return FALSE;
}
static void vn_batch_buildable_custom_finished (GtkBuildable * buildable,
GtkBuilder * builder, GObject * child, const gchar * tagname, gpointer data)
{
GSList * i, * p;
VnBatchData * d = data;
g_return_if_fail (d->builder);
if (!g_strcmp0 (tagname, "items"))
{
for (i = d->ids, p = d->params;
i && p;
i = i->next, p = p->next)
{
gchar * id = i->data;
GvnParam * param = GVN_PARAM (gtk_builder_get_object (d->builder, p->data));
sql_batch_add_from_param (SQL_BATCH (buildable), id, param);
}
g_slist_free_full (d->ids, g_free);
g_slist_free_full (d->params, g_free);
g_slice_free (VnBatchData, d);
}
}
//+++++++++++++++++++++++++++++++++++++++++++++++++++ Class
static void vn_batch_buildable_interface_init (GtkBuildableIface * iface)
{
iface->custom_tag_start = vn_batch_buildable_custom_tag_start;
iface->custom_finished = vn_batch_buildable_custom_finished;
}
static void vn_batch_init (VnBatch * self)
{
}
static void vn_batch_finalize (VnBatch * self)
{
G_OBJECT_CLASS (vn_batch_parent_class)->finalize (G_OBJECT (self));
}
static void vn_batch_class_init (VnBatchClass * klass)
{
GObjectClass * k = G_OBJECT_CLASS (klass);
k->finalize = (GObjectFinalizeFunc) vn_batch_finalize;
}