[geary/mjog/mail-merge-plugin: 69/72] MailMerge.Folder: Add skeleton properties for accessing folder state




commit 99bc719fe1d39118a713c28ca6f980a78065e72b
Author: Michael Gratton <mike vee net>
Date:   Fri Aug 14 16:05:12 2020 +1000

    MailMerge.Folder: Add skeleton properties for accessing folder state
    
    Add properties to allow determining the data's file name, the number of
    email total and sent, and if the folder is currently sending.

 .../plugin/mail-merge/mail-merge-folder.vala       | 44 ++++++++++++++++++++--
 src/client/plugin/mail-merge/mail-merge.vala       |  3 +-
 2 files changed, 42 insertions(+), 5 deletions(-)
---
diff --git a/src/client/plugin/mail-merge/mail-merge-folder.vala 
b/src/client/plugin/mail-merge/mail-merge-folder.vala
index bacc9216a..7e07f10d7 100644
--- a/src/client/plugin/mail-merge/mail-merge-folder.vala
+++ b/src/client/plugin/mail-merge/mail-merge-folder.vala
@@ -114,6 +114,22 @@ public class MailMerge.Folder : Geary.AbstractLocalFolder {
     }
     Geary.Folder.SpecialUse _used_as = NONE;
 
+    /** The source data file used the folder. */
+    public GLib.File data_location { get; private set; }
+
+    /** The display name for {@link data_location}. */
+    public string data_display_name { get; private set; }
+
+    /** The number of email that have been sent. */
+    public uint email_sent { get; private set; default = 0; }
+
+    /** The number of email in total. */
+    public uint email_total { get; private set; default = 0; }
+
+    /** Specifies if the merged mail is currently being sent. */
+    public bool is_sending { get; private set; default = false; }
+
+
     private Gee.Map<Geary.EmailIdentifier,Geary.Email> map =
         new Gee.HashMap<Geary.EmailIdentifier,Geary.Email>();
     private Gee.List<Geary.Email> list =
@@ -123,18 +139,37 @@ public class MailMerge.Folder : Geary.AbstractLocalFolder {
     private GLib.Cancellable loading = new GLib.Cancellable();
 
 
-    public Folder(Geary.Account account,
-                  Geary.FolderRoot root,
-                  Geary.Email template,
-                  Csv.Reader data) {
+    public async Folder(Geary.Account account,
+                        Geary.FolderRoot root,
+                        Geary.Email template,
+                        GLib.File data_location,
+                        Csv.Reader data)
+        throws GLib.Error {
         this._account = account;
         this._path = root.get_child("$Plugin.MailMerge$");
         this.template = template;
+        this.data_location = data_location;
         this.data = data;
 
+        var info = yield data_location.query_info_async(
+            GLib.FileAttribute.STANDARD_DISPLAY_NAME,
+            NONE,
+            GLib.Priority.DEFAULT,
+            null
+        );
+        this.data_display_name = info.get_display_name();
+
+        // Do this in the background to avoid blocking while the whole
+        // file is processed
         this.load_data.begin(this.loading);
     }
 
+
+    /** Starts or stops the folder sending mail. */
+    public void set_sending(bool is_sending) {
+        this.is_sending = is_sending;
+    }
+
     /** {@inheritDoc} */
     public override async Gee.Collection<Geary.EmailIdentifier> contains_identifiers(
         Gee.Collection<Geary.EmailIdentifier> ids,
@@ -278,6 +313,7 @@ public class MailMerge.Folder : Geary.AbstractLocalFolder {
                 this.list.add(email);
                 this.map.set(id, email);
                 this._properties.set_total((int) next_id);
+                this.email_total = (uint) next_id;
 
                 notify_email_inserted(Geary.Collection.single(id));
                 record = yield this.data.read_record();
diff --git a/src/client/plugin/mail-merge/mail-merge.vala b/src/client/plugin/mail-merge/mail-merge.vala
index 6a33f65c0..10b64660d 100644
--- a/src/client/plugin/mail-merge/mail-merge.vala
+++ b/src/client/plugin/mail-merge/mail-merge.vala
@@ -199,10 +199,11 @@ public class Plugin.MailMerge :
                     );
                     var email = Geary.Collection.first(emails);
 
-                    this.merge_folder = new global::MailMerge.Folder(
+                    this.merge_folder = yield new global::MailMerge.Folder(
                         account_context.account,
                         account_context.account.local_folder_root,
                         yield load_merge_email(email),
+                        csv_file,
                         csv
                     );
 


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