gnome-scan r800 - in trunk: . lib
- From: bersace svn gnome org
- To: svn-commits-list gnome org
- Subject: gnome-scan r800 - in trunk: . lib
- Date: Sat, 31 Jan 2009 13:34:05 +0000 (UTC)
Author: bersace
Date: Sat Jan 31 13:34:05 2009
New Revision: 800
URL: http://svn.gnome.org/viewvc/gnome-scan?rev=800&view=rev
Log:
Added value setter from GValue.
Modified:
trunk/ChangeLog
trunk/lib/gnome-scan-option.vala
Modified: trunk/lib/gnome-scan-option.vala
==============================================================================
--- trunk/lib/gnome-scan-option.vala (original)
+++ trunk/lib/gnome-scan-option.vala Sat Jan 31 13:34:05 2009
@@ -49,6 +49,33 @@
public Gnome.Scan.Unit unit {get; set construct; default = Unit.NONE;}
public OptionHint hint {get; set construct;}
public bool active {get; set; default = true;}
+
+ public virtual void set_g_value(Value value)
+ {
+ }
+
+ // Helper function for set_g_value() implementation that copy
+ // or transform a value from src to dest. Returns whether the
+ // operation was successful.
+ protected bool copy_or_transform_g_value(Value src, ref Value dest)
+ {
+ Type stype = src.type();
+ Type dtype = dest.type();
+
+ if (Value.type_compatible(stype, dtype)) {
+ src.copy(ref dest);
+ return true;
+ }
+ else if (Value.type_transformable(stype, dtype)) {
+ src.transform(ref dest);
+ return true;
+ }
+ else {
+ warning("Unable to set %s value for %s",
+ stype.name(), dtype.name());
+ return false;
+ }
+ }
}
public class OptionBool : Option {
@@ -64,6 +91,13 @@
this.value = value;
this.hint = hint;
}
+
+ public override void set_g_value(Value value)
+ {
+ Value oval = Value(typeof(bool));
+ if (this.copy_or_transform_g_value(value, ref oval))
+ this.value = oval.get_boolean();
+ }
}
public class OptionInt : Option {
@@ -86,6 +120,13 @@
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 {
@@ -108,6 +149,13 @@
this.unit = unit;
this.hint = hint;
}
+
+ public override void set_g_value(Value value)
+ {
+ Value oval = Value(typeof(double));
+ if (this.copy_or_transform_g_value(value, ref oval))
+ this.value = oval.get_double();
+ }
}
public class OptionString : Option {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]