gnome-scan r821 - in trunk: . lib modules/gsane



Author: bersace
Date: Tue Feb  3 19:54:51 2009
New Revision: 821
URL: http://svn.gnome.org/viewvc/gnome-scan?rev=821&view=rev

Log:
Merge OptionInt and OptionDouble in OptionNumber

Modified:
   trunk/ChangeLog
   trunk/lib/gnome-scan-init.vala
   trunk/lib/gnome-scan-option.vala
   trunk/lib/gnome-scan-scale-widget.vala
   trunk/modules/gsane/gsane-option-handler-generic.c

Modified: trunk/lib/gnome-scan-init.vala
==============================================================================
--- trunk/lib/gnome-scan-init.vala	(original)
+++ trunk/lib/gnome-scan-init.vala	Tue Feb  3 19:54:51 2009
@@ -39,8 +39,7 @@
 
 		option_manager = new OptionManager();
 		option_manager.register_rule_by_type(typeof(OptionBool), typeof(CheckboxWidget));
-		option_manager.register_rule_by_type(typeof(OptionInt), typeof(ScaleWidget));
-		option_manager.register_rule_by_type(typeof(OptionDouble), typeof(ScaleWidget));
+		option_manager.register_rule_by_type(typeof(OptionNumber), typeof(ScaleWidget));
 		option_manager.register_rule_by_type(typeof(OptionString), typeof(EntryWidget));
 		option_manager.register_rule_by_type(typeof(OptionEnum), typeof(ComboBoxWidget));
 		option_manager.register_rule_by_type(typeof(OptionPaperSize), typeof(PaperSizeWidget));

Modified: trunk/lib/gnome-scan-option.vala
==============================================================================
--- trunk/lib/gnome-scan-option.vala	(original)
+++ trunk/lib/gnome-scan-option.vala	Tue Feb  3 19:54:51 2009
@@ -100,42 +100,12 @@
 		}
 	}
 
