[gnome-contacts] Contact: make Store reference private.



commit 0e2f79aba5d800511f1b25559c60aa09ab3c07f9
Author: Niels De Graef <nielsdegraef gmail com>
Date:   Sat Mar 31 13:50:34 2018 +0200

    Contact: make Store reference private.
    
    This was used an easy way to get to the Store, rather than doing it
    properly using dependency injection. Even more, some closures
    somehow seemed to leak this reference.

 src/contacts-contact-editor.vala         | 12 +++++++-----
 src/contacts-contact-pane.vala           |  4 ++--
 src/contacts-contact-sheet.vala          | 22 +++++++++++++---------
 src/contacts-contact.vala                | 30 +++++++++++++-----------------
 src/contacts-linked-personas-dialog.vala |  4 ++--
 src/contacts-linking.vala                |  4 ++--
 6 files changed, 39 insertions(+), 37 deletions(-)
---
diff --git a/src/contacts-contact-editor.vala b/src/contacts-contact-editor.vala
index 3cde0c2..16c11da 100644
--- a/src/contacts-contact-editor.vala
+++ b/src/contacts-contact-editor.vala
@@ -70,6 +70,7 @@ public class Contacts.ContactEditor : Grid {
   };
 
   private Contact contact;
+  private Store store;
 
   [GtkChild]
   private Grid container_grid;
@@ -762,7 +763,9 @@ public class Contacts.ContactEditor : Grid {
     }
   }
 
