From 8a9d50f560ee0d5d26c77b5868af2baa0ab0bb2f Mon Sep 17 00:00:00 2001 From: Ettore Perazzoli Date: Tue, 3 Jul 2001 13:29:12 +0000 Subject: [The following makes the shell able to create the `shortcuts.xml' file by itself when the file is not present or corrupted. Fixes #3668, failure to handle malformed shortcuts.xml file.] * e-shell.c (e_shell_construct): If the `e_shortcuts_new()' returns an object with no shortcuts in it, fill it in with `e_shortcuts_add_default_group()'. * e-shortcuts.c: New member `num_groups' in EShortcutsPrivate. (init): Init to zero. (e_shortcuts_add_group): Increment. (e_shortcuts_remove_group): Decrement. (e_shortcuts_get_num_groups): New. (e_shortcuts_add_default_group): New function to set up the default shortcuts. (e_shortcuts_new): Return an empty EShortcuts object if loading the file files, instead of returning NULL. svn path=/trunk/; revision=10744 --- shell/e-shortcuts.c | 34 ++++++++++++++++++++++++++++++---- 1 file changed, 30 insertions(+), 4 deletions(-) (limited to 'shell/e-shortcuts.c') diff --git a/shell/e-shortcuts.c b/shell/e-shortcuts.c index 5f1614a964..8c708254c8 100644 --- a/shell/e-shortcuts.c +++ b/shell/e-shortcuts.c @@ -97,6 +97,9 @@ struct _EShortcutsPrivate { /* The folder type registry. */ EFolderTypeRegistry *folder_type_registry; + /* Total number of groups. */ + int num_groups; + /* A list of ShortcutGroups. */ GSList *groups; @@ -681,6 +684,7 @@ init (EShortcuts *shortcuts) priv->file_name = NULL; priv->storage_set = NULL; + priv->num_groups = 0; priv->groups = NULL; priv->views = NULL; priv->dirty = 0; @@ -731,15 +735,21 @@ e_shortcuts_new (EStorageSet *storage_set, new = gtk_type_new (e_shortcuts_get_type ()); e_shortcuts_construct (new, storage_set, folder_type_registry); - if (! e_shortcuts_load (new, file_name)) { - gtk_object_unref (GTK_OBJECT (new)); - return NULL; - } + e_shortcuts_load (new, file_name); return new; } +int +e_shortcuts_get_num_groups (EShortcuts *shortcuts) +{ + g_return_val_if_fail (shortcuts != NULL, 0); + g_return_val_if_fail (E_IS_SHORTCUTS (shortcuts), 0); + + return shortcuts->priv->num_groups; +} + GSList * e_shortcuts_get_group_titles (EShortcuts *shortcuts) { @@ -976,6 +986,20 @@ e_shortcuts_update_shortcut (EShortcuts *shortcuts, } +void +e_shortcuts_add_default_group (EShortcuts *shortcuts) +{ + g_return_if_fail (shortcuts != NULL); + g_return_if_fail (E_IS_SHORTCUTS (shortcuts)); + + e_shortcuts_add_group (shortcuts, -1, _("Shortcuts")); + + e_shortcuts_add_shortcut (shortcuts, 0, -1, "evolution:/local/Inbox", _("Inbox"), "mail"); + e_shortcuts_add_shortcut (shortcuts, 0, -1, "evolution:/local/Calendar", _("Calendar"), "calendar"); + e_shortcuts_add_shortcut (shortcuts, 0, -1, "evolution:/local/Tasks", _("Tasks"), "tasks"); + e_shortcuts_add_shortcut (shortcuts, 0, -1, "evolution:/local/Contacts", _("Contacts"), "contacts"); +} + void e_shortcuts_remove_group (EShortcuts *shortcuts, int group_num) @@ -996,6 +1020,7 @@ e_shortcuts_remove_group (EShortcuts *shortcuts, shortcut_group_free ((ShortcutGroup *) p->data); priv->groups = g_slist_remove_link (priv->groups, p); + priv->num_groups --; make_dirty (shortcuts); } @@ -1047,6 +1072,7 @@ e_shortcuts_add_group (EShortcuts *shortcuts, group_num = g_slist_length (priv->groups); priv->groups = g_slist_insert (priv->groups, group, group_num); + priv->num_groups ++; gtk_signal_emit (GTK_OBJECT (shortcuts), signals[NEW_GROUP], group_num); -- cgit v1.2.3