wmclockmon: fix global variables causing linkage failure
[dockapps.git] / wmclockmon / wmclockmon-config / actions.c
blob45ded055be973847b420707c6111bce73aee997e
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"
22 extern int free_light_color;
23 extern int free_command;
25 void quit_app() {
26 if (free_command)
27 FREE(command);
28 FREE(config_file);
29 if (free_light_color)
30 FREE(light_color);
31 free_alrm(&alarms);
32 gtk_main_quit();
36 void set_list() {
37 Alarm *alrm = alarms;
38 gchar *text_line[4];
39 int row = 0, r = 0;
41 gtk_clist_clear(GTK_CLIST(alarmlist));
42 selected_row = -1;
43 gtk_clist_freeze(GTK_CLIST(alarmlist));
44 while (alrm) {
45 text_line[0] = alrm->on ? "ON" : "OFF";
46 text_line[1] = alrm->time ? alrm->time : "ERROR";
47 text_line[2] = alrm->date ? alrm->date : "ALL";
48 text_line[3] = alrm->msg ? alrm->msg : "";
49 row = gtk_clist_append(GTK_CLIST(alarmlist), text_line);
50 gtk_clist_set_row_data(GTK_CLIST(alarmlist), row, (gpointer)alrm);
51 alrm = alrm->next;
52 r++;
54 gtk_clist_thaw(GTK_CLIST(alarmlist));
55 list_unsel_cb(GTK_CLIST(alarmlist), 0, 0, NULL, NULL);
58 void set_values() {
59 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(wid_backlight), backlight);
60 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(wid_blink),
61 switch_authorized);
62 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(wid_h12), h12);
63 if (time_mode == 1)
64 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(wid_itm), 1);
65 else if (time_mode == 2)
66 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(wid_bin), 1);
67 else
68 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(wid_clk), 1);
69 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(wid_locale), use_locale);
70 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(wid_showcal), showcal);
71 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(wid_calalrms), calalrms);
72 if (light_color) gtk_entry_set_text(GTK_ENTRY(wid_color), light_color);
73 if (command) gtk_entry_set_text(GTK_ENTRY(wid_command), command);
74 if (msgcmd) gtk_entry_set_text(GTK_ENTRY(wid_msgcmd), msgcmd);
75 if (style_name) gtk_entry_set_text(GTK_ENTRY(wid_stylename), style_name);
76 if (style_dir) gtk_entry_set_text(GTK_ENTRY(wid_styledir), style_dir);
78 set_list();
82 void save_datas() {
83 if (free_command) {
84 FREE(command);
85 free_command = 0;
87 if (free_light_color) {
88 FREE(light_color);
89 free_light_color = 0;
91 style_dir = gtk_entry_get_text(GTK_ENTRY(wid_styledir));
92 style_name = gtk_entry_get_text(GTK_ENTRY(wid_stylename));
93 light_color = gtk_entry_get_text(GTK_ENTRY(wid_color));
94 command = gtk_entry_get_text(GTK_ENTRY(wid_command));
95 msgcmd = gtk_entry_get_text(GTK_ENTRY(wid_msgcmd));
96 backlight = GTK_TOGGLE_BUTTON(wid_backlight)->active;
97 switch_authorized = GTK_TOGGLE_BUTTON(wid_blink)->active;
98 h12 = GTK_TOGGLE_BUTTON(wid_h12)->active;
99 if (GTK_TOGGLE_BUTTON(wid_itm)->active)
100 time_mode = 1;
101 if (GTK_TOGGLE_BUTTON(wid_bin)->active)
102 time_mode = 2;
103 else
104 time_mode = 0;
105 use_locale = GTK_TOGGLE_BUTTON(wid_locale)->active;
106 showcal = GTK_TOGGLE_BUTTON(wid_showcal)->active;
107 calalrms = GTK_TOGGLE_BUTTON(wid_calalrms)->active;
109 save_cfgfile();
113 void do_add(GtkWidget *widget, void *data) {
114 alrm_add(&alarms, newalarm);
115 set_list();
116 FREE(newalarm);
120 void add_alarm() {
121 edit_dialog("Add alarm...", TRUE, "12:00", NULL, NULL, do_add);
125 void do_change(GtkWidget *widget, void *data) {
126 Alarm *alrm;
127 char *time = NULL, *date = NULL, *ison = NULL, *mesg = NULL, *at;
128 char *tokstr = xstrdup(newalarm);
129 char *toksav = tokstr;
131 alrm = (Alarm *)gtk_clist_get_row_data(GTK_CLIST(alarmlist), selected_row);
133 at = strchr(newalarm, '@');
134 if (at) ison = strtok(tokstr, "@");
135 time = strtok(at ? NULL : tokstr, "-.");
136 if (strchr(newalarm, '-')) date = strtok(NULL, ".");
137 mesg = strtok(NULL, "\n\0");
139 FREE(alrm->entry);
140 FREE(alrm->time);
141 FREE(alrm->date);
142 FREE(alrm->msg);
143 alrm->entry = xstrdup(newalarm);
144 alrm->time = time ? xstrdup(time) : NULL;
145 alrm->date = date ? xstrdup(date) : NULL;
146 alrm->on = ison ? getbool(ison) : TRUE;
147 alrm->msg = mesg ? xstrdup(mesg) : NULL;
148 set_list();
149 FREE(newalarm);
150 FREE(toksav);
155 void edit_entry() {
156 Alarm *alrm;
158 alrm = (Alarm *)gtk_clist_get_row_data(GTK_CLIST(alarmlist), selected_row);
159 edit_dialog("Edit alarm...", alrm->on, alrm->time, alrm->date, alrm->msg, do_change);
163 void switch_onoff() {
164 Alarm *alrm;
166 /* get selected default box */
167 alrm = (Alarm *)gtk_clist_get_row_data(GTK_CLIST(alarmlist), selected_row);
168 alrm->on = !alrm->on;
169 /* set text in both rows */
170 gtk_clist_set_text(GTK_CLIST(alarmlist), selected_row, 0,
171 alrm->on ? "ON" : "OFF");
176 void remove_alarm() {
177 Alarm *alrm, *prev;
179 alrm = (Alarm *)gtk_clist_get_row_data(GTK_CLIST(alarmlist), selected_row);
180 prev = alarms;
181 while (prev && (prev->next != alrm)) {
182 prev = prev->next;
184 if (alrm == alarms) {
185 alarms = alrm->next;
186 } else if (prev != NULL) {
187 prev->next = alrm->next;
188 } else {
189 fprintf(stderr, "Error when removing alarm...\n");
191 FREE(alrm->entry);
192 FREE(alrm->time);
193 FREE(alrm->date);
194 FREE(alrm->msg);
195 FREE(alrm);
196 set_list();