aboutsummaryrefslogtreecommitdiffstats
path: root/mail/em-utils.c
diff options
context:
space:
mode:
authorMatthew Barnes <mbarnes@redhat.com>2011-12-09 23:34:55 +0800
committerMatthew Barnes <mbarnes@redhat.com>2011-12-11 10:34:19 +0800
commit7c0c40f83317228e0a725bfb5ca8854339d25588 (patch)
treedb1197dd9f336e175c590c3a41201dfa78ee303e /mail/em-utils.c
parent2f32e1cc68cd416f4530ecc3d2ff08b0e6498d45 (diff)
downloadgsoc2013-evolution-7c0c40f83317228e0a725bfb5ca8854339d25588.tar
gsoc2013-evolution-7c0c40f83317228e0a725bfb5ca8854339d25588.tar.gz
gsoc2013-evolution-7c0c40f83317228e0a725bfb5ca8854339d25588.tar.bz2
gsoc2013-evolution-7c0c40f83317228e0a725bfb5ca8854339d25588.tar.lz
gsoc2013-evolution-7c0c40f83317228e0a725bfb5ca8854339d25588.tar.xz
gsoc2013-evolution-7c0c40f83317228e0a725bfb5ca8854339d25588.tar.zst
gsoc2013-evolution-7c0c40f83317228e0a725bfb5ca8854339d25588.zip
Reorder accounts by drag-and-drop.
This implements https://bugzilla.gnome.org/show_bug.cgi?id=663527#c3. Account reordering is now done by drag-and-drop instead of up/down buttons. Turned out to be a wee bit more complicated than I initially thought. This scraps EAccountManager and EAccountTreeView and replaces them with new classes centered around EMailAccountStore, which EMailSession owns. EMailAccountStore is the model behind the account list in Preferences. The folder tree model now uses it to sort its own top-level rows using gtk_tree_path_compare(). It also broadcasts account operations through signals so we don't have to rely so heavily on EAccountList signals, since EAccountList is going away soon. Also as part of this work, the e-mail-local.h and e-mail-store.h APIs have been merged into EMailSession and MailFolderCache.
Diffstat (limited to 'mail/em-utils.c')
-rw-r--r--mail/em-utils.c206
1 files changed, 22 insertions, 184 deletions
diff --git a/mail/em-utils.c b/mail/em-utils.c
index c15f8b67b5..bfda4056be 100644
--- a/mail/em-utils.c
+++ b/mail/em-utils.c
@@ -71,7 +71,6 @@
#include "em-composer-utils.h"
#include "em-format-quote.h"
#include "e-mail-folder-utils.h"
-#include "e-mail-local.h"
#include "e-mail-session.h"
/* XXX This is a dirty hack on a dirty hack. We really need
@@ -84,8 +83,6 @@ extern const gchar *shell_builtin_backend;
#define d(x)
-static void free_account_sort_order_cache (void);
-
gboolean
em_utils_ask_open_many (GtkWindow *parent,
gint how_many)
@@ -998,17 +995,18 @@ em_utils_folder_is_templates (CamelFolder *folder)
g_return_val_if_fail (CAMEL_IS_FOLDER (folder), FALSE);
+ store = camel_folder_get_parent_store (folder);
+ session = camel_service_get_session (CAMEL_SERVICE (store));
+
local_templates_folder =
- e_mail_local_get_folder (E_MAIL_LOCAL_FOLDER_TEMPLATES);
+ e_mail_session_get_local_folder (
+ E_MAIL_SESSION (session), E_MAIL_LOCAL_FOLDER_TEMPLATES);
if (folder == local_templates_folder)
return TRUE;
folder_uri = e_mail_folder_uri_from_folder (folder);
- store = camel_folder_get_parent_store (folder);
- session = camel_service_get_session (CAMEL_SERVICE (store));
-
account_list = e_get_account_list ();
iterator = e_list_get_iterator (E_LIST (account_list));
@@ -1053,17 +1051,18 @@ em_utils_folder_is_drafts (CamelFolder *folder)
g_return_val_if_fail (CAMEL_IS_FOLDER (folder), FALSE);
+ store = camel_folder_get_parent_store (folder);
+ session = camel_service_get_session (CAMEL_SERVICE (store));
+
local_drafts_folder =
- e_mail_local_get_folder (E_MAIL_LOCAL_FOLDER_DRAFTS);
+ e_mail_session_get_local_folder (
+ E_MAIL_SESSION (session), E_MAIL_LOCAL_FOLDER_DRAFTS);
if (folder == local_drafts_folder)
return TRUE;
folder_uri = e_mail_folder_uri_from_folder (folder);
- store = camel_folder_get_parent_store (folder);
- session = camel_service_get_session (CAMEL_SERVICE (store));
-
account_list = e_get_account_list ();
iterator = e_list_get_iterator (E_LIST (account_list));
@@ -1108,17 +1107,18 @@ em_utils_folder_is_sent (CamelFolder *folder)
g_return_val_if_fail (CAMEL_IS_FOLDER (folder), FALSE);
+ store = camel_folder_get_parent_store (folder);
+ session = camel_service_get_session (CAMEL_SERVICE (store));
+
local_sent_folder =
- e_mail_local_get_folder (E_MAIL_LOCAL_FOLDER_SENT);
+ e_mail_session_get_local_folder (
+ E_MAIL_SESSION (session), E_MAIL_LOCAL_FOLDER_SENT);
if (folder == local_sent_folder)
return TRUE;
folder_uri = e_mail_folder_uri_from_folder (folder);
- store = camel_folder_get_parent_store (folder);
- session = camel_service_get_session (CAMEL_SERVICE (store));
-
account_list = e_get_account_list ();
iterator = e_list_get_iterator (E_LIST (account_list));
@@ -1153,12 +1153,18 @@ em_utils_folder_is_sent (CamelFolder *folder)
gboolean
em_utils_folder_is_outbox (CamelFolder *folder)
{
+ CamelStore *store;
+ CamelSession *session;
CamelFolder *local_outbox_folder;
g_return_val_if_fail (CAMEL_IS_FOLDER (folder), FALSE);
+ store = camel_folder_get_parent_store (folder);
+ session = camel_service_get_session (CAMEL_SERVICE (store));
+
local_outbox_folder =
- e_mail_local_get_folder (E_MAIL_LOCAL_FOLDER_OUTBOX);
+ e_mail_session_get_local_folder (
+ E_MAIL_SESSION (session), E_MAIL_LOCAL_FOLDER_OUTBOX);
return (folder == local_outbox_folder);
}
@@ -1911,8 +1917,6 @@ emu_free_mail_cache (void)
photos_cache = NULL;
G_UNLOCK (photos_cache);
-
- free_account_sort_order_cache ();
}
void
@@ -2269,169 +2273,3 @@ em_utils_disconnect_service_sync (CamelService *service,
return res;
}
-G_LOCK_DEFINE_STATIC (accounts_sort_order_cache);
-static GHashTable *accounts_sort_order_cache = NULL; /* account_uid string to sort order uint */
-
-static void
-free_account_sort_order_cache (void)
-{
- G_LOCK (accounts_sort_order_cache);
-
- if (accounts_sort_order_cache) {
- g_hash_table_destroy (accounts_sort_order_cache);
- accounts_sort_order_cache = NULL;
- }
-
- G_UNLOCK (accounts_sort_order_cache);
-}
-
-static void
-fill_accounts_sort_order_cache (EMailBackend *backend,
- gboolean force_reload)
-{
- GSList *account_uids;
-
- G_LOCK (accounts_sort_order_cache);
-
- if (!force_reload && accounts_sort_order_cache) {
- G_UNLOCK (accounts_sort_order_cache);
- return;
- }
-
- if (!accounts_sort_order_cache)
- accounts_sort_order_cache = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
- else
- g_hash_table_remove_all (accounts_sort_order_cache);
-
- account_uids = em_utils_load_accounts_sort_order (backend);
- if (account_uids) {
- GSList *iter;
- guint index;
-
- for (index = 1, iter = account_uids; iter; index++, iter = iter->next) {
- if (iter->data)
- g_hash_table_insert (accounts_sort_order_cache, iter->data, GUINT_TO_POINTER (index));
- }
-
- /* items are stolen into the cache */
- /* g_slist_foreach (account_uids, (GFunc) g_free, NULL); */
- g_slist_free (account_uids);
- }
-
- G_UNLOCK (accounts_sort_order_cache);
-}
-
-static gchar *
-emu_get_sort_order_filename (EMailBackend *backend)
-{
- g_return_val_if_fail (backend != NULL, NULL);
-
- return g_build_filename (
- e_shell_backend_get_config_dir (E_SHELL_BACKEND (backend)),
- "sortorder.ini", NULL);
-}
-
-static GKeyFile *
-emu_get_sort_order_key_file (EMailBackend *backend)
-{
- gchar *filename;
- GKeyFile *key_file;
-
- g_return_val_if_fail (backend != NULL, NULL);
-
- filename = emu_get_sort_order_filename (backend);
- g_return_val_if_fail (filename != NULL, NULL);
-
- key_file = g_key_file_new ();
- g_key_file_load_from_file (key_file, filename, G_KEY_FILE_NONE, NULL);
-
- g_free (filename);
-
- return key_file;
-}
-
-void
-em_utils_save_accounts_sort_order (EMailBackend *backend,
- const GSList *account_uids)
-{
- gchar *filename;
- GKeyFile *key_file;
- gint ii;
- gchar key[32];
- gchar *content;
- gsize length = 0;
-
- key_file = emu_get_sort_order_key_file (backend);
- g_return_if_fail (key_file != NULL);
-
- filename = emu_get_sort_order_filename (backend);
- g_return_if_fail (filename != NULL);
-
- g_key_file_remove_group (key_file, "accounts", NULL);
-
- for (ii = 0; account_uids; ii++, account_uids = account_uids->next) {
- sprintf (key, "%d", ii);
-
- g_key_file_set_string (key_file, "accounts", key, account_uids->data);
- }
-
- content = g_key_file_to_data (key_file, &length, NULL);
- if (content)
- g_file_set_contents (filename, content, length, NULL);
-
- g_free (content);
- g_free (filename);
- g_key_file_free (key_file);
-
- fill_accounts_sort_order_cache (backend, TRUE);
- e_mail_backend_account_sort_order_changed (backend);
-}
-
-GSList *
-em_utils_load_accounts_sort_order (EMailBackend *backend)
-{
- GKeyFile *key_file;
- GSList *account_uids = NULL;
- gchar key[32];
- gchar *value;
- gint ii;
-
- key_file = emu_get_sort_order_key_file (backend);
- g_return_val_if_fail (key_file != NULL, NULL);
-
- ii = 0;
- do {
- sprintf (key, "%d", ii);
- ii++;
-
- value = g_key_file_get_string (key_file, "accounts", key, NULL);
- if (!value)
- break;
-
- account_uids = g_slist_prepend (account_uids, value);
- } while (*key);
-
- g_key_file_free (key_file);
-
- return g_slist_reverse (account_uids);
-}
-
-guint
-em_utils_get_account_sort_order (EMailBackend *backend,
- const gchar *account_uid)
-{
- guint res;
-
- g_return_val_if_fail (backend != NULL, 0);
- g_return_val_if_fail (account_uid != NULL, 0);
-
- fill_accounts_sort_order_cache (backend, FALSE);
-
- G_LOCK (accounts_sort_order_cache);
-
- res = GPOINTER_TO_UINT (g_hash_table_lookup (accounts_sort_order_cache, account_uid));
-
- G_UNLOCK (accounts_sort_order_cache);
-
- return res;
-}