13 #include <sys/types.h>
15 #include "variables.h"
17 #include "mainwindow.h"
22 extern int free_light_color
;
23 extern int free_command
;
41 gtk_clist_clear(GTK_CLIST(alarmlist
));
43 gtk_clist_freeze(GTK_CLIST(alarmlist
));
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
);
54 gtk_clist_thaw(GTK_CLIST(alarmlist
));
55 list_unsel_cb(GTK_CLIST(alarmlist
), 0, 0, NULL
, NULL
);
59 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(wid_backlight
), backlight
);
60 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(wid_blink
),
62 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(wid_h12
), h12
);
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);
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
);
87 if (free_light_color
) {
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
)
101 if (GTK_TOGGLE_BUTTON(wid_bin
)->active
)
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
;
113 void do_add(GtkWidget
*widget
, void *data
) {
114 alrm_add(&alarms
, newalarm
);
121 edit_dialog("Add alarm...", TRUE
, "12:00", NULL
, NULL
, do_add
);
125 void do_change(GtkWidget
*widget
, void *data
) {
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");
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
;
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() {
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() {
179 alrm
= (Alarm
*)gtk_clist_get_row_data(GTK_CLIST(alarmlist
), selected_row
);
181 while (prev
&& (prev
->next
!= alrm
)) {
184 if (alrm
== alarms
) {
186 } else if (prev
!= NULL
) {
187 prev
->next
= alrm
->next
;
189 fprintf(stderr
, "Error when removing alarm...\n");