2 * Copyright (C) 2007-2011 Collabora Ltd.
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 * Authors: Xavier Claessens <xclaesse@gmail.com>
19 * Philip Withnall <philip.withnall@collabora.co.uk>
20 * Danielle Madeley <danielle.madeley@collabora.co.uk>
27 #include <glib/gi18n-lib.h>
29 #include <telepathy-glib/util.h>
31 #include "empathy-contactinfo-utils.h"
35 const gchar *field_name;
40 static InfoFieldData info_field_data[] =
42 { "fn", N_("Full name"), FALSE },
43 { "tel", N_("Phone number"), FALSE },
44 { "email", N_("E-mail address"), TRUE },
45 { "url", N_("Website"), TRUE },
46 { "bday", N_("Birthday"), FALSE },
56 static InfoParameterData info_parameter_data[] =
58 { "work", N_("work") },
59 { "home", N_("home") },
60 { "cell", N_("mobile") },
61 { "voice", N_("voice") },
62 { "pref", N_("preferred") },
63 { "postal", N_("postal") },
64 { "parcel", N_("parcel") },
69 empathy_contact_info_lookup_field (const gchar *field_name,
75 for (i = 0; info_field_data[i].field_name != NULL; i++)
77 if (tp_strdiff (info_field_data[i].field_name, field_name) == FALSE)
80 *title = gettext (info_field_data[i].title);
83 *linkify = info_field_data[i].linkify;
93 build_parameters_string (GStrv parameters)
95 GPtrArray *output = g_ptr_array_new ();
99 for (iter = parameters; iter != NULL && *iter != NULL; iter++)
101 static const char *prefix = "type=";
102 const char *param = *iter;
103 InfoParameterData *iter2;
105 if (!g_str_has_prefix (param, prefix))
108 param += strlen (prefix);
110 for (iter2 = info_parameter_data; iter2->type != NULL; iter2++)
112 if (!tp_strdiff (iter2->type, param))
114 g_ptr_array_add (output, gettext (iter2->title));
120 if (output->len == 0)
123 g_ptr_array_add (output, NULL); /* NULL-terminate */
125 join = g_strjoinv (", ", (char **) output->pdata);
126 g_ptr_array_free (output, TRUE);
132 empathy_contact_info_field_label (const char *field_name,
137 char *join = build_parameters_string (parameters);
139 if (!empathy_contact_info_lookup_field (field_name, &title, NULL))
143 ret = g_strdup_printf ("%s (%s):", title, join);
145 ret = g_strdup_printf ("%s:", title);
153 contact_info_field_name_cmp (const gchar *name1,
158 if (tp_strdiff (name1, name2) == FALSE)
161 /* We use the order of info_field_data */
162 for (i = 0; info_field_data[i].field_name != NULL; i++)
164 if (tp_strdiff (info_field_data[i].field_name, name1) == FALSE)
166 if (tp_strdiff (info_field_data[i].field_name, name2) == FALSE)
170 return g_strcmp0 (name1, name2);
174 empathy_contact_info_field_cmp (TpContactInfoField *field1,
175 TpContactInfoField *field2)
177 return contact_info_field_name_cmp (field1->field_name, field2->field_name);
181 empathy_contact_info_field_spec_cmp (TpContactInfoFieldSpec *spec1,
182 TpContactInfoFieldSpec *spec2)
184 return contact_info_field_name_cmp (spec1->name, spec2->name);