gnome-scan r693 - in trunk: . lib



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

Log:
Added Enum option type support.

Added:
   trunk/lib/gnome-scan-combo-box-widget.vala
Modified:
   trunk/ChangeLog
   trunk/lib/Makefile.am
   trunk/lib/gnome-scan-common.vala
   trunk/lib/gnome-scan-init.vala
   trunk/lib/gnome-scan-option.vala

Modified: trunk/lib/Makefile.am
==============================================================================
--- trunk/lib/Makefile.am	(original)
+++ trunk/lib/Makefile.am	Mon Dec 15 10:37:45 2008
@@ -28,6 +28,7 @@
 	gnome-scan-checkbox-widget.vala		\
 	gnome-scan-scale-widget.vala		\
 	gnome-scan-entry-widget.vala		\
+	gnome-scan-combo-box-widget.vala	\
 	gnome-scan-option-box.vala		\
 	gnome-scan-option-page.vala		\
 	gnome-scan-scanner-selector.vala	\

Added: trunk/lib/gnome-scan-combo-box-widget.vala
==============================================================================
--- (empty file)
+++ trunk/lib/gnome-scan-combo-box-widget.vala	Mon Dec 15 10:37:45 2008
@@ -0,0 +1,107 @@
+/* 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 ComboBoxWidget : OptionWidget {
+		private ListStore store;
+		private ComboBox combo;
+		private bool inhibit = false;
+		private HashTable<Gnome.Scan.EnumValue?,string> strings;
+
+		enum Column {
+			LABEL,
+			VALUE,
+			LENGTH
+		}
+
+		construct {
+			TreeIter iter;
+			CellRenderer renderer;
+
+			strings = new HashTable<string,string>(GLib.direct_hash, GLib.direct_equal);
+
+			this.store = new ListStore(Column.LENGTH, typeof(string), typeof(Gnome.Scan.EnumValue));
+			combo = new ComboBox.with_model(store);
+			this.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(Gnome.Scan.EnumValue? value in option.values) {
+				store.append(out iter);
+				store.set(iter,
+						  Column.LABEL, value.label,
+						  Column.VALUE, value);
+				
+				strings.insert(value, store.get_string_from_iter(iter));
+
+				if (value.label == curval.label)
+					combo.set_active_iter(iter);
+			}
+
+			combo.changed += 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;
+			Gnome.Scan.EnumValue value;
+
+			if (inhibit)
+				return;
+
+			combo.get_active_iter(out iter);
+			store.get(iter, Column.VALUE, out value);
+
+			inhibit = true;
+			((OptionEnum)option).value = value;
+			inhibit = false;
+		}
+
+		private void on_option_changed()
+		{
+			TreeIter iter;
+
+			if (inhibit)
+				return;
+
+			string str = strings.lookup(((OptionEnum)option).value);
+
+			if (str == null)
+				return;
+
+			store.get_iter_from_string(out iter, str);
+			inhibit = true;
+			combo.set_active_iter(iter);
+			inhibit = false;
+		}
+	}
+} 
\ No newline at end of file

Modified: trunk/lib/gnome-scan-common.vala
==============================================================================
--- trunk/lib/gnome-scan-common.vala	(original)
+++ trunk/lib/gnome-scan-common.vala	Mon Dec 15 10:37:45 2008
@@ -95,6 +95,19 @@
 		}
 	}
 
+	public struct EnumValue {
+		public Value? value;
+		public string label;
+		public string? domain;
+
+		public EnumValue(Value? value, string label, string? domain)
+		{
+			this.value = value;
+			this.label = label;
+			this.domain = domain;
+		}
+	}
+
 	private const double MM_PER_INCH	= 25.4;
 
 	// debugging facility, return the nickk of value.
@@ -102,7 +115,7 @@
 								int value)
 	{
 		EnumClass klass = (EnumClass) enum_type.class_ref();
-		weak EnumValue enum_value = klass.get_value(value);
+		weak GLib.EnumValue enum_value = klass.get_value(value);
 		if (enum_value == null)
 			return "%i".printf(value);
 		else

Modified: trunk/lib/gnome-scan-init.vala
==============================================================================
--- trunk/lib/gnome-scan-init.vala	(original)
+++ trunk/lib/gnome-scan-init.vala	Mon Dec 15 10:37:45 2008
@@ -42,6 +42,7 @@
 		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(OptionString), typeof(EntryWidget));
+		option_manager.register_rule_by_type(typeof(OptionEnum), typeof(ComboBoxWidget));
 
 		module_path = string.join(GLib.Path.SEARCHPATH_SEPARATOR_S, MODULE_DIR,
 								  "modules/gsfile", "modules/gsane",

Modified: trunk/lib/gnome-scan-option.vala
==============================================================================
--- trunk/lib/gnome-scan-option.vala	(original)
+++ trunk/lib/gnome-scan-option.vala	Mon Dec 15 10:37:45 2008
@@ -124,4 +124,26 @@
 			this.hint = hint;
 		}
 	}
+
+	public class OptionEnum : Option {
+		public weak Gnome.Scan.EnumValue value {get; set;}
+		protected weak SList<Gnome.Scan.EnumValue?> _values;
+		public weak SList<Gnome.Scan.EnumValue?> values {
+			get {
+				return this._values;
+			}
+		}
+
+		public OptionEnum(string name, string title, string desc, string group, string domain, 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.value = value;
+			this._values = values;
+			this.hint = hint;
+		}
+	}
 }



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