diff options
author | Matthew Barnes <mbarnes@redhat.com> | 2009-12-15 01:47:38 +0800 |
---|---|---|
committer | Matthew Barnes <mbarnes@redhat.com> | 2009-12-15 09:11:38 +0800 |
commit | 5ba8caffba174a468359cdb9a7da83bf1fad6033 (patch) | |
tree | d80941ee46b45fedd54e378fee04511e6e6cd65d /mail | |
parent | ca899cf1cbed85d333e19437512aab63dd866a0e (diff) | |
download | gsoc2013-evolution-5ba8caffba174a468359cdb9a7da83bf1fad6033.tar gsoc2013-evolution-5ba8caffba174a468359cdb9a7da83bf1fad6033.tar.gz gsoc2013-evolution-5ba8caffba174a468359cdb9a7da83bf1fad6033.tar.bz2 gsoc2013-evolution-5ba8caffba174a468359cdb9a7da83bf1fad6033.tar.lz gsoc2013-evolution-5ba8caffba174a468359cdb9a7da83bf1fad6033.tar.xz gsoc2013-evolution-5ba8caffba174a468359cdb9a7da83bf1fad6033.tar.zst gsoc2013-evolution-5ba8caffba174a468359cdb9a7da83bf1fad6033.zip |
Introduce EMailSidebar into libevolution-mail.
EMailSidebar is a subclass of EMFolderTree that implements the state
saving and restoration feature from EMailShellSidebar. Placing this
in the shared mail library allows Anjal to reuse it.
Diffstat (limited to 'mail')
-rw-r--r-- | mail/Makefile.am | 2 | ||||
-rw-r--r-- | mail/e-mail-sidebar.c | 616 | ||||
-rw-r--r-- | mail/e-mail-sidebar.h | 87 | ||||
-rw-r--r-- | mail/em-folder-tree.c | 385 |
4 files changed, 900 insertions, 190 deletions
diff --git a/mail/Makefile.am b/mail/Makefile.am index e06b175e7d..2f0f5c94ca 100644 --- a/mail/Makefile.am +++ b/mail/Makefile.am @@ -48,6 +48,7 @@ mailinclude_HEADERS = \ e-mail-reader.h \ e-mail-reader-utils.h \ e-mail-search-bar.h \ + e-mail-sidebar.h \ e-mail-store.h \ e-mail-tag-editor.h \ e-searching-tokenizer.h \ @@ -104,6 +105,7 @@ libevolution_mail_la_SOURCES = \ e-mail-reader.c \ e-mail-reader-utils.c \ e-mail-search-bar.c \ + e-mail-sidebar.c \ e-mail-store.c \ e-mail-tag-editor.c \ e-searching-tokenizer.c \ diff --git a/mail/e-mail-sidebar.c b/mail/e-mail-sidebar.c new file mode 100644 index 0000000000..95379e51a5 --- /dev/null +++ b/mail/e-mail-sidebar.c @@ -0,0 +1,616 @@ +/* + * e-mail-sidebar.c + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) version 3. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with the program; if not, see <http://www.gnu.org/licenses/> + * + * + * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) + * + */ + +#include "e-mail-sidebar.h" + +#include <string.h> +#include <camel/camel.h> + +#include "mail/e-mail-local.h" +#include "mail/em-utils.h" + +#define E_MAIL_SIDEBAR_GET_PRIVATE(obj) \ + (G_TYPE_INSTANCE_GET_PRIVATE \ + ((obj), E_TYPE_MAIL_SIDEBAR, EMailSidebarPrivate)) + +#define STATE_KEY_EXPANDED "Expanded" + +struct _EMailSidebarPrivate { + GKeyFile *key_file; /* not owned */ +}; + +enum { + PROP_0, + PROP_KEY_FILE +}; + +enum { + KEY_FILE_CHANGED, + LAST_SIGNAL +}; + +static gpointer parent_class; +static guint signals[LAST_SIGNAL]; + +static void +mail_sidebar_restore_state (EMailSidebar *sidebar) +{ + EMFolderTree *folder_tree; + GtkTreeModel *tree_model; + GtkTreeView *tree_view; + GtkTreeIter iter; + GKeyFile *key_file; + gboolean valid; + gchar *selected; + gchar **groups; + gint ii; + + key_file = e_mail_sidebar_get_key_file (sidebar); + + /* Make sure we have a key file to restore state from. */ + if (key_file == NULL) + return; + + folder_tree = EM_FOLDER_TREE (sidebar); + + tree_view = GTK_TREE_VIEW (sidebar); + tree_model = gtk_tree_view_get_model (tree_view); + + /* Restore selected folder. */ + + selected = g_key_file_get_string ( + key_file, "Folder Tree", "Selected", NULL); + if (selected != NULL) { + em_folder_tree_set_selected (folder_tree, selected, FALSE); + g_free (selected); + } + + /* Set the initial folder tree expanded state in two stages: + * + * 1) Iterate over the "Store" and "Folder" state file groups + * and apply the "Expanded" keys where possible. + * + * 2) Iterate over the top-level nodes in the folder tree + * (these are all stores) and expand those that have no + * corresponding "Expanded" key in the state file. This + * ensures that new stores are expanded by default. + */ + + /* Stage 1 */ + + /* Collapse all so we have a clean slate. */ + gtk_tree_view_collapse_all (tree_view); + + groups = g_key_file_get_groups (key_file, NULL); + + for (ii = 0; groups[ii] != NULL; ii++) { + GtkTreeRowReference *reference; + GtkTreePath *path; + GtkTreeIter iter; + const gchar *group_name = groups[ii]; + const gchar *key = STATE_KEY_EXPANDED; + const gchar *uri; + gboolean expanded; + + if (g_str_has_prefix (group_name, "Store ")) { + uri = group_name + 6; + expanded = TRUE; + } else if (g_str_has_prefix (group_name, "Folder ")) { + uri = group_name + 7; + expanded = FALSE; + } else + continue; + + if (g_key_file_has_key (key_file, group_name, key, NULL)) + expanded = g_key_file_get_boolean ( + key_file, group_name, key, NULL); + + if (!expanded) + continue; + + reference = em_folder_tree_model_lookup_uri ( + EM_FOLDER_TREE_MODEL (tree_model), uri); + if (reference == NULL) + continue; + + path = gtk_tree_row_reference_get_path (reference); + gtk_tree_model_get_iter (tree_model, &iter, path); + gtk_tree_view_expand_row (tree_view, path, FALSE); + gtk_tree_path_free (path); + } + + g_strfreev (groups); + + /* Stage 2 */ + + valid = gtk_tree_model_get_iter_first (tree_model, &iter); + + while (valid) { + const gchar *key = STATE_KEY_EXPANDED; + gchar *group_name; + gchar *uri; + + gtk_tree_model_get ( + tree_model, &iter, COL_STRING_URI, &uri, -1); + + if (uri == NULL) + goto next; + + group_name = g_strdup_printf ("Store %s", uri); + + if (!g_key_file_has_key (key_file, group_name, key, NULL)) { + GtkTreePath *path; + + path = gtk_tree_model_get_path (tree_model, &iter); + gtk_tree_view_expand_row (tree_view, path, FALSE); + gtk_tree_path_free (path); + } + + g_free (group_name); + g_free (uri); + + next: + valid = gtk_tree_model_iter_next (tree_model, &iter); + } +} + +static void +mail_sidebar_model_loaded_row_cb (GtkTreeModel *model, + GtkTreePath *path, + GtkTreeIter *iter, + EMailSidebar *sidebar) +{ + GtkTreeView *tree_view; + GKeyFile *key_file; + gboolean expanded; + gboolean is_folder; + gboolean is_store; + const gchar *key; + gchar *group_name; + gchar *uri; + + tree_view = GTK_TREE_VIEW (sidebar); + key_file = e_mail_sidebar_get_key_file (sidebar); + + /* Make sure we have a key file to record state changes. */ + if (key_file == NULL) + return; + + gtk_tree_model_get ( + model, iter, + COL_STRING_URI, &uri, + COL_BOOL_IS_STORE, &is_store, + COL_BOOL_IS_FOLDER, &is_folder, -1); + + g_return_if_fail (is_store || is_folder); + + key = STATE_KEY_EXPANDED; + if (is_store) { + group_name = g_strdup_printf ("Store %s", uri); + expanded = TRUE; + } else { + group_name = g_strdup_printf ("Folder %s", uri); + expanded = FALSE; + } + + if (g_key_file_has_key (key_file, group_name, key, NULL)) + expanded = g_key_file_get_boolean ( + key_file, group_name, key, NULL); + + if (expanded) + gtk_tree_view_expand_row (tree_view, path, FALSE); + + g_free (group_name); + g_free (uri); +} + +static void +mail_sidebar_selection_changed_cb (GtkTreeSelection *selection, + EMailSidebar *sidebar) +{ + GtkTreeModel *model; + GtkTreeIter iter; + GKeyFile *key_file; + gchar *uri = NULL; + + key_file = e_mail_sidebar_get_key_file (sidebar); + + /* Make sure we have a key file to record state changes. */ + if (key_file == NULL) + return; + + if (gtk_tree_selection_get_selected (selection, &model, &iter)) + gtk_tree_model_get (model, &iter, COL_STRING_URI, &uri, -1); + + if (uri != NULL) + g_key_file_set_string ( + key_file, "Folder Tree", "Selected", uri); + else + g_key_file_remove_key ( + key_file, "Folder Tree", "Selected", NULL); + + e_mail_sidebar_key_file_changed (sidebar); +} + +static void +mail_sidebar_set_property (GObject *object, + guint property_id, + const GValue *value, + GParamSpec *pspec) +{ + switch (property_id) { + case PROP_KEY_FILE: + e_mail_sidebar_set_key_file ( + E_MAIL_SIDEBAR (object), + g_value_get_pointer (value)); + return; + } + + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); +} + +static void +mail_sidebar_get_property (GObject *object, + guint property_id, + GValue *value, + GParamSpec *pspec) +{ + switch (property_id) { + case PROP_KEY_FILE: + g_value_set_pointer ( + value, e_mail_sidebar_get_key_file ( + E_MAIL_SIDEBAR (object))); + return; + } + + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); +} + +static void +mail_sidebar_row_expanded (GtkTreeView *tree_view, + GtkTreeIter *unused, + GtkTreePath *path) +{ + GtkTreeViewClass *tree_view_class; + EMailSidebar *sidebar; + GtkTreeModel *model; + GKeyFile *key_file; + const gchar *key; + gboolean is_folder; + gboolean is_store; + gchar *group_name; + gchar *uri; + + /* Chain up to parent's row_expanded() method. Do this first + * because we stomp on the path argument a few lines down. */ + tree_view_class = GTK_TREE_VIEW_CLASS (parent_class); + tree_view_class->row_expanded (tree_view, unused, path); + + sidebar = E_MAIL_SIDEBAR (tree_view); + key_file = e_mail_sidebar_get_key_file (sidebar); + + /* Make sure we have a key file to record state changes. */ + if (key_file == NULL) + return; + + path = gtk_tree_path_copy (path); + model = gtk_tree_view_get_model (tree_view); + + /* Expand the node and all ancestors. */ + while (gtk_tree_path_get_depth (path) > 0) { + GtkTreeIter iter; + + gtk_tree_model_get_iter (model, &iter, path); + + gtk_tree_model_get ( + model, &iter, + COL_STRING_URI, &uri, + COL_BOOL_IS_STORE, &is_store, + COL_BOOL_IS_FOLDER, &is_folder, -1); + + g_return_if_fail (is_store || is_folder); + + key = STATE_KEY_EXPANDED; + if (is_store) + group_name = g_strdup_printf ("Store %s", uri); + else + group_name = g_strdup_printf ("Folder %s", uri); + + g_key_file_set_boolean (key_file, group_name, key, TRUE); + e_mail_sidebar_key_file_changed (sidebar); + + g_free (group_name); + g_free (uri); + + gtk_tree_path_up (path); + } + + gtk_tree_path_free (path); +} + +static void +mail_sidebar_row_collapsed (GtkTreeView *tree_view, + GtkTreeIter *iter, + GtkTreePath *path) +{ + EMailSidebar *sidebar; + GtkTreeModel *model; + GKeyFile *key_file; + const gchar *key; + gboolean is_folder; + gboolean is_store; + gchar *group_name; + gchar *uri; + + sidebar = E_MAIL_SIDEBAR (tree_view); + key_file = e_mail_sidebar_get_key_file (sidebar); + + /* Make sure we have a key file to record state changes. */ + if (key_file == NULL) + return; + + model = gtk_tree_view_get_model (tree_view); + + gtk_tree_model_get ( + model, iter, + COL_STRING_URI, &uri, + COL_BOOL_IS_STORE, &is_store, + COL_BOOL_IS_FOLDER, &is_folder, -1); + + g_return_if_fail (is_store || is_folder); + + key = STATE_KEY_EXPANDED; + if (is_store) + group_name = g_strdup_printf ("Store %s", uri); + else + group_name = g_strdup_printf ("Folder %s", uri); + + g_key_file_set_boolean (key_file, group_name, key, FALSE); + e_mail_sidebar_key_file_changed (sidebar); + + g_free (group_name); + g_free (uri); +} + +static guint32 +mail_sidebar_check_state (EMailSidebar *sidebar) +{ + GtkTreeSelection *selection; + GtkTreeView *tree_view; + GtkTreeModel *model; + GtkTreeIter iter; + CamelStore *local_store; + CamelStore *store; + gchar *full_name; + gchar *uri; + gboolean allows_children = TRUE; + gboolean can_delete = TRUE; + gboolean is_junk = FALSE; + gboolean is_outbox = FALSE; + gboolean is_store; + gboolean is_trash = FALSE; + guint32 folder_flags = 0; + guint32 state = 0; + + local_store = e_mail_local_get_store (); + + tree_view = GTK_TREE_VIEW (sidebar); + selection = gtk_tree_view_get_selection (tree_view); + + if (!gtk_tree_selection_get_selected (selection, &model, &iter)) + return 0; + + gtk_tree_model_get ( + model, &iter, + COL_POINTER_CAMEL_STORE, &store, + COL_STRING_FULL_NAME, &full_name, + COL_BOOL_IS_STORE, &is_store, + COL_UINT_FLAGS, &folder_flags, + COL_STRING_URI, &uri, -1); + + if (!is_store && full_name != NULL) { + guint32 folder_type; + + /* Is this a virtual junk or trash folder? */ + is_junk = (strcmp (full_name, CAMEL_VJUNK_NAME) == 0); + is_trash = (strcmp (full_name, CAMEL_VTRASH_NAME) == 0); + + /* Is this a real trash folder? + * Used by Exchange and GroupWise accounts. */ + folder_type = (folder_flags & CAMEL_FOLDER_TYPE_MASK); + is_trash |= (folder_type == CAMEL_FOLDER_TYPE_TRASH); + + allows_children = !(is_junk || is_trash); + + /* Don't allow deletion of special local folders. */ + if (store == local_store) + can_delete = + (strcmp (full_name, "Drafts") != 0) && + (strcmp (full_name, "Inbox") != 0) && + (strcmp (full_name, "Outbox") != 0) && + (strcmp (full_name, "Sent") != 0) && + (strcmp (full_name, "Templates") != 0); + + is_outbox = em_utils_folder_is_outbox (NULL, uri); + can_delete &= !(folder_flags & CAMEL_FOLDER_SYSTEM); + } + + if (allows_children) + state |= E_MAIL_SIDEBAR_FOLDER_ALLOWS_CHILDREN; + if (can_delete) + state |= E_MAIL_SIDEBAR_FOLDER_CAN_DELETE; + if (is_junk) + state |= E_MAIL_SIDEBAR_FOLDER_IS_JUNK; + if (is_outbox) + state |= E_MAIL_SIDEBAR_FOLDER_IS_OUTBOX; + if (is_store) + state |= E_MAIL_SIDEBAR_FOLDER_IS_STORE; + if (is_trash) + state |= E_MAIL_SIDEBAR_FOLDER_IS_TRASH; + + return state; +} + +static void +mail_sidebar_class_init (EMailSidebarClass *class) +{ + GObjectClass *object_class; + GtkTreeViewClass *tree_view_class; + + parent_class = g_type_class_peek_parent (class); + g_type_class_add_private (class, sizeof (EMailSidebarPrivate)); + + object_class = G_OBJECT_CLASS (class); + object_class->set_property = mail_sidebar_set_property; + object_class->get_property = mail_sidebar_get_property; + + tree_view_class = GTK_TREE_VIEW_CLASS (class); + tree_view_class->row_expanded = mail_sidebar_row_expanded; + tree_view_class->row_collapsed = mail_sidebar_row_collapsed; + + class->check_state = mail_sidebar_check_state; + + g_object_class_install_property ( + object_class, + PROP_KEY_FILE, + g_param_spec_pointer ( + "key-file", + "Key File", + NULL, + G_PARAM_READWRITE)); + + signals[KEY_FILE_CHANGED] = g_signal_new ( + "key-file-changed", + G_OBJECT_CLASS_TYPE (object_class), + G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION, + G_STRUCT_OFFSET (EMailSidebarClass, key_file_changed), + NULL, NULL, + g_cclosure_marshal_VOID__VOID, + G_TYPE_NONE, 0); +} + +static void +mail_sidebar_init (EMailSidebar *sidebar) +{ + GtkTreeModel *model; + GtkTreeView *tree_view; + GtkTreeSelection *selection; + EMFolderTree *folder_tree; + + sidebar->priv = E_MAIL_SIDEBAR_GET_PRIVATE (sidebar); + + folder_tree = EM_FOLDER_TREE (sidebar); + em_folder_tree_set_excluded (folder_tree, 0); + em_folder_tree_enable_drag_and_drop (folder_tree); + + tree_view = GTK_TREE_VIEW (sidebar); + model = gtk_tree_view_get_model (tree_view); + selection = gtk_tree_view_get_selection (tree_view); + + em_folder_tree_model_set_selection ( + EM_FOLDER_TREE_MODEL (model), selection); + + g_signal_connect ( + model, "loaded-row", + G_CALLBACK (mail_sidebar_model_loaded_row_cb), sidebar); + + g_signal_connect ( + selection, "changed", + G_CALLBACK (mail_sidebar_selection_changed_cb), sidebar); +} + +GType +e_mail_sidebar_get_type (void) +{ + static GType type = 0; + + if (G_UNLIKELY (type == 0)) { + static const GTypeInfo type_info = { + sizeof (EMailSidebarClass), + (GBaseInitFunc) NULL, + (GBaseFinalizeFunc) NULL, + (GClassInitFunc) mail_sidebar_class_init, + (GClassFinalizeFunc) NULL, + NULL, /* class_data */ + sizeof (EMailSidebar), + 0, /* n_preallocs */ + (GInstanceInitFunc) mail_sidebar_init, + NULL /* value_table */ + }; + + type = g_type_register_static ( + EM_TYPE_FOLDER_TREE, "EMailSidebar", &type_info, 0); + } + + return type; +} + +GtkWidget * +e_mail_sidebar_new (void) +{ + return g_object_new (E_TYPE_MAIL_SIDEBAR, NULL); +} + +GKeyFile * +e_mail_sidebar_get_key_file (EMailSidebar *sidebar) +{ + g_return_val_if_fail (E_IS_MAIL_SIDEBAR (sidebar), NULL); + + return sidebar->priv->key_file; +} + +void +e_mail_sidebar_set_key_file (EMailSidebar *sidebar, + GKeyFile *key_file) +{ + g_return_if_fail (E_IS_MAIL_SIDEBAR (sidebar)); + + /* XXX GKeyFile has no reference count, so all we can do is + * replace the old pointer and hope the key file is not + * freed on us. Most other GLib data structures have + * grown reference counts so maybe this should too. */ + sidebar->priv->key_file = key_file; + + mail_sidebar_restore_state (sidebar); + + g_object_notify (G_OBJECT (sidebar), "key-file"); +} + +guint32 +e_mail_sidebar_check_state (EMailSidebar *sidebar) +{ + EMailSidebarClass *class; + + g_return_val_if_fail (E_IS_MAIL_SIDEBAR (sidebar), 0); + + class = E_MAIL_SIDEBAR_GET_CLASS (sidebar); + g_return_val_if_fail (class->check_state != NULL, 0); + + return class->check_state (sidebar); +} + +void +e_mail_sidebar_key_file_changed (EMailSidebar *sidebar) +{ + g_return_if_fail (E_IS_MAIL_SIDEBAR (sidebar)); + + g_signal_emit (sidebar, signals[KEY_FILE_CHANGED], 0); +} diff --git a/mail/e-mail-sidebar.h b/mail/e-mail-sidebar.h new file mode 100644 index 0000000000..f08c05d2fe --- /dev/null +++ b/mail/e-mail-sidebar.h @@ -0,0 +1,87 @@ +/* + * e-mail-sidebar.h + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) version 3. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with the program; if not, see <http://www.gnu.org/licenses/> + * + * + * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) + * + */ + +#ifndef E_MAIL_SIDEBAR_H +#define E_MAIL_SIDEBAR_H + +#include <mail/em-folder-tree.h> + +/* Standard GObject macros */ +#define E_TYPE_MAIL_SIDEBAR \ + (e_mail_sidebar_get_type ()) +#define E_MAIL_SIDEBAR(obj) \ + (G_TYPE_CHECK_INSTANCE_CAST \ + ((obj), E_TYPE_MAIL_SIDEBAR, EMailSidebar)) +#define E_MAIL_SIDEBAR_CLASS(cls) \ + (G_TYPE_CHECK_CLASS_CAST \ + ((cls), E_TYPE_MAIL_SIDEBAR, EMailSidebarClass)) +#define E_IS_MAIL_SIDEBAR(obj) \ + (G_TYPE_CHECK_INSTANCE_TYPE \ + ((obj), E_TYPE_MAIL_SIDEBAR)) +#define E_IS_MAIL_SIDEBAR_CLASS(cls) \ + (G_TYPE_CHECK_CLASS_TYPE \ + ((cls), E_TYPE_MAIL_SIDEBAR)) +#define E_MAIL_SIDEBAR_GET_CLASS(obj) \ + (G_TYPE_INSTANCE_GET_CLASS \ + ((obj), E_TYPE_MAIL_SIDEBAR, EMailSidebarClass)) + +G_BEGIN_DECLS + +typedef struct _EMailSidebar EMailSidebar; +typedef struct _EMailSidebarClass EMailSidebarClass; +typedef struct _EMailSidebarPrivate EMailSidebarPrivate; + +/* Flags describing the selected folder. */ +enum { + E_MAIL_SIDEBAR_FOLDER_ALLOWS_CHILDREN = 1 << 0, + E_MAIL_SIDEBAR_FOLDER_CAN_DELETE = 1 << 1, + E_MAIL_SIDEBAR_FOLDER_IS_JUNK = 1 << 2, + E_MAIL_SIDEBAR_FOLDER_IS_OUTBOX = 1 << 3, + E_MAIL_SIDEBAR_FOLDER_IS_STORE = 1 << 4, + E_MAIL_SIDEBAR_FOLDER_IS_TRASH = 1 << 5 +}; + +struct _EMailSidebar { + EMFolderTree parent; + EMailSidebarPrivate *priv; +}; + +struct _EMailSidebarClass { + EMFolderTreeClass parent; + + /* Methods */ + guint32 (*check_state) (EMailSidebar *sidebar); + + /* Signals */ + void (*key_file_changed) (EMailSidebar *sidebar); +}; + +GType e_mail_sidebar_get_type (void); +GtkWidget * e_mail_sidebar_new (void); +GKeyFile * e_mail_sidebar_get_key_file (EMailSidebar *sidebar); +void e_mail_sidebar_set_key_file (EMailSidebar *sidebar, + GKeyFile *key_file); +guint32 e_mail_sidebar_check_state (EMailSidebar *sidebar); +void e_mail_sidebar_key_file_changed (EMailSidebar *sidebar); + +G_END_DECLS + +#endif /* E_MAIL_SIDEBAR_H */ diff --git a/mail/em-folder-tree.c b/mail/em-folder-tree.c index 4a336d1fe4..c439961572 100644 --- a/mail/em-folder-tree.c +++ b/mail/em-folder-tree.c @@ -381,6 +381,154 @@ folder_tree_select_func (GtkTreeSelection *selection, return (flags & priv->excluded) == 0; } +/* NOTE: Removes and frees the selected uri structure */ +static void +folder_tree_select_uri (EMFolderTree *folder_tree, + GtkTreePath *path, + struct _selected_uri *u) +{ + EMFolderTreePrivate *priv = folder_tree->priv; + GtkTreeView *tree_view; + GtkTreeSelection *selection; + + tree_view = GTK_TREE_VIEW (folder_tree); + selection = gtk_tree_view_get_selection (tree_view); + gtk_tree_selection_select_path(selection, path); + if (!priv->cursor_set) { + gtk_tree_view_set_cursor (tree_view, path, NULL, FALSE); + priv->cursor_set = TRUE; + } + gtk_tree_view_scroll_to_cell (tree_view, path, NULL, TRUE, 0.8f, 0.0f); + g_hash_table_remove(priv->select_uris_table, u->key); + priv->select_uris = g_slist_remove(priv->select_uris, u); + folder_tree_free_select_uri(u); +} + +static void +folder_tree_expand_node (const gchar *key, + EMFolderTree *folder_tree) +{ + struct _EMFolderTreeModelStoreInfo *si; + GtkTreeRowReference *row; + GtkTreeView *tree_view; + GtkTreeModel *model; + GtkTreePath *path; + EAccount *account; + CamelStore *store; + const gchar *p; + gchar *uid; + gsize n; + struct _selected_uri *u; + + if (!(p = strchr (key, '/'))) + n = strlen (key); + else + n = (p - key); + + uid = g_alloca (n + 1); + memcpy (uid, key, n); + uid[n] = '\0'; + + tree_view = GTK_TREE_VIEW (folder_tree); + model = gtk_tree_view_get_model (tree_view); + + if ((account = e_get_account_by_uid (uid)) && account->enabled) { + CamelException ex; + + camel_exception_init (&ex); + store = (CamelStore *) camel_session_get_service (session, account->source->url, CAMEL_PROVIDER_STORE, &ex); + camel_exception_clear (&ex); + + if (store == NULL) + return; + } else if (!strcmp (uid, "vfolder")) { + if (!(store = vfolder_store)) + return; + + camel_object_ref (store); + } else if (!strcmp (uid, "local")) { + if (!(store = e_mail_local_get_store ())) + return; + + camel_object_ref (store); + } else { + return; + } + + si = em_folder_tree_model_lookup_store_info ( + EM_FOLDER_TREE_MODEL (model), store); + if (si == NULL) { + camel_object_unref (store); + return; + } + + camel_object_unref (store); + + if (p != NULL) { + if (!(row = g_hash_table_lookup (si->full_hash, p + 1))) + return; + } else + row = si->row; + + path = gtk_tree_row_reference_get_path (row); + gtk_tree_view_expand_to_path (tree_view, path); + + u = g_hash_table_lookup(folder_tree->priv->select_uris_table, key); + if (u) + folder_tree_select_uri(folder_tree, path, u); + + gtk_tree_path_free (path); +} + +static void +folder_tree_maybe_expand_row (EMFolderTreeModel *model, + GtkTreePath *tree_path, + GtkTreeIter *iter, + EMFolderTree *folder_tree) +{ + EMFolderTreePrivate *priv = folder_tree->priv; + struct _EMFolderTreeModelStoreInfo *si; + GtkTreeView *tree_view; + gboolean is_store; + CamelStore *store; + EAccount *account; + gchar *full_name; + gchar *key; + struct _selected_uri *u; + + tree_view = GTK_TREE_VIEW (folder_tree); + + gtk_tree_model_get ((GtkTreeModel *) model, iter, + COL_STRING_FULL_NAME, &full_name, + COL_POINTER_CAMEL_STORE, &store, + COL_BOOL_IS_STORE, &is_store, + -1); + + si = em_folder_tree_model_lookup_store_info (model, store); + if ((account = e_get_account_by_name (si->display_name))) { + key = g_strdup_printf ("%s/%s", account->uid, full_name ? full_name : ""); + } else if (CAMEL_IS_VEE_STORE (store)) { + /* vfolder store */ + key = g_strdup_printf ("vfolder/%s", full_name ? full_name : ""); + } else { + /* local store */ + key = g_strdup_printf ("local/%s", full_name ? full_name : ""); + } + + u = g_hash_table_lookup(priv->select_uris_table, key); + if (u) { + gchar *c = strrchr (key, '/'); + + *c = '\0'; + folder_tree_expand_node (key, folder_tree); + + folder_tree_select_uri(folder_tree, tree_path, u); + } + + g_free (full_name); + g_free (key); +} + static void folder_tree_clear_selected_list(EMFolderTree *folder_tree) { @@ -854,57 +1002,6 @@ folder_tree_class_init (EMFolderTreeClass *class) G_TYPE_NONE, 1, GDK_TYPE_EVENT); } -static void -folder_tree_init (EMFolderTree *folder_tree) -{ - GtkTreeSelection *selection; - GHashTable *select_uris_table; - EMFolderTreeModel *model; - gulong handler_id; - - select_uris_table = g_hash_table_new (g_str_hash, g_str_equal); - - folder_tree->priv = EM_FOLDER_TREE_GET_PRIVATE (folder_tree); - folder_tree->priv->select_uris_table = select_uris_table; - - model = em_folder_tree_model_get_default (); - gtk_tree_view_set_model (GTK_TREE_VIEW (folder_tree), GTK_TREE_MODEL (model)); - - selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (folder_tree)); - - handler_id = g_signal_connect_swapped ( - selection, "changed", - G_CALLBACK (folder_tree_selection_changed_cb), folder_tree); - - folder_tree->priv->selection_changed_handler_id = handler_id; -} - -GType -em_folder_tree_get_type (void) -{ - static GType type = 0; - - if (G_UNLIKELY (type == 0)) { - static const GTypeInfo type_info = { - sizeof (EMFolderTreeClass), - (GBaseInitFunc) NULL, - (GBaseFinalizeFunc) NULL, - (GClassInitFunc) folder_tree_class_init, - (GClassFinalizeFunc) NULL, - NULL, /* class_data */ - sizeof (EMFolderTree), - 0, /* n_preallocs */ - (GInstanceInitFunc) folder_tree_init, - NULL /* value_table */ - }; - - type = g_type_register_static ( - GTK_TYPE_TREE_VIEW, "EMFolderTree", &type_info, 0); - } - - return type; -} - static gboolean subdirs_contain_unread (GtkTreeModel *model, GtkTreeIter *root) { @@ -1144,171 +1241,79 @@ em_folder_tree_construct (EMFolderTree *folder_tree) gtk_widget_show (GTK_WIDGET (folder_tree)); } -/* NOTE: Removes and frees the selected uri structure */ static void -folder_tree_select_uri(EMFolderTree *folder_tree, GtkTreePath *path, struct _selected_uri *u) +folder_tree_init (EMFolderTree *folder_tree) { - EMFolderTreePrivate *priv = folder_tree->priv; GtkTreeView *tree_view; GtkTreeSelection *selection; + GHashTable *select_uris_table; + EMFolderTreeModel *model; + gulong handler_id; + AtkObject *a11y; - tree_view = GTK_TREE_VIEW (folder_tree); - selection = gtk_tree_view_get_selection (tree_view); - gtk_tree_selection_select_path(selection, path); - if (!priv->cursor_set) { - gtk_tree_view_set_cursor (tree_view, path, NULL, FALSE); - priv->cursor_set = TRUE; - } - gtk_tree_view_scroll_to_cell (tree_view, path, NULL, TRUE, 0.8f, 0.0f); - g_hash_table_remove(priv->select_uris_table, u->key); - priv->select_uris = g_slist_remove(priv->select_uris, u); - folder_tree_free_select_uri(u); -} - -static void -folder_tree_expand_node (const gchar *key, EMFolderTree *folder_tree) -{ - struct _EMFolderTreeModelStoreInfo *si; - GtkTreeRowReference *row; - GtkTreeView *tree_view; - GtkTreeModel *model; - GtkTreePath *path; - EAccount *account; - CamelStore *store; - const gchar *p; - gchar *uid; - gsize n; - struct _selected_uri *u; - - if (!(p = strchr (key, '/'))) - n = strlen (key); - else - n = (p - key); + select_uris_table = g_hash_table_new (g_str_hash, g_str_equal); - uid = g_alloca (n + 1); - memcpy (uid, key, n); - uid[n] = '\0'; + folder_tree->priv = EM_FOLDER_TREE_GET_PRIVATE (folder_tree); + folder_tree->priv->select_uris_table = select_uris_table; tree_view = GTK_TREE_VIEW (folder_tree); - model = gtk_tree_view_get_model (tree_view); - - if ((account = e_get_account_by_uid (uid)) && account->enabled) { - CamelException ex; - - camel_exception_init (&ex); - store = (CamelStore *) camel_session_get_service (session, account->source->url, CAMEL_PROVIDER_STORE, &ex); - camel_exception_clear (&ex); - - if (store == NULL) - return; - } else if (!strcmp (uid, "vfolder")) { - if (!(store = vfolder_store)) - return; - - camel_object_ref (store); - } else if (!strcmp (uid, "local")) { - if (!(store = e_mail_local_get_store ())) - return; - - camel_object_ref (store); - } else { - return; - } + model = em_folder_tree_model_get_default (); + selection = gtk_tree_view_get_selection (tree_view); - si = em_folder_tree_model_lookup_store_info ( - EM_FOLDER_TREE_MODEL (model), store); - if (si == NULL) { - camel_object_unref (store); - return; - } + gtk_tree_view_set_model (tree_view, GTK_TREE_MODEL (model)); - camel_object_unref (store); + handler_id = g_signal_connect ( + model, "loading-row", + G_CALLBACK (folder_tree_maybe_expand_row), folder_tree); + folder_tree->priv->loading_row_id = handler_id; - if (p != NULL) { - if (!(row = g_hash_table_lookup (si->full_hash, p + 1))) - return; - } else - row = si->row; + handler_id = g_signal_connect ( + model, "loaded-row", + G_CALLBACK (folder_tree_maybe_expand_row), folder_tree); + folder_tree->priv->loaded_row_id = handler_id; - path = gtk_tree_row_reference_get_path (row); - gtk_tree_view_expand_to_path (tree_view, path); + handler_id = g_signal_connect_swapped ( + selection, "changed", + G_CALLBACK (folder_tree_selection_changed_cb), folder_tree); + folder_tree->priv->selection_changed_handler_id = handler_id; - u = g_hash_table_lookup(folder_tree->priv->select_uris_table, key); - if (u) - folder_tree_select_uri(folder_tree, path, u); + a11y = gtk_widget_get_accessible (GTK_WIDGET (folder_tree)); + atk_object_set_name (a11y, _("Mail Folder Tree")); - gtk_tree_path_free (path); + /* FIXME Kill this thing. */ + em_folder_tree_construct (folder_tree); } -static void -folder_tree_maybe_expand_row (EMFolderTreeModel *model, GtkTreePath *tree_path, GtkTreeIter *iter, EMFolderTree *folder_tree) +GType +em_folder_tree_get_type (void) { - EMFolderTreePrivate *priv = folder_tree->priv; - struct _EMFolderTreeModelStoreInfo *si; - GtkTreeView *tree_view; - gboolean is_store; - CamelStore *store; - EAccount *account; - gchar *full_name; - gchar *key; - struct _selected_uri *u; - - tree_view = GTK_TREE_VIEW (folder_tree); - - gtk_tree_model_get ((GtkTreeModel *) model, iter, - COL_STRING_FULL_NAME, &full_name, - COL_POINTER_CAMEL_STORE, &store, - COL_BOOL_IS_STORE, &is_store, - -1); - - si = em_folder_tree_model_lookup_store_info (model, store); - if ((account = e_get_account_by_name (si->display_name))) { - key = g_strdup_printf ("%s/%s", account->uid, full_name ? full_name : ""); - } else if (CAMEL_IS_VEE_STORE (store)) { - /* vfolder store */ - key = g_strdup_printf ("vfolder/%s", full_name ? full_name : ""); - } else { - /* local store */ - key = g_strdup_printf ("local/%s", full_name ? full_name : ""); - } - - u = g_hash_table_lookup(priv->select_uris_table, key); - if (u) { - gchar *c = strrchr (key, '/'); + static GType type = 0; - *c = '\0'; - folder_tree_expand_node (key, folder_tree); + if (G_UNLIKELY (type == 0)) { + static const GTypeInfo type_info = { + sizeof (EMFolderTreeClass), + (GBaseInitFunc) NULL, + (GBaseFinalizeFunc) NULL, + (GClassInitFunc) folder_tree_class_init, + (GClassFinalizeFunc) NULL, + NULL, /* class_data */ + sizeof (EMFolderTree), + 0, /* n_preallocs */ + (GInstanceInitFunc) folder_tree_init, + NULL /* value_table */ + }; - folder_tree_select_uri(folder_tree, tree_path, u); + type = g_type_register_static ( + GTK_TYPE_TREE_VIEW, "EMFolderTree", &type_info, 0); } - g_free (full_name); - g_free (key); + return type; } GtkWidget * em_folder_tree_new (void) { - EMFolderTree *folder_tree; - GtkTreeModel *model; - AtkObject *a11y; - - folder_tree = g_object_new (EM_TYPE_FOLDER_TREE, NULL); - em_folder_tree_construct (folder_tree); - - model = gtk_tree_view_get_model (GTK_TREE_VIEW (folder_tree)); - - folder_tree->priv->loading_row_id = g_signal_connect ( - model, "loading-row", - G_CALLBACK (folder_tree_maybe_expand_row), folder_tree); - folder_tree->priv->loaded_row_id = g_signal_connect ( - model, "loaded-row", - G_CALLBACK (folder_tree_maybe_expand_row), folder_tree); - - a11y = gtk_widget_get_accessible (GTK_WIDGET (folder_tree)); - atk_object_set_name (a11y, _("Mail Folder Tree")); - - return (GtkWidget *) folder_tree; + return g_object_new (EM_TYPE_FOLDER_TREE, NULL); } static void |