[gnome-contacts] Sort emails and phone nrs
- From: Alexander Larsson <alexl src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-contacts] Sort emails and phone nrs
- Date: Mon, 13 Jun 2011 13:31:24 +0000 (UTC)
commit acb6c7865ec8fe20583cf465d5dba8eda9bbf22c
Author: Alexander Larsson <alexl redhat com>
Date: Mon Jun 13 13:18:25 2011 +0200
Sort emails and phone nrs
src/contacts-contact-pane.vala | 17 +++++++------
src/contacts-contact.vala | 47 ++++++++++++++++++++++++++++++++++++++++
2 files changed, 56 insertions(+), 8 deletions(-)
---
diff --git a/src/contacts-contact-pane.vala b/src/contacts-contact-pane.vala
index d740976..ece3753 100644
--- a/src/contacts-contact-pane.vala
+++ b/src/contacts-contact-pane.vala
@@ -239,18 +239,19 @@ public class Contacts.ContactPane : EventBox {
var emails = contact.individual.email_addresses;
if (!emails.is_empty) {
- foreach (var p in emails) {
+ foreach (var email in Contact.sort_fields (emails)) {
var type = "";
- var types = p.parameters["type"];
+ var types = email.parameters["type"];
if (types != null) {
var i = types.iterator();
if (i.next())
- type = i.get();
+ type = type + i.get();
}
- layout.add_label_detail (type, p.value);
+ layout.add_label_detail (type, email.value);
var button = layout.add_button ("mail-unread-symbolic");
+ var email_addr = email.value;
button.clicked.connect ( () => {
- Utils.compose_mail (p.value);
+ Utils.compose_mail (email_addr);
});
}
}
@@ -279,13 +280,13 @@ public class Contacts.ContactPane : EventBox {
var phone_numbers = contact.individual.phone_numbers;
if (!phone_numbers.is_empty) {
- foreach (var p in phone_numbers) {
+ foreach (var p in Contact.sort_fields (phone_numbers)) {
var type = "";
var types = p.parameters["type"];
if (types != null) {
var i = types.iterator();
if (i.next())
- type = i.get();
+ type = type + i.get();
}
layout.add_label_detail (type, p.value);
}
@@ -299,7 +300,7 @@ public class Contacts.ContactPane : EventBox {
if (types != null) {
var i = types.iterator();
if (i.next())
- type = i.get();
+ type = type + i.get();
}
string[] strs = Contact.format_address (addr);
if (strs.length > 0) {
diff --git a/src/contacts-contact.vala b/src/contacts-contact.vala
index 691f566..fa6d27c 100644
--- a/src/contacts-contact.vala
+++ b/src/contacts-contact.vala
@@ -19,6 +19,7 @@
using Gtk;
using Folks;
+using Gee;
public class Contacts.Contact : GLib.Object {
static Gdk.Pixbuf fallback_avatar;
@@ -142,6 +143,52 @@ public class Contacts.Contact : GLib.Object {
return "user-offline-symbolic";
}
+ static string? get_first_string (Collection<string> collection) {
+ var i = collection.iterator();
+ if (i.next())
+ return i.get();
+ return null;
+ }
+
+ static int get_first_string_as_int (Collection<string> collection) {
+ var s = get_first_string (collection);
+ if (s == null)
+ return int.MAX;
+ return int.parse (s);
+ }
+
+ public static GLib.List<FieldDetails> sort_fields (Set<FieldDetails> details) {
+ GLib.List<FieldDetails> sorted = null;
+ GLib.List<FieldDetails> pref = null;
+ GLib.List<FieldDetails> rest = null;
+ foreach (var detail in details) {
+ if (detail.parameters.contains ("x-evolution-ui-slot")) {
+ sorted.prepend (detail);
+ } else {
+ bool found = false;
+ foreach (var param in detail.parameters.get ("type")) {
+ if (param.ascii_casecmp ("PREF") == 0) {
+ found = true;
+ break;
+ }
+ }
+ if (found)
+ pref.prepend (detail);
+ else
+ rest.prepend (detail);
+ }
+ }
+ pref.reverse();
+ rest.reverse();
+ sorted.sort ( (a, b) => {
+ var aa = get_first_string_as_int (a.parameters.get ("x-evolution-ui-slot"));
+ var bb = get_first_string_as_int (b.parameters.get ("x-evolution-ui-slot"));
+ return aa - bb;
+ });
+ sorted.concat ((owned)pref);
+ sorted.concat ((owned)rest);
+ return sorted;
+ }
public static string[] format_address (PostalAddress addr) {
string[] lines = {};
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]