anjuta r4433 - in trunk: . plugins/gtodo
- From: sgranjoux svn gnome org
- To: svn-commits-list gnome org
- Subject: anjuta r4433 - in trunk: . plugins/gtodo
- Date: Tue, 9 Dec 2008 20:12:21 +0000 (UTC)
Author: sgranjoux
Date: Tue Dec 9 20:12:20 2008
New Revision: 4433
URL: http://svn.gnome.org/viewvc/anjuta?rev=4433&view=rev
Log:
* plugins/gtodo/interface.c,
plugins/gtodo/plugin.c,
plugins/gtodo/libgtodo.c,
plugins/gtodo/libgtodo.h:
Fix #563586 Crash if project TODO.tasks is not readable
Modified:
trunk/ChangeLog
trunk/plugins/gtodo/interface.c
trunk/plugins/gtodo/libgtodo.c
trunk/plugins/gtodo/libgtodo.h
trunk/plugins/gtodo/plugin.c
Modified: trunk/plugins/gtodo/interface.c
==============================================================================
--- trunk/plugins/gtodo/interface.c (original)
+++ trunk/plugins/gtodo/interface.c Tue Dec 9 20:12:20 2008
@@ -124,6 +124,9 @@
if (!cl)
cl = gtodo_client_new_default (NULL);
+ if (!cl)
+ return NULL;
+
stock_icons();
/* add an verticall box */
mw.vbox = gtk_vbox_new(FALSE, 0);
Modified: trunk/plugins/gtodo/libgtodo.c
==============================================================================
--- trunk/plugins/gtodo/libgtodo.c (original)
+++ trunk/plugins/gtodo/libgtodo.c Tue Dec 9 20:12:20 2008
@@ -27,7 +27,7 @@
/* this checks if the xml backend file exists.. not to be used by the user */
void check_item_changed (GFileMonitor *monitor, GFile *file, GFile *other_file, GFileMonitorEvent event, GTodoClient *cl);
-int gtodo_client_check_file(GTodoClient *cl, GError **error);
+gboolean gtodo_client_check_file(GTodoClient *cl, GError **error);
/* Function that creates an empty todo item. WARNING Don't use this when adding a todo item to the list.*/
@@ -553,7 +553,7 @@
}
/* initialise the gtodo lib */
-int gtodo_client_check_file(GTodoClient *cl, GError **error)
+gboolean gtodo_client_check_file(GTodoClient *cl, GError **error)
{
GError *tmp_error = NULL;
GFile *base_path = NULL;
@@ -601,7 +601,7 @@
g_set_error(&tmp_error,LIBGTODO_ERROR,LIBGTODO_ERROR_NO_PERMISSION,
_("No permission to read the file."));
g_propagate_error(error, tmp_error);
- return TRUE;
+ return FALSE;
}
cl->read_only = !write;
DEBUG_PRINT("trying to read file: %s, size: %d", g_file_get_parse_name (cl->xml_file), size);
@@ -617,7 +617,7 @@
g_set_error(&tmp_error, LIBGTODO_ERROR, LIBGTODO_ERROR_FAILED, _("Failed to read file"));
g_propagate_error(error, tmp_error);
}
- return TRUE;
+ return FALSE;
}
cl->gtodo_doc = xmlParseMemory(read_buf, size);
if(cl->gtodo_doc == NULL)
@@ -626,7 +626,7 @@
g_propagate_error(error, tmp_error);
DEBUG_PRINT("%s", "failed to read the file");
g_free (read_buf);
- return TRUE;
+ return FALSE;
}
/* get root element.. this "root" is used in the while program */
@@ -637,7 +637,7 @@
g_propagate_error(error, tmp_error);
DEBUG_PRINT("%s", "failed to get root node.");
g_free (read_buf);
- return TRUE;
+ return FALSE;
}
/* check if the name of the root file is ok.. just to make sure :) */
if(!xmlStrEqual(cl->root->name, (const xmlChar *)"gtodo"))
@@ -645,7 +645,7 @@
g_set_error(&tmp_error,LIBGTODO_ERROR,LIBGTODO_ERROR_XML,_("File is not a valid gtodo file"));
g_propagate_error(error, tmp_error);
g_free (read_buf);
- return TRUE;
+ return FALSE;
}
g_free (read_buf);
@@ -666,7 +666,7 @@
if(gtodo_client_save_xml(cl, &tmp_error))
{
g_propagate_error(error, tmp_error);
- return TRUE;
+ return FALSE;
}
cl->read_only = FALSE;
g_error_free (file_error);
@@ -674,9 +674,9 @@
else{
/* save some more info here.. check for some logicol errors and print it. */
g_propagate_error(error, file_error);
- return TRUE;
+ return FALSE;
}
- return FALSE;
+ return TRUE;
}
/* Remove unwanted text nodes from the document */
@@ -800,38 +800,37 @@
return FALSE;
}
-int gtodo_client_reload(GTodoClient *cl)
+gboolean gtodo_client_reload(GTodoClient *cl, GError **error)
{
- /* fixme */
if (cl->gtodo_doc)
xmlFreeDoc(cl->gtodo_doc);
+ cl->gtodo_doc = NULL;
cl->root = NULL;
- if(gtodo_client_check_file(cl, NULL))
- {
- if(debug)g_print("Failed to reload the file\n");
- return FALSE;
- }
- return TRUE;
+ return gtodo_client_check_file(cl, error);
}
-int gtodo_client_load(GTodoClient *cl, GFile *xml_file)
+gboolean gtodo_client_load(GTodoClient *cl, GFile *xml_file, GError **error)
{
- /* fixme */
+ void *(* function)(gpointer cl, gpointer data) ;
+ gpointer data;
+
if (cl->gtodo_doc)
xmlFreeDoc(cl->gtodo_doc);
+ cl->gtodo_doc = NULL;
cl->root = NULL;
+ function = cl->function;
+ data = cl->data;
+ gtodo_client_destroy_changed_callback (cl, function, data);
if (cl->xml_file)
g_object_unref (cl->xml_file);
cl->xml_file = g_file_dup (xml_file);
- if(gtodo_client_check_file(cl, NULL))
- {
- if(debug)g_print("Failed to reload the file\n");
- return FALSE;
- }
- gtodo_client_set_changed_callback (cl, cl->function, cl->data);
+ if(!gtodo_client_check_file(cl, error)) return FALSE;
+
+ gtodo_client_set_changed_callback (cl, function, data);
if (cl->function)
- cl->function(cl, cl->data);
+ cl->function(cl, cl->data);
+
return TRUE;
}
@@ -844,11 +843,11 @@
g_return_val_if_fail(error == NULL || *error == NULL,FALSE);
- cl = g_malloc(sizeof(GTodoClient));
+ cl = g_malloc0(sizeof(GTodoClient));
default_uri = g_strdup_printf("/%s/.gtodo/todos", g_getenv("HOME"));
cl->xml_file = g_file_new_for_path (default_uri);
/* check, open or create the correct xml file */
- if(gtodo_client_check_file(cl, &tmp_error))
+ if(!gtodo_client_check_file(cl, &tmp_error))
{
g_propagate_error(error, tmp_error);
return NULL;
@@ -875,7 +874,7 @@
cl = g_malloc(sizeof(GTodoClient));
cl->xml_file = g_file_new_for_path(filename);
/* check, open or create the correct xml file */
- if(gtodo_client_check_file(cl,&tmp_error))
+ if(!gtodo_client_check_file(cl,&tmp_error))
{
g_propagate_error(error, tmp_error);
return NULL;
@@ -1239,7 +1238,7 @@
{
if (event == G_FILE_MONITOR_EVENT_CHANGES_DONE_HINT)
{
- gtodo_client_reload(cl);
+ gtodo_client_reload(cl, NULL);
DEBUG_PRINT ("%s", "Item changed");
cl->function(cl, cl->data);
}
@@ -1250,6 +1249,11 @@
void gtodo_client_set_changed_callback(GTodoClient *cl, void *(*function)(gpointer cl, gpointer data), gpointer data)
{
cl->function = function;
+ if(cl->timeout != NULL)
+ {
+ g_file_monitor_cancel (cl->timeout);
+ g_object_unref (cl->timeout);
+ }
cl->timeout = g_file_monitor_file (cl->xml_file, G_FILE_MONITOR_NONE, NULL, NULL);
g_signal_connect (G_OBJECT (cl->timeout), "changed", G_CALLBACK (check_item_changed), cl);
cl->data = data;
@@ -1546,7 +1550,7 @@
void gtodo_client_save_client_to_client(GTodoClient *source, GTodoClient *duplicate)
{
gtodo_client_save_xml_to_file(source, duplicate->xml_file,NULL);
- gtodo_client_reload(duplicate);
+ gtodo_client_reload(duplicate, NULL);
}
gboolean gtodo_client_get_read_only(GTodoClient *cl)
Modified: trunk/plugins/gtodo/libgtodo.h
==============================================================================
--- trunk/plugins/gtodo/libgtodo.h (original)
+++ trunk/plugins/gtodo/libgtodo.h Tue Dec 9 20:12:20 2008
@@ -272,10 +272,10 @@
int gtodo_client_save_xml_to_file(GTodoClient *cl, GFile *file, GError **error);
/* reloads the client backend data*/
-int gtodo_client_reload(GTodoClient *cl);
+gboolean gtodo_client_reload(GTodoClient *cl, GError **error);
/* Loads a file */
-int gtodo_client_load(GTodoClient *cl, GFile *xml_file);
+gboolean gtodo_client_load(GTodoClient *cl, GFile *xml_file, GError **error);
/* creates a new GTodoClient that opens the default backend */
GTodoClient * gtodo_client_new_default(GError **error);
Modified: trunk/plugins/gtodo/plugin.c
==============================================================================
--- trunk/plugins/gtodo/plugin.c (original)
+++ trunk/plugins/gtodo/plugin.c Tue Dec 9 20:12:20 2008
@@ -97,6 +97,83 @@
}
};
+static gboolean
+create_gui (GTodoPlugin *gtodo_plugin)
+{
+ GtkWidget *wid;
+ AnjutaUI *ui;
+ GtkAction* hide_due;
+ GtkAction* hide_nodate;
+ GtkAction* hide_done;
+
+ if (gtodo_plugin->widget) return TRUE;
+
+ wid = gui_create_todo_widget();
+ if (!wid) return FALSE;
+
+ gtk_widget_show_all (wid);
+ gtodo_plugin->widget = wid;
+
+ ui = anjuta_shell_get_ui (ANJUTA_PLUGIN (gtodo_plugin)->shell, NULL);
+
+ /* Add all our editor actions */
+ gtodo_plugin->action_group =
+ anjuta_ui_add_action_group_entries (ui, "ActionGroupTodoView",
+ _("Tasks manager"),
+ actions_todo_view,
+ G_N_ELEMENTS (actions_todo_view),
+ GETTEXT_PACKAGE, FALSE, gtodo_plugin);
+ gtodo_plugin->action_group2 =
+ anjuta_ui_add_toggle_action_group_entries (ui, "ActionGroupTodoViewOps",
+ _("Tasks manager view"),
+ actions_view,
+ G_N_ELEMENTS (actions_view),
+ GETTEXT_PACKAGE, TRUE, gtodo_plugin);
+ gtodo_plugin->uiid = anjuta_ui_merge (ui, UI_FILE);
+ anjuta_shell_add_widget (ANJUTA_PLUGIN (gtodo_plugin)->shell, wid,
+ "AnjutaTodoPlugin", _("Tasks"),
+ "gtodo", /* Icon stock */
+ ANJUTA_SHELL_PLACEMENT_CENTER, NULL);
+
+ hide_done = anjuta_ui_get_action (ui, "ActionGroupTodoViewOps",
+ "ActionViewTodoHideCompleted");
+ g_object_set(G_OBJECT(hide_done), "active",
+ gtodo_get_hide_done(), NULL);
+ hide_due = anjuta_ui_get_action (ui, "ActionGroupTodoViewOps",
+ "ActionViewTodoHideDueDate");
+ g_object_set(G_OBJECT(hide_due), "active",
+ gtodo_get_hide_due(), NULL);
+ hide_nodate = anjuta_ui_get_action (ui, "ActionGroupTodoViewOps",
+ "ActionViewTodoHideEndDate");
+ g_object_set(G_OBJECT(hide_nodate), "active",
+ gtodo_get_hide_nodate(), NULL);
+
+ return TRUE;
+}
+
+static gboolean
+remove_gui (GTodoPlugin *gtodo_plugin)
+{
+ AnjutaUI *ui = anjuta_shell_get_ui (ANJUTA_PLUGIN (gtodo_plugin)->shell, NULL);
+
+ if (!gtodo_plugin->widget) return FALSE;
+
+ /* Container holds the last ref to this widget so it will be destroyed as
+ * soon as removed. No need to separately destroy it. */
+ anjuta_shell_remove_widget (ANJUTA_PLUGIN (gtodo_plugin)->shell, gtodo_plugin->widget,
+ NULL);
+ anjuta_ui_unmerge (ui, gtodo_plugin->uiid);
+ anjuta_ui_remove_action_group (ui, gtodo_plugin->action_group2);
+ anjuta_ui_remove_action_group (ui, gtodo_plugin->action_group);
+
+ gtodo_plugin->uiid = 0;
+ gtodo_plugin->widget = NULL;
+ gtodo_plugin->action_group = NULL;
+ gtodo_plugin->action_group2 = NULL;
+
+ return TRUE;
+}
+
static void
project_root_added (AnjutaPlugin *plugin, const gchar *name,
const GValue *value, gpointer user_data)
@@ -109,13 +186,23 @@
{
GFile *file;
gchar *todo_file;
+ GError *error = NULL;
todo_file = g_strconcat (root_uri, "/TODO.tasks", NULL);
file = g_file_parse_name (todo_file);
- gtodo_client_load (cl, file);
+ if (!gtodo_client_load (cl, file, &error))
+ {
+ remove_gui (ANJUTA_PLUGIN_GTODO (plugin));
+ anjuta_util_dialog_error (GTK_WINDOW (plugin->shell), "Unable to load todo file: %s", error->message);
+ g_error_free (error);
+ error = NULL;
+ }
+ else
+ {
+ create_gui (ANJUTA_PLUGIN_GTODO (plugin));
+ }
g_free (todo_file);
g_object_unref (file);
- category_changed();
}
}
@@ -126,13 +213,23 @@
const gchar * home;
gchar *default_todo;
GFile* file;
+ GError *error = NULL;
home = g_get_home_dir ();
default_todo = g_strconcat ("file://", home, "/.gtodo/todos", NULL);
file = g_file_new_for_uri (default_todo);
- gtodo_client_load (cl, file);
- category_changed();
+ if (!gtodo_client_load (cl, file, &error))
+ {
+ remove_gui (ANJUTA_PLUGIN_GTODO (plugin));
+ anjuta_util_dialog_error (GTK_WINDOW (plugin->shell), "Unable to load todo file: %s", error->message);
+ g_error_free (error);
+ error = NULL;
+ }
+ else
+ {
+ create_gui (ANJUTA_PLUGIN_GTODO (plugin));
+ }
g_free (default_todo);
g_object_unref (file);
}
@@ -140,64 +237,24 @@
static gboolean
activate_plugin (AnjutaPlugin *plugin)
{
- GtkWidget *wid;
- AnjutaUI *ui;
- AnjutaPreferences *prefs;
GTodoPlugin *gtodo_plugin;
- GtkAction* hide_due;
- GtkAction* hide_nodate;
- GtkAction* hide_done;
static gboolean initialized;
DEBUG_PRINT ("%s", "GTodoPlugin: Activating Task manager plugin ...");
gtodo_plugin = ANJUTA_PLUGIN_GTODO (plugin);
- ui = anjuta_shell_get_ui (plugin->shell, NULL);
- prefs = anjuta_shell_get_preferences (plugin->shell, NULL);
-
if (!initialized)
{
gtodo_load_settings();
}
- wid = gui_create_todo_widget();
- gtk_widget_show_all (wid);
- gtodo_plugin->widget = wid;
- /* Add all our editor actions */
- gtodo_plugin->action_group =
- anjuta_ui_add_action_group_entries (ui, "ActionGroupTodoView",
- _("Tasks manager"),
- actions_todo_view,
- G_N_ELEMENTS (actions_todo_view),
- GETTEXT_PACKAGE, FALSE, plugin);
- gtodo_plugin->action_group2 =
- anjuta_ui_add_toggle_action_group_entries (ui, "ActionGroupTodoViewOps",
- _("Tasks manager view"),
- actions_view,
- G_N_ELEMENTS (actions_view),
- GETTEXT_PACKAGE, TRUE, plugin);
- gtodo_plugin->uiid = anjuta_ui_merge (ui, UI_FILE);
- anjuta_shell_add_widget (plugin->shell, wid,
- "AnjutaTodoPlugin", _("Tasks"),
- "gtodo", /* Icon stock */
- ANJUTA_SHELL_PLACEMENT_CENTER, NULL);
+ create_gui (ANJUTA_PLUGIN_GTODO (plugin));
+
/* set up project directory watch */
gtodo_plugin->root_watch_id = anjuta_plugin_add_watch (plugin,
IANJUTA_PROJECT_MANAGER_PROJECT_ROOT_URI,
project_root_added,
project_root_removed, NULL);
- hide_done = anjuta_ui_get_action (ui, "ActionGroupTodoViewOps",
- "ActionViewTodoHideCompleted");
- g_object_set(G_OBJECT(hide_done), "active",
- gtodo_get_hide_done(), NULL);
- hide_due = anjuta_ui_get_action (ui, "ActionGroupTodoViewOps",
- "ActionViewTodoHideDueDate");
- g_object_set(G_OBJECT(hide_due), "active",
- gtodo_get_hide_due(), NULL);
- hide_nodate = anjuta_ui_get_action (ui, "ActionGroupTodoViewOps",
- "ActionViewTodoHideEndDate");
- g_object_set(G_OBJECT(hide_nodate), "active",
- gtodo_get_hide_nodate(), NULL);
initialized = TRUE;
return TRUE;
@@ -207,26 +264,15 @@
deactivate_plugin (AnjutaPlugin *plugin)
{
GTodoPlugin *gplugin = ANJUTA_PLUGIN_GTODO (plugin);
- AnjutaUI *ui = anjuta_shell_get_ui (plugin->shell, NULL);
DEBUG_PRINT ("%s", "GTodoPlugin: Dectivating Tasks manager plugin ...");
anjuta_plugin_remove_watch (plugin, gplugin->root_watch_id, TRUE);
+
+ remove_gui (gplugin);
- /* Container holds the last ref to this widget so it will be destroyed as
- * soon as removed. No need to separately destroy it. */
- anjuta_shell_remove_widget (plugin->shell, gplugin->widget,
- NULL);
- anjuta_ui_unmerge (ui, gplugin->uiid);
- anjuta_ui_remove_action_group (ui, gplugin->action_group2);
- anjuta_ui_remove_action_group (ui, gplugin->action_group);
-
-
- gplugin->uiid = 0;
- gplugin->widget = NULL;
gplugin->root_watch_id = 0;
- gplugin->action_group = NULL;
- gplugin->action_group2 = NULL;
+
return TRUE;
}
@@ -263,10 +309,17 @@
}
static void
-itodo_load (IAnjutaTodo *profile, GFile* file, GError **err)
+itodo_load (IAnjutaTodo *plugin, GFile* file, GError **err)
{
g_return_if_fail (file != NULL);
- gtodo_client_load (cl, file);
+ if (!gtodo_client_load (cl, file, err))
+ {
+ remove_gui (ANJUTA_PLUGIN_GTODO (plugin));
+ }
+ else
+ {
+ create_gui (ANJUTA_PLUGIN_GTODO (plugin));
+ }
}
static void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]