Add missing libraries to examples' Makefiles
[dockapps.git] / wmclockmon / wmclockmon-config / mainwindow.c
blobcd335059f99f2dd8f4ef9c1dc1186f88d4a52b1a
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 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);
42 static void
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);
53 static GtkWidget *
54 create_alarmlist (void)
56 GtkTreeView *view;
57 GtkTreeSelection *selection;
58 GtkCellRenderer *renderer;
59 GtkTreeModel *model;
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,
70 NULL);
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,
76 NULL);
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,
82 NULL);
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,
88 NULL);
90 model = GTK_TREE_MODEL(gtk_list_store_new(NUM_COLS,
91 G_TYPE_STRING,
92 G_TYPE_STRING,
93 G_TYPE_STRING,
94 G_TYPE_STRING,
95 G_TYPE_POINTER));
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;
109 GtkWidget *bouton;
110 GtkWidget *scrolled_window;
111 GtkWidget *vbox;
112 GtkWidget *hbox;
113 GtkWidget *label;
114 GtkWidget *frame;
115 GtkWidget *grid;
116 GtkWidget *notebook;
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_box_new(GTK_ORIENTATION_VERTICAL, 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_box_new(GTK_ORIENTATION_VERTICAL, 1);
143 /*--- Frame 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_box_new(GTK_ORIENTATION_HORIZONTAL, 1);
150 gtk_container_add(GTK_CONTAINER(frame), hbox);
151 gtk_widget_show(hbox);
153 vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 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_box_new(GTK_ORIENTATION_VERTICAL, 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_box_new(GTK_ORIENTATION_VERTICAL, 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);
201 /*--- Frame 2 ---*/
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 grid = gtk_grid_new();
208 gtk_grid_set_row_homogeneous(GTK_GRID(grid), TRUE);
209 gtk_grid_set_column_homogeneous(GTK_GRID(grid), TRUE);
210 gtk_container_set_border_width(GTK_CONTAINER(grid), 2);
211 gtk_container_add(GTK_CONTAINER(frame), grid);
212 gtk_widget_show(grid);
214 label = gtk_label_new("Style directory : ");
215 gtk_label_set_xalign(GTK_LABEL(label), 0.0f);
216 gtk_label_set_yalign(GTK_LABEL(label), 0.5f);
217 gtk_grid_attach(GTK_GRID(grid), label, 0, 0, 1, 1);
218 gtk_widget_show(label);
220 wid_styledir = gtk_entry_new();
221 gtk_grid_attach(GTK_GRID(grid), wid_styledir, 1, 0, 1, 1);
222 gtk_widget_show(wid_styledir);
224 label = gtk_label_new("Style : ");
225 gtk_label_set_xalign(GTK_LABEL(label), 0.0f);
226 gtk_label_set_yalign(GTK_LABEL(label), 0.5f);
227 gtk_grid_attach(GTK_GRID(grid), label, 0, 1, 1, 1);
228 gtk_widget_show(label);
230 wid_stylename = gtk_entry_new();
231 gtk_grid_attach(GTK_GRID(grid), wid_stylename, 1, 1, 1, 1);
232 gtk_widget_show(wid_stylename);
234 label = gtk_label_new("Color : ");
235 gtk_label_set_xalign(GTK_LABEL(label), 0.0f);
236 gtk_label_set_yalign(GTK_LABEL(label), 0.5f);
237 gtk_grid_attach(GTK_GRID(grid), label, 0, 2, 1, 1);
238 gtk_widget_show(label);
240 wid_color = gtk_entry_new();
241 gtk_grid_attach(GTK_GRID(grid), wid_color, 1, 2, 1, 1);
242 gtk_widget_show(wid_color);
244 /*--- Frame 3 ---*/
245 frame = gtk_frame_new(" Commands ");
246 gtk_frame_set_shadow_type(GTK_FRAME(frame), GTK_SHADOW_ETCHED_IN);
247 gtk_box_pack_start(GTK_BOX(left_vbox), frame, FALSE, FALSE, 1);
248 gtk_widget_show(frame);
250 vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 1);
251 gtk_container_add(GTK_CONTAINER(frame), vbox);
252 gtk_widget_show(vbox);
254 hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 1);
255 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, TRUE, 1);
256 gtk_widget_show(hbox);
258 label = gtk_label_new("Command : ");
259 gtk_label_set_xalign(GTK_LABEL(label), 0.0f);
260 gtk_label_set_yalign(GTK_LABEL(label), 0.5f);
261 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, TRUE, 1);
262 gtk_widget_show(label);
264 wid_command = gtk_entry_new();
265 gtk_box_pack_start(GTK_BOX(hbox), wid_command, TRUE, TRUE, 1);
266 gtk_widget_show(wid_command);
268 hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 1);
269 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, TRUE, 1);
270 gtk_widget_show(hbox);
272 label = gtk_label_new("Message command : ");
273 gtk_label_set_xalign(GTK_LABEL(label), 0.0f);
274 gtk_label_set_yalign(GTK_LABEL(label), 0.5f);
275 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, TRUE, 1);
276 gtk_widget_show(label);
278 wid_msgcmd = gtk_entry_new();
279 gtk_box_pack_start(GTK_BOX(hbox), wid_msgcmd, TRUE, TRUE, 1);
280 gtk_widget_show(wid_msgcmd);
283 label = gtk_label_new(" Misc options ");
284 gtk_label_set_xalign(GTK_LABEL(label), 0.0f);
285 gtk_label_set_yalign(GTK_LABEL(label), 0.5f);
286 gtk_notebook_append_page(GTK_NOTEBOOK(notebook), left_vbox, label);
287 gtk_widget_show(label);
288 gtk_widget_show(left_vbox);
291 /*-- Liste des alarmes --*/
292 right_vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 1);
294 scrolled_window = gtk_scrolled_window_new(NULL, NULL);
295 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled_window),
296 GTK_POLICY_AUTOMATIC, GTK_POLICY_ALWAYS);
298 alarmlist = create_alarmlist();
299 g_signal_connect(gtk_tree_view_get_selection(GTK_TREE_VIEW(alarmlist)),
300 "changed", G_CALLBACK(alarmlist_selection_changed), NULL);
301 gtk_container_add(GTK_CONTAINER(scrolled_window), alarmlist);
302 gtk_widget_show(alarmlist);
304 gtk_box_pack_start(GTK_BOX(right_vbox), scrolled_window, TRUE, TRUE, 1);
305 gtk_widget_show(scrolled_window);
307 /*--- Frame 4 ---*/
308 frame = gtk_frame_new(NULL);
309 gtk_frame_set_shadow_type(GTK_FRAME(frame), GTK_SHADOW_ETCHED_IN);
310 gtk_box_pack_start(GTK_BOX(right_vbox), frame, FALSE, TRUE, 1);
311 gtk_widget_show(frame);
313 grid = gtk_grid_new();
314 gtk_grid_set_row_homogeneous(GTK_GRID(grid), TRUE);
315 gtk_grid_set_column_homogeneous(GTK_GRID(grid), TRUE);
316 gtk_container_set_border_width(GTK_CONTAINER(grid), 2);
317 gtk_container_add(GTK_CONTAINER(frame), grid);
318 gtk_widget_show(grid);
320 bouton = gtk_button_new_with_label(" Add alarm ");
321 g_signal_connect(bouton, "clicked", G_CALLBACK(add_alarm), NULL);
322 gtk_grid_attach(GTK_GRID(grid), bouton, 0, 0, 1, 1);
323 gtk_widget_show(bouton);
325 bouton = gtk_button_new_with_label(" Edit entry ");
326 g_signal_connect(bouton, "clicked", G_CALLBACK(edit_entry), NULL);
327 gtk_grid_attach(GTK_GRID(grid), bouton, 0, 1, 1, 1);
328 gtk_widget_set_sensitive(bouton, FALSE);
329 gtk_widget_show(bouton);
330 b_edit = bouton;
332 bouton = gtk_button_new_with_label(" Switch On/Off ");
333 g_signal_connect(bouton, "clicked", G_CALLBACK(switch_onoff), NULL);
334 gtk_grid_attach(GTK_GRID(grid), bouton, 1, 1, 1, 1);
335 gtk_widget_set_sensitive(bouton, FALSE);
336 gtk_widget_show(bouton);
337 b_set = bouton;
339 bouton = gtk_button_new_with_label(" Remove alarm ");
340 g_signal_connect(bouton, "clicked", G_CALLBACK(remove_alarm), NULL);
341 gtk_grid_attach(GTK_GRID(grid), bouton, 1, 0, 1, 1);
342 gtk_widget_set_sensitive(bouton, FALSE);
343 gtk_widget_show(bouton);
344 b_remove = bouton;
347 label = gtk_label_new(" Alarms ");
348 gtk_label_set_xalign(GTK_LABEL(label), 0.0f);
349 gtk_label_set_yalign(GTK_LABEL(label), 0.5f);
350 gtk_notebook_append_page(GTK_NOTEBOOK(notebook), right_vbox, label);
351 gtk_widget_show(label);
352 gtk_widget_show(right_vbox);
355 gtk_box_pack_start(GTK_BOX(main_vbox), notebook, TRUE, TRUE, 1);
356 gtk_widget_show(notebook);
360 /*** BOUTONS DE SAUVEGARDE ET ANNULATION ***/
361 buttons_hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 1);
362 gtk_box_pack_start(GTK_BOX(main_vbox), buttons_hbox, FALSE, TRUE, 1);
363 gtk_widget_show(buttons_hbox);
366 bouton = gtk_button_new_with_label(" Save ");
367 g_signal_connect(bouton, "clicked", G_CALLBACK(save_datas), NULL);
368 g_signal_connect(bouton, "clicked", G_CALLBACK(quit_app), NULL);
369 gtk_box_pack_start(GTK_BOX(buttons_hbox), bouton, TRUE, TRUE, 0);
370 gtk_widget_set_can_default(GTK_WIDGET(bouton), TRUE);
371 gtk_widget_grab_default(GTK_WIDGET(bouton));
372 gtk_widget_show(bouton);
374 bouton = gtk_button_new_with_label(" Cancel ");
375 g_signal_connect(bouton, "clicked", G_CALLBACK(quit_app), NULL);
376 gtk_box_pack_start(GTK_BOX(buttons_hbox), bouton, TRUE, TRUE, 0);
377 gtk_widget_set_can_default(GTK_WIDGET(bouton), TRUE);
378 gtk_widget_show(bouton);
382 /*** AFFICHAGE DE LA FENÊTRE ***/
383 gtk_widget_show(application);