Update called vala api.
[stuffkeeper.git] / src / stuffkeeper-data-boolean-config.vala
blob433370e5221fc98109ddca10a51546cdbc43b4bf
1 using GLib;
2 using Gtk;
3 using Stuffkeeper;
5 public class Stuffkeeper.DataBooleanConfig : Gtk.HBox {
6 private string field = null;
7 private DataSchema schema = null;
8 private Gtk.CheckButton checkbox = null;
9 /* hack to fix vala bug */
11 /**
12 * Listen to changes to this field
14 private void field_changed(DataSchema schema, string id, int field)
16 if(field == 0)
18 int value = 0;
19 if(schema.get_custom_field_integer(id, 0, out value))
21 if(checkbox.active != (bool)value)
23 this.checkbox.toggled.disconnect(toggled);
24 checkbox.active = (bool)value;
25 this.checkbox.toggled.connect(toggled);
31 /**
32 * Listen to clicks
33 */
34 private void toggled(Gtk.ToggleButton toggle)
36 if(toggle.active)
38 schema.set_custom_field_integer(field,0,1);
39 }else{
40 schema.set_custom_field_integer(field,0,0);
44 /**
45 * Destruction
47 ~DataBooleanConfig() {
48 stdout.printf("Dispose data boolean config\n");
49 schema.schema_custom_field_changed.disconnect(field_changed);
51 /**
52 * Construct
54 construct {
55 var label = new Gtk.Label("Default value");
56 this.checkbox = new Gtk.CheckButton();
58 this.pack_start(label, false, false,0);
59 this.pack_start(checkbox, true, true,0);
60 this.show_all();
63 /**
64 * Set it up
66 public void setup (Stuffkeeper.DataSchema schema, string fid) {
67 int value;
68 this.schema = schema;
69 this.field = fid;
71 if(schema.get_custom_field_integer(field, 0, out value))
73 this.checkbox.active = (bool)value;
75 /* connect signals */
76 this.checkbox.toggled.connect(toggled);
77 schema.schema_custom_field_changed.connect(field_changed);