13 #include <sys/types.h>
15 #include "variables.h"
16 #include "mainwindow.h"
33 static void set_list(void) {
35 GtkTreeModel
*model
= gtk_tree_view_get_model(GTK_TREE_VIEW(alarmlist
));
36 GtkListStore
*store
= GTK_LIST_STORE(model
);
40 gtk_list_store_clear(store
);
44 gtk_list_store_append(store
, &iter
);
45 gtk_list_store_set (store
, &iter
,
46 COL_STATUS
, alrm
->on
? "ON" : "OFF",
47 COL_HOUR
, alrm
->time
? alrm
->time
: "ERROR",
48 COL_DAY
, alrm
->date
? alrm
->date
: "ALL",
49 COL_MESSAGE
, alrm
->msg
? alrm
->msg
: "",
57 clear_alarmlist_selection();
61 void set_values(void) {
62 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(wid_backlight
), backlight
);
63 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(wid_blink
),
65 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(wid_h12
), h12
);
67 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(wid_itm
), 1);
68 else if (time_mode
== 2)
69 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(wid_bin
), 1);
71 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(wid_clk
), 1);
72 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(wid_locale
), use_locale
);
73 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(wid_showcal
), showcal
);
74 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(wid_calalrms
), calalrms
);
75 if (light_color
) gtk_entry_set_text(GTK_ENTRY(wid_color
), light_color
);
76 if (command
) gtk_entry_set_text(GTK_ENTRY(wid_command
), command
);
77 if (msgcmd
) gtk_entry_set_text(GTK_ENTRY(wid_msgcmd
), msgcmd
);
78 if (style_name
) gtk_entry_set_text(GTK_ENTRY(wid_stylename
), style_name
);
79 if (style_dir
) gtk_entry_set_text(GTK_ENTRY(wid_styledir
), style_dir
);
85 void save_datas(void) {
92 style_dir
= xstrdup(gtk_entry_get_text(GTK_ENTRY(wid_styledir
)));
93 style_name
= xstrdup(gtk_entry_get_text(GTK_ENTRY(wid_stylename
)));
94 light_color
= xstrdup(gtk_entry_get_text(GTK_ENTRY(wid_color
)));
95 command
= xstrdup(gtk_entry_get_text(GTK_ENTRY(wid_command
)));
96 msgcmd
= xstrdup(gtk_entry_get_text(GTK_ENTRY(wid_msgcmd
)));
97 backlight
= gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(wid_backlight
));
98 switch_authorized
= gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(wid_blink
));
99 h12
= gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(wid_h12
));
100 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(wid_itm
)))
102 else if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(wid_bin
)))
106 use_locale
= gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(wid_locale
));
107 showcal
= gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(wid_showcal
));
108 calalrms
= gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(wid_calalrms
));
115 alrm_add(&alarms
, newalarm
);
121 void add_alarm(void) {
122 edit_dialog("Add alarm...", TRUE
, "12:00", NULL
, NULL
, do_add
);
127 get_alarm(GtkTreeModel
**modelp
, GtkTreeIter
*iterp
) {
129 GtkTreeSelection
*selection
;
134 selection
= gtk_tree_view_get_selection(GTK_TREE_VIEW(alarmlist
));
135 if (gtk_tree_selection_get_selected(selection
, &model
, &iter
))
136 gtk_tree_model_get(model
, &iter
, COL_ALARM
, (gpointer
) &alrm
, -1);
149 void do_change(void) {
151 char *time
= NULL
, *date
= NULL
, *ison
= NULL
, *mesg
= NULL
, *at
;
152 char *tokstr
= xstrdup(newalarm
);
153 char *toksav
= tokstr
;
155 alrm
= get_alarm(NULL
, NULL
);
159 at
= strchr(newalarm
, '@');
160 if (at
) ison
= strtok(tokstr
, "@");
161 time
= strtok(at
? NULL
: tokstr
, "-.");
162 if (strchr(newalarm
, '-')) date
= strtok(NULL
, ".");
163 mesg
= strtok(NULL
, "\n\0");
169 alrm
->entry
= xstrdup(newalarm
);
170 alrm
->time
= time
? xstrdup(time
) : NULL
;
171 alrm
->date
= date
? xstrdup(date
) : NULL
;
172 alrm
->on
= ison
? getbool(ison
) : TRUE
;
173 alrm
->msg
= mesg
? xstrdup(mesg
) : NULL
;
180 void edit_entry(void) {
183 alrm
= get_alarm(NULL
, NULL
);
187 edit_dialog("Edit alarm...", alrm
->on
, alrm
->time
, alrm
->date
, alrm
->msg
, do_change
);
191 void switch_onoff(void) {
196 /* get selected default box */
197 alrm
= get_alarm(&model
, &iter
);
200 alrm
->on
= !alrm
->on
;
201 /* set text in both rows */
202 gtk_list_store_set(GTK_LIST_STORE(model
), &iter
,
203 COL_STATUS
, alrm
->on
? "ON" : "OFF",
208 void remove_alarm(void) {
211 alrm
= get_alarm(NULL
, NULL
);
216 while (prev
&& (prev
->next
!= alrm
)) {
219 if (alrm
== alarms
) {
221 } else if (prev
!= NULL
) {
222 prev
->next
= alrm
->next
;
224 fprintf(stderr
, "Error when removing alarm...\n");