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 "gvn-misc.h"
|
|
|
|
#include "gvn-param.h"
|
|
|
|
#include "gvn-value.h"
|
|
|
|
|
|
|
|
/**
|
|
|
|
* SECTION: gvn-param
|
|
|
|
* @Short_description:
|
|
|
|
* @Title: GvnParam
|
|
|
|
**/
|
2014-07-16 14:12:36 +00:00
|
|
|
G_DEFINE_INTERFACE (GvnParam, gvn_param, G_TYPE_OBJECT);
|
2013-10-11 23:07:35 +00:00
|
|
|
|
|
|
|
enum {
|
|
|
|
VALUE_CHANGED
|
|
|
|
,SPEC_CHANGED
|
|
|
|
,STATUS_CHANGED
|
|
|
|
,LAST_SIGNAL
|
|
|
|
};
|
|
|
|
|
|
|
|
static guint signals[LAST_SIGNAL] = {0};
|
|
|
|
|
|
|
|
//+++++++++++++++++++++++++++++++++++++++++++++++++++ Public
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gvn_param_get_value:
|
2014-07-16 14:12:36 +00:00
|
|
|
* @self: a #GvnParam where be took the value
|
2013-10-11 23:07:35 +00:00
|
|
|
*
|
|
|
|
* Gets the value of param.
|
|
|
|
*
|
|
|
|
* Return value: (transfer none): the #GValue
|
|
|
|
**/
|
2014-07-16 14:12:36 +00:00
|
|
|
const GValue * gvn_param_get_value (GvnParam * self)
|
2013-10-11 23:07:35 +00:00
|
|
|
{
|
2014-07-16 14:12:36 +00:00
|
|
|
g_return_val_if_fail (GVN_IS_PARAM (self), NULL);
|
|
|
|
|
|
|
|
return GVN_PARAM_GET_INTERFACE (self)->get_value (self);
|
2013-10-11 23:07:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-07-16 14:12:36 +00:00
|
|
|
* gvn_param_request_value:
|
|
|
|
* @self: #GvnParam object where @value wants to be validated.
|
2013-10-11 23:07:35 +00:00
|
|
|
* @value: new value.
|
|
|
|
* @err: (out) (allow-none): the return location for an allocated @GError, or
|
|
|
|
* NULL to ignore errors.
|
|
|
|
*
|
2014-07-16 14:12:36 +00:00
|
|
|
* Sets @value into @self.
|
2013-10-11 23:07:35 +00:00
|
|
|
*
|
|
|
|
* Return value: %TRUE if assigment is valid, %FALSE otherwise.
|
|
|
|
**/
|
2014-07-16 14:12:36 +00:00
|
|
|
gboolean gvn_param_request_value (GvnParam * self, const GValue * value, GError ** err)
|
2013-10-11 23:07:35 +00:00
|
|
|
{
|
2014-07-16 14:12:36 +00:00
|
|
|
g_return_val_if_fail (GVN_IS_PARAM (self), FALSE);
|
2013-10-11 23:07:35 +00:00
|
|
|
g_return_val_if_fail (G_IS_VALUE (value), FALSE);
|
2014-07-16 14:12:36 +00:00
|
|
|
|
|
|
|
return GVN_PARAM_GET_INTERFACE (self)->request_value (self, value, err);
|
2013-10-11 23:07:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-07-16 14:12:36 +00:00
|
|
|
* gvn_param_set_value:
|
|
|
|
* @self: #GvnParam object where @value wants to be validated.
|
|
|
|
* @value: new value.
|
2013-10-11 23:07:35 +00:00
|
|
|
*
|
2014-07-16 14:12:36 +00:00
|
|
|
* Sets @value into @self.
|
2013-10-11 23:07:35 +00:00
|
|
|
**/
|
2014-07-16 14:12:36 +00:00
|
|
|
void gvn_param_set_value (GvnParam * self, const GValue * value)
|
2013-10-11 23:07:35 +00:00
|
|
|
{
|
2014-07-16 14:12:36 +00:00
|
|
|
g_return_val_if_fail (GVN_IS_PARAM (self), FALSE);
|
|
|
|
g_return_val_if_fail (G_IS_VALUE (value), FALSE);
|
|
|
|
|
|
|
|
gvn_param_request_value (self, value, NULL);
|
2013-10-11 23:07:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gvn_param_get_master:
|
2014-07-16 14:12:36 +00:00
|
|
|
* @self: a #GvnParam where be took the value
|
2013-10-11 23:07:35 +00:00
|
|
|
*
|
2014-07-16 14:12:36 +00:00
|
|
|
* Gets the master param of @self
|
2013-10-11 23:07:35 +00:00
|
|
|
*
|
|
|
|
* Return value: (transfer none): the master #GvnParam or %NULL if it haven't.
|
|
|
|
**/
|
2014-07-16 14:12:36 +00:00
|
|
|
GvnParam * gvn_param_get_master (GvnParam * self)
|
2013-10-11 23:07:35 +00:00
|
|
|
{
|
2014-07-16 14:12:36 +00:00
|
|
|
g_return_val_if_fail (GVN_IS_PARAM (self), NULL);
|
2013-10-11 23:07:35 +00:00
|
|
|
|
2014-07-16 14:12:36 +00:00
|
|
|
return GVN_PARAM_GET_INTERFACE (self)->get_master (self);
|
2013-10-11 23:07:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-07-16 14:12:36 +00:00
|
|
|
* gvn_param_set_master:
|
|
|
|
* @self: #GvnParam object
|
|
|
|
* @master: #GvnParam master
|
2013-10-11 23:07:35 +00:00
|
|
|
*
|
|
|
|
* Sets @dst as a master of @src
|
|
|
|
**/
|
2014-07-16 14:12:36 +00:00
|
|
|
void gvn_param_set_master (GvnParam * self, GvnParam * master)
|
2013-10-11 23:07:35 +00:00
|
|
|
{
|
2014-07-16 14:12:36 +00:00
|
|
|
g_return_val_if_fail (GVN_IS_PARAM (self), NULL);
|
|
|
|
g_return_val_if_fail (GVN_IS_PARAM (master), NULL);
|
|
|
|
|
|
|
|
GVN_PARAM_GET_INTERFACE (self)->set_master (self, master);
|
2013-10-11 23:07:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-07-16 14:12:36 +00:00
|
|
|
* gvn_param_get_spec:
|
|
|
|
* @self: #GvnParam object
|
2013-10-11 23:07:35 +00:00
|
|
|
*
|
2014-07-16 14:12:36 +00:00
|
|
|
* Gets the #GvnParamSpec of @self
|
2013-10-11 23:07:35 +00:00
|
|
|
*
|
2014-07-16 14:12:36 +00:00
|
|
|
* Return value: (transfer none): the #GvnParamSpec
|
2013-10-11 23:07:35 +00:00
|
|
|
**/
|
2014-07-16 14:12:36 +00:00
|
|
|
const GvnParamSpec * gvn_param_get_spec (GvnParam * self)
|
2013-10-11 23:07:35 +00:00
|
|
|
{
|
2014-07-16 14:12:36 +00:00
|
|
|
g_return_val_if_fail (GVN_IS_PARAM (self), NULL);
|
2013-10-11 23:07:35 +00:00
|
|
|
|
2014-07-16 14:12:36 +00:00
|
|
|
return GVN_PARAM_GET_INTERFACE (self)->get_spec (self);
|
2013-10-11 23:07:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-07-16 14:12:36 +00:00
|
|
|
* gvn_param_get_status:
|
|
|
|
* @self: #GvnParam object
|
2013-10-11 23:07:35 +00:00
|
|
|
*
|
2014-07-16 14:12:36 +00:00
|
|
|
* Gets the status of @self
|
2013-10-11 23:07:35 +00:00
|
|
|
*
|
2014-07-16 14:12:36 +00:00
|
|
|
* Return value: the current status of the param.
|
2013-10-11 23:07:35 +00:00
|
|
|
**/
|
2014-07-16 14:12:36 +00:00
|
|
|
GvnParamStatus gvn_param_get_status (GvnParam * self)
|
2013-10-11 23:07:35 +00:00
|
|
|
{
|
2014-07-16 14:12:36 +00:00
|
|
|
g_return_val_if_fail (GVN_IS_PARAM (self), GVN_PARAM_STATUS_OK);
|
2013-10-11 23:07:35 +00:00
|
|
|
|
2014-07-16 14:12:36 +00:00
|
|
|
return GVN_PARAM_GET_INTERFACE (self)->get_status (self);
|
2013-10-11 23:07:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gvn_param_value_changed:
|
2014-07-16 14:12:36 +00:00
|
|
|
* @self: a #GvnParam
|
2013-10-11 23:07:35 +00:00
|
|
|
*
|
|
|
|
* Emits the "value-changed" signal for that param.
|
|
|
|
**/
|
2014-07-16 14:12:36 +00:00
|
|
|
void gvn_param_value_changed (GvnParam * self)
|
2013-10-11 23:07:35 +00:00
|
|
|
{
|
2014-07-16 14:12:36 +00:00
|
|
|
g_signal_emit (self, signals[VALUE_CHANGED], 0, gvn_param_get_value (self));
|
2013-10-11 23:07:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//+++++++++++++++++++++++++++++++++++++++++++++++++++ Class
|
|
|
|
|
2014-07-16 14:12:36 +00:00
|
|
|
static void gvn_param_default_init (GvnParamInterface * iface)
|
2013-10-11 23:07:35 +00:00
|
|
|
{
|
|
|
|
signals[VALUE_CHANGED] = g_signal_new ("value-changed",
|
|
|
|
GVN_TYPE_PARAM, G_SIGNAL_RUN_FIRST, 0, NULL, NULL,
|
|
|
|
g_cclosure_marshal_VOID__BOXED, G_TYPE_NONE, 1, G_TYPE_VALUE
|
|
|
|
);
|
|
|
|
signals[SPEC_CHANGED] = g_signal_new ("spec-changed",
|
|
|
|
GVN_TYPE_PARAM, G_SIGNAL_RUN_FIRST, 0, NULL, NULL,
|
|
|
|
g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0
|
|
|
|
);
|
|
|
|
signals[STATUS_CHANGED] = g_signal_new ("status-changed",
|
|
|
|
GVN_TYPE_PARAM, G_SIGNAL_RUN_FIRST, 0, NULL, NULL,
|
|
|
|
g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0
|
|
|
|
);
|
|
|
|
|
2014-07-16 14:12:36 +00:00
|
|
|
g_object_interface_install_property (iface,
|
2013-10-11 23:07:35 +00:00
|
|
|
g_param_spec_boxed ("value"
|
|
|
|
,_("Value")
|
|
|
|
,_("The value of the param")
|
|
|
|
,G_TYPE_VALUE
|
|
|
|
,G_PARAM_READWRITE
|
|
|
|
));
|
2014-07-16 14:12:36 +00:00
|
|
|
g_object_interface_install_property (iface,
|
2013-10-11 23:07:35 +00:00
|
|
|
g_param_spec_object ("master"
|
|
|
|
,_("Master")
|
2014-07-16 14:12:36 +00:00
|
|
|
,_("The master parameter")
|
2013-10-11 23:07:35 +00:00
|
|
|
,GVN_TYPE_PARAM
|
|
|
|
,G_PARAM_READWRITE
|
|
|
|
));
|
|
|
|
}
|