gnome-scan r694 - in trunk: . modules/gsane



Author: bersace
Date: Mon Dec 15 10:40:29 2008
New Revision: 694
URL: http://svn.gnome.org/viewvc/gnome-scan?rev=694&view=rev

Log:
Expose SANE list constrained int option as Enum option.


Modified:
   trunk/ChangeLog
   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-option-handler-generic.c
==============================================================================
--- trunk/modules/gsane/gsane-option-handler-generic.c	(original)
+++ trunk/modules/gsane/gsane-option-handler-generic.c	Mon Dec 15 10:40:29 2008
@@ -69,6 +69,38 @@
 }
 
 static void
+gsane_option_handler_generic_enum_option_value_changed(GSaneOptionHandlerGeneric* self, GParamSpec* pspec, GObject* option)
+{
+	GnomeScanEnumValue *evalue;
+	g_object_get(option, "value", &evalue, NULL);
+	gsane_option_handler_set_enum(GSANE_OPTION_HANDLER(self), self->priv->desc, self->priv->index, evalue, NULL);
+}
+
+
+
+static void
+gsane_option_handler_generic_handle_bool_option(GSaneOptionHandler *handler, SANE_Int n, const SANE_Option_Descriptor*desc, const gchar* group)
+{
+	GSaneOptionHandlerGeneric* self = GSANE_OPTION_HANDLER_GENERIC(handler);
+	gboolean value = 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, value, 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(value));
+}
+
+static void
+gsane_option_handler_generic_handle_string_option(GSaneOptionHandler *handler, SANE_Int n, const SANE_Option_Descriptor*desc, const gchar* group)
+{
+	GSaneOptionHandlerGeneric* self = GSANE_OPTION_HANDLER_GENERIC(handler);
+	gchar* value = gsane_option_handler_get_string(handler, desc, n, NULL);
+	self->priv->option = GNOME_SCAN_OPTION(gnome_scan_option_string_new(desc->name, S_(desc->title), S_(desc->desc), group, SANE_GETTEXT_PACKAGE,
+									    value, GNOME_SCAN_OPTION_HINT_SECONDARY));
+	g_signal_connect_swapped(self->priv->option, "notify::value", G_CALLBACK(gsane_option_handler_generic_string_option_value_changed), self);
+	g_debug("\toption  %d : string %s = \"%s\"", n, desc->name, value);
+	g_free(value);
+}
+
+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);
@@ -119,18 +151,12 @@
 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;
-	gchar* strval;
 	gint array_length;
 
 	/* instanciate option with default value depending on SANE_Value_Type */
 	switch(desc->type) {
 	case SANE_TYPE_BOOL:
-		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));
+		gsane_option_handler_generic_handle_bool_option(handler, n, desc, group);
 		break;
 	case SANE_TYPE_INT:
 		array_length = desc->size / sizeof(SANE_Word);
@@ -147,12 +173,7 @@
 			gsane_option_handler_generic_handle_double_option(handler, n, desc, group);
 		break;
 	case SANE_TYPE_STRING:
-		strval = gsane_option_handler_get_string(handler, desc, n, NULL);
-		self->priv->option = GNOME_SCAN_OPTION(gnome_scan_option_string_new(desc->name, S_(desc->title), S_(desc->desc), group, SANE_GETTEXT_PACKAGE,
-										    strval, GNOME_SCAN_OPTION_HINT_SECONDARY));
-		g_signal_connect_swapped(self->priv->option, "notify::value", G_CALLBACK(gsane_option_handler_generic_string_option_value_changed), self);
-		g_debug("\toption  %d : string %s = \"%s\"", n, desc->name, strval);
-		g_free(strval);
+		gsane_option_handler_generic_handle_string_option(handler, n, desc, group);
 		break;
 	default:
 		g_debug("\toption %d : <unhandled> %s", n, desc->name);
@@ -161,9 +182,61 @@
 }
 
 static void
