gnome-scan r818 - in trunk: . lib modules/gsane src



Author: bersace
Date: Mon Feb  2 22:47:40 2009
New Revision: 818
URL: http://svn.gnome.org/viewvc/gnome-scan?rev=818&view=rev

Log:
Filter preselected papersizes

Added:
   trunk/lib/gnome-scan-paper-size-widget.vala
Modified:
   trunk/ChangeLog
   trunk/lib/Makefile.am
   trunk/lib/gnome-scan-init.vala
   trunk/lib/gnome-scan-option.vala
   trunk/modules/gsane/gsane-option-area.c
   trunk/src/flegita.vala

Modified: trunk/lib/Makefile.am
==============================================================================
--- trunk/lib/Makefile.am	(original)
+++ trunk/lib/Makefile.am	Mon Feb  2 22:47:40 2009
@@ -32,6 +32,7 @@
 	gnome-scan-scale-widget.vala		\
 	gnome-scan-entry-widget.vala		\
 	gnome-scan-combo-box-widget.vala	\
+	gnome-scan-paper-size-widget.vala	\
 	gnome-scan-page-orientation-widget.vala	\
 	gnome-scan-option-box.vala		\
 	gnome-scan-option-page.vala		\

Modified: trunk/lib/gnome-scan-init.vala
==============================================================================
--- trunk/lib/gnome-scan-init.vala	(original)
+++ trunk/lib/gnome-scan-init.vala	Mon Feb  2 22:47:40 2009
@@ -43,6 +43,7 @@
 		option_manager.register_rule_by_type(typeof(OptionDouble), 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_name(typeof(OptionPaperSize), typeof(PaperSizeWidget));
 		option_manager.register_rule_by_name("page-orientation", typeof(PageOrientationWidget));
 
 		// If we are in source tree.

Modified: trunk/lib/gnome-scan-option.vala
==============================================================================
--- trunk/lib/gnome-scan-option.vala	(original)
+++ trunk/lib/gnome-scan-option.vala	Mon Feb  2 22:47:40 2009
@@ -176,7 +176,7 @@
 	public class OptionEnum : Option {
 		public weak Gnome.Scan.EnumValue? value {set; get;}
 
-		private weak SList<Gnome.Scan.EnumValue?> _values;
+		protected weak SList<Gnome.Scan.EnumValue?> _values;
 		public weak SList<Gnome.Scan.EnumValue?> values {
 			get {
 				return this._values;
@@ -195,12 +195,42 @@
 			this.hint = hint;
 		}
 
-		public void append(Gnome.Scan.EnumValue? value)
+		public virtual void append(Gnome.Scan.EnumValue? value)
 		{
 			_values.append(value);
 		}
 	}
 
+	public class OptionPaperSize : OptionEnum {
+		public Extent extent {set construct; get; }
+
+		public OptionPaperSize(string name, string title, string desc, string group, string domain, Extent extent, Gnome.Scan.EnumValue? value, SList<Gnome.Scan.EnumValue?> values, OptionHint hint)
+		{
+			this.name = name;
+			this.title = title;
+			this.desc = desc;
+			this.group = group;
+			this.domain = domain;
+			this.extent	= extent;
+			this.value = value;
+			this._values = values;
+			this.hint = hint;
+		}
+
+		public override void append(Gnome.Scan.EnumValue? value)
+		{
+			// Ensure the wanted papersize fit the device extent.
+			weak Gtk.PaperSize ps = (Gtk.PaperSize) value.value.get_boxed();
+
+			debug("Adding %s (%.2fx%.2f)", ps.get_display_name(),
+				  ps.get_width(Gtk.Unit.MM), ps.get_height(Gtk.Unit.MM));
+
+			if (ps.get_width(Gtk.Unit.MM) <= extent.width
+				&& ps.get_height(Gtk.Unit.MM) <= extent.height)
+				base.append(value);
+		}
+	}
+
 	public class OptionBoxed : Option {
 		public weak Boxed value {set; get;}
 

Added: trunk/lib/gnome-scan-paper-size-widget.vala
==============================================================================
--- (empty file)
+++ trunk/lib/gnome-scan-paper-size-widget.vala	Mon Feb  2 22:47:40 2009
@@ -0,0 +1,125 @@
+/* GNOME Scan - Scan as easy as you print
+ * Copyright  2006-2008  Ãtienne Bersac <bersace gnome org>
+ *
+ * GNOME Scan is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ * 
+ * GNOME Scan is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ * 
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with GNOME Scan. If not, write to:
+ *
+ *	the Free Software Foundation, Inc.
+ *	51 Franklin Street, Fifth Floor
+ *	Boston, MA 02110-1301, USA
+ */
+ 
+using Gtk;
+
+namespace Gnome.Scan {
+	public class PaperSizeWidget : OptionWidget {
+		private ListStore store;
+		private ComboBox combo;
+		private Label label;
+		private HashTable<string,string> strings;
+
+		enum Column {
+			LABEL,
+			VALUE,
+			LENGTH
+		}
+
+		construct {
+			TreeIter iter;
+			CellRenderer renderer;
+
+			this.no_label = true;
+
+			var box = new VBox(false, 4);
+			this.pack_start(box, false, true, 0);
+			strings = new HashTable<string,string>(GLib.str_hash, GLib.str_equal);
+
+			this.store = new ListStore(Column.LENGTH, typeof(string), typeof(Gnome.Scan.EnumValue));
+			combo = new ComboBox.with_model(store);
+			box.pack_start(combo, false, true, 0);
+			renderer = new CellRendererText();
+			combo.pack_start(renderer,true);
+			combo.set_attributes(renderer, "text", Column.LABEL);
+
+			var option = this.option as OptionEnum;
+			Gnome.Scan.EnumValue? curval = option.value;
+			foreach(weak Gnome.Scan.EnumValue? value in option.values) {
+				store.append(out iter);
+				store.set(iter,
+						  Column.LABEL, value.label,
+						  Column.VALUE, value);
+				
+				strings.insert(value.label, store.get_string_from_iter(iter));
+
+				if (curval != null && value.label == curval.label)
+						combo.set_active_iter(iter);
+			}
+
+			label = new Label(null);
+			label.set_alignment(0, (float)0.5);
+			label.set_padding(12, 0);
+			box.pack_start(label, false, true, 0);
+			if (curval != null) {
+				weak PaperSize ps = (PaperSize) curval.value.get_boxed();
+				label.set_text("%.0fx%.0f mm".printf(ps.get_width(Gtk.Unit.MM),
+													 ps.get_height(Gtk.Unit.MM)));
+			}
+
+			combo.notify["active"] += this.on_combo_changed;
+			option.notify["value"] += this.on_option_changed;
+
+			// don't show one option selector. Thanks Philipp for
+			// pointing that.
+			if (option.values.length() <= 1)
+				this.no_show_all = true;
+		}
+
+		private void on_combo_changed()
+		{
+			TreeIter iter;
+			weak Gnome.Scan.EnumValue? value;
+			weak string label;
+
+			combo.get_active_iter(out iter);
+			store.get(iter,
+					  Column.VALUE, out value,
+					  Column.LABEL, out label);
+
+			option.freeze_notify();
+			var option = this.option as OptionEnum;
+			option.value = value;
+			option.thaw_notify();
+		}
+
+		private void on_option_changed()
+		{
+			TreeIter iter;
+			OptionEnum option = this.option as OptionEnum;
+			string str = strings.lookup(option.value.label);
+			if (str == null) {
+				debug("No path for %s value", option.value.label);
+				return;
+			}
+
+			store.get_iter_from_string(out iter, str);
+
+			weak PaperSize ps = (PaperSize) option.value.value.get_boxed();
+			label.set_text("%.0fx%.0f mm".printf(ps.get_width(Gtk.Unit.MM),
+												 ps.get_height(Gtk.Unit.MM)));
+		   
+			combo.freeze_notify();
+			combo.set_active_iter(iter);
+			combo.thaw_notify();
+		}
+	}
+} 
\ No newline at end of file

Modified: trunk/modules/gsane/gsane-option-area.c
==============================================================================
--- trunk/modules/gsane/gsane-option-area.c	(original)
+++ trunk/modules/gsane/gsane-option-area.c	Mon Feb  2 22:47:40 2009
@@ -78,6 +78,13 @@
 	GtkPageOrientation orientation;
 
 	gnome_scan_option_enum_get_value(GNOME_SCAN_OPTION_ENUM(self->priv->paper_size), &value);
+
+	/* Value was unset, don't actually update hardware
+	   values. Should you use default hardware value ? No use case
+	   yet. */
+	if (value == NULL)
+		return;
+
 	ps = g_value_get_boxed(&value->value);
 	gnome_scan_option_enum_get_value(GNOME_SCAN_OPTION_ENUM(self->priv->page_orientation), &value);
 	orientation = g_value_get_enum(&value->value);
@@ -228,8 +235,8 @@
 	g_free(value);
 
 
-	self->priv->paper_size = GNOME_SCAN_OPTION(gnome_scan_option_enum_new("paper-size", _("Paper-Size"), _("Paper-Size"), GNOME_SCAN_OPTION_GROUP_FORMAT, GETTEXT_PACKAGE,
-									      enum_values->data, enum_values, GNOME_SCAN_OPTION_HINT_PRIMARY));
+	self->priv->paper_size = GNOME_SCAN_OPTION(gnome_scan_option_paper_size_new("paper-size", _("Paper-Size"), _("Paper-Size"), GNOME_SCAN_OPTION_GROUP_FORMAT, GETTEXT_PACKAGE,
+										    &extent, enum_values->data, enum_values, GNOME_SCAN_OPTION_HINT_PRIMARY));
 	gnome_scan_node_install_option(GNOME_SCAN_NODE(handler->scanner), self->priv->paper_size);
 	g_signal_connect_swapped(self->priv->paper_size, "notify::value", G_CALLBACK(gsane_option_area_option_changed), self);
 

Modified: trunk/src/flegita.vala
==============================================================================
--- trunk/src/flegita.vala	(original)
+++ trunk/src/flegita.vala	Mon Feb  2 22:47:40 2009
@@ -61,7 +61,7 @@
 	foreach(string format in formats) {
 		ps = new PaperSize(format);
 		value = Value(typeof(Gtk.PaperSize));
-		value.set_pointer(ps);
+		value.set_boxed(ps);
 		evalue = Gnome.Scan.EnumValue(value, ps.get_display_name(), null);
 		ps_list.append(evalue);
 	}



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