4 * (c) 2002 Martin Mares <mj@ucw.cz>
15 #define UNUSED __attribute__((unused))
17 static guint second_timer;
18 static unsigned char old_text[8];
19 static GtkWidget *win, *hbox1, *timebox, *togglebutton1;
20 static time_t alarm_time;
23 it_tolls_for_thee(void)
29 on_second_timeout(gpointer data UNUSED)
32 time_t now = time(NULL);
33 int delta = alarm_time - now;
43 sprintf(buf, "%s%02d:%02d", sign, delta/60, delta%60);
44 gtk_entry_set_text(GTK_ENTRY(timebox), buf);
45 if (now >= alarm_time)
51 on_timebox_key(GtkWidget *widget UNUSED, GdkEventKey *ev, gpointer user_data UNUSED)
53 if (!strcmp(ev->string, "\r"))
54 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(togglebutton1), !GTK_TOGGLE_BUTTON(togglebutton1)->active);
55 else if (!strcmp(ev->string, "\033"))
65 while (*c && *c != ':')
67 if (*c >= '0' && *c <= '9')
68 t = 10*t + *c++ - '0';
78 if (*c >= '0' && *c <= '9')
79 m = 10*m + *c++ - '0';
91 on_togglebutton1_toggled(GtkToggleButton *togglebutton, gpointer user_data UNUSED)
93 if (togglebutton->active)
96 strcpy(old_text, gtk_entry_get_text(GTK_ENTRY(timebox)));
97 t = parse_time(old_text);
100 gtk_toggle_button_set_active(togglebutton, 0);
103 alarm_time = time(NULL) + t;
104 gtk_entry_set_editable(GTK_ENTRY(timebox), 0);
105 on_second_timeout(NULL);
106 second_timer = gtk_timeout_add(1000, on_second_timeout, NULL);
112 gtk_timeout_remove(second_timer);
115 gtk_entry_set_text(GTK_ENTRY(timebox), old_text);
116 gtk_entry_set_editable(GTK_ENTRY(timebox), 1);
117 gtk_widget_grab_focus (timebox);
122 on_window_remove(GtkContainer *container UNUSED, GtkWidget *widget UNUSED, gpointer user_data UNUSED)
130 win = gtk_window_new (GTK_WINDOW_TOPLEVEL);
131 gtk_window_set_title (GTK_WINDOW (win), "Tea Timer");
132 gtk_window_set_policy (GTK_WINDOW (win), TRUE, TRUE, TRUE);
134 hbox1 = gtk_hbox_new (FALSE, 0);
135 gtk_widget_show (hbox1);
136 gtk_container_add (GTK_CONTAINER (win), hbox1);
138 timebox = gtk_entry_new_with_max_length (6);
139 gtk_widget_show (timebox);
140 gtk_box_pack_start (GTK_BOX (hbox1), timebox, TRUE, TRUE, 0);
141 gtk_entry_set_text (GTK_ENTRY (timebox), "00:00");
143 togglebutton1 = gtk_toggle_button_new_with_label ("Run");
144 gtk_widget_show (togglebutton1);
145 gtk_box_pack_start (GTK_BOX (hbox1), togglebutton1, FALSE, FALSE, 0);
147 gtk_signal_connect(GTK_OBJECT (win), "remove", GTK_SIGNAL_FUNC (on_window_remove), NULL);
148 gtk_signal_connect(GTK_OBJECT (timebox), "key_press_event", GTK_SIGNAL_FUNC (on_timebox_key), NULL);
149 gtk_signal_connect(GTK_OBJECT (togglebutton1), "toggled", GTK_SIGNAL_FUNC (on_togglebutton1_toggled), NULL);
151 gtk_widget_grab_focus (timebox);
153 gtk_widget_show(win);
157 main(int argc, char **argv)
160 gtk_init(&argc, &argv);
164 gtk_entry_set_text(GTK_ENTRY(timebox), argv[1]);
165 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(togglebutton1), 1);