gnome-scan r686 - in trunk: . modules/gsane
- From: bersace svn gnome org
- To: svn-commits-list gnome org
- Subject: gnome-scan r686 - in trunk: . modules/gsane
- Date: Sun, 14 Dec 2008 17:24:06 +0000 (UTC)
Author: bersace
Date: Sun Dec 14 17:24:06 2008
New Revision: 686
URL: http://svn.gnome.org/viewvc/gnome-scan?rev=686&view=rev
Log:
Added double option support to GSane.
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 17:24:06 2008
@@ -62,6 +62,7 @@
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);
}
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 17:24:06 2008
@@ -52,13 +52,67 @@
static void
+gsane_option_handler_generic_double_option_value_changed(GSaneOptionHandlerGeneric* self, GParamSpec* pspec, GObject* option)
+{
+ gdouble value;
+ g_object_get(option, "value", &value, NULL);
+ gsane_option_handler_set_double(GSANE_OPTION_HANDLER(self), self->priv->desc, self->priv->index, value, NULL);
+}
+
+static void
+gsane_option_handler_generic_handle_int_option(GSaneOptionHandler *handler, SANE_Int n, const SANE_Option_Descriptor*desc, const gchar* group)
+{
+ GSaneOptionHandlerGeneric* self = GSANE_OPTION_HANDLER_GENERIC(handler);
+ gint value, min, step, max;
+
+ value = gsane_option_handler_get_int(handler, desc, n, NULL);
+ if (desc->constraint_type == SANE_CONSTRAINT_RANGE) {
+ min = desc->constraint.range->min;
+ step = desc->constraint.range->quant;
+ max = desc->constraint.range->max;
+ }
+ else {
+ min = G_MININT;
+ step = 1;
+ max = 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,
+ value, min, step, max,
+ gsane_option_unit(desc), 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, range = [%d;%d;%d]", n, desc->name, value, min, step, max);
+}
+
+static void
+gsane_option_handler_generic_handle_double_option(GSaneOptionHandler *handler, SANE_Int n, const SANE_Option_Descriptor*desc, const gchar* group)
+{
+ GSaneOptionHandlerGeneric* self = GSANE_OPTION_HANDLER_GENERIC(handler);
+ gdouble value, min, step, max;
+
+ value = gsane_option_handler_get_double(handler, desc, n, NULL);
+ if (desc->constraint_type == SANE_CONSTRAINT_RANGE) {
+ min = SANE_UNFIX(desc->constraint.range->min);
+ step = SANE_UNFIX(desc->constraint.range->quant);
+ max = SANE_UNFIX(desc->constraint.range->max);
+ }
+ else {
+ min = G_MINDOUBLE;
+ step = 1.;
+ max = G_MAXDOUBLE;
+ }
+ self->priv->option = GNOME_SCAN_OPTION(gnome_scan_option_double_new(desc->name, S_(desc->title), S_(desc->desc), group, SANE_GETTEXT_PACKAGE,
+ value, min, step, max,
+ gsane_option_unit(desc), GNOME_SCAN_OPTION_HINT_SECONDARY));
+ g_signal_connect_swapped(self->priv->option, "notify::value", G_CALLBACK(gsane_option_handler_generic_double_option_value_changed), self);
+ g_debug("\toption %d : double %s = %.2g, range = [%.2e;%.2e;%.2e]", n, desc->name, value, min, step, max);
+}
+
+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;
gint array_length;
- gint intval;
- gint intmin, intstep, intmax;
/* instanciate option with default value depending on SANE_Value_Type */
switch(desc->type) {
@@ -70,26 +124,17 @@
break;
case SANE_TYPE_INT:
array_length = desc->size / sizeof(SANE_Word);
- if (array_length > 1) {
+ if (array_length > 1)
g_debug("Ignoring int array option %s", desc->name);
- break;
- }
- 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,
- gsane_option_unit(desc), 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);
+ else
+ gsane_option_handler_generic_handle_int_option(handler, n, desc, group);
+ break;
+ case SANE_TYPE_FIXED:
+ array_length = desc->size / sizeof(SANE_Word);
+ if (array_length > 1)
+ g_debug("Ignoring double array option %s", desc->name);
+ else
+ gsane_option_handler_generic_handle_double_option(handler, n, desc, group);
break;
default:
g_debug("\toption %d : <unhandled> %s", n, desc->name);
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 17:24:06 2008
@@ -30,7 +30,8 @@
SANE_Handle handle;
};
-GnomeScanOptionHint gsane_option_hint(const SANE_Option_Descriptor*desc)
+GnomeScanOptionHint
+gsane_option_hint(const SANE_Option_Descriptor*desc)
{
if (desc->cap & SANE_CAP_ADVANCED) {
return GNOME_SCAN_OPTION_HINT_SECONDARY;
@@ -40,6 +41,27 @@
}
}
+GnomeScanUnit
+gsane_option_unit(const SANE_Option_Descriptor* desc)
+{
+ switch(desc->unit) {
+ case SANE_UNIT_PIXEL:
+ return GNOME_SCAN_UNIT_PIXEL;
+ case SANE_UNIT_BIT:
+ return GNOME_SCAN_UNIT_BIT;
+ case SANE_UNIT_MM:
+ return GNOME_SCAN_UNIT_MM;
+ case SANE_UNIT_DPI:
+ return GNOME_SCAN_UNIT_DPI;
+ case SANE_UNIT_PERCENT:
+ return GNOME_SCAN_UNIT_PERCENT;
+ case SANE_UNIT_MICROSECOND:
+ return GNOME_SCAN_UNIT_MICROSECOND;
+ default:
+ return GNOME_SCAN_UNIT_NONE;
+ }
+}
+
GSaneOptionHandler*
gsane_option_handler_new(GType type, GnomeScanScanner* scanner, SANE_Handle handle)
{
@@ -148,6 +170,22 @@
gsane_option_handler_control_option(self, desc, index, SANE_ACTION_SET_VALUE, &value, error);
}
+
+gdouble
+gsane_option_handler_get_double(GSaneOptionHandler *self, const SANE_Option_Descriptor* desc, SANE_Int index, GError **error)
+{
+ SANE_Word value;
+ gsane_option_handler_control_option(self, desc, index, SANE_ACTION_GET_VALUE, &value, error);
+ return SANE_UNFIX(value);
+}
+
+void
+gsane_option_handler_set_double(GSaneOptionHandler *self, const SANE_Option_Descriptor* desc, SANE_Int index, gdouble value, GError **error)
+{
+ SANE_Fixed fixed = SANE_FIX(value);
+ gsane_option_handler_control_option(self, desc, index, SANE_ACTION_SET_VALUE, &fixed, error);
+}
+
/* GType instance boiler plate code */
void
gsane_option_handler_instance_init(GTypeInstance *instance, gpointer g_class)
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 17:24:06 2008
@@ -57,9 +57,11 @@
GSaneOptionHandlerPrivate* priv;
};
-/* utils */
+/* option utils */
GnomeScanOptionHint gsane_option_hint(const SANE_Option_Descriptor*desc);
+GnomeScanUnit gsane_option_unit(const SANE_Option_Descriptor* desc);
+/* option handler methods */
GSaneOptionHandler* gsane_option_handler_new(GType type, GnomeScanScanner *scanner, SANE_Handle handle);
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);
@@ -71,6 +73,9 @@
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);
+gdouble gsane_option_handler_get_double(GSaneOptionHandler *self, const SANE_Option_Descriptor* desc, SANE_Int index, GError **error);
+void gsane_option_handler_set_double(GSaneOptionHandler *self, const SANE_Option_Descriptor* desc, SANE_Int index, gdouble 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]