diff options
Diffstat (limited to 'mail/mail-vfolder.c')
-rw-r--r-- | mail/mail-vfolder.c | 136 |
1 files changed, 75 insertions, 61 deletions
diff --git a/mail/mail-vfolder.c b/mail/mail-vfolder.c index e995589fe2..96d60ab5f0 100644 --- a/mail/mail-vfolder.c +++ b/mail/mail-vfolder.c @@ -31,10 +31,11 @@ #include <camel/camel-vee-folder.h> #include <camel/camel-vee-store.h> #include <camel/camel-vtrash-folder.h> +#include <libedataserver/e-account-list.h> -#include "libedataserver/e-account-list.h" #include "e-util/e-error.h" #include "e-util/e-util-private.h" +#include "e-util/e-account-utils.h" #include "em-folder-tree-model.h" #include "em-utils.h" @@ -42,7 +43,6 @@ #include "em-vfolder-editor.h" #include "em-vfolder-rule.h" #include "mail-autofilter.h" -#include "mail-component.h" #include "mail-config.h" #include "mail-folder-cache.h" #include "mail-mt.h" @@ -50,6 +50,9 @@ #include "mail-tools.h" #include "mail-vfolder.h" +#include "e-mail-local.h" +#include "e-mail-store.h" + #define d(x) /* (printf("%s:%s: ", G_STRLOC, G_STRFUNC), (x))*/ static EMVFolderContext *context; /* context remains open all time */ @@ -224,7 +227,7 @@ vfolder_adduri_desc (struct _adduri_msg *m) else uid = g_strdup_printf("%s@%s", url->user, url->host); - account = e_account_list_find(mail_config_get_accounts(), E_ACCOUNT_FIND_UID, uid); + account = e_get_account_by_uid (uid); g_free(uid); if (account != NULL) loc = account->name; @@ -336,21 +339,28 @@ uri_is_ignore(CamelStore *store, const gchar *uri) EAccountList *accounts; EAccount *account; EIterator *iter; + const gchar *local_drafts_uri; + const gchar *local_outbox_uri; + const gchar *local_sent_uri; gint found = FALSE; + local_drafts_uri = e_mail_local_get_folder_uri (E_MAIL_FOLDER_DRAFTS); + local_outbox_uri = e_mail_local_get_folder_uri (E_MAIL_FOLDER_OUTBOX); + local_sent_uri = e_mail_local_get_folder_uri (E_MAIL_FOLDER_SENT); + d(printf("checking '%s' against:\n %s\n %s\n %s\n", uri, - mail_component_get_folder_uri(NULL, MAIL_COMPONENT_FOLDER_OUTBOX), - mail_component_get_folder_uri(NULL, MAIL_COMPONENT_FOLDER_SENT), - mail_component_get_folder_uri(NULL, MAIL_COMPONENT_FOLDER_DRAFTS))); + local_outbox_uri, + local_sent_uri, + local_drafts_uri)); - found = camel_store_folder_uri_equal(store, mail_component_get_folder_uri(NULL, MAIL_COMPONENT_FOLDER_OUTBOX), uri) - || camel_store_folder_uri_equal(store, mail_component_get_folder_uri(NULL, MAIL_COMPONENT_FOLDER_SENT), uri) - || camel_store_folder_uri_equal(store, mail_component_get_folder_uri(NULL, MAIL_COMPONENT_FOLDER_DRAFTS), uri); + found = camel_store_folder_uri_equal(store, local_outbox_uri, uri) + || camel_store_folder_uri_equal(store, local_sent_uri, uri) + || camel_store_folder_uri_equal(store, local_drafts_uri, uri); if (found) return found; - accounts = mail_config_get_accounts (); + accounts = e_get_account_list (); iter = e_list_get_iterator ((EList *) accounts); while (e_iterator_is_valid (iter)) { gchar *curi; @@ -591,13 +601,14 @@ done: if (changed->str[0]) { GtkWidget *dialog; + const gchar *data_dir; gchar *user; dialog = e_error_new(NULL, "mail:vfolder-updated", changed->str, uri, NULL); em_utils_show_info_silent (dialog); - user = g_strdup_printf ("%s/vfolders.xml", - mail_component_peek_base_directory (mail_component_peek ())); + data_dir = em_utils_get_data_dir (); + user = g_build_filename (data_dir, "vfolders.xml", NULL); rule_context_save ((RuleContext *) context, user); g_free (user); } @@ -660,10 +671,12 @@ mail_vfolder_rename_uri(CamelStore *store, const gchar *cfrom, const gchar *cto) UNLOCK(); if (changed) { + const gchar *data_dir; gchar *user; d(printf("Vfolders updated from renamed folder\n")); - user = g_strdup_printf("%s/vfolders.xml", mail_component_peek_base_directory (mail_component_peek ())); + data_dir = em_utils_get_data_dir (); + user = g_build_filename (data_dir, "vfolders.xml", NULL); rule_context_save((RuleContext *)context, user); g_free(user); } @@ -784,21 +797,12 @@ static void context_rule_added(RuleContext *ctx, FilterRule *rule) static void context_rule_removed(RuleContext *ctx, FilterRule *rule) { - gchar *path; - gpointer key, folder = NULL; d(printf("rule removed; %s\n", rule->name)); /* TODO: remove from folder info cache? */ - /* FIXME: is this even necessary? if we remove the folder from - * the CamelStore, the tree should pick it up auto-magically - * because it listens to CamelStore events... */ - path = g_strdup_printf("/%s", rule->name); - mail_component_remove_folder (mail_component_peek (), vfolder_store, path); - g_free(path); - LOCK(); if (g_hash_table_lookup_extended (vfolder_hash, rule->name, &key, &folder)) { g_hash_table_remove (vfolder_hash, key); @@ -840,6 +844,8 @@ store_folder_deleted(CamelObject *o, gpointer event_data, gpointer data) /* delete it from our list */ rule = rule_context_find_rule((RuleContext *)context, info->full_name, NULL); if (rule) { + const gchar *data_dir; + /* We need to stop listening to removed events, otherwise we'll try and remove it again */ g_signal_handlers_disconnect_matched(context, G_SIGNAL_MATCH_FUNC|G_SIGNAL_MATCH_DATA, 0, 0, NULL, context_rule_removed, context); @@ -847,7 +853,8 @@ store_folder_deleted(CamelObject *o, gpointer event_data, gpointer data) g_object_unref(rule); g_signal_connect(context, "rule_removed", G_CALLBACK(context_rule_removed), context); - user = g_strdup_printf("%s/vfolders.xml", mail_component_peek_base_directory (mail_component_peek ())); + data_dir = em_utils_get_data_dir (); + user = g_build_filename (data_dir, "vfolders.xml", NULL); rule_context_save((RuleContext *)context, user); g_free(user); } else { @@ -874,6 +881,8 @@ store_folder_renamed(CamelObject *o, gpointer event_data, gpointer data) LOCK(); d(printf("Changing folder name in hash table to '%s'\n", info->new->full_name)); if (g_hash_table_lookup_extended (vfolder_hash, info->old_base, &key, &folder)) { + const gchar *data_dir; + g_hash_table_remove (vfolder_hash, key); g_free (key); g_hash_table_insert (vfolder_hash, g_strdup(info->new->full_name), folder); @@ -890,7 +899,8 @@ store_folder_renamed(CamelObject *o, gpointer event_data, gpointer data) filter_rule_set_name(rule, info->new->full_name); g_signal_connect(rule, "changed", G_CALLBACK(rule_changed), folder); - user = g_strdup_printf("%s/vfolders.xml", mail_component_peek_base_directory (mail_component_peek ())); + data_dir = em_utils_get_data_dir (); + user = g_build_filename (data_dir, "vfolders.xml", NULL); rule_context_save((RuleContext *)context, user); g_free(user); @@ -907,6 +917,7 @@ vfolder_load_storage(void) /* lock for loading storage, it is safe to call it more than once */ static pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER; + const gchar *data_dir; gchar *user, *storeuri; FilterRule *rule; gchar *xmlfile; @@ -925,7 +936,8 @@ vfolder_load_storage(void) pthread_mutex_unlock (&lock); /* first, create the vfolder store, and set it up */ - storeuri = g_strdup_printf("vfolder:%s/vfolder", mail_component_peek_base_directory (mail_component_peek ())); + data_dir = em_utils_get_data_dir (); + storeuri = g_strdup_printf("vfolder:%s/vfolder", data_dir); vfolder_store = camel_session_get_store(session, storeuri, NULL); if (vfolder_store == NULL) { g_warning("Cannot open vfolder store - no vfolders available"); @@ -942,7 +954,7 @@ vfolder_load_storage(void) d(printf("got store '%s' = %p\n", storeuri, vfolder_store)); /* load our rules */ - user = g_strdup_printf ("%s/vfolders.xml", mail_component_peek_base_directory (mail_component_peek ())); + user = g_build_filename (data_dir, "vfolders.xml", NULL); context = em_vfolder_context_new (); xmlfile = g_build_filename (EVOLUTION_PRIVDATADIR, "vfoldertypes.xml", NULL); @@ -957,7 +969,7 @@ vfolder_load_storage(void) g_signal_connect(context, "rule_removed", G_CALLBACK(context_rule_removed), context); /* load store to mail component */ - mail_component_load_store_by_uri (mail_component_peek (), storeuri, _("Search Folders")); + e_mail_store_add_by_uri (storeuri, _("Search Folders")); /* and setup the rules we have */ rule = NULL; @@ -981,66 +993,66 @@ vfolder_load_storage(void) void vfolder_revert(void) { + const gchar *data_dir; gchar *user; d(printf("vfolder_revert\n")); - user = g_strdup_printf("%s/vfolders.xml", mail_component_peek_base_directory (mail_component_peek ())); + data_dir = em_utils_get_data_dir (); + user = g_build_filename (data_dir, "vfolders.xml", NULL); rule_context_revert((RuleContext *)context, user); g_free(user); } -static GtkWidget *vfolder_editor = NULL; - -static void -em_vfolder_editor_response (GtkWidget *dialog, gint button, gpointer data) +void +vfolder_edit (EShellView *shell_view) { - gchar *user; + EShellBackend *shell_backend; + EShellWindow *shell_window; + GtkWidget *dialog; + const gchar *data_dir; + gchar *filename; - user = g_strdup_printf ("%s/vfolders.xml", mail_component_peek_base_directory (mail_component_peek ())); - - switch (button) { - case GTK_RESPONSE_OK: - rule_context_save((RuleContext *)context, user); - break; - default: - rule_context_revert((RuleContext *)context, user); - } + g_return_if_fail (E_IS_SHELL_VIEW (shell_view)); - vfolder_editor = NULL; + shell_backend = e_shell_view_get_shell_backend (shell_view); + shell_window = e_shell_view_get_shell_window (shell_view); - gtk_widget_destroy(dialog); - - g_free (user); -} - -void -vfolder_edit (void) -{ - if (vfolder_editor) { - gdk_window_raise (GTK_WIDGET (vfolder_editor)->window); - return; - } + data_dir = e_shell_backend_get_data_dir (shell_backend); + filename = g_build_filename (data_dir, "vfolders.xml", NULL); /* ensures vfolder is running */ vfolder_load_storage (); - vfolder_editor = GTK_WIDGET (em_vfolder_editor_new (context)); - gtk_window_set_title (GTK_WINDOW (vfolder_editor), _("Search Folders")); - g_signal_connect(vfolder_editor, "response", G_CALLBACK(em_vfolder_editor_response), NULL); + dialog = em_vfolder_editor_new (context); + gtk_window_set_title ( + GTK_WINDOW (dialog), _("Search Folders")); + gtk_window_set_transient_for ( + GTK_WINDOW (dialog), GTK_WINDOW (shell_window)); + + switch (gtk_dialog_run (GTK_DIALOG (dialog))) { + case GTK_RESPONSE_OK: + rule_context_save ((RuleContext *) context, filename); + break; + default: + rule_context_revert ((RuleContext *) context, filename); + break; + } - gtk_widget_show (vfolder_editor); + gtk_widget_destroy (dialog); } static void edit_rule_response(GtkWidget *w, gint button, gpointer data) { if (button == GTK_RESPONSE_OK) { + const gchar *data_dir; gchar *user; FilterRule *rule = g_object_get_data (G_OBJECT (w), "rule"); FilterRule *orig = g_object_get_data (G_OBJECT (w), "orig"); filter_rule_copy(orig, rule); - user = g_strdup_printf("%s/vfolders.xml", mail_component_peek_base_directory (mail_component_peek ())); + data_dir = em_utils_get_data_dir (); + user = g_build_filename (data_dir, "vfolders.xml", NULL); rule_context_save((RuleContext *)context, user); g_free(user); } @@ -1097,6 +1109,7 @@ static void new_rule_clicked(GtkWidget *w, gint button, gpointer data) { if (button == GTK_RESPONSE_OK) { + const gchar *data_dir; gchar *user; FilterRule *rule = g_object_get_data((GObject *)w, "rule"); @@ -1112,7 +1125,8 @@ new_rule_clicked(GtkWidget *w, gint button, gpointer data) g_object_ref(rule); rule_context_add_rule((RuleContext *)context, rule); - user = g_strdup_printf("%s/vfolders.xml", mail_component_peek_base_directory (mail_component_peek ())); + data_dir = em_utils_get_data_dir (); + user = g_build_filename (data_dir, "vfolders.xml", NULL); rule_context_save((RuleContext *)context, user); g_free(user); } |