[gnome-contacts] Nicer labels for phone and email
- From: Alexander Larsson <alexl src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-contacts] Nicer labels for phone and email
- Date: Mon, 13 Jun 2011 13:31:29 +0000 (UTC)
commit d0177b574f780c2e6ae72c99f5669a77a7b20bca
Author: Alexander Larsson <alexl redhat com>
Date: Mon Jun 13 15:25:39 2011 +0200
Nicer labels for phone and email
src/contacts-contact-pane.vala | 18 +----
src/contacts-contact.vala | 150 +++++++++++++++++++++++++++++++++++++++-
2 files changed, 151 insertions(+), 17 deletions(-)
---
diff --git a/src/contacts-contact-pane.vala b/src/contacts-contact-pane.vala
index ece3753..853f046 100644
--- a/src/contacts-contact-pane.vala
+++ b/src/contacts-contact-pane.vala
@@ -210,7 +210,7 @@ public class Contacts.ContactPane : EventBox {
text.set_vexpand (true);
scrolled.add_with_viewport (text);
fields_grid.attach (scrolled, 0, 1, 1, 1);
-
+
// This is kinda weird, but there might be multiple notes. We let
// you edit the first and just display the rest. This isn't quite
// right, we should really ensure its the editable/primary one first.
@@ -240,13 +240,7 @@ public class Contacts.ContactPane : EventBox {
var emails = contact.individual.email_addresses;
if (!emails.is_empty) {
foreach (var email in Contact.sort_fields (emails)) {
- var type = "";
- var types = email.parameters["type"];
- if (types != null) {
- var i = types.iterator();
- if (i.next())
- type = type + i.get();
- }
+ var type = contact.format_email_type (email);
layout.add_label_detail (type, email.value);
var button = layout.add_button ("mail-unread-symbolic");
var email_addr = email.value;
@@ -281,13 +275,7 @@ public class Contacts.ContactPane : EventBox {
var phone_numbers = contact.individual.phone_numbers;
if (!phone_numbers.is_empty) {
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 = type + i.get();
- }
+ var type = contact.format_phone_type (p);
layout.add_label_detail (type, p.value);
}
}
diff --git a/src/contacts-contact.vala b/src/contacts-contact.vala
index fa6d27c..acffd0f 100644
--- a/src/contacts-contact.vala
+++ b/src/contacts-contact.vala
@@ -157,6 +157,152 @@ public class Contacts.Contact : GLib.Object {
return int.parse (s);
}
+ private struct PhoneData {
+ unowned string display_name;
+ unowned string types[2];
+ }
+
+ private static HashTable<unowned string, GLib.List> phone_types_hash;
+ public static string format_phone_type (FieldDetails detail) {
+ // List most specific first, always in upper case
+ const PhoneData[] data = {
+ { N_("Assistant"), { "X-EVOLUTION-ASSISTANT" } },
+ { N_("Work"), { "WORK", "VOICE" } },
+ // { N_("Business Phone 2"), { "WORK", "VOICE"}, 1
+ { N_("Work Fax"), { "WORK", "FAX" } },
+ { N_("Callback"), { "X-EVOLUTION-CALLBACK" } },
+ { N_("Car"), { "CAR" } },
+ { N_("Company"), { "X-EVOLUTION-COMPANY" } },
+ { N_("Home"), { "HOME", "VOICE" } },
+ //{ N_("Home 2"), { "HOME", "VOICE" } }, 1),
+ { N_("Home Fax"), { "HOME", "FAX" } },
+ { N_("ISDN"), { "ISDN" } },
+ { N_("Mobile"), { "CELL" } },
+ { N_("Other"), { "VOICE" } },
+ { N_("Fax"), { "FAX" } },
+ { N_("Pager"), { "PAGER" } },
+ { N_("Radio"), { "X-EVOLUTION-RADIO" } },
+ { N_("Telex"), { "X-EVOLUTION-TELEX" } },
+ /* To translators: TTY is Teletypewriter */
+ { N_("TTY"), { "X-EVOLUTION-TTYTDD" } },
+ { N_("Home"), { "HOME" } },
+ { N_("Work"), { "WORK" } }
+ };
+ if (detail.parameters.contains ("x-google-label")) {
+ return get_first_string (detail.parameters.get ("x-google-label"));
+ }
+ if (phone_types_hash == null) {
+ phone_types_hash = new HashTable<unowned string, GLib.List<unowned PhoneData*> > (str_hash, str_equal);
+ for (int i = 0; i < data.length; i++) {
+ unowned PhoneData *d = &data[i];
+ unowned GLib.List<unowned PhoneData *> l = phone_types_hash.lookup (d.types[0]);
+ if (l != null) {
+ l.append (d);
+ } else {
+ GLib.List<unowned PhoneData *> l2 = null;
+ l2.append (d);
+ phone_types_hash.insert (d.types[0], (owned) l2);
+ }
+ }
+ }
+
+ var i = detail.get_parameter_values ("type");
+ if (i == null || i.is_empty)
+ return _("Other");
+
+ var list = new Gee.ArrayList<string> ();
+ foreach (var s in detail.get_parameter_values ("type")) {
+ if (s.ascii_casecmp ("OTHER") == 0 ||
+ s.ascii_casecmp ("PREF") == 0)
+ continue;
+ list.add (s.up ());
+ }
+
+ if (list.is_empty)
+ return _("Other");
+
+ list.sort ();
+
+ unowned GLib.List<unowned PhoneData *>? l = phone_types_hash.lookup (list[0]);
+ foreach (var d in l) {
+ bool all_found = true;
+ for (int j = 0; j < 2 && d.types[j] != null; j++) {
+ if (!list.contains (d.types[j])) {
+ all_found = false;
+ break;
+ }
+ }
+ if (all_found)
+ return dgettext (Config.GETTEXT_PACKAGE, d.display_name);
+ }
+
+ return _("Other");
+ }
+
+ private struct EmailData {
+ unowned string display_name;
+ unowned string types[2];
+ }
+
+ private static HashTable<unowned string, GLib.List> email_types_hash;
+ public static string format_email_type (FieldDetails detail) {
+ // List most specific first, always in upper case
+ const EmailData[] data = {
+ { N_("Home"), { "HOME" } },
+ { N_("Work"), { "WORK" } }
+ };
+ if (detail.parameters.contains ("x-google-label")) {
+ return get_first_string (detail.parameters.get ("x-google-label"));
+ }
+ if (email_types_hash == null) {
+ email_types_hash = new HashTable<unowned string, GLib.List<unowned EmailData*> > (str_hash, str_equal);
+ for (int i = 0; i < data.length; i++) {
+ unowned EmailData *d = &data[i];
+ unowned GLib.List<unowned EmailData *> l = email_types_hash.lookup (d.types[0]);
+ if (l != null) {
+ l.append (d);
+ } else {
+ GLib.List<unowned EmailData *> l2 = null;
+ l2.append (d);
+ email_types_hash.insert (d.types[0], (owned) l2);
+ }
+ }
+ }
+
+ var i = detail.get_parameter_values ("type");
+ if (i == null || i.is_empty)
+ return _("Other");
+
+ var list = new Gee.ArrayList<string> ();
+ foreach (var s in detail.get_parameter_values ("type")) {
+ if (s.ascii_casecmp ("OTHER") == 0 ||
+ s.ascii_casecmp ("INTERNET") == 0 ||
+ s.ascii_casecmp ("PREF") == 0)
+ continue;
+ list.add (s.up ());
+ }
+
+ if (list.is_empty)
+ return _("Other");
+
+ list.sort ();
+
+ unowned GLib.List<unowned EmailData *>? l = email_types_hash.lookup (list[0]);
+ foreach (var d in l) {
+ bool all_found = true;
+ for (int j = 0; j < 2 && d.types[j] != null; j++) {
+ if (!list.contains (d.types[j])) {
+ all_found = false;
+ break;
+ }
+ }
+ if (all_found)
+ return dgettext (Config.GETTEXT_PACKAGE, d.display_name);
+ }
+
+ return _("Other");
+ }
+
public static GLib.List<FieldDetails> sort_fields (Set<FieldDetails> details) {
GLib.List<FieldDetails> sorted = null;
GLib.List<FieldDetails> pref = null;
@@ -245,7 +391,7 @@ public class Contacts.Contact : GLib.Object {
ALIAS_SERVICE /* $alias ($service) */
}
- private struct ImData {
+ private struct ImData {
unowned string service;
unowned string display_name;
ImDisplay display;
@@ -261,7 +407,7 @@ public class Contacts.Contact : GLib.Object {
if (service == null || service == "")
service = protocol;
- const ImData[] data = {
+ const ImData[] data = {
{ "google-talk", N_("Google Talk") },
{ "ovi-chat", N_("Ovi Chat") },
{ "facebook", N_("Facebook"), ImDisplay.ALIAS_SERVICE },
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]