Updated Spanish translation
[anjuta-git-plugin.git] / plugins / gtodo / callback.c
blob6a6e58bc0e5a31ddf18d0977f122471c844199b4
1 #include <gtk/gtk.h>
2 #include "main.h"
4 void remove_todo_item(GtkWidget *fake, gboolean internall){
5 GtkTreeSelection *selection;
6 GtkTreeIter iter;
7 GtkTreeModel *model = mw.sortmodel;
8 gint value;
10 /* testing blocking the file changed */
11 /* it seems to work.. so I keep it here */
12 gtodo_client_block_changed_callback(cl);
14 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(mw.treeview));
15 if(!gtk_tree_selection_get_selected(selection, &model, &iter))
17 if(!internall)message_box( _("You need to select a todo item before you can remove it"),"",GTK_MESSAGE_INFO);
18 return;
20 if(!internall) if(!message_box( _("Are you sure you want to remove the selected todo item?"), _("Remove"), GTK_MESSAGE_WARNING))
22 return;
25 gtk_tree_model_get(model,&iter, ID, &value, -1);
27 gtodo_client_delete_todo_by_id(cl,value);
28 gtk_list_store_clear(mw.list);
29 load_category();
31 /* end test */
32 gtodo_client_unblock_changed_callback(cl);
35 /* this is the function called if the user switches to another category.. */
36 /* can't hurt to change the name here. */
38 void category_changed(void)
40 if(cl != NULL)
42 int i = gtk_option_menu_get_history(GTK_OPTION_MENU(mw.option));
43 if(i != 0)if( mw.mitems == NULL || mw.mitems[i-2] == NULL) return;
44 if(i == categorys+3)
46 int j = gconf_client_get_int(client, "/apps/gtodo/view/last-category",NULL);
47 category_manager();
48 if(j < categorys+3 && mw.mitems != NULL && mw.mitems[j-2] != NULL) gtk_option_menu_set_history(GTK_OPTION_MENU(mw.option),j);
49 gtk_list_store_clear(mw.list);
50 load_category();
51 return;
53 gtk_list_store_clear(mw.list);
54 load_category();
55 gconf_client_set_int(client, "/apps/gtodo/view/last-category",i,NULL);
60 void list_toggled_done(GtkCellRendererToggle *cell, gchar *path_str)
62 GtkTreeIter iter, childiter;
63 GtkTreeModel *model = mw.sortmodel;
64 gint done, id;
65 GTodoItem *item = NULL;
66 GtkTreePath *path = gtk_tree_path_new_from_string (path_str);
67 if(gtodo_client_get_read_only(cl))
69 gtk_tree_path_free(path);
70 return;
72 /* get toggled iter */
73 gtk_tree_model_get_iter (model, &iter, path);
74 gtk_tree_model_sort_convert_iter_to_child_iter(GTK_TREE_MODEL_SORT(mw.sortmodel), &childiter, &iter);
75 gtk_tree_path_free(path);
76 gtk_tree_model_get(model, &iter,ID, &id,DONE, &done, -1);
77 gtk_list_store_set(mw.list, &childiter,DONE, !done, -1);
78 item = gtodo_client_get_todo_item_from_id(cl, id);
79 if(item == NULL) return;
80 if(done== 0)gtodo_todo_item_set_done(item, TRUE);
81 if(done == 1) gtodo_todo_item_set_done(item,FALSE);
82 /* block the callback and reset the changed dbase, because I don't want to refresh tree view */
83 gtodo_client_block_changed_callback(cl);
84 gtodo_client_edit_todo_item(cl, item);
85 gtodo_client_reset_changed_callback(cl);
86 gtodo_client_unblock_changed_callback(cl);
89 void purge_category(void)
91 gint done, value;
92 GtkTreeIter iter;
93 GtkTreeModel *model = mw.sortmodel;
94 gchar *category;
95 gchar *tm;
97 if(gtk_option_menu_get_history(GTK_OPTION_MENU(mw.option))== 0)tm = g_strdup_printf(_("Are you sure you want to remove all the completed todo items?"));
98 else tm = g_strdup_printf(_("Are you sure you want to remove all the completed todo items in the category \"%s\"?"), mw.mitems[gtk_option_menu_get_history(GTK_OPTION_MENU(mw.option))-2]->date);
100 if(!message_box( tm, _("Remove"), GTK_MESSAGE_WARNING))
102 g_free(tm);
103 return;
105 g_free(tm);
106 gtodo_client_block_changed_callback(cl);
107 if(gtk_tree_model_get_iter_first(model, &iter))
110 gtk_tree_model_get(model,&iter,DONE, &done, ID, &value,CATEGORY, &category, -1);
111 if(done)
113 gtodo_client_delete_todo_by_id(cl, value);
115 g_free(category);
116 }while(gtk_tree_model_iter_next(model, &iter));
118 gtodo_client_unblock_changed_callback(cl);
119 gtk_list_store_clear(mw.list);
120 load_category();
124 int message_box(gchar *text, gchar *buttext, GtkMessageType type)
126 GtkWidget *dialog;
127 dialog = gtk_message_dialog_new(GTK_WINDOW(mw.window),
128 GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
129 type,
130 GTK_BUTTONS_NONE,
131 text
133 if(type == GTK_MESSAGE_WARNING)
135 gtk_dialog_add_buttons(GTK_DIALOG(dialog),GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, buttext, GTK_RESPONSE_OK, NULL);
137 else gtk_dialog_add_buttons(GTK_DIALOG(dialog),GTK_STOCK_OK, GTK_RESPONSE_OK, NULL);
138 gtk_widget_show_all(dialog);
139 switch(gtk_dialog_run(GTK_DIALOG(dialog)))
141 case GTK_RESPONSE_CLOSE:
142 case GTK_RESPONSE_OK:
143 case GTK_RESPONSE_YES:
144 gtk_widget_destroy(dialog);
145 return 1;
146 default:
147 gtk_widget_destroy(dialog);
148 return 0;
150 return 0;
154 /* the custom sorthing function.. I think I have all sort possiblilties here.. */
156 gint sort_function_test(GtkTreeModel *model,GtkTreeIter *a,GtkTreeIter *b,gpointer user_data)
158 gint prioritya=0, priorityb=0;
159 gint donea=0, doneb=0;
160 guint64 datea=0, dateb=0;
161 if(a == NULL || b == NULL) return 0;
163 gtk_tree_model_get(model,a, DONE, &donea,PRIORITY,&prioritya,END_DATE, &datea, -1);
164 gtk_tree_model_get(model,b, DONE, &doneb,PRIORITY,&priorityb,END_DATE, &dateb, -1);
166 if(settings.sorttype == 0)
168 /* done, date, priority */
170 if((donea - doneb)!= 0) return doneb-donea;
171 if(dateb == GTODO_NO_DUE_DATE && datea != GTODO_NO_DUE_DATE) return 1;
172 if(datea == GTODO_NO_DUE_DATE && dateb != GTODO_NO_DUE_DATE) return -1;
173 if((datea - dateb) != 0)return dateb - datea;
174 if((prioritya - priorityb) != 0) return prioritya -priorityb;
176 else if(settings.sorttype == 1)
178 /* done, priority, date */
179 if((donea - doneb)!= 0) return doneb-donea;
180 if((prioritya - priorityb) != 0) return prioritya -priorityb;
181 if((datea - dateb) != 0)return dateb - datea;
183 else if(settings.sorttype == 2)
185 /* priority,date, done */
186 if((prioritya - priorityb) != 0) return prioritya -priorityb;
187 if((datea - dateb) != 0)return dateb - datea;
188 if((donea - doneb)!= 0) return doneb-donea;
190 else if(settings.sorttype == 3)
192 /* priority,done, date */
193 if((prioritya - priorityb) != 0) return prioritya -priorityb;
194 if((donea - doneb)!= 0) return doneb-donea;
195 if((datea - dateb) != 0)return dateb - datea;
197 else if(settings.sorttype == 4)
199 /* date, priority, done */
200 if((datea - dateb) != 0)return dateb - datea;
201 if((prioritya - priorityb) != 0) return prioritya -priorityb;
202 if((donea - doneb)!= 0) return doneb-donea;
204 else if(settings.sorttype == 5)
206 /* date, done, priority */
207 if((datea - dateb) != 0)return dateb - datea;
208 if((donea - doneb)!= 0) return doneb-donea;
209 if((prioritya - priorityb) != 0) return prioritya -priorityb;
211 return 0;