Fix a Gtk warning when checking path input in the log viewer.
[anjuta-git-plugin.git] / plugins / gtodo / interface.c
blob342cdff7edfa09f447b9fb8028fdf91f968442a4
1 #include <config.h>
2 #include <gtk/gtk.h>
3 #include <string.h>
4 #include <stdio.h>
5 #include "main.h"
6 #include "tray-icon.h"
7 #include "debug_printf.h"
9 /* the main window struct */
10 mwindow mw;
12 /* settings struct */
13 sets settings;
14 GConfClient* client;
16 /* the connection to the xml file */
17 GTodoClient *cl = NULL;
19 gulong shand;
20 GdkEventMotion *ovent;
22 static void stock_icons(void);
24 static void backend_changed()
26 debug_printf(DEBUG_INFO, "Backend data changed, updating interface");
27 read_categorys();
28 category_changed();
31 static void set_read_only()
33 gtk_widget_set_sensitive (mw.tbdelbut, FALSE);
34 gtk_label_set_text_with_mnemonic(GTK_LABEL(mw.tbeditlb),_("_View"));
35 gtk_widget_set_sensitive(mw.tbaddbut, FALSE);
38 void gtodo_load_settings ()
40 debug_printf(DEBUG_INFO, "Creating gconf client");
41 client = gconf_client_get_default();
43 gconf_client_add_dir(client,
44 "/apps/gtodo/prefs",
45 GCONF_CLIENT_PRELOAD_NONE,
46 NULL);
47 gconf_client_add_dir(client,
48 "/apps/gtodo/view",
49 GCONF_CLIENT_PRELOAD_NONE,
50 NULL);
52 debug_printf(DEBUG_INFO, "Loading settings from gconf");
54 /* Enable tray by default.. user won't know if he/she doesnt have tray */
55 /* this is just for people who don't want it in there tray */
56 settings.place = gconf_client_get_bool(client, "/apps/gtodo/prefs/restore-position",NULL);;
57 settings.size = gconf_client_get_bool(client, "/apps/gtodo/prefs/restore-size",NULL);;
58 settings.ask_delete_category = gconf_client_get_bool(client, "/apps/gtodo/prefs/ask-delete-category",NULL);
59 /* this is kinda (thanks gtk :-/) buggy.. gtk need fix first */
60 // settings.list_tooltip = gconf_client_get_bool(client, "/apps/gtodo/prefs/show-tooltip",NULL);
61 /* auto purge is default on.. */
62 settings.auto_purge = gconf_client_get_bool(client, "/apps/gtodo/prefs/auto-purge",NULL);
63 /* set default auto purge to a week */
64 settings.purge_days = gconf_client_get_int(client, "/apps/gtodo/prefs/auto-purge-days",NULL);
65 settings.due_color = gconf_client_get_string(client, "/apps/gtodo/prefs/due-color",NULL);
66 settings.due_today_color = gconf_client_get_string(client, "/apps/gtodo/prefs/due-today-color",NULL);
67 settings.due_in_days_color = gconf_client_get_string(client, "/apps/gtodo/prefs/due-in-days-color",NULL);
68 settings.due_days = gconf_client_get_int(client, "/apps/gtodo/prefs/due-days",NULL);
69 settings.sorttype = gconf_client_get_int(client, "/apps/gtodo/prefs/sort-type",NULL);
70 settings.sortorder = gconf_client_get_int(client, "/apps/gtodo/prefs/sort-order",NULL);
71 /* treeview hide preferences.. */
72 settings.hide_done = gconf_client_get_bool(client, "/apps/gtodo/prefs/hide-done",NULL);
73 settings.hide_due = gconf_client_get_bool(client, "/apps/gtodo/prefs/hide-due",NULL);
74 settings.hide_nodate = gconf_client_get_bool(client, "/apps/gtodo/prefs/hide-nodate",NULL);
75 settings.hl_indays = gconf_client_get_bool(client,"/apps/gtodo/prefs/hl-indays",NULL);
76 settings.hl_due = gconf_client_get_bool(client,"/apps/gtodo/prefs/hl-due",NULL);
77 settings.hl_today = gconf_client_get_bool(client,"/apps/gtodo/prefs/hl-today",NULL);
78 pref_gconf_set_notifications(client);
81 void gtodo_update_settings()
83 if(settings.auto_purge && !gtodo_client_get_read_only(cl))
85 debug_printf(DEBUG_INFO, "Purging items that are past purge date");
86 get_all_past_purge();
89 /* read the categorys */
91 int i = gconf_client_get_int(client, "/apps/gtodo/view/last-category",NULL);
92 debug_printf(DEBUG_INFO, "Reading categories");
93 read_categorys();
94 gtk_option_menu_set_history(GTK_OPTION_MENU(mw.option),i);
96 /* nasty thing to fix the tooltip in the list */
97 if(gconf_client_get_bool(client, "/apps/gtodo/prefs/show-tooltip",NULL))
99 gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(mw.treeview), FALSE);
102 if(gtodo_client_get_read_only(cl))
104 debug_printf(DEBUG_WARNING, "Read only file detected, disabling severall options");
105 set_read_only();
108 gtodo_client_set_changed_callback(cl,(void *)backend_changed ,NULL);
109 g_timeout_add(300000, (GSourceFunc)check_for_notification_event, NULL);
111 check_for_notification_event();
115 GtkWidget * gui_create_todo_widget()
117 GtkTreeViewColumn *column;
118 GtkCellRenderer *renderer;
119 GtkWidget *lb, *hbox;
120 static GtkWidget *sw;
121 /* used for the buttons @ the bottom */
122 GtkSizeGroup *sgroup;
123 /* TODO: make this compile time (path is now)*/
125 if (!cl)
126 cl = gtodo_client_new_default (NULL);
127 stock_icons();
128 /* add an verticall box */
129 mw.vbox = gtk_vbox_new(FALSE, 0);
131 mw.toolbar = gtk_hbox_new(FALSE, 6);
132 gtk_box_pack_end(GTK_BOX(mw.vbox), mw.toolbar, FALSE, TRUE, 0);
133 gtk_container_set_border_width(GTK_CONTAINER(mw.toolbar), 6);
135 /* add drop down menu's */
136 mw.option = gtk_option_menu_new();
137 mw.menu = gtk_menu_new();
138 // gtk_widget_set_usize(mw.option, 120 , -1);
139 gtk_option_menu_set_menu(GTK_OPTION_MENU(mw.option), mw.menu);
140 gtk_box_pack_start(GTK_BOX(mw.toolbar), mw.option, FALSE, FALSE, 0);
142 gtk_menu_shell_insert (GTK_MENU_SHELL (mw.menu), gtk_menu_item_new_with_label (_("All")), 0);
143 gtk_menu_shell_insert (GTK_MENU_SHELL (mw.menu), gtk_separator_menu_item_new(), 1);
144 mw.mitems = g_malloc(1*sizeof(GtkWidget *));
145 mw.mitems[0] = NULL;
146 /* shand can be removed?? */
147 shand = g_signal_connect(G_OBJECT(mw.option), "changed", G_CALLBACK(category_changed), NULL);
149 /* the buttonbox buttons */
150 /* set the button's same size */
151 sgroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
152 /*buttons */
153 mw.tbaddbut = gtk_button_new_from_stock(GTK_STOCK_ADD);
154 mw.tbdelbut = gtk_button_new_from_stock(GTK_STOCK_REMOVE);
155 mw.tbeditbut = gtk_button_new();
156 hbox = gtk_hbox_new(FALSE, 6);
157 lb = gtk_alignment_new(0.5,0.5,0,0);
158 gtk_container_add(GTK_CONTAINER(lb), hbox);
159 gtk_container_add(GTK_CONTAINER(mw.tbeditbut), lb);
162 lb = gtk_image_new_from_stock("gtodo-edit", GTK_ICON_SIZE_BUTTON);
163 gtk_box_pack_start(GTK_BOX(hbox), lb, FALSE, TRUE, 0);
164 mw.tbeditlb = gtk_label_new_with_mnemonic(_("_Edit"));
165 gtk_box_pack_start(GTK_BOX(hbox), mw.tbeditlb, FALSE, TRUE,0);
167 /* add them */
168 gtk_box_pack_end(GTK_BOX(mw.toolbar), mw.tbaddbut, FALSE, FALSE, 0);
169 gtk_box_pack_end(GTK_BOX(mw.toolbar), mw.tbdelbut, FALSE, FALSE, 0);
170 gtk_box_pack_end(GTK_BOX(mw.toolbar), mw.tbeditbut, FALSE, FALSE, 0);
171 gtk_size_group_add_widget(sgroup, mw.tbaddbut);
172 gtk_size_group_add_widget(sgroup, mw.tbeditbut);
173 gtk_size_group_add_widget(sgroup, mw.tbdelbut);
175 /* signals */
176 g_signal_connect(G_OBJECT(mw.tbaddbut), "clicked", G_CALLBACK(gui_add_todo_item), GINT_TO_POINTER(0));
177 g_signal_connect(G_OBJECT(mw.tbeditbut), "clicked", G_CALLBACK(gui_add_todo_item), GINT_TO_POINTER(1));
178 g_signal_connect(G_OBJECT(mw.tbdelbut), "clicked", G_CALLBACK(remove_todo_item), FALSE);
181 /* add the todo list */
182 mw.list = gtk_list_store_new(N_COL, G_TYPE_UINT64, G_TYPE_INT,G_TYPE_STRING, G_TYPE_INT, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_UINT64, G_TYPE_BOOLEAN, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_UINT64, G_TYPE_UINT64, G_TYPE_BOOLEAN);
183 mw.sortmodel = gtk_tree_model_sort_new_with_model(GTK_TREE_MODEL(mw.list));
184 mw.treeview = gtk_tree_view_new_with_model(GTK_TREE_MODEL(mw.sortmodel));
186 sw = gtk_scrolled_window_new(NULL, NULL);
187 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(sw), GTK_SHADOW_ETCHED_IN);
188 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(sw),
189 GTK_POLICY_AUTOMATIC,
190 GTK_POLICY_AUTOMATIC);
191 gtk_container_add(GTK_CONTAINER(sw), mw.treeview);
193 gtk_box_pack_end(GTK_BOX(mw.vbox), sw, TRUE, TRUE, 0);
194 gtk_tree_view_set_rules_hint(GTK_TREE_VIEW(mw.treeview), TRUE);
196 /* add the columns to the list */
197 renderer = gtk_cell_renderer_toggle_new();
198 g_object_set (renderer, "yalign", 0.0, NULL);
199 column = gtk_tree_view_column_new_with_attributes("", renderer, "active",DONE,"activatable", EDITABLE, NULL);
200 gtk_tree_view_column_set_sort_column_id (column, DONE);
201 g_signal_connect(renderer, "toggled", G_CALLBACK(list_toggled_done), NULL);
202 gtk_tree_view_append_column(GTK_TREE_VIEW(mw.treeview), column);
204 renderer = gtk_cell_renderer_text_new();
205 g_object_set (renderer, "yalign", 0.0, NULL);
206 column = gtk_tree_view_column_new_with_attributes(_("Priority"), renderer, "text" , PRIOSTR,"strikethrough", DONE, "foreground-set", DUE,"foreground", COLOR, NULL);
207 gtk_tree_view_column_set_sort_column_id (column, PRIOSTR);
208 gtk_tree_view_append_column(GTK_TREE_VIEW(mw.treeview), column);
209 if(!gconf_client_get_bool(client, "/apps/gtodo/view/show-priority-column",NULL)) gtk_tree_view_column_set_visible(column, FALSE);
211 renderer = gtk_cell_renderer_text_new();
212 g_object_set (renderer, "yalign", 0.0, NULL);
213 column = gtk_tree_view_column_new_with_attributes(_("Due date"), renderer, "text" , F_DATE,"strikethrough", DONE, "foreground-set", DUE,"foreground", COLOR,NULL);
214 gtk_tree_view_column_set_sort_column_id (column, F_DATE);
215 gtk_tree_view_append_column(GTK_TREE_VIEW(mw.treeview), column);
216 if(!gconf_client_get_bool(client, "/apps/gtodo/prefs/show-due-column",NULL)) gtk_tree_view_column_set_visible(column, FALSE);
218 renderer = gtk_cell_renderer_text_new();
219 g_object_set (renderer, "yalign", 0.0, NULL);
220 column = gtk_tree_view_column_new_with_attributes(_("Category"), renderer, "text" , CATEGORY,"strikethrough", DONE, "foreground-set", DUE,"foreground", COLOR,NULL);
221 gtk_tree_view_column_set_sort_column_id (column, CATEGORY);
222 gtk_tree_view_append_column(GTK_TREE_VIEW(mw.treeview), column);
223 if(!gconf_client_get_bool(client, "/apps/gtodo/view/show-category-column",NULL)) gtk_tree_view_column_set_visible(column, FALSE);
225 renderer = gtk_cell_renderer_text_new();
226 g_object_set (renderer, "yalign", 0.0, "wrap-mode", PANGO_WRAP_WORD, "wrap-width", 500, NULL);
227 column = gtk_tree_view_column_new_with_attributes(_("Summary"), renderer, "markup",SUMMARY,"strikethrough", DONE, "foreground-set", DUE,"foreground", COLOR,NULL);
228 gtk_tree_view_column_set_sort_column_id (column, SUMMARY);
229 gtk_tree_view_append_column(GTK_TREE_VIEW(mw.treeview), column);
231 gtk_tree_sortable_set_sort_func(GTK_TREE_SORTABLE (mw.sortmodel),0, (GtkTreeIterCompareFunc)sort_function_test, NULL, NULL);
232 gtk_tree_sortable_set_sort_column_id(GTK_TREE_SORTABLE (mw.sortmodel),0, settings.sortorder);
234 // gtk_tree_view_column_set_fixed_width(column, 10);
235 gtk_tree_view_column_set_sizing(column, GTK_TREE_VIEW_COLUMN_AUTOSIZE);
236 gtk_tree_view_set_expander_column (GTK_TREE_VIEW (mw.treeview), column);
238 /* handlers */
239 g_signal_connect(G_OBJECT(mw.treeview), "motion-notify-event", G_CALLBACK(mw_motion_cb), NULL);
240 g_signal_connect(G_OBJECT(mw.treeview), "leave-notify-event", G_CALLBACK(mw_leave_cb), NULL);
242 g_signal_connect(G_OBJECT (mw.treeview), "row-activated", G_CALLBACK (gui_add_todo_item), GINT_TO_POINTER(1));
243 // FIXME: set_sorting_menu_item();
244 gtodo_update_settings();
245 return mw.vbox;
248 static void stock_icons()
250 GtkIconFactory *factory;
251 GtkIconSet *icons;
252 GtkIconSource *icon_source;
254 /* testing icon factory.. hope it works a little */
255 factory = gtk_icon_factory_new();
256 /* random icon */
257 icons = gtk_icon_set_new();
258 icon_source = gtk_icon_source_new();
259 gtk_icon_source_set_filename(icon_source, PIXMAP_PATH"/gtodo-edit.png");
260 gtk_icon_set_add_source(icons, icon_source);
261 gtk_icon_factory_add(factory, "gtodo-edit", icons);
263 icons = gtk_icon_set_new();
264 icon_source = gtk_icon_source_new();
265 gtk_icon_source_set_filename(icon_source, PIXMAP_PATH"/"ICON_FILE);
266 gtk_icon_set_add_source(icons, icon_source);
267 gtk_icon_factory_add(factory, "gtodo", icons);
269 icons = gtk_icon_set_new();
270 icon_source = gtk_icon_source_new();
271 gtk_icon_source_set_filename(icon_source, PIXMAP_PATH"/gtodo_tray.png");
272 gtk_icon_set_add_source(icons, icon_source);
273 gtk_icon_factory_add(factory, "gtodo-tray", icons);
275 /* added this because there isn no about availible in the default stock set. */
276 /* I call it gnome about so it still uses the one out off the current icon theme */
277 icons = gtk_icon_set_new();
278 icon_source = gtk_icon_source_new();
279 gtk_icon_source_set_filename(icon_source, PIXMAP_PATH"/gtodo-about.png");
280 gtk_icon_set_add_source(icons, icon_source);
281 gtk_icon_factory_add(factory, "gnome-stock-about", icons);
282 gtk_icon_factory_add_default (factory);
286 void gtodo_set_hide_done(gboolean hide_it)
288 /* settings.hide_done = gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM (gtk_item_factory_get_widget(mw.item_factory, N_("/View/Todo List/Hide Completed Items"))));*/
289 settings.hide_done = hide_it;
290 gconf_client_set_bool(client, "/apps/gtodo/prefs/hide-done", settings.hide_done,NULL);
293 void gtodo_set_hide_nodate(gboolean hide_it)
295 settings.hide_nodate = hide_it;
296 gconf_client_set_bool(client, "/apps/gtodo/prefs/hide-nodate", settings.hide_nodate, NULL);
299 void gtodo_set_hide_due(gboolean hide_it)
301 settings.hide_due = hide_it;
302 gconf_client_set_bool(client, "/apps/gtodo/prefs/hide-due", settings.hide_due, NULL);
305 gboolean gtodo_get_hide_done()
307 return settings.hide_done;
310 gboolean gtodo_get_hide_nodate()
312 return settings.hide_nodate;
315 gboolean gtodo_get_hide_due()
317 return settings.hide_due;
320 void gtodo_set_sorting_order (gboolean ascending_sort)
322 settings.sortorder = ascending_sort;
323 gconf_client_set_int(client, "/apps/gtodo/prefs/sort-order",settings.sortorder,NULL);
324 gtk_tree_sortable_set_sort_column_id(GTK_TREE_SORTABLE (mw.sortmodel),0, settings.sortorder);
327 void gtodo_set_sorting_type (int sorting_type)
329 settings.sorttype = sorting_type;
330 gconf_client_set_int(client, "/apps/gtodo/prefs/sort-type",sorting_type,NULL);
331 gtk_tree_sortable_set_sort_column_id(GTK_TREE_SORTABLE (gtk_tree_view_get_model(GTK_TREE_VIEW(mw.treeview))),0, settings.sortorder);
332 category_changed();