gnome-scan r699 - in trunk: . modules/gsane
- From: bersace svn gnome org
- To: svn-commits-list gnome org
- Subject: gnome-scan r699 - in trunk: . modules/gsane
- Date: Mon, 15 Dec 2008 21:18:44 +0000 (UTC)
Author: bersace
Date: Mon Dec 15 21:18:44 2008
New Revision: 699
URL: http://svn.gnome.org/viewvc/gnome-scan?rev=699&view=rev
Log:
Added support for string enum. Reread option when inexact value is set.
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 21:18:44 2008
@@ -47,7 +47,9 @@
{
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);
+ if (gsane_option_handler_set_int(GSANE_OPTION_HANDLER(self), self->priv->desc, self->priv->index, value, NULL))
+ gnome_scan_option_int_set_value(GNOME_SCAN_OPTION_INT(option),
+ gsane_option_handler_get_int(GSANE_OPTION_HANDLER(self), self->priv->desc, self->priv->index, NULL));
}
@@ -56,7 +58,9 @@
{
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);
+ if (gsane_option_handler_set_double(GSANE_OPTION_HANDLER(self), self->priv->desc, self->priv->index, value, NULL))
+ gnome_scan_option_double_set_value(GNOME_SCAN_OPTION_DOUBLE(option),
+ gsane_option_handler_get_double(GSANE_OPTION_HANDLER(self), self->priv->desc, self->priv->index, NULL));
}
static void
@@ -69,15 +73,17 @@
}
static void
-gsane_option_handler_generic_enum_option_value_changed(GSaneOptionHandlerGeneric* self, GParamSpec* pspec, GObject* option)
+gsane_option_handler_generic_enum_option_changed(GSaneOptionHandlerGeneric* self, 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);
+ GnomeScanEnumValue evalue = {0};
+ 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);
}
+
+
static void
gsane_option_handler_generic_handle_bool_option(GSaneOptionHandler *handler, SANE_Int n, const SANE_Option_Descriptor*desc, const gchar* group)
{
@@ -231,6 +237,29 @@
return list;
}
+static GSList*
+gsane_option_handler_generic_enum_list_string_values(GSaneOptionHandler *handler, SANE_Int n, const SANE_Option_Descriptor*desc, const gchar* group)
+{
+ GSList *list = NULL;
+ gint i;
+ const gchar*strval;
+ GValue *value;
+ GnomeScanEnumValue *evalue;
+ const SANE_String_Const *strlist = desc->constraint.string_list;
+
+ for(i = 0; strlist[i]; i++) {
+ strval = strlist[i];
+ value = g_new0(GValue, 1);
+ evalue = g_new0(GnomeScanEnumValue, 1);
+ g_value_init(value, G_TYPE_STRING);
+ g_value_set_string(value, strval);
+ gnome_scan_enum_value_init(evalue, value, S_(strval), SANE_GETTEXT_PACKAGE);
+ list = g_slist_append(list, evalue);
+ g_free(value);
+ }
+ return list;
+}
+
static void
gsane_option_handler_generic_handle_list_option(GSaneOptionHandler *handler, SANE_Int n, const SANE_Option_Descriptor*desc, const gchar* group)
@@ -255,6 +284,9 @@
else
values = gsane_option_handler_generic_enum_list_double_values(handler, n, desc, group);
break;
+ case SANE_TYPE_STRING:
+ values = gsane_option_handler_generic_enum_list_string_values(handler, n, desc, group);
+ break;
default:
g_debug("\toption %d : <unhandled> %s", n, desc->name);
break;
@@ -266,7 +298,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));
- g_signal_connect_swapped(self->priv->option, "notify::value", G_CALLBACK(gsane_option_handler_generic_enum_option_value_changed), self);
+ g_signal_connect_swapped(self->priv->option, "changed", G_CALLBACK(gsane_option_handler_generic_enum_option_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 21:18:44 2008
@@ -106,7 +106,7 @@
/* wrapper aroung sane_control_option handling errors and propagating
reload signals */
-static void
+static gboolean
gsane_option_handler_control_option(GSaneOptionHandler*self, const SANE_Option_Descriptor* desc, SANE_Int index, SANE_Action action, gpointer data, GError**error)
{
SANE_Status status;
@@ -115,13 +115,13 @@
if (!SANE_OPTION_IS_ACTIVE(desc->cap)) {
g_propagate_error(error, g_error_new(GSANE_ERROR, GSANE_ERROR_OPTION_INACTIVE,
"Option %s is inactive", desc->name));
- return;
+ return FALSE;
}
if (action == SANE_ACTION_SET_VALUE && !SANE_OPTION_IS_SETTABLE(desc->cap)) {
g_propagate_error(error, g_error_new(GSANE_ERROR, GSANE_ERROR_OPTION_READONLY,
"Unable to set readonly option %s", desc->name));
- return;
+ return FALSE;
}
status = sane_control_option(self->priv->handle, index, action, data, &flags);
@@ -129,15 +129,22 @@
if (status != SANE_STATUS_GOOD) {
gsane_propagate_prefixed_status(error, status,
"%s(%s)", GSANE_ACTION_TO_STRING(action), desc->name);
- return;
+ return FALSE;
}
- if (flags & SANE_INFO_INEXACT)
- g_debug("Value inexact");
+ gboolean inexact = FALSE;
+ if (flags & SANE_INFO_INEXACT) {
+ g_debug("Setting %s : value inexact", desc->name);
+ inexact = TRUE;
+ }
+ else
+ gs_debug("%s(%s) successful", GSANE_ACTION_TO_STRING(action), desc->name);
if (flags & SANE_INFO_RELOAD_OPTIONS)
g_signal_emit_by_name(self->scanner, "reload-options");
if (flags & SANE_INFO_RELOAD_PARAMS)
g_debug("Reload params");
+
+ return inexact;
}
@@ -149,10 +156,10 @@
return value;
}
-void
+gboolean
gsane_option_handler_set_bool(GSaneOptionHandler *self, const SANE_Option_Descriptor* desc, SANE_Int index, gboolean value, GError**error)
{
- gsane_option_handler_control_option(self, desc, index, SANE_ACTION_SET_VALUE, &value, error);
+ return gsane_option_handler_control_option(self, desc, index, SANE_ACTION_SET_VALUE, &value, error);
}
@@ -164,10 +171,10 @@
return value;
}
-void
+gboolean
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);
+ return gsane_option_handler_control_option(self, desc, index, SANE_ACTION_SET_VALUE, &value, error);
}
@@ -179,11 +186,11 @@
return SANE_UNFIX(value);
}
-void
+gboolean
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);
+ return gsane_option_handler_control_option(self, desc, index, SANE_ACTION_SET_VALUE, &fixed, error);
}
@@ -198,10 +205,10 @@
return ret;
}
-void
+gboolean
gsane_option_handler_set_string(GSaneOptionHandler *self, const SANE_Option_Descriptor* desc, SANE_Int index, gchar* value, GError **error)
{
- gsane_option_handler_control_option(self, desc, index, SANE_ACTION_SET_VALUE, value, error);
+ return gsane_option_handler_control_option(self, desc, index, SANE_ACTION_SET_VALUE, value, error);
}
@@ -214,6 +221,7 @@
{
gint intval;
gdouble doubleval;
+ gchar* strval;
GSList* iter;
GnomeScanEnumValue* evalue;
@@ -234,6 +242,13 @@
if (g_value_get_double(evalue->value) == doubleval)
return evalue;
}
+ case SANE_TYPE_STRING:
+ strval = gsane_option_handler_get_string(self, desc, index, error);
+ for (iter = values; iter; iter = iter->next) {
+ evalue = iter->data;
+ if (g_str_equal(g_value_get_string(evalue->value), strval))
+ return evalue;
+ }
default:
break;
}
@@ -241,17 +256,20 @@
return NULL;
}
-void
+gboolean
gsane_option_handler_set_enum(GSaneOptionHandler *self, const SANE_Option_Descriptor* desc, SANE_Int index, GnomeScanEnumValue* value, GError **error)
{
switch(desc->type) {
case SANE_TYPE_INT:
- gsane_option_handler_set_int(self, desc, index, g_value_get_double(value->value), error);
+ return gsane_option_handler_set_int(self, desc, index, g_value_get_double(value->value), error);
break;
case SANE_TYPE_FIXED:
- gsane_option_handler_set_double(self, desc, index, g_value_get_double(value->value), error);
+ return gsane_option_handler_set_double(self, desc, index, g_value_get_double(value->value), error);
break;
+ case SANE_TYPE_STRING:
+ return gsane_option_handler_set_string(self, desc, index, g_value_dup_string(value->value), error);
default:
+ return FALSE;
break;
}
}
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 21:18:44 2008
@@ -68,19 +68,19 @@
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);
+gboolean 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);
+gboolean 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);
+gboolean gsane_option_handler_set_double(GSaneOptionHandler *self, const SANE_Option_Descriptor* desc, SANE_Int index, gdouble value, GError **error);
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);
+gboolean 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);
+gboolean 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;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]