[gnome-contacts] AddresBookDialog: Split off code in its own class
- From: Niels De Graef <nielsdg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-contacts] AddresBookDialog: Split off code in its own class
- Date: Fri, 5 Jun 2020 12:15:21 +0000 (UTC)
commit c2b0edc13a8013365bf7ddffda08cff7d715dd5f
Author: Niels De Graef <nielsdegraef gmail com>
Date: Fri Jun 5 14:14:06 2020 +0200
AddresBookDialog: Split off code in its own class
... and fix the minimal height obscuring most of the content on
non-small screens.
Fixes https://gitlab.gnome.org/GNOME/gnome-contacts/-/issues/119
po/POTFILES.in | 1 +
po/POTFILES.skip | 1 +
src/contacts-addressbook-dialog.vala | 95 ++++++++++++++++++++++++++++++++++++
src/contacts-app.vala | 69 ++------------------------
src/meson.build | 1 +
5 files changed, 101 insertions(+), 66 deletions(-)
---
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 7dcb1c8..40c2f63 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -15,6 +15,7 @@ data/ui/contacts-setup-window.ui
data/ui/contacts-window.ui
src/contacts-accounts-list.vala
src/contacts-addressbook-list.vala
+src/contacts-addressbook-dialog.vala
src/contacts-app.vala
src/contacts-avatar-selector.vala
src/contacts-avatar.vala
diff --git a/po/POTFILES.skip b/po/POTFILES.skip
index c282dce..ba07dd3 100644
--- a/po/POTFILES.skip
+++ b/po/POTFILES.skip
@@ -4,6 +4,7 @@ data/org.gnome.Contacts.appdata.xml
data/org.gnome.Contacts.desktop
src/contacts-accounts-list.c
src/contacts-addressbook-list.c
+src/contacts-addressbook-dialog.c
src/contacts-app.c
src/contacts-avatar.c
src/contacts-avatar-selector.c
diff --git a/src/contacts-addressbook-dialog.vala b/src/contacts-addressbook-dialog.vala
new file mode 100644
index 0000000..7405eb7
--- /dev/null
+++ b/src/contacts-addressbook-dialog.vala
@@ -0,0 +1,95 @@
+/*
+ * Copyright (C) 2020 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;
+
+public class Contacts.AddressbookDialog : Hdy.Dialog {
+
+ private AccountsList accounts_list;
+
+ public AddressbookDialog (Store contacts_store, Gtk.Window? window) {
+ Object(
+ transient_for: window,
+ title: _("Change Address Book"),
+ use_header_bar: 1
+ );
+
+ add_buttons (_("Change"), Gtk.ResponseType.OK,
+ _("Cancel"), Gtk.ResponseType.CANCEL);
+
+ var content_area = get_content_area () as Gtk.Box;
+ content_area.border_width = 0;
+
+ var ok_button = get_widget_for_response (Gtk.ResponseType.OK);
+ ok_button.sensitive = false;
+ ok_button.get_style_context ().add_class ("suggested-action");
+
+ var scrolled_window = new Gtk.ScrolledWindow (null, null);
+ scrolled_window.expand = true;
+ scrolled_window.height_request = 300;
+ scrolled_window.hscrollbar_policy = Gtk.PolicyType.NEVER;
+ scrolled_window.propagate_natural_height = true;
+ content_area.add (scrolled_window);
+
+ var column = new Hdy.Column ();
+ column.margin_top = 32;
+ column.margin_bottom = 32;
+ column.margin_start = 12;
+ column.margin_end = 12;
+ column.maximum_width = 400;
+ column.linear_growth_width = 400;
+ scrolled_window.add (column);
+
+ var box = new Gtk.Box (Gtk.Orientation.VERTICAL, 12);
+ box.valign = Gtk.Align.START;
+ column.add (box);
+
+ var explanation_label = new Gtk.Label (_("New contacts will be added to the selected address book.\nYou
are able to view and edit contacts from other address books."));
+ explanation_label.xalign = 0;
+ explanation_label.wrap = true;
+ box.add (explanation_label);
+
+ this.accounts_list = new AccountsList (contacts_store);
+ this.accounts_list.update_contents (true);
+
+ ulong active_button_once = 0;
+ active_button_once = this.accounts_list.account_selected.connect (() => {
+ ok_button.sensitive = true;
+ this.accounts_list.disconnect (active_button_once);
+ });
+
+ contacts_store.backend_store.backend_available.connect (() => {
+ this.accounts_list.update_contents (true);
+ });
+
+ box.add (this.accounts_list);
+
+ show_all ();
+ }
+
+ public override void response (int response) {
+ if (response != Gtk.ResponseType.OK)
+ return;
+
+ var e_store = this.accounts_list.selected_store as Edsf.PersonaStore;
+ 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));
+ }
+ }
+}
diff --git a/src/contacts-app.vala b/src/contacts-app.vala
index c0ab5d5..531d0e0 100644
--- a/src/contacts-app.vala
+++ b/src/contacts-app.vala
@@ -112,72 +112,9 @@ public class Contacts.App : Gtk.Application {
}
public void change_address_book () {
- var dialog = new Hdy.Dialog ((Window) window);
- dialog.title = _("Change Address Book");
- dialog.add_buttons (_("Change"), Gtk.ResponseType.OK,
- _("Cancel"), Gtk.ResponseType.CANCEL,
- null);
-
- var content_area = dialog.get_content_area () as Gtk.Box;
- content_area.border_width = 0;
-
- var ok_button = dialog.get_widget_for_response (Gtk.ResponseType.OK);
- ok_button.sensitive = false;
- ok_button.get_style_context ().add_class ("suggested-action");
-
- var scrolled_window = new Gtk.ScrolledWindow (null, null);
- scrolled_window.expand = true;
- scrolled_window.hscrollbar_policy = Gtk.PolicyType.NEVER;
- scrolled_window.propagate_natural_height = true;
- content_area.add (scrolled_window);
-
- var column = new Hdy.Column ();
- column.margin_top = 32;
- column.margin_bottom = 32;
- column.margin_start = 12;
- column.margin_end = 12;
- column.maximum_width = 400;
- column.linear_growth_width = 400;
- scrolled_window.add (column);
-
- var box = new Gtk.Box (Gtk.Orientation.VERTICAL, 12);
- box.valign = Gtk.Align.START;
- column.add (box);
-
- var explanation_label = new Gtk.Label (_("New contacts will be added to the selected address book.\nYou
are able to view and edit contacts from other address books."));
- explanation_label.xalign = 0;
- explanation_label.wrap = true;
- box.add (explanation_label);
-
- var acc = new AccountsList (this.contacts_store);
- acc.update_contents (true);
-
- ulong active_button_once = 0;
- active_button_once = acc.account_selected.connect (() => {
- ok_button.sensitive = true;
- acc.disconnect (active_button_once);
- });
-
- ulong stores_changed_id = contacts_store.backend_store.backend_available.connect (() => {
- acc.update_contents (true);
- });
-
- box.add (acc);
-
- dialog.show_all ();
- dialog.response.connect ( (response) => {
- if (response == Gtk.ResponseType.OK) {
- var e_store = acc.selected_store as Edsf.PersonaStore;
- 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));
- }
- }
- contacts_store.backend_store.disconnect (stores_changed_id);
- dialog.destroy ();
- });
+ var dialog = new AddressbookDialog (this.contacts_store, this.window);
+ dialog.run ();
+ dialog.destroy ();
}
public void online_accounts () {
diff --git a/src/meson.build b/src/meson.build
index def863c..b59578a 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -75,6 +75,7 @@ libcontacts_dep = declare_dependency(
# The gnome-contacts binary
contacts_vala_sources = files(
'contacts-addressbook-list.vala',
+ 'contacts-addressbook-dialog.vala',
'contacts-accounts-list.vala',
'contacts-app.vala',
'contacts-avatar.vala',
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]