16 static GtkWidget
*wid_status
;
17 static GtkWidget
*wid_time
;
18 static GtkWidget
*wid_date
;
19 static GtkWidget
*wid_mesg
;
21 void set_data(GtkWidget
*widget UNUSED
, GtkWidget
*data UNUSED
) {
23 const char *wstat
= gtk_combo_box_text_get_active_text(GTK_COMBO_BOX_TEXT(wid_status
));
24 const char *wtime
= gtk_entry_get_text(GTK_ENTRY(wid_time
));
25 const char *wdate
= gtk_combo_box_text_get_active_text(GTK_COMBO_BOX_TEXT(wid_date
));
26 const char *wmesg
= gtk_entry_get_text(GTK_ENTRY(wid_mesg
));
28 int has_day
= (strcmp(wdate
, "ALL") != 0);
29 int has_msg
= (strcmp(wdate
, "") != 0);
30 int len
= strlen(wstat
) + 1 + strlen(wtime
) + 1;
32 len
+= has_day
? strlen(wdate
) + 1 : 0;
33 len
+= has_msg
? strlen(wmesg
) + 1 : 0;
34 newalarm
= xmalloc(len
);
36 sprintf(newalarm
, "%s@%s%s%s%s%s",
42 has_msg
? wmesg
: "");
47 static gboolean
set_active_date(GtkTreeModel
*model
, GtkTreePath
*path
,
48 GtkTreeIter
*iter
, gpointer user_data
)
50 const char *date1
= user_data
;
55 gtk_tree_model_get(model
, iter
, 0, (gpointer
) &date2
, -1);
56 if (strcmp(date1
, date2
) == 0) {
57 gtk_combo_box_set_active_iter(GTK_COMBO_BOX(wid_date
), iter
);
64 void edit_dialog(const char *title
,
78 dialog
= gtk_dialog_new();
79 gtk_window_set_title(GTK_WINDOW(dialog
), title
);
80 g_signal_connect(dialog
, "delete_event",
81 G_CALLBACK(gtk_widget_destroy
), NULL
);
82 g_signal_connect(dialog
, "destroy",
83 G_CALLBACK(gtk_widget_destroy
), NULL
);
85 bouton
= gtk_button_new_with_label("Ok");
86 g_signal_connect(bouton
, "clicked", G_CALLBACK(set_data
), NULL
);
87 g_signal_connect(bouton
, "clicked", G_CALLBACK(f_ok
), NULL
);
88 g_signal_connect_swapped(bouton
, "clicked",
89 G_CALLBACK(gtk_widget_destroy
), dialog
);
90 gtk_dialog_add_action_widget(GTK_DIALOG(dialog
), bouton
, GTK_RESPONSE_OK
);
91 gtk_widget_set_can_default(GTK_WIDGET(bouton
), TRUE
);
92 gtk_widget_grab_default(GTK_WIDGET(bouton
));
93 gtk_widget_show(bouton
);
95 bouton
= gtk_button_new_with_label("Cancel");
96 g_signal_connect_swapped(bouton
, "clicked",
97 G_CALLBACK(gtk_widget_destroy
), dialog
);
98 gtk_dialog_add_action_widget(GTK_DIALOG(dialog
), bouton
, GTK_RESPONSE_CANCEL
);
99 gtk_widget_set_can_default(GTK_WIDGET(bouton
), TRUE
);
100 gtk_widget_show(bouton
);
102 gtk_container_set_border_width(GTK_CONTAINER
103 (gtk_dialog_get_content_area(GTK_DIALOG(dialog
))), 6);
105 hbox
= gtk_box_new(GTK_ORIENTATION_HORIZONTAL
, 1);
106 gtk_container_add(GTK_CONTAINER(gtk_dialog_get_content_area(GTK_DIALOG(dialog
))), hbox
);
107 gtk_widget_show(hbox
);
110 vbox
= gtk_box_new(GTK_ORIENTATION_VERTICAL
, 1);
111 gtk_container_add(GTK_CONTAINER(hbox
), vbox
);
112 gtk_widget_show(vbox
);
114 label
= gtk_label_new("Status");
115 gtk_label_set_xalign(GTK_LABEL(label
), 0.0f
);
116 gtk_label_set_yalign(GTK_LABEL(label
), 0.5f
);
117 gtk_box_pack_start(GTK_BOX(vbox
), label
, FALSE
, FALSE
, 6);
118 gtk_widget_show(label
);
120 wid_status
= gtk_combo_box_text_new();
121 gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(wid_status
), "On");
122 gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(wid_status
), "Off");
123 gtk_box_pack_start(GTK_BOX(vbox
), wid_status
, FALSE
, TRUE
, 6);
124 gtk_widget_show(wid_status
);
125 gtk_combo_box_set_active(GTK_COMBO_BOX(wid_status
), on
? 0 : 1);
128 vbox
= gtk_box_new(GTK_ORIENTATION_VERTICAL
, 1);
129 gtk_container_add(GTK_CONTAINER(hbox
), vbox
);
130 gtk_widget_show(vbox
);
132 label
= gtk_label_new("Hour");
133 gtk_label_set_xalign(GTK_LABEL(label
), 0.0f
);
134 gtk_label_set_yalign(GTK_LABEL(label
), 0.5f
);
135 gtk_box_pack_start(GTK_BOX(vbox
), label
, FALSE
, FALSE
, 6);
136 gtk_widget_show(label
);
138 wid_time
= gtk_entry_new();
139 if (atime
) gtk_entry_set_text(GTK_ENTRY(wid_time
), atime
);
140 gtk_box_pack_start(GTK_BOX(vbox
), wid_time
, FALSE
, TRUE
, 6);
141 gtk_widget_show(wid_time
);
145 vbox
= gtk_box_new(GTK_ORIENTATION_VERTICAL
, 1);
146 gtk_container_add(GTK_CONTAINER(hbox
), vbox
);
147 gtk_widget_show(vbox
);
149 label
= gtk_label_new("Day");
150 gtk_label_set_xalign(GTK_LABEL(label
), 0.0f
);
151 gtk_label_set_yalign(GTK_LABEL(label
), 0.5f
);
152 gtk_box_pack_start(GTK_BOX(vbox
), label
, FALSE
, FALSE
, 6);
153 gtk_widget_show(label
);
155 wid_date
= gtk_combo_box_text_new();
156 gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(wid_date
), "ALL");
157 gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(wid_date
), "1");
158 gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(wid_date
), "2");
159 gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(wid_date
), "3");
160 gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(wid_date
), "4");
161 gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(wid_date
), "5");
162 gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(wid_date
), "6");
163 gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(wid_date
), "7");
164 gtk_box_pack_start(GTK_BOX(vbox
), wid_date
, FALSE
, TRUE
, 6);
165 gtk_widget_show(wid_date
);
166 gtk_combo_box_set_active(GTK_COMBO_BOX(wid_date
), 0);
168 gtk_tree_model_foreach(gtk_combo_box_get_model(GTK_COMBO_BOX(wid_date
)),
169 set_active_date
, (void *) adate
);
172 vbox
= gtk_box_new(GTK_ORIENTATION_VERTICAL
, 1);
173 gtk_container_add(GTK_CONTAINER(gtk_dialog_get_content_area(GTK_DIALOG(dialog
))), vbox
);
174 gtk_widget_show(vbox
);
176 label
= gtk_label_new("Message");
177 gtk_label_set_xalign(GTK_LABEL(label
), 0.0f
);
178 gtk_label_set_yalign(GTK_LABEL(label
), 0.5f
);
179 gtk_box_pack_start(GTK_BOX(vbox
), label
, FALSE
, FALSE
, 6);
180 gtk_widget_show(label
);
182 wid_mesg
= gtk_entry_new();
183 if (amesg
) gtk_entry_set_text(GTK_ENTRY(wid_mesg
), amesg
);
184 gtk_box_pack_start(GTK_BOX(vbox
), wid_mesg
, FALSE
, TRUE
, 6);
185 gtk_widget_show(wid_mesg
);
189 gtk_window_set_modal(GTK_WINDOW(dialog
), TRUE
);
190 gtk_widget_show(dialog
);