aboutsummaryrefslogtreecommitdiffstats
path: root/mail
diff options
context:
space:
mode:
authorMatthew Barnes <mbarnes@redhat.com>2012-04-09 01:22:25 +0800
committerMatthew Barnes <mbarnes@redhat.com>2012-04-09 02:54:02 +0800
commit9585c43f4e6be99584b7970bbccc0700b0120311 (patch)
tree3605707f646eaabc6b9c0b265328cf251ec574e1 /mail
parent6c04867188a8cae5ec0c02d01176596f96e34d24 (diff)
downloadgsoc2013-evolution-9585c43f4e6be99584b7970bbccc0700b0120311.tar.gz
gsoc2013-evolution-9585c43f4e6be99584b7970bbccc0700b0120311.tar.zst
gsoc2013-evolution-9585c43f4e6be99584b7970bbccc0700b0120311.zip
mail/state.ini: Remember stores by UID instead of URI.
This breaks backward compatibility slightly by changing the way the folder tree "expanded" state for CamelStores is remembered. Instead of naming the [Store ...] key file group after the CamelStore's URI string, we now name it after its UID string.
Diffstat (limited to 'mail')
-rw-r--r--mail/e-mail-sidebar.c79
-rw-r--r--mail/em-folder-tree.c97
2 files changed, 129 insertions, 47 deletions
diff --git a/mail/e-mail-sidebar.c b/mail/e-mail-sidebar.c
index b8dc823648..ef2133aebe 100644
--- a/mail/e-mail-sidebar.c
+++ b/mail/e-mail-sidebar.c
@@ -28,6 +28,8 @@
#include <string.h>
#include <camel/camel.h>
+#include <libemail-engine/e-mail-folder-utils.h>
+
#include "mail/em-utils.h"
#define E_MAIL_SIDEBAR_GET_PRIVATE(obj) \
@@ -91,13 +93,14 @@ mail_sidebar_model_loaded_row_cb (GtkTreeModel *model,
EMailSidebar *sidebar)
{
GtkTreeView *tree_view;
+ CamelStore *store;
GKeyFile *key_file;
gboolean expanded;
gboolean is_folder;
gboolean is_store;
- const gchar *key;
+ gchar *folder_name;
gchar *group_name;
- gchar *uri;
+ const gchar *key;
tree_view = GTK_TREE_VIEW (sidebar);
key_file = e_mail_sidebar_get_key_file (sidebar);
@@ -108,7 +111,8 @@ mail_sidebar_model_loaded_row_cb (GtkTreeModel *model,
gtk_tree_model_get (
model, iter,
- COL_STRING_URI, &uri,
+ COL_POINTER_CAMEL_STORE, &store,
+ COL_STRING_FULL_NAME, &folder_name,
COL_BOOL_IS_STORE, &is_store,
COL_BOOL_IS_FOLDER, &is_folder, -1);
@@ -116,10 +120,17 @@ mail_sidebar_model_loaded_row_cb (GtkTreeModel *model,
key = STATE_KEY_EXPANDED;
if (is_store) {
- group_name = g_strdup_printf ("Store %s", uri);
+ const gchar *uid;
+
+ uid = camel_service_get_uid (CAMEL_SERVICE (store));
+ group_name = g_strdup_printf ("Store %s", uid);
expanded = TRUE;
} else {
+ gchar *uri;
+
+ uri = e_mail_folder_uri_build (store, folder_name);
group_name = g_strdup_printf ("Folder %s", uri);
+ g_free (uri);
expanded = FALSE;
}
@@ -131,7 +142,7 @@ mail_sidebar_model_loaded_row_cb (GtkTreeModel *model,
gtk_tree_view_expand_row (tree_view, path, FALSE);
g_free (group_name);
- g_free (uri);
+ g_free (folder_name);
}
static void
@@ -149,8 +160,18 @@ mail_sidebar_selection_changed_cb (GtkTreeSelection *selection,
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 (gtk_tree_selection_get_selected (selection, &model, &iter)) {
+ CamelStore *store;
+ gchar *folder_name;
+
+ gtk_tree_model_get (
+ model, &iter,
+ COL_POINTER_CAMEL_STORE, &store,
+ COL_STRING_FULL_NAME, &folder_name, -1);
+
+ if (CAMEL_IS_STORE (store) && folder_name != NULL)
+ uri = e_mail_folder_uri_build (store, folder_name);
+ }
if (uri != NULL)
g_key_file_set_string (
@@ -273,7 +294,6 @@ mail_sidebar_row_expanded (GtkTreeView *tree_view,
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. */
@@ -292,29 +312,40 @@ mail_sidebar_row_expanded (GtkTreeView *tree_view,
/* Expand the node and all ancestors. */
while (gtk_tree_path_get_depth (path) > 0) {
+ CamelStore *store;
GtkTreeIter iter;
+ gchar *folder_name;
gtk_tree_model_get_iter (model, &iter, path);
gtk_tree_model_get (
model, &iter,
- COL_STRING_URI, &uri,
+ COL_POINTER_CAMEL_STORE, &store,
+ COL_STRING_FULL_NAME, &folder_name,
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
+ if (is_store) {
+ const gchar *uid;
+
+ uid = camel_service_get_uid (CAMEL_SERVICE (store));
+ group_name = g_strdup_printf ("Store %s", uid);
+ } else {
+ gchar *uri;
+
+ uri = e_mail_folder_uri_build (store, folder_name);
group_name = g_strdup_printf ("Folder %s", uri);
+ g_free (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);
+ g_free (folder_name);
gtk_tree_path_up (path);
}
@@ -330,11 +361,12 @@ mail_sidebar_row_collapsed (GtkTreeView *tree_view,
EMailSidebar *sidebar;
GtkTreeModel *model;
GKeyFile *key_file;
+ CamelStore *store;
const gchar *key;
gboolean is_folder;
gboolean is_store;
+ gchar *folder_name;
gchar *group_name;
- gchar *uri;
sidebar = E_MAIL_SIDEBAR (tree_view);
key_file = e_mail_sidebar_get_key_file (sidebar);
@@ -347,23 +379,32 @@ mail_sidebar_row_collapsed (GtkTreeView *tree_view,
gtk_tree_model_get (
model, iter,
- COL_STRING_URI, &uri,
+ COL_POINTER_CAMEL_STORE, &store,
+ COL_STRING_FULL_NAME, &folder_name,
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
+ if (is_store) {
+ const gchar *uid;
+
+ uid = camel_service_get_uid (CAMEL_SERVICE (store));
+ group_name = g_strdup_printf ("Store %s", uid);
+ } else {
+ gchar *uri;
+
+ uri = e_mail_folder_uri_build (store, folder_name);
group_name = g_strdup_printf ("Folder %s", uri);
+ g_free (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);
+ g_free (folder_name);
}
static guint32
diff --git a/mail/em-folder-tree.c b/mail/em-folder-tree.c
index 4dbbb36224..606721f887 100644
--- a/mail/em-folder-tree.c
+++ b/mail/em-folder-tree.c
@@ -3440,12 +3440,15 @@ em_folder_tree_restore_state (EMFolderTree *folder_tree,
GKeyFile *key_file)
{
EShell *shell;
+ EMFolderTreeModel *folder_tree_model;
+ EMailSession *session;
GtkTreeModel *tree_model;
GtkTreeView *tree_view;
GtkTreeIter iter;
gboolean valid;
gchar **groups_arr;
GSList *groups, *group;
+ gboolean express_mode;
gint ii;
/* Make sure we have a key file to restore state from. */
@@ -3454,10 +3457,15 @@ em_folder_tree_restore_state (EMFolderTree *folder_tree,
/* XXX Pass this in. */
shell = e_shell_get_default ();
+ express_mode = e_shell_get_express_mode (shell);
tree_view = GTK_TREE_VIEW (folder_tree);
tree_model = gtk_tree_view_get_model (tree_view);
+ folder_tree_model = EM_FOLDER_TREE_MODEL (tree_model);
+ session = em_folder_tree_model_get_session (folder_tree_model);
+ g_return_if_fail (E_IS_MAIL_SESSION (session));
+
/* Set the initial folder tree expanded state in two stages:
*
* 1) Iterate over the "Store" and "Folder" state file groups
@@ -3484,39 +3492,66 @@ em_folder_tree_restore_state (EMFolderTree *folder_tree,
groups = g_slist_sort (groups, sort_by_store_and_uri);
for (group = groups; group != NULL; group = group->next) {
- GtkTreeRowReference *reference;
- GtkTreePath *path;
- GtkTreeIter iter;
+ GtkTreeRowReference *reference = NULL;
+ CamelStore *store = NULL;
const gchar *group_name = group->data;
const gchar *key = STATE_KEY_EXPANDED;
- const gchar *uri;
+ gchar *folder_name = NULL;
gboolean expanded;
+ gboolean success = FALSE;
if (g_str_has_prefix (group_name, "Store ")) {
- uri = group_name + 6;
+ CamelService *service;
+ const gchar *uid = group_name + 6;
+
+ service = camel_session_get_service (
+ CAMEL_SESSION (session), uid);
+ if (CAMEL_IS_STORE (service)) {
+ store = g_object_ref (service);
+ success = TRUE;
+ }
expanded = TRUE;
+
} else if (g_str_has_prefix (group_name, "Folder ")) {
- uri = group_name + 7;
+ const gchar *uri = group_name + 7;
+
+ success = e_mail_folder_uri_parse (
+ CAMEL_SESSION (session), uri,
+ &store, &folder_name, NULL);
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;
+ if (expanded && success) {
+ EMFolderTreeModelStoreInfo *si;
- reference = em_folder_tree_model_lookup_uri (
- EM_FOLDER_TREE_MODEL (tree_model), uri);
- if (reference == NULL)
- continue;
+ si = em_folder_tree_model_lookup_store_info (
+ folder_tree_model, store);
+ if (si != NULL) {
+ if (folder_name != NULL)
+ reference = g_hash_table_lookup (
+ si->full_hash, folder_name);
+ else
+ reference = si->row;
+ }
+ }
- 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);
+ if (gtk_tree_row_reference_valid (reference)) {
+ GtkTreePath *path;
+ GtkTreeIter iter;
+
+ 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);
+ }
+
+ if (store != NULL)
+ g_object_unref (store);
+ g_free (folder_name);
}
g_slist_free (groups);
@@ -3527,28 +3562,35 @@ em_folder_tree_restore_state (EMFolderTree *folder_tree,
valid = gtk_tree_model_get_iter_first (tree_model, &iter);
while (valid) {
+ CamelStore *store;
+ CamelService *service;
const gchar *key = STATE_KEY_EXPANDED;
+ const gchar *uid;
gboolean expand_row;
+ gboolean built_in_store;
gchar *group_name;
- gchar *uri;
gtk_tree_model_get (
- tree_model, &iter, COL_STRING_URI, &uri, -1);
+ tree_model, &iter,
+ COL_POINTER_CAMEL_STORE, &store, -1);
- if (uri == NULL)
+ if (!CAMEL_IS_STORE (store))
goto next;
- group_name = g_strdup_printf ("Store %s", uri);
+ service = CAMEL_SERVICE (store);
+ uid = camel_service_get_uid (service);
+ group_name = g_strdup_printf ("Store %s", uid);
/* Expand stores that have no "Expanded" key. */
expand_row = !g_key_file_has_key (
key_file, group_name, key, NULL);
- /* Do not expand local stores in Express mode. */
- if (e_shell_get_express_mode (shell)) {
- expand_row &= (strncmp (uri, "vfolder", 7) != 0);
- expand_row &= (strncmp (uri, "maildir", 7) != 0);
- }
+ built_in_store =
+ (g_strcmp0 (uid, E_MAIL_SESSION_LOCAL_UID) == 0) ||
+ (g_strcmp0 (uid, E_MAIL_SESSION_VFOLDER_UID) == 0);
+
+ if (express_mode && built_in_store)
+ expand_row = FALSE;
if (expand_row) {
GtkTreePath *path;
@@ -3559,7 +3601,6 @@ em_folder_tree_restore_state (EMFolderTree *folder_tree,
}
g_free (group_name);
- g_free (uri);
next:
valid = gtk_tree_model_iter_next (tree_model, &iter);