5 public class Stuffkeeper
.DataRatingConfig
: Gtk
.Table
{
6 private string field
= null;
7 private DataSchema schema
= null;
8 private Gtk
.SpinButton min_spin
= null;
9 private Gtk
.SpinButton max_spin
= null;
10 private Gtk
.SpinButton default_spin
= null;
11 private uint update_timeout
= 0;
13 public enum CustomFields
{
20 * Listen to changes to this field
22 private void field_changed(DataSchema schema
, string id
, int field
)
24 if(field
== CustomFields
.MIN_RANGE
)
27 if(schema
.get_custom_field_integer(id
, field
, out value
))
29 if(min_spin
.value
!= (double)value
)
31 min_spin
.value_changed
.disconnect(spin_changed
);
32 min_spin
.value
= (double)value
;
33 max_spin
.set_range(min_spin
.value
+1, int.MAX
);
34 default_spin
.set_range((double)value
, max_spin
.value
);
35 min_spin
.value_changed
.connect(spin_changed
);
40 if(field
== CustomFields
.MAX_RANGE
)
43 if(schema
.get_custom_field_integer(id
, field
, out value
))
45 if(max_spin
.value
!= (double)value
)
47 max_spin
.value_changed
.disconnect(spin_changed
);
48 max_spin
.value
= (double)value
;
49 min_spin
.set_range(int.MIN
, max_spin
.value
-1);
50 default_spin
.set_range(min_spin
.value
, (double)value
);
51 max_spin
.value_changed
.connect(spin_changed
);
55 if(field
== CustomFields
.DEFAULT_VALUE
)
58 if(schema
.get_custom_field_integer(id
, field
, out value
))
60 if(default_spin
.value
!= (double)(value
/10.0))
62 default_spin
.value_changed
.disconnect(spin_changed
);
63 default_spin
.value
= (double)value
/10.0;
64 default_spin
.value_changed
.connect(spin_changed
);
75 stdout
.printf("Save changes\n");
76 value
= min_spin
.value
;
77 schema
.set_custom_field_integer(field
, CustomFields
.MIN_RANGE
, (int)value
);
78 value
= max_spin
.value
;
79 schema
.set_custom_field_integer(field
, CustomFields
.MAX_RANGE
, (int)value
);
81 value
= default_spin
.value
;
82 schema
.set_custom_field_integer(field
, CustomFields
.DEFAULT_VALUE
, (int)(value
*10));
94 stdout
.printf("Dispose\n");
96 schema
.schema_custom_field_changed
.disconnect(field_changed
);
97 if(update_timeout
> 0)
99 stdout
.printf("force saving\n");
100 Source
.remove(update_timeout
);
104 stdout
.printf("kdispose_done\n");
111 private void spin_changed(SpinButton spin
)
113 stdout
.printf("value changed\n");
116 min_spin
.set_range(int.MIN
, max_spin
.value
-1);
117 max_spin
.set_range(min_spin
.value
+1, int.MAX
);
118 default_spin
.set_range(min_spin
.value
, max_spin
.value
);
119 if(update_timeout
> 0)
121 Source
.remove(update_timeout
);
123 update_timeout
= GLib
.Timeout
.add_seconds(1, save_changes
);
128 this
.set_row_spacings(6);
129 this
.set_col_spacings(6);
131 var label
= new Gtk
.Label("Minimum value");
132 label
.set_alignment(1.0f
,0.5f
);
133 min_spin
= new Gtk
.SpinButton
.with_range(int.MIN
, int.MAX
, 1);
134 min_spin
.numeric
= true;
135 this
.attach(label
, 0,1,0,1,
136 AttachOptions
.SHRINK
|AttachOptions
.FILL
,
137 AttachOptions
.SHRINK
,0,0);
138 this
.attach(min_spin
, 1,2,0,1,
139 AttachOptions
.SHRINK
|AttachOptions
.FILL
,
140 AttachOptions
.SHRINK
,0,0);
142 min_spin
.value
= 0.0;
143 min_spin
.value_changed
.connect(spin_changed
);
145 label
= new Gtk
.Label("Maximum value");
146 label
.set_alignment(1.0f
,0.5f
);
148 max_spin
= new Gtk
.SpinButton
.with_range(int.MIN
, int.MAX
, 1);
149 max_spin
.numeric
= true;
151 this
.attach(label
, 0,1,1,2,
152 AttachOptions
.SHRINK
|AttachOptions
.FILL
,
153 AttachOptions
.SHRINK
,0,0);
154 this
.attach(max_spin
, 1,2,1,2,
155 AttachOptions
.SHRINK
|AttachOptions
.FILL
,
156 AttachOptions
.SHRINK
,0,0);
157 max_spin
.value
= 10.0;
158 max_spin
.value_changed
.connect(spin_changed
);
160 label
= new Gtk
.Label("Default value");
161 label
.set_alignment(1.0f
,0.5f
);
163 default_spin
= new Gtk
.SpinButton
.with_range(int.MIN
, int.MAX
,0.1);
164 default_spin
.numeric
= true;
166 this
.attach(label
, 0,1,2,3,
167 AttachOptions
.SHRINK
|AttachOptions
.FILL
,
168 AttachOptions
.SHRINK
,0,0);
169 this
.attach(default_spin
, 1,2,2,3,
170 AttachOptions
.SHRINK
|AttachOptions
.FILL
,
171 AttachOptions
.SHRINK
,0,0);
172 default_spin
.value
= 5.0;
173 default_spin
.value_changed
.connect(spin_changed
);
182 public void setup (Stuffkeeper
.DataSchema schema
, string fid
) {
183 this
.schema
= schema
;
186 /* update all the boxes */
187 field_changed(schema
,field
, CustomFields
.MIN_RANGE
);
188 field_changed(schema
,field
, CustomFields
.MAX_RANGE
);
189 field_changed(schema
,field
, CustomFields
.DEFAULT_VALUE
);
191 /* connect signals */
192 schema
.schema_custom_field_changed
.connect(field_changed
);