-	public class OptionInt : Option {
-		public int value {set; get;}
-		public int min {set construct; get;}
-		public int step {set construct; get;}
-		public int max {set construct; get;}
-
-		public OptionInt(string name, string title, string desc, string group, string domain, int value, int min, int step, int max, Gnome.Scan.Unit unit, OptionHint hint)
-		{
-			this.name = name;
-			this.title = title;
-			this.desc = desc;
-			this.group = group;
-			this.domain = domain;
-			this.value = value;
-			this.min = min;
-			this.step = step;
-			this.max = max;
-			this.unit = unit;
-			this.hint = hint;
-		}
-
-		public override void set_g_value(Value value)
-		{
-			Value oval = Value(typeof(int));
-			if (this.copy_or_transform_g_value(value, ref oval))
-				this.value = oval.get_int();
-		}
-	}
-
-	public class OptionDouble : Option {
+	public class OptionNumber : Option
+	{
 		public double value {set; get;}
-		public double min {set construct; get;}
-		public double step {set construct; get;}
-		public double max {set construct; get;}
+		public Range range {set construct; get;}
 
-		public OptionDouble(string name, string title, string desc, string group, string domain, double value, double min, double step, double max, Gnome.Scan.Unit unit, OptionHint hint)
+		public OptionNumber(string name, string title, string desc, string group, string domain, double value, Range range, Gnome.Scan.Unit unit, OptionHint hint)
 		{
 			this.name = name;
 			this.title = title;
@@ -143,9 +113,7 @@
 			this.group = group;
 			this.domain = domain;
 			this.value = value;
-			this.min = min;
-			this.step = step;
-			this.max = max;
+			this.range = range;
 			this.unit = unit;
 			this.hint = hint;
 		}

Modified: trunk/lib/gnome-scan-scale-widget.vala
==============================================================================
--- trunk/lib/gnome-scan-scale-widget.vala	(original)
+++ trunk/lib/gnome-scan-scale-widget.vala	Tue Feb  3 19:54:51 2009
@@ -32,63 +32,36 @@
 			SpinButton spin;
 			Scale scale;
 			int digits = 0;
-			if (option is OptionInt) {
-				var option = this.option as OptionInt;
 
-				adj = new Adjustment(option.value, option.min, option.max, option.step, option.step, 0);
+			var option = this.option as OptionNumber;
 
-				scale = new HScale(adj);
-				scale.draw_value = false;
-				scale.set_digits(digits);
+			adj = new Adjustment(option.value, option.range.min, option.range.max, option.range.step, option.range.step, 0);
 
-				spin = new SpinButton(adj, option.step, digits);
+			if (option.range.step < 1.0)
+				digits = 2;
 
-				adj.notify["value"] += this.on_int_adj_value_changed;
-				option.notify["value"] += this.on_int_option_value_changed;
-			}
-			else if (option is OptionDouble) {
-				var option = this.option as OptionDouble;
+			scale = new HScale(adj);
+			scale.draw_value = false;
+			scale.set_digits(digits);
 
-				if (option.step < 1.0)
-					digits = 2;
+			spin = new SpinButton(adj, option.range.step, digits);
 
-				adj = new Adjustment(option.value, option.min, option.max, option.step, option.step, 0);
-
-				scale = new HScale(adj);
-				scale.draw_value = false;
-				scale.set_digits(digits);
-
-				spin = new SpinButton(adj, option.step, digits);
-
-				adj.notify["value"] += this.on_double_adj_value_changed;
-				option.notify["value"] += this.on_double_option_value_changed;
-			}
+			adj.notify["value"] += this.on_adj_value_changed;
+			option.notify["value"] += this.on_option_value_changed;
 
 			this.pack_start(scale, true, true, 0);
 			this.pack_start(spin, false, true, 0);
 		}
 
-		private void on_int_option_value_changed()
-		{
-			var option = option as OptionInt;
-			adj.value = (double) option.value;
-		}
-
-		private void on_int_adj_value_changed()
-		{
-			var option = option as OptionInt;
-			option.value = (int) adj.value;
-		}
-
-		private void on_double_option_value_changed()
+		private void on_option_value_changed()
 		{
-			var option = option as OptionDouble;
+			var option = option as OptionNumber;
 			adj.value = option.value;
 		}
 
-		private void on_double_adj_value_changed()
+		private void on_adj_value_changed()
 		{
-			var option = option as OptionDouble;
+			var option = option as OptionNumber;
 			option.value = adj.value;
 		}
 	}

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	Tue Feb  3 19:54:51 2009
@@ -52,17 +52,10 @@
 }
 
 static void
-gsane_option_handler_generic_int_get_value(GSaneOptionHandlerGeneric *self)
+gsane_option_handler_generic_number_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);
+	gint value = gsane_option_handler_get_double(GSANE_OPTION_HANDLER(self), self->priv->desc, self->priv->index, NULL);
+	gnome_scan_option_number_set_value(GNOME_SCAN_OPTION_NUMBER(self->priv->option), value);
 }
 
 static void
@@ -92,23 +85,12 @@
 }
 
 static void
-gsane_option_handler_generic_int_option_value_changed(GSaneOptionHandlerGeneric* self, GParamSpec* pspec, GObject* option)
-{
-	gint value;
-	g_object_get(option, "value", &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));
-}
-
-
-static void
-gsane_option_handler_generic_double_option_value_changed(GSaneOptionHandlerGeneric* self, GParamSpec* pspec, GObject* option)
+gsane_option_handler_generic_number_option_value_changed(GSaneOptionHandlerGeneric* self, GParamSpec* pspec, GObject* option)
 {
 	gdouble value;
 	g_object_get(option, "value", &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),
+		gnome_scan_option_number_set_value(GNOME_SCAN_OPTION_NUMBER(option),
 						   gsane_option_handler_get_double(GSANE_OPTION_HANDLER(self), self->priv->desc, self->priv->index, NULL));
 }
 
