gnome-scan r683 - in trunk: . modules/gsane
- From: bersace svn gnome org
- To: svn-commits-list gnome org
- Subject: gnome-scan r683 - in trunk: . modules/gsane
- Date: Sun, 14 Dec 2008 16:19:26 +0000 (UTC)
Author: bersace
Date: Sun Dec 14 16:19:26 2008
New Revision: 683
URL: http://svn.gnome.org/viewvc/gnome-scan?rev=683&view=rev
Log:
Added int option translation.
Modified:
trunk/ChangeLog
trunk/modules/gsane/gsane-module.c
trunk/modules/gsane/gsane-option-handler-generic.c
trunk/modules/gsane/gsane-option-handler.c
trunk/modules/gsane/gsane-option-handler.h
Modified: trunk/modules/gsane/gsane-module.c
==============================================================================
--- trunk/modules/gsane/gsane-module.c (original)
+++ trunk/modules/gsane/gsane-module.c Sun Dec 14 16:19:26 2008
@@ -62,8 +62,6 @@
gsane_option_manager = gsane_option_manager_new();
gsane_option_manager_add_rule_by_type(gsane_option_manager, SANE_TYPE_BOOL, GSANE_TYPE_OPTION_HANDLER_GENERIC);
gsane_option_manager_add_rule_by_type(gsane_option_manager, SANE_TYPE_INT, GSANE_TYPE_OPTION_HANDLER_GENERIC);
- gsane_option_manager_add_rule_by_type(gsane_option_manager, SANE_TYPE_FIXED, GSANE_TYPE_OPTION_HANDLER_GENERIC);
- gsane_option_manager_add_rule_by_type(gsane_option_manager, SANE_TYPE_STRING, GSANE_TYPE_OPTION_HANDLER_GENERIC);
}
G_MODULE_EXPORT void
Modified: trunk/modules/gsane/gsane-option-handler-generic.c
==============================================================================
--- trunk/modules/gsane/gsane-option-handler-generic.c (original)
+++ trunk/modules/gsane/gsane-option-handler-generic.c Sun Dec 14 16:19:26 2008
@@ -43,32 +43,75 @@
}
static void
-gsane_option_handler_generic_handle_option(GSaneOptionHandler *handler, SANE_Int n, const SANE_Option_Descriptor*desc, const gchar* group)
+gsane_option_handler_generic_int_option_value_changed(GSaneOptionHandlerGeneric* self, GParamSpec* pspec, GObject* option)
+{
+ gint value;
+ g_object_get(option, "value", &value, NULL);
+ gsane_option_handler_set_int(GSANE_OPTION_HANDLER(self), self->priv->desc, self->priv->index, value, NULL);
+}
+
+
+static void
+gsane_option_handler_generic_handle_non_list_option(GSaneOptionHandler *handler, SANE_Int n, const SANE_Option_Descriptor*desc, const gchar* group)
{
GSaneOptionHandlerGeneric* self = GSANE_OPTION_HANDLER_GENERIC(handler);
gboolean boolval;
- self->priv->index = n;
- self->priv->desc = desc;
-
- /* don't trust SANE test backend for primary/secondary
- options. Most primary options are swallowed in
- special/high-level OptionHandler. Might make sense to have
- a generic primary option handler subclassing Generic
- handler, with rules by name. */
- GnomeScanOptionHint hint = GNOME_SCAN_OPTION_HINT_SECONDARY;
+ gint intval;
+ gint intmin, intstep, intmax;
/* instanciate option with default value depending on SANE_Value_Type */
switch(desc->type) {
case SANE_TYPE_BOOL:
- boolval = gsane_option_handler_get_bool(GSANE_OPTION_HANDLER(self), desc, n, NULL);
- self->priv->option = GNOME_SCAN_OPTION(gnome_scan_option_bool_new(desc->name, S_(desc->title), S_(desc->desc), group, SANE_GETTEXT_PACKAGE, boolval, hint));
+ boolval = gsane_option_handler_get_bool(handler, desc, n, NULL);
+ self->priv->option = GNOME_SCAN_OPTION(gnome_scan_option_bool_new(desc->name, S_(desc->title), S_(desc->desc), group, SANE_GETTEXT_PACKAGE, boolval, GNOME_SCAN_OPTION_HINT_SECONDARY));
g_signal_connect_swapped(self->priv->option, "notify::value", G_CALLBACK(gsane_option_handler_generic_bool_option_value_changed), self);
g_debug("\toption %d : boolean %s = %s", n, desc->name, GSANE_BOOLEAN_TO_STRING(boolval));
break;
+ case SANE_TYPE_INT:
+ intval = gsane_option_handler_get_int(handler, desc, n, NULL);
+ if (desc->constraint_type == SANE_CONSTRAINT_RANGE) {
+ intmin = desc->constraint.range->min;
+ intstep = desc->constraint.range->quant;
+ intmax = desc->constraint.range->max;
+ }
+ else {
+ intmin = G_MININT;
+ intstep = 1;
+ intmax = G_MAXINT;
+ }
+ self->priv->option = GNOME_SCAN_OPTION(gnome_scan_option_int_new(desc->name, S_(desc->title), S_(desc->desc), group, SANE_GETTEXT_PACKAGE, intval, intmin, intstep, intmax, GNOME_SCAN_UNIT_NONE, GNOME_SCAN_OPTION_HINT_SECONDARY));
+ g_signal_connect_swapped(self->priv->option, "notify::value", G_CALLBACK(gsane_option_handler_generic_int_option_value_changed), self);
+ g_debug("\toption %d : int %s = %d", n, desc->name, intval);
+ break;
default:
g_debug("\toption %d : <unhandled> %s", n, desc->name);
break;
}
+}
+
+static void
+gsane_option_handler_generic_handle_list_option(GSaneOptionHandler *handler, SANE_Int n, const SANE_Option_Descriptor*desc, const gchar* group)
+{
+ g_debug("\toption %d : <unhandled> %s", n, desc->name);
+}
+
+static void
+gsane_option_handler_generic_handle_option(GSaneOptionHandler *handler, SANE_Int n, const SANE_Option_Descriptor*desc, const gchar* group)
+{
+ GSaneOptionHandlerGeneric* self = GSANE_OPTION_HANDLER_GENERIC(handler);
+ self->priv->index = n;
+ self->priv->desc = desc;
+
+ switch(desc->constraint_type) {
+ case SANE_CONSTRAINT_NONE:
+ case SANE_CONSTRAINT_RANGE:
+ gsane_option_handler_generic_handle_non_list_option(handler, n, desc, group);
+ break;
+ case SANE_CONSTRAINT_WORD_LIST:
+ case SANE_CONSTRAINT_STRING_LIST:
+ gsane_option_handler_generic_handle_list_option(handler, n, desc, group);
+ break;
+ }
if (!self->priv->option)
return;
Modified: trunk/modules/gsane/gsane-option-handler.c
==============================================================================
--- trunk/modules/gsane/gsane-option-handler.c (original)
+++ trunk/modules/gsane/gsane-option-handler.c Sun Dec 14 16:19:26 2008
@@ -56,6 +56,7 @@
g_type_free_instance((GTypeInstance*) self);
}
+/* handle-options abstract method */
static void
gsane_option_handler_default_handle_option(GSaneOptionHandler *self, SANE_Int n, const SANE_Option_Descriptor* desc, const gchar* group)
{
@@ -68,6 +69,7 @@
GSANE_OPTION_HANDLER_GET_CLASS(self)->handle_option(self, n, desc, group);
}
+/* reload-options abstract method */
static void
gsane_option_handler_default_reload_options(GSaneOptionHandler *self)
{
@@ -80,6 +82,8 @@
GSANE_OPTION_HANDLER_GET_CLASS(self)->reload_options(self);
}
+/* wrapper aroung sane_control_option handling errors and propagating
+ reload signals */
static void
gsane_option_handler_control_option(GSaneOptionHandler*self, const SANE_Option_Descriptor* desc, SANE_Int index, SANE_Action action, gpointer data, GError**error)
{
@@ -114,6 +118,7 @@
g_debug("Reload params");
}
+
gboolean
gsane_option_handler_get_bool(GSaneOptionHandler *self, const SANE_Option_Descriptor* desc, SANE_Int index, GError**error)
{
@@ -129,6 +134,20 @@
}
+gint
+gsane_option_handler_get_int(GSaneOptionHandler *self, const SANE_Option_Descriptor* desc, SANE_Int index, GError **error)
+{
+ gint value = 0;
+ gsane_option_handler_control_option(self, desc, index, SANE_ACTION_GET_VALUE, &value, error);
+ return value;
+}
+
+void
+gsane_option_handler_set_int(GSaneOptionHandler *self, const SANE_Option_Descriptor* desc, SANE_Int index, gint value, GError **error)
+{
+ gsane_option_handler_control_option(self, desc, index, SANE_ACTION_SET_VALUE, &value, error);
+}
+
/* GType instance boiler plate code */
void
gsane_option_handler_instance_init(GTypeInstance *instance, gpointer g_class)
@@ -159,7 +178,6 @@
.class_finalize = NULL,
.class_data = NULL,
.instance_size = sizeof(GSaneOptionHandler),
- .n_preallocs = 0,
.instance_init = gsane_option_handler_instance_init,
.value_table = NULL,
};
Modified: trunk/modules/gsane/gsane-option-handler.h
==============================================================================
--- trunk/modules/gsane/gsane-option-handler.h (original)
+++ trunk/modules/gsane/gsane-option-handler.h Sun Dec 14 16:19:26 2008
@@ -64,9 +64,13 @@
void gsane_option_handler_destroy(GSaneOptionHandler *self);
void gsane_option_handler_handle_option(GSaneOptionHandler *self, SANE_Int n, const SANE_Option_Descriptor* desc, const gchar*group);
void gsane_option_handler_reload_options(GSaneOptionHandler *self);
+
gboolean gsane_option_handler_get_bool(GSaneOptionHandler *self, const SANE_Option_Descriptor* desc, SANE_Int index, GError **error);
void gsane_option_handler_set_bool(GSaneOptionHandler *self, const SANE_Option_Descriptor* desc, SANE_Int index, gboolean value, GError **error);
+gint gsane_option_handler_get_int(GSaneOptionHandler *self, const SANE_Option_Descriptor* desc, SANE_Int index, GError **error);
+void gsane_option_handler_set_int(GSaneOptionHandler *self, const SANE_Option_Descriptor* desc, SANE_Int index, gint value, GError **error);
+
GType gsane_option_handler_get_type(void) G_GNUC_CONST;
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]