[geary/mjog/email-plugins: 61/61] Plugin.SpecialFolder: Update to also handle drafts and outbox
- From: Michael Gratton <mjog src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [geary/mjog/email-plugins: 61/61] Plugin.SpecialFolder: Update to also handle drafts and outbox
- Date: Mon, 30 Mar 2020 10:08:43 +0000 (UTC)
commit b2e1461322fbc9d8ab2a02b3e5f9a6afdfe4e860
Author: Michael Gratton <mike vee net>
Date: Mon Mar 23 00:13:51 2020 +1100
Plugin.SpecialFolder: Update to also handle drafts and outbox
Keep track of email being displayed, add an infobar to any that are
drafts or that are un-saved outbox messages.
.../plugin/special-folders/special-folders.vala | 117 ++++++++++++++++++---
1 file changed, 100 insertions(+), 17 deletions(-)
---
diff --git a/src/client/plugin/special-folders/special-folders.vala
b/src/client/plugin/special-folders/special-folders.vala
index daea99b0..6896294a 100644
--- a/src/client/plugin/special-folders/special-folders.vala
+++ b/src/client/plugin/special-folders/special-folders.vala
@@ -17,7 +17,8 @@ public void peas_register_types(TypeModule module) {
/**
* Manages UI for special folders.
*/
-public class Plugin.SpecialFolders : PluginBase, FolderExtension {
+public class Plugin.SpecialFolders :
+ PluginBase, FolderExtension, EmailExtension {
// InfoBar button action name
@@ -31,59 +32,108 @@ public class Plugin.SpecialFolders : PluginBase, FolderExtension {
get; set construct;
}
+ public EmailContext email {
+ get; set construct;
+ }
- private FolderStore? store = null;
+
+ private FolderStore? folder_store = null;
private GLib.SimpleAction? empty_action = null;
+ private EmailStore? email_store = null;
+
private Gee.Map<Folder,InfoBar> info_bars =
new Gee.HashMap<Folder,InfoBar>();
+ private GLib.Cancellable cancellable = new GLib.Cancellable();
+
public override async void activate() throws GLib.Error {
- this.store = yield this.folders.get_folders();
- this.store.folder_selected.connect(on_folder_selected);
- this.store.folders_type_changed.connect(on_folders_type_changed);
+ this.folder_store = yield this.folders.get_folders();
+ this.folder_store.folder_selected.connect(on_folder_selected);
+ this.folder_store.folders_type_changed.connect(on_folders_type_changed);
this.empty_action = new GLib.SimpleAction(
- ACTION_NAME, store.folder_variant_type
+ ACTION_NAME, this.folder_store.folder_variant_type
);
this.empty_action.activate.connect(on_empty_activated);
-
this.plugin_application.register_action(this.empty_action);
+
+ this.email_store = yield this.email.get_email();
+ this.email_store.email_displayed.connect(on_email_displayed);
}
public override async void deactivate(bool is_shutdown) throws GLib.Error {
this.plugin_application.deregister_action(this.empty_action);
-
this.empty_action.activate.disconnect(on_empty_activated);
this.empty_action = null;
- this.store.folder_selected.disconnect(on_folder_selected);
- this.store.folders_type_changed.disconnect(on_folders_type_changed);
- this.store = null;
+ this.folder_store.folder_selected.disconnect(on_folder_selected);
+ this.folder_store.folders_type_changed.disconnect(on_folders_type_changed);
+ this.folder_store = null;
+
+ this.email_store.email_displayed.disconnect(on_email_displayed);
+
+ this.cancellable.cancel();
}
private void update_folder(Folder target) {
switch (target.folder_type) {
case TRASH:
this.folders.add_folder_info_bar(
- target, get_info_bar(target), PRIORITY
+ target, get_folder_info_bar(target), PRIORITY
);
break;
case SPAM:
this.folders.add_folder_info_bar(
- target, get_info_bar(target), PRIORITY
+ target, get_folder_info_bar(target), PRIORITY
);
break;
}
}
- private InfoBar get_info_bar(Folder target) {
+ private async void update_email(Email target) {
+ bool is_draft = false;
+ if (target.flags.is_draft()) {
+ is_draft = true;
+ } else if (this.folder_store != null) {
+ try {
+ Gee.Collection<Folder> folders = yield
+ this.folder_store.list_containing_folders(
+ target.identifier, this.cancellable
+ );
+ foreach (var folder in folders) {
+ if (folder.folder_type == DRAFTS) {
+ is_draft = true;
+ break;
+ }
+ }
+ } catch (GLib.Error err) {
+ warning("Could not list containing folders for email");
+ }
+ }
+ if (is_draft) {
+ this.email.add_email_info_bar(
+ target.identifier,
+ new_draft_info_bar(target),
+ PRIORITY
+ );
+ }
+
+ if (target.flags.is_outbox_sent()) {
+ this.email.add_email_info_bar(
+ target.identifier,
+ new_unsaved_info_bar(target),
+ PRIORITY
+ );
+ }
+ }
+
+ private InfoBar get_folder_info_bar(Folder target) {
var bar = this.info_bars.get(target);
if (bar == null) {
bar = new InfoBar(target.folder_type.get_display_name());
- debug("XXXX folder variant type: %s", target.to_variant().get_type_string());
bar.primary_button = new Button(
// Translators: Info bar button label for emptying
// trash/spam folders
@@ -96,6 +146,35 @@ public class Plugin.SpecialFolders : PluginBase, FolderExtension {
return bar;
}
+ private InfoBar new_draft_info_bar(Email target) {
+ var bar = new InfoBar(
+ // Translators: Info bar status message for a draft email
+ _("Draft message"),
+ // Translators: Info bar status description for a draft
+ // email
+ _("This message has not yet been sent.")
+ );
+ bar.primary_button = new Button(
+ // Translators: Info bar button label for editing a draft
+ // email
+ _("Edit"),
+ this.empty_action,
+ target.identifier.to_variant()
+ );
+ return bar;
+ }
+
+ private InfoBar new_unsaved_info_bar(Email target) {
+ return new InfoBar(
+ // Translators: Info bar status message for an sent but
+ // unsaved email
+ _("Message not saved"),
+ // Translators: Info bar status description for a sent but
+ // unsaved email
+ _("This message was sent, but has not been saved to your account.")
+ );
+ }
+
private void on_folder_selected(Folder selected) {
update_folder(selected);
}
@@ -112,12 +191,16 @@ public class Plugin.SpecialFolders : PluginBase, FolderExtension {
}
private void on_empty_activated(GLib.Action action, GLib.Variant? target) {
- if (this.store != null && target != null) {
- Folder? folder = this.store.get_folder_from_variant(target);
+ if (this.folder_store != null && target != null) {
+ Folder? folder = this.folder_store.get_folder_from_variant(target);
if (folder != null) {
this.plugin_application.empty_folder.begin(folder);
}
}
}
+ private void on_email_displayed(Email email) {
+ update_email.begin(email);
+ }
+
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]