@@ -152,74 +134,83 @@
 	g_debug("\toption %02d : boolean %s = %s", n, desc->name, GSANE_BOOLEAN_TO_STRING(value));
 }
 
-static void
-gsane_option_handler_generic_handle_int_option(GSaneOptionHandler *handler, const SANE_Option_Descriptor*desc, SANE_Int n, const gchar* group)
+static gchar*
+gsane_option_handler_generic_int_get_range(GSaneOptionHandler *handler, const SANE_Option_Descriptor*desc, SANE_Int n, gdouble value, GnomeScanRange *range)
 {
-	GSaneOptionHandlerGeneric* self = GSANE_OPTION_HANDLER_GENERIC(handler);
-	gint value, min, step, max;
-	gchar *smin, *smax;
+	gchar *smin, *smax, *debug;
 
-	value = gsane_option_handler_get_int(handler, desc, n, NULL);
 	if (desc->constraint_type == SANE_CONSTRAINT_RANGE) {
-		min = desc->constraint.range->min;
-		smin = g_strdup_printf("%d", min);
-		step = MAX(1, desc->constraint.range->quant);
-		max = desc->constraint.range->max;
-		smax = g_strdup_printf("%d", max);
+		range->min = desc->constraint.range->min;
+		smin = g_strdup_printf("%.0f", range->min);
+		range->step = MAX(1, desc->constraint.range->quant);
+		range->max = desc->constraint.range->max;
+		smax = g_strdup_printf("%.0f", range->max);
 	}
 	else {
-		min = G_MININT;
+		range->min = G_MININT;
 		smin = g_strdup("G_MININT");
-		step = 1;
-		max = G_MAXINT;
+		range->step = 1.;
+		range->max = G_MAXINT;
 		smax = g_strdup("G_MAXINT");
 	}
-	self->priv->option = GNOME_SCAN_OPTION(gnome_scan_option_int_new(desc->name, S_(desc->title), S_(desc->desc),
-									 gsane_option_handler_generic_get_group(self, desc, n, group),
-									 SANE_GETTEXT_PACKAGE,
-									 value, min, step, max,
-									 gsane_option_unit(desc),
-									 GSANE_OPTION_HANDLER_GENERIC_GET_CLASS(handler)->option_hint));
-	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 %02d : int %s = %d, range = [%s;%d;%s]", n, desc->name, value, smin, step, smax);
+
+	debug = g_strdup_printf("\toption %02d : int %s = %.0f, range = [%s;%.0f;%s]", n, desc->name, value, smin, range->step, smax);
 	g_free(smin);
 	g_free(smax);
+	return debug;
 }
 
