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



Author: bersace
Date: Sat Dec 20 15:32:47 2008
New Revision: 714
URL: http://svn.gnome.org/viewvc/gnome-scan?rev=714&view=rev

Log:
Check option value on option-reload.

Modified:
   trunk/ChangeLog
   trunk/modules/gsane/gsane-option-handler-generic.c

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	Sat Dec 20 15:32:47 2008
@@ -30,10 +30,51 @@
 	SANE_Int index;
 	const SANE_Option_Descriptor* desc;
 	GnomeScanOption* option;
+	void (*get_value) (GSaneOptionHandlerGeneric *self);
 };
 
 static GSaneOptionHandlerClass*gsane_option_handler_generic_parent_class = NULL;
 
+
+static void
+gsane_option_handler_generic_bool_get_value(GSaneOptionHandlerGeneric *self)
+{
+	gboolean value = gsane_option_handler_get_bool(GSANE_OPTION_HANDLER(self), self->priv->desc, self->priv->index, NULL);
+	gnome_scan_option_bool_set_value(GNOME_SCAN_OPTION_BOOL(self->priv->option), value);
+}
+
+static void
+gsane_option_handler_generic_int_get_value(GSaneOptionHandlerGeneric *self)
+{
+	gint value = gsane_option_handler_get_int(GSANE_OPTION_HANDLER(self), self->priv->desc, self->priv->index, NULL);
+	gnome_scan_option_int_set_value(GNOME_SCAN_OPTION_INT(self->priv->option), value);
+}
+
+static void
+gsane_option_handler_generic_double_get_value(GSaneOptionHandlerGeneric *self)
+{
+	gdouble value = gsane_option_handler_get_double(GSANE_OPTION_HANDLER(self), self->priv->desc, self->priv->index, NULL);
+	gnome_scan_option_double_set_value(GNOME_SCAN_OPTION_DOUBLE(self->priv->option), value);
+}
+
+static void
+gsane_option_handler_generic_string_get_value(GSaneOptionHandlerGeneric *self)
+{
+	gchar* value = gsane_option_handler_get_string(GSANE_OPTION_HANDLER(self), self->priv->desc, self->priv->index, NULL);
+	gnome_scan_option_string_set_value(GNOME_SCAN_OPTION_STRING(self->priv->option), value);
+}
+
+static void
+gsane_option_handler_generic_enum_get_value(GSaneOptionHandlerGeneric *self)
+{
+	GnomeScanEnumValue* value = gsane_option_handler_get_enum(GSANE_OPTION_HANDLER(self), self->priv->desc, self->priv->index,
+								  gnome_scan_option_enum_get_values(GNOME_SCAN_OPTION_ENUM(self->priv->option)),
+								  NULL);
+	gnome_scan_option_enum_set_value(GNOME_SCAN_OPTION_ENUM(self->priv->option), &value);
+}
+
+
+
 static void
 gsane_option_handler_generic_bool_option_value_changed(GSaneOptionHandlerGeneric* self, GParamSpec* pspec, GObject* option)
 {
@@ -75,38 +116,26 @@
 static void
 gsane_option_handler_generic_enum_option_changed(GSaneOptionHandlerGeneric* self, GObject* option)
 {
-	GnomeScanEnumValue evalue = {0};
+	GnomeScanEnumValue *evalue = NULL;
 	gnome_scan_option_enum_get_value(GNOME_SCAN_OPTION_ENUM(option), &evalue);
-	gsane_option_handler_set_enum(GSANE_OPTION_HANDLER(self), self->priv->desc, self->priv->index, &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));
+	self->priv->get_value = gsane_option_handler_generic_bool_get_value;
 	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);
@@ -126,6 +155,7 @@
 	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));
+	self->priv->get_value = gsane_option_handler_generic_int_get_value;
 	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);
 }
@@ -150,11 +180,25 @@
 	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));
+	self->priv->get_value = gsane_option_handler_generic_double_get_value;
 	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_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));
+	self->priv->get_value = gsane_option_handler_generic_string_get_value;
+	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_non_list_option(GSaneOptionHandler *handler, SANE_Int n, const SANE_Option_Descriptor*desc, const gchar* group)
 {
 	gint array_length;
@@ -298,6 +342,7 @@
 	default_value = gsane_option_handler_get_enum(handler, desc, n, values, NULL);
 	self->priv->option = GNOME_SCAN_OPTION(gnome_scan_option_enum_new(desc->name, S_(desc->title), S_(desc->desc), group, SANE_GETTEXT_PACKAGE,
 									  default_value, values, GNOME_SCAN_OPTION_HINT_SECONDARY));
+	self->priv->get_value = gsane_option_handler_generic_enum_get_value;
 	g_signal_connect_swapped(self->priv->option, "changed", G_CALLBACK(gsane_option_handler_generic_enum_option_changed), self);
 }
 
@@ -336,7 +381,16 @@
 	if (!self->priv->option) {
 		return;
 	}
-	g_object_set(self->priv->option, "active", SANE_OPTION_IS_ACTIVE(self->priv->desc->cap), NULL);
+	gboolean was_active = gnome_scan_option_get_active(self->priv->option);
+	gboolean is_active = SANE_OPTION_IS_ACTIVE(self->priv->desc->cap);
+	if (!was_active && is_active) {
+		g_object_freeze_notify(G_OBJECT(self->priv->option));
+		self->priv->get_value(self);
+		g_object_thaw_notify(G_OBJECT(self->priv->option));
+	}
+
+	if (was_active != is_active)
+		gnome_scan_option_set_active(self->priv->option, is_active);
 }
 
 static void



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]