[gnome-contacts] Only show non-primary contacts when searching
- From: Alexander Larsson <alexl src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-contacts] Only show non-primary contacts when searching
- Date: Mon, 16 Jan 2012 16:02:22 +0000 (UTC)
commit 2264be7b523ff75b31821f15a5f00d1636996efc
Author: Alexander Larsson <alexl redhat com>
Date: Mon Jan 16 15:04:25 2012 +0100
Only show non-primary contacts when searching
src/contacts-link-dialog.vala | 2 +-
src/contacts-list-pane.vala | 6 +++
src/contacts-view.vala | 85 ++++++++++++++++++++++++++++++++++-------
3 files changed, 78 insertions(+), 15 deletions(-)
---
diff --git a/src/contacts-link-dialog.vala b/src/contacts-link-dialog.vala
index aa74d25..03c8221 100644
--- a/src/contacts-link-dialog.vala
+++ b/src/contacts-link-dialog.vala
@@ -98,7 +98,7 @@ public class Contacts.LinkDialog : Dialog {
var c = Contact.from_individual (ind);
if (c != null) {
var result = matches.get (ind);
- view.add_custom_sort (c, (int) result);
+ view.set_custom_sort_prio (c, (int) result);
}
}
diff --git a/src/contacts-list-pane.vala b/src/contacts-list-pane.vala
index bd920bf..fa06b41 100644
--- a/src/contacts-list-pane.vala
+++ b/src/contacts-list-pane.vala
@@ -44,6 +44,10 @@ public class Contacts.ListPane : Frame {
}
contacts_view.set_filter_values (values);
+ if (values == null)
+ contacts_view.set_show_subset (View.Subset.PRIMARY);
+ else
+ contacts_view.set_show_subset (View.Subset.ALL_SEPARATED);
}
private bool filter_entry_changed_timeout () {
@@ -77,6 +81,8 @@ public class Contacts.ListPane : Frame {
toolbar.set_vexpand (false);
toolbar.set_hexpand (true);
+ contacts_view.set_show_subset (View.Subset.PRIMARY);
+
filter_entry = new Entry ();
filter_entry.set_icon_from_icon_name (EntryIconPosition.SECONDARY, "edit-find-symbolic");
filter_entry.changed.connect (filter_entry_changed);
diff --git a/src/contacts-view.vala b/src/contacts-view.vala
index 2ca440f..7daf5a5 100644
--- a/src/contacts-view.vala
+++ b/src/contacts-view.vala
@@ -29,32 +29,48 @@ public class Contacts.View : GLib.Object {
public int sort_prio;
}
+ public enum Subset {
+ PRIMARY,
+ NON_PRIMARY,
+ ALL_SEPARATED,
+ ALL
+ }
+
Store contacts_store;
+ Subset show_subset;
ListStore list_store;
HashSet<Contact> hidden_contacts;
string []? filter_values;
int custom_visible_count;
- ContactData header_data;
+ ContactData suggestions_header_data;
ContactData padding_data;
+ ContactData other_header_data;
public View (Store store) {
contacts_store = store;
hidden_contacts = new HashSet<Contact>();
+ show_subset = Subset.ALL;
list_store = new ListStore (2, typeof (Contact), typeof (ContactData *));
- header_data = new ContactData ();
- header_data.sort_prio = int.MAX;
+ suggestions_header_data = new ContactData ();
+ suggestions_header_data.sort_prio = int.MAX;
padding_data = new ContactData ();
padding_data.sort_prio = 1;
+ other_header_data = new ContactData ();
+ other_header_data.sort_prio = -1;
+
list_store.set_sort_func (0, (model, iter_a, iter_b) => {
ContactData *aa, bb;
model.get (iter_a, 1, out aa);
model.get (iter_b, 1, out bb);
- if (aa->sort_prio > bb->sort_prio)
+ int a_prio = get_sort_prio (aa);
+ int b_prio = get_sort_prio (bb);
+
+ if (a_prio > b_prio)
return -1;
- if (aa->sort_prio < bb->sort_prio)
+ if (a_prio < b_prio)
return 1;
var a = aa->contact;
@@ -80,18 +96,53 @@ public class Contacts.View : GLib.Object {
contact_added_cb (store, c);
}
+ private int get_sort_prio (ContactData *data) {
+ if (data->sort_prio != 0)
+ return data->sort_prio;
+
+ if (show_subset == Subset.ALL_SEPARATED &&
+ !data->contact.is_primary)
+ return -2;
+ return 0;
+ }
+
public string get_header_text (TreeIter iter) {
ContactData *data;
model.get (iter, 1, out data);
- if (data == header_data) {
+ if (data == suggestions_header_data) {
/* Translators: This is the header for the list of suggested contacts to
link to the current contact */
return ngettext ("Suggestion", "Suggestions", custom_visible_count);
}
+ if (data == other_header_data) {
+ /* Translators: This is the header for the list of suggested contacts to
+ link to the current contact */
+ return _("Other Contacts");
+ }
return "";
}
- public void add_custom_sort (Contact c, int prio) {
+ public void set_show_subset (Subset subset) {
+ show_subset = subset;
+
+ bool new_visible = show_subset == Subset.ALL_SEPARATED;
+ if (new_visible && !other_header_data.visible) {
+ other_header_data.visible = true;
+ list_store.append (out other_header_data.iter);
+ list_store.set (other_header_data.iter, 1, other_header_data);
+ }
+ if (!new_visible && other_header_data.visible) {
+ other_header_data.visible = false;
+ list_store.remove (other_header_data.iter);
+ }
+
+ refilter ();
+ }
+
+ public void set_custom_sort_prio (Contact c, int prio) {
+ /* We use negative prios internally */
+ assert (prio >= 0);
+
var data = lookup_data (c);
// We insert a priority between 0 and 1 for the padding
if (prio > 0)
@@ -119,6 +170,12 @@ public class Contacts.View : GLib.Object {
if (contact in hidden_contacts)
return false;
+ if ((show_subset == Subset.PRIMARY &&
+ !contact.is_primary) ||
+ (show_subset == Subset.NON_PRIMARY &&
+ contact.is_primary))
+ return false;
+
if (filter_values == null || filter_values.length == 0)
return true;
@@ -161,8 +218,8 @@ public class Contacts.View : GLib.Object {
private bool update_is_first (ContactData data, ContactData? previous) {
bool old_is_first = data.is_first;
- bool is_custom = data.sort_prio > 0;
- bool previous_is_custom = previous != null && previous.sort_prio > 0;
+ bool is_custom = data.sort_prio != 0;
+ bool previous_is_custom = previous != null && (previous.sort_prio != 0) ;
if (is_custom) {
data.is_first = false;
@@ -183,17 +240,17 @@ public class Contacts.View : GLib.Object {
}
private void add_custom_headers () {
- header_data.visible = true;
- list_store.append (out header_data.iter);
- list_store.set (header_data.iter, 1, header_data);
+ suggestions_header_data.visible = true;
+ list_store.append (out suggestions_header_data.iter);
+ list_store.set (suggestions_header_data.iter, 1, suggestions_header_data);
padding_data.visible = true;
list_store.append (out padding_data.iter);
list_store.set (padding_data.iter, 1, padding_data);
}
private void remove_custom_headers () {
- header_data.visible = false;
- list_store.remove (header_data.iter);
+ suggestions_header_data.visible = false;
+ list_store.remove (suggestions_header_data.iter);
padding_data.visible = false;
list_store.remove (padding_data.iter);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]