[geary/mjog/mail-merge-plugin: 48/71] Plugins.MailMerge: Initial composer mail merge support
- From: Michael Gratton <mjog src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [geary/mjog/mail-merge-plugin: 48/71] Plugins.MailMerge: Initial composer mail merge support
- Date: Wed, 5 Aug 2020 05:00:48 +0000 (UTC)
commit 035129f18118391edc2904488c2169bad4401097
Author: Michael Gratton <mike vee net>
Date: Fri Jul 3 18:09:13 2020 +1000
Plugins.MailMerge: Initial composer mail merge support
Register composer menu item for loading mail merge data, show file
chooser for CSV and print test debug on loading.
src/client/plugin/mail-merge/mail-merge.vala | 45 ++++++++++++++++++++++++++++
1 file changed, 45 insertions(+)
---
diff --git a/src/client/plugin/mail-merge/mail-merge.vala b/src/client/plugin/mail-merge/mail-merge.vala
index e1001ad23..fe5fa254d 100644
--- a/src/client/plugin/mail-merge/mail-merge.vala
+++ b/src/client/plugin/mail-merge/mail-merge.vala
@@ -40,6 +40,7 @@ public class Plugin.MailMerge :
private const string ACTION_EDIT = "edit-template";
private const string ACTION_MERGE = "merge-template";
+ private const string ACTION_LOAD = "load-merge-data";
private const int INFO_BAR_PRIORITY = 10;
@@ -90,6 +91,10 @@ public class Plugin.MailMerge :
);
this.merge_action.activate.connect(on_merge_activated);
this.plugin_application.register_action(this.merge_action);
+
+ this.plugin_application.composer_registered.connect(
+ this.on_composer_registered
+ );
}
public override async void deactivate(bool is_shutdown) throws GLib.Error {
@@ -181,6 +186,42 @@ public class Plugin.MailMerge :
}
}
+ private async void update_composer(Composer composer) {
+ if (true) {
+ var load_action = new GLib.SimpleAction(ACTION_LOAD, null);
+ load_action.activate.connect(
+ () => { load_composer_data.begin(composer); }
+ );
+ composer.register_action(load_action);
+ composer.append_menu_item(
+ new Actionable(_("Mail Merge"), load_action)
+ );
+ }
+ }
+
+ private async void load_composer_data(Composer composer) {
+ var chooser = new Gtk.FileChooserNative(
+ _("Mail Merge"), null, OPEN, _("_Open"), _("_Cancel")
+ );
+ var csv_filter = new Gtk.FileFilter();
+ csv_filter.set_filter_name(_("Comma separated values (CSV)"));
+ csv_filter.add_mime_type("text/csv");
+ chooser.add_filter(csv_filter);
+ if (chooser.run() == Gtk.ResponseType.ACCEPT) {
+ try {
+ var input = yield chooser.get_file().read_async(
+ GLib.Priority.DEFAULT,
+ this.cancellable
+ );
+ var csv = yield new Util.Csv.Reader(input, this.cancellable);
+ var record = yield csv.read_record();
+ debug("XXX record: %s", string.join(",", record));
+ } catch (GLib.Error err) {
+ debug("Error loading CSV: %s", err.message);
+ }
+ }
+ }
+
private InfoBar new_template_email_info_bar(EmailIdentifier target) {
// Translators: Infobar status label for an email mail merge
// template
@@ -250,6 +291,10 @@ public class Plugin.MailMerge :
}
}
+ private void on_composer_registered(Composer registered) {
+ this.update_composer.begin(registered);
+ }
+
private void on_email_displayed(Email email) {
this.update_email.begin(email);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]