2 * Create the main window.
9 #include "mainwindow.h"
13 GtkWidget
*application
;
15 GtkWidget
*wid_backlight
;
17 GtkWidget
*wid_styledir
;
18 GtkWidget
*wid_stylename
;
20 GtkWidget
*wid_command
;
21 GtkWidget
*wid_msgcmd
;
26 GtkWidget
*wid_locale
;
27 GtkWidget
*wid_showcal
;
28 GtkWidget
*wid_calalrms
;
30 static const gchar
*const clist_titles
[] = {" Status ", " Hour ", " Day ", " Message "};
32 static GtkWidget
*b_edit
;
33 static GtkWidget
*b_set
;
34 static GtkWidget
*b_remove
;
36 void clear_alarmlist_selection(void) {
37 gtk_widget_set_sensitive(b_edit
, FALSE
);
38 gtk_widget_set_sensitive(b_set
, FALSE
);
39 gtk_widget_set_sensitive(b_remove
, FALSE
);
43 alarmlist_selection_changed(void)
45 GtkTreeSelection
*selection
= gtk_tree_view_get_selection(GTK_TREE_VIEW(alarmlist
));
46 gboolean selected
= gtk_tree_selection_get_selected(selection
, NULL
, NULL
);
48 gtk_widget_set_sensitive(b_edit
, selected
);
49 gtk_widget_set_sensitive(b_set
, selected
);
50 gtk_widget_set_sensitive(b_remove
, selected
);
54 create_alarmlist (void)
57 GtkTreeSelection
*selection
;
58 GtkCellRenderer
*renderer
;
61 view
= GTK_TREE_VIEW(gtk_tree_view_new());
63 selection
= gtk_tree_view_get_selection(view
);
64 gtk_tree_selection_set_mode(selection
, GTK_SELECTION_SINGLE
);
66 renderer
= gtk_cell_renderer_text_new();
67 gtk_tree_view_insert_column_with_attributes(view
, -1,
68 clist_titles
[COL_STATUS
],
69 renderer
, "text", COL_STATUS
,
72 renderer
= gtk_cell_renderer_text_new();
73 gtk_tree_view_insert_column_with_attributes(view
, -1,
74 clist_titles
[COL_HOUR
],
75 renderer
, "text", COL_HOUR
,
78 renderer
= gtk_cell_renderer_text_new();
79 gtk_tree_view_insert_column_with_attributes(view
, -1,
80 clist_titles
[COL_DAY
],
81 renderer
, "text", COL_DAY
,
84 renderer
= gtk_cell_renderer_text_new();
85 gtk_tree_view_insert_column_with_attributes(view
, -1,
86 clist_titles
[COL_MESSAGE
],
87 renderer
, "text", COL_MESSAGE
,
90 model
= GTK_TREE_MODEL(gtk_list_store_new(NUM_COLS
,
97 gtk_tree_view_set_model(view
, model
);
99 g_object_unref (model
);
101 return GTK_WIDGET(view
);
104 void create_mainwindow(void) {
105 GtkWidget
*main_vbox
;
106 GtkWidget
*buttons_hbox
;
107 GtkWidget
*left_vbox
;
108 GtkWidget
*right_vbox
;
110 GtkWidget
*scrolled_window
;
118 /*** FENÊTRE PRINCIPALE ***/
119 application
= gtk_window_new(GTK_WINDOW_TOPLEVEL
);
120 gtk_window_set_title(GTK_WINDOW(application
), PACKAGE
" Config");
121 /*-- Connexion aux signaux --*/
122 g_signal_connect(application
, "delete_event", G_CALLBACK(quit_app
), NULL
);
123 g_signal_connect(application
, "destroy", G_CALLBACK(quit_app
), NULL
);
124 /*-- Taille de la fenêtre --*/
125 gtk_widget_set_size_request(GTK_WIDGET(application
), WIN_WIDTH
, WIN_HEIGHT
);
126 gtk_widget_realize(application
);
128 /*** Zone principale de placement des widgets***/
129 main_vbox
= gtk_vbox_new(FALSE
, 1);
130 gtk_container_set_border_width(GTK_CONTAINER(main_vbox
), 1);
131 gtk_container_add(GTK_CONTAINER(application
), main_vbox
);
132 gtk_widget_show(main_vbox
);
136 /*** WIDGETS DE DONNÉES ***/
137 notebook
= gtk_notebook_new();
139 /*-- Zones des données simples --*/
140 left_vbox
= gtk_vbox_new(FALSE
, 1);
144 frame
= gtk_frame_new(" Startup ");
145 gtk_frame_set_shadow_type(GTK_FRAME(frame
), GTK_SHADOW_ETCHED_IN
);
146 gtk_box_pack_start(GTK_BOX(left_vbox
), frame
, FALSE
, TRUE
, 1);
147 gtk_widget_show(frame
);
149 hbox
= gtk_hbox_new(FALSE
, 1);
150 gtk_container_add(GTK_CONTAINER(frame
), hbox
);
151 gtk_widget_show(hbox
);
153 vbox
= gtk_vbox_new(FALSE
, 1);
154 gtk_box_pack_start(GTK_BOX(hbox
), vbox
, TRUE
, TRUE
, 1);
155 gtk_widget_show(vbox
);
157 wid_backlight
= gtk_check_button_new_with_label("Back (or LED) light");
158 gtk_box_pack_start(GTK_BOX(vbox
), wid_backlight
, FALSE
, TRUE
, 1);
159 gtk_widget_show(wid_backlight
);
161 wid_blink
= gtk_check_button_new_with_label("Blink");
162 gtk_box_pack_start(GTK_BOX(vbox
), wid_blink
, FALSE
, TRUE
, 1);
163 gtk_widget_show(wid_blink
);
165 wid_h12
= gtk_check_button_new_with_label("12h clock mode");
166 gtk_box_pack_start(GTK_BOX(vbox
), wid_h12
, FALSE
, TRUE
, 1);
167 gtk_widget_show(wid_h12
);
169 vbox
= gtk_vbox_new(FALSE
, 1);
170 gtk_box_pack_start(GTK_BOX(hbox
), vbox
, TRUE
, TRUE
, 1);
171 gtk_widget_show(vbox
);
173 wid_locale
= gtk_check_button_new_with_label("Use current locale");
174 gtk_box_pack_start(GTK_BOX(vbox
), wid_locale
, FALSE
, TRUE
, 1);
175 gtk_widget_show(wid_locale
);
177 wid_showcal
= gtk_check_button_new_with_label("Show calendar");
178 gtk_box_pack_start(GTK_BOX(vbox
), wid_showcal
, FALSE
, TRUE
, 1);
179 gtk_widget_show(wid_showcal
);
181 wid_calalrms
= gtk_check_button_new_with_label("Load calendar alarms");
182 gtk_box_pack_start(GTK_BOX(vbox
), wid_calalrms
, FALSE
, TRUE
, 1);
183 gtk_widget_show(wid_calalrms
);
185 vbox
= gtk_vbox_new(FALSE
, 1);
186 gtk_box_pack_start(GTK_BOX(hbox
), vbox
, TRUE
, TRUE
, 1);
187 gtk_widget_show(vbox
);
189 wid_clk
= gtk_radio_button_new_with_label(NULL
, "Normal clock");
190 gtk_box_pack_start(GTK_BOX(vbox
), wid_clk
, FALSE
, TRUE
, 1);
191 gtk_widget_show(wid_clk
);
193 wid_itm
= gtk_radio_button_new_with_label_from_widget(GTK_RADIO_BUTTON(wid_clk
), "Internet time");
194 gtk_box_pack_start(GTK_BOX(vbox
), wid_itm
, FALSE
, TRUE
, 1);
195 gtk_widget_show(wid_itm
);
197 wid_bin
= gtk_radio_button_new_with_label_from_widget(GTK_RADIO_BUTTON(wid_clk
), "Binary clock");
198 gtk_box_pack_start(GTK_BOX(vbox
), wid_bin
, FALSE
, TRUE
, 1);
199 gtk_widget_show(wid_bin
);
202 frame
= gtk_frame_new(" Look ");
203 gtk_frame_set_shadow_type(GTK_FRAME(frame
), GTK_SHADOW_ETCHED_IN
);
204 gtk_box_pack_start(GTK_BOX(left_vbox
), frame
, FALSE
, TRUE
, 1);
205 gtk_widget_show(frame
);
207 table
= gtk_table_new(2, 3, FALSE
);
208 gtk_container_set_border_width(GTK_CONTAINER(table
), 2);
209 gtk_container_add(GTK_CONTAINER(frame
), table
);
210 gtk_widget_show(table
);
212 label
= gtk_label_new("Style directory : ");
213 gtk_misc_set_alignment(GTK_MISC(label
), 0.0f
, 0.5f
);
214 gtk_table_attach_defaults(GTK_TABLE(table
), label
, 0, 1, 0, 1);
215 gtk_widget_show(label
);
217 wid_styledir
= gtk_entry_new();
218 gtk_table_attach_defaults(GTK_TABLE(table
), wid_styledir
, 1, 2, 0, 1);
219 gtk_widget_show(wid_styledir
);
221 label
= gtk_label_new("Style : ");
222 gtk_misc_set_alignment(GTK_MISC(label
), 0.0f
, 0.5f
);
223 gtk_table_attach_defaults(GTK_TABLE(table
), label
, 0, 1, 1, 2);
224 gtk_widget_show(label
);
226 wid_stylename
= gtk_entry_new();
227 gtk_table_attach_defaults(GTK_TABLE(table
), wid_stylename
, 1, 2, 1, 2);
228 gtk_widget_show(wid_stylename
);
230 label
= gtk_label_new("Color : ");
231 gtk_misc_set_alignment(GTK_MISC(label
), 0.0f
, 0.5f
);
232 gtk_table_attach_defaults(GTK_TABLE(table
), label
, 0, 1, 2, 3);
233 gtk_widget_show(label
);
235 wid_color
= gtk_entry_new();
236 gtk_table_attach_defaults(GTK_TABLE(table
), wid_color
, 1, 2, 2, 3);
237 gtk_widget_show(wid_color
);
240 frame
= gtk_frame_new(" Commands ");
241 gtk_frame_set_shadow_type(GTK_FRAME(frame
), GTK_SHADOW_ETCHED_IN
);
242 gtk_box_pack_start(GTK_BOX(left_vbox
), frame
, FALSE
, FALSE
, 1);
243 gtk_widget_show(frame
);
245 vbox
= gtk_vbox_new(FALSE
, 1);
246 gtk_container_add(GTK_CONTAINER(frame
), vbox
);
247 gtk_widget_show(vbox
);
249 hbox
= gtk_hbox_new(FALSE
, 1);
250 gtk_box_pack_start(GTK_BOX(vbox
), hbox
, FALSE
, TRUE
, 1);
251 gtk_widget_show(hbox
);
253 label
= gtk_label_new("Command : ");
254 gtk_misc_set_alignment(GTK_MISC(label
), 0.0f
, 0.5f
);
255 gtk_box_pack_start(GTK_BOX(hbox
), label
, FALSE
, TRUE
, 1);
256 gtk_widget_show(label
);
258 wid_command
= gtk_entry_new();
259 gtk_box_pack_start(GTK_BOX(hbox
), wid_command
, TRUE
, TRUE
, 1);
260 gtk_widget_show(wid_command
);
262 hbox
= gtk_hbox_new(FALSE
, 1);
263 gtk_box_pack_start(GTK_BOX(vbox
), hbox
, FALSE
, TRUE
, 1);
264 gtk_widget_show(hbox
);
266 label
= gtk_label_new("Message command : ");
267 gtk_misc_set_alignment(GTK_MISC(label
), 0.0f
, 0.5f
);
268 gtk_box_pack_start(GTK_BOX(hbox
), label
, FALSE
, TRUE
, 1);
269 gtk_widget_show(label
);
271 wid_msgcmd
= gtk_entry_new();
272 gtk_box_pack_start(GTK_BOX(hbox
), wid_msgcmd
, TRUE
, TRUE
, 1);
273 gtk_widget_show(wid_msgcmd
);
276 label
= gtk_label_new(" Misc options ");
277 gtk_misc_set_alignment(GTK_MISC(label
), 0.0f
, 0.5f
);
278 gtk_notebook_append_page(GTK_NOTEBOOK(notebook
), left_vbox
, label
);
279 gtk_widget_show(label
);
280 gtk_widget_show(left_vbox
);
283 /*-- Liste des alarmes --*/
284 right_vbox
= gtk_vbox_new(FALSE
, 1);
286 scrolled_window
= gtk_scrolled_window_new(NULL
, NULL
);
287 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled_window
),
288 GTK_POLICY_AUTOMATIC
, GTK_POLICY_ALWAYS
);
290 alarmlist
= create_alarmlist();
291 g_signal_connect(gtk_tree_view_get_selection(GTK_TREE_VIEW(alarmlist
)),
292 "changed", G_CALLBACK(alarmlist_selection_changed
), NULL
);
293 gtk_container_add(GTK_CONTAINER(scrolled_window
), alarmlist
);
294 gtk_widget_show(alarmlist
);
296 gtk_box_pack_start(GTK_BOX(right_vbox
), scrolled_window
, TRUE
, TRUE
, 1);
297 gtk_widget_show(scrolled_window
);
300 frame
= gtk_frame_new(NULL
);
301 gtk_frame_set_shadow_type(GTK_FRAME(frame
), GTK_SHADOW_ETCHED_IN
);
302 gtk_box_pack_start(GTK_BOX(right_vbox
), frame
, FALSE
, TRUE
, 1);
303 gtk_widget_show(frame
);
305 table
= gtk_table_new(2, 2, FALSE
);
306 gtk_container_set_border_width(GTK_CONTAINER(table
), 2);
307 gtk_container_add(GTK_CONTAINER(frame
), table
);
308 gtk_widget_show(table
);
310 bouton
= gtk_button_new_with_label(" Add alarm ");
311 g_signal_connect(bouton
, "clicked", G_CALLBACK(add_alarm
), NULL
);
312 gtk_table_attach_defaults(GTK_TABLE(table
), bouton
, 0, 1, 0, 1);
313 gtk_widget_show(bouton
);
315 bouton
= gtk_button_new_with_label(" Edit entry ");
316 g_signal_connect(bouton
, "clicked", G_CALLBACK(edit_entry
), NULL
);
317 gtk_table_attach_defaults(GTK_TABLE(table
), bouton
, 0, 1, 1, 2);
318 gtk_widget_set_sensitive(bouton
, FALSE
);
319 gtk_widget_show(bouton
);
322 bouton
= gtk_button_new_with_label(" Switch On/Off ");
323 g_signal_connect(bouton
, "clicked", G_CALLBACK(switch_onoff
), NULL
);
324 gtk_table_attach_defaults(GTK_TABLE(table
), bouton
, 1, 2, 1, 2);
325 gtk_widget_set_sensitive(bouton
, FALSE
);
326 gtk_widget_show(bouton
);
329 bouton
= gtk_button_new_with_label(" Remove alarm ");
330 g_signal_connect(bouton
, "clicked", G_CALLBACK(remove_alarm
), NULL
);
331 gtk_table_attach_defaults(GTK_TABLE(table
), bouton
, 1, 2, 0, 1);
332 gtk_widget_set_sensitive(bouton
, FALSE
);
333 gtk_widget_show(bouton
);
337 label
= gtk_label_new(" Alarms ");
338 gtk_misc_set_alignment(GTK_MISC(label
), 0.0f
, 0.5f
);
339 gtk_notebook_append_page(GTK_NOTEBOOK(notebook
), right_vbox
, label
);
340 gtk_widget_show(label
);
341 gtk_widget_show(right_vbox
);
344 gtk_box_pack_start(GTK_BOX(main_vbox
), notebook
, TRUE
, TRUE
, 1);
345 gtk_widget_show(notebook
);
349 /*** BOUTONS DE SAUVEGARDE ET ANNULATION ***/
350 buttons_hbox
= gtk_hbox_new(FALSE
, 1);
351 gtk_box_pack_start(GTK_BOX(main_vbox
), buttons_hbox
, FALSE
, TRUE
, 1);
352 gtk_widget_show(buttons_hbox
);
355 bouton
= gtk_button_new_with_label(" Save ");
356 g_signal_connect(bouton
, "clicked", G_CALLBACK(save_datas
), NULL
);
357 g_signal_connect(bouton
, "clicked", G_CALLBACK(quit_app
), NULL
);
358 gtk_box_pack_start(GTK_BOX(buttons_hbox
), bouton
, TRUE
, TRUE
, 0);
359 gtk_widget_set_can_default(GTK_WIDGET(bouton
), TRUE
);
360 gtk_widget_grab_default(GTK_WIDGET(bouton
));
361 gtk_widget_show(bouton
);
363 bouton
= gtk_button_new_with_label(" Cancel ");
364 g_signal_connect(bouton
, "clicked", G_CALLBACK(quit_app
), NULL
);
365 gtk_box_pack_start(GTK_BOX(buttons_hbox
), bouton
, TRUE
, TRUE
, 0);
366 gtk_widget_set_can_default(GTK_WIDGET(bouton
), TRUE
);
367 gtk_widget_show(bouton
);
371 /*** AFFICHAGE DE LA FENÊTRE ***/
372 gtk_widget_show(application
);