wmclockmon: build against GTK+ 2.0.
[dockapps.git] / wmclockmon / wmclockmon-config / actions.c
blob0fb62eb35c86f2cc48a996d186ce8577710e716c
1 /*
2 * actions.c
3 */
5 #include <stdio.h>
6 #include <stdlib.h>
7 #include <string.h>
8 #include <strings.h>
9 #include <sys/types.h>
10 #include <ctype.h>
11 #include <pwd.h>
12 #include <unistd.h>
13 #include <sys/types.h>
14 #include "defines.h"
15 #include "variables.h"
16 #include "dialogs.h"
17 #include "mainwindow.h"
18 #include "tools.h"
19 #include "edit.h"
20 #include "actions.h"
23 void quit_app() {
24 FREE(command);
25 FREE(config_file);
26 FREE(light_color);
27 free_alrm(&alarms);
28 gtk_main_quit();
32 void set_list() {
33 Alarm *alrm = alarms;
34 gchar *text_line[4];
35 int row = 0, r = 0;
37 gtk_clist_clear(GTK_CLIST(alarmlist));
38 selected_row = -1;
39 gtk_clist_freeze(GTK_CLIST(alarmlist));
40 while (alrm) {
41 text_line[0] = alrm->on ? "ON" : "OFF";
42 text_line[1] = alrm->time ? alrm->time : "ERROR";
43 text_line[2] = alrm->date ? alrm->date : "ALL";
44 text_line[3] = alrm->msg ? alrm->msg : "";
45 row = gtk_clist_append(GTK_CLIST(alarmlist), text_line);
46 gtk_clist_set_row_data(GTK_CLIST(alarmlist), row, (gpointer)alrm);
47 alrm = alrm->next;
48 r++;
50 gtk_clist_thaw(GTK_CLIST(alarmlist));
51 list_unsel_cb(GTK_CLIST(alarmlist), 0, 0, NULL, NULL);
54 void set_values() {
55 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(wid_backlight), backlight);
56 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(wid_blink),
57 switch_authorized);
58 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(wid_h12), h12);
59 if (time_mode == 1)
60 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(wid_itm), 1);
61 else if (time_mode == 2)
62 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(wid_bin), 1);
63 else
64 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(wid_clk), 1);
65 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(wid_locale), use_locale);
66 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(wid_showcal), showcal);
67 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(wid_calalrms), calalrms);
68 if (light_color) gtk_entry_set_text(GTK_ENTRY(wid_color), light_color);
69 if (command) gtk_entry_set_text(GTK_ENTRY(wid_command), command);
70 if (msgcmd) gtk_entry_set_text(GTK_ENTRY(wid_msgcmd), msgcmd);
71 if (style_name) gtk_entry_set_text(GTK_ENTRY(wid_stylename), style_name);
72 if (style_dir) gtk_entry_set_text(GTK_ENTRY(wid_styledir), style_dir);
74 set_list();
78 void save_datas() {
79 style_dir = gtk_entry_get_text(GTK_ENTRY(wid_styledir));
80 style_name = gtk_entry_get_text(GTK_ENTRY(wid_stylename));
81 light_color = gtk_entry_get_text(GTK_ENTRY(wid_color));
82 command = gtk_entry_get_text(GTK_ENTRY(wid_command));
83 msgcmd = gtk_entry_get_text(GTK_ENTRY(wid_msgcmd));
84 backlight = GTK_TOGGLE_BUTTON(wid_backlight)->active;
85 switch_authorized = GTK_TOGGLE_BUTTON(wid_blink)->active;
86 h12 = GTK_TOGGLE_BUTTON(wid_h12)->active;
87 if (GTK_TOGGLE_BUTTON(wid_itm)->active)
88 time_mode = 1;
89 if (GTK_TOGGLE_BUTTON(wid_bin)->active)
90 time_mode = 2;
91 else
92 time_mode = 0;
93 use_locale = GTK_TOGGLE_BUTTON(wid_locale)->active;
94 showcal = GTK_TOGGLE_BUTTON(wid_showcal)->active;
95 calalrms = GTK_TOGGLE_BUTTON(wid_calalrms)->active;
97 save_cfgfile();
101 void do_add(GtkWidget *widget, void *data) {
102 alrm_add(&alarms, newalarm);
103 set_list();
104 FREE(newalarm);
108 void add_alarm() {
109 edit_dialog("Add alarm...", TRUE, "12:00", NULL, NULL, do_add);
113 void do_change(GtkWidget *widget, void *data) {
114 Alarm *alrm;
115 char *time = NULL, *date = NULL, *ison = NULL, *mesg = NULL, *at;
116 char *tokstr = xstrdup(newalarm);
117 char *toksav = tokstr;
119 alrm = (Alarm *)gtk_clist_get_row_data(GTK_CLIST(alarmlist), selected_row);
121 at = strchr(newalarm, '@');
122 if (at) ison = strtok(tokstr, "@");
123 time = strtok(at ? NULL : tokstr, "-.");
124 if (strchr(newalarm, '-')) date = strtok(NULL, ".");
125 mesg = strtok(NULL, "\n\0");
127 FREE(alrm->entry);
128 FREE(alrm->time);
129 FREE(alrm->date);
130 FREE(alrm->msg);
131 alrm->entry = xstrdup(newalarm);
132 alrm->time = time ? xstrdup(time) : NULL;
133 alrm->date = date ? xstrdup(date) : NULL;
134 alrm->on = ison ? getbool(ison) : TRUE;
135 alrm->msg = mesg ? xstrdup(mesg) : NULL;
136 set_list();
137 FREE(newalarm);
138 FREE(toksav);
143 void edit_entry() {
144 Alarm *alrm;
146 alrm = (Alarm *)gtk_clist_get_row_data(GTK_CLIST(alarmlist), selected_row);
147 edit_dialog("Edit alarm...", alrm->on, alrm->time, alrm->date, alrm->msg, do_change);
151 void switch_onoff() {
152 Alarm *alrm;
154 /* get selected default box */
155 alrm = (Alarm *)gtk_clist_get_row_data(GTK_CLIST(alarmlist), selected_row);
156 alrm->on = !alrm->on;
157 /* set text in both rows */
158 gtk_clist_set_text(GTK_CLIST(alarmlist), selected_row, 0,
159 alrm->on ? "ON" : "OFF");
164 void remove_alarm() {
165 Alarm *alrm, *prev;
167 alrm = (Alarm *)gtk_clist_get_row_data(GTK_CLIST(alarmlist), selected_row);
168 prev = alarms;
169 while (prev && (prev->next != alrm)) {
170 prev = prev->next;
172 if (alrm == alarms) {
173 alarms = alrm->next;
174 } else if (prev != NULL) {
175 prev->next = alrm->next;
176 } else {
177 fprintf(stderr, "Error when removing alarm...\n");
179 FREE(alrm->entry);
180 FREE(alrm->time);
181 FREE(alrm->date);
182 FREE(alrm->msg);
183 FREE(alrm);
184 set_list();