1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
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
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>
32 #define UI_FILE PACKAGE_DATA_DIR"/ui/anjuta-gtodo.ui"
34 static gpointer parent_class
;
37 on_hide_completed_action_activate (GtkAction
*action
, GTodoPlugin
*plugin
)
40 state
= gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action
));
41 gtodo_set_hide_done (state
);
45 on_hide_due_date_action_activate (GtkAction
*action
, GTodoPlugin
*plugin
)
48 state
= gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action
));
49 gtodo_set_hide_due (state
);
53 on_hide_end_date_action_activate (GtkAction
*action
, GTodoPlugin
*plugin
)
56 state
= gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action
));
57 gtodo_set_hide_nodate (state
);
60 static GtkActionEntry actions_todo_view
[] = {
69 static GtkToggleActionEntry actions_view
[] = {
71 "ActionViewTodoHideCompleted",
73 N_("Hide _Completed Items"),
75 N_("Hide completed todo items"),
76 G_CALLBACK (on_hide_completed_action_activate
),
80 "ActionViewTodoHideDueDate",
82 N_("Hide Items Past _Due Date"),
84 N_("Hide items that are past due date"),
85 G_CALLBACK (on_hide_due_date_action_activate
),
89 "ActionViewTodoHideEndDate",
91 N_("Hide Items Without _End Date"),
93 N_("Hide items without an end date"),
94 G_CALLBACK (on_hide_end_date_action_activate
),
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
);
111 todo_file
= g_strconcat (root_uri
, "/TODO.tasks", NULL
);
112 gtodo_client_load (cl
, todo_file
);
119 project_root_removed (AnjutaPlugin
*plugin
, const gchar
*name
,
125 home
= g_get_home_dir ();
126 default_todo
= g_strconcat ("file://", home
, "/.gtodo/todos", NULL
);
128 gtodo_client_load (cl
, default_todo
);
130 g_free (default_todo
);
134 activate_plugin (AnjutaPlugin
*plugin
)
138 AnjutaPreferences
*prefs
;
139 GTodoPlugin
*gtodo_plugin
;
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
);
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",
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"),
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
,
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
);
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
,
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
);
219 gplugin
->widget
= NULL
;
220 gplugin
->root_watch_id
= 0;
221 gplugin
->action_group
= NULL
;
222 gplugin
->action_group2
= NULL
;
227 finalize (GObject
*obj
)
229 G_OBJECT_CLASS (parent_class
)->finalize (obj
);
233 dispose (GObject
*obj
)
235 G_OBJECT_CLASS (parent_class
)->dispose (obj
);
239 gtodo_plugin_instance_init (GObject
*obj
)
241 GTodoPlugin
*plugin
= ANJUTA_PLUGIN_GTODO (obj
);
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
;
259 itodo_load (IAnjutaTodo
*profile
, const gchar
*filename
, GError
**err
)
261 g_return_if_fail (filename
!= NULL
);
262 gtodo_client_load (cl
, filename
);
266 itodo_iface_init(IAnjutaTodoIface
*iface
)
268 iface
->load
= itodo_load
;
272 ipreferences_merge(IAnjutaPreferences
* ipref
, AnjutaPreferences
* prefs
, GError
** e
)
274 /* Add preferences */
275 GTodoPlugin
* gtodo_plugin
= ANJUTA_PLUGIN_GTODO (ipref
);
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
)),
283 pixbuf
, gtodo_plugin
->prefs
);
284 g_object_unref (pixbuf
);
288 ipreferences_unmerge(IAnjutaPreferences
* ipref
, AnjutaPreferences
* prefs
, GError
** e
)
290 preferences_remove_signals();
291 anjuta_preferences_remove_page(prefs
, _("Todo Manager"));
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
);
308 ANJUTA_SIMPLE_PLUGIN (GTodoPlugin
, gtodo_plugin
);