Commit f6c0c822 authored by Milan Crha's avatar Milan Crha

Bug 223621 - Add per-account mail Archive Folder option

parent 1d34b8e5
......@@ -562,6 +562,12 @@
<child name="subscription-window" schema="org.gnome.evolution.window"/>
<child name="vfolder-window" schema="org.gnome.evolution.window"/>
<key name="local-archive-folder" type="s">
<default>''</default>
<_summary>An Archive folder for On This Computer folders.</_summary>
<_description>An Archive folder to use for Messages|Archive... feature when in an On This Computer folder.</_description>
</key>
<!-- The following keys are deprecated. -->
<key name="forward-style" type="i">
......
......@@ -44,6 +44,7 @@ typedef struct {
gboolean jh_check;
gboolean book_lookup;
gboolean book_lookup_local_only;
gchar *local_archive_folder;
} MailConfig;
extern gint camel_header_param_encode_filenames_in_rfc_2047;
......@@ -149,6 +150,15 @@ settings_int_value_changed (GSettings *settings,
*save_location = g_settings_get_int (settings, key);
}
static void
settings_string_value_changed (GSettings *settings,
const gchar *key,
gchar **save_location)
{
g_free (*save_location);
*save_location = g_settings_get_string (settings, key);
}
gint
mail_config_get_address_count (void)
{
......@@ -230,6 +240,14 @@ mail_config_get_lookup_book_local_only (void)
return config->book_lookup_local_only;
}
gchar *
mail_config_dup_local_archive_folder (void)
{
g_return_val_if_fail (config != NULL, NULL);
return g_strdup (config->local_archive_folder);
}
/* Config struct routines */
void
mail_config_init (EMailSession *session)
......@@ -292,5 +310,12 @@ mail_config_init (EMailSession *session)
config->book_lookup_local_only = g_settings_get_boolean (
mail_settings, "junk-lookup-addressbook-local-only");
g_signal_connect (
mail_settings, "changed::local-archive-folder",
G_CALLBACK (settings_string_value_changed),
&config->local_archive_folder);
config->local_archive_folder = g_settings_get_string (
mail_settings, "local-archive-folder");
settings_jh_check_changed (mail_settings, NULL, session);
}
......@@ -45,6 +45,7 @@ gint mail_config_get_sync_timeout (void);
void mail_config_reload_junk_headers (EMailSession *session);
gboolean mail_config_get_lookup_book (void);
gboolean mail_config_get_lookup_book_local_only (void);
gchar * mail_config_dup_local_archive_folder (void);
G_END_DECLS
......
......@@ -36,6 +36,7 @@ struct _EMailConfigDefaultsPagePrivate {
GtkWidget *drafts_button; /* not referenced */
GtkWidget *sent_button; /* not referenced */
GtkWidget *archive_button; /* not referenced */
GtkWidget *replies_toggle; /* not referenced */
GtkWidget *trash_toggle; /* not referenced */
GtkWidget *junk_toggle; /* not referenced */
......@@ -624,9 +625,33 @@ mail_config_defaults_page_constructed (GObject *object)
G_BINDING_BIDIRECTIONAL |
G_BINDING_SYNC_CREATE);
text = _("Archi_ve Folder:");
widget = gtk_label_new_with_mnemonic (text);
gtk_widget_set_margin_left (widget, 12);
gtk_size_group_add_widget (size_group, widget);
gtk_misc_set_alignment (GTK_MISC (widget), 1.0, 0.5);
gtk_grid_attach (GTK_GRID (container), widget, 0, 4, 1, 1);
gtk_widget_show (widget);
label = GTK_LABEL (widget);
text = _("Choose a folder to archive messages to.");
widget = em_folder_selection_button_new (session, "", text);
gtk_widget_set_hexpand (widget, TRUE);
gtk_label_set_mnemonic_widget (label, widget);
gtk_grid_attach (GTK_GRID (container), widget, 1, 4, 1, 1);
page->priv->archive_button = widget; /* not referenced */
gtk_widget_show (widget);
e_binding_bind_object_text_property (
account_ext, "archive-folder",
widget, "folder-uri",
G_BINDING_BIDIRECTIONAL |
G_BINDING_SYNC_CREATE);
widget = gtk_button_new_with_mnemonic (_("_Restore Defaults"));
gtk_widget_set_halign (widget, GTK_ALIGN_START);
gtk_grid_attach (GTK_GRID (container), widget, 1, 6, 1, 1);
gtk_grid_attach (GTK_GRID (container), widget, 1, 7, 1, 1);
gtk_widget_show (widget);
g_signal_connect_swapped (
......@@ -642,7 +667,7 @@ mail_config_defaults_page_constructed (GObject *object)
_("Choose a folder for deleted messages."),
"real-trash-path", "use-real-trash-path");
if (widget != NULL) {
gtk_grid_attach (GTK_GRID (container), widget, 0, 4, 2, 1);
gtk_grid_attach (GTK_GRID (container), widget, 0, 5, 2, 1);
gtk_widget_show (widget);
}
......@@ -652,7 +677,7 @@ mail_config_defaults_page_constructed (GObject *object)
_("Choose a folder for junk messages."),
"real-junk-path", "use-real-junk-path");
if (widget != NULL) {
gtk_grid_attach (GTK_GRID (container), widget, 0, 5, 2, 1);
gtk_grid_attach (GTK_GRID (container), widget, 0, 6, 2, 1);
gtk_widget_show (widget);
}
......
......@@ -819,6 +819,108 @@ action_mail_message_open_cb (GtkAction *action,
e_mail_reader_open_selected_mail (reader);
}
static gchar *
mail_reader_get_archive_folder_from_folder (CamelFolder *folder,
ESourceRegistry *registry,
GPtrArray *uids,
gboolean deep_uids_check)
{
CamelStore *store;
ESource *source = NULL;
gchar *archive_folder = NULL;
if (!folder)
return NULL;
store = camel_folder_get_parent_store (folder);
if (g_strcmp0 (E_MAIL_SESSION_LOCAL_UID, camel_service_get_uid (CAMEL_SERVICE (store))) == 0) {
return mail_config_dup_local_archive_folder ();
}
if (CAMEL_IS_VEE_FOLDER (folder) && uids && uids->len > 0) {
CamelVeeFolder *vee_folder = CAMEL_VEE_FOLDER (folder);
CamelFolder *orig_folder;
store = NULL;
if (deep_uids_check) {
gint ii;
for (ii = 0; ii < uids->len; ii++) {
orig_folder = camel_vee_folder_get_vee_uid_folder (vee_folder, uids->pdata[ii]);
if (orig_folder) {
if (store && camel_folder_get_parent_store (orig_folder) != store) {
/* Do not know which archive folder to use when there are
selected messages from multiple accounts/stores. */
store = NULL;
break;
}
store = camel_folder_get_parent_store (orig_folder);
}
}
} else {
orig_folder = camel_vee_folder_get_vee_uid_folder (CAMEL_VEE_FOLDER (folder), uids->pdata[0]);
if (orig_folder)
store = camel_folder_get_parent_store (orig_folder);
}
}
if (store)
source = e_source_registry_ref_source (registry, camel_service_get_uid (CAMEL_SERVICE (store)));
if (source) {
if (e_source_has_extension (source, E_SOURCE_EXTENSION_MAIL_ACCOUNT)) {
ESourceMailAccount *account_ext;
account_ext = e_source_get_extension (source, E_SOURCE_EXTENSION_MAIL_ACCOUNT);
archive_folder = e_source_mail_account_dup_archive_folder (account_ext);
if (!archive_folder || !*archive_folder) {
g_free (archive_folder);
archive_folder = NULL;
}
}
g_object_unref (source);
}
return archive_folder;
}
static void
action_mail_archive_cb (GtkAction *action,
EMailReader *reader)
{
CamelFolder *folder;
EMailBackend *backend;
EMailSession *session;
EShell *shell;
ESourceRegistry *registry;
GPtrArray *uids;
gchar *archive_folder;
backend = e_mail_reader_get_backend (reader);
session = e_mail_backend_get_session (backend);
shell = e_shell_backend_get_shell (E_SHELL_BACKEND (backend));
registry = e_shell_get_registry (shell);
uids = e_mail_reader_get_selected_uids (reader);
g_return_if_fail (uids != NULL);
folder = e_mail_reader_ref_folder (reader);
archive_folder = mail_reader_get_archive_folder_from_folder (folder, registry, uids, TRUE);
if (archive_folder != NULL)
mail_transfer_messages (
session, folder, uids,
TRUE, archive_folder, 0, NULL, NULL);
g_clear_object (&folder);
g_ptr_array_unref (uids);
g_free (archive_folder);
}
static void
action_mail_move_cb (GtkAction *action,
EMailReader *reader)
......@@ -1868,6 +1970,13 @@ static GtkActionEntry mail_reader_entries[] = {
N_("Add sender to address book"),
G_CALLBACK (action_mail_add_sender_cb) },
{ "mail-archive",
"mail-move",
N_("_Archive..."),
"<Shift><Control>a",
N_("Move selected messages to the Archive folder for the account"),
G_CALLBACK (action_mail_archive_cb) },
{ "mail-check-for-junk",
"mail-mark-junk",
N_("Check for _Junk"),
......@@ -2324,6 +2433,10 @@ static GtkActionEntry mail_reader_search_folder_entries[] = {
static EPopupActionEntry mail_reader_popup_entries[] = {
{ "mail-popup-archive",
NULL,
"mail-archive" },
{ "mail-popup-copy",
NULL,
"mail-copy" },
......@@ -3361,6 +3474,11 @@ mail_reader_update_actions (EMailReader *reader,
action = e_mail_reader_get_action (reader, action_name);
gtk_action_set_sensitive (action, sensitive);
action_name = "mail-archive";
sensitive = any_messages_selected && (state & E_MAIL_READER_FOLDER_ARCHIVE_FOLDER_SET) != 0;
action = e_mail_reader_get_action (reader, action_name);
gtk_action_set_sensitive (action, sensitive);
action_name = "mail-check-for-junk";
sensitive = any_messages_selected;
action = e_mail_reader_get_action (reader, action_name);
......@@ -4098,6 +4216,7 @@ e_mail_reader_check_state (EMailReader *reader)
gboolean is_mailing_list;
gboolean is_junk_folder = FALSE;
gboolean is_vtrash_folder = FALSE;
gboolean archive_folder_set = FALSE;
guint32 state = 0;
guint ii;
......@@ -4114,6 +4233,8 @@ e_mail_reader_check_state (EMailReader *reader)
uids = e_mail_reader_get_selected_uids (reader);
if (folder != NULL) {
gchar *archive_folder;
store = camel_folder_get_parent_store (folder);
store_supports_vjunk = (store->flags & CAMEL_STORE_VJUNK);
is_junk_folder =
......@@ -4122,6 +4243,12 @@ e_mail_reader_check_state (EMailReader *reader)
drafts_or_outbox =
em_utils_folder_is_drafts (registry, folder) ||
em_utils_folder_is_outbox (registry, folder);
archive_folder = mail_reader_get_archive_folder_from_folder (folder, registry, uids, TRUE);
if (archive_folder && *archive_folder)
archive_folder_set = TRUE;
g_free (archive_folder);
}
/* Initialize this flag based on whether there are any
......@@ -4248,6 +4375,8 @@ e_mail_reader_check_state (EMailReader *reader)
state |= E_MAIL_READER_FOLDER_IS_JUNK;
if (is_vtrash_folder)
state |= E_MAIL_READER_FOLDER_IS_VTRASH;
if (archive_folder_set)
state |= E_MAIL_READER_FOLDER_ARCHIVE_FOLDER_SET;
g_clear_object (&folder);
g_ptr_array_unref (uids);
......
......@@ -87,7 +87,8 @@ enum {
E_MAIL_READER_SELECTION_HAS_ATTACHMENTS = 1 << 15,
E_MAIL_READER_SELECTION_IS_MAILING_LIST = 1 << 16,
E_MAIL_READER_FOLDER_IS_JUNK = 1 << 17,
E_MAIL_READER_FOLDER_IS_VTRASH = 1 << 18
E_MAIL_READER_FOLDER_IS_VTRASH = 1 << 18,
E_MAIL_READER_FOLDER_ARCHIVE_FOLDER_SET = 1 << 19
};
struct _EMailReaderInterface {
......
......@@ -2028,6 +2028,81 @@
<property name="position">2</property>
</packing>
</child>
<child>
<object class="GtkVBox" id="archive-mail-section">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="spacing">6</property>
<child>
<object class="GtkLabel" id="archive-mail-header">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="xalign">0</property>
<property name="label" translatable="yes">Archive Mail</property>
<attributes>
<attribute name="weight" value="bold"/>
</attributes>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkAlignment" id="archive-mail-alignment">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="left_padding">12</property>
<child>
<object class="GtkVBox" id="archive-mail-vbox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="spacing">6</property>
<child>
<object class="GtkHBox" id="archive-mail-hbox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="spacing">4</property>
<child>
<object class="GtkLabel" id="lblArchiveMailFolder">
<property name="label" translatable="yes">On This Computer A_rchive folder:</property>
<property name="tooltip-text" translatable="yes">Archive folder to use for On This Computer messages</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="use-underline">True</property>
<property name="xalign">0</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">0</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">0</property>
</packing>
</child>
</object>
</child>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">3</property>
</packing>
</child>
</object>
<packing>
<property name="tab_fill">False</property>
......
......@@ -1075,6 +1075,18 @@ em_mailer_prefs_construct (EMMailerPrefs *prefs,
widget, "sensitive",
G_SETTINGS_BIND_GET);
container = e_builder_get_widget (prefs->builder, "archive-mail-hbox");
widget = em_folder_selection_button_new (session, "", _("Choose a folder to archive messages to."));
gtk_widget_set_hexpand (widget, FALSE);
gtk_label_set_mnemonic_widget (GTK_LABEL (e_builder_get_widget (prefs->builder, "lblArchiveMailFolder")), widget);
gtk_container_add (GTK_CONTAINER (container), widget);
gtk_widget_show (widget);
g_settings_bind (
settings, "local-archive-folder",
widget, "folder-uri",
G_SETTINGS_BIND_DEFAULT);
/* always de-sensitised until the user types something in the entry */
prefs->add_header = GTK_BUTTON (e_builder_get_widget (prefs->builder, "cmdHeadersAdd"));
gtk_widget_set_sensitive ((GtkWidget *) prefs->add_header, FALSE);
......
......@@ -72,6 +72,7 @@
<separator/>
<menuitem action='mail-copy'/>
<menuitem action='mail-move'/>
<menuitem action='mail-archive'/>
<separator/>
<menu action='mail-mark-as-menu'>
<menuitem action="mail-mark-read"/>
......
......@@ -101,6 +101,7 @@
<menuitem action='mail-popup-undelete'/>
<menuitem action='mail-popup-copy'/>
<menuitem action='mail-popup-move'/>
<menuitem action='mail-popup-archive'/>
<separator/>
<menuitem action='mail-popup-mark-read'/>
<menuitem action='mail-popup-mark-unread'/>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment