Update called vala api.
[stuffkeeper.git] / src / stuffkeeper-data-image-config.vala
blob0fbf640b12064b189f1b81adb9d92cdbe46bceba
1 using GLib;
2 using Gtk;
3 using Stuffkeeper;
5 public class Stuffkeeper.DataImageConfig : Gtk.HBox {
6 private string field = null;
7 private DataSchema schema = null;
8 private Gtk.SpinButton spinbutton = null;
9 /* hack to fix vala bug */
10 static bool quit = false;
11 private enum PrivateField {
12 IMAGE_SIZE = 0;
15 /**
16 * Listen to changes to this field
18 private void field_changed(DataSchema schema, string id, int field)
20 if(field == (int)PrivateField.IMAGE_SIZE)
22 int value = 0;
23 if(schema.get_custom_field_integer(id, PrivateField.IMAGE_SIZE, out value))
25 if(spinbutton.value != value)
27 //schema.schema_custom_field_changed -= field_changed;
28 this.spinbutton.value_changed.disconnect(toggled);
29 spinbutton.value = value;
30 //schema.schema_custom_field_changed += field_changed;
31 this.spinbutton.value_changed.connect(toggled);
37 /**
38 * Listen to clicks
39 */
40 private void toggled(Gtk.SpinButton spinbutton)
42 int value = (int)spinbutton.value;
43 schema.set_custom_field_integer(field,PrivateField.IMAGE_SIZE,value);
46 /**
47 * Destruction
49 ~DataImageConfig() {
50 stdout.printf("Dispose data boolean config\n");
52 /* This gets called twice..
53 * Hack it to have it run only once*/
54 if(!quit)
56 schema.schema_custom_field_changed.disconnect(field_changed);
58 quit = true;
60 /**
61 * Construct
63 construct {
64 var label = new Gtk.Label("Default value");
65 this.spinbutton = new Gtk.SpinButton.with_range(8, 4192,4);
67 this.pack_start(label, false, false,0);
68 this.pack_start(spinbutton, true, true,0);
69 this.show_all();
72 /**
73 * Set it up
75 public void setup (Stuffkeeper.DataSchema schema, string fid) {
76 int value;
77 this.schema = schema;
78 this.field = fid;
80 if(schema.get_custom_field_integer(field, PrivateField.IMAGE_SIZE, out value))
82 this.spinbutton.value = value;
84 else this.spinbutton.value = 250;
85 /* connect signals */
86 this.spinbutton.value_changed.connect(toggled);
87 schema.schema_custom_field_changed.connect(field_changed);