[gnome-contacts] Try to steer away from using App as a singleton.
- From: Niels De Graef <nielsdg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-contacts] Try to steer away from using App as a singleton.
- Date: Sun, 27 Aug 2017 16:39:24 +0000 (UTC)
commit dc2a0452424bf79714b1478c3249deac94bc2bcd
Author: Niels De Graef <nielsdegraef gmail com>
Date: Sun Aug 27 18:34:03 2017 +0200
Try to steer away from using App as a singleton.
In the end, the best way to go would be to not use the App singleton at
all. For example, this would allow us to have modular, testable classes.
src/contacts-accounts-list.vala | 11 +++++++----
src/contacts-app.vala | 9 ++++-----
src/contacts-contact-pane.vala | 7 +++----
3 files changed, 14 insertions(+), 13 deletions(-)
---
diff --git a/src/contacts-accounts-list.vala b/src/contacts-accounts-list.vala
index 652b26e..85c6aca 100644
--- a/src/contacts-accounts-list.vala
+++ b/src/contacts-accounts-list.vala
@@ -25,11 +25,14 @@ public class Contacts.AccountsList : Box {
private ListBoxRow last_selected_row;
- public PersonaStore selected_store;
+ private Store contacts_store;
+
+ public PersonaStore? selected_store;
public signal void account_selected ();
- construct {
+ public AccountsList (Store contacts_store) {
+ this.contacts_store = contacts_store;
this.selected_store = null;
this.accounts_view.set_header_func (add_separator);
@@ -123,7 +126,7 @@ public class Contacts.AccountsList : Box {
accounts_view.add (row_data);
if (select_active &&
- persona_store == App.app.contacts_store.aggregator.primary_store) {
+ persona_store == this.contacts_store.aggregator.primary_store) {
var row = row_data.get_parent () as ListBoxRow;
row_activated (row);
}
@@ -142,7 +145,7 @@ public class Contacts.AccountsList : Box {
local_data.add (local_label);
accounts_view.add (local_data);
if (select_active &&
- local_store == App.app.contacts_store.aggregator.primary_store) {
+ local_store == this.contacts_store.aggregator.primary_store) {
var row = local_data.get_parent () as ListBoxRow;
row_activated (row);
}
diff --git a/src/contacts-app.vala b/src/contacts-app.vala
index 61c2f91..3923189 100644
--- a/src/contacts-app.vala
+++ b/src/contacts-app.vala
@@ -23,7 +23,6 @@ public class Contacts.App : Gtk.Application {
private Settings settings;
- /* moving creation to Window */
public Store contacts_store;
private Window window;
@@ -80,7 +79,7 @@ public class Contacts.App : Gtk.Application {
(dialog.get_content_area () as Box).add (explanation_label);
(dialog.get_content_area () as Box).set_spacing (12);
- var acc = new AccountsList ();
+ var acc = new AccountsList (this.contacts_store);
acc.update_contents (true);
ulong active_button_once = 0;
@@ -247,7 +246,7 @@ public class Contacts.App : Gtk.Application {
if (!ensure_eds_accounts (true))
quit ();
- contacts_store = new Store ();
+ this.contacts_store = new Store ();
base.startup ();
var css_provider = load_css ("style.css");
@@ -260,7 +259,7 @@ public class Contacts.App : Gtk.Application {
public override void activate () {
/* window creation code */
if (window == null) {
- if (!contacts_store.is_prepared) {
+ if (!this.contacts_store.is_prepared) {
if (!is_prepare_scheluded) {
schedule_window_creation ();
return;
@@ -272,7 +271,7 @@ public class Contacts.App : Gtk.Application {
window.show ();
}
- if (contacts_store.is_quiescent) {
+ if (this.contacts_store.is_quiescent) {
debug ("callign set_list_pane cause store is already quiescent");
window.set_list_pane ();
} else if (!is_quiescent_scheduled) {
diff --git a/src/contacts-contact-pane.vala b/src/contacts-contact-pane.vala
index 11c2068..1820652 100644
--- a/src/contacts-contact-pane.vala
+++ b/src/contacts-contact-pane.vala
@@ -391,7 +391,6 @@ public class Contacts.ContactPane : Stack {
// Creates a new contact from the details in the ContactEditor
public async void create_contact () {
var details = new HashTable<string, Value?> (str_hash, str_equal);
- var contacts_store = App.app.contacts_store;
// Collect the details from the editor
if (editor.name_changed ())
@@ -411,13 +410,13 @@ public class Contacts.ContactPane : Stack {
return;
}
- if (contacts_store.aggregator.primary_store == null) {
+ if (this.store.aggregator.primary_store == null) {
show_message_dialog (_("No primary addressbook configured"));
return;
}
// Create the contact
- var primary_store = contacts_store.aggregator.primary_store;
+ var primary_store = this.store.aggregator.primary_store;
Persona? persona = null;
try {
persona = yield Contact.create_primary_persona_for_details (primary_store, details);
@@ -427,7 +426,7 @@ public class Contacts.ContactPane : Stack {
}
// Now show it to the user
- var contact = contacts_store.find_contact_with_persona (persona);
+ var contact = this.store.find_contact_with_persona (persona);
if (contact != null)
App.app.show_contact (contact);
else
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]