wmclockmon: add missing `const` qualifiers
[dockapps.git] / wmclockmon / wmclockmon-config / edit.c
blobf52be54c9b692de3c79ed2db64097a4036cedbb7
1 /*
2 * edit.c
3 */
5 #include <gtk/gtk.h>
6 #include <stdio.h>
7 #include <stdlib.h>
8 #include <string.h>
9 #include <strings.h>
10 #include "defines.h"
11 #include "tools.h"
12 #include "edit.h"
14 char *newalarm;
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) {
22 const char *wstat = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(wid_status)->entry));
23 const char *wtime = gtk_entry_get_text(GTK_ENTRY(wid_time));
24 const char *wdate = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(wid_date)->entry));
25 const char *wmesg = gtk_entry_get_text(GTK_ENTRY(wid_mesg));
26 int has_day = (strcmp(wdate, "ALL") != 0);
27 int has_msg = (strcmp(wdate, "") != 0);
28 int len = strlen(wstat) + 1 + strlen(wtime) + 1;
30 len += has_day ? strlen(wdate) + 1 : 0;
31 len += has_msg ? strlen(wmesg) + 1 : 0;
32 newalarm = xmalloc(len);
34 sprintf(newalarm, "%s@%s%s%s%s%s",
35 wstat,
36 wtime,
37 has_day ? "-" : "",
38 has_day ? wdate : "",
39 has_msg ? "." : "",
40 has_msg ? wmesg : "");
44 void edit_dialog(const char *title,
45 int on,
46 const char *atime,
47 const char *adate,
48 const char *amesg,
49 void (*f_ok)(GtkWidget *, void *)) {
51 GtkWidget *dialog;
52 GtkWidget *bouton;
53 GtkWidget *label;
54 GtkWidget *hbox;
55 GtkWidget *vbox;
56 GList *items = NULL;
58 FREE(newalarm);
59 dialog = gtk_dialog_new();
60 gtk_window_set_title(GTK_WINDOW(dialog), title);
61 gtk_signal_connect(GTK_OBJECT(dialog), "delete_event",
62 GTK_SIGNAL_FUNC(gtk_widget_destroy),
63 NULL);
64 gtk_signal_connect(GTK_OBJECT(dialog), "destroy",
65 GTK_SIGNAL_FUNC(gtk_widget_destroy),
66 NULL);
68 bouton = gtk_button_new_with_label("Ok");
69 gtk_signal_connect(GTK_OBJECT(bouton), "clicked",
70 GTK_SIGNAL_FUNC(set_data),
71 NULL);
72 gtk_signal_connect(GTK_OBJECT(bouton), "clicked",
73 GTK_SIGNAL_FUNC(f_ok),
74 NULL);
75 gtk_signal_connect_object(GTK_OBJECT(bouton), "clicked",
76 GTK_SIGNAL_FUNC(gtk_widget_destroy),
77 GTK_OBJECT(dialog));
78 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->action_area),
79 bouton, TRUE, TRUE, 0);
80 GTK_WIDGET_SET_FLAGS(GTK_WIDGET(bouton), GTK_CAN_DEFAULT);
81 gtk_widget_grab_default(GTK_WIDGET(bouton));
82 gtk_widget_show(bouton);
84 bouton = gtk_button_new_with_label("Cancel");
85 gtk_signal_connect_object(GTK_OBJECT(bouton), "clicked",
86 GTK_SIGNAL_FUNC(gtk_widget_destroy),
87 GTK_OBJECT(dialog));
88 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->action_area),
89 bouton, TRUE, TRUE, 0);
90 GTK_WIDGET_SET_FLAGS(GTK_WIDGET(bouton), GTK_CAN_DEFAULT);
91 gtk_widget_show(bouton);
93 gtk_container_set_border_width(GTK_CONTAINER
94 (GTK_DIALOG(dialog)->vbox), 6);
96 hbox = gtk_hbox_new(FALSE, 1);
97 gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog)->vbox), hbox);
98 gtk_widget_show(hbox);
100 /* STATUS */
101 vbox = gtk_vbox_new(FALSE, 1);
102 gtk_container_add(GTK_CONTAINER(hbox), vbox);
103 gtk_widget_show(vbox);
105 label = gtk_label_new("Status");
106 gtk_misc_set_alignment(GTK_MISC(label), 0.0f, 0.5f);
107 gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 6);
108 gtk_widget_show(label);
110 items = g_list_append(items, "On");
111 items = g_list_append(items, "Off");
112 wid_status = gtk_combo_new();
113 gtk_combo_set_popdown_strings(GTK_COMBO(wid_status), items);
114 gtk_combo_set_value_in_list(GTK_COMBO(wid_status), TRUE, FALSE);
115 gtk_entry_set_editable(GTK_ENTRY(GTK_COMBO(wid_status)->entry), FALSE);
116 gtk_box_pack_start(GTK_BOX(vbox), wid_status, FALSE, TRUE, 6);
117 gtk_widget_show(wid_status);
118 if (on)
119 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(wid_status)->entry), "On");
120 else
121 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(wid_status)->entry), "Off");
124 /* HOUR */
125 vbox = gtk_vbox_new(FALSE, 1);
126 gtk_container_add(GTK_CONTAINER(hbox), vbox);
127 gtk_widget_show(vbox);
129 label = gtk_label_new("Hour");
130 gtk_misc_set_alignment(GTK_MISC(label), 0.0f, 0.5f);
131 gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 6);
132 gtk_widget_show(label);
134 wid_time = gtk_entry_new();
135 if (atime) gtk_entry_set_text(GTK_ENTRY(wid_time), atime);
136 gtk_box_pack_start(GTK_BOX(vbox), wid_time, FALSE, TRUE, 6);
137 gtk_widget_show(wid_time);
140 /* DAY */
141 vbox = gtk_vbox_new(FALSE, 1);
142 gtk_container_add(GTK_CONTAINER(hbox), vbox);
143 gtk_widget_show(vbox);
145 label = gtk_label_new("Day");
146 gtk_misc_set_alignment(GTK_MISC(label), 0.0f, 0.5f);
147 gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 6);
148 gtk_widget_show(label);
150 items = NULL;
151 items = g_list_append(items, "ALL");
152 items = g_list_append(items, "1");
153 items = g_list_append(items, "2");
154 items = g_list_append(items, "3");
155 items = g_list_append(items, "4");
156 items = g_list_append(items, "5");
157 items = g_list_append(items, "6");
158 items = g_list_append(items, "7");
159 wid_date = gtk_combo_new();
160 gtk_combo_set_popdown_strings(GTK_COMBO(wid_date), items);
161 gtk_combo_set_value_in_list(GTK_COMBO(wid_date), TRUE, TRUE);
162 gtk_entry_set_editable(GTK_ENTRY(GTK_COMBO(wid_date)->entry), FALSE);
163 gtk_box_pack_start(GTK_BOX(vbox), wid_date, FALSE, TRUE, 6);
164 gtk_widget_show(wid_date);
165 if (adate)
166 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(wid_date)->entry), adate);
169 /* MESSAGE */
170 vbox = gtk_vbox_new(FALSE, 1);
171 gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog)->vbox), vbox);
172 gtk_widget_show(vbox);
174 label = gtk_label_new("Message");
175 gtk_misc_set_alignment(GTK_MISC(label), 0.0f, 0.5f);
176 gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 6);
177 gtk_widget_show(label);
179 wid_mesg = gtk_entry_new();
180 if (amesg) gtk_entry_set_text(GTK_ENTRY(wid_mesg), amesg);
181 gtk_box_pack_start(GTK_BOX(vbox), wid_mesg, FALSE, TRUE, 6);
182 gtk_widget_show(wid_mesg);
186 gtk_window_set_modal(GTK_WINDOW(dialog), TRUE);
187 gtk_widget_show(dialog);