Add missing libraries to examples' Makefiles
[dockapps.git] / wmclockmon / wmclockmon-config / edit.c
blob5e5e4ff08c49c7ebae6456345b86b438262f3fd0
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) {
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",
37 wstat,
38 wtime,
39 has_day ? "-" : "",
40 has_day ? wdate : "",
41 has_msg ? "." : "",
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;
51 const char *date2;
53 (void) path;
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);
58 return TRUE;
61 return FALSE;
64 void edit_dialog(const char *title,
65 int on,
66 const char *atime,
67 const char *adate,
68 const char *amesg,
69 void (*f_ok)(void)) {
71 GtkWidget *dialog;
72 GtkWidget *bouton;
73 GtkWidget *label;
74 GtkWidget *hbox;
75 GtkWidget *vbox;
77 FREE(newalarm);
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);
109 /* STATUS */
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);
127 /* HOUR */
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);
144 /* DAY */
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);
167 if (adate)
168 gtk_tree_model_foreach(gtk_combo_box_get_model(GTK_COMBO_BOX(wid_date)),
169 set_active_date, (void *) adate);
171 /* MESSAGE */
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);