[gnome-contacts/wip/nielsdg/get-rid-of-signals: 8/8] Contact: get rid of the `changed` signal.



commit febc407d4e2f22a4bf274cf06cbc540e941785f8
Author: Niels De Graef <nielsdegraef gmail com>
Date:   Sat Nov 3 19:15:58 2018 +0100

    Contact: get rid of the `changed` signal.
    
    This allows us to get rid of a lot of unnecessary signals and scheduled
    handlers filling up the main loop for honestly no good reason.

 src/contacts-contact-list.vala  |  4 ++--
 src/contacts-contact-sheet.vala |  2 +-
 src/contacts-contact.vala       | 34 ++++++++--------------------------
 src/contacts-store.vala         |  2 +-
 4 files changed, 12 insertions(+), 30 deletions(-)
---
diff --git a/src/contacts-contact-list.vala b/src/contacts-contact-list.vala
index 2d39739..31b2603 100644
--- a/src/contacts-contact-list.vala
+++ b/src/contacts-contact-list.vala
@@ -37,7 +37,7 @@ public class Contacts.ContactList : ListBox {
 
     public ContactDataRow(Contact c) {
       this.contact = c;
-      this.contact.changed.connect (on_contact_changed);
+      this.contact.individual.notify.connect (on_contact_changed);
       this.contact.notify["hidden"].connect ((o, p) => changed());
 
       get_style_context (). add_class ("contact-data-row");
@@ -70,7 +70,7 @@ public class Contacts.ContactList : ListBox {
       this.show_all ();
     }
 
-    private void on_contact_changed () {
+    private void on_contact_changed (Object obj, ParamSpec pspec) {
       this.label.set_text (this.contact.individual.display_name);
       changed ();
     }
diff --git a/src/contacts-contact-sheet.vala b/src/contacts-contact-sheet.vala
index de15309..3ac3a79 100644
--- a/src/contacts-contact-sheet.vala
+++ b/src/contacts-contact-sheet.vala
@@ -30,7 +30,7 @@ public class Contacts.ContactSheet : ContactForm {
       this.contact = contact;
       this.store = store;
 
-      this.contact.changed.connect (update);
+      this.contact.individual.notify.connect (update);
       this.contact.individual.personas_changed.connect (update);
       this.store.quiescent.connect (update);
 
diff --git a/src/contacts-contact.vala b/src/contacts-contact.vala
index 2dcec0a..f0cc442 100644
--- a/src/contacts-contact.vala
+++ b/src/contacts-contact.vala
@@ -29,7 +29,6 @@ public class Contacts.Contact : GLib.Object  {
   public bool is_main;
 
   public Individual individual;
-  uint changed_id;
 
   public Persona? fake_persona = null;
 
@@ -46,8 +45,6 @@ public class Contacts.Contact : GLib.Object  {
     return false;
   }
 
-  public signal void changed ();
-
   /**
    * There are 2 reasons why we want to hide a contact in the UI:
    * 1. The contact is going to be deleted (but isn't yet, since we support undoing)
@@ -69,7 +66,7 @@ public class Contacts.Contact : GLib.Object  {
     this.store = store;
     this.individual = i;
     this.individual.set_data ("contact", this);
-    this.individual.notify.connect(notify_cb);
+    this.individual.notify.connect(on_individual_notify);
 
     this.ignored = is_ignorable ();
     this.is_main = calc_is_main ();
@@ -97,16 +94,15 @@ public class Contacts.Contact : GLib.Object  {
   }
 
   public void replace_individual (Individual new_individual) {
-    individual.notify.disconnect(notify_cb);
+    individual.notify.disconnect(on_individual_notify);
     individual = new_individual;
     individual.set_data ("contact", this);
-    individual.notify.connect(notify_cb);
-    queue_changed ();
+    individual.notify.connect(on_individual_notify);
+    update ();
   }
 
   public void remove () {
-    unqueue_changed ();
-    individual.notify.disconnect(notify_cb);
+    this.individual.notify.disconnect(on_individual_notify);
   }
 
   private bool is_ignorable () {
@@ -234,27 +230,13 @@ public class Contacts.Contact : GLib.Object  {
   }
 #endif
 
-  private bool changed_cb () {
-    this.changed_id = 0;
+  public bool update () {
     this.is_main = calc_is_main ();
-    changed ();
     return false;
   }
 
-  private void unqueue_changed () {
-    if (changed_id != 0) {
-      Source.remove (changed_id);
-      changed_id = 0;
-    }
-  }
-
-  public void queue_changed () {
-    if (this.changed_id == 0)
-      this.changed_id = Idle.add (changed_cb);
-  }
-
-  private void notify_cb (ParamSpec pspec) {
-    queue_changed ();
+  private void on_individual_notify (ParamSpec pspec) {
+    update ();
   }
 
   /* We claim something is "removable" if at least one persona is removable,
diff --git a/src/contacts-store.vala b/src/contacts-store.vala
index 961edac..96c9d04 100644
--- a/src/contacts-store.vala
+++ b/src/contacts-store.vala
@@ -47,7 +47,7 @@ public class Contacts.Store : GLib.Object {
 
   public void refresh () {
     foreach (var c in contacts)
-      c.queue_changed ();
+      c.update ();
   }
 
   private bool individual_can_replace_at_split (Individual new_individual) {


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