diff options
author | Niels De Graef <nielsdegraef@gmail.com> | 2023-02-11 10:55:00 +0100 |
---|---|---|
committer | Niels De Graef <nielsdegraef@gmail.com> | 2023-02-12 09:29:32 +0000 |
commit | 8d9624e25e20e573d5e320ce377c9a171671c164 (patch) | |
tree | 62a81b401a91411b5a0453499562f809c05b91c4 | |
parent | cf0987c7dab429c86f3295c440dbfd0ad957c406 (diff) | |
download | gnome-contacts-8d9624e25e20e573d5e320ce377c9a171671c164.tar.gz |
main-window: Add a menu item to export all contacts
Fixes: https://gitlab.gnome.org/GNOME/gnome-contacts/-/issues/285
-rw-r--r-- | data/ui/contacts-main-window.ui | 6 | ||||
-rw-r--r-- | src/contacts-app.vala | 11 | ||||
-rw-r--r-- | src/contacts-main-window.vala | 10 |
3 files changed, 22 insertions, 5 deletions
diff --git a/data/ui/contacts-main-window.ui b/data/ui/contacts-main-window.ui index 206d172..669db58 100644 --- a/data/ui/contacts-main-window.ui +++ b/data/ui/contacts-main-window.ui @@ -16,9 +16,13 @@ </section> <section> <item> - <attribute name="label" translatable="yes">Import…</attribute> + <attribute name="label" translatable="yes">Import From File…</attribute> <attribute name="action">app.import</attribute> </item> + <item> + <attribute name="label" translatable="yes">Export All Contacts…</attribute> + <attribute name="action">app.export-all</attribute> + </item> </section> <section> <item> diff --git a/src/contacts-app.vala b/src/contacts-app.vala index 3a2cb11..12d2dc5 100644 --- a/src/contacts-app.vala +++ b/src/contacts-app.vala @@ -38,7 +38,8 @@ public class Contacts.App : Adw.Application { { "about", show_about }, { "show-preferences", show_preferences }, { "show-contact", on_show_contact, "s" }, - { "import", on_import } + { "import", on_import }, + { "export-all", on_export_all } }; private const OptionEntry[] options = { @@ -420,4 +421,12 @@ public class Contacts.App : Adw.Application { }); dialog.present (); } + + private void on_export_all (SimpleAction action, Variant? param) { + var model = this.contacts_store.filter_model; + var individuals = new Gee.ArrayList<Individual> (); + for (uint i = 0; i < model.get_n_items (); i++) + individuals.add ((Individual) model.get_item (i)); + this.window.export_individuals (individuals); + } } diff --git a/src/contacts-main-window.vala b/src/contacts-main-window.vala index 8d46b6b..24a8a8d 100644 --- a/src/contacts-main-window.vala +++ b/src/contacts-main-window.vala @@ -592,6 +592,13 @@ public class Contacts.MainWindow : Adw.ApplicationWindow { this.marked_contacts.unselect_all (); this.state = UiState.NORMAL; + var individuals = bitset_to_individuals (this.store.filter_model, + selection); + export_individuals (individuals); + } + + + public void export_individuals (Gee.List<Individual> individuals) { // Open up a file chooser var chooser = new Gtk.FileChooserNative (_("Export to file"), this, @@ -607,9 +614,6 @@ public class Contacts.MainWindow : Adw.ApplicationWindow { } // Do the actual export - var individuals = bitset_to_individuals (this.store.filter_model, - selection); - OutputStream filestream = null; try { filestream = chooser.get_file ().replace (null, false, FileCreateFlags.NONE); |