Check that a given filename is valid before setting it on a GtkFileChooserButton
[anjuta-git-plugin.git] / plugins / gtodo / notification.c
blob91a19f2cd2f739e463cb89c5e68745cc88018cb0
1 #include <gtk/gtk.h>
2 #include <gconf/gconf.h>
3 #include <gconf/gconf-client.h>
4 #include "main.h"
6 void create_notification_window(GTodoItem *item);
7 void notification_window_cancel(GtkWidget *but_cancel);
8 void notification_window_remove_notification(GtkWidget *but_cancel, gpointer data);
9 void notification_window_set_notification(GtkWidget *check_but, gpointer data);
10 GArray *table;
12 typedef struct
14 GtkWidget *dialog;
15 gint id;
16 } not_window;
18 int check_for_notification_event(void)
20 GTodoList *list = NULL;
21 int min_b_not = gconf_client_get_int(client, "/apps/gtodo/prefs/notify_in_minutes",NULL);
22 if(!gconf_client_get_bool(client, "/apps/gtodo/prefs/do_notification",NULL)) return TRUE;
23 list = gtodo_client_get_todo_item_list(cl, NULL);
24 if(list == NULL) return TRUE;
25 do{
26 GTodoItem *item = gtodo_client_get_todo_item_from_list(list);
27 if(!gtodo_todo_item_get_done(item) && gtodo_todo_item_get_notify(item))
29 if((gtodo_todo_item_check_due(item) == 0 && gtodo_todo_item_check_due_time_minutes_left(item) <= min_b_not)
30 || (gtodo_todo_item_check_due(item) > 0 && gtodo_todo_item_get_due_date_as_julian(item) != GTODO_NO_DUE_DATE))
32 create_notification_window(item);
35 }while(gtodo_client_get_list_next(list));
36 gtodo_client_free_todo_item_list(cl, list);
37 return TRUE;
42 void create_notification_window(GTodoItem *item)
44 GtkWidget *dialog, *but_cancel, *image, *ck_but;
45 GtkWidget *hbox, *label, *vbox;
46 gchar *buffer, *tempstr;
47 if(table == NULL) table = g_array_new(TRUE, TRUE, sizeof(GtkWidget *));
48 else{
49 not_window *test=NULL;
50 int i=0;
53 test = g_array_index(table, not_window *, i);
54 if(test == NULL) break;
55 if(test->id == gtodo_todo_item_get_id(item))
57 gtk_window_present(GTK_WINDOW(test->dialog));
58 return;
60 i++;
61 }while(test != NULL);
63 if(gtodo_todo_item_check_due(item) == 0 && gtodo_todo_item_check_due_time_minutes_left(item) > 0 )
65 int minutes = gtodo_todo_item_check_due_time_minutes_left(item);
66 tempstr = g_strdup_printf("<span weight=\"bold\" size=\"larger\">%s</span>\n\"%s\"",
67 ngettext("The following item is due in %i minute:",
68 "The following item is due in %i minutes:", minutes),
69 gtodo_todo_item_get_summary(item));
70 buffer = g_strdup_printf(tempstr, minutes);
71 g_free(tempstr);
73 else
75 buffer = g_strdup_printf("<span weight=\"bold\" size=\"larger\">%s</span>\n\"%s\"",
76 _("The following item is due:"),
77 gtodo_todo_item_get_summary(item));
79 /* create image and more stuff in dialog */
80 dialog = gtk_dialog_new();
81 gtk_container_set_border_width(GTK_CONTAINER(GTK_DIALOG(dialog)), 6);
82 gtk_container_set_border_width(GTK_CONTAINER(GTK_DIALOG(dialog)->vbox), 12);
83 /* hig stuff */
84 gtk_dialog_set_has_separator(GTK_DIALOG(dialog), FALSE);
85 gtk_window_set_transient_for(GTK_WINDOW(dialog), GTK_WINDOW(mw.window));
86 gtk_window_set_type_hint(GTK_WINDOW(dialog), GDK_WINDOW_TYPE_HINT_DIALOG);
87 gtk_window_set_position(GTK_WINDOW(dialog), GTK_WIN_POS_CENTER_ALWAYS);
88 gtk_window_set_modal(GTK_WINDOW(dialog), TRUE);
89 gtk_window_set_title(GTK_WINDOW(dialog),"Warning");
90 gtk_window_set_resizable(GTK_WINDOW(dialog), FALSE);
91 gtk_window_set_skip_taskbar_hint(GTK_WINDOW(dialog), TRUE);
93 hbox = gtk_hbox_new(FALSE,6);
94 gtk_container_set_border_width(GTK_CONTAINER(hbox), 12);
95 vbox= gtk_vbox_new(FALSE, 0);
97 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox), hbox, TRUE, TRUE,0);
98 /* Add the image */
99 image = gtk_image_new_from_stock(GTK_STOCK_DIALOG_INFO, GTK_ICON_SIZE_DIALOG);
100 label = gtk_alignment_new(0.5, 0,0,0);
101 gtk_container_add(GTK_CONTAINER(label), image);
103 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, TRUE,0);
104 /* add an vbox*/
105 gtk_box_pack_start(GTK_BOX(hbox), vbox, TRUE, TRUE,12);
108 label = gtk_label_new("");
109 gtk_label_set_markup(GTK_LABEL(label), buffer);
110 gtk_label_set_line_wrap(GTK_LABEL(label), TRUE);
111 image = gtk_alignment_new(0.5,0,0,0);
112 gtk_container_add(GTK_CONTAINER(image), label);
113 gtk_box_pack_start(GTK_BOX(vbox), image, TRUE, TRUE,0);
114 /* gtk_container_set_border_width(GTK_CONTAINER(hbox), 9);*/
116 ck_but = gtk_check_button_new_with_mnemonic(_("_Do not show again"));
117 label = gtk_alignment_new(1, 1,0,0);
118 gtk_container_add(GTK_CONTAINER(label), ck_but);
119 gtk_box_pack_end(GTK_BOX(vbox), label, FALSE, FALSE,12);
121 g_signal_connect(G_OBJECT(ck_but), "toggled", G_CALLBACK(notification_window_set_notification), GINT_TO_POINTER(gtodo_todo_item_get_id(item)));
123 but_cancel = gtk_dialog_add_button(GTK_DIALOG(dialog), GTK_STOCK_OPEN, GTK_RESPONSE_CANCEL);
125 g_signal_connect(G_OBJECT(but_cancel), "clicked", G_CALLBACK(notification_window_remove_notification),GINT_TO_POINTER(gtodo_todo_item_get_id(item)));
127 but_cancel = gtk_dialog_add_button(GTK_DIALOG(dialog),GTK_STOCK_CLOSE, GTK_RESPONSE_CANCEL);
128 g_signal_connect(G_OBJECT(but_cancel), "clicked", G_CALLBACK(notification_window_cancel), NULL);
130 /* set window signal */
131 g_signal_connect(G_OBJECT(dialog), "destroy", G_CALLBACK(notification_window_cancel), NULL);
133 g_free(buffer);
134 gtk_widget_show_all(dialog);
136 not_window *nw = g_malloc(sizeof(not_window));
137 nw->dialog = dialog;
138 nw->id = gtodo_todo_item_get_id(item);
139 g_array_append_vals(table, &nw, 1);
143 /* destroy the notification window */
144 void notification_window_cancel(GtkWidget *but_cancel)
146 GtkWidget *dialog = gtk_widget_get_toplevel(but_cancel);
147 not_window *test = NULL;
148 int i=0;
151 test = g_array_index(table, not_window *, i);
152 if(test == NULL) break;
153 if(test->dialog == dialog)
155 g_free(test);
156 g_array_remove_index(table, i);
158 i++;
159 }while(test != NULL);
161 gtk_widget_destroy(dialog);
164 void notification_window_remove_notification(GtkWidget *but_cancel, gpointer data)
166 gint id = GPOINTER_TO_INT(data);
167 notification_window_cancel(but_cancel);
168 gui_add_todo_item(NULL, GINT_TO_POINTER(1), id);
171 void notification_window_set_notification(GtkWidget *check_but, gpointer data)
173 gint id = GPOINTER_TO_INT(data);
174 GTodoItem *item = gtodo_client_get_todo_item_from_id(cl, id);
175 if(item != NULL)
177 gtodo_todo_item_set_notify(item, !gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(check_but)));
178 gtodo_client_edit_todo_item(cl, item);