258 lines
6.0 KiB
C
258 lines
6.0 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-form.h"
|
|
#include "vn-batch.h"
|
|
|
|
G_DEFINE_ABSTRACT_TYPE (VnForm, vn_form, GTK_TYPE_ALIGNMENT);
|
|
|
|
//+++++++++++++++++++++++++++++++++++++++++++++++++++ Public
|
|
|
|
/**
|
|
* vn_form_open: (virtual open):
|
|
* @obj: the #VnForm
|
|
*
|
|
* Activates the form.
|
|
**/
|
|
void vn_form_open (VnForm * obj)
|
|
{
|
|
const gchar * dir;
|
|
gchar * file;
|
|
GError * err = NULL;
|
|
|
|
obj->builder = gtk_builder_new ();
|
|
gtk_builder_set_translation_domain (obj->builder, vn_mod_get_text_domain (obj->mod));
|
|
|
|
dir = vn_mod_get_data_dir (obj->mod);
|
|
file = g_strdup_printf ("%s/%s.glade", dir, obj->name);
|
|
|
|
if (gtk_builder_add_from_file (obj->builder, file, &err))
|
|
{
|
|
const GList * m;
|
|
VnBatch * models = VN_BATCH (gtk_builder_get_object (obj->builder, "models"));
|
|
|
|
if (models)
|
|
for (m = vn_batch_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);
|
|
gtk_container_add (GTK_CONTAINER (obj), vn_form_get (obj, "main"));
|
|
gtk_widget_show_all (GTK_WIDGET (obj));
|
|
|
|
// Loading menu
|
|
|
|
g_free (file);
|
|
file = g_strdup_printf ("%s/%s-menu.xml", dir, obj->name);
|
|
|
|
if (gtk_builder_add_from_file (obj->builder, file, &err))
|
|
{
|
|
obj->menu = vn_form_get (obj, "menu");
|
|
}
|
|
else
|
|
{
|
|
if (err && err->code != G_FILE_ERROR_NOENT)
|
|
g_warning ("VnForm: %s", err->message);
|
|
|
|
g_error_free (err);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
g_warning ("VnForm: %s", err->message);
|
|
g_error_free (err);
|
|
}
|
|
|
|
g_free (file);
|
|
}
|
|
|
|
/**
|
|
* vn_form_get:
|
|
* @obj: the #VnForm
|
|
* @name: the object name
|
|
*
|
|
* Gets an object from the form builder using its name.
|
|
*
|
|
* Return value: (transfer none): the object, or %NULL if there is no object
|
|
* with that name
|
|
**/
|
|
gpointer vn_form_get (VnForm * obj, const gchar * name)
|
|
{
|
|
return (gpointer) gtk_builder_get_object (obj->builder, name);
|
|
}
|
|
|
|
/**
|
|
* vn_form_get_name:
|
|
* @obj: the #VnForm
|
|
*
|
|
* Gets the name of the form.
|
|
**/
|
|
const gchar * vn_form_get_name (VnForm * obj)
|
|
{
|
|
g_return_val_if_fail (VN_IS_FORM (obj), NULL);
|
|
|
|
return obj->name;
|
|
}
|
|
|
|
/**
|
|
* vn_form_get_actions: (virtual get_actions):
|
|
* @obj: the #VnForm
|
|
* @size:(out): the return location for the size of the array
|
|
*
|
|
* Returns the actions implemented by @obj.
|
|
*
|
|
* Return value:(transfer none) (array length=size): a #GActionEntry array
|
|
**/
|
|
const GActionEntry * vn_form_get_actions (VnForm * obj, gint * size)
|
|
{
|
|
g_return_val_if_fail (VN_IS_FORM (obj), NULL);
|
|
|
|
if (!VN_FORM_GET_CLASS (obj)->get_actions)
|
|
{
|
|
*size = 0;
|
|
return NULL;
|
|
}
|
|
else
|
|
return VN_FORM_GET_CLASS (obj)->get_actions (obj, size);
|
|
}
|
|
|
|
/**
|
|
* vn_form_get_menu_model:
|
|
* @obj: the #VnForm
|
|
*
|
|
* Returns the #GMenuModel of the form.
|
|
*
|
|
* Return value: (transfer none): a #GMenuModel or #NULL
|
|
**/
|
|
GMenuModel * vn_form_get_menu_model (VnForm * obj)
|
|
{
|
|
g_return_val_if_fail (VN_IS_FORM (obj), NULL);
|
|
|
|
return obj->menu;
|
|
}
|
|
//+++++++++++++++++++++++++++++++++++++++++++++++++++ Properties
|
|
|
|
enum
|
|
{
|
|
PROP_NAME = 1
|
|
,PROP_GUI
|
|
,PROP_CONN
|
|
,PROP_MODULE
|
|
};
|
|
|
|
static void vn_form_set_property (VnForm * obj, guint id,
|
|
const GValue * value, GParamSpec * pspec)
|
|
{
|
|
switch (id)
|
|
{
|
|
case PROP_NAME:
|
|
obj->name = g_value_dup_string (value);
|
|
break;
|
|
case PROP_GUI:
|
|
obj->gui = g_value_dup_object (value);
|
|
obj->conn = vn_gui_get_conn (obj->gui);
|
|
break;
|
|
case PROP_MODULE:
|
|
obj->mod = g_value_dup_object (value);
|
|
break;
|
|
default:
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, id, pspec);
|
|
}
|
|
}
|
|
|
|
static void vn_form_get_property (VnForm * obj, guint id,
|
|
GValue * value, GParamSpec * pspec)
|
|
{
|
|
switch (id)
|
|
{
|
|
case PROP_NAME:
|
|
g_value_set_string (value, obj->name);
|
|
break;
|
|
case PROP_GUI:
|
|
g_value_set_object (value, obj->gui);
|
|
break;
|
|
case PROP_CONN:
|
|
g_value_set_object (value, obj->conn);
|
|
break;
|
|
case PROP_MODULE:
|
|
g_value_set_object (value, obj->mod);
|
|
break;
|
|
default:
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, id, pspec);
|
|
}
|
|
}
|
|
|
|
//+++++++++++++++++++++++++++++++++++++++++++++++++++ Class
|
|
|
|
static void vn_form_init (VnForm * obj)
|
|
{
|
|
obj->name = NULL;
|
|
obj->gui = NULL;
|
|
obj->conn = NULL;
|
|
obj->builder = NULL;
|
|
obj->mod = NULL;
|
|
obj->menu = NULL;
|
|
}
|
|
|
|
static void vn_form_finalize (VnForm * obj)
|
|
{
|
|
g_free (obj->name);
|
|
g_clear_object (&obj->gui);
|
|
g_clear_object (&obj->builder);
|
|
g_clear_object (&obj->mod);
|
|
g_clear_object (&obj->menu);
|
|
G_OBJECT_CLASS (vn_form_parent_class)->finalize (G_OBJECT (obj));
|
|
}
|
|
|
|
static void vn_form_class_init (VnFormClass * k)
|
|
{
|
|
GObjectClass * klass = G_OBJECT_CLASS (k);
|
|
klass->finalize = (GObjectFinalizeFunc) vn_form_finalize;
|
|
klass->set_property = (GObjectSetPropertyFunc) vn_form_set_property;
|
|
klass->get_property = (GObjectGetPropertyFunc) vn_form_get_property;
|
|
|
|
g_object_class_install_property (klass, PROP_NAME,
|
|
g_param_spec_string ("name"
|
|
,_("Name")
|
|
,_("The form name")
|
|
,NULL
|
|
,G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE
|
|
));
|
|
g_object_class_install_property (klass, PROP_GUI,
|
|
g_param_spec_object ("gui"
|
|
,_("Gui")
|
|
,_("The Gui object")
|
|
,VN_TYPE_GUI
|
|
,G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE
|
|
));
|
|
g_object_class_install_property (klass, PROP_CONN,
|
|
g_param_spec_object ("conn"
|
|
,_("Connection")
|
|
,_("The connection used by the module")
|
|
,DB_TYPE_CONN
|
|
,G_PARAM_READABLE
|
|
));
|
|
g_object_class_install_property (klass, PROP_MODULE,
|
|
g_param_spec_object ("module"
|
|
,_("Module")
|
|
,_("The module")
|
|
,VN_TYPE_MOD
|
|
,G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE
|
|
));
|
|
}
|