-  public ContactEditor (SimpleActionGroup editor_actions) {
+  public ContactEditor (Store store, SimpleActionGroup editor_actions) {
+    this.store = store;
+
     this.container_grid.set_focus_vadjustment (this.main_sw.get_vadjustment ());
 
     this.main_sw.get_style_context ().add_class ("contacts-main-view");
@@ -915,11 +918,10 @@ public class Contacts.ContactEditor : Grid {
     Persona persona = null;
     if (contact != null) {
       if (p == null) {
-       persona = new FakePersona (contact);
-       writable_personas.set (persona.uid,
-                              new HashMap<string, Field?> ());
+        persona = new FakePersona (this.store, contact);
+        writable_personas[persona.uid] = new HashMap<string, Field?> ();
       } else {
-       persona = p;
+        persona = p;
       }
     }
 
diff --git a/src/contacts-contact-pane.vala b/src/contacts-contact-pane.vala
index d0fa95e..3f3cd2b 100644
--- a/src/contacts-contact-pane.vala
+++ b/src/contacts-contact-pane.vala
@@ -119,7 +119,7 @@ public class Contacts.ContactPane : Stack {
     this.edit_contact_actions.add_action_entries (action_entries, this);
 
     // Contact editor
-    this.editor = new ContactEditor (this.edit_contact_actions);
+    this.editor = new ContactEditor (this.store, this.edit_contact_actions);
     this.editor.linked_button.clicked.connect (linked_accounts);
     this.editor.remove_button.clicked.connect (delete_contact);
     this.contact_editor_page.add (this.editor);
@@ -179,7 +179,7 @@ public class Contacts.ContactPane : Stack {
   }
 
   private void linked_accounts () {
-    var dialog = new LinkedPersonasDialog (this.parent_window, contact);
+    var dialog = new LinkedPersonasDialog (this.parent_window, this.store, contact);
     if (dialog.run () == ResponseType.CLOSE && dialog.any_unlinked) {
       /* update edited contact if any_unlinked */
       set_edit_mode (false);
diff --git a/src/contacts-contact-sheet.vala b/src/contacts-contact-sheet.vala
index 3324e5b..b567fc2 100644
--- a/src/contacts-contact-sheet.vala
+++ b/src/contacts-contact-sheet.vala
@@ -29,14 +29,18 @@ public class Contacts.ContactSheet : Grid {
 
   private Contact? contact;
 
+  private Store store;
+
   [GtkChild]
   private Label name_label;
 
   public ContactSheet (Contact contact, Store store) {
       this.contact = contact;
+      this.store = store;
+
       this.contact.changed.connect (update);
       this.contact.individual.personas_changed.connect (update);
-      store.quiescent.connect (update);
+      this.store.quiescent.connect (update);
 
       update ();
   }
@@ -152,14 +156,14 @@ public class Contacts.ContactSheet : Grid {
        var phones = Contact.sort_fields<PhoneFieldDetails>(phone_details.phone_numbers);
        foreach (var phone in phones) {
 #if HAVE_TELEPATHY
-         if (this.contact.store != null && this.contact.store.caller_account != null) {
-           var button = add_row_with_button (ref i, TypeSet.phone.format_type (phone), phone.value);
-           button.clicked.connect (() => {
-            Utils.start_call (phone.value, this.contact.store.caller_account);
-             });
-         } else {
-           add_row_with_label (ref i, TypeSet.phone.format_type (phone), phone.value);
-         }
+          if (this.store.caller_account != null) {
+            var button = add_row_with_button (ref i, TypeSet.phone.format_type (phone), phone.value);
+            button.clicked.connect (() => {
+                Utils.start_call (phone.value, this.store.caller_account);
+              });
+          } else {
+            add_row_with_label (ref i, TypeSet.phone.format_type (phone), phone.value);
+          }
 #else
           add_row_with_label (ref i, TypeSet.phone.format_type (phone), phone.value);
 #endif
diff --git a/src/contacts-contact.vala b/src/contacts-contact.vala
index 6c52deb..22fd76d 100644
--- a/src/contacts-contact.vala
+++ b/src/contacts-contact.vala
@@ -25,7 +25,7 @@ public errordomain ContactError {
 }
 
 public class Contacts.Contact : GLib.Object  {
-  public weak Store store;
+  private weak Store store;
   public bool is_main;
 
   public Individual individual;
@@ -331,7 +331,7 @@ public class Contacts.Contact : GLib.Object  {
     var persona_set = new HashSet<Persona>();
     persona_set.add_all (individual.personas);
     if (persona_set.size == 1)
-      persona_set.add (new FakePersona (this));
+      persona_set.add (new FakePersona (this.store, this));
 
     yield store.aggregator.link_personas (persona_set);
 
@@ -379,14 +379,10 @@ public class Contacts.Contact : GLib.Object  {
   }
 
   public Persona? find_primary_persona () {
-    var primary_store = store.aggregator.primary_store;
-    if (primary_store == null)
-      return null;
-
-    foreach (var p in individual.personas) {
-      if (p.store == primary_store)
+    foreach (var p in individual.personas)
+      if (p.store.is_primary_store)
         return p;
-    }
+
     return null;
   }
 
@@ -559,7 +555,7 @@ public class Contacts.Contact : GLib.Object  {
     }
 
     if (!did_set) {
-      var fake = new FakePersona (contact);
+      var fake = new FakePersona (contact.store, contact);
       return yield fake.make_real_and_set (property_name, value);
     }
     return null;
@@ -712,7 +708,7 @@ public class Contacts.FakePersona : Persona {
   private bool now_real;
   private bool has_full_name;
 
-  public static FakePersona? maybe_create_for (Contact contact) {
+  public static FakePersona? maybe_create_for (Store store, Contact contact) {
     var primary_persona = contact.find_primary_persona ();
 
     if (primary_persona != null)
@@ -727,7 +723,7 @@ public class Contacts.FakePersona : Persona {
        return null;
     }
 
-    return new FakePersona (contact);
+    return new FakePersona (store, contact);
   }
 
   private const string[] _linkable_properties = {};
@@ -768,12 +764,12 @@ public class Contacts.FakePersona : Persona {
     }
   }
 
-  public FakePersona (Contact contact) {
+  public FakePersona (Store? store, Contact contact) {
     Object (display_id: "display_id",
-           uid: "uid-fake-persona",
-           iid: "iid",
-           store: contact.store.aggregator.primary_store ?? FakePersonaStore.the_store(),
-           is_user: false);
+            uid: "uid-fake-persona",
+            iid: "iid",
+            store: store.aggregator.primary_store ?? FakePersonaStore.the_store(),
+            is_user: false);
     this.contact = contact;
     this.contact.fake_persona = this;
   }
diff --git a/src/contacts-linked-personas-dialog.vala b/src/contacts-linked-personas-dialog.vala
index b210bb9..be3e0e1 100644
--- a/src/contacts-linked-personas-dialog.vala
+++ b/src/contacts-linked-personas-dialog.vala
@@ -29,7 +29,7 @@ public class Contacts.LinkedPersonasDialog : Dialog {
 
   public bool any_unlinked = false;
 
-  public LinkedPersonasDialog (Window main_win, Contact contact) {
+  public LinkedPersonasDialog (Window main_win, Store store, Contact contact) {
     Object (
       use_header_bar: 1,
       transient_for: main_win,
@@ -79,7 +79,7 @@ public class Contacts.LinkedPersonasDialog : Dialog {
 
       /* signal */
       button.clicked.connect (() => {
-          unlink_persona.begin (contact, p, (obj, result) => {
+          unlink_persona.begin (store, contact, p, (obj, result) => {
               unlink_persona.end (result);
 
               row_grid.destroy ();
diff --git a/src/contacts-linking.vala b/src/contacts-linking.vala
index 7fa6914..999d514 100644
--- a/src/contacts-linking.vala
+++ b/src/contacts-linking.vala
@@ -592,7 +592,7 @@ namespace Contacts {
     return operation;
   }
 
-  public async LinkOperation unlink_persona (Contact contact, Persona persona_to_unlink) {
+  public async LinkOperation unlink_persona (Store store, Contact contact, Persona persona_to_unlink) {
     var individual = contact.individual;
     var persona_to_unlink_removals = PersonaAttribute.create_set ();
     var other_personas_removals = PersonaAttribute.create_set ();
@@ -676,7 +676,7 @@ namespace Contacts {
     if (main_persona == null && other_personas.size > 1) {
       var details = new HashTable<string, Value?> (str_hash, str_equal);
       try {
-        main_persona = yield contact.store.aggregator.primary_store.add_persona_from_details (details);
+        main_persona = yield store.aggregator.primary_store.add_persona_from_details (details);
         yield (main_persona as NameDetails).change_full_name (contact.individual.display_name);
         operation.added_persona (main_persona);
       } catch (GLib.Error e) {


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