1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
3 * Copyright (C) 2007-2009 Collabora Ltd.
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 * Authors: Xavier Claessens <xclaesse@gmail.com>
28 #include <glib/gi18n-lib.h>
30 #ifdef HAVE_LIBCHAMPLAIN
31 #include <champlain/champlain.h>
32 #include <champlain-gtk/champlain-gtk.h>
35 #include <telepathy-glib/account.h>
36 #include <telepathy-glib/util.h>
37 #include <telepathy-glib/interfaces.h>
39 #include <libempathy/empathy-tp-contact-factory.h>
40 #include <libempathy/empathy-contact-manager.h>
41 #include <libempathy/empathy-contact-list.h>
42 #include <libempathy/empathy-location.h>
43 #include <libempathy/empathy-request-util.h>
44 #include <libempathy/empathy-time.h>
45 #include <libempathy/empathy-utils.h>
47 #include "empathy-contact-widget.h"
48 #include "empathy-account-chooser.h"
49 #include "empathy-avatar-chooser.h"
50 #include "empathy-avatar-image.h"
51 #include "empathy-groups-widget.h"
52 #include "empathy-ui-utils.h"
53 #include "empathy-string-parser.h"
55 #define DEBUG_FLAG EMPATHY_DEBUG_CONTACT
56 #include <libempathy/empathy-debug.h>
59 * SECTION:empathy-contact-widget
60 * @title:EmpathyContactWidget
61 * @short_description: A widget used to display and edit details about a contact
62 * @include: libempathy-empathy-contact-widget.h
64 * #EmpathyContactWidget is a widget which displays appropriate widgets
65 * with details about a contact, also allowing changing these details,
70 * EmpathyContactWidget:
71 * @parent: parent object
73 * Widget which displays appropriate widgets with details about a contact,
74 * also allowing changing these details, if desired.
77 /* Delay before updating the widget when the id entry changed (seconds) */
78 #define ID_CHANGED_TIMEOUT 1
80 #define DATA_FIELD "contact-info-field"
84 EmpathyContactManager *manager;
85 EmpathyContact *contact;
86 EmpathyContactWidgetFlags flags;
87 guint widget_id_timeout;
90 GtkWidget *vbox_contact_widget;
93 GtkWidget *hbox_contact;
94 GtkWidget *widget_avatar;
95 GtkWidget *widget_account;
96 GtkWidget *image_account;
97 GtkWidget *label_account;
99 GtkWidget *widget_alias;
100 GtkWidget *label_alias;
101 GtkWidget *hbox_presence;
102 GtkWidget *image_state;
103 GtkWidget *label_status;
104 GtkWidget *table_contact;
105 GtkWidget *vbox_avatar;
106 GtkWidget *favourite_checkbox;
109 GtkWidget *vbox_location;
110 GtkWidget *subvbox_location;
111 GtkWidget *table_location;
112 GtkWidget *label_location;
113 #ifdef HAVE_LIBCHAMPLAIN
114 GtkWidget *viewport_map;
115 GtkWidget *map_view_embed;
116 ChamplainView *map_view;
120 GtkWidget *groups_widget;
123 GtkWidget *vbox_details;
124 GtkWidget *table_details;
125 GtkWidget *hbox_details_requested;
126 GtkWidget *spinner_details;
127 GList *details_to_set;
128 GCancellable *details_cancellable;
129 gboolean details_changed;
132 GtkWidget *vbox_client;
133 GtkWidget *table_client;
134 GtkWidget *hbox_client_requested;
135 } EmpathyContactWidget;
139 EmpathyContactWidget *information;
142 GtkTreeIter found_iter;
154 field_value_is_empty (TpContactInfoField *field)
158 if (field->field_value == NULL)
161 /* Field is empty if all its values are empty */
162 for (i = 0; field->field_value[i] != NULL; i++)
164 if (!tp_str_empty (field->field_value[i]))
172 set_contact_info_cb (GObject *source,
173 GAsyncResult *result,
176 GError *error = NULL;
178 if (!tp_connection_set_contact_info_finish (TP_CONNECTION (source), result,
181 DEBUG ("SetContactInfo() failed: %s", error->message);
182 g_error_free (error);
186 DEBUG ("SetContactInfo() succeeded");
190 contact_widget_save (EmpathyContactWidget *information)
192 TpConnection *connection;
195 connection = empathy_contact_get_connection (information->contact);
197 /* Remove empty fields */
198 for (l = information->details_to_set; l != NULL; l = next)
200 TpContactInfoField *field = l->data;
203 if (field_value_is_empty (field))
205 DEBUG ("Drop empty field: %s", field->field_name);
206 tp_contact_info_field_free (field);
207 information->details_to_set =
208 g_list_delete_link (information->details_to_set, l);
212 if (information->details_to_set != NULL)
214 if (information->details_changed)
216 tp_connection_set_contact_info_async (connection,
217 information->details_to_set, set_contact_info_cb, NULL);
220 tp_contact_info_list_free (information->details_to_set);
221 information->details_to_set = NULL;
226 contact_widget_details_setup (EmpathyContactWidget *information)
228 gtk_widget_hide (information->vbox_details);
230 information->spinner_details = gtk_spinner_new ();
231 gtk_box_pack_end (GTK_BOX (information->hbox_details_requested),
232 information->spinner_details, TRUE, TRUE, 0);
233 gtk_widget_show (information->spinner_details);
237 contact_widget_details_changed_cb (GtkEntry *entry,
238 EmpathyContactWidget *self)
240 const gchar *strv[] = { NULL, NULL };
241 TpContactInfoField *field;
243 self->details_changed = TRUE;
245 field = g_object_get_data ((GObject *) entry, DATA_FIELD);
246 g_assert (field != NULL);
248 strv[0] = gtk_entry_get_text (entry);
250 if (field->field_value != NULL)
251 g_strfreev (field->field_value);
252 field->field_value = g_strdupv ((GStrv) strv);
256 contact_widget_bday_changed_cb (GtkCalendar *calendar,
257 EmpathyContactWidget *self)
259 guint year, month, day;
262 const gchar *strv[] = { NULL, NULL };
263 TpContactInfoField *field;
265 self->details_changed = TRUE;
267 field = g_object_get_data ((GObject *) calendar, DATA_FIELD);
268 g_assert (field != NULL);
270 gtk_calendar_get_date (calendar, &year, &month, &day);
271 date = g_date_new_dmy (day, month+1, year);
273 gtk_calendar_clear_marks (calendar);
274 gtk_calendar_mark_day (calendar, g_date_get_day (date));
276 g_date_strftime (tmp, sizeof (tmp), EMPATHY_DATE_FORMAT_DISPLAY_SHORT, date);
278 if (field->field_value != NULL)
279 g_strfreev (field->field_value);
280 field->field_value = g_strdupv ((GStrv) strv);
285 static void contact_widget_details_notify_cb (EmpathyContactWidget *information);
287 typedef gchar * (* FieldFormatFunc) (GStrv);
291 const gchar *field_name;
293 FieldFormatFunc format;
297 linkify_first_value (GStrv values)
299 return empathy_add_link_markup (values[0]);
303 format_idle_time (GStrv values)
305 const gchar *value = values[0];
306 int duration = strtol (value, NULL, 10);
311 return empathy_duration_to_string (duration);
315 format_server (GStrv values)
317 g_assert (values[0] != NULL);
319 if (values[1] == NULL)
320 return g_markup_escape_text (values[0], -1);
322 return g_markup_printf_escaped ("%s (%s)", values[0], values[1]);
326 presence_hack (GStrv values)
328 if (tp_str_empty (values[0]))
331 return g_markup_escape_text (values[0], -1);
334 static InfoFieldData info_field_datas[] =
336 { "fn", N_("Full name:"), NULL },
337 { "tel", N_("Phone number:"), NULL },
338 { "email", N_("E-mail address:"), linkify_first_value },
339 { "url", N_("Website:"), linkify_first_value },
340 { "bday", N_("Birthday:"), NULL },
342 /* Note to translators: this is the caption for a string of the form "5
343 * minutes ago", and refers to the time since the contact last interacted
344 * with their IM client.
346 { "x-idle-time", N_("Last seen:"), format_idle_time },
347 { "x-irc-server", N_("Server:"), format_server },
348 { "x-host", N_("Connected from:"), format_server },
350 /* FIXME: once Idle implements SimplePresence using this information, we can
351 * and should bin this.
353 { "x-presence-status-message", N_("Away message:"), presence_hack },
358 static InfoFieldData *
359 find_info_field_data (const gchar *field_name)
363 for (i = 0; info_field_datas[i].field_name != NULL; i++)
365 if (!tp_strdiff (info_field_datas[i].field_name, field_name))
366 return info_field_datas + i;
372 contact_info_field_name_cmp (const gchar *name1,
377 if (!tp_strdiff (name1, name2))
380 /* We use the order of info_field_datas */
381 for (i = 0; info_field_datas[i].field_name != NULL; i++)
383 if (!tp_strdiff (info_field_datas[i].field_name, name1))
385 if (!tp_strdiff (info_field_datas[i].field_name, name2))
389 return g_strcmp0 (name1, name2);
393 contact_info_field_cmp (TpContactInfoField *field1,
394 TpContactInfoField *field2)
396 return contact_info_field_name_cmp (field1->field_name, field2->field_name);
400 field_name_in_field_list (GList *list,
405 for (l = list; l != NULL; l = g_list_next (l))
407 TpContactInfoField *field = l->data;
409 if (!tp_strdiff (field->field_name, name))
416 static TpContactInfoFieldSpec *
417 get_spec_from_list (GList *list,
422 for (l = list; l != NULL; l = g_list_next (l))
424 TpContactInfoFieldSpec *spec = l->data;
426 if (!tp_strdiff (spec->name, name))
434 contact_widget_details_update_edit (EmpathyContactWidget *information)
437 TpConnection *connection;
443 g_assert (information->details_to_set == NULL);
445 information->details_changed = FALSE;
447 contact = empathy_contact_get_tp_contact (information->contact);
448 connection = tp_contact_get_connection (contact);
450 info = tp_contact_get_contact_info (contact);
452 specs = tp_connection_get_contact_info_supported_fields (connection);
454 /* Look at the fields set in our vCard */
455 for (l = info; l != NULL; l = l->next)
457 TpContactInfoField *field = l->data;
459 /* make a copy for the details_to_set list */
460 field = tp_contact_info_field_copy (field);
461 DEBUG ("Field %s is in our vCard", field->field_name);
463 information->details_to_set = g_list_prepend (information->details_to_set,
467 /* Add fields which are supported but not in the vCard */
468 for (i = 0; info_field_datas[i].field_name != NULL; i++)
470 TpContactInfoFieldSpec *spec;
471 TpContactInfoField *field;
473 /* Check if the field was in the vCard */
474 if (field_name_in_field_list (information->details_to_set,
475 info_field_datas[i].field_name))
478 /* Check if the CM supports the field */
479 spec = get_spec_from_list (specs, info_field_datas[i].field_name);
483 /* add an empty field so user can set a value */
484 field = tp_contact_info_field_new (spec->name, spec->parameters, NULL);
486 information->details_to_set = g_list_prepend (information->details_to_set,
490 /* Add widgets for supported fields */
491 information->details_to_set = g_list_sort (information->details_to_set,
492 (GCompareFunc) contact_info_field_cmp);
494 for (l = information->details_to_set; l != NULL; l= g_list_next (l))
496 TpContactInfoField *field = l->data;
497 InfoFieldData *field_data;
499 TpContactInfoFieldSpec *spec;
501 field_data = find_info_field_data (field->field_name);
502 if (field_data == NULL)
504 /* Empathy doesn't display this field so we can't change it.
505 * But we put it in the details_to_set list so it won't be erased
506 * when calling SetContactInfo (bgo #630427) */
507 DEBUG ("Unhandled ContactInfo field spec: %s", field->field_name);
511 spec = get_spec_from_list (specs, field->field_name);
512 /* We shouldn't have added the field to details_to_set if it's not
513 * supported by the CM */
514 g_assert (spec != NULL);
516 if (spec->flags & TP_CONTACT_INFO_FIELD_FLAG_OVERWRITTEN_BY_NICKNAME)
518 DEBUG ("Ignoring field '%s' due it to having the "
519 "Overwritten_By_Nickname flag", field->field_name);
524 w = gtk_label_new (_(field_data->title));
525 gtk_table_attach (GTK_TABLE (information->table_details),
526 w, 0, 1, n_rows, n_rows + 1, GTK_FILL, 0, 0, 0);
527 gtk_misc_set_alignment (GTK_MISC (w), 0, 0.5);
531 if (!tp_strdiff (field->field_name, "bday"))
533 w = gtk_calendar_new ();
534 if (field->field_value[0])
538 g_date_set_parse (&date, field->field_value[0]);
539 if (g_date_valid (&date))
541 gtk_calendar_select_day (GTK_CALENDAR (w),
542 g_date_get_day (&date));
543 gtk_calendar_select_month (GTK_CALENDAR (w),
544 g_date_get_month (&date) - 1, g_date_get_year (&date));
545 gtk_calendar_mark_day (GTK_CALENDAR (w),
546 g_date_get_day (&date));
549 gtk_table_attach_defaults (GTK_TABLE (information->table_details),
550 w, 1, 2, n_rows, n_rows + 1);
553 g_object_set_data ((GObject *) w, DATA_FIELD, field);
555 g_signal_connect (w, "day-selected",
556 G_CALLBACK (contact_widget_bday_changed_cb), information);
557 g_signal_connect (w, "month-changed",
558 G_CALLBACK (contact_widget_bday_changed_cb), information);
562 w = gtk_entry_new ();
563 gtk_entry_set_text (GTK_ENTRY (w),
564 field->field_value[0] ? field->field_value[0] : "");
565 gtk_table_attach_defaults (GTK_TABLE (information->table_details),
566 w, 1, 2, n_rows, n_rows + 1);
569 g_object_set_data ((GObject *) w, DATA_FIELD, field);
571 g_signal_connect (w, "changed",
572 G_CALLBACK (contact_widget_details_changed_cb), information);
585 channel_name_activated_cb (
588 EmpathyContactWidget *information)
590 TpAccount *account = empathy_contact_get_account (information->contact);
592 empathy_join_muc (account, uri, empathy_get_current_action_time ());
598 EmpathyContactWidget *information,
603 GString *label_markup = g_string_new ("");
606 w = gtk_label_new (_("Channels:"));
607 gtk_table_attach (GTK_TABLE (information->table_details),
608 w, 0, 1, row, row + 1, GTK_FILL, 0, 0, 0);
609 gtk_misc_set_alignment (GTK_MISC (w), 0, 0.5);
612 for (i = 0; i < channels->len; i++)
614 const gchar *channel_name = g_ptr_array_index (channels, i);
615 /* We abuse the URI of the link to hold the channel name. It seems to
616 * be okay to just use it essentially verbatim, rather than trying to
617 * ensure it's actually a valid URI. g_string_append_uri_escaped()
618 * escapes way more than we actually need to; so we're just using
619 * g_markup_escape_text directly.
621 gchar *escaped = g_markup_escape_text (channel_name, -1);
624 g_string_append (label_markup, ", ");
626 g_string_append_printf (label_markup, "<a href='%s'>%s</a>",
627 escaped, channel_name);
631 w = gtk_label_new (NULL);
632 gtk_label_set_markup (GTK_LABEL (w), label_markup->str);
633 gtk_label_set_line_wrap (GTK_LABEL (w), TRUE);
634 g_signal_connect (w, "activate-link",
635 (GCallback) channel_name_activated_cb, information);
636 gtk_table_attach_defaults (GTK_TABLE (information->table_details),
637 w, 1, 2, row, row + 1);
638 gtk_misc_set_alignment (GTK_MISC (w), 0, 0.5);
641 g_string_free (label_markup, TRUE);
645 contact_widget_details_update_show (EmpathyContactWidget *information)
650 GPtrArray *channels = g_ptr_array_new ();
652 contact = empathy_contact_get_tp_contact (information->contact);
653 info = tp_contact_get_contact_info (contact);
654 info = g_list_sort (info, (GCompareFunc) contact_info_field_cmp);
655 for (l = info; l != NULL; l = l->next)
657 TpContactInfoField *field = l->data;
658 InfoFieldData *field_data;
660 gchar *markup = NULL;
663 if (field->field_value == NULL || field->field_value[0] == NULL)
666 value = field->field_value[0];
668 if (!tp_strdiff (field->field_name, "x-irc-channel"))
670 g_ptr_array_add (channels, (gpointer) field->field_value[0]);
674 field_data = find_info_field_data (field->field_name);
675 if (field_data == NULL)
677 DEBUG ("Unhandled ContactInfo field: %s", field->field_name);
681 if (field_data->format != NULL)
683 markup = field_data->format (field->field_value);
687 DEBUG ("Invalid value for field '%s' (first element was '%s')",
688 field->field_name, field->field_value[0]);
694 w = gtk_label_new (_(field_data->title));
695 gtk_table_attach (GTK_TABLE (information->table_details),
696 w, 0, 1, n_rows, n_rows + 1, GTK_FILL, 0, 0, 0);
697 gtk_misc_set_alignment (GTK_MISC (w), 0, 0.5);
701 w = gtk_label_new (value);
704 gtk_label_set_markup (GTK_LABEL (w), markup);
708 if ((information->flags & EMPATHY_CONTACT_WIDGET_FOR_TOOLTIP) == 0)
709 gtk_label_set_selectable (GTK_LABEL (w), TRUE);
711 gtk_table_attach_defaults (GTK_TABLE (information->table_details),
712 w, 1, 2, n_rows, n_rows + 1);
713 gtk_misc_set_alignment (GTK_MISC (w), 0, 0.5);
720 if (channels->len > 0)
722 add_channel_list (information, channels, n_rows);
726 g_ptr_array_unref (channels);
731 contact_widget_details_notify_cb (EmpathyContactWidget *information)
735 gtk_container_foreach (GTK_CONTAINER (information->table_details),
736 (GtkCallback) gtk_widget_destroy, NULL);
738 if ((information->flags & EMPATHY_CONTACT_WIDGET_EDIT_DETAILS) != 0)
739 n_rows = contact_widget_details_update_edit (information);
741 n_rows = contact_widget_details_update_show (information);
745 gtk_widget_show (information->vbox_details);
746 gtk_widget_show (information->table_details);
750 gtk_widget_hide (information->vbox_details);
753 gtk_widget_hide (information->hbox_details_requested);
754 gtk_spinner_stop (GTK_SPINNER (information->spinner_details));
758 contact_widget_details_request_cb (GObject *object,
762 TpContact *contact = TP_CONTACT (object);
763 EmpathyContactWidget *information = user_data;
764 GError *error = NULL;
766 if (!tp_contact_request_contact_info_finish (contact, res, &error))
768 /* If the request got cancelled it could mean the contact widget is
769 * destroyed, so we should not dereference information */
770 if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
772 g_clear_error (&error);
776 gtk_widget_hide (information->vbox_details);
777 g_clear_error (&error);
781 contact_widget_details_notify_cb (information);
784 /* If we are going to edit ContactInfo, we don't want live updates */
785 if ((information->flags & EMPATHY_CONTACT_WIDGET_EDIT_DETAILS) == 0)
787 g_signal_connect_swapped (contact, "notify::contact-info",
788 G_CALLBACK (contact_widget_details_notify_cb), information);
791 tp_clear_object (&information->details_cancellable);
795 fetch_contact_information (EmpathyContactWidget *information,
796 TpConnection *connection)
799 TpContactInfoFlags flags;
801 if (!tp_proxy_has_interface_by_id (connection,
802 TP_IFACE_QUARK_CONNECTION_INTERFACE_CONTACT_INFO))
804 gtk_widget_hide (information->vbox_details);
808 /* If we want to edit info, but connection does not support that, stop */
809 flags = tp_connection_get_contact_info_flags (connection);
810 if ((flags & TP_CONTACT_INFO_FLAG_CAN_SET) == 0 &&
811 (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_DETAILS) != 0)
813 gtk_widget_hide (information->vbox_details);
817 /* Request the contact's info */
818 gtk_widget_show (information->vbox_details);
819 gtk_widget_show (information->hbox_details_requested);
820 gtk_widget_hide (information->table_details);
821 gtk_spinner_start (GTK_SPINNER (information->spinner_details));
823 contact = empathy_contact_get_tp_contact (information->contact);
824 g_assert (information->details_cancellable == NULL);
825 information->details_cancellable = g_cancellable_new ();
826 tp_contact_request_contact_info_async (contact,
827 information->details_cancellable, contact_widget_details_request_cb,
832 contact_widget_details_update (EmpathyContactWidget *information)
834 TpContact *tp_contact = NULL;
836 if ((information->flags & EMPATHY_CONTACT_WIDGET_SHOW_DETAILS) == 0 &&
837 (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_DETAILS) == 0)
840 gtk_widget_hide (information->vbox_details);
842 if (information->contact != NULL)
843 tp_contact = empathy_contact_get_tp_contact (information->contact);
845 if (tp_contact != NULL)
847 TpConnection *connection;
849 connection = tp_contact_get_connection (tp_contact);
851 fetch_contact_information (information, connection);
856 contact_widget_client_update (EmpathyContactWidget *information)
858 /* FIXME: Needs new telepathy spec */
862 contact_widget_client_setup (EmpathyContactWidget *information)
864 /* FIXME: Needs new telepathy spec */
865 gtk_widget_hide (information->vbox_client);
869 contact_widget_groups_update (EmpathyContactWidget *information)
871 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_GROUPS &&
872 information->contact != NULL)
874 FolksPersona *persona =
875 empathy_contact_get_persona (information->contact);
877 if (FOLKS_IS_GROUP_DETAILS (persona))
879 empathy_groups_widget_set_group_details (
880 EMPATHY_GROUPS_WIDGET (information->groups_widget),
881 FOLKS_GROUP_DETAILS (persona));
882 gtk_widget_show (information->groups_widget);
888 /* In case of failure */
889 gtk_widget_hide (information->groups_widget);
892 /* Converts the Location's GHashTable's key to a user readable string */
894 location_key_to_label (const gchar *key)
896 if (tp_strdiff (key, EMPATHY_LOCATION_COUNTRY_CODE) == FALSE)
897 return _("Country ISO Code:");
898 else if (tp_strdiff (key, EMPATHY_LOCATION_COUNTRY) == FALSE)
899 return _("Country:");
900 else if (tp_strdiff (key, EMPATHY_LOCATION_REGION) == FALSE)
902 else if (tp_strdiff (key, EMPATHY_LOCATION_LOCALITY) == FALSE)
904 else if (tp_strdiff (key, EMPATHY_LOCATION_AREA) == FALSE)
906 else if (tp_strdiff (key, EMPATHY_LOCATION_POSTAL_CODE) == FALSE)
907 return _("Postal Code:");
908 else if (tp_strdiff (key, EMPATHY_LOCATION_STREET) == FALSE)
910 else if (tp_strdiff (key, EMPATHY_LOCATION_BUILDING) == FALSE)
911 return _("Building:");
912 else if (tp_strdiff (key, EMPATHY_LOCATION_FLOOR) == FALSE)
914 else if (tp_strdiff (key, EMPATHY_LOCATION_ROOM) == FALSE)
916 else if (tp_strdiff (key, EMPATHY_LOCATION_TEXT) == FALSE)
918 else if (tp_strdiff (key, EMPATHY_LOCATION_DESCRIPTION) == FALSE)
919 return _("Description:");
920 else if (tp_strdiff (key, EMPATHY_LOCATION_URI) == FALSE)
922 else if (tp_strdiff (key, EMPATHY_LOCATION_ACCURACY_LEVEL) == FALSE)
923 return _("Accuracy Level:");
924 else if (tp_strdiff (key, EMPATHY_LOCATION_ERROR) == FALSE)
926 else if (tp_strdiff (key, EMPATHY_LOCATION_VERTICAL_ERROR_M) == FALSE)
927 return _("Vertical Error (meters):");
928 else if (tp_strdiff (key, EMPATHY_LOCATION_HORIZONTAL_ERROR_M) == FALSE)
929 return _("Horizontal Error (meters):");
930 else if (tp_strdiff (key, EMPATHY_LOCATION_SPEED) == FALSE)
932 else if (tp_strdiff (key, EMPATHY_LOCATION_BEARING) == FALSE)
933 return _("Bearing:");
934 else if (tp_strdiff (key, EMPATHY_LOCATION_CLIMB) == FALSE)
935 return _("Climb Speed:");
936 else if (tp_strdiff (key, EMPATHY_LOCATION_TIMESTAMP) == FALSE)
937 return _("Last Updated on:");
938 else if (tp_strdiff (key, EMPATHY_LOCATION_LON) == FALSE)
939 return _("Longitude:");
940 else if (tp_strdiff (key, EMPATHY_LOCATION_LAT) == FALSE)
941 return _("Latitude:");
942 else if (tp_strdiff (key, EMPATHY_LOCATION_ALT) == FALSE)
943 return _("Altitude:");
946 DEBUG ("Unexpected Location key: %s", key);
952 contact_widget_location_update (EmpathyContactWidget *information)
954 GHashTable *location;
956 #ifdef HAVE_LIBCHAMPLAIN
957 gdouble lat = 0.0, lon = 0.0;
958 gboolean has_position = TRUE;
962 static const gchar* ordered_geolocation_keys[] = {
963 EMPATHY_LOCATION_TEXT,
964 EMPATHY_LOCATION_URI,
965 EMPATHY_LOCATION_DESCRIPTION,
966 EMPATHY_LOCATION_BUILDING,
967 EMPATHY_LOCATION_FLOOR,
968 EMPATHY_LOCATION_ROOM,
969 EMPATHY_LOCATION_STREET,
970 EMPATHY_LOCATION_AREA,
971 EMPATHY_LOCATION_LOCALITY,
972 EMPATHY_LOCATION_REGION,
973 EMPATHY_LOCATION_COUNTRY,
978 gboolean display_map = FALSE;
980 if (!(information->flags & EMPATHY_CONTACT_WIDGET_SHOW_LOCATION))
982 gtk_widget_hide (information->vbox_location);
986 location = empathy_contact_get_location (information->contact);
987 if (location == NULL || g_hash_table_size (location) == 0)
989 gtk_widget_hide (information->vbox_location);
993 value = g_hash_table_lookup (location, EMPATHY_LOCATION_TIMESTAMP);
996 gchar *loc = g_strdup_printf ("<b>%s</b>", _("Location"));
997 gtk_label_set_markup (GTK_LABEL (information->label_location), loc);
1007 stamp = g_value_get_int64 (value);
1009 user_date = empathy_time_to_string_relative (stamp);
1011 tmp = g_strdup_printf ("<b>%s</b>", _("Location"));
1012 /* translators: format is "Location, $date" */
1013 text = g_strdup_printf (_("%s, %s"), tmp, user_date);
1015 gtk_label_set_markup (GTK_LABEL (information->label_location), text);
1021 /* Prepare the location information table */
1022 if (information->table_location != NULL)
1024 gtk_widget_destroy (information->table_location);
1027 information->table_location = gtk_table_new (1, 2, FALSE);
1028 gtk_box_pack_start (GTK_BOX (information->subvbox_location),
1029 information->table_location, FALSE, FALSE, 5);
1032 for (i = 0; (skey = ordered_geolocation_keys[i]); i++)
1034 const gchar* user_label;
1036 char *svalue = NULL;
1038 gvalue = g_hash_table_lookup (location, (gpointer) skey);
1042 user_label = location_key_to_label (skey);
1044 label = gtk_label_new (user_label);
1045 gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
1046 gtk_table_attach (GTK_TABLE (information->table_location),
1047 label, 0, 1, row, row + 1, GTK_FILL, GTK_FILL, 10, 0);
1048 gtk_widget_show (label);
1050 if (G_VALUE_TYPE (gvalue) == G_TYPE_DOUBLE)
1053 dvalue = g_value_get_double (gvalue);
1054 svalue = g_strdup_printf ("%f", dvalue);
1056 else if (G_VALUE_TYPE (gvalue) == G_TYPE_STRING)
1058 svalue = g_value_dup_string (gvalue);
1060 else if (G_VALUE_TYPE (gvalue) == G_TYPE_INT64)
1064 time_ = g_value_get_int64 (value);
1065 svalue = empathy_time_to_string_utc (time_, _("%B %e, %Y at %R UTC"));
1070 label = gtk_label_new (svalue);
1071 gtk_table_attach_defaults (GTK_TABLE (information->table_location),
1072 label, 1, 2, row, row + 1);
1073 gtk_misc_set_alignment (GTK_MISC (label), 0, 0);
1074 gtk_widget_show (label);
1076 if (!(information->flags & EMPATHY_CONTACT_WIDGET_FOR_TOOLTIP))
1077 gtk_label_set_selectable (GTK_LABEL (label), TRUE);
1084 #ifdef HAVE_LIBCHAMPLAIN
1086 !(information->flags & EMPATHY_CONTACT_WIDGET_FOR_TOOLTIP))
1088 /* Cannot be displayed in tooltips until Clutter-Gtk can deal with such
1096 /* We can display some fields */
1097 gtk_widget_show (information->table_location);
1099 else if (!display_map)
1101 /* Can't display either fields or map */
1102 gtk_widget_hide (information->vbox_location);
1106 #ifdef HAVE_LIBCHAMPLAIN
1109 ClutterActor *marker;
1110 ChamplainMarkerLayer *layer;
1112 information->map_view_embed = gtk_champlain_embed_new ();
1113 information->map_view = gtk_champlain_embed_get_view (
1114 GTK_CHAMPLAIN_EMBED (information->map_view_embed));
1116 gtk_container_add (GTK_CONTAINER (information->viewport_map),
1117 information->map_view_embed);
1118 g_object_set (G_OBJECT (information->map_view),
1119 "kinetic-mode", TRUE,
1123 layer = champlain_marker_layer_new ();
1124 champlain_view_add_layer (information->map_view, CHAMPLAIN_LAYER (layer));
1126 marker = champlain_label_new_with_text (
1127 empathy_contact_get_alias (information->contact), NULL, NULL, NULL);
1128 champlain_location_set_location (CHAMPLAIN_LOCATION (marker), lat, lon);
1129 champlain_marker_layer_add_marker (layer, CHAMPLAIN_MARKER (marker));
1131 champlain_view_center_on (information->map_view, lat, lon);
1132 gtk_widget_show_all (information->viewport_map);
1136 gtk_widget_show (information->vbox_location);
1140 save_avatar_menu_activate_cb (GtkWidget *widget,
1141 EmpathyContactWidget *information)
1144 EmpathyAvatar *avatar;
1145 gchar *ext = NULL, *filename;
1147 dialog = gtk_file_chooser_dialog_new (_("Save Avatar"),
1149 GTK_FILE_CHOOSER_ACTION_SAVE,
1150 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
1151 GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT,
1154 gtk_file_chooser_set_do_overwrite_confirmation (GTK_FILE_CHOOSER (dialog),
1157 /* look for the avatar extension */
1158 avatar = empathy_contact_get_avatar (information->contact);
1159 if (avatar->format != NULL)
1163 splitted = g_strsplit (avatar->format, "/", 2);
1164 if (splitted[0] != NULL && splitted[1] != NULL)
1165 ext = g_strdup (splitted[1]);
1167 g_strfreev (splitted);
1171 /* Avatar was loaded from the cache so was converted to PNG */
1172 ext = g_strdup ("png");
1179 id = tp_escape_as_identifier (empathy_contact_get_id (
1180 information->contact));
1182 filename = g_strdup_printf ("%s.%s", id, ext);
1183 gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (dialog), filename);
1190 if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT)
1192 GError *error = NULL;
1194 filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
1196 if (!empathy_avatar_save_to_file (avatar, filename, &error))
1199 GtkWidget *error_dialog;
1201 error_dialog = gtk_message_dialog_new (NULL, 0,
1202 GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE,
1203 _("Unable to save avatar"));
1205 gtk_message_dialog_format_secondary_text (
1206 GTK_MESSAGE_DIALOG (error_dialog), "%s", error->message);
1208 g_signal_connect (error_dialog, "response",
1209 G_CALLBACK (gtk_widget_destroy), NULL);
1211 gtk_window_present (GTK_WINDOW (error_dialog));
1213 g_clear_error (&error);
1219 gtk_widget_destroy (dialog);
1223 popup_avatar_menu (EmpathyContactWidget *information,
1225 GdkEventButton *event)
1227 GtkWidget *menu, *item;
1228 gint button, event_time;
1230 if (information->contact == NULL ||
1231 empathy_contact_get_avatar (information->contact) == NULL)
1234 menu = empathy_context_menu_new (parent);
1236 /* Add "Save as..." entry */
1237 item = gtk_image_menu_item_new_from_stock (GTK_STOCK_SAVE_AS, NULL);
1238 gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
1239 gtk_widget_show (item);
1241 g_signal_connect (item, "activate",
1242 G_CALLBACK (save_avatar_menu_activate_cb), information);
1246 button = event->button;
1247 event_time = event->time;
1252 event_time = gtk_get_current_event_time ();
1255 gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
1256 button, event_time);
1260 widget_avatar_popup_menu_cb (GtkWidget *widget,
1261 EmpathyContactWidget *information)
1263 popup_avatar_menu (information, widget, NULL);
1269 widget_avatar_button_press_event_cb (GtkWidget *widget,
1270 GdkEventButton *event,
1271 EmpathyContactWidget *information)
1273 /* Ignore double-clicks and triple-clicks */
1274 if (event->button == 3 && event->type == GDK_BUTTON_PRESS)
1276 popup_avatar_menu (information, widget, event);
1284 set_avatar_cb (GObject *source,
1288 GError *error = NULL;
1290 if (!tp_account_set_avatar_finish (TP_ACCOUNT (source), res, &error)) {
1291 DEBUG ("Failed to set Account.Avatar: %s", error->message);
1292 g_error_free (error);
1297 set_avatar_on_account (TpAccount *account,
1300 const gchar *mime_type)
1302 DEBUG ("%s Account.Avatar on %s", size > 0 ? "Set": "Clear",
1303 tp_proxy_get_object_path (account));
1305 tp_account_set_avatar_async (account, (const guchar *) data, size,
1306 mime_type, set_avatar_cb, NULL);
1310 contact_widget_avatar_changed_cb (EmpathyAvatarChooser *chooser,
1311 EmpathyContactWidget *information)
1315 const gchar *mime_type;
1318 empathy_avatar_chooser_get_image_data (
1319 EMPATHY_AVATAR_CHOOSER (information->widget_avatar),
1320 &data, &size, &mime_type);
1322 account = empathy_contact_get_account (information->contact);
1323 set_avatar_on_account (account, data, size, mime_type);
1327 set_nickname_cb (GObject *source,
1331 GError *error = NULL;
1333 if (!tp_account_set_nickname_finish (TP_ACCOUNT (source), res, &error))
1335 DEBUG ("Failed to set Account.Nickname: %s", error->message);
1336 g_error_free (error);
1340 /* Update all the contact info fields having the
1341 * Overwritten_By_Nickname flag to the new alias. This avoid accidentally
1342 * reseting the alias when calling SetContactInfo(). See bgo #644298 for
1345 update_nickname_in_contact_info (EmpathyContactWidget *self,
1346 TpConnection *connection,
1347 const gchar *nickname)
1351 specs = tp_connection_get_contact_info_supported_fields (connection);
1353 for (l = self->details_to_set; l != NULL; l= g_list_next (l))
1355 TpContactInfoField *field = l->data;
1356 TpContactInfoFieldSpec *spec;
1358 spec = get_spec_from_list (specs, field->field_name);
1359 /* We shouldn't have added the field to details_to_set if it's not
1360 * supported by the CM */
1361 g_assert (spec != NULL);
1363 if (spec->flags & TP_CONTACT_INFO_FIELD_FLAG_OVERWRITTEN_BY_NICKNAME)
1365 const gchar *strv[] = { nickname, NULL };
1367 DEBUG ("Updating field '%s' to '%s' as it has the "
1368 "Overwritten_By_Nickname flag and Account.Nickname has "
1369 "been updated", field->field_name, nickname);
1371 if (field->field_value != NULL)
1372 g_strfreev (field->field_value);
1373 field->field_value = g_strdupv ((GStrv) strv);
1377 g_list_free (specs);
1381 contact_widget_entry_alias_focus_event_cb (GtkEditable *editable,
1382 GdkEventFocus *event,
1383 EmpathyContactWidget *information)
1385 if (information->contact)
1389 alias = gtk_entry_get_text (GTK_ENTRY (editable));
1391 if (empathy_contact_is_user (information->contact))
1393 TpAccount * account;
1394 const gchar *current_nickname;
1396 account = empathy_contact_get_account (information->contact);
1397 current_nickname = tp_account_get_nickname (account);
1399 if (tp_strdiff (current_nickname, alias))
1401 DEBUG ("Set Account.Nickname to %s", alias);
1403 tp_account_set_nickname_async (account, alias, set_nickname_cb,
1406 update_nickname_in_contact_info (information,
1407 empathy_contact_get_connection (information->contact), alias);
1412 empathy_contact_set_alias (information->contact, alias);
1420 update_avatar_chooser_account_cb (EmpathyAccountChooser *account_chooser,
1421 EmpathyAvatarChooser *avatar_chooser)
1425 account = empathy_account_chooser_get_account (account_chooser);
1426 if (account == NULL)
1429 empathy_avatar_chooser_set_account (avatar_chooser, account);
1433 contact_widget_avatar_notify_cb (EmpathyContactWidget *information)
1435 EmpathyAvatar *avatar = NULL;
1437 if (information->contact)
1438 avatar = empathy_contact_get_avatar (information->contact);
1440 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_AVATAR)
1442 g_signal_handlers_block_by_func (information->widget_avatar,
1443 contact_widget_avatar_changed_cb,
1445 empathy_avatar_chooser_set (
1446 EMPATHY_AVATAR_CHOOSER (information->widget_avatar), avatar);
1447 g_signal_handlers_unblock_by_func (information->widget_avatar,
1448 contact_widget_avatar_changed_cb, information);
1451 empathy_avatar_image_set (
1452 EMPATHY_AVATAR_IMAGE (information->widget_avatar), avatar);
1456 contact_widget_name_notify_cb (EmpathyContactWidget *information)
1458 if (GTK_IS_ENTRY (information->widget_alias))
1459 gtk_entry_set_text (GTK_ENTRY (information->widget_alias),
1460 empathy_contact_get_alias (information->contact));
1462 gtk_label_set_label (GTK_LABEL (information->widget_alias),
1463 empathy_contact_get_alias (information->contact));
1467 contact_widget_presence_notify_cb (EmpathyContactWidget *information)
1469 const gchar *status;
1470 gchar *markup_text = NULL;
1472 status = empathy_contact_get_status (information->contact);
1474 markup_text = empathy_add_link_markup (status);
1475 gtk_label_set_markup (GTK_LABEL (information->label_status), markup_text);
1476 g_free (markup_text);
1478 gtk_image_set_from_icon_name (GTK_IMAGE (information->image_state),
1479 empathy_icon_name_for_contact (information->contact),
1480 GTK_ICON_SIZE_BUTTON);
1481 gtk_widget_show (information->image_state);
1485 contact_widget_favourites_changed_cb (EmpathyContactManager *manager,
1486 EmpathyContact *contact,
1487 gboolean is_favourite,
1488 EmpathyContactWidget *information)
1490 if (contact != information->contact)
1493 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (
1494 information->favourite_checkbox), is_favourite);
1498 contact_widget_remove_contact (EmpathyContactWidget *information)
1500 if (information->contact)
1502 TpContact *tp_contact;
1504 contact_widget_save (information);
1506 g_signal_handlers_disconnect_by_func (information->contact,
1507 contact_widget_name_notify_cb, information);
1508 g_signal_handlers_disconnect_by_func (information->contact,
1509 contact_widget_presence_notify_cb, information);
1510 g_signal_handlers_disconnect_by_func (information->contact,
1511 contact_widget_avatar_notify_cb, information);
1513 tp_contact = empathy_contact_get_tp_contact (information->contact);
1514 if (tp_contact != NULL)
1516 g_signal_handlers_disconnect_by_func (tp_contact,
1517 contact_widget_details_notify_cb, information);
1520 g_object_unref (information->contact);
1521 information->contact = NULL;
1524 if (information->details_cancellable != NULL)
1526 g_cancellable_cancel (information->details_cancellable);
1527 tp_clear_object (&information->details_cancellable);
1531 static void contact_widget_change_contact (EmpathyContactWidget *information);
1534 contact_widget_contact_update (EmpathyContactWidget *information)
1536 TpAccount *account = NULL;
1537 const gchar *id = NULL;
1539 /* Connect and get info from new contact */
1540 if (information->contact)
1542 g_signal_connect_swapped (information->contact, "notify::name",
1543 G_CALLBACK (contact_widget_name_notify_cb), information);
1544 g_signal_connect_swapped (information->contact, "notify::presence",
1545 G_CALLBACK (contact_widget_presence_notify_cb), information);
1546 g_signal_connect_swapped (information->contact,
1547 "notify::presence-message",
1548 G_CALLBACK (contact_widget_presence_notify_cb), information);
1549 g_signal_connect_swapped (information->contact, "notify::avatar",
1550 G_CALLBACK (contact_widget_avatar_notify_cb), information);
1552 account = empathy_contact_get_account (information->contact);
1553 id = empathy_contact_get_id (information->contact);
1556 /* Update account widget */
1557 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ACCOUNT)
1561 g_signal_handlers_block_by_func (information->widget_account,
1562 contact_widget_change_contact,
1564 empathy_account_chooser_set_account (
1565 EMPATHY_ACCOUNT_CHOOSER (information->widget_account), account);
1566 g_signal_handlers_unblock_by_func (information->widget_account,
1567 contact_widget_change_contact, information);
1576 name = tp_account_get_display_name (account);
1577 gtk_label_set_label (GTK_LABEL (information->label_account), name);
1579 name = tp_account_get_icon_name (account);
1580 gtk_image_set_from_icon_name (GTK_IMAGE (information->image_account),
1581 name, GTK_ICON_SIZE_MENU);
1585 /* Update id widget */
1586 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ID)
1587 gtk_entry_set_text (GTK_ENTRY (information->widget_id), id ? id : "");
1589 gtk_label_set_label (GTK_LABEL (information->widget_id), id ? id : "");
1591 /* Update other widgets */
1592 if (information->contact)
1594 contact_widget_name_notify_cb (information);
1595 contact_widget_presence_notify_cb (information);
1596 contact_widget_avatar_notify_cb (information);
1598 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_FAVOURITE)
1600 FolksPersona *persona = empathy_contact_get_persona (
1601 information->contact);
1603 if (persona != NULL && FOLKS_IS_FAVOURITE_DETAILS (persona))
1605 gboolean is_favourite = folks_favourite_details_get_is_favourite (
1606 FOLKS_FAVOURITE_DETAILS (persona));
1607 contact_widget_favourites_changed_cb (information->manager,
1608 information->contact, is_favourite, information);
1612 gtk_widget_show (information->label_alias);
1613 gtk_widget_show (information->widget_alias);
1614 gtk_widget_show (information->hbox_presence);
1615 gtk_widget_show (information->widget_avatar);
1619 gtk_widget_hide (information->label_alias);
1620 gtk_widget_hide (information->widget_alias);
1621 gtk_widget_hide (information->hbox_presence);
1622 gtk_widget_hide (information->widget_avatar);
1627 contact_widget_set_contact (EmpathyContactWidget *information,
1628 EmpathyContact *contact)
1630 if (contact == information->contact)
1633 contact_widget_remove_contact (information);
1635 information->contact = g_object_ref (contact);
1637 /* set the selected account to be the account this contact came from */
1638 if (contact && EMPATHY_IS_ACCOUNT_CHOOSER (information->widget_account)) {
1639 empathy_account_chooser_set_account (
1640 EMPATHY_ACCOUNT_CHOOSER (information->widget_account),
1641 empathy_contact_get_account (contact));
1644 /* Update information for widgets */
1645 contact_widget_contact_update (information);
1646 contact_widget_groups_update (information);
1647 contact_widget_details_update (information);
1648 contact_widget_client_update (information);
1649 contact_widget_location_update (information);
1653 contact_widget_got_contact_cb (TpConnection *connection,
1654 EmpathyContact *contact,
1655 const GError *error,
1657 GObject *weak_object)
1659 EmpathyContactWidget *information = user_data;
1663 DEBUG ("Error: %s", error->message);
1667 contact_widget_set_contact (information, contact);
1671 contact_widget_change_contact (EmpathyContactWidget *information)
1673 TpConnection *connection;
1675 connection = empathy_account_chooser_get_connection (
1676 EMPATHY_ACCOUNT_CHOOSER (information->widget_account));
1680 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ID)
1684 id = gtk_entry_get_text (GTK_ENTRY (information->widget_id));
1685 if (!EMP_STR_EMPTY (id))
1687 empathy_tp_contact_factory_get_from_id (connection, id,
1688 contact_widget_got_contact_cb, information, NULL,
1689 G_OBJECT (information->vbox_contact_widget));
1694 empathy_tp_contact_factory_get_from_handle (connection,
1695 tp_connection_get_self_handle (connection),
1696 contact_widget_got_contact_cb, information, NULL,
1697 G_OBJECT (information->vbox_contact_widget));
1702 contact_widget_id_activate_timeout (EmpathyContactWidget *self)
1704 contact_widget_change_contact (self);
1709 contact_widget_id_changed_cb (GtkEntry *entry,
1710 EmpathyContactWidget *self)
1712 if (self->widget_id_timeout != 0)
1714 g_source_remove (self->widget_id_timeout);
1717 self->widget_id_timeout =
1718 g_timeout_add_seconds (ID_CHANGED_TIMEOUT,
1719 (GSourceFunc) contact_widget_id_activate_timeout, self);
1723 contact_widget_id_focus_out_cb (GtkWidget *widget,
1724 GdkEventFocus *event,
1725 EmpathyContactWidget *information)
1727 contact_widget_change_contact (information);
1732 favourite_toggled_cb (GtkToggleButton *button,
1733 EmpathyContactWidget *information)
1735 FolksPersona *persona = empathy_contact_get_persona (information->contact);
1737 if (persona != NULL && FOLKS_IS_FAVOURITE_DETAILS (persona))
1739 gboolean active = gtk_toggle_button_get_active (button);
1740 folks_favourite_details_set_is_favourite (
1741 FOLKS_FAVOURITE_DETAILS (persona), active);
1746 contact_widget_contact_setup (EmpathyContactWidget *information)
1748 information->label_status = gtk_label_new ("");
1749 gtk_label_set_line_wrap_mode (GTK_LABEL (information->label_status),
1750 PANGO_WRAP_WORD_CHAR);
1751 gtk_label_set_line_wrap (GTK_LABEL (information->label_status),
1754 if (!(information->flags & EMPATHY_CONTACT_WIDGET_FOR_TOOLTIP))
1755 gtk_label_set_selectable (GTK_LABEL (information->label_status), TRUE);
1757 gtk_box_pack_start (GTK_BOX (information->hbox_presence),
1758 information->label_status, TRUE, TRUE, 0);
1759 gtk_widget_show (information->label_status);
1761 /* Setup account label/chooser */
1762 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ACCOUNT)
1764 information->widget_account = empathy_account_chooser_new ();
1766 g_signal_connect_swapped (information->widget_account, "changed",
1767 G_CALLBACK (contact_widget_change_contact),
1772 /* Pack the protocol icon with the account name in an hbox */
1773 information->widget_account = gtk_hbox_new (FALSE, 6);
1775 information->label_account = gtk_label_new (NULL);
1776 if (!(information->flags & EMPATHY_CONTACT_WIDGET_FOR_TOOLTIP)) {
1777 gtk_label_set_selectable (GTK_LABEL (information->label_account), TRUE);
1779 gtk_misc_set_alignment (GTK_MISC (information->label_account), 0, 0.5);
1780 gtk_widget_show (information->label_account);
1782 information->image_account = gtk_image_new ();
1783 gtk_widget_show (information->image_account);
1785 gtk_box_pack_start (GTK_BOX (information->widget_account),
1786 information->image_account, FALSE, FALSE, 0);
1787 gtk_box_pack_start (GTK_BOX (information->widget_account),
1788 information->label_account, FALSE, TRUE, 0);
1790 gtk_table_attach_defaults (GTK_TABLE (information->table_contact),
1791 information->widget_account,
1793 gtk_widget_show (information->widget_account);
1795 /* Set up avatar chooser/display */
1796 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_AVATAR)
1798 information->widget_avatar = empathy_avatar_chooser_new ();
1799 g_signal_connect (information->widget_avatar, "changed",
1800 G_CALLBACK (contact_widget_avatar_changed_cb),
1802 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ACCOUNT)
1804 g_signal_connect (information->widget_account, "changed",
1805 G_CALLBACK (update_avatar_chooser_account_cb),
1806 information->widget_avatar);
1807 update_avatar_chooser_account_cb (
1808 EMPATHY_ACCOUNT_CHOOSER (information->widget_account),
1809 EMPATHY_AVATAR_CHOOSER (information->widget_avatar));
1814 information->widget_avatar = empathy_avatar_image_new ();
1816 g_signal_connect (information->widget_avatar, "popup-menu",
1817 G_CALLBACK (widget_avatar_popup_menu_cb), information);
1818 g_signal_connect (information->widget_avatar, "button-press-event",
1819 G_CALLBACK (widget_avatar_button_press_event_cb), information);
1822 gtk_box_pack_start (GTK_BOX (information->vbox_avatar),
1823 information->widget_avatar,
1826 gtk_widget_show (information->widget_avatar);
1828 /* Setup id label/entry */
1829 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ID)
1831 information->widget_id = gtk_entry_new ();
1832 g_signal_connect (information->widget_id, "focus-out-event",
1833 G_CALLBACK (contact_widget_id_focus_out_cb),
1835 g_signal_connect (information->widget_id, "changed",
1836 G_CALLBACK (contact_widget_id_changed_cb),
1841 information->widget_id = gtk_label_new (NULL);
1842 if (!(information->flags & EMPATHY_CONTACT_WIDGET_FOR_TOOLTIP)) {
1843 gtk_label_set_selectable (GTK_LABEL (information->widget_id), TRUE);
1845 gtk_misc_set_alignment (GTK_MISC (information->widget_id), 0, 0.5);
1847 gtk_table_attach_defaults (GTK_TABLE (information->table_contact),
1848 information->widget_id,
1850 gtk_widget_show (information->widget_id);
1852 /* Setup alias label/entry */
1853 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ALIAS)
1855 information->widget_alias = gtk_entry_new ();
1857 if (!(information->flags & EMPATHY_CONTACT_WIDGET_NO_SET_ALIAS))
1858 g_signal_connect (information->widget_alias, "focus-out-event",
1859 G_CALLBACK (contact_widget_entry_alias_focus_event_cb),
1862 /* Make return activate the window default (the Close button) */
1863 gtk_entry_set_activates_default (GTK_ENTRY (information->widget_alias),
1868 information->widget_alias = gtk_label_new (NULL);
1869 if (!(information->flags & EMPATHY_CONTACT_WIDGET_FOR_TOOLTIP)) {
1870 gtk_label_set_selectable (GTK_LABEL (information->widget_alias), TRUE);
1872 gtk_misc_set_alignment (GTK_MISC (information->widget_alias), 0, 0.5);
1874 gtk_table_attach_defaults (GTK_TABLE (information->table_contact),
1875 information->widget_alias,
1877 if (information->flags & EMPATHY_CONTACT_WIDGET_FOR_TOOLTIP) {
1878 gtk_label_set_selectable (GTK_LABEL (information->label_status), FALSE);
1880 gtk_widget_show (information->widget_alias);
1883 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_FAVOURITE)
1885 information->favourite_checkbox = gtk_check_button_new_with_label (
1888 g_signal_connect (information->favourite_checkbox, "toggled",
1889 G_CALLBACK (favourite_toggled_cb), information);
1891 gtk_table_attach_defaults (GTK_TABLE (information->table_contact),
1892 information->favourite_checkbox, 0, 2, 3, 4);
1894 information->fav_sig_id = g_signal_connect (information->manager,
1895 "favourites-changed",
1896 G_CALLBACK (contact_widget_favourites_changed_cb), information);
1898 gtk_widget_show (information->favourite_checkbox);
1903 contact_widget_destroy_cb (GtkWidget *widget,
1904 EmpathyContactWidget *information)
1906 contact_widget_remove_contact (information);
1908 if (information->widget_id_timeout != 0)
1910 g_source_remove (information->widget_id_timeout);
1913 if (information->fav_sig_id != 0)
1914 g_signal_handler_disconnect (information->manager, information->fav_sig_id);
1916 g_object_unref (information->manager);
1918 g_slice_free (EmpathyContactWidget, information);
1922 * empathy_contact_widget_new:
1923 * @contact: an #EmpathyContact
1924 * @flags: #EmpathyContactWidgetFlags for the new contact widget
1926 * Creates a new #EmpathyContactWidget.
1928 * Return value: a new #EmpathyContactWidget
1931 empathy_contact_widget_new (EmpathyContact *contact,
1932 EmpathyContactWidgetFlags flags)
1934 EmpathyContactWidget *information;
1938 g_return_val_if_fail (contact == NULL || EMPATHY_IS_CONTACT (contact), NULL);
1940 information = g_slice_new0 (EmpathyContactWidget);
1941 information->flags = flags;
1943 filename = empathy_file_lookup ("empathy-contact-widget.ui",
1945 gui = empathy_builder_get_file (filename,
1946 "vbox_contact_widget", &information->vbox_contact_widget,
1947 "hbox_contact", &information->hbox_contact,
1948 "hbox_presence", &information->hbox_presence,
1949 "label_alias", &information->label_alias,
1950 "image_state", &information->image_state,
1951 "table_contact", &information->table_contact,
1952 "vbox_avatar", &information->vbox_avatar,
1953 "vbox_location", &information->vbox_location,
1954 "subvbox_location", &information->subvbox_location,
1955 "label_location", &information->label_location,
1956 #ifdef HAVE_LIBCHAMPLAIN
1957 "viewport_map", &information->viewport_map,
1959 "groups_widget", &information->groups_widget,
1960 "vbox_details", &information->vbox_details,
1961 "table_details", &information->table_details,
1962 "hbox_details_requested", &information->hbox_details_requested,
1963 "vbox_client", &information->vbox_client,
1964 "table_client", &information->table_client,
1965 "hbox_client_requested", &information->hbox_client_requested,
1969 empathy_builder_connect (gui, information,
1970 "vbox_contact_widget", "destroy", contact_widget_destroy_cb,
1972 information->table_location = NULL;
1974 g_object_set_data (G_OBJECT (information->vbox_contact_widget),
1975 "EmpathyContactWidget",
1978 information->manager = empathy_contact_manager_dup_singleton ();
1980 /* Create widgets */
1981 contact_widget_contact_setup (information);
1982 contact_widget_details_setup (information);
1983 contact_widget_client_setup (information);
1985 if (contact != NULL)
1986 contact_widget_set_contact (information, contact);
1987 else if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ACCOUNT ||
1988 information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ID)
1989 contact_widget_change_contact (information);
1991 return empathy_builder_unref_and_keep_widget (gui,
1992 information->vbox_contact_widget);
1996 * empathy_contact_widget_get_contact:
1997 * @widget: an #EmpathyContactWidget
1999 * Get the #EmpathyContact related with the #EmpathyContactWidget @widget.
2001 * Returns: the #EmpathyContact associated with @widget
2004 empathy_contact_widget_get_contact (GtkWidget *widget)
2006 EmpathyContactWidget *information;
2008 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
2010 information = g_object_get_data (G_OBJECT (widget), "EmpathyContactWidget");
2014 return information->contact;
2018 empathy_contact_widget_get_alias (GtkWidget *widget)
2020 EmpathyContactWidget *information;
2022 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
2024 information = g_object_get_data (G_OBJECT (widget), "EmpathyContactWidget");
2028 return gtk_entry_get_text (GTK_ENTRY (information->widget_alias));
2032 * empathy_contact_widget_set_contact:
2033 * @widget: an #EmpathyContactWidget
2034 * @contact: a different #EmpathyContact
2036 * Change the #EmpathyContact related with the #EmpathyContactWidget @widget.
2039 empathy_contact_widget_set_contact (GtkWidget *widget,
2040 EmpathyContact *contact)
2042 EmpathyContactWidget *information;
2044 g_return_if_fail (GTK_IS_WIDGET (widget));
2045 g_return_if_fail (EMPATHY_IS_CONTACT (contact));
2047 information = g_object_get_data (G_OBJECT (widget), "EmpathyContactWidget");
2051 contact_widget_set_contact (information, contact);
2055 * empathy_contact_widget_set_account_filter:
2056 * @widget: an #EmpathyContactWidget
2057 * @filter: a #EmpathyAccountChooserFilterFunc
2058 * @user_data: user data to pass to @filter, or %NULL
2060 * Set a filter on the #EmpathyAccountChooser included in the
2061 * #EmpathyContactWidget.
2064 empathy_contact_widget_set_account_filter (
2066 EmpathyAccountChooserFilterFunc filter,
2069 EmpathyContactWidget *information;
2070 EmpathyAccountChooser *chooser;
2072 g_return_if_fail (GTK_IS_WIDGET (widget));
2074 information = g_object_get_data (G_OBJECT (widget), "EmpathyContactWidget");
2078 chooser = EMPATHY_ACCOUNT_CHOOSER (information->widget_account);
2080 empathy_account_chooser_set_filter (chooser, filter, user_data);