Commit a9cfed59 authored by Matthew Barnes's avatar Matthew Barnes
Browse files

Avoid passing EMailBackend as much as possible.

More mail API churn... reversing some previous API decisions.

I've made some key API changes to EMailSession on the account-mgmt
branch which should allow for this, and will hopefully also benefit
the "email-factory" branch.

EMailBackend barely needs to exist anymore, except as the owner of
EMailSession.

For several low-level functions, we replace its EMailBackend parameter
with EMailSession and EAlertSink parameters; the latter so it can still
pass user alerts up the chain.
parent df85cb1b
......@@ -387,6 +387,7 @@ mail_backend_folder_deleted_cb (MailFolderCache *folder_cache,
EAccountList *account_list;
EIterator *iterator;
EMailSession *session;
EAlertSink *alert_sink;
const gchar *local_drafts_folder_uri;
const gchar *local_sent_folder_uri;
gboolean write_config = FALSE;
......@@ -400,6 +401,7 @@ mail_backend_folder_deleted_cb (MailFolderCache *folder_cache,
g_return_if_fail (class->compare_folder_name != NULL);
session = e_mail_backend_get_session (backend);
alert_sink = e_mail_backend_get_alert_sink (backend);
local_drafts_folder_uri =
e_mail_session_get_local_folder_uri (
......@@ -459,7 +461,7 @@ mail_backend_folder_deleted_cb (MailFolderCache *folder_cache,
/* This does something completely different.
* XXX Make it a separate signal handler? */
mail_filter_delete_folder (backend, store, folder_name);
mail_filter_delete_folder (store, folder_name, alert_sink);
}
static void
......@@ -553,7 +555,7 @@ mail_backend_folder_renamed_cb (MailFolderCache *folder_cache,
/* This does something completely different.
* XXX Make it a separate signal handler? */
mail_filter_rename_folder (
backend, store, old_folder_name, new_folder_name);
store, old_folder_name, new_folder_name);
}
static void
......@@ -896,38 +898,8 @@ e_mail_backend_get_session (EMailBackend *backend)
return backend->priv->session;
}
gboolean
e_mail_backend_delete_junk_policy_decision (EMailBackend *backend)
{
EMailBackendClass *class;
g_return_val_if_fail (E_IS_MAIL_BACKEND (backend), FALSE);
class = E_MAIL_BACKEND_GET_CLASS (backend);
if (class->delete_junk_policy_decision == NULL)
return FALSE;
return class->delete_junk_policy_decision (backend);
}
gboolean
e_mail_backend_empty_trash_policy_decision (EMailBackend *backend)
{
EMailBackendClass *class;
g_return_val_if_fail (E_IS_MAIL_BACKEND (backend), FALSE);
class = E_MAIL_BACKEND_GET_CLASS (backend);
if (class->empty_trash_policy_decision == NULL)
return FALSE;
return class->empty_trash_policy_decision (backend);
}
void
e_mail_backend_submit_alert (EMailBackend *backend,
const gchar *tag,
...)
EAlertSink *
e_mail_backend_get_alert_sink (EMailBackend *backend)
{
EShell *shell;
EShellView *shell_view;
......@@ -936,16 +908,13 @@ e_mail_backend_submit_alert (EMailBackend *backend,
EShellWindow *shell_window = NULL;
EShellBackendClass *class;
GtkApplication *application;
GList *list, *iter;
va_list va;
GList *list, *link;
/* XXX This is meant to be a convenient but temporary hack.
* Instead, pass alerts directly to an EShellContent.
* Perhaps even take an EAlert** instead of a GError**
* in some low-level functions. */
* It digs through the list of available EShellWindows
* to find a suitable EAlertSink. */
g_return_if_fail (E_IS_MAIL_BACKEND (backend));
g_return_if_fail (tag != NULL);
g_return_val_if_fail (E_IS_MAIL_BACKEND (backend), NULL);
shell_backend = E_SHELL_BACKEND (backend);
shell = e_shell_backend_get_shell (shell_backend);
......@@ -954,23 +923,47 @@ e_mail_backend_submit_alert (EMailBackend *backend,
list = gtk_application_get_windows (application);
/* Find the most recently used EShellWindow. */
for (iter = list; iter != NULL; iter = g_list_next (iter)) {
if (E_IS_SHELL_WINDOW (iter->data)) {
shell_window = E_SHELL_WINDOW (iter->data);
for (link = list; link != NULL; link = g_list_next (link)) {
if (E_IS_SHELL_WINDOW (link->data)) {
shell_window = E_SHELL_WINDOW (link->data);
break;
}
}
/* If we can't find an EShellWindow then... well, screw it. */
if (shell_window == NULL)
return;
g_return_val_if_fail (shell_window != NULL, NULL);
class = E_SHELL_BACKEND_GET_CLASS (shell_backend);
shell_view = e_shell_window_get_shell_view (shell_window, class->name);
shell_content = e_shell_view_get_shell_content (shell_view);
va_start (va, tag);
e_alert_submit_valist (E_ALERT_SINK (shell_content), tag, va);
va_end (va);
return E_ALERT_SINK (shell_content);
}
gboolean
e_mail_backend_delete_junk_policy_decision (EMailBackend *backend)
{
EMailBackendClass *class;
g_return_val_if_fail (E_IS_MAIL_BACKEND (backend), FALSE);
class = E_MAIL_BACKEND_GET_CLASS (backend);
if (class->delete_junk_policy_decision == NULL)
return FALSE;
return class->delete_junk_policy_decision (backend);
}
gboolean
e_mail_backend_empty_trash_policy_decision (EMailBackend *backend)
{
EMailBackendClass *class;
g_return_val_if_fail (E_IS_MAIL_BACKEND (backend), FALSE);
class = E_MAIL_BACKEND_GET_CLASS (backend);
if (class->empty_trash_policy_decision == NULL)
return FALSE;
return class->empty_trash_policy_decision (backend);
}
......@@ -71,13 +71,11 @@ struct _EMailBackendClass {
GType e_mail_backend_get_type (void);
EMailSession * e_mail_backend_get_session (EMailBackend *backend);
EAlertSink * e_mail_backend_get_alert_sink (EMailBackend *backend);
gboolean e_mail_backend_delete_junk_policy_decision
(EMailBackend *backend);
gboolean e_mail_backend_empty_trash_policy_decision
(EMailBackend *backend);
void e_mail_backend_submit_alert (EMailBackend *backend,
const gchar *tag,
...) G_GNUC_NULL_TERMINATED;
G_END_DECLS
......
......@@ -537,6 +537,7 @@ mail_browser_constructed (GObject *object)
EMFormatHTML *formatter;
EMailReader *reader;
EMailBackend *backend;
EMailSession *session;
EShellBackend *shell_backend;
EShell *shell;
EFocusTracker *focus_tracker;
......@@ -560,6 +561,7 @@ mail_browser_constructed (GObject *object)
reader = E_MAIL_READER (object);
backend = e_mail_reader_get_backend (reader);
session = e_mail_backend_get_session (backend);
shell_backend = E_SHELL_BACKEND (backend);
shell = e_shell_backend_get_shell (shell_backend);
......@@ -579,7 +581,7 @@ mail_browser_constructed (GObject *object)
/* The message list is a widget, but it is not shown in the browser.
* Unfortunately, the widget is inseparable from its model, and the
* model is all we need. */
browser->priv->message_list = message_list_new (backend);
browser->priv->message_list = message_list_new (session);
g_object_ref_sink (browser->priv->message_list);
g_signal_connect_swapped (
......
......@@ -619,6 +619,8 @@ mail_paned_view_constructed (GObject *object)
EShellSettings *shell_settings;
ESearchBar *search_bar;
EMailReader *reader;
EMailBackend *backend;
EMailSession *session;
EMailView *view;
GtkWidget *message_list;
GtkWidget *container;
......@@ -635,6 +637,9 @@ mail_paned_view_constructed (GObject *object)
shell = e_shell_window_get_shell (shell_window);
shell_settings = e_shell_get_shell_settings (shell);
backend = E_MAIL_BACKEND (shell_backend);
session = e_mail_backend_get_session (backend);
/* Make headers collapsable and store state of headers in config file */
em_format_html_set_headers_collapsable (
EM_FORMAT_HTML (priv->formatter), TRUE);
......@@ -675,7 +680,7 @@ mail_paned_view_constructed (GObject *object)
container = widget;
widget = message_list_new (E_MAIL_BACKEND (shell_backend));
widget = message_list_new (session);
gtk_container_add (GTK_CONTAINER (container), widget);
priv->message_list = g_object_ref (widget);
gtk_widget_show (widget);
......
......@@ -198,6 +198,7 @@ e_mail_reader_delete_folder (EMailReader *reader,
GtkWindow *parent = e_shell_get_active_window (NULL);
GtkWidget *dialog;
gboolean store_is_local;
const gchar *display_name;
const gchar *full_name;
const gchar *uid;
CamelFolderInfoFlags flags = 0;
......@@ -207,6 +208,7 @@ e_mail_reader_delete_folder (EMailReader *reader,
g_return_if_fail (CAMEL_IS_FOLDER (folder));
full_name = camel_folder_get_full_name (folder);
display_name = camel_folder_get_display_name (folder);
parent_store = camel_folder_get_parent_store (folder);
uid = camel_service_get_uid (CAMEL_SERVICE (parent_store));
......@@ -220,9 +222,9 @@ e_mail_reader_delete_folder (EMailReader *reader,
if (store_is_local &&
mail_reader_is_special_local_folder (full_name)) {
e_mail_backend_submit_alert (
backend, "mail:no-delete-special-folder",
full_name, NULL);
e_alert_submit (
alert_sink, "mail:no-delete-special-folder",
display_name, NULL);
return;
}
......@@ -232,7 +234,7 @@ e_mail_reader_delete_folder (EMailReader *reader,
if (have_flags && (flags & CAMEL_FOLDER_SYSTEM)) {
e_alert_submit (
alert_sink, "mail:no-delete-special-folder",
camel_folder_get_display_name (folder), NULL);
display_name, NULL);
return;
}
......@@ -240,20 +242,20 @@ e_mail_reader_delete_folder (EMailReader *reader,
if (CAMEL_IS_VEE_STORE (parent_store))
dialog = e_alert_dialog_new_for_args (
parent, "mail:ask-delete-vfolder",
full_name, NULL);
display_name, NULL);
else
dialog = e_alert_dialog_new_for_args (
parent, "mail:ask-delete-folder",
full_name, NULL);
display_name, NULL);
} else {
if (CAMEL_IS_VEE_STORE (parent_store))
dialog = e_alert_dialog_new_for_args (
parent, "mail:ask-delete-vfolder-nochild",
full_name, NULL);
display_name, NULL);
else
dialog = e_alert_dialog_new_for_args (
parent, "mail:ask-delete-folder-nochild",
full_name, NULL);
display_name, NULL);
}
if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_OK) {
......@@ -1097,6 +1099,7 @@ mail_reader_create_filter_cb (CamelFolder *folder,
AsyncContext *context)
{
EMailBackend *backend;
EMailSession *session;
EAlertSink *alert_sink;
CamelMimeMessage *message;
GError *error = NULL;
......@@ -1130,9 +1133,10 @@ mail_reader_create_filter_cb (CamelFolder *folder,
context->activity = NULL;
backend = e_mail_reader_get_backend (context->reader);
session = e_mail_backend_get_session (backend);
filter_gui_add_from_message (
backend, message,
session, message,
context->filter_source,
context->filter_type);
......
......@@ -305,7 +305,7 @@ action_mail_copy_cb (GtkAction *action,
model = em_folder_tree_model_get_default ();
dialog = em_folder_selector_new (
window, backend, model,
window, model,
EM_FOLDER_SELECTOR_CAN_CREATE,
_("Copy to Folder"), NULL, _("C_opy"));
......@@ -820,7 +820,7 @@ action_mail_move_cb (GtkAction *action,
model = em_folder_tree_model_get_default ();
dialog = em_folder_selector_new (
window, backend, model,
window, model,
EM_FOLDER_SELECTOR_CAN_CREATE,
_("Move to Folder"), NULL, _("_Move"));
......
......@@ -345,8 +345,6 @@ main_get_filter_driver (CamelSession *session,
const gchar *type,
GError **error)
{
EShell *shell;
EShellBackend *shell_backend;
EMailSession *ms = E_MAIL_SESSION (session);
CamelFilterDriver *driver;
EFilterRule *rule = NULL;
......@@ -355,17 +353,12 @@ main_get_filter_driver (CamelSession *session,
GSettings *settings;
ERuleContext *fc;
shell = e_shell_get_default ();
shell_backend = e_shell_get_backend_by_name (shell, "mail");
g_return_val_if_fail (E_IS_MAIL_BACKEND (shell_backend), NULL);
settings = g_settings_new ("org.gnome.evolution.mail");
config_dir = mail_session_get_config_dir ();
user = g_build_filename (config_dir, "filters.xml", NULL);
system = g_build_filename (EVOLUTION_PRIVDATADIR, "filtertypes.xml", NULL);
fc = (ERuleContext *) em_filter_context_new (
E_MAIL_BACKEND (shell_backend));
fc = (ERuleContext *) em_filter_context_new (ms);
e_rule_context_load (fc, system, user);
g_free (system);
g_free (user);
......@@ -446,17 +439,10 @@ static guint preparing_flush = 0;
static gboolean
forward_to_flush_outbox_cb (EMailSession *session)
{
EShell *shell;
EShellBackend *shell_backend;
g_return_val_if_fail (preparing_flush != 0, FALSE);
shell = e_shell_get_default ();
shell_backend = e_shell_get_backend_by_name (shell, "mail");
g_return_val_if_fail (E_IS_MAIL_BACKEND (shell_backend), FALSE);
preparing_flush = 0;
mail_send (E_MAIL_BACKEND (shell_backend));
mail_send (session);
return FALSE;
}
......
......@@ -464,12 +464,12 @@ e_mail_sidebar_init (EMailSidebar *sidebar)
}
GtkWidget *
e_mail_sidebar_new (EMailBackend *backend,
e_mail_sidebar_new (EMailSession *session,
EAlertSink *alert_sink)
{
EMFolderTreeModel *model;
g_return_val_if_fail (E_IS_MAIL_BACKEND (backend), NULL);
g_return_val_if_fail (E_IS_MAIL_SESSION (session), NULL);
g_return_val_if_fail (E_IS_ALERT_SINK (alert_sink), NULL);
model = em_folder_tree_model_get_default ();
......@@ -477,7 +477,7 @@ e_mail_sidebar_new (EMailBackend *backend,
return g_object_new (
E_TYPE_MAIL_SIDEBAR,
"alert-sink", alert_sink,
"backend", backend,
"session", session,
"model", model, NULL);
}
......
......@@ -22,6 +22,7 @@
#ifndef E_MAIL_SIDEBAR_H
#define E_MAIL_SIDEBAR_H
#include <mail/e-mail-session.h>
#include <mail/em-folder-tree.h>
/* Standard GObject macros */
......@@ -76,7 +77,7 @@ struct _EMailSidebarClass {
};
GType e_mail_sidebar_get_type (void);
GtkWidget * e_mail_sidebar_new (EMailBackend *backend,
GtkWidget * e_mail_sidebar_new (EMailSession *session,
EAlertSink *alert_sink);
GKeyFile * e_mail_sidebar_get_key_file (EMailSidebar *sidebar);
void e_mail_sidebar_set_key_file (EMailSidebar *sidebar,
......
......@@ -1856,7 +1856,7 @@ emae_account_folder (EMAccountEditor *emae,
session = e_mail_backend_get_session (backend);
folder = (EMFolderSelectionButton *) e_builder_get_widget (builder, name);
em_folder_selection_button_set_backend (folder, backend);
em_folder_selection_button_set_session (folder, session);
uri = e_account_get_string (account, item);
if (uri != NULL) {
......@@ -3752,7 +3752,7 @@ update_real_folder_cb (GtkButton *folder_button,
if (folder_uri && *folder_uri) {
EMailSession *session;
session = e_mail_backend_get_session (em_folder_selection_button_get_backend (sel_button));
session = em_folder_selection_button_get_session (sel_button);
if (!e_mail_folder_uri_parse (CAMEL_SESSION (session), folder_uri, NULL, &path, NULL))
path = NULL;
}
......@@ -3831,7 +3831,7 @@ emae_defaults_page (EConfig *ec,
widget = e_builder_get_widget (builder, "trash_folder_butt");
button = EM_FOLDER_SELECTION_BUTTON (widget);
em_folder_selection_button_set_backend (button, backend);
em_folder_selection_button_set_session (button, session);
em_folder_selection_button_set_store (button, store);
priv->trash_folder_button = GTK_BUTTON (button);
......@@ -3889,7 +3889,7 @@ emae_defaults_page (EConfig *ec,
widget = e_builder_get_widget (builder, "junk_folder_butt");
button = EM_FOLDER_SELECTION_BUTTON (widget);
em_folder_selection_button_set_backend (button, backend);
em_folder_selection_button_set_session (button, session);
em_folder_selection_button_set_store (button, store);
priv->junk_folder_button = GTK_BUTTON (button);
......
......@@ -2738,8 +2738,6 @@ static void
post_header_clicked_cb (EComposerPostHeader *header,
EMailSession *session)
{
EShell *shell;
EShellBackend *shell_backend;
GtkTreeSelection *selection;
EMFolderSelector *selector;
EMFolderTreeModel *model;
......@@ -2747,16 +2745,11 @@ post_header_clicked_cb (EComposerPostHeader *header,
GtkWidget *dialog;
GList *list;
/* FIXME Figure out a way to pass the mail backend in. */
shell = e_shell_get_default ();
shell_backend = e_shell_get_backend_by_name (shell, "mail");
/* FIXME Limit the folder tree to the NNTP account? */
model = em_folder_tree_model_get_default ();
dialog = em_folder_selector_new (
/* FIXME GTK_WINDOW (composer) */ NULL,
E_MAIL_BACKEND (shell_backend),
model, EM_FOLDER_SELECTOR_CAN_CREATE,
_("Posting destination"),
_("Choose folders to post the message to."),
......
......@@ -41,13 +41,13 @@
((obj), EM_TYPE_FILTER_CONTEXT, EMFilterContextPrivate))
struct _EMFilterContextPrivate {
EMailBackend *backend;
EMailSession *session;
GList *actions;
};
enum {
PROP_0,
PROP_BACKEND
PROP_SESSION
};
G_DEFINE_TYPE (
......@@ -56,13 +56,13 @@ G_DEFINE_TYPE (
E_TYPE_RULE_CONTEXT)
static void
filter_context_set_backend (EMFilterContext *context,
EMailBackend *backend)
filter_context_set_session (EMFilterContext *context,
EMailSession *session)
{
g_return_if_fail (E_IS_MAIL_BACKEND (backend));
g_return_if_fail (context->priv->backend == NULL);
g_return_if_fail (E_IS_MAIL_SESSION (session));
g_return_if_fail (context->priv->session == NULL);
context->priv->backend = g_object_ref (backend);
context->priv->session = g_object_ref (session);
}
static void
......@@ -72,8 +72,8 @@ filter_context_set_property (GObject *object,
GParamSpec *pspec)
{
switch (property_id) {
case PROP_BACKEND:
filter_context_set_backend (
case PROP_SESSION:
filter_context_set_session (
EM_FILTER_CONTEXT (object),
g_value_get_object (value));
return;
......@@ -89,10 +89,10 @@ filter_context_get_property (GObject *object,
GParamSpec *pspec)
{
switch (property_id) {
case PROP_BACKEND:
case PROP_SESSION:
g_value_set_object (
value,
em_filter_context_get_backend (
em_filter_context_get_session (
EM_FILTER_CONTEXT (object)));
return;
}
......@@ -107,9 +107,9 @@ filter_context_dispose (GObject *object)
priv = EM_FILTER_CONTEXT_GET_PRIVATE (object);
if (priv->backend != NULL) {
g_object_unref (priv->backend);
priv->backend = NULL;
if (priv->session != NULL) {
g_object_unref (priv->session);
priv->session = NULL;
}
g_list_foreach (priv->actions, (GFunc) g_object_unref, NULL);
......@@ -236,7 +236,7 @@ filter_context_new_element (ERuleContext *context,
priv = EM_FILTER_CONTEXT_GET_PRIVATE (context);
if (strcmp (type, "folder") == 0)
return em_filter_folder_element_new (priv->backend);
return em_filter_folder_element_new (priv->session);
if (strcmp (type, "system-flag") == 0)
return e_filter_option_new ();
......@@ -245,7 +245,7 @@ filter_context_new_element (ERuleContext *context,
return e_filter_int_new_type ("score", -3, 3);
if (strcmp (type, "source") == 0)
return em_filter_source_element_new (priv->backend);
return em_filter_source_element_new (priv->session);
return E_RULE_CONTEXT_CLASS (em_filter_context_parent_class)->
new_element (context, type);
......@@ -271,12 +271,12 @@ em_filter_context_class_init (EMFilterContextClass *class)
g_object_class_install_property (
object_class,
PROP_BACKEND,
PROP_SESSION,
g_param_spec_object (
"backend",
"session",
NULL,
NULL,
E_TYPE_MAIL_BACKEND,
E_TYPE_MAIL_SESSION,
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT_ONLY));
}
......@@ -306,20 +306,20 @@ em_filter_context_init (EMFilterContext *context)
}
EMFilterContext *
em_filter_context_new (EMailBackend *backend)
em_filter_context_new (EMailSession *session)
{
g_return_val_if_fail (E_IS_MAIL_BACKEND (backend), NULL);
g_return_val_if_fail (E_IS_MAIL_SESSION (session), NULL);
return g_object_new (
EM_TYPE_FILTER_CONTEXT, "backend", backend, NULL);
EM_TYPE_FILTER_CONTEXT, "session", session, NULL);
}
EMailBackend *
em_filter_context_get_backend (EMFilterContext *context)
EMailSession *
em_filter_context_get_session (EMFilterContext *context)
{
g_return_val_if_fail (EM_IS_FILTER_CONTEXT (context), NULL);
return context->priv->backend;
return context->priv->session;
}
void
......
......@@ -25,7 +25,7 @@
#ifndef EM_FILTER_CONTEXT_H
#define EM_FILTER_CONTEXT_H
#include <mail/e-mail-backend.h>
#include <mail/e-mail-session.h>
#include <filter/e-rule-context.h>
/* Standard GObject macros */
......@@ -64,8 +64,8 @@ struct _EMFilterContextClass {
GType em_filter_context_get_type (void);
EMFilterContext *
em_filter_context_new (EMailBackend *backend);
EMailBackend * em_filter_context_get_backend (EMFilterContext *context);
em_filter_context_new (EMailSession *session);
EMailSession * em_filter_context_get_session (EMFilterContext *context);
void em_filter_context_add_action (EMFilterContext *context,
EFilterPart *action);
EFilterPart * em_filter_context_find_action (EMFilterContext *context,
......
......@@ -43,13 +43,13 @@
((obj), EM_TYPE_FILTER_FOLDER_ELEMENT, EMFilterFolderElementPrivate))
struct _EMFilterFolderElementPrivate {
EMailBackend *backend;
EMailSession *session;
gchar *uri;
};
enum {
PROP_0,