+gsane_option_handler_generic_handle_int_list_option(GSaneOptionHandler *handler, SANE_Int n, const SANE_Option_Descriptor*desc, const gchar* group)
+{
+	GSaneOptionHandlerGeneric* self = GSANE_OPTION_HANDLER_GENERIC(handler);
+	GSList *list = NULL;
+	gint count = desc->constraint.word_list[0];
+	gint i, intval;
+	GValue* values = g_new0(GValue, count);
+	GValue* value;
+	GnomeScanEnumValue* evalues = g_new0(GnomeScanEnumValue, count);
+	GnomeScanEnumValue* evalue;
+
+	/* list values */
+	for(i = 0; i < count; i++) {
+		value = values+i;
+		evalue = evalues+i;
+		intval = desc->constraint.word_list[i+1];
+
+		g_value_init(value, G_TYPE_INT);
+		g_value_set_int(value, intval);
+
+		gnome_scan_enum_value_init(evalue, value, g_strdup_printf("%i", intval), NULL);
+		list = g_slist_append(list, evalue);
+	}
+
+	/* retrieve default value */
+	evalue = gsane_option_handler_get_enum(handler, desc, n, list, NULL);
+	/* instanciate value */
+	self->priv->option = GNOME_SCAN_OPTION(gnome_scan_option_enum_new(desc->name, S_(desc->title), S_(desc->desc), group, SANE_GETTEXT_PACKAGE,
+									  evalue, list, GNOME_SCAN_OPTION_HINT_SECONDARY));
+	g_free(values);
+}
+
+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);
+	GSaneOptionHandlerGeneric* self = GSANE_OPTION_HANDLER_GENERIC(handler);
+	gint array_length;
+
+	switch(desc->type) {
+	case SANE_TYPE_INT:
+		array_length = desc->size/sizeof(SANE_Int);
+		if (array_length > 1)
+			g_debug("Ignoring int enum array option %s", desc->name);
+		else
+			gsane_option_handler_generic_handle_int_list_option(handler, n, desc, group);
+		break;
+	default:
+		g_debug("\toption %d : <unhandled> %s", n, desc->name);
+		break;
+	}
+
+	if (!self->priv->option)
+		return;
+
+	g_signal_connect_swapped(self->priv->option, "notify::value", G_CALLBACK(gsane_option_handler_generic_enum_option_value_changed), self);
 }
 
 static void

Modified: trunk/modules/gsane/gsane-option-handler.c
==============================================================================
--- trunk/modules/gsane/gsane-option-handler.c	(original)
+++ trunk/modules/gsane/gsane-option-handler.c	Mon Dec 15 10:40:29 2008
@@ -205,6 +205,44 @@
 }
 
 
+
+
+
+
+GnomeScanEnumValue*
+gsane_option_handler_get_enum(GSaneOptionHandler *self, const SANE_Option_Descriptor* desc, SANE_Int index, GSList* values, GError **error)
+{
+	gint intval, testval;
+	GSList* iter;
+	GnomeScanEnumValue* evalue;
+	GValue *value;
+
+	switch(desc->type) {
+	case SANE_TYPE_INT:
+		intval = gsane_option_handler_get_int(self, desc, index, error);
+		for (iter = values; iter; iter = iter->next) {
+			evalue = iter->data;
+			value = evalue->value;
+			testval = g_value_get_int(value);
+			if (testval == intval) {
+				return evalue;
+			}
+		}
+		return values->data;
+		break;
+	default:
+		break;
+	}
+
+	return NULL;
+}
+
+void
+gsane_option_handler_set_enum(GSaneOptionHandler *self, const SANE_Option_Descriptor* desc, SANE_Int index, GnomeScanEnumValue* value, GError **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	Mon Dec 15 10:40:29 2008
@@ -79,6 +79,9 @@
 gchar* gsane_option_handler_get_string(GSaneOptionHandler *self, const SANE_Option_Descriptor* desc, SANE_Int index, GError **error);
 void gsane_option_handler_set_string(GSaneOptionHandler *self, const SANE_Option_Descriptor* desc, SANE_Int index, gchar* value, GError **error);
 
+GnomeScanEnumValue* gsane_option_handler_get_enum(GSaneOptionHandler *self, const SANE_Option_Descriptor* desc, SANE_Int index, GSList* values, GError **error);
+void gsane_option_handler_set_enum(GSaneOptionHandler *self, const SANE_Option_Descriptor* desc, SANE_Int index, GnomeScanEnumValue* 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]