aboutsummaryrefslogtreecommitdiffstats
path: root/mail/mail-vfolder.c
diff options
context:
space:
mode:
Diffstat (limited to 'mail/mail-vfolder.c')
-rw-r--r--mail/mail-vfolder.c139
1 files changed, 78 insertions, 61 deletions
diff --git a/mail/mail-vfolder.c b/mail/mail-vfolder.c
index 5ba3f17427..2afcafdd6a 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,8 @@
#include "mail-tools.h"
#include "mail-vfolder.h"
+#include "e-mail-shell-module.h"
+
#define d(x) /* (printf("%s:%s: ", G_STRLOC, G_STRFUNC), (x))*/
static EMVFolderContext *context; /* context remains open all time */
@@ -224,7 +226,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;
@@ -337,21 +339,31 @@ uri_is_ignore(CamelStore *store, const char *uri)
EAccountList *accounts;
EAccount *account;
EIterator *iter;
+ const gchar *local_drafts_folder_uri;
+ const gchar *local_outbox_folder_uri;
+ const gchar *local_sent_folder_uri;
int found = FALSE;
+ local_drafts_folder_uri = e_mail_shell_module_get_folder_uri (
+ mail_shell_module, E_MAIL_FOLDER_DRAFTS);
+ local_outbox_folder_uri = e_mail_shell_module_get_folder_uri (
+ mail_shell_module, E_MAIL_FOLDER_OUTBOX);
+ local_sent_folder_uri = e_mail_shell_module_get_folder_uri (
+ mail_shell_module, 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_folder_uri,
+ local_sent_folder_uri,
+ local_drafts_folder_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_folder_uri, uri)
+ || camel_store_folder_uri_equal(store, local_sent_folder_uri, uri)
+ || camel_store_folder_uri_equal(store, local_drafts_folder_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)) {
char *curi;
@@ -592,13 +604,14 @@ done:
if (changed->str[0]) {
GtkWidget *dialog;
+ const gchar *data_dir;
char *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 = e_shell_module_get_data_dir (mail_shell_module);
+ user = g_build_filename (data_dir, "vfolders.xml", NULL);
rule_context_save ((RuleContext *) context, user);
g_free (user);
}
@@ -661,10 +674,12 @@ mail_vfolder_rename_uri(CamelStore *store, const char *cfrom, const char *cto)
UNLOCK();
if (changed) {
+ const gchar *data_dir;
char *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 = e_shell_module_get_data_dir (mail_shell_module);
+ user = g_build_filename (data_dir, "vfolders.xml", NULL);
rule_context_save((RuleContext *)context, user);
g_free(user);
}
@@ -785,21 +800,12 @@ static void context_rule_added(RuleContext *ctx, FilterRule *rule)
static void context_rule_removed(RuleContext *ctx, FilterRule *rule)
{
- char *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);
@@ -841,6 +847,8 @@ store_folder_deleted(CamelObject *o, void *event_data, void *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);
@@ -848,7 +856,8 @@ store_folder_deleted(CamelObject *o, void *event_data, void *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 = e_shell_module_get_data_dir (mail_shell_module);
+ user = g_build_filename (data_dir, "vfolders.xml", NULL);
rule_context_save((RuleContext *)context, user);
g_free(user);
} else {
@@ -875,6 +884,8 @@ store_folder_renamed(CamelObject *o, void *event_data, void *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);
@@ -891,7 +902,8 @@ store_folder_renamed(CamelObject *o, void *event_data, void *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 = e_shell_module_get_data_dir (mail_shell_module);
+ user = g_build_filename (data_dir, "vfolders.xml", NULL);
rule_context_save((RuleContext *)context, user);
g_free(user);
@@ -908,6 +920,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;
char *user, *storeuri;
FilterRule *rule;
char *xmlfile;
@@ -926,7 +939,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 = e_shell_module_get_data_dir (mail_shell_module);
+ 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");
@@ -943,7 +957,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);
@@ -958,7 +972,8 @@ 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_shell_module_load_store_by_uri (
+ mail_shell_module, storeuri, _("Search Folders"));
/* and setup the rules we have */
rule = NULL;
@@ -981,66 +996,66 @@ vfolder_load_storage(void)
void
vfolder_revert(void)
{
+ const gchar *data_dir;
char *user;
d(printf("vfolder_revert\n"));
- user = g_strdup_printf("%s/vfolders.xml", mail_component_peek_base_directory (mail_component_peek ()));
+ data_dir = e_shell_module_get_data_dir (mail_shell_module);
+ 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, int button, void *data)
+void
+vfolder_edit (EShellView *shell_view)
{
- char *user;
+ EShellModule *shell_module;
+ 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_module = e_shell_view_get_shell_module (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_module_get_data_dir (shell_module);
+ 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, int button, void *data)
{
if (button == GTK_RESPONSE_OK) {
+ const gchar *data_dir;
char *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 = e_shell_module_get_data_dir (mail_shell_module);
+ user = g_build_filename (data_dir, "vfolders.xml", NULL);
rule_context_save((RuleContext *)context, user);
g_free(user);
}
@@ -1097,6 +1112,7 @@ static void
new_rule_clicked(GtkWidget *w, int button, void *data)
{
if (button == GTK_RESPONSE_OK) {
+ const gchar *data_dir;
char *user;
FilterRule *rule = g_object_get_data((GObject *)w, "rule");
@@ -1113,7 +1129,8 @@ new_rule_clicked(GtkWidget *w, int button, void *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 = e_shell_module_get_data_dir (mail_shell_module);
+ user = g_build_filename (data_dir, "vfolders.xml", NULL);
rule_context_save((RuleContext *)context, user);
g_free(user);
}