-static void
-gsane_option_handler_generic_handle_double_option(GSaneOptionHandler *handler, const SANE_Option_Descriptor*desc, SANE_Int n, const gchar* group)
+
+static gchar*
+gsane_option_handler_generic_double_get_range(GSaneOptionHandler *handler, const SANE_Option_Descriptor*desc, SANE_Int n, gdouble value, GnomeScanRange *range)
 {
-	GSaneOptionHandlerGeneric* self = GSANE_OPTION_HANDLER_GENERIC(handler);
-	gdouble value, min, step, max;
-	gchar* smin, *smax;
+	gchar *smin, *smax, *debug;
 
-	value = gsane_option_handler_get_double(handler, desc, n, NULL);
 	if (desc->constraint_type == SANE_CONSTRAINT_RANGE) {
-		min = SANE_UNFIX(desc->constraint.range->min);
-		smin = g_strdup_printf("%.2f", min);
-		step = MAX(1., SANE_UNFIX(desc->constraint.range->quant));
-		max = SANE_UNFIX(desc->constraint.range->max);
-		smax = g_strdup_printf("%.2f", max);
+		range->min = SANE_UNFIX(desc->constraint.range->min);
+		smin = g_strdup_printf("%.2f", range->min);
+		range->step = MAX(1., SANE_UNFIX(desc->constraint.range->quant));
+		range->max = SANE_UNFIX(desc->constraint.range->max);
+		smax = g_strdup_printf("%.2f", range->max);
 	}
 	else {
-		min = G_MINDOUBLE;
+		range->min = G_MINDOUBLE;
 		smin = g_strdup("G_MINDOUBLE");
-		step = .1;
-		max = G_MAXDOUBLE;
+		range->step = .1;
+		range->max = G_MAXDOUBLE;
 		smax = g_strdup("G_MAXDOUBLE");
 	}
-	self->priv->option = GNOME_SCAN_OPTION(gnome_scan_option_double_new(desc->name, S_(desc->title), S_(desc->desc),
+
+	debug = g_strdup_printf("\toption %02d : int %s = %.2f, range = [%s;%.2f;%s]", n, desc->name, value, smin, range->step, smax);
+	g_free(smin);
+	g_free(smax);
+	return debug;
+}
+
+static void
+gsane_option_handler_generic_handle_number_option(GSaneOptionHandler *handler, const SANE_Option_Descriptor*desc, SANE_Int n, const gchar* group)
+{
+	GSaneOptionHandlerGeneric* self = GSANE_OPTION_HANDLER_GENERIC(handler);
+	GnomeScanRange range = {0};
+	gdouble value;
+	gchar* debug;
+
+	value = gsane_option_handler_get_double(handler, desc, n, NULL);
+	if (desc->type == SANE_TYPE_INT)
+		debug = gsane_option_handler_generic_int_get_range(handler, desc, n, value, &range);
+	else
+		debug = gsane_option_handler_generic_double_get_range(handler, desc, n, value, &range);
+
+	self->priv->option = GNOME_SCAN_OPTION(gnome_scan_option_number_new(desc->name, S_(desc->title), S_(desc->desc),
 									    gsane_option_handler_generic_get_group(self, desc, n, group),
 									    SANE_GETTEXT_PACKAGE,
-									    value, min, step, max,
+									    value, gnome_scan_range_dup(&range),
 									    gsane_option_unit(desc),
 									    GSANE_OPTION_HANDLER_GENERIC_GET_CLASS(handler)->option_hint));
-	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 %02d : double %s = %.2g, range = [%s;%.2f;%s]", n, desc->name, value, smin, step, smax);
-	g_free(smin);
-	g_free(smax);
+	self->priv->get_value = gsane_option_handler_generic_number_get_value;
+	g_signal_connect_swapped(self->priv->option, "notify::value", G_CALLBACK(gsane_option_handler_generic_number_option_value_changed), self);
+	g_debug("%s", debug);
+	g_free(debug);
 }
 
 static void
@@ -249,18 +240,12 @@
 		gsane_option_handler_generic_handle_bool_option(handler, desc, n, group);
 		break;
 	case SANE_TYPE_INT:
-		array_length = desc->size / sizeof(SANE_Word);
-		if (array_length > 1)
-			g_debug("\toption %02d : Ignoring int array option %s", n, desc->name);
-		else
-			gsane_option_handler_generic_handle_int_option(handler, desc, n, group);
-		break;
 	case SANE_TYPE_FIXED:
 		array_length = desc->size / sizeof(SANE_Word);
 		if (array_length > 1)
-			g_debug("\toption %02d : Ignoring double array option %s", n, desc->name);
+			g_debug("\toption %02d : Ignoring number array option %s", n, desc->name);
 		else
-			gsane_option_handler_generic_handle_double_option(handler, desc, n, group);
+			gsane_option_handler_generic_handle_number_option(handler, desc, n, group);
 		break;
 	case SANE_TYPE_STRING:
 		gsane_option_handler_generic_handle_string_option(handler, desc, n, group);



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