summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNiels De Graef <nielsdegraef@gmail.com>2018-04-02 13:24:53 +0200
committerNiels De Graef <nielsdegraef@gmail.com>2018-04-02 15:07:56 +0200
commitd00865bc2c4ce4508fc3cdc0226be542b17f1788 (patch)
tree6f8e609beb08849019984b6ba6fdf1d0d42ea179
parentdb84afdd50bc8d45a0dcf7114881a9a23819445f (diff)
downloadgnome-contacts-d00865bc2c4ce4508fc3cdc0226be542b17f1788.tar.gz
Contact: make hidden a property & cleanup the code.
-rw-r--r--src/contacts-contact-list.vala3
-rw-r--r--src/contacts-contact-pane.vala3
-rw-r--r--src/contacts-contact.vala85
-rw-r--r--src/contacts-list-pane.vala2
-rw-r--r--src/contacts-window.vala2
5 files changed, 40 insertions, 55 deletions
diff --git a/src/contacts-contact-list.vala b/src/contacts-contact-list.vala
index 2696002..08fa8a3 100644
--- a/src/contacts-contact-list.vala
+++ b/src/contacts-contact-list.vala
@@ -38,6 +38,7 @@ public class Contacts.ContactList : ListBox {
public ContactDataRow(Contact c) {
this.contact = c;
this.contact.changed.connect (on_contact_changed);
+ this.contact.notify["hidden"].connect ((o, p) => changed());
get_style_context (). add_class ("contact-data-row");
@@ -240,7 +241,7 @@ public class Contacts.ContactList : ListBox {
private bool filter_row (ListBoxRow row) {
var contact = ((ContactDataRow) row).contact;
- return !contact.is_hidden && this.filter_query.is_match (contact.individual) > 0;
+ return !contact.hidden && this.filter_query.is_match (contact.individual) > 0;
}
public void select_contact (Contact? contact) {
diff --git a/src/contacts-contact-pane.vala b/src/contacts-contact-pane.vala
index 3f3cd2b..1ca6d15 100644
--- a/src/contacts-contact-pane.vala
+++ b/src/contacts-contact-pane.vala
@@ -190,8 +190,7 @@ public class Contacts.ContactPane : Stack {
void delete_contact () {
if (contact != null) {
- contact.hide ();
-
+ contact.hidden = true;
this.will_delete (contact);
}
}
diff --git a/src/contacts-contact.vala b/src/contacts-contact.vala
index 8ac9481..74bfe84 100644
--- a/src/contacts-contact.vala
+++ b/src/contacts-contact.vala
@@ -48,56 +48,22 @@ public class Contacts.Contact : GLib.Object {
public signal void changed ();
- private bool _is_hidden;
- private bool _is_hidden_uptodate;
- private bool _is_hidden_to_delete;
-
- private bool _get_is_hidden () {
- // Contact has been deleted (but this is not actually posted, for undo support)
- if (this._is_hidden_to_delete)
- return true;
-
- var i = this.individual.personas.iterator();
- // Look for single-persona individuals
- if (i.next() && !i.has_next ()) {
- var persona = i.get();
- var store = persona.store;
-
- // Filter out pure key-file persona individuals as these are
- // not very interesting
- if (store.type_id == "key-file")
- return true;
-
- // Filter out uncertain things like link-local xmpp
- if (store.type_id == "telepathy" &&
- store.trust_level == PersonaStoreTrust.NONE)
- return true;
- }
-
- return false;
- }
-
- public bool is_hidden {
- get {
- if (!_is_hidden_uptodate) {
- _is_hidden = _get_is_hidden ();
- _is_hidden_uptodate = true;
+ /**
+ * 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)
+ * 2. The contact comes from an uninteresting or untrusted source.
+ */
+ public bool hidden {
+ get { return this.ignored || this.to_be_deleted; }
+ set {
+ if (this.to_be_deleted != value) {
+ this.to_be_deleted = value;
+ notify_property("hidden");
}
- return _is_hidden;
}
}
-
- public void hide () {
- _is_hidden_to_delete = true;
-
- queue_changed ();
- }
-
- public void show () {
- _is_hidden_to_delete = false;
-
- queue_changed ();
- }
+ private bool to_be_deleted; // this.hidden, part 1
+ private bool ignored; // this.hidden, part 2
public static Contact from_individual (Individual i) {
return i.get_data ("contact");
@@ -125,7 +91,8 @@ public class Contacts.Contact : GLib.Object {
individual = i;
individual.set_data ("contact", this);
- is_main = calc_is_main ();
+ this.ignored = is_ignorable ();
+ this.is_main = calc_is_main ();
individual.notify.connect(notify_cb);
}
@@ -143,6 +110,26 @@ public class Contacts.Contact : GLib.Object {
individual.notify.disconnect(notify_cb);
}
+ private bool is_ignorable () {
+ var i = this.individual.personas.iterator();
+
+ // Look for single-persona individuals
+ if (i.next() && !i.has_next ()) {
+ var persona_store = i.get().store;
+
+ // Filter out pure key-file persona individuals as these are not very interesting
+ if (persona_store.type_id == "key-file")
+ return true;
+
+ // Filter out uncertain things like link-local xmpp
+ if (persona_store.type_id == "telepathy" &&
+ persona_store.trust_level == PersonaStoreTrust.NONE)
+ return true;
+ }
+
+ return false;
+ }
+
public bool has_email (string email_address) {
var addrs = individual.email_addresses;
foreach (var detail in addrs) {
@@ -263,8 +250,6 @@ public class Contacts.Contact : GLib.Object {
}
public void queue_changed () {
- this._is_hidden_uptodate = false;
-
if (this.changed_id == 0)
this.changed_id = Idle.add (changed_cb);
}
diff --git a/src/contacts-list-pane.vala b/src/contacts-list-pane.vala
index 9f4d3f1..3aaf3d6 100644
--- a/src/contacts-list-pane.vala
+++ b/src/contacts-list-pane.vala
@@ -102,7 +102,7 @@ public class Contacts.ListPane : Frame {
private void on_delete_button_clicked (Gtk.Button delete_button) {
var marked_contacts = this.contacts_list.get_marked_contacts ();
foreach (var c in marked_contacts)
- c.hide ();
+ c.hidden = true;
delete_contacts (marked_contacts);
}
diff --git a/src/contacts-window.vala b/src/contacts-window.vala
index a37023f..4e11ac4 100644
--- a/src/contacts-window.vala
+++ b/src/contacts-window.vala
@@ -412,7 +412,7 @@ public class Contacts.Window : Gtk.ApplicationWindow {
notification.dismiss ();
foreach (var c in contacts)
- c.show ();
+ c.hidden = false;
set_shown_contact (contacts[0]);
this.state = UiState.SHOWING;