wmclockmon: import version 0.8.1
[dockapps.git] / wmclockmon / wmclockmon-config / edit.c
blobf9800c1502ca6ea778b324b62aa96d99986bf5f2
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 static GtkWidget *wid_status;
15 static GtkWidget *wid_time;
16 static GtkWidget *wid_date;
17 static GtkWidget *wid_mesg;
19 void set_data(GtkWidget *widget, GtkWidget *data) {
20 char *wstat = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(wid_status)->entry));
21 char *wtime = gtk_entry_get_text(GTK_ENTRY(wid_time));
22 char *wdate = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(wid_date)->entry));
23 char *wmesg = gtk_entry_get_text(GTK_ENTRY(wid_mesg));
24 int has_day = (strcmp(wdate, "ALL") != 0);
25 int has_msg = (strcmp(wdate, "") != 0);
26 int len = strlen(wstat) + 1 + strlen(wtime) + 1;
28 len += has_day ? strlen(wdate) + 1 : 0;
29 len += has_msg ? strlen(wmesg) + 1 : 0;
30 newalarm = xmalloc(len);
32 sprintf(newalarm, "%s@%s%s%s%s%s",
33 wstat,
34 wtime,
35 has_day ? "-" : "",
36 has_day ? wdate : "",
37 has_msg ? "." : "",
38 has_msg ? wmesg : "");
42 void edit_dialog(const char *title,
43 int on,
44 const char *atime,
45 const char *adate,
46 const char *amesg,
47 void *f_ok) {
48 GtkWidget *dialog;
49 GtkWidget *bouton;
50 GtkWidget *label;
51 GtkWidget *hbox;
52 GtkWidget *vbox;
53 GList *items = NULL;
55 FREE(newalarm);
56 dialog = gtk_dialog_new();
57 gtk_window_set_title(GTK_WINDOW(dialog), title);
58 gtk_signal_connect(GTK_OBJECT(dialog), "delete_event",
59 GTK_SIGNAL_FUNC(gtk_widget_destroy),
60 NULL);
61 gtk_signal_connect(GTK_OBJECT(dialog), "destroy",
62 GTK_SIGNAL_FUNC(gtk_widget_destroy),
63 NULL);
65 bouton = gtk_button_new_with_label("Ok");
66 gtk_signal_connect(GTK_OBJECT(bouton), "clicked",
67 GTK_SIGNAL_FUNC(set_data),
68 NULL);
69 gtk_signal_connect(GTK_OBJECT(bouton), "clicked",
70 GTK_SIGNAL_FUNC(f_ok),
71 NULL);
72 gtk_signal_connect_object(GTK_OBJECT(bouton), "clicked",
73 GTK_SIGNAL_FUNC(gtk_widget_destroy),
74 GTK_OBJECT(dialog));
75 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->action_area),
76 bouton, TRUE, TRUE, 0);
77 GTK_WIDGET_SET_FLAGS(GTK_WIDGET(bouton), GTK_CAN_DEFAULT);
78 gtk_widget_grab_default(GTK_WIDGET(bouton));
79 gtk_widget_draw_default(GTK_WIDGET(bouton));
80 gtk_widget_show(bouton);
82 bouton = gtk_button_new_with_label("Cancel");
83 gtk_signal_connect_object(GTK_OBJECT(bouton), "clicked",
84 GTK_SIGNAL_FUNC(gtk_widget_destroy),
85 GTK_OBJECT(dialog));
86 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->action_area),
87 bouton, TRUE, TRUE, 0);
88 GTK_WIDGET_SET_FLAGS(GTK_WIDGET(bouton), GTK_CAN_DEFAULT);
89 gtk_widget_show(bouton);
91 gtk_container_set_border_width(GTK_CONTAINER
92 (GTK_DIALOG(dialog)->vbox), 6);
94 hbox = gtk_hbox_new(FALSE, 1);
95 gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog)->vbox), hbox);
96 gtk_widget_show(hbox);
98 /* STATUS */
99 vbox = gtk_vbox_new(FALSE, 1);
100 gtk_container_add(GTK_CONTAINER(hbox), vbox);
101 gtk_widget_show(vbox);
103 label = gtk_label_new("Status");
104 gtk_misc_set_alignment(GTK_MISC(label), 0.0f, 0.5f);
105 gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 6);
106 gtk_widget_show(label);
108 items = g_list_append(items, "On");
109 items = g_list_append(items, "Off");
110 wid_status = gtk_combo_new();
111 gtk_combo_set_popdown_strings(GTK_COMBO(wid_status), items);
112 gtk_combo_set_value_in_list(GTK_COMBO(wid_status), TRUE, FALSE);
113 gtk_entry_set_editable(GTK_ENTRY(GTK_COMBO(wid_status)->entry), FALSE);
114 gtk_box_pack_start(GTK_BOX(vbox), wid_status, FALSE, TRUE, 6);
115 gtk_widget_show(wid_status);
116 if (on)
117 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(wid_status)->entry), "On");
118 else
119 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(wid_status)->entry), "Off");
122 /* HOUR */
123 vbox = gtk_vbox_new(FALSE, 1);
124 gtk_container_add(GTK_CONTAINER(hbox), vbox);
125 gtk_widget_show(vbox);
127 label = gtk_label_new("Hour");
128 gtk_misc_set_alignment(GTK_MISC(label), 0.0f, 0.5f);
129 gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 6);
130 gtk_widget_show(label);
132 wid_time = gtk_entry_new();
133 if (atime) gtk_entry_set_text(GTK_ENTRY(wid_time), atime);
134 gtk_box_pack_start(GTK_BOX(vbox), wid_time, FALSE, TRUE, 6);
135 gtk_widget_show(wid_time);
138 /* DAY */
139 vbox = gtk_vbox_new(FALSE, 1);
140 gtk_container_add(GTK_CONTAINER(hbox), vbox);
141 gtk_widget_show(vbox);
143 label = gtk_label_new("Day");
144 gtk_misc_set_alignment(GTK_MISC(label), 0.0f, 0.5f);
145 gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 6);
146 gtk_widget_show(label);
148 items = NULL;
149 items = g_list_append(items, "ALL");
150 items = g_list_append(items, "1");
151 items = g_list_append(items, "2");
152 items = g_list_append(items, "3");
153 items = g_list_append(items, "4");
154 items = g_list_append(items, "5");
155 items = g_list_append(items, "6");
156 items = g_list_append(items, "7");
157 wid_date = gtk_combo_new();
158 gtk_combo_set_popdown_strings(GTK_COMBO(wid_date), items);
159 gtk_combo_set_value_in_list(GTK_COMBO(wid_date), TRUE, TRUE);
160 gtk_entry_set_editable(GTK_ENTRY(GTK_COMBO(wid_date)->entry), FALSE);
161 gtk_box_pack_start(GTK_BOX(vbox), wid_date, FALSE, TRUE, 6);
162 gtk_widget_show(wid_date);
163 if (adate)
164 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(wid_date)->entry), adate);
167 /* MESSAGE */
168 vbox = gtk_vbox_new(FALSE, 1);
169 gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog)->vbox), vbox);
170 gtk_widget_show(vbox);
172 label = gtk_label_new("Message");
173 gtk_misc_set_alignment(GTK_MISC(label), 0.0f, 0.5f);
174 gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 6);
175 gtk_widget_show(label);
177 wid_mesg = gtk_entry_new();
178 if (amesg) gtk_entry_set_text(GTK_ENTRY(wid_mesg), amesg);
179 gtk_box_pack_start(GTK_BOX(vbox), wid_mesg, FALSE, TRUE, 6);
180 gtk_widget_show(wid_mesg);
184 gtk_window_set_modal(GTK_WINDOW(dialog), TRUE);
185 gtk_widget_show(dialog);