summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorNiels De Graef <nielsdegraef@gmail.com>2022-07-24 13:33:04 +0200
committerNiels De Graef <nielsdegraef@gmail.com>2022-07-24 13:57:25 +0200
commitf677414715d5a79c0d88a9833690e5b8f6e5254a (patch)
treeff0df4f115c8be4f318d36d6d36bd6575e4a1f4b /src
parent200bc934b6938cabd97f7a90624b5e0fd9d9307c (diff)
downloadgnome-contacts-f677414715d5a79c0d88a9833690e5b8f6e5254a.tar.gz
Add a preferences window
This allows us to simplify the main menu, as well as having an easy way in the future to add extra options.
Diffstat (limited to 'src')
-rw-r--r--src/contacts-accounts-list.vala47
-rw-r--r--src/contacts-addressbook-dialog.vala7
-rw-r--r--src/contacts-app.vala38
-rw-r--r--src/contacts-preferences-window.vala78
-rw-r--r--src/contacts-utils.vala6
-rw-r--r--src/meson.build1
6 files changed, 119 insertions, 58 deletions
diff --git a/src/contacts-accounts-list.vala b/src/contacts-accounts-list.vala
index 202c160..db04cc9 100644
--- a/src/contacts-accounts-list.vala
+++ b/src/contacts-accounts-list.vala
@@ -25,14 +25,12 @@ using Folks;
*
* Internally, each "address book" is a {@link Folks.PersonaStore}.
*/
-[GtkTemplate (ui = "/org/gnome/Contacts/ui/contacts-accounts-list.ui")]
-public class Contacts.AccountsList : Adw.Bin {
-
- [GtkChild]
- private unowned Gtk.ListBox listbox;
+public class Contacts.AccountsList : Adw.PreferencesGroup {
private Gtk.SingleSelection selection;
+ private GenericArray<AddressbookRow> rows = new GenericArray<AddressbookRow> ();
+
/** The selected PersonaStore (or null if none) */
public PersonaStore? selected_store {
get { return (PersonaStore) this.selection.selected_item; }
@@ -47,32 +45,20 @@ public class Contacts.AccountsList : Adw.Bin {
var model = new Gtk.FilterListModel (contacts_store.address_books,
(owned) filter);
+ model.items_changed.connect (on_model_items_changed);
+ on_model_items_changed (model, 0, 0, model.get_n_items ());
+
// Setup the selection model
this.selection = new Gtk.SingleSelection (model);
// Update the row when the selection model changes
this.selection.selection_changed.connect ((sel, pos, n_items) => {
for (uint i = pos; i < pos + n_items; i++) {
- var row = (AddressbookRow?) this.listbox.get_row_at_index ((int) i);
- if (row != null)
- row.selected = this.selection.is_selected (i);
+ this.rows[i].selected = this.selection.is_selected (i);
}
notify_property ("selected-store");
});
- // Now bind the listbox to it
- this.listbox.bind_model (model, (item) => {
- unowned var persona_store = (PersonaStore) item;
- var row = new AddressbookRow (persona_store);
-
- // Update the selection model when the row is activated
- row.activated.connect ((row) => {
- this.selection.set_selected ((uint) row.get_index ());
- });
-
- return row;
- });
-
// Initially, the primary store (if set) is selected
for (uint i = 0; i < model.get_n_items (); i++) {
var persona_store = (PersonaStore) model.get_item (i);
@@ -81,6 +67,25 @@ public class Contacts.AccountsList : Adw.Bin {
}
}
+ private void on_model_items_changed (ListModel model, uint pos, uint removed, uint added) {
+ for (uint i = pos; i < pos + removed; i++) {
+ remove (this.rows[i]);
+ this.rows.remove_index (i);
+ }
+
+ for (uint i = pos; i < pos + added; i++) {
+ var persona_store = (PersonaStore) model.get_item(i);
+ var row = new AddressbookRow (persona_store);
+ add (row);
+ this.rows.add (row);
+
+ // Update the selection model when the row is activated
+ row.activated.connect ((row) => {
+ this.selection.set_selected ((uint) row.get_index ());
+ });
+ }
+ }
+
private class AddressbookRow : Adw.ActionRow {
public PersonaStore persona_store { get; construct set; }
diff --git a/src/contacts-addressbook-dialog.vala b/src/contacts-addressbook-dialog.vala
index 03b13b0..14d7153 100644
--- a/src/contacts-addressbook-dialog.vala
+++ b/src/contacts-addressbook-dialog.vala
@@ -74,10 +74,7 @@ public class Contacts.AddressbookDialog : Gtk.Dialog {
return;
unowned var e_store = (Edsf.PersonaStore) this.accounts_list.selected_store;
- if (e_store != null) {
- eds_source_registry.set_default_address_book (e_store.source);
- var settings = new GLib.Settings ("org.freedesktop.folks");
- settings.set_string ("primary-store", "eds:%s".printf (e_store.id));
- }
+ if (e_store != null)
+ Utils.set_primary_store (e_store);
}
}
diff --git a/src/contacts-app.vala b/src/contacts-app.vala
index dcf3e6e..b127554 100644
--- a/src/contacts-app.vala
+++ b/src/contacts-app.vala
@@ -36,8 +36,7 @@ public class Contacts.App : Adw.Application {
{ "quit", quit_action },
{ "help", show_help },
{ "about", show_about },
- { "change-book", change_address_book },
- { "online-accounts", online_accounts },
+ { "show-preferences", show_preferences },
{ "show-contact", on_show_contact, "s"}
};
@@ -121,30 +120,9 @@ public class Contacts.App : Adw.Application {
dialog.show ();
}
- public void online_accounts () {
- try {
- var proxy = new DBusProxy.for_bus_sync (BusType.SESSION,
- DBusProxyFlags.NONE,
- null,
- "org.gnome.Settings",
- "/org/gnome/Settings",
- "org.gtk.Actions");
-
- var builder = new VariantBuilder (new VariantType ("av"));
- builder.add ("v", new Variant.string (""));
- var param = new Variant.tuple ({
- new Variant.string ("launch-panel"),
- new Variant.array (new VariantType ("v"), {
- new Variant ("v", new Variant ("(sav)", "online-accounts", builder))
- }),
- new Variant.array (new VariantType ("{sv}"), {})
- });
-
- proxy.call_sync ("Activate", param, DBusCallFlags.NONE, -1);
- } catch (Error e) {
- // TODO: Show error dialog
- warning ("Couldn't open online-accounts: %s", e.message);
- }
+ public void show_preferences () {
+ var prefs_window = new PreferencesWindow (this.contacts_store, this.window);
+ prefs_window.show ();
}
public void show_help () {
@@ -278,19 +256,15 @@ public class Contacts.App : Adw.Application {
private void run_setup () {
debug ("Running initial setup");
- // Disable change-book action (don't want the user to do that during setup)
- unowned var change_book_action = lookup_action ("change-book") as SimpleAction;
- change_book_action.set_enabled (false);
-
// Create and show the setup window
var setup_window = new SetupWindow (this, this.contacts_store);
setup_window.setup_done.connect ((selected_store) => {
setup_window.destroy ();
- eds_source_registry.set_default_address_book (selected_store.source);
+ unowned var edsf_store = (Edsf.PersonaStore) selected_store;
+ Utils.set_primary_store (edsf_store);
this.settings.did_initial_setup = true;
- change_book_action.set_enabled (true); // re-enable change-book action
create_window ();
});
setup_window.show ();
diff --git a/src/contacts-preferences-window.vala b/src/contacts-preferences-window.vala
new file mode 100644
index 0000000..e6abbd2
--- /dev/null
+++ b/src/contacts-preferences-window.vala
@@ -0,0 +1,78 @@
+/*
+ * Copyright (C) 2022 Niels De Graef <nielsdegraef@gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+using Folks;
+
+[GtkTemplate (ui = "/org/gnome/Contacts/ui/contacts-preferences-window.ui")]
+public class Contacts.PreferencesWindow : Adw.PreferencesWindow {
+
+ [GtkChild]
+ private unowned Adw.PreferencesPage address_books_page;
+
+ public PreferencesWindow (Store contacts_store, Gtk.Window? transient_for) {
+ Object (transient_for: transient_for, search_enabled: false);
+
+ var acc_list = new AccountsList (contacts_store);
+ acc_list.title = _("Primary Address Book");
+ acc_list.description = _("New contacts will be added to the selected address book. You are able to view and edit contacts from other address books.");
+ this.address_books_page.add (acc_list);
+
+ acc_list.notify["selected-store"].connect ((obj, pspec) => {
+ var edsf_store = (Edsf.PersonaStore) acc_list.selected_store;
+ Utils.set_primary_store (edsf_store);
+ });
+
+ var goa_button_content = new Adw.ButtonContent ();
+ goa_button_content.label = _("_Online Accounts");
+ goa_button_content.use_underline = true;
+ goa_button_content.icon_name = "external-link-symbolic";
+ var goa_button = new Gtk.Button ();
+ goa_button.set_child (goa_button_content);
+ goa_button.tooltip_text = _("Opens the Online Accounts panel in GNOME Settings");
+ goa_button.margin_top = 36;
+ goa_button.halign = Gtk.Align.CENTER;
+ goa_button.add_css_class ("pill");
+ goa_button.clicked.connect (on_goa_button_clicked);
+ acc_list.add (goa_button);
+ }
+
+ private void on_goa_button_clicked (Gtk.Button goa_button) {
+ try {
+ var proxy = new DBusProxy.for_bus_sync (BusType.SESSION,
+ DBusProxyFlags.NONE,
+ null,
+ "org.gnome.Settings",
+ "/org/gnome/Settings",
+ "org.gtk.Actions");
+
+ var builder = new VariantBuilder (new VariantType ("av"));
+ builder.add ("v", new Variant.string (""));
+ var param = new Variant.tuple ({
+ new Variant.string ("launch-panel"),
+ new Variant.array (new VariantType ("v"), {
+ new Variant ("v", new Variant ("(sav)", "online-accounts", builder))
+ }),
+ new Variant.array (new VariantType ("{sv}"), {})
+ });
+
+ proxy.call_sync ("Activate", param, DBusCallFlags.NONE, -1);
+ } catch (Error e) {
+ // TODO: Show error dialog
+ warning ("Couldn't open online-accounts: %s", e.message);
+ }
+ }
+}
diff --git a/src/contacts-utils.vala b/src/contacts-utils.vala
index a5c28c0..f5d6a66 100644
--- a/src/contacts-utils.vala
+++ b/src/contacts-utils.vala
@@ -29,6 +29,12 @@ namespace Contacts {
namespace Contacts.Utils {
+ public void set_primary_store (Edsf.PersonaStore e_store) {
+ eds_source_registry.set_default_address_book (e_store.source);
+ var settings = new GLib.Settings ("org.freedesktop.folks");
+ settings.set_string ("primary-store", "eds:%s".printf (e_store.id));
+ }
+
public void compose_mail (string email) {
var mailto_uri = "mailto:" + Uri.escape_string (email, "@" , false);
Gtk.show_uri (null, mailto_uri, 0);
diff --git a/src/meson.build b/src/meson.build
index 1f3890e..c246b61 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -87,6 +87,7 @@ contacts_vala_sources = files(
'contacts-link-suggestion-grid.vala',
'contacts-linked-personas-dialog.vala',
'contacts-main-window.vala',
+ 'contacts-preferences-window.vala',
'contacts-settings.vala',
'contacts-setup-window.vala',
'contacts-type-combo.vala',