[gnome-contacts] Sort persona tabs in a stable sort order
- From: Alexander Larsson <alexl src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-contacts] Sort persona tabs in a stable sort order
- Date: Wed, 24 Aug 2011 21:05:13 +0000 (UTC)
commit b61a4c446a373dce54f5dd0bd0da291ee9a35856
Author: Alexander Larsson <alexl redhat com>
Date: Wed Aug 24 22:19:56 2011 +0200
Sort persona tabs in a stable sort order
src/contacts-contact-pane.vala | 2 +-
src/contacts-contact.vala | 26 ++++++++++++++++++++++++++
2 files changed, 27 insertions(+), 1 deletions(-)
---
diff --git a/src/contacts-contact-pane.vala b/src/contacts-contact-pane.vala
index ed67b26..0e92eb0 100644
--- a/src/contacts-contact-pane.vala
+++ b/src/contacts-contact-pane.vala
@@ -888,7 +888,7 @@ public class Contacts.ContactPane : EventBox {
var fake_persona = FakePersona.maybe_create_for (contact);
if (fake_persona != null)
persona_list.add (fake_persona);
- // TODO Sort these personas in a stable way
+ persona_list.sort (Contact.compare_persona_by_store);
PersonaButton button = null;
foreach (var p in persona_list) {
diff --git a/src/contacts-contact.vala b/src/contacts-contact.vala
index 5b583cf..dc2bafc 100644
--- a/src/contacts-contact.vala
+++ b/src/contacts-contact.vala
@@ -445,6 +445,32 @@ public class Contacts.Contact : GLib.Object {
return 1;
}
+ public static int compare_persona_by_store (void *a, void *b) {
+ Persona persona_a = (Persona *)a;
+ Persona persona_b = (Persona *)b;
+ var store_a = persona_a.store;
+ var store_b = persona_b.store;
+
+ if (store_a == store_b)
+ return 0;
+
+ if (store_a.is_writeable && store_b.is_writeable)
+ return 0;
+ if (store_a.is_writeable)
+ return -1;
+ if (store_b.is_writeable)
+ return 1;
+
+ if (store_a.type_id == "eds" && store_b.type_id == "eds")
+ return strcmp (store_a.id, store_b.id);
+ if (store_a.type_id == "eds")
+ return -1;
+ if (store_b.type_id == "eds")
+ return 1;
+
+ return strcmp (store_a.id, store_b.id);
+ }
+
public static ArrayList<T> sort_fields<T> (Collection<T> fields) {
// TODO: This should take an extra delegate arg to compare by value for T
var res = new ArrayList<T>();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]