wmclockmon: fix global variables causing linkage failure
[dockapps.git] / wmclockmon / wmclockmon-config / mainwindow.c
blobb7a72bb763e4f1cd9aeb6283656d9d8bbdf6a1e1
1 /*
2 * Create the main window.
3 */
5 #include <gtk/gtk.h>
6 #include "../config.h"
7 #include "defines.h"
8 #include "variables.h"
9 #include "mainwindow.h"
10 #include "actions.h"
13 GtkWidget *application;
14 GtkWidget *alarmlist;
15 GtkWidget *wid_backlight;
16 GtkWidget *wid_blink;
17 GtkWidget *wid_styledir;
18 GtkWidget *wid_stylename;
19 GtkWidget *wid_color;
20 GtkWidget *wid_command;
21 GtkWidget *wid_msgcmd;
22 GtkWidget *wid_h12;
23 GtkWidget *wid_clk;
24 GtkWidget *wid_itm;
25 GtkWidget *wid_bin;
26 GtkWidget *wid_locale;
27 GtkWidget *wid_showcal;
28 GtkWidget *wid_calalrms;
30 int selected_row;
32 static GtkWidget *b_edit;
33 static GtkWidget *b_set;
34 static GtkWidget *b_remove;
36 static gint list_sel_cb (GtkCList *clist,
37 gint row,
38 gint column,
39 GdkEventButton *event,
40 void *data) {
41 selected_row = row;
42 gtk_widget_set_sensitive(b_edit, TRUE);
43 gtk_widget_set_sensitive(b_set, TRUE);
44 gtk_widget_set_sensitive(b_remove, TRUE);
45 return TRUE;
49 gint list_unsel_cb (GtkCList *clist,
50 gint row,
51 gint column,
52 GdkEventButton *event,
53 void *data) {
54 selected_row = -1;
55 gtk_widget_set_sensitive(b_edit, FALSE);
56 gtk_widget_set_sensitive(b_set, FALSE);
57 gtk_widget_set_sensitive(b_remove, FALSE);
58 return TRUE;
62 void create_mainwindow() {
63 GtkWidget *main_vbox;
64 GtkWidget *buttons_hbox;
65 GtkWidget *left_vbox;
66 GtkWidget *right_vbox;
67 GtkWidget *bouton;
68 GtkWidget *scrolled_window;
69 GtkWidget *vbox;
70 GtkWidget *hbox;
71 GtkWidget *label;
72 GtkWidget *frame;
73 GtkWidget *table;
74 GtkWidget *notebook;
75 gchar *clist_titles[4] = {" Status ", " Hour ", " Day ", " Message "};
78 /*** FENÊTRE PRINCIPALE ***/
79 application = gtk_window_new(GTK_WINDOW_TOPLEVEL);
80 gtk_window_set_title(GTK_WINDOW(application), PACKAGE" Config");
81 /*-- Connexion aux signaux --*/
82 gtk_signal_connect(GTK_OBJECT(application), "delete_event",
83 GTK_SIGNAL_FUNC(quit_app), NULL);
84 gtk_signal_connect(GTK_OBJECT(application), "destroy",
85 GTK_SIGNAL_FUNC(quit_app), "WM destroy");
86 /*-- Taille de la fenêtre --*/
87 gtk_widget_set_usize(GTK_WIDGET(application), WIN_WIDTH, WIN_HEIGHT);
88 gtk_widget_realize(application);
90 /*** Zone principale de placement des widgets***/
91 main_vbox = gtk_vbox_new(FALSE, 1);
92 gtk_container_border_width(GTK_CONTAINER(main_vbox), 1);
93 gtk_container_add(GTK_CONTAINER(application), main_vbox);
94 gtk_widget_show(main_vbox);
98 /*** WIDGETS DE DONNÉES ***/
99 notebook = gtk_notebook_new();
101 /*-- Zones des données simples --*/
102 left_vbox = gtk_vbox_new(FALSE, 1);
105 /*--- Frame 1 ---*/
106 frame = gtk_frame_new(" Startup ");
107 gtk_frame_set_shadow_type(GTK_FRAME(frame), GTK_SHADOW_ETCHED_IN);
108 gtk_box_pack_start(GTK_BOX(left_vbox), frame, FALSE, TRUE, 1);
109 gtk_widget_show(frame);
111 hbox = gtk_hbox_new(FALSE, 1);
112 gtk_container_add(GTK_CONTAINER(frame), hbox);
113 gtk_widget_show(hbox);
115 vbox = gtk_vbox_new(FALSE, 1);
116 gtk_box_pack_start(GTK_BOX(hbox), vbox, TRUE, TRUE, 1);
117 gtk_widget_show(vbox);
119 wid_backlight = gtk_check_button_new_with_label("Back (or LED) light");
120 gtk_box_pack_start(GTK_BOX(vbox), wid_backlight, FALSE, TRUE, 1);
121 gtk_widget_show(wid_backlight);
123 wid_blink = gtk_check_button_new_with_label("Blink");
124 gtk_box_pack_start(GTK_BOX(vbox), wid_blink, FALSE, TRUE, 1);
125 gtk_widget_show(wid_blink);
127 wid_h12 = gtk_check_button_new_with_label("12h clock mode");
128 gtk_box_pack_start(GTK_BOX(vbox), wid_h12, FALSE, TRUE, 1);
129 gtk_widget_show(wid_h12);
131 vbox = gtk_vbox_new(FALSE, 1);
132 gtk_box_pack_start(GTK_BOX(hbox), vbox, TRUE, TRUE, 1);
133 gtk_widget_show(vbox);
135 wid_locale = gtk_check_button_new_with_label("Use current locale");
136 gtk_box_pack_start(GTK_BOX(vbox), wid_locale, FALSE, TRUE, 1);
137 gtk_widget_show(wid_locale);
139 wid_showcal = gtk_check_button_new_with_label("Show calendar");
140 gtk_box_pack_start(GTK_BOX(vbox), wid_showcal, FALSE, TRUE, 1);
141 gtk_widget_show(wid_showcal);
143 wid_calalrms = gtk_check_button_new_with_label("Load calendar alarms");
144 gtk_box_pack_start(GTK_BOX(vbox), wid_calalrms, FALSE, TRUE, 1);
145 gtk_widget_show(wid_calalrms);
147 vbox = gtk_vbox_new(FALSE, 1);
148 gtk_box_pack_start(GTK_BOX(hbox), vbox, TRUE, TRUE, 1);
149 gtk_widget_show(vbox);
151 wid_clk = gtk_radio_button_new_with_label(NULL, "Normal clock");
152 gtk_box_pack_start(GTK_BOX(vbox), wid_clk, FALSE, TRUE, 1);
153 gtk_widget_show(wid_clk);
155 wid_itm = gtk_radio_button_new_with_label_from_widget(GTK_RADIO_BUTTON(wid_clk), "Internet time");
156 gtk_box_pack_start(GTK_BOX(vbox), wid_itm, FALSE, TRUE, 1);
157 gtk_widget_show(wid_itm);
159 wid_bin = gtk_radio_button_new_with_label_from_widget(GTK_RADIO_BUTTON(wid_clk), "Binary clock");
160 gtk_box_pack_start(GTK_BOX(vbox), wid_bin, FALSE, TRUE, 1);
161 gtk_widget_show(wid_bin);
163 /*--- Frame 2 ---*/
164 frame = gtk_frame_new(" Look ");
165 gtk_frame_set_shadow_type(GTK_FRAME(frame), GTK_SHADOW_ETCHED_IN);
166 gtk_box_pack_start(GTK_BOX(left_vbox), frame, FALSE, TRUE, 1);
167 gtk_widget_show(frame);
169 table = gtk_table_new(2, 3, FALSE);
170 gtk_container_set_border_width(GTK_CONTAINER(table), 2);
171 gtk_container_add(GTK_CONTAINER(frame), table);
172 gtk_widget_show(table);
174 label = gtk_label_new("Style directory : ");
175 gtk_misc_set_alignment(GTK_MISC(label), 0.0f, 0.5f);
176 gtk_table_attach_defaults(GTK_TABLE(table), label, 0, 1, 0, 1);
177 gtk_widget_show(label);
179 wid_styledir = gtk_entry_new();
180 gtk_table_attach_defaults(GTK_TABLE(table), wid_styledir, 1, 2, 0, 1);
181 gtk_widget_show(wid_styledir);
183 label = gtk_label_new("Style : ");
184 gtk_misc_set_alignment(GTK_MISC(label), 0.0f, 0.5f);
185 gtk_table_attach_defaults(GTK_TABLE(table), label, 0, 1, 1, 2);
186 gtk_widget_show(label);
188 wid_stylename = gtk_entry_new();
189 gtk_table_attach_defaults(GTK_TABLE(table), wid_stylename, 1, 2, 1, 2);
190 gtk_widget_show(wid_stylename);
192 label = gtk_label_new("Color : ");
193 gtk_misc_set_alignment(GTK_MISC(label), 0.0f, 0.5f);
194 gtk_table_attach_defaults(GTK_TABLE(table), label, 0, 1, 2, 3);
195 gtk_widget_show(label);
197 wid_color = gtk_entry_new();
198 gtk_table_attach_defaults(GTK_TABLE(table), wid_color, 1, 2, 2, 3);
199 gtk_widget_show(wid_color);
201 /*--- Frame 3 ---*/
202 frame = gtk_frame_new(" Commands ");
203 gtk_frame_set_shadow_type(GTK_FRAME(frame), GTK_SHADOW_ETCHED_IN);
204 gtk_box_pack_start(GTK_BOX(left_vbox), frame, FALSE, FALSE, 1);
205 gtk_widget_show(frame);
207 vbox = gtk_vbox_new(FALSE, 1);
208 gtk_container_add(GTK_CONTAINER(frame), vbox);
209 gtk_widget_show(vbox);
211 hbox = gtk_hbox_new(FALSE, 1);
212 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, TRUE, 1);
213 gtk_widget_show(hbox);
215 label = gtk_label_new("Command : ");
216 gtk_misc_set_alignment(GTK_MISC(label), 0.0f, 0.5f);
217 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, TRUE, 1);
218 gtk_widget_show(label);
220 wid_command = gtk_entry_new();
221 gtk_box_pack_start(GTK_BOX(hbox), wid_command, TRUE, TRUE, 1);
222 gtk_widget_show(wid_command);
224 hbox = gtk_hbox_new(FALSE, 1);
225 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, TRUE, 1);
226 gtk_widget_show(hbox);
228 label = gtk_label_new("Message command : ");
229 gtk_misc_set_alignment(GTK_MISC(label), 0.0f, 0.5f);
230 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, TRUE, 1);
231 gtk_widget_show(label);
233 wid_msgcmd = gtk_entry_new();
234 gtk_box_pack_start(GTK_BOX(hbox), wid_msgcmd, TRUE, TRUE, 1);
235 gtk_widget_show(wid_msgcmd);
238 label = gtk_label_new(" Misc options ");
239 gtk_misc_set_alignment(GTK_MISC(label), 0.0f, 0.5f);
240 gtk_notebook_append_page(GTK_NOTEBOOK(notebook), left_vbox, label);
241 gtk_widget_show(label);
242 gtk_widget_show(left_vbox);
245 /*-- Liste des alarmes --*/
246 right_vbox = gtk_vbox_new(FALSE, 1);
249 scrolled_window = gtk_scrolled_window_new(NULL, NULL);
250 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled_window),
251 GTK_POLICY_AUTOMATIC, GTK_POLICY_ALWAYS);
253 alarmlist = gtk_clist_new_with_titles(4, clist_titles);
254 selected_row = -1;
255 gtk_signal_connect(GTK_OBJECT(alarmlist), "select-row",
256 GTK_SIGNAL_FUNC(list_sel_cb), NULL);
257 gtk_signal_connect(GTK_OBJECT(alarmlist), "unselect-row",
258 GTK_SIGNAL_FUNC(list_unsel_cb), NULL);
259 gtk_container_add(GTK_CONTAINER(scrolled_window), alarmlist);
260 gtk_clist_set_auto_sort(GTK_CLIST(alarmlist), FALSE);
261 gtk_widget_show(alarmlist);
263 gtk_box_pack_start(GTK_BOX(right_vbox), scrolled_window, TRUE, TRUE, 1);
264 gtk_widget_show(scrolled_window);
266 /*--- Frame 4 ---*/
267 frame = gtk_frame_new(NULL);
268 gtk_frame_set_shadow_type(GTK_FRAME(frame), GTK_SHADOW_ETCHED_IN);
269 gtk_box_pack_start(GTK_BOX(right_vbox), frame, FALSE, TRUE, 1);
270 gtk_widget_show(frame);
272 table = gtk_table_new(2, 2, FALSE);
273 gtk_container_set_border_width(GTK_CONTAINER(table), 2);
274 gtk_container_add(GTK_CONTAINER(frame), table);
275 gtk_widget_show(table);
277 bouton = gtk_button_new_with_label(" Add alarm ");
278 gtk_signal_connect(GTK_OBJECT(bouton), "clicked",
279 GTK_SIGNAL_FUNC(add_alarm), NULL);
280 gtk_table_attach_defaults(GTK_TABLE(table), bouton, 0, 1, 0, 1);
281 gtk_widget_show(bouton);
283 bouton = gtk_button_new_with_label(" Edit entry ");
284 gtk_signal_connect(GTK_OBJECT(bouton), "clicked",
285 GTK_SIGNAL_FUNC(edit_entry), NULL);
286 gtk_table_attach_defaults(GTK_TABLE(table), bouton, 0, 1, 1, 2);
287 gtk_widget_set_sensitive(bouton, FALSE);
288 gtk_widget_show(bouton);
289 b_edit = bouton;
291 bouton = gtk_button_new_with_label(" Switch On/Off ");
292 gtk_signal_connect(GTK_OBJECT(bouton), "clicked",
293 GTK_SIGNAL_FUNC(switch_onoff), NULL);
294 gtk_table_attach_defaults(GTK_TABLE(table), bouton, 1, 2, 1, 2);
295 gtk_widget_set_sensitive(bouton, FALSE);
296 gtk_widget_show(bouton);
297 b_set = bouton;
299 bouton = gtk_button_new_with_label(" Remove alarm ");
300 gtk_signal_connect(GTK_OBJECT(bouton), "clicked",
301 GTK_SIGNAL_FUNC(remove_alarm), NULL);
302 gtk_table_attach_defaults(GTK_TABLE(table), bouton, 1, 2, 0, 1);
303 gtk_widget_set_sensitive(bouton, FALSE);
304 gtk_widget_show(bouton);
305 b_remove = bouton;
308 label = gtk_label_new(" Alarms ");
309 gtk_misc_set_alignment(GTK_MISC(label), 0.0f, 0.5f);
310 gtk_notebook_append_page(GTK_NOTEBOOK(notebook), right_vbox, label);
311 gtk_widget_show(label);
312 gtk_widget_show(right_vbox);
315 gtk_box_pack_start(GTK_BOX(main_vbox), notebook, TRUE, TRUE, 1);
316 gtk_widget_show(notebook);
320 /*** BOUTONS DE SAUVEGARDE ET ANNULATION ***/
321 buttons_hbox = gtk_hbox_new(FALSE, 1);
322 gtk_box_pack_start(GTK_BOX(main_vbox), buttons_hbox, FALSE, TRUE, 1);
323 gtk_widget_show(buttons_hbox);
326 bouton = gtk_button_new_with_label(" Save ");
327 gtk_signal_connect(GTK_OBJECT(bouton), "clicked",
328 GTK_SIGNAL_FUNC(save_datas), NULL);
329 gtk_signal_connect(GTK_OBJECT(bouton), "clicked",
330 GTK_SIGNAL_FUNC(quit_app), NULL);
331 gtk_box_pack_start(GTK_BOX(buttons_hbox), bouton, TRUE, TRUE, 0);
332 GTK_WIDGET_SET_FLAGS(GTK_WIDGET(bouton), GTK_CAN_DEFAULT);
333 gtk_widget_grab_default(GTK_WIDGET(bouton));
334 gtk_widget_show(bouton);
336 bouton = gtk_button_new_with_label(" Cancel ");
337 gtk_signal_connect(GTK_OBJECT(bouton), "clicked",
338 GTK_SIGNAL_FUNC(quit_app), NULL);
339 gtk_box_pack_start(GTK_BOX(buttons_hbox), bouton, TRUE, TRUE, 0);
340 GTK_WIDGET_SET_FLAGS(GTK_WIDGET(bouton), GTK_CAN_DEFAULT);
341 gtk_widget_show(bouton);
345 /*** AFFICHAGE DE LA FENÊTRE ***/
346 gtk_widget_show(application);