[geary/mjog/email-plugins: 9/13] Plugin.EmailContext: Add support for adding email info bars



commit 81c6b894772693bf896bbeba8786020f4f89b92c
Author: Michael Gratton <mike vee net>
Date:   Sun Mar 22 18:06:16 2020 +1100

    Plugin.EmailContext: Add support for adding email info bars
    
    Add new add_email_info_bar and remove_email_info_bar methods to the
    interface, implement these in Application.EmailContext.

 .../application/application-email-context.vala     | 39 +++++++++++++++++++++-
 .../application-email-store-factory.vala           |  5 +++
 .../application/application-plugin-manager.vala    |  3 +-
 src/client/plugin/plugin-email-extension.vala      | 25 ++++++++++++++
 4 files changed, 70 insertions(+), 2 deletions(-)
---
diff --git a/src/client/application/application-email-context.vala 
b/src/client/application/application-email-context.vala
index dd8a13df..a79cd5bb 100644
--- a/src/client/application/application-email-context.vala
+++ b/src/client/application/application-email-context.vala
@@ -15,13 +15,16 @@ internal class Application.EmailContext :
     private unowned Client application;
     private EmailStoreFactory email_factory;
     private Plugin.EmailStore email;
+    private string action_group_name;
 
 
     internal EmailContext(Client application,
-                          EmailStoreFactory email_factory) {
+                          EmailStoreFactory email_factory,
+                          string action_group_name) {
         this.application = application;
         this.email_factory = email_factory;
         this.email = email_factory.new_email_store();
+        this.action_group_name = action_group_name;
     }
 
     public async Plugin.EmailStore get_email()
@@ -29,6 +32,40 @@ internal class Application.EmailContext :
         return this.email;
     }
 
+    public void add_email_info_bar(Plugin.EmailIdentifier displayed,
+                                    Plugin.InfoBar info_bar,
+                                    uint priority) {
+        Geary.EmailIdentifier? id = this.email_factory.to_engine_id(displayed);
+        if (id != null) {
+            foreach (MainWindow main in this.application.get_main_windows()) {
+                if (main.conversation_viewer.current_list != null) {
+                    main.conversation_viewer.current_list.add_email_info_bar(
+                        id,
+                        new Components.InfoBar.for_plugin(
+                            info_bar, this.action_group_name
+                        )
+                    );
+                }
+            }
+        }
+    }
+
+    public void remove_email_info_bar(Plugin.EmailIdentifier displayed,
+                                      Plugin.InfoBar info_bar) {
+        Geary.EmailIdentifier? id = this.email_factory.to_engine_id(displayed);
+        if (id != null) {
+            foreach (MainWindow main in this.application.get_main_windows()) {
+                if (main.conversation_viewer.current_list != null) {
+                    // XXX implement this
+                    //main.conversation_viewer.current_list.remove_email_info_bar(
+                    //    id,
+                    //    XXX
+                    //);
+                }
+            }
+        }
+    }
+
     internal void email_sent(Geary.AccountInformation account,
                              Geary.Email email) {
         this.email.email_sent(email_factory.to_plugin_email(email, account));
diff --git a/src/client/application/application-email-store-factory.vala 
b/src/client/application/application-email-store-factory.vala
index f65a6233..805c6b37 100644
--- a/src/client/application/application-email-store-factory.vala
+++ b/src/client/application/application-email-store-factory.vala
@@ -207,6 +207,11 @@ internal class Application.EmailStoreFactory : Geary.BaseObject {
         return plugin_ids;
     }
 
+    public Geary.EmailIdentifier? to_engine_id(Plugin.EmailIdentifier plugin) {
+        var impl = plugin as IdImpl;
+        return (impl != null) ? impl.backing : null;
+    }
+
     public Plugin.Email to_plugin_email(Geary.Email engine,
                                         Geary.AccountInformation account) {
         return new EmailImpl(engine, account);
diff --git a/src/client/application/application-plugin-manager.vala 
b/src/client/application/application-plugin-manager.vala
index 89bc02be..4dffbf28 100644
--- a/src/client/application/application-plugin-manager.vala
+++ b/src/client/application/application-plugin-manager.vala
@@ -323,7 +323,8 @@ public class Application.PluginManager : GLib.Object {
             if (email != null) {
                 var context = new EmailContext(
                     this.application,
-                    this.email_factory
+                    this.email_factory,
+                    plugin_application.action_group_name
                 );
                 this.email_contexts.set(info, context);
                 email.email = context;
diff --git a/src/client/plugin/plugin-email-extension.vala b/src/client/plugin/plugin-email-extension.vala
index 3106d301..77ce0dd2 100644
--- a/src/client/plugin/plugin-email-extension.vala
+++ b/src/client/plugin/plugin-email-extension.vala
@@ -50,4 +50,29 @@ public interface Plugin.EmailContext : Geary.BaseObject {
     public abstract async EmailStore get_email()
         throws Error.PERMISSION_DENIED;
 
+    /**
+     * Adds an info bar to an email, if displayed.
+     *
+     * The info bar will be shown for the given email if it is
+     * currently displayed in any main window, which can be determined
+     * by connecting to the {@link email_displayed} signal. Further,
+     * if multiple info bars are added for the same email, only the
+     * one with a higher priority will be shown. If that is closed or
+     * removed, the second highest will be shown, and so on. Once the
+     * email is no longer shown, the info bars will be automatically
+     * removed.
+     */
+    public abstract void add_email_info_bar(EmailIdentifier displayed,
+                                            InfoBar info_bar,
+                                            uint priority);
+
+    /**
+     * Removes an info bar from a email, if displayed.
+     *
+     * Removes the info bar from the given email if it is currently
+     * displayed in any main window.
+     */
+    public abstract void remove_email_info_bar(EmailIdentifier displayed,
+                                               InfoBar info_bar);
+
 }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]