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-mod.h"
|
|
|
|
|
|
|
|
struct _VnModPrivate
|
|
|
|
{
|
|
|
|
gchar * name;
|
|
|
|
gchar * data_dir;
|
|
|
|
gchar * text_domain;
|
2014-05-29 08:37:06 +00:00
|
|
|
gchar * title;
|
2014-07-07 15:00:21 +00:00
|
|
|
VnGui * gui;
|
2013-10-11 23:07:35 +00:00
|
|
|
GModule * module;
|
2014-05-22 10:54:00 +00:00
|
|
|
GActionEntry * actions;
|
2013-10-11 23:07:35 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
G_DEFINE_TYPE (VnMod, vn_mod, G_TYPE_OBJECT);
|
|
|
|
|
|
|
|
//+++++++++++++++++++++++++++++++++++++++++++++++++++ Public
|
|
|
|
|
|
|
|
/**
|
2014-04-15 09:36:14 +00:00
|
|
|
* vn_mod_activate: (virtual activate)
|
2013-10-11 23:07:35 +00:00
|
|
|
* @obj: the #VnMod
|
|
|
|
*
|
|
|
|
* Activates the module.
|
|
|
|
**/
|
|
|
|
void vn_mod_activate (VnMod * obj)
|
|
|
|
{
|
|
|
|
g_return_if_fail (VN_IS_MOD (obj));
|
|
|
|
|
|
|
|
VN_MOD_GET_CLASS (obj)->activate (obj);
|
|
|
|
}
|
|
|
|
|
|
|
|
const gchar * vn_mod_get_name (VnMod * obj)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (VN_IS_MOD (obj), NULL);
|
|
|
|
|
|
|
|
return obj->priv->name;
|
|
|
|
}
|
|
|
|
|
|
|
|
const gchar * vn_mod_get_text_domain (VnMod * obj)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (VN_IS_MOD (obj), NULL);
|
|
|
|
|
|
|
|
return obj->priv->text_domain;
|
|
|
|
}
|
|
|
|
|
|
|
|
const gchar * vn_mod_get_data_dir (VnMod * obj)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (VN_IS_MOD (obj), NULL);
|
|
|
|
|
|
|
|
return obj->priv->data_dir;
|
|
|
|
}
|
|
|
|
|
2014-05-29 08:37:06 +00:00
|
|
|
const gchar * vn_mod_get_title (VnMod * obj)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (VN_IS_MOD (obj), NULL);
|
|
|
|
|
|
|
|
return obj->priv->title;
|
|
|
|
}
|
|
|
|
|
2014-05-20 15:45:13 +00:00
|
|
|
/**
|
|
|
|
* vn_mod_get_menu_model:
|
2014-05-29 08:37:06 +00:00
|
|
|
* @obj: a #VnMod
|
|
|
|
*
|
|
|
|
* Gets a menu to open the forms of the module.
|
|
|
|
*
|
|
|
|
* Returns: (transfer full): a #GMenuModel
|
2014-05-20 15:45:13 +00:00
|
|
|
**/
|
|
|
|
GMenuModel * vn_mod_get_menu_model (VnMod * obj)
|
2013-10-11 23:07:35 +00:00
|
|
|
{
|
2014-05-20 15:45:13 +00:00
|
|
|
gchar * menu_file;
|
|
|
|
GMenuModel * menu = NULL;
|
|
|
|
GtkBuilder * builder;
|
|
|
|
GError * err = NULL;
|
|
|
|
|
2013-10-11 23:07:35 +00:00
|
|
|
g_return_val_if_fail (VN_IS_MOD (obj), NULL);
|
|
|
|
|
2014-07-07 15:00:21 +00:00
|
|
|
menu_file = g_strdup_printf ("%s/%s-menu.xml",
|
2014-05-20 15:45:13 +00:00
|
|
|
obj->priv->data_dir, obj->priv->name);
|
|
|
|
builder = gtk_builder_new ();
|
2013-10-11 23:07:35 +00:00
|
|
|
|
2014-05-20 15:45:13 +00:00
|
|
|
if (gtk_builder_add_from_file (builder, menu_file, &err))
|
2014-05-29 08:37:06 +00:00
|
|
|
menu = G_MENU_MODEL (gtk_builder_get_object (builder, "menu"));
|
2014-05-20 15:45:13 +00:00
|
|
|
else if (err)
|
|
|
|
{
|
|
|
|
if (err->code != G_FILE_ERROR_NOENT)
|
2014-05-29 08:37:06 +00:00
|
|
|
g_warning ("%s", err->message);
|
2014-05-20 15:45:13 +00:00
|
|
|
|
|
|
|
g_clear_error (&err);
|
|
|
|
}
|
2013-10-11 23:07:35 +00:00
|
|
|
|
2014-05-20 15:45:13 +00:00
|
|
|
g_free (menu_file);
|
|
|
|
g_object_unref (builder);
|
|
|
|
return menu;
|
2013-10-11 23:07:35 +00:00
|
|
|
}
|
|
|
|
|
2014-07-07 15:00:21 +00:00
|
|
|
/**
|
|
|
|
* vn_mod_get_actions: (virtual get_actions):
|
|
|
|
* @obj: a #VnMod
|
|
|
|
* @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_mod_get_actions (VnMod * obj, gint * size)
|
|
|
|
{
|
|
|
|
g_return_if_fail (VN_IS_MOD (obj));
|
|
|
|
|
|
|
|
if (!VN_MOD_GET_CLASS (obj)->get_actions)
|
|
|
|
{
|
|
|
|
*size = 0;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return VN_MOD_GET_CLASS (obj)->get_actions (obj, size);
|
|
|
|
}
|
|
|
|
|
2013-10-11 23:07:35 +00:00
|
|
|
//+++++++++++++++++++++++++++++++++++++++++++++++++++ Properties
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
PROP_NAME = 1
|
|
|
|
,PROP_DATA_DIR
|
|
|
|
,PROP_MODULE
|
|
|
|
,PROP_TEXT_DOMAIN
|
2014-05-29 08:37:06 +00:00
|
|
|
,PROP_TITLE
|
2014-07-07 15:00:21 +00:00
|
|
|
,PROP_GUI
|
2013-10-11 23:07:35 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static void vn_mod_set_property (VnMod * obj, guint id,
|
|
|
|
const GValue * value, GParamSpec * pspec)
|
|
|
|
{
|
|
|
|
switch (id)
|
|
|
|
{
|
|
|
|
case PROP_NAME:
|
|
|
|
obj->priv->name = g_value_dup_string (value);
|
2013-12-13 09:07:52 +00:00
|
|
|
|
|
|
|
//XXX Remove when the "example" mod gets removed from the project
|
|
|
|
if (g_strcmp0 (obj->priv->name, "example"))
|
|
|
|
obj->priv->text_domain = g_strdup_printf ("%s-%s", GETTEXT_PACKAGE, obj->priv->name);
|
|
|
|
else
|
|
|
|
obj->priv->text_domain = g_strdup (GETTEXT_PACKAGE);
|
|
|
|
|
2013-10-11 23:07:35 +00:00
|
|
|
bindtextdomain (obj->priv->text_domain, _HEDERA_LOCALE_DIR);
|
|
|
|
break;
|
|
|
|
case PROP_DATA_DIR:
|
|
|
|
obj->priv->data_dir = g_value_dup_string (value);
|
|
|
|
break;
|
|
|
|
case PROP_MODULE:
|
|
|
|
obj->priv->module = g_value_get_pointer (value);
|
|
|
|
break;
|
2014-05-29 08:37:06 +00:00
|
|
|
case PROP_TITLE:
|
|
|
|
obj->priv->title = g_value_dup_string (value);
|
|
|
|
break;
|
2014-07-07 15:00:21 +00:00
|
|
|
case PROP_GUI:
|
|
|
|
obj->priv->gui = g_value_dup_object (value);
|
|
|
|
break;
|
2013-10-11 23:07:35 +00:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, id, pspec);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void vn_mod_get_property (VnMod * obj, guint id,
|
|
|
|
GValue * value, GParamSpec * pspec)
|
|
|
|
{
|
|
|
|
switch (id)
|
|
|
|
{
|
|
|
|
case PROP_NAME:
|
|
|
|
g_value_set_string (value, obj->priv->name);
|
|
|
|
break;
|
|
|
|
case PROP_DATA_DIR:
|
|
|
|
g_value_set_string (value, obj->priv->data_dir);
|
|
|
|
break;
|
|
|
|
case PROP_MODULE:
|
|
|
|
g_value_set_pointer (value, obj->priv->module);
|
|
|
|
break;
|
|
|
|
case PROP_TEXT_DOMAIN:
|
|
|
|
g_value_set_string (value, obj->priv->text_domain);
|
|
|
|
break;
|
2014-05-29 08:37:06 +00:00
|
|
|
case PROP_TITLE:
|
|
|
|
g_value_set_string (value, obj->priv->title);
|
|
|
|
break;
|
2014-07-07 15:00:21 +00:00
|
|
|
case PROP_GUI:
|
|
|
|
g_value_set_object (value, obj->priv->gui);
|
|
|
|
break;
|
2013-10-11 23:07:35 +00:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, id, pspec);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//+++++++++++++++++++++++++++++++++++++++++++++++++++ Class
|
|
|
|
|
|
|
|
static void vn_mod_init (VnMod * obj)
|
|
|
|
{
|
2014-07-07 15:00:21 +00:00
|
|
|
VnModPrivate * priv;
|
|
|
|
priv = obj->priv = G_TYPE_INSTANCE_GET_PRIVATE (obj, VN_TYPE_MOD, VnModPrivate);
|
|
|
|
|
|
|
|
priv->name = NULL;
|
|
|
|
priv->gui = NULL;
|
|
|
|
priv->data_dir = NULL;
|
|
|
|
priv->module = NULL;
|
|
|
|
priv->text_domain = NULL;
|
|
|
|
priv->actions = NULL;
|
2013-10-11 23:07:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void vn_mod_finalize (VnMod * obj)
|
|
|
|
{
|
|
|
|
g_free (obj->priv->name);
|
|
|
|
g_free (obj->priv->data_dir);
|
|
|
|
g_free (obj->priv->text_domain);
|
|
|
|
G_OBJECT_CLASS (vn_mod_parent_class)->finalize (G_OBJECT (obj));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void vn_mod_class_init (VnModClass * k)
|
|
|
|
{
|
|
|
|
GObjectClass * klass = G_OBJECT_CLASS (k);
|
|
|
|
klass->finalize = (GObjectFinalizeFunc) vn_mod_finalize;
|
|
|
|
klass->set_property = (GObjectSetPropertyFunc) vn_mod_set_property;
|
|
|
|
klass->get_property = (GObjectGetPropertyFunc) vn_mod_get_property;
|
|
|
|
g_type_class_add_private (klass, sizeof (VnModPrivate));
|
|
|
|
|
|
|
|
g_object_class_install_property (klass, PROP_NAME,
|
|
|
|
g_param_spec_string ("name"
|
|
|
|
,"Name"
|
|
|
|
,"The module name"
|
|
|
|
,NULL
|
|
|
|
,G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE
|
|
|
|
));
|
|
|
|
g_object_class_install_property (klass, PROP_DATA_DIR,
|
|
|
|
g_param_spec_string ("data-dir"
|
|
|
|
,"Data directory"
|
|
|
|
,"The directory in which the data of the module is allocated"
|
|
|
|
,NULL
|
|
|
|
,G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE
|
|
|
|
));
|
|
|
|
g_object_class_install_property (klass, PROP_MODULE,
|
|
|
|
g_param_spec_pointer ("module"
|
|
|
|
,"Module"
|
|
|
|
,"The GModule"
|
|
|
|
,G_PARAM_CONSTRUCT_ONLY | G_PARAM_WRITABLE
|
|
|
|
));
|
|
|
|
g_object_class_install_property (klass, PROP_TEXT_DOMAIN,
|
|
|
|
g_param_spec_string ("text-domain"
|
|
|
|
,"Text domain"
|
|
|
|
,"The domain in wich the module is"
|
|
|
|
,NULL
|
|
|
|
,G_PARAM_READABLE
|
|
|
|
));
|
2014-05-29 08:37:06 +00:00
|
|
|
g_object_class_install_property (klass, PROP_TITLE,
|
|
|
|
g_param_spec_string ("title"
|
|
|
|
,"Title"
|
|
|
|
,"The module title"
|
|
|
|
,NULL
|
|
|
|
,G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE
|
|
|
|
));
|
2014-07-07 15:00:21 +00:00
|
|
|
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
|
|
|
|
));
|
2013-10-11 23:07:35 +00:00
|
|
|
}
|