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.
This commit is contained in:
Michael Gratton 2020-08-14 16:05:12 +10:00 committed by Michael James Gratton
parent 7d6078d7c9
commit 99bc719fe1
2 changed files with 42 additions and 5 deletions

View file

@ -114,6 +114,22 @@ public class MailMerge.Folder : Geary.AbstractLocalFolder {
} }
Geary.Folder.SpecialUse _used_as = NONE; 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 = private Gee.Map<Geary.EmailIdentifier,Geary.Email> map =
new Gee.HashMap<Geary.EmailIdentifier,Geary.Email>(); new Gee.HashMap<Geary.EmailIdentifier,Geary.Email>();
private Gee.List<Geary.Email> list = private Gee.List<Geary.Email> list =
@ -123,18 +139,37 @@ public class MailMerge.Folder : Geary.AbstractLocalFolder {
private GLib.Cancellable loading = new GLib.Cancellable(); private GLib.Cancellable loading = new GLib.Cancellable();
public Folder(Geary.Account account, public async Folder(Geary.Account account,
Geary.FolderRoot root, Geary.FolderRoot root,
Geary.Email template, Geary.Email template,
Csv.Reader data) { GLib.File data_location,
Csv.Reader data)
throws GLib.Error {
this._account = account; this._account = account;
this._path = root.get_child("$Plugin.MailMerge$"); this._path = root.get_child("$Plugin.MailMerge$");
this.template = template; this.template = template;
this.data_location = data_location;
this.data = data; 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); 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} */ /** {@inheritDoc} */
public override async Gee.Collection<Geary.EmailIdentifier> contains_identifiers( public override async Gee.Collection<Geary.EmailIdentifier> contains_identifiers(
Gee.Collection<Geary.EmailIdentifier> ids, Gee.Collection<Geary.EmailIdentifier> ids,
@ -278,6 +313,7 @@ public class MailMerge.Folder : Geary.AbstractLocalFolder {
this.list.add(email); this.list.add(email);
this.map.set(id, email); this.map.set(id, email);
this._properties.set_total((int) next_id); this._properties.set_total((int) next_id);
this.email_total = (uint) next_id;
notify_email_inserted(Geary.Collection.single(id)); notify_email_inserted(Geary.Collection.single(id));
record = yield this.data.read_record(); record = yield this.data.read_record();

View file

@ -199,10 +199,11 @@ public class Plugin.MailMerge :
); );
var email = Geary.Collection.first(emails); 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,
account_context.account.local_folder_root, account_context.account.local_folder_root,
yield load_merge_email(email), yield load_merge_email(email),
csv_file,
csv csv
); );