Add a function for getting relative paths from full paths.
[anjuta-git-plugin.git] / plugins / gtodo / plugin.c
blob35a88f61e01b9ddc2a2a4bd55fc634d0d615fc98
1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
2 /*
3 plugin.c
4 Copyright (C) 2000 Naba Kumar
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 #include <config.h>
22 #include <libanjuta/anjuta-shell.h>
23 #include <libanjuta/resources.h>
24 #include <libanjuta/anjuta-debug.h>
25 #include <libanjuta/interfaces/ianjuta-todo.h>
26 #include <libanjuta/interfaces/ianjuta-preferences.h>
28 //#include <libgtodo/main.h>
29 #include "main.h"
30 #include "plugin.h"
32 #define UI_FILE PACKAGE_DATA_DIR"/ui/anjuta-gtodo.ui"
34 static gpointer parent_class;
36 static void
37 on_hide_completed_action_activate (GtkAction *action, GTodoPlugin *plugin)
39 gboolean state;
40 state = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action));
41 gtodo_set_hide_done (state);
44 static void
45 on_hide_due_date_action_activate (GtkAction *action, GTodoPlugin *plugin)
47 gboolean state;
48 state = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action));
49 gtodo_set_hide_due (state);
52 static void
53 on_hide_end_date_action_activate (GtkAction *action, GTodoPlugin *plugin)
55 gboolean state;
56 state = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action));
57 gtodo_set_hide_nodate (state);
60 static GtkActionEntry actions_todo_view[] = {
62 "ActionMenuViewTodo",
63 NULL,
64 N_("_Tasks"),
65 NULL, NULL, NULL,
69 static GtkToggleActionEntry actions_view[] = {
71 "ActionViewTodoHideCompleted",
72 NULL,
73 N_("Hide _Completed Items"),
74 NULL,
75 N_("Hide completed todo items"),
76 G_CALLBACK (on_hide_completed_action_activate),
77 FALSE
80 "ActionViewTodoHideDueDate",
81 NULL,
82 N_("Hide Items Past _Due Date"),
83 NULL,
84 N_("Hide items that are past due date"),
85 G_CALLBACK (on_hide_due_date_action_activate),
86 FALSE
89 "ActionViewTodoHideEndDate",
90 NULL,
91 N_("Hide Items Without _End Date"),
92 NULL,
93 N_("Hide items without an end date"),
94 G_CALLBACK (on_hide_end_date_action_activate),
95 FALSE
99 static void
100 project_root_added (AnjutaPlugin *plugin, const gchar *name,
101 const GValue *value, gpointer user_data)
103 const gchar *root_uri;
105 root_uri = g_value_get_string (value);
107 if (root_uri)
109 gchar *todo_file;
111 todo_file = g_strconcat (root_uri, "/TODO.tasks", NULL);
112 gtodo_client_load (cl, todo_file);
113 g_free (todo_file);
114 category_changed();
118 static void
119 project_root_removed (AnjutaPlugin *plugin, const gchar *name,
120 gpointer user_data)
122 const gchar * home;
123 gchar *default_todo;
125 home = g_get_home_dir ();
126 default_todo = g_strconcat ("file://", home, "/.gtodo/todos", NULL);
128 gtodo_client_load (cl, default_todo);
129 category_changed();
130 g_free (default_todo);
133 static gboolean
134 activate_plugin (AnjutaPlugin *plugin)
136 GtkWidget *wid;
137 AnjutaUI *ui;
138 AnjutaPreferences *prefs;
139 GTodoPlugin *gtodo_plugin;
140 GtkAction* hide_due;
141 GtkAction* hide_nodate;
142 GtkAction* hide_done;
143 static gboolean initialized;
145 DEBUG_PRINT ("GTodoPlugin: Activating Task manager plugin ...");
146 gtodo_plugin = ANJUTA_PLUGIN_GTODO (plugin);
148 ui = anjuta_shell_get_ui (plugin->shell, NULL);
149 prefs = anjuta_shell_get_preferences (plugin->shell, NULL);
151 if (!initialized)
153 gtodo_load_settings();
155 wid = gui_create_todo_widget();
156 gtk_widget_show_all (wid);
157 gtodo_plugin->widget = wid;
159 /* Add all our editor actions */
160 gtodo_plugin->action_group =
161 anjuta_ui_add_action_group_entries (ui, "ActionGroupTodoView",
162 _("Tasks manager"),
163 actions_todo_view,
164 G_N_ELEMENTS (actions_todo_view),
165 GETTEXT_PACKAGE, FALSE, plugin);
166 gtodo_plugin->action_group2 =
167 anjuta_ui_add_toggle_action_group_entries (ui, "ActionGroupTodoViewOps",
168 _("Tasks manager view"),
169 actions_view,
170 G_N_ELEMENTS (actions_view),
171 GETTEXT_PACKAGE, TRUE, plugin);
172 gtodo_plugin->uiid = anjuta_ui_merge (ui, UI_FILE);
173 anjuta_shell_add_widget (plugin->shell, wid,
174 "AnjutaTodoPlugin", _("Tasks"),
175 "gtodo", /* Icon stock */
176 ANJUTA_SHELL_PLACEMENT_CENTER, NULL);
177 /* set up project directory watch */
178 gtodo_plugin->root_watch_id = anjuta_plugin_add_watch (plugin,
179 "project_root_uri",
180 project_root_added,
181 project_root_removed, NULL);
182 hide_done = anjuta_ui_get_action (ui, "ActionGroupTodoViewOps",
183 "ActionViewTodoHideCompleted");
184 g_object_set(G_OBJECT(hide_done), "active",
185 gtodo_get_hide_done(), NULL);
186 hide_due = anjuta_ui_get_action (ui, "ActionGroupTodoViewOps",
187 "ActionViewTodoHideDueDate");
188 g_object_set(G_OBJECT(hide_due), "active",
189 gtodo_get_hide_due(), NULL);
190 hide_nodate = anjuta_ui_get_action (ui, "ActionGroupTodoViewOps",
191 "ActionViewTodoHideEndDate");
192 g_object_set(G_OBJECT(hide_nodate), "active",
193 gtodo_get_hide_nodate(), NULL);
195 initialized = TRUE;
196 return TRUE;
199 static gboolean
200 deactivate_plugin (AnjutaPlugin *plugin)
202 GTodoPlugin *gplugin = ANJUTA_PLUGIN_GTODO (plugin);
203 AnjutaUI *ui = anjuta_shell_get_ui (plugin->shell, NULL);
205 DEBUG_PRINT ("GTodoPlugin: Dectivating Tasks manager plugin ...");
207 anjuta_plugin_remove_watch (plugin, gplugin->root_watch_id, TRUE);
209 /* Container holds the last ref to this widget so it will be destroyed as
210 * soon as removed. No need to separately destroy it. */
211 anjuta_shell_remove_widget (plugin->shell, gplugin->widget,
212 NULL);
213 anjuta_ui_unmerge (ui, gplugin->uiid);
214 anjuta_ui_remove_action_group (ui, gplugin->action_group2);
215 anjuta_ui_remove_action_group (ui, gplugin->action_group);
218 gplugin->uiid = 0;
219 gplugin->widget = NULL;
220 gplugin->root_watch_id = 0;
221 gplugin->action_group = NULL;
222 gplugin->action_group2 = NULL;
223 return TRUE;
226 static void
227 finalize (GObject *obj)
229 G_OBJECT_CLASS (parent_class)->finalize (obj);
232 static void
233 dispose (GObject *obj)
235 G_OBJECT_CLASS (parent_class)->dispose (obj);
238 static void
239 gtodo_plugin_instance_init (GObject *obj)
241 GTodoPlugin *plugin = ANJUTA_PLUGIN_GTODO (obj);
242 plugin->uiid = 0;
245 static void
246 gtodo_plugin_class_init (GObjectClass *klass)
248 AnjutaPluginClass *plugin_class = ANJUTA_PLUGIN_CLASS (klass);
250 parent_class = g_type_class_peek_parent (klass);
252 plugin_class->activate = activate_plugin;
253 plugin_class->deactivate = deactivate_plugin;
254 klass->dispose = dispose;
255 klass->finalize = finalize;
258 static void
259 itodo_load (IAnjutaTodo *profile, const gchar *filename, GError **err)
261 g_return_if_fail (filename != NULL);
262 gtodo_client_load (cl, filename);
265 static void
266 itodo_iface_init(IAnjutaTodoIface *iface)
268 iface->load = itodo_load;
271 static void
272 ipreferences_merge(IAnjutaPreferences* ipref, AnjutaPreferences* prefs, GError** e)
274 /* Add preferences */
275 GTodoPlugin* gtodo_plugin = ANJUTA_PLUGIN_GTODO (ipref);
276 GdkPixbuf *pixbuf;
278 pixbuf = gdk_pixbuf_new_from_file (PACKAGE_PIXMAPS_DIR"/"ICON_FILE, NULL);
279 gtodo_plugin->prefs = preferences_widget();
280 anjuta_preferences_dialog_add_page (ANJUTA_PREFERENCES_DIALOG (anjuta_preferences_get_dialog (prefs)),
281 "GTodo",
282 _("Todo Manager"),
283 pixbuf, gtodo_plugin->prefs);
284 g_object_unref (pixbuf);
287 static void
288 ipreferences_unmerge(IAnjutaPreferences* ipref, AnjutaPreferences* prefs, GError** e)
290 preferences_remove_signals();
291 anjuta_preferences_remove_page(prefs, _("Todo Manager"));
295 static void
296 ipreferences_iface_init(IAnjutaPreferencesIface* iface)
298 iface->merge = ipreferences_merge;
299 iface->unmerge = ipreferences_unmerge;
303 ANJUTA_PLUGIN_BEGIN (GTodoPlugin, gtodo_plugin);
304 ANJUTA_PLUGIN_ADD_INTERFACE (itodo, IANJUTA_TYPE_TODO);
305 ANJUTA_PLUGIN_ADD_INTERFACE(ipreferences, IANJUTA_TYPE_PREFERENCES);
306 ANJUTA_PLUGIN_END;
308 ANJUTA_SIMPLE_PLUGIN (GTodoPlugin, gtodo_plugin);