[gnome-contacts] Prevent more uses of App singleton for its Store



commit 0f8647fba93135dfc6dbcd7a30c66ec71f4b44f1
Author: Niels De Graef <nielsdegraef gmail com>
Date:   Sun Aug 27 21:41:42 2017 +0200

    Prevent more uses of App singleton for its Store

 src/contacts-contact-pane.vala  |   39 +++++++++++++++++++++------------------
 src/contacts-contact-sheet.vala |   10 +++++++---
 2 files changed, 28 insertions(+), 21 deletions(-)
---
diff --git a/src/contacts-contact-pane.vala b/src/contacts-contact-pane.vala
index 2eb026c..eda3193 100644
--- a/src/contacts-contact-pane.vala
+++ b/src/contacts-contact-pane.vala
@@ -203,24 +203,7 @@ public class Contacts.ContactPane : Stack {
     this.edit_contact_actions = new SimpleActionGroup ();
     this.edit_contact_actions.add_action_entries (action_entries, this);
 
-    // contact editor page
-    sheet = new ContactSheet ();
-    sheet.hexpand = true;
-    sheet.vexpand = true;
-    sheet.margin = 36;
-    sheet.set_margin_bottom (24);
-
-    var hcenter = new Center ();
-    hcenter.max_width = 600;
-    hcenter.xalign = 0.0;
-    hcenter.show ();
-    hcenter.add (sheet);
-
-    this.contact_sheet_page.add (hcenter);
-    sheet.set_focus_vadjustment (this.contact_sheet_page.get_vadjustment ());
-
-    this.contact_sheet_page.get_child ().get_style_context ().add_class ("contacts-main-view");
-    this.contact_sheet_page.get_child ().get_style_context ().add_class ("view");
+    create_contact_sheet ();
 
     this.suggestion_grid = null;
 
@@ -253,6 +236,26 @@ public class Contacts.ContactPane : Stack {
                                BindingFlags.INVERT_BOOLEAN);
   }
 
+  private void create_contact_sheet () {
+    this.sheet = new ContactSheet (this.store);
+    this.sheet.hexpand = true;
+    this.sheet.vexpand = true;
+    this.sheet.margin = 36;
+    this.sheet.set_margin_bottom (24);
+
+    var hcenter = new Center ();
+    hcenter.max_width = 600;
+    hcenter.xalign = 0.0;
+    hcenter.show ();
+    hcenter.add (this.sheet);
+
+    this.contact_sheet_page.add (hcenter);
+    this.sheet.set_focus_vadjustment (this.contact_sheet_page.get_vadjustment ());
+
+    this.contact_sheet_page.get_child ().get_style_context ().add_class ("contacts-main-view");
+    this.contact_sheet_page.get_child ().get_style_context ().add_class ("view");
+  }
+
   void on_add_detail (GLib.SimpleAction action, GLib.Variant? parameter) {
     var tok = action.name.split (".");
 
diff --git a/src/contacts-contact-sheet.vala b/src/contacts-contact-sheet.vala
index bbeb9ba..113e294 100644
--- a/src/contacts-contact-sheet.vala
+++ b/src/contacts-contact-sheet.vala
@@ -22,6 +22,8 @@ using Gee;
 
 public class Contacts.ContactSheet : Grid {
 
+  private Store contacts_store;
+
   Button add_row_with_button (ref int row, string label_value, string value) {
     var type_label = new Label (label_value);
     type_label.xalign = 1.0f;
@@ -88,7 +90,9 @@ public class Contacts.ContactSheet : Grid {
     row++;
   }
 
-  public ContactSheet () {
+  public ContactSheet (Store contacts_store) {
+    this.contacts_store = contacts_store;
+
     set_row_spacing (12);
     set_column_spacing (16);
     set_orientation (Orientation.VERTICAL);
@@ -152,10 +156,10 @@ public class Contacts.ContactSheet : Grid {
       if (phone_details != null) {
        var phones = Contact.sort_fields<PhoneFieldDetails>(phone_details.phone_numbers);
        foreach (var phone in phones) {
-         if (App.app.contacts_store.can_call) {
+         if (this.contacts_store.can_call) {
            var button = add_row_with_button (ref i, TypeSet.phone.format_type (phone), phone.value);
            button.clicked.connect (() => {
-               Utils.start_call (phone.value, App.app.contacts_store.calling_accounts);
+            Utils.start_call (phone.value, this.contacts_store.calling_accounts);
              });
          } else {
            add_row_with_label (ref i, TypeSet.phone.format_type (phone), phone.value);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]