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-contactinfo-utils.h"
49 #include "empathy-account-chooser.h"
50 #include "empathy-avatar-chooser.h"
51 #include "empathy-avatar-image.h"
52 #include "empathy-groups-widget.h"
53 #include "empathy-ui-utils.h"
54 #include "empathy-string-parser.h"
56 #define DEBUG_FLAG EMPATHY_DEBUG_CONTACT
57 #include <libempathy/empathy-debug.h>
60 * SECTION:empathy-contact-widget
61 * @title:EmpathyContactWidget
62 * @short_description: A widget used to display and edit details about a contact
63 * @include: libempathy-empathy-contact-widget.h
65 * #EmpathyContactWidget is a widget which displays appropriate widgets
66 * with details about a contact, also allowing changing these details,
71 * EmpathyContactWidget:
72 * @parent: parent object
74 * Widget which displays appropriate widgets with details about a contact,
75 * also allowing changing these details, if desired.
78 /* Delay before updating the widget when the id entry changed (seconds) */
79 #define ID_CHANGED_TIMEOUT 1
81 #define DATA_FIELD "contact-info-field"
85 EmpathyContactManager *manager;
86 EmpathyContact *contact;
87 EmpathyContactWidgetFlags flags;
88 guint widget_id_timeout;
91 GtkWidget *vbox_contact_widget;
94 GtkWidget *hbox_contact;
95 GtkWidget *widget_avatar;
96 GtkWidget *widget_account;
97 GtkWidget *image_account;
98 GtkWidget *label_account;
100 GtkWidget *widget_alias;
101 GtkWidget *label_alias;
102 GtkWidget *hbox_presence;
103 GtkWidget *image_state;
104 GtkWidget *label_status;
105 GtkWidget *table_contact;
106 GtkWidget *vbox_avatar;
107 GtkWidget *favourite_checkbox;
110 GtkWidget *vbox_location;
111 GtkWidget *subvbox_location;
112 GtkWidget *table_location;
113 GtkWidget *label_location;
114 #ifdef HAVE_LIBCHAMPLAIN
115 GtkWidget *viewport_map;
116 GtkWidget *map_view_embed;
117 ChamplainView *map_view;
121 GtkWidget *groups_widget;
124 GtkWidget *vbox_details;
125 GtkWidget *table_details;
126 GtkWidget *hbox_details_requested;
127 GtkWidget *spinner_details;
128 GList *details_to_set;
129 GCancellable *details_cancellable;
130 gboolean details_changed;
133 GtkWidget *vbox_client;
134 GtkWidget *table_client;
135 GtkWidget *hbox_client_requested;
136 } EmpathyContactWidget;
140 EmpathyContactWidget *information;
143 GtkTreeIter found_iter;
155 field_value_is_empty (TpContactInfoField *field)
159 if (field->field_value == NULL)
162 /* Field is empty if all its values are empty */
163 for (i = 0; field->field_value[i] != NULL; i++)
165 if (!tp_str_empty (field->field_value[i]))
173 set_contact_info_cb (GObject *source,
174 GAsyncResult *result,
177 GError *error = NULL;
179 if (!tp_connection_set_contact_info_finish (TP_CONNECTION (source), result,
182 DEBUG ("SetContactInfo() failed: %s", error->message);
183 g_error_free (error);
187 DEBUG ("SetContactInfo() succeeded");
191 contact_widget_save (EmpathyContactWidget *information)
193 TpConnection *connection;
196 connection = empathy_contact_get_connection (information->contact);
198 /* Remove empty fields */
199 for (l = information->details_to_set; l != NULL; l = next)
201 TpContactInfoField *field = l->data;
204 if (field_value_is_empty (field))
206 DEBUG ("Drop empty field: %s", field->field_name);
207 tp_contact_info_field_free (field);
208 information->details_to_set =
209 g_list_delete_link (information->details_to_set, l);
213 if (information->details_to_set != NULL)
215 if (information->details_changed)
217 tp_connection_set_contact_info_async (connection,
218 information->details_to_set, set_contact_info_cb, NULL);
221 tp_contact_info_list_free (information->details_to_set);
222 information->details_to_set = NULL;
227 contact_widget_details_setup (EmpathyContactWidget *information)
229 gtk_widget_hide (information->vbox_details);
231 information->spinner_details = gtk_spinner_new ();
232 gtk_box_pack_end (GTK_BOX (information->hbox_details_requested),
233 information->spinner_details, TRUE, TRUE, 0);
234 gtk_widget_show (information->spinner_details);
238 contact_widget_details_changed_cb (GtkEntry *entry,
239 EmpathyContactWidget *self)
241 const gchar *strv[] = { NULL, NULL };
242 TpContactInfoField *field;
244 self->details_changed = TRUE;
246 field = g_object_get_data ((GObject *) entry, DATA_FIELD);
247 g_assert (field != NULL);
249 strv[0] = gtk_entry_get_text (entry);
251 if (field->field_value != NULL)
252 g_strfreev (field->field_value);
253 field->field_value = g_strdupv ((GStrv) strv);
257 contact_widget_bday_changed_cb (GtkCalendar *calendar,
258 EmpathyContactWidget *self)
260 guint year, month, day;
263 const gchar *strv[] = { NULL, NULL };
264 TpContactInfoField *field;
266 self->details_changed = TRUE;
268 field = g_object_get_data ((GObject *) calendar, DATA_FIELD);
269 g_assert (field != NULL);
271 gtk_calendar_get_date (calendar, &year, &month, &day);
272 date = g_date_new_dmy (day, month+1, year);
274 gtk_calendar_clear_marks (calendar);
275 gtk_calendar_mark_day (calendar, g_date_get_day (date));
277 g_date_strftime (tmp, sizeof (tmp), EMPATHY_DATE_FORMAT_DISPLAY_SHORT, date);
279 if (field->field_value != NULL)
280 g_strfreev (field->field_value);
281 field->field_value = g_strdupv ((GStrv) strv);
286 static void contact_widget_details_notify_cb (EmpathyContactWidget *information);
289 field_name_in_field_list (GList *list,
294 for (l = list; l != NULL; l = g_list_next (l))
296 TpContactInfoField *field = l->data;
298 if (!tp_strdiff (field->field_name, name))
305 static TpContactInfoFieldSpec *
306 get_spec_from_list (GList *list,
311 for (l = list; l != NULL; l = g_list_next (l))
313 TpContactInfoFieldSpec *spec = l->data;
315 if (!tp_strdiff (spec->name, name))
323 contact_widget_details_update_edit (EmpathyContactWidget *information)
326 TpConnection *connection;
330 const char **field_names = empathy_contact_info_get_field_names (NULL);
333 g_assert (information->details_to_set == NULL);
335 information->details_changed = FALSE;
337 contact = empathy_contact_get_tp_contact (information->contact);
338 connection = tp_contact_get_connection (contact);
340 info = tp_contact_get_contact_info (contact);
342 specs = tp_connection_get_contact_info_supported_fields (connection);
344 /* Look at the fields set in our vCard */
345 for (l = info; l != NULL; l = l->next)
347 TpContactInfoField *field = l->data;
349 /* make a copy for the details_to_set list */
350 field = tp_contact_info_field_copy (field);
351 DEBUG ("Field %s is in our vCard", field->field_name);
353 information->details_to_set = g_list_prepend (information->details_to_set,
357 /* Add fields which are supported but not in the vCard */
358 for (i = 0; field_names[i] != NULL; i++)
360 TpContactInfoFieldSpec *spec;
361 TpContactInfoField *field;
363 /* Check if the field was in the vCard */
364 if (field_name_in_field_list (information->details_to_set,
368 /* Check if the CM supports the field */
369 spec = get_spec_from_list (specs, field_names[i]);
373 /* add an empty field so user can set a value */
374 field = tp_contact_info_field_new (spec->name, spec->parameters, NULL);
376 information->details_to_set = g_list_prepend (information->details_to_set,
380 /* Add widgets for supported fields */
381 information->details_to_set = g_list_sort (information->details_to_set,
382 (GCompareFunc) empathy_contact_info_field_spec_cmp);
384 for (l = information->details_to_set; l != NULL; l= g_list_next (l))
386 TpContactInfoField *field = l->data;
388 TpContactInfoFieldSpec *spec;
392 has_field = empathy_contact_info_lookup_field (field->field_name,
396 /* Empathy doesn't display this field so we can't change it.
397 * But we put it in the details_to_set list so it won't be erased
398 * when calling SetContactInfo (bgo #630427) */
399 DEBUG ("Unhandled ContactInfo field spec: %s", field->field_name);
403 spec = get_spec_from_list (specs, field->field_name);
404 /* We shouldn't have added the field to details_to_set if it's not
405 * supported by the CM */
406 g_assert (spec != NULL);
408 if (spec->flags & TP_CONTACT_INFO_FIELD_FLAG_OVERWRITTEN_BY_NICKNAME)
410 DEBUG ("Ignoring field '%s' due it to having the "
411 "Overwritten_By_Nickname flag", field->field_name);
416 title = empathy_contact_info_field_label (field->field_name,
418 w = gtk_label_new (title);
421 gtk_table_attach (GTK_TABLE (information->table_details),
422 w, 0, 1, n_rows, n_rows + 1, GTK_FILL, 0, 0, 0);
423 gtk_misc_set_alignment (GTK_MISC (w), 0, 0.5);
427 if (!tp_strdiff (field->field_name, "bday"))
429 w = gtk_calendar_new ();
430 if (field->field_value[0])
434 g_date_set_parse (&date, field->field_value[0]);
435 if (g_date_valid (&date))
437 gtk_calendar_select_day (GTK_CALENDAR (w),
438 g_date_get_day (&date));
439 gtk_calendar_select_month (GTK_CALENDAR (w),
440 g_date_get_month (&date) - 1, g_date_get_year (&date));
441 gtk_calendar_mark_day (GTK_CALENDAR (w),
442 g_date_get_day (&date));
445 gtk_table_attach_defaults (GTK_TABLE (information->table_details),
446 w, 1, 2, n_rows, n_rows + 1);
449 g_object_set_data ((GObject *) w, DATA_FIELD, field);
451 g_signal_connect (w, "day-selected",
452 G_CALLBACK (contact_widget_bday_changed_cb), information);
453 g_signal_connect (w, "month-changed",
454 G_CALLBACK (contact_widget_bday_changed_cb), information);
458 w = gtk_entry_new ();
459 gtk_entry_set_text (GTK_ENTRY (w),
460 field->field_value[0] ? field->field_value[0] : "");
461 gtk_table_attach_defaults (GTK_TABLE (information->table_details),
462 w, 1, 2, n_rows, n_rows + 1);
465 g_object_set_data ((GObject *) w, DATA_FIELD, field);
467 g_signal_connect (w, "changed",
468 G_CALLBACK (contact_widget_details_changed_cb), information);
481 channel_name_activated_cb (
484 EmpathyContactWidget *information)
486 TpAccount *account = empathy_contact_get_account (information->contact);
488 empathy_join_muc (account, uri, empathy_get_current_action_time ());
494 EmpathyContactWidget *information,
499 GString *label_markup = g_string_new ("");
502 w = gtk_label_new (_("Channels:"));
503 gtk_table_attach (GTK_TABLE (information->table_details),
504 w, 0, 1, row, row + 1, GTK_FILL, 0, 0, 0);
505 gtk_misc_set_alignment (GTK_MISC (w), 0, 0.5);
508 for (i = 0; i < channels->len; i++)
510 const gchar *channel_name = g_ptr_array_index (channels, i);
511 /* We abuse the URI of the link to hold the channel name. It seems to
512 * be okay to just use it essentially verbatim, rather than trying to
513 * ensure it's actually a valid URI. g_string_append_uri_escaped()
514 * escapes way more than we actually need to; so we're just using
515 * g_markup_escape_text directly.
517 gchar *escaped = g_markup_escape_text (channel_name, -1);
520 g_string_append (label_markup, ", ");
522 g_string_append_printf (label_markup, "<a href='%s'>%s</a>",
523 escaped, channel_name);
527 w = gtk_label_new (NULL);
528 gtk_label_set_markup (GTK_LABEL (w), label_markup->str);
529 gtk_label_set_line_wrap (GTK_LABEL (w), TRUE);
530 g_signal_connect (w, "activate-link",
531 (GCallback) channel_name_activated_cb, information);
532 gtk_table_attach_defaults (GTK_TABLE (information->table_details),
533 w, 1, 2, row, row + 1);
534 gtk_misc_set_alignment (GTK_MISC (w), 0, 0.5);
537 g_string_free (label_markup, TRUE);
541 contact_widget_details_update_show (EmpathyContactWidget *information)
546 GPtrArray *channels = g_ptr_array_new ();
548 contact = empathy_contact_get_tp_contact (information->contact);
549 info = tp_contact_get_contact_info (contact);
550 info = g_list_sort (info, (GCompareFunc) empathy_contact_info_field_cmp);
551 for (l = info; l != NULL; l = l->next)
553 TpContactInfoField *field = l->data;
555 gchar *markup = NULL, *title;
557 EmpathyContactInfoFormatFunc format;
559 if (field->field_value == NULL || field->field_value[0] == NULL)
562 value = field->field_value[0];
564 if (!tp_strdiff (field->field_name, "x-irc-channel"))
566 g_ptr_array_add (channels, (gpointer) field->field_value[0]);
570 if (!empathy_contact_info_lookup_field (field->field_name, NULL, &format))
572 DEBUG ("Unhandled ContactInfo field: %s", field->field_name);
578 markup = format (field->field_value);
582 DEBUG ("Invalid value for field '%s' (first element was '%s')",
583 field->field_name, field->field_value[0]);
589 title = empathy_contact_info_field_label (field->field_name,
591 w = gtk_label_new (title);
594 gtk_table_attach (GTK_TABLE (information->table_details),
595 w, 0, 1, n_rows, n_rows + 1, GTK_FILL, 0, 0, 0);
596 gtk_misc_set_alignment (GTK_MISC (w), 0, 0.5);
600 w = gtk_label_new (value);
603 gtk_label_set_markup (GTK_LABEL (w), markup);
607 if ((information->flags & EMPATHY_CONTACT_WIDGET_FOR_TOOLTIP) == 0)
608 gtk_label_set_selectable (GTK_LABEL (w), TRUE);
610 gtk_table_attach_defaults (GTK_TABLE (information->table_details),
611 w, 1, 2, n_rows, n_rows + 1);
612 gtk_misc_set_alignment (GTK_MISC (w), 0, 0.5);
620 if (channels->len > 0)
622 add_channel_list (information, channels, n_rows);
626 g_ptr_array_unref (channels);
631 contact_widget_details_notify_cb (EmpathyContactWidget *information)
635 gtk_container_foreach (GTK_CONTAINER (information->table_details),
636 (GtkCallback) gtk_widget_destroy, NULL);
638 if ((information->flags & EMPATHY_CONTACT_WIDGET_EDIT_DETAILS) != 0)
639 n_rows = contact_widget_details_update_edit (information);
641 n_rows = contact_widget_details_update_show (information);
645 gtk_widget_show (information->vbox_details);
646 gtk_widget_show (information->table_details);
650 gtk_widget_hide (information->vbox_details);
653 gtk_widget_hide (information->hbox_details_requested);
654 gtk_spinner_stop (GTK_SPINNER (information->spinner_details));
658 contact_widget_details_request_cb (GObject *object,
662 TpContact *contact = TP_CONTACT (object);
663 EmpathyContactWidget *information = user_data;
664 GError *error = NULL;
666 if (!tp_contact_request_contact_info_finish (contact, res, &error))
668 /* If the request got cancelled it could mean the contact widget is
669 * destroyed, so we should not dereference information */
670 if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
672 g_clear_error (&error);
676 gtk_widget_hide (information->vbox_details);
677 g_clear_error (&error);
681 contact_widget_details_notify_cb (information);
684 /* If we are going to edit ContactInfo, we don't want live updates */
685 if ((information->flags & EMPATHY_CONTACT_WIDGET_EDIT_DETAILS) == 0)
687 g_signal_connect_swapped (contact, "notify::contact-info",
688 G_CALLBACK (contact_widget_details_notify_cb), information);
691 tp_clear_object (&information->details_cancellable);
695 fetch_contact_information (EmpathyContactWidget *information,
696 TpConnection *connection)
699 TpContactInfoFlags flags;
701 if (!tp_proxy_has_interface_by_id (connection,
702 TP_IFACE_QUARK_CONNECTION_INTERFACE_CONTACT_INFO))
704 gtk_widget_hide (information->vbox_details);
708 /* If we want to edit info, but connection does not support that, stop */
709 flags = tp_connection_get_contact_info_flags (connection);
710 if ((flags & TP_CONTACT_INFO_FLAG_CAN_SET) == 0 &&
711 (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_DETAILS) != 0)
713 gtk_widget_hide (information->vbox_details);
717 /* Request the contact's info */
718 gtk_widget_show (information->vbox_details);
719 gtk_widget_show (information->hbox_details_requested);
720 gtk_widget_hide (information->table_details);
721 gtk_spinner_start (GTK_SPINNER (information->spinner_details));
723 contact = empathy_contact_get_tp_contact (information->contact);
724 g_assert (information->details_cancellable == NULL);
725 information->details_cancellable = g_cancellable_new ();
726 tp_contact_request_contact_info_async (contact,
727 information->details_cancellable, contact_widget_details_request_cb,
732 contact_widget_details_update (EmpathyContactWidget *information)
734 TpContact *tp_contact = NULL;
736 if ((information->flags & EMPATHY_CONTACT_WIDGET_SHOW_DETAILS) == 0 &&
737 (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_DETAILS) == 0)
740 gtk_widget_hide (information->vbox_details);
742 if (information->contact != NULL)
743 tp_contact = empathy_contact_get_tp_contact (information->contact);
745 if (tp_contact != NULL)
747 TpConnection *connection;
749 connection = tp_contact_get_connection (tp_contact);
751 fetch_contact_information (information, connection);
756 contact_widget_client_update (EmpathyContactWidget *information)
758 /* FIXME: Needs new telepathy spec */
762 contact_widget_client_setup (EmpathyContactWidget *information)
764 /* FIXME: Needs new telepathy spec */
765 gtk_widget_hide (information->vbox_client);
769 contact_widget_groups_update (EmpathyContactWidget *information)
771 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_GROUPS &&
772 information->contact != NULL)
774 FolksPersona *persona =
775 empathy_contact_get_persona (information->contact);
777 if (FOLKS_IS_GROUP_DETAILS (persona))
779 empathy_groups_widget_set_group_details (
780 EMPATHY_GROUPS_WIDGET (information->groups_widget),
781 FOLKS_GROUP_DETAILS (persona));
782 gtk_widget_show (information->groups_widget);
788 /* In case of failure */
789 gtk_widget_hide (information->groups_widget);
792 /* Converts the Location's GHashTable's key to a user readable string */
794 location_key_to_label (const gchar *key)
796 if (tp_strdiff (key, EMPATHY_LOCATION_COUNTRY_CODE) == FALSE)
797 return _("Country ISO Code:");
798 else if (tp_strdiff (key, EMPATHY_LOCATION_COUNTRY) == FALSE)
799 return _("Country:");
800 else if (tp_strdiff (key, EMPATHY_LOCATION_REGION) == FALSE)
802 else if (tp_strdiff (key, EMPATHY_LOCATION_LOCALITY) == FALSE)
804 else if (tp_strdiff (key, EMPATHY_LOCATION_AREA) == FALSE)
806 else if (tp_strdiff (key, EMPATHY_LOCATION_POSTAL_CODE) == FALSE)
807 return _("Postal Code:");
808 else if (tp_strdiff (key, EMPATHY_LOCATION_STREET) == FALSE)
810 else if (tp_strdiff (key, EMPATHY_LOCATION_BUILDING) == FALSE)
811 return _("Building:");
812 else if (tp_strdiff (key, EMPATHY_LOCATION_FLOOR) == FALSE)
814 else if (tp_strdiff (key, EMPATHY_LOCATION_ROOM) == FALSE)
816 else if (tp_strdiff (key, EMPATHY_LOCATION_TEXT) == FALSE)
818 else if (tp_strdiff (key, EMPATHY_LOCATION_DESCRIPTION) == FALSE)
819 return _("Description:");
820 else if (tp_strdiff (key, EMPATHY_LOCATION_URI) == FALSE)
822 else if (tp_strdiff (key, EMPATHY_LOCATION_ACCURACY_LEVEL) == FALSE)
823 return _("Accuracy Level:");
824 else if (tp_strdiff (key, EMPATHY_LOCATION_ERROR) == FALSE)
826 else if (tp_strdiff (key, EMPATHY_LOCATION_VERTICAL_ERROR_M) == FALSE)
827 return _("Vertical Error (meters):");
828 else if (tp_strdiff (key, EMPATHY_LOCATION_HORIZONTAL_ERROR_M) == FALSE)
829 return _("Horizontal Error (meters):");
830 else if (tp_strdiff (key, EMPATHY_LOCATION_SPEED) == FALSE)
832 else if (tp_strdiff (key, EMPATHY_LOCATION_BEARING) == FALSE)
833 return _("Bearing:");
834 else if (tp_strdiff (key, EMPATHY_LOCATION_CLIMB) == FALSE)
835 return _("Climb Speed:");
836 else if (tp_strdiff (key, EMPATHY_LOCATION_TIMESTAMP) == FALSE)
837 return _("Last Updated on:");
838 else if (tp_strdiff (key, EMPATHY_LOCATION_LON) == FALSE)
839 return _("Longitude:");
840 else if (tp_strdiff (key, EMPATHY_LOCATION_LAT) == FALSE)
841 return _("Latitude:");
842 else if (tp_strdiff (key, EMPATHY_LOCATION_ALT) == FALSE)
843 return _("Altitude:");
846 DEBUG ("Unexpected Location key: %s", key);
852 contact_widget_location_update (EmpathyContactWidget *information)
854 GHashTable *location;
856 #ifdef HAVE_LIBCHAMPLAIN
857 gdouble lat = 0.0, lon = 0.0;
858 gboolean has_position = TRUE;
862 static const gchar* ordered_geolocation_keys[] = {
863 EMPATHY_LOCATION_TEXT,
864 EMPATHY_LOCATION_URI,
865 EMPATHY_LOCATION_DESCRIPTION,
866 EMPATHY_LOCATION_BUILDING,
867 EMPATHY_LOCATION_FLOOR,
868 EMPATHY_LOCATION_ROOM,
869 EMPATHY_LOCATION_STREET,
870 EMPATHY_LOCATION_AREA,
871 EMPATHY_LOCATION_LOCALITY,
872 EMPATHY_LOCATION_REGION,
873 EMPATHY_LOCATION_COUNTRY,
878 gboolean display_map = FALSE;
880 if (!(information->flags & EMPATHY_CONTACT_WIDGET_SHOW_LOCATION))
882 gtk_widget_hide (information->vbox_location);
886 location = empathy_contact_get_location (information->contact);
887 if (location == NULL || g_hash_table_size (location) == 0)
889 gtk_widget_hide (information->vbox_location);
893 value = g_hash_table_lookup (location, EMPATHY_LOCATION_TIMESTAMP);
896 gchar *loc = g_strdup_printf ("<b>%s</b>", _("Location"));
897 gtk_label_set_markup (GTK_LABEL (information->label_location), loc);
907 stamp = g_value_get_int64 (value);
909 user_date = empathy_time_to_string_relative (stamp);
911 tmp = g_strdup_printf ("<b>%s</b>", _("Location"));
912 /* translators: format is "Location, $date" */
913 text = g_strdup_printf (_("%s, %s"), tmp, user_date);
915 gtk_label_set_markup (GTK_LABEL (information->label_location), text);
921 /* Prepare the location information table */
922 if (information->table_location != NULL)
924 gtk_widget_destroy (information->table_location);
927 information->table_location = gtk_table_new (1, 2, FALSE);
928 gtk_box_pack_start (GTK_BOX (information->subvbox_location),
929 information->table_location, FALSE, FALSE, 5);
932 for (i = 0; (skey = ordered_geolocation_keys[i]); i++)
934 const gchar* user_label;
938 gvalue = g_hash_table_lookup (location, (gpointer) skey);
942 user_label = location_key_to_label (skey);
944 label = gtk_label_new (user_label);
945 gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
946 gtk_table_attach (GTK_TABLE (information->table_location),
947 label, 0, 1, row, row + 1, GTK_FILL, GTK_FILL, 10, 0);
948 gtk_widget_show (label);
950 if (G_VALUE_TYPE (gvalue) == G_TYPE_DOUBLE)
953 dvalue = g_value_get_double (gvalue);
954 svalue = g_strdup_printf ("%f", dvalue);
956 else if (G_VALUE_TYPE (gvalue) == G_TYPE_STRING)
958 svalue = g_value_dup_string (gvalue);
960 else if (G_VALUE_TYPE (gvalue) == G_TYPE_INT64)
964 time_ = g_value_get_int64 (value);
965 svalue = empathy_time_to_string_utc (time_, _("%B %e, %Y at %R UTC"));
970 label = gtk_label_new (svalue);
971 gtk_table_attach_defaults (GTK_TABLE (information->table_location),
972 label, 1, 2, row, row + 1);
973 gtk_misc_set_alignment (GTK_MISC (label), 0, 0);
974 gtk_widget_show (label);
976 if (!(information->flags & EMPATHY_CONTACT_WIDGET_FOR_TOOLTIP))
977 gtk_label_set_selectable (GTK_LABEL (label), TRUE);
984 #ifdef HAVE_LIBCHAMPLAIN
986 !(information->flags & EMPATHY_CONTACT_WIDGET_FOR_TOOLTIP))
988 /* Cannot be displayed in tooltips until Clutter-Gtk can deal with such
996 /* We can display some fields */
997 gtk_widget_show (information->table_location);
999 else if (!display_map)
1001 /* Can't display either fields or map */
1002 gtk_widget_hide (information->vbox_location);
1006 #ifdef HAVE_LIBCHAMPLAIN
1009 ClutterActor *marker;
1010 ChamplainMarkerLayer *layer;
1012 information->map_view_embed = gtk_champlain_embed_new ();
1013 information->map_view = gtk_champlain_embed_get_view (
1014 GTK_CHAMPLAIN_EMBED (information->map_view_embed));
1016 gtk_container_add (GTK_CONTAINER (information->viewport_map),
1017 information->map_view_embed);
1018 g_object_set (G_OBJECT (information->map_view),
1019 "kinetic-mode", TRUE,
1023 layer = champlain_marker_layer_new ();
1024 champlain_view_add_layer (information->map_view, CHAMPLAIN_LAYER (layer));
1026 marker = champlain_label_new_with_text (
1027 empathy_contact_get_alias (information->contact), NULL, NULL, NULL);
1028 champlain_location_set_location (CHAMPLAIN_LOCATION (marker), lat, lon);
1029 champlain_marker_layer_add_marker (layer, CHAMPLAIN_MARKER (marker));
1031 champlain_view_center_on (information->map_view, lat, lon);
1032 gtk_widget_show_all (information->viewport_map);
1036 gtk_widget_show (information->vbox_location);
1040 save_avatar_menu_activate_cb (GtkWidget *widget,
1041 EmpathyContactWidget *information)
1044 EmpathyAvatar *avatar;
1045 gchar *ext = NULL, *filename;
1047 dialog = gtk_file_chooser_dialog_new (_("Save Avatar"),
1049 GTK_FILE_CHOOSER_ACTION_SAVE,
1050 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
1051 GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT,
1054 gtk_file_chooser_set_do_overwrite_confirmation (GTK_FILE_CHOOSER (dialog),
1057 /* look for the avatar extension */
1058 avatar = empathy_contact_get_avatar (information->contact);
1059 if (avatar->format != NULL)
1063 splitted = g_strsplit (avatar->format, "/", 2);
1064 if (splitted[0] != NULL && splitted[1] != NULL)
1065 ext = g_strdup (splitted[1]);
1067 g_strfreev (splitted);
1071 /* Avatar was loaded from the cache so was converted to PNG */
1072 ext = g_strdup ("png");
1079 id = tp_escape_as_identifier (empathy_contact_get_id (
1080 information->contact));
1082 filename = g_strdup_printf ("%s.%s", id, ext);
1083 gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (dialog), filename);
1090 if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT)
1092 GError *error = NULL;
1094 filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
1096 if (!empathy_avatar_save_to_file (avatar, filename, &error))
1099 GtkWidget *error_dialog;
1101 error_dialog = gtk_message_dialog_new (NULL, 0,
1102 GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE,
1103 _("Unable to save avatar"));
1105 gtk_message_dialog_format_secondary_text (
1106 GTK_MESSAGE_DIALOG (error_dialog), "%s", error->message);
1108 g_signal_connect (error_dialog, "response",
1109 G_CALLBACK (gtk_widget_destroy), NULL);
1111 gtk_window_present (GTK_WINDOW (error_dialog));
1113 g_clear_error (&error);
1119 gtk_widget_destroy (dialog);
1123 popup_avatar_menu (EmpathyContactWidget *information,
1125 GdkEventButton *event)
1127 GtkWidget *menu, *item;
1128 gint button, event_time;
1130 if (information->contact == NULL ||
1131 empathy_contact_get_avatar (information->contact) == NULL)
1134 menu = empathy_context_menu_new (parent);
1136 /* Add "Save as..." entry */
1137 item = gtk_image_menu_item_new_from_stock (GTK_STOCK_SAVE_AS, NULL);
1138 gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
1139 gtk_widget_show (item);
1141 g_signal_connect (item, "activate",
1142 G_CALLBACK (save_avatar_menu_activate_cb), information);
1146 button = event->button;
1147 event_time = event->time;
1152 event_time = gtk_get_current_event_time ();
1155 gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
1156 button, event_time);
1160 widget_avatar_popup_menu_cb (GtkWidget *widget,
1161 EmpathyContactWidget *information)
1163 popup_avatar_menu (information, widget, NULL);
1169 widget_avatar_button_press_event_cb (GtkWidget *widget,
1170 GdkEventButton *event,
1171 EmpathyContactWidget *information)
1173 /* Ignore double-clicks and triple-clicks */
1174 if (event->button == 3 && event->type == GDK_BUTTON_PRESS)
1176 popup_avatar_menu (information, widget, event);
1184 set_avatar_cb (GObject *source,
1188 GError *error = NULL;
1190 if (!tp_account_set_avatar_finish (TP_ACCOUNT (source), res, &error)) {
1191 DEBUG ("Failed to set Account.Avatar: %s", error->message);
1192 g_error_free (error);
1197 set_avatar_on_account (TpAccount *account,
1200 const gchar *mime_type)
1202 DEBUG ("%s Account.Avatar on %s", size > 0 ? "Set": "Clear",
1203 tp_proxy_get_object_path (account));
1205 tp_account_set_avatar_async (account, (const guchar *) data, size,
1206 mime_type, set_avatar_cb, NULL);
1210 contact_widget_avatar_changed_cb (EmpathyAvatarChooser *chooser,
1211 EmpathyContactWidget *information)
1215 const gchar *mime_type;
1218 empathy_avatar_chooser_get_image_data (
1219 EMPATHY_AVATAR_CHOOSER (information->widget_avatar),
1220 &data, &size, &mime_type);
1222 account = empathy_contact_get_account (information->contact);
1223 set_avatar_on_account (account, data, size, mime_type);
1227 set_nickname_cb (GObject *source,
1231 GError *error = NULL;
1233 if (!tp_account_set_nickname_finish (TP_ACCOUNT (source), res, &error))
1235 DEBUG ("Failed to set Account.Nickname: %s", error->message);
1236 g_error_free (error);
1240 /* Update all the contact info fields having the
1241 * Overwritten_By_Nickname flag to the new alias. This avoid accidentally
1242 * reseting the alias when calling SetContactInfo(). See bgo #644298 for
1245 update_nickname_in_contact_info (EmpathyContactWidget *self,
1246 TpConnection *connection,
1247 const gchar *nickname)
1251 specs = tp_connection_get_contact_info_supported_fields (connection);
1253 for (l = self->details_to_set; l != NULL; l= g_list_next (l))
1255 TpContactInfoField *field = l->data;
1256 TpContactInfoFieldSpec *spec;
1258 spec = get_spec_from_list (specs, field->field_name);
1259 /* We shouldn't have added the field to details_to_set if it's not
1260 * supported by the CM */
1261 g_assert (spec != NULL);
1263 if (spec->flags & TP_CONTACT_INFO_FIELD_FLAG_OVERWRITTEN_BY_NICKNAME)
1265 const gchar *strv[] = { nickname, NULL };
1267 DEBUG ("Updating field '%s' to '%s' as it has the "
1268 "Overwritten_By_Nickname flag and Account.Nickname has "
1269 "been updated", field->field_name, nickname);
1271 if (field->field_value != NULL)
1272 g_strfreev (field->field_value);
1273 field->field_value = g_strdupv ((GStrv) strv);
1277 g_list_free (specs);
1281 contact_widget_entry_alias_focus_event_cb (GtkEditable *editable,
1282 GdkEventFocus *event,
1283 EmpathyContactWidget *information)
1285 if (information->contact)
1289 alias = gtk_entry_get_text (GTK_ENTRY (editable));
1291 if (empathy_contact_is_user (information->contact))
1293 TpAccount * account;
1294 const gchar *current_nickname;
1296 account = empathy_contact_get_account (information->contact);
1297 current_nickname = tp_account_get_nickname (account);
1299 if (tp_strdiff (current_nickname, alias))
1301 DEBUG ("Set Account.Nickname to %s", alias);
1303 tp_account_set_nickname_async (account, alias, set_nickname_cb,
1306 update_nickname_in_contact_info (information,
1307 empathy_contact_get_connection (information->contact), alias);
1312 empathy_contact_set_alias (information->contact, alias);
1320 update_avatar_chooser_account_cb (EmpathyAccountChooser *account_chooser,
1321 EmpathyAvatarChooser *avatar_chooser)
1325 account = empathy_account_chooser_get_account (account_chooser);
1326 if (account == NULL)
1329 empathy_avatar_chooser_set_account (avatar_chooser, account);
1333 contact_widget_avatar_notify_cb (EmpathyContactWidget *information)
1335 EmpathyAvatar *avatar = NULL;
1337 if (information->contact)
1338 avatar = empathy_contact_get_avatar (information->contact);
1340 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_AVATAR)
1342 g_signal_handlers_block_by_func (information->widget_avatar,
1343 contact_widget_avatar_changed_cb,
1345 empathy_avatar_chooser_set (
1346 EMPATHY_AVATAR_CHOOSER (information->widget_avatar), avatar);
1347 g_signal_handlers_unblock_by_func (information->widget_avatar,
1348 contact_widget_avatar_changed_cb, information);
1351 empathy_avatar_image_set (
1352 EMPATHY_AVATAR_IMAGE (information->widget_avatar), avatar);
1356 contact_widget_name_notify_cb (EmpathyContactWidget *information)
1358 if (GTK_IS_ENTRY (information->widget_alias))
1359 gtk_entry_set_text (GTK_ENTRY (information->widget_alias),
1360 empathy_contact_get_alias (information->contact));
1362 gtk_label_set_label (GTK_LABEL (information->widget_alias),
1363 empathy_contact_get_alias (information->contact));
1367 contact_widget_presence_notify_cb (EmpathyContactWidget *information)
1369 const gchar *status;
1370 gchar *markup_text = NULL;
1372 status = empathy_contact_get_status (information->contact);
1374 markup_text = empathy_add_link_markup (status);
1375 gtk_label_set_markup (GTK_LABEL (information->label_status), markup_text);
1376 g_free (markup_text);
1378 gtk_image_set_from_icon_name (GTK_IMAGE (information->image_state),
1379 empathy_icon_name_for_contact (information->contact),
1380 GTK_ICON_SIZE_BUTTON);
1381 gtk_widget_show (information->image_state);
1385 contact_widget_favourites_changed_cb (EmpathyContactManager *manager,
1386 EmpathyContact *contact,
1387 gboolean is_favourite,
1388 EmpathyContactWidget *information)
1390 if (contact != information->contact)
1393 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (
1394 information->favourite_checkbox), is_favourite);
1398 contact_widget_remove_contact (EmpathyContactWidget *information)
1400 if (information->contact)
1402 TpContact *tp_contact;
1404 contact_widget_save (information);
1406 g_signal_handlers_disconnect_by_func (information->contact,
1407 contact_widget_name_notify_cb, information);
1408 g_signal_handlers_disconnect_by_func (information->contact,
1409 contact_widget_presence_notify_cb, information);
1410 g_signal_handlers_disconnect_by_func (information->contact,
1411 contact_widget_avatar_notify_cb, information);
1413 tp_contact = empathy_contact_get_tp_contact (information->contact);
1414 if (tp_contact != NULL)
1416 g_signal_handlers_disconnect_by_func (tp_contact,
1417 contact_widget_details_notify_cb, information);
1420 g_object_unref (information->contact);
1421 information->contact = NULL;
1424 if (information->details_cancellable != NULL)
1426 g_cancellable_cancel (information->details_cancellable);
1427 tp_clear_object (&information->details_cancellable);
1431 static void contact_widget_change_contact (EmpathyContactWidget *information);
1434 contact_widget_contact_update (EmpathyContactWidget *information)
1436 TpAccount *account = NULL;
1437 const gchar *id = NULL;
1439 /* Connect and get info from new contact */
1440 if (information->contact)
1442 g_signal_connect_swapped (information->contact, "notify::name",
1443 G_CALLBACK (contact_widget_name_notify_cb), information);
1444 g_signal_connect_swapped (information->contact, "notify::presence",
1445 G_CALLBACK (contact_widget_presence_notify_cb), information);
1446 g_signal_connect_swapped (information->contact,
1447 "notify::presence-message",
1448 G_CALLBACK (contact_widget_presence_notify_cb), information);
1449 g_signal_connect_swapped (information->contact, "notify::avatar",
1450 G_CALLBACK (contact_widget_avatar_notify_cb), information);
1452 account = empathy_contact_get_account (information->contact);
1453 id = empathy_contact_get_id (information->contact);
1456 /* Update account widget */
1457 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ACCOUNT)
1461 g_signal_handlers_block_by_func (information->widget_account,
1462 contact_widget_change_contact,
1464 empathy_account_chooser_set_account (
1465 EMPATHY_ACCOUNT_CHOOSER (information->widget_account), account);
1466 g_signal_handlers_unblock_by_func (information->widget_account,
1467 contact_widget_change_contact, information);
1476 name = tp_account_get_display_name (account);
1477 gtk_label_set_label (GTK_LABEL (information->label_account), name);
1479 name = tp_account_get_icon_name (account);
1480 gtk_image_set_from_icon_name (GTK_IMAGE (information->image_account),
1481 name, GTK_ICON_SIZE_MENU);
1485 /* Update id widget */
1486 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ID)
1487 gtk_entry_set_text (GTK_ENTRY (information->widget_id), id ? id : "");
1489 gtk_label_set_label (GTK_LABEL (information->widget_id), id ? id : "");
1491 /* Update other widgets */
1492 if (information->contact)
1494 contact_widget_name_notify_cb (information);
1495 contact_widget_presence_notify_cb (information);
1496 contact_widget_avatar_notify_cb (information);
1498 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_FAVOURITE)
1500 FolksPersona *persona = empathy_contact_get_persona (
1501 information->contact);
1503 if (persona != NULL && FOLKS_IS_FAVOURITE_DETAILS (persona))
1505 gboolean is_favourite = folks_favourite_details_get_is_favourite (
1506 FOLKS_FAVOURITE_DETAILS (persona));
1507 contact_widget_favourites_changed_cb (information->manager,
1508 information->contact, is_favourite, information);
1512 gtk_widget_show (information->label_alias);
1513 gtk_widget_show (information->widget_alias);
1514 gtk_widget_show (information->hbox_presence);
1515 gtk_widget_show (information->widget_avatar);
1519 gtk_widget_hide (information->label_alias);
1520 gtk_widget_hide (information->widget_alias);
1521 gtk_widget_hide (information->hbox_presence);
1522 gtk_widget_hide (information->widget_avatar);
1527 contact_widget_set_contact (EmpathyContactWidget *information,
1528 EmpathyContact *contact)
1530 if (contact == information->contact)
1533 contact_widget_remove_contact (information);
1535 information->contact = g_object_ref (contact);
1537 /* set the selected account to be the account this contact came from */
1538 if (contact && EMPATHY_IS_ACCOUNT_CHOOSER (information->widget_account)) {
1539 empathy_account_chooser_set_account (
1540 EMPATHY_ACCOUNT_CHOOSER (information->widget_account),
1541 empathy_contact_get_account (contact));
1544 /* Update information for widgets */
1545 contact_widget_contact_update (information);
1546 contact_widget_groups_update (information);
1547 contact_widget_details_update (information);
1548 contact_widget_client_update (information);
1549 contact_widget_location_update (information);
1553 contact_widget_got_contact_cb (TpConnection *connection,
1554 EmpathyContact *contact,
1555 const GError *error,
1557 GObject *weak_object)
1559 EmpathyContactWidget *information = user_data;
1563 DEBUG ("Error: %s", error->message);
1567 contact_widget_set_contact (information, contact);
1571 contact_widget_change_contact (EmpathyContactWidget *information)
1573 TpConnection *connection;
1575 connection = empathy_account_chooser_get_connection (
1576 EMPATHY_ACCOUNT_CHOOSER (information->widget_account));
1580 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ID)
1584 id = gtk_entry_get_text (GTK_ENTRY (information->widget_id));
1585 if (!EMP_STR_EMPTY (id))
1587 empathy_tp_contact_factory_get_from_id (connection, id,
1588 contact_widget_got_contact_cb, information, NULL,
1589 G_OBJECT (information->vbox_contact_widget));
1594 empathy_tp_contact_factory_get_from_handle (connection,
1595 tp_connection_get_self_handle (connection),
1596 contact_widget_got_contact_cb, information, NULL,
1597 G_OBJECT (information->vbox_contact_widget));
1602 contact_widget_id_activate_timeout (EmpathyContactWidget *self)
1604 contact_widget_change_contact (self);
1609 contact_widget_id_changed_cb (GtkEntry *entry,
1610 EmpathyContactWidget *self)
1612 if (self->widget_id_timeout != 0)
1614 g_source_remove (self->widget_id_timeout);
1617 self->widget_id_timeout =
1618 g_timeout_add_seconds (ID_CHANGED_TIMEOUT,
1619 (GSourceFunc) contact_widget_id_activate_timeout, self);
1623 contact_widget_id_focus_out_cb (GtkWidget *widget,
1624 GdkEventFocus *event,
1625 EmpathyContactWidget *information)
1627 contact_widget_change_contact (information);
1632 favourite_toggled_cb (GtkToggleButton *button,
1633 EmpathyContactWidget *information)
1635 FolksPersona *persona = empathy_contact_get_persona (information->contact);
1637 if (persona != NULL && FOLKS_IS_FAVOURITE_DETAILS (persona))
1639 gboolean active = gtk_toggle_button_get_active (button);
1640 folks_favourite_details_set_is_favourite (
1641 FOLKS_FAVOURITE_DETAILS (persona), active);
1646 contact_widget_contact_setup (EmpathyContactWidget *information)
1648 information->label_status = gtk_label_new ("");
1649 gtk_label_set_line_wrap_mode (GTK_LABEL (information->label_status),
1650 PANGO_WRAP_WORD_CHAR);
1651 gtk_label_set_line_wrap (GTK_LABEL (information->label_status),
1653 gtk_misc_set_alignment (GTK_MISC (information->label_status), 0, 0.5);
1655 if (!(information->flags & EMPATHY_CONTACT_WIDGET_FOR_TOOLTIP))
1656 gtk_label_set_selectable (GTK_LABEL (information->label_status), TRUE);
1658 gtk_box_pack_start (GTK_BOX (information->hbox_presence),
1659 information->label_status, TRUE, TRUE, 0);
1660 gtk_widget_show (information->label_status);
1662 /* Setup account label/chooser */
1663 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ACCOUNT)
1665 information->widget_account = empathy_account_chooser_new ();
1667 g_signal_connect_swapped (information->widget_account, "changed",
1668 G_CALLBACK (contact_widget_change_contact),
1673 /* Pack the protocol icon with the account name in an hbox */
1674 information->widget_account = gtk_hbox_new (FALSE, 6);
1676 information->label_account = gtk_label_new (NULL);
1677 if (!(information->flags & EMPATHY_CONTACT_WIDGET_FOR_TOOLTIP)) {
1678 gtk_label_set_selectable (GTK_LABEL (information->label_account), TRUE);
1680 gtk_misc_set_alignment (GTK_MISC (information->label_account), 0, 0.5);
1681 gtk_widget_show (information->label_account);
1683 information->image_account = gtk_image_new ();
1684 gtk_widget_show (information->image_account);
1686 gtk_box_pack_start (GTK_BOX (information->widget_account),
1687 information->image_account, FALSE, FALSE, 0);
1688 gtk_box_pack_start (GTK_BOX (information->widget_account),
1689 information->label_account, FALSE, TRUE, 0);
1691 gtk_table_attach_defaults (GTK_TABLE (information->table_contact),
1692 information->widget_account,
1694 gtk_widget_show (information->widget_account);
1696 /* Set up avatar chooser/display */
1697 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_AVATAR)
1699 information->widget_avatar = empathy_avatar_chooser_new ();
1700 g_signal_connect (information->widget_avatar, "changed",
1701 G_CALLBACK (contact_widget_avatar_changed_cb),
1703 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ACCOUNT)
1705 g_signal_connect (information->widget_account, "changed",
1706 G_CALLBACK (update_avatar_chooser_account_cb),
1707 information->widget_avatar);
1708 update_avatar_chooser_account_cb (
1709 EMPATHY_ACCOUNT_CHOOSER (information->widget_account),
1710 EMPATHY_AVATAR_CHOOSER (information->widget_avatar));
1715 information->widget_avatar = empathy_avatar_image_new ();
1717 g_signal_connect (information->widget_avatar, "popup-menu",
1718 G_CALLBACK (widget_avatar_popup_menu_cb), information);
1719 g_signal_connect (information->widget_avatar, "button-press-event",
1720 G_CALLBACK (widget_avatar_button_press_event_cb), information);
1723 gtk_box_pack_start (GTK_BOX (information->vbox_avatar),
1724 information->widget_avatar,
1727 gtk_widget_show (information->widget_avatar);
1729 /* Setup id label/entry */
1730 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ID)
1732 information->widget_id = gtk_entry_new ();
1733 g_signal_connect (information->widget_id, "focus-out-event",
1734 G_CALLBACK (contact_widget_id_focus_out_cb),
1736 g_signal_connect (information->widget_id, "changed",
1737 G_CALLBACK (contact_widget_id_changed_cb),
1742 information->widget_id = gtk_label_new (NULL);
1743 if (!(information->flags & EMPATHY_CONTACT_WIDGET_FOR_TOOLTIP)) {
1744 gtk_label_set_selectable (GTK_LABEL (information->widget_id), TRUE);
1746 gtk_misc_set_alignment (GTK_MISC (information->widget_id), 0, 0.5);
1748 gtk_table_attach_defaults (GTK_TABLE (information->table_contact),
1749 information->widget_id,
1751 gtk_widget_show (information->widget_id);
1753 /* Setup alias label/entry */
1754 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ALIAS)
1756 information->widget_alias = gtk_entry_new ();
1758 if (!(information->flags & EMPATHY_CONTACT_WIDGET_NO_SET_ALIAS))
1759 g_signal_connect (information->widget_alias, "focus-out-event",
1760 G_CALLBACK (contact_widget_entry_alias_focus_event_cb),
1763 /* Make return activate the window default (the Close button) */
1764 gtk_entry_set_activates_default (GTK_ENTRY (information->widget_alias),
1769 information->widget_alias = gtk_label_new (NULL);
1770 if (!(information->flags & EMPATHY_CONTACT_WIDGET_FOR_TOOLTIP)) {
1771 gtk_label_set_selectable (GTK_LABEL (information->widget_alias), TRUE);
1773 gtk_misc_set_alignment (GTK_MISC (information->widget_alias), 0, 0.5);
1775 gtk_table_attach_defaults (GTK_TABLE (information->table_contact),
1776 information->widget_alias,
1778 if (information->flags & EMPATHY_CONTACT_WIDGET_FOR_TOOLTIP) {
1779 gtk_label_set_selectable (GTK_LABEL (information->label_status), FALSE);
1781 gtk_widget_show (information->widget_alias);
1784 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_FAVOURITE)
1786 information->favourite_checkbox = gtk_check_button_new_with_label (
1789 g_signal_connect (information->favourite_checkbox, "toggled",
1790 G_CALLBACK (favourite_toggled_cb), information);
1792 gtk_table_attach_defaults (GTK_TABLE (information->table_contact),
1793 information->favourite_checkbox, 0, 2, 3, 4);
1795 information->fav_sig_id = g_signal_connect (information->manager,
1796 "favourites-changed",
1797 G_CALLBACK (contact_widget_favourites_changed_cb), information);
1799 gtk_widget_show (information->favourite_checkbox);
1804 contact_widget_destroy_cb (GtkWidget *widget,
1805 EmpathyContactWidget *information)
1807 contact_widget_remove_contact (information);
1809 if (information->widget_id_timeout != 0)
1811 g_source_remove (information->widget_id_timeout);
1814 if (information->fav_sig_id != 0)
1815 g_signal_handler_disconnect (information->manager, information->fav_sig_id);
1817 g_object_unref (information->manager);
1819 g_slice_free (EmpathyContactWidget, information);
1823 * empathy_contact_widget_new:
1824 * @contact: an #EmpathyContact
1825 * @flags: #EmpathyContactWidgetFlags for the new contact widget
1827 * Creates a new #EmpathyContactWidget.
1829 * Return value: a new #EmpathyContactWidget
1832 empathy_contact_widget_new (EmpathyContact *contact,
1833 EmpathyContactWidgetFlags flags)
1835 EmpathyContactWidget *information;
1839 g_return_val_if_fail (contact == NULL || EMPATHY_IS_CONTACT (contact), NULL);
1841 information = g_slice_new0 (EmpathyContactWidget);
1842 information->flags = flags;
1844 filename = empathy_file_lookup ("empathy-contact-widget.ui",
1846 gui = empathy_builder_get_file (filename,
1847 "vbox_contact_widget", &information->vbox_contact_widget,
1848 "hbox_contact", &information->hbox_contact,
1849 "hbox_presence", &information->hbox_presence,
1850 "label_alias", &information->label_alias,
1851 "image_state", &information->image_state,
1852 "table_contact", &information->table_contact,
1853 "vbox_avatar", &information->vbox_avatar,
1854 "vbox_location", &information->vbox_location,
1855 "subvbox_location", &information->subvbox_location,
1856 "label_location", &information->label_location,
1857 #ifdef HAVE_LIBCHAMPLAIN
1858 "viewport_map", &information->viewport_map,
1860 "groups_widget", &information->groups_widget,
1861 "vbox_details", &information->vbox_details,
1862 "table_details", &information->table_details,
1863 "hbox_details_requested", &information->hbox_details_requested,
1864 "vbox_client", &information->vbox_client,
1865 "table_client", &information->table_client,
1866 "hbox_client_requested", &information->hbox_client_requested,
1870 empathy_builder_connect (gui, information,
1871 "vbox_contact_widget", "destroy", contact_widget_destroy_cb,
1873 information->table_location = NULL;
1875 g_object_set_data (G_OBJECT (information->vbox_contact_widget),
1876 "EmpathyContactWidget",
1879 information->manager = empathy_contact_manager_dup_singleton ();
1881 /* Create widgets */
1882 contact_widget_contact_setup (information);
1883 contact_widget_details_setup (information);
1884 contact_widget_client_setup (information);
1886 if (contact != NULL)
1887 contact_widget_set_contact (information, contact);
1888 else if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ACCOUNT ||
1889 information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ID)
1890 contact_widget_change_contact (information);
1892 return empathy_builder_unref_and_keep_widget (gui,
1893 information->vbox_contact_widget);
1897 * empathy_contact_widget_get_contact:
1898 * @widget: an #EmpathyContactWidget
1900 * Get the #EmpathyContact related with the #EmpathyContactWidget @widget.
1902 * Returns: the #EmpathyContact associated with @widget
1905 empathy_contact_widget_get_contact (GtkWidget *widget)
1907 EmpathyContactWidget *information;
1909 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
1911 information = g_object_get_data (G_OBJECT (widget), "EmpathyContactWidget");
1915 return information->contact;
1919 empathy_contact_widget_get_alias (GtkWidget *widget)
1921 EmpathyContactWidget *information;
1923 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
1925 information = g_object_get_data (G_OBJECT (widget), "EmpathyContactWidget");
1929 return gtk_entry_get_text (GTK_ENTRY (information->widget_alias));
1933 * empathy_contact_widget_set_contact:
1934 * @widget: an #EmpathyContactWidget
1935 * @contact: a different #EmpathyContact
1937 * Change the #EmpathyContact related with the #EmpathyContactWidget @widget.
1940 empathy_contact_widget_set_contact (GtkWidget *widget,
1941 EmpathyContact *contact)
1943 EmpathyContactWidget *information;
1945 g_return_if_fail (GTK_IS_WIDGET (widget));
1946 g_return_if_fail (EMPATHY_IS_CONTACT (contact));
1948 information = g_object_get_data (G_OBJECT (widget), "EmpathyContactWidget");
1952 contact_widget_set_contact (information, contact);
1956 * empathy_contact_widget_set_account_filter:
1957 * @widget: an #EmpathyContactWidget
1958 * @filter: a #EmpathyAccountChooserFilterFunc
1959 * @user_data: user data to pass to @filter, or %NULL
1961 * Set a filter on the #EmpathyAccountChooser included in the
1962 * #EmpathyContactWidget.
1965 empathy_contact_widget_set_account_filter (
1967 EmpathyAccountChooserFilterFunc filter,
1970 EmpathyContactWidget *information;
1971 EmpathyAccountChooser *chooser;
1973 g_return_if_fail (GTK_IS_WIDGET (widget));
1975 information = g_object_get_data (G_OBJECT (widget), "EmpathyContactWidget");
1979 chooser = EMPATHY_ACCOUNT_CHOOSER (information->widget_account);
1981 empathy_account_chooser_set_filter (chooser, filter, user_data);