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 *grid_contact;
106 GtkWidget *vbox_avatar;
107 GtkWidget *favourite_checkbox;
110 GtkWidget *vbox_location;
111 GtkWidget *subvbox_location;
112 GtkWidget *grid_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 *grid_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 *grid_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_grid_attach (GTK_GRID (information->grid_details),
424 gtk_misc_set_alignment (GTK_MISC (w), 0, 0.5);
428 if (!tp_strdiff (field->field_name, "bday"))
430 w = gtk_calendar_new ();
431 if (field->field_value[0])
435 g_date_set_parse (&date, field->field_value[0]);
436 if (g_date_valid (&date))
438 gtk_calendar_select_day (GTK_CALENDAR (w),
439 g_date_get_day (&date));
440 gtk_calendar_select_month (GTK_CALENDAR (w),
441 g_date_get_month (&date) - 1, g_date_get_year (&date));
442 gtk_calendar_mark_day (GTK_CALENDAR (w),
443 g_date_get_day (&date));
447 gtk_grid_attach (GTK_GRID (information->grid_details),
451 g_object_set_data ((GObject *) w, DATA_FIELD, field);
453 g_signal_connect (w, "day-selected",
454 G_CALLBACK (contact_widget_bday_changed_cb), information);
455 g_signal_connect (w, "month-changed",
456 G_CALLBACK (contact_widget_bday_changed_cb), information);
460 w = gtk_entry_new ();
461 gtk_entry_set_text (GTK_ENTRY (w),
462 field->field_value[0] ? field->field_value[0] : "");
463 gtk_grid_attach (GTK_GRID (information->grid_details),
467 g_object_set_data ((GObject *) w, DATA_FIELD, field);
469 g_signal_connect (w, "changed",
470 G_CALLBACK (contact_widget_details_changed_cb), information);
483 channel_name_activated_cb (
486 EmpathyContactWidget *information)
488 TpAccount *account = empathy_contact_get_account (information->contact);
490 empathy_join_muc (account, uri, empathy_get_current_action_time ());
496 EmpathyContactWidget *information,
501 GString *label_markup = g_string_new ("");
504 w = gtk_label_new (_("Channels:"));
505 gtk_grid_attach (GTK_GRID (information->grid_details),
507 gtk_misc_set_alignment (GTK_MISC (w), 0, 0.5);
510 for (i = 0; i < channels->len; i++)
512 const gchar *channel_name = g_ptr_array_index (channels, i);
513 /* We abuse the URI of the link to hold the channel name. It seems to
514 * be okay to just use it essentially verbatim, rather than trying to
515 * ensure it's actually a valid URI. g_string_append_uri_escaped()
516 * escapes way more than we actually need to; so we're just using
517 * g_markup_escape_text directly.
519 gchar *escaped = g_markup_escape_text (channel_name, -1);
522 g_string_append (label_markup, ", ");
524 g_string_append_printf (label_markup, "<a href='%s'>%s</a>",
525 escaped, channel_name);
529 w = gtk_label_new (NULL);
530 gtk_label_set_markup (GTK_LABEL (w), label_markup->str);
531 gtk_label_set_line_wrap (GTK_LABEL (w), TRUE);
532 g_signal_connect (w, "activate-link",
533 (GCallback) channel_name_activated_cb, information);
534 gtk_grid_attach (GTK_GRID (information->grid_details),
536 gtk_misc_set_alignment (GTK_MISC (w), 0, 0.5);
539 g_string_free (label_markup, TRUE);
543 contact_widget_details_update_show (EmpathyContactWidget *information)
548 GPtrArray *channels = g_ptr_array_new ();
550 contact = empathy_contact_get_tp_contact (information->contact);
551 info = tp_contact_get_contact_info (contact);
552 info = g_list_sort (info, (GCompareFunc) empathy_contact_info_field_cmp);
553 for (l = info; l != NULL; l = l->next)
555 TpContactInfoField *field = l->data;
557 gchar *markup = NULL, *title;
559 EmpathyContactInfoFormatFunc format;
561 if (field->field_value == NULL || field->field_value[0] == NULL)
564 value = field->field_value[0];
566 if (!tp_strdiff (field->field_name, "x-irc-channel"))
568 g_ptr_array_add (channels, (gpointer) field->field_value[0]);
572 if (!empathy_contact_info_lookup_field (field->field_name, NULL, &format))
574 DEBUG ("Unhandled ContactInfo field: %s", field->field_name);
580 markup = format (field->field_value);
584 DEBUG ("Invalid value for field '%s' (first element was '%s')",
585 field->field_name, field->field_value[0]);
591 title = empathy_contact_info_field_label (field->field_name,
593 w = gtk_label_new (title);
596 gtk_grid_attach (GTK_GRID (information->grid_details),
598 gtk_misc_set_alignment (GTK_MISC (w), 0, 0.5);
602 w = gtk_label_new (value);
605 gtk_label_set_markup (GTK_LABEL (w), markup);
609 if ((information->flags & EMPATHY_CONTACT_WIDGET_FOR_TOOLTIP) == 0)
610 gtk_label_set_selectable (GTK_LABEL (w), TRUE);
612 gtk_grid_attach (GTK_GRID (information->grid_details),
614 gtk_misc_set_alignment (GTK_MISC (w), 0, 0.5);
622 if (channels->len > 0)
624 add_channel_list (information, channels, n_rows);
628 g_ptr_array_unref (channels);
633 contact_widget_details_notify_cb (EmpathyContactWidget *information)
637 gtk_container_foreach (GTK_CONTAINER (information->grid_details),
638 (GtkCallback) gtk_widget_destroy, NULL);
640 if ((information->flags & EMPATHY_CONTACT_WIDGET_EDIT_DETAILS) != 0)
641 n_rows = contact_widget_details_update_edit (information);
643 n_rows = contact_widget_details_update_show (information);
647 gtk_widget_show (information->vbox_details);
648 gtk_widget_show (information->grid_details);
652 gtk_widget_hide (information->vbox_details);
655 gtk_widget_hide (information->hbox_details_requested);
656 gtk_spinner_stop (GTK_SPINNER (information->spinner_details));
660 contact_widget_details_request_cb (GObject *object,
664 TpContact *contact = TP_CONTACT (object);
665 EmpathyContactWidget *information = user_data;
666 GError *error = NULL;
668 if (!tp_contact_request_contact_info_finish (contact, res, &error))
670 /* If the request got cancelled it could mean the contact widget is
671 * destroyed, so we should not dereference information */
672 if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
674 g_clear_error (&error);
678 gtk_widget_hide (information->vbox_details);
679 g_clear_error (&error);
683 contact_widget_details_notify_cb (information);
686 /* If we are going to edit ContactInfo, we don't want live updates */
687 if ((information->flags & EMPATHY_CONTACT_WIDGET_EDIT_DETAILS) == 0)
689 g_signal_connect_swapped (contact, "notify::contact-info",
690 G_CALLBACK (contact_widget_details_notify_cb), information);
693 tp_clear_object (&information->details_cancellable);
697 fetch_contact_information (EmpathyContactWidget *information,
698 TpConnection *connection)
701 TpContactInfoFlags flags;
703 if (!tp_proxy_has_interface_by_id (connection,
704 TP_IFACE_QUARK_CONNECTION_INTERFACE_CONTACT_INFO))
706 gtk_widget_hide (information->vbox_details);
710 /* If we want to edit info, but connection does not support that, stop */
711 flags = tp_connection_get_contact_info_flags (connection);
712 if ((flags & TP_CONTACT_INFO_FLAG_CAN_SET) == 0 &&
713 (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_DETAILS) != 0)
715 gtk_widget_hide (information->vbox_details);
719 /* Request the contact's info */
720 gtk_widget_show (information->vbox_details);
721 gtk_widget_show (information->hbox_details_requested);
722 gtk_widget_hide (information->grid_details);
723 gtk_spinner_start (GTK_SPINNER (information->spinner_details));
725 contact = empathy_contact_get_tp_contact (information->contact);
726 g_assert (information->details_cancellable == NULL);
727 information->details_cancellable = g_cancellable_new ();
728 tp_contact_request_contact_info_async (contact,
729 information->details_cancellable, contact_widget_details_request_cb,
734 contact_widget_details_update (EmpathyContactWidget *information)
736 TpContact *tp_contact = NULL;
738 if ((information->flags & EMPATHY_CONTACT_WIDGET_SHOW_DETAILS) == 0 &&
739 (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_DETAILS) == 0)
742 gtk_widget_hide (information->vbox_details);
744 if (information->contact != NULL)
745 tp_contact = empathy_contact_get_tp_contact (information->contact);
747 if (tp_contact != NULL)
749 TpConnection *connection;
751 connection = tp_contact_get_connection (tp_contact);
753 fetch_contact_information (information, connection);
758 contact_widget_client_update (EmpathyContactWidget *information)
760 /* FIXME: Needs new telepathy spec */
764 contact_widget_client_setup (EmpathyContactWidget *information)
766 /* FIXME: Needs new telepathy spec */
767 gtk_widget_hide (information->vbox_client);
771 contact_widget_groups_update (EmpathyContactWidget *information)
773 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_GROUPS &&
774 information->contact != NULL)
776 FolksPersona *persona =
777 empathy_contact_get_persona (information->contact);
779 if (FOLKS_IS_GROUP_DETAILS (persona))
781 empathy_groups_widget_set_group_details (
782 EMPATHY_GROUPS_WIDGET (information->groups_widget),
783 FOLKS_GROUP_DETAILS (persona));
784 gtk_widget_show (information->groups_widget);
790 /* In case of failure */
791 gtk_widget_hide (information->groups_widget);
794 /* Converts the Location's GHashTable's key to a user readable string */
796 location_key_to_label (const gchar *key)
798 if (tp_strdiff (key, EMPATHY_LOCATION_COUNTRY_CODE) == FALSE)
799 return _("Country ISO Code:");
800 else if (tp_strdiff (key, EMPATHY_LOCATION_COUNTRY) == FALSE)
801 return _("Country:");
802 else if (tp_strdiff (key, EMPATHY_LOCATION_REGION) == FALSE)
804 else if (tp_strdiff (key, EMPATHY_LOCATION_LOCALITY) == FALSE)
806 else if (tp_strdiff (key, EMPATHY_LOCATION_AREA) == FALSE)
808 else if (tp_strdiff (key, EMPATHY_LOCATION_POSTAL_CODE) == FALSE)
809 return _("Postal Code:");
810 else if (tp_strdiff (key, EMPATHY_LOCATION_STREET) == FALSE)
812 else if (tp_strdiff (key, EMPATHY_LOCATION_BUILDING) == FALSE)
813 return _("Building:");
814 else if (tp_strdiff (key, EMPATHY_LOCATION_FLOOR) == FALSE)
816 else if (tp_strdiff (key, EMPATHY_LOCATION_ROOM) == FALSE)
818 else if (tp_strdiff (key, EMPATHY_LOCATION_TEXT) == FALSE)
820 else if (tp_strdiff (key, EMPATHY_LOCATION_DESCRIPTION) == FALSE)
821 return _("Description:");
822 else if (tp_strdiff (key, EMPATHY_LOCATION_URI) == FALSE)
824 else if (tp_strdiff (key, EMPATHY_LOCATION_ACCURACY_LEVEL) == FALSE)
825 return _("Accuracy Level:");
826 else if (tp_strdiff (key, EMPATHY_LOCATION_ERROR) == FALSE)
828 else if (tp_strdiff (key, EMPATHY_LOCATION_VERTICAL_ERROR_M) == FALSE)
829 return _("Vertical Error (meters):");
830 else if (tp_strdiff (key, EMPATHY_LOCATION_HORIZONTAL_ERROR_M) == FALSE)
831 return _("Horizontal Error (meters):");
832 else if (tp_strdiff (key, EMPATHY_LOCATION_SPEED) == FALSE)
834 else if (tp_strdiff (key, EMPATHY_LOCATION_BEARING) == FALSE)
835 return _("Bearing:");
836 else if (tp_strdiff (key, EMPATHY_LOCATION_CLIMB) == FALSE)
837 return _("Climb Speed:");
838 else if (tp_strdiff (key, EMPATHY_LOCATION_TIMESTAMP) == FALSE)
839 return _("Last Updated on:");
840 else if (tp_strdiff (key, EMPATHY_LOCATION_LON) == FALSE)
841 return _("Longitude:");
842 else if (tp_strdiff (key, EMPATHY_LOCATION_LAT) == FALSE)
843 return _("Latitude:");
844 else if (tp_strdiff (key, EMPATHY_LOCATION_ALT) == FALSE)
845 return _("Altitude:");
848 DEBUG ("Unexpected Location key: %s", key);
854 contact_widget_location_update (EmpathyContactWidget *information)
856 GHashTable *location;
858 #ifdef HAVE_LIBCHAMPLAIN
859 gdouble lat = 0.0, lon = 0.0;
860 gboolean has_position = TRUE;
864 static const gchar* ordered_geolocation_keys[] = {
865 EMPATHY_LOCATION_TEXT,
866 EMPATHY_LOCATION_URI,
867 EMPATHY_LOCATION_DESCRIPTION,
868 EMPATHY_LOCATION_BUILDING,
869 EMPATHY_LOCATION_FLOOR,
870 EMPATHY_LOCATION_ROOM,
871 EMPATHY_LOCATION_STREET,
872 EMPATHY_LOCATION_AREA,
873 EMPATHY_LOCATION_LOCALITY,
874 EMPATHY_LOCATION_REGION,
875 EMPATHY_LOCATION_COUNTRY,
880 gboolean display_map = FALSE;
882 if (!(information->flags & EMPATHY_CONTACT_WIDGET_SHOW_LOCATION))
884 gtk_widget_hide (information->vbox_location);
888 location = empathy_contact_get_location (information->contact);
889 if (location == NULL || g_hash_table_size (location) == 0)
891 gtk_widget_hide (information->vbox_location);
895 value = g_hash_table_lookup (location, EMPATHY_LOCATION_TIMESTAMP);
898 gchar *loc = g_strdup_printf ("<b>%s</b>", _("Location"));
899 gtk_label_set_markup (GTK_LABEL (information->label_location), loc);
909 stamp = g_value_get_int64 (value);
911 user_date = empathy_time_to_string_relative (stamp);
913 tmp = g_strdup_printf ("<b>%s</b>", _("Location"));
914 /* translators: format is "Location, $date" */
915 text = g_strdup_printf (_("%s, %s"), tmp, user_date);
917 gtk_label_set_markup (GTK_LABEL (information->label_location), text);
923 /* Prepare the location information grid */
924 if (information->grid_location != NULL)
926 gtk_widget_destroy (information->grid_location);
929 information->grid_location = gtk_grid_new ();
930 gtk_box_pack_start (GTK_BOX (information->subvbox_location),
931 information->grid_location, FALSE, FALSE, 5);
934 for (i = 0; (skey = ordered_geolocation_keys[i]); i++)
936 const gchar* user_label;
940 gvalue = g_hash_table_lookup (location, (gpointer) skey);
944 user_label = location_key_to_label (skey);
946 label = gtk_label_new (user_label);
947 gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
948 gtk_grid_attach (GTK_GRID (information->grid_location),
949 label, 0, row, 1, 1);
950 gtk_widget_show (label);
952 if (G_VALUE_TYPE (gvalue) == G_TYPE_DOUBLE)
955 dvalue = g_value_get_double (gvalue);
956 svalue = g_strdup_printf ("%f", dvalue);
958 else if (G_VALUE_TYPE (gvalue) == G_TYPE_STRING)
960 svalue = g_value_dup_string (gvalue);
962 else if (G_VALUE_TYPE (gvalue) == G_TYPE_INT64)
966 time_ = g_value_get_int64 (value);
967 svalue = empathy_time_to_string_utc (time_, _("%B %e, %Y at %R UTC"));
972 label = gtk_label_new (svalue);
973 gtk_grid_attach (GTK_GRID (information->grid_location),
974 label, 1, row, 1, 1);
975 gtk_misc_set_alignment (GTK_MISC (label), 0, 0);
976 gtk_widget_show (label);
978 if (!(information->flags & EMPATHY_CONTACT_WIDGET_FOR_TOOLTIP))
979 gtk_label_set_selectable (GTK_LABEL (label), TRUE);
986 #ifdef HAVE_LIBCHAMPLAIN
988 !(information->flags & EMPATHY_CONTACT_WIDGET_FOR_TOOLTIP))
990 /* Cannot be displayed in tooltips until Clutter-Gtk can deal with such
998 /* We can display some fields */
999 gtk_widget_show (information->grid_location);
1001 else if (!display_map)
1003 /* Can't display either fields or map */
1004 gtk_widget_hide (information->vbox_location);
1008 #ifdef HAVE_LIBCHAMPLAIN
1011 ClutterActor *marker;
1012 ChamplainMarkerLayer *layer;
1014 information->map_view_embed = gtk_champlain_embed_new ();
1015 information->map_view = gtk_champlain_embed_get_view (
1016 GTK_CHAMPLAIN_EMBED (information->map_view_embed));
1018 gtk_container_add (GTK_CONTAINER (information->viewport_map),
1019 information->map_view_embed);
1020 g_object_set (G_OBJECT (information->map_view),
1021 "kinetic-mode", TRUE,
1025 layer = champlain_marker_layer_new ();
1026 champlain_view_add_layer (information->map_view, CHAMPLAIN_LAYER (layer));
1028 marker = champlain_label_new_with_text (
1029 empathy_contact_get_alias (information->contact), NULL, NULL, NULL);
1030 champlain_location_set_location (CHAMPLAIN_LOCATION (marker), lat, lon);
1031 champlain_marker_layer_add_marker (layer, CHAMPLAIN_MARKER (marker));
1033 champlain_view_center_on (information->map_view, lat, lon);
1034 gtk_widget_show_all (information->viewport_map);
1038 gtk_widget_show (information->vbox_location);
1042 save_avatar_menu_activate_cb (GtkWidget *widget,
1043 EmpathyContactWidget *information)
1046 EmpathyAvatar *avatar;
1047 gchar *ext = NULL, *filename;
1049 dialog = gtk_file_chooser_dialog_new (_("Save Avatar"),
1051 GTK_FILE_CHOOSER_ACTION_SAVE,
1052 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
1053 GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT,
1056 gtk_file_chooser_set_do_overwrite_confirmation (GTK_FILE_CHOOSER (dialog),
1059 /* look for the avatar extension */
1060 avatar = empathy_contact_get_avatar (information->contact);
1061 if (avatar->format != NULL)
1065 splitted = g_strsplit (avatar->format, "/", 2);
1066 if (splitted[0] != NULL && splitted[1] != NULL)
1067 ext = g_strdup (splitted[1]);
1069 g_strfreev (splitted);
1073 /* Avatar was loaded from the cache so was converted to PNG */
1074 ext = g_strdup ("png");
1081 id = tp_escape_as_identifier (empathy_contact_get_id (
1082 information->contact));
1084 filename = g_strdup_printf ("%s.%s", id, ext);
1085 gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (dialog), filename);
1092 if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT)
1094 GError *error = NULL;
1096 filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
1098 if (!empathy_avatar_save_to_file (avatar, filename, &error))
1101 GtkWidget *error_dialog;
1103 error_dialog = gtk_message_dialog_new (NULL, 0,
1104 GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE,
1105 _("Unable to save avatar"));
1107 gtk_message_dialog_format_secondary_text (
1108 GTK_MESSAGE_DIALOG (error_dialog), "%s", error->message);
1110 g_signal_connect (error_dialog, "response",
1111 G_CALLBACK (gtk_widget_destroy), NULL);
1113 gtk_window_present (GTK_WINDOW (error_dialog));
1115 g_clear_error (&error);
1121 gtk_widget_destroy (dialog);
1125 popup_avatar_menu (EmpathyContactWidget *information,
1127 GdkEventButton *event)
1129 GtkWidget *menu, *item;
1130 gint button, event_time;
1132 if (information->contact == NULL ||
1133 empathy_contact_get_avatar (information->contact) == NULL)
1136 menu = empathy_context_menu_new (parent);
1138 /* Add "Save as..." entry */
1139 item = gtk_image_menu_item_new_from_stock (GTK_STOCK_SAVE_AS, NULL);
1140 gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
1141 gtk_widget_show (item);
1143 g_signal_connect (item, "activate",
1144 G_CALLBACK (save_avatar_menu_activate_cb), information);
1148 button = event->button;
1149 event_time = event->time;
1154 event_time = gtk_get_current_event_time ();
1157 gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
1158 button, event_time);
1162 widget_avatar_popup_menu_cb (GtkWidget *widget,
1163 EmpathyContactWidget *information)
1165 popup_avatar_menu (information, widget, NULL);
1171 widget_avatar_button_press_event_cb (GtkWidget *widget,
1172 GdkEventButton *event,
1173 EmpathyContactWidget *information)
1175 /* Ignore double-clicks and triple-clicks */
1176 if (event->button == 3 && event->type == GDK_BUTTON_PRESS)
1178 popup_avatar_menu (information, widget, event);
1186 set_avatar_cb (GObject *source,
1190 GError *error = NULL;
1192 if (!tp_account_set_avatar_finish (TP_ACCOUNT (source), res, &error)) {
1193 DEBUG ("Failed to set Account.Avatar: %s", error->message);
1194 g_error_free (error);
1199 set_avatar_on_account (TpAccount *account,
1202 const gchar *mime_type)
1204 DEBUG ("%s Account.Avatar on %s", size > 0 ? "Set": "Clear",
1205 tp_proxy_get_object_path (account));
1207 tp_account_set_avatar_async (account, (const guchar *) data, size,
1208 mime_type, set_avatar_cb, NULL);
1212 contact_widget_avatar_changed_cb (EmpathyAvatarChooser *chooser,
1213 EmpathyContactWidget *information)
1217 const gchar *mime_type;
1220 empathy_avatar_chooser_get_image_data (
1221 EMPATHY_AVATAR_CHOOSER (information->widget_avatar),
1222 &data, &size, &mime_type);
1224 account = empathy_contact_get_account (information->contact);
1225 set_avatar_on_account (account, data, size, mime_type);
1229 set_nickname_cb (GObject *source,
1233 GError *error = NULL;
1235 if (!tp_account_set_nickname_finish (TP_ACCOUNT (source), res, &error))
1237 DEBUG ("Failed to set Account.Nickname: %s", error->message);
1238 g_error_free (error);
1242 /* Update all the contact info fields having the
1243 * Overwritten_By_Nickname flag to the new alias. This avoid accidentally
1244 * reseting the alias when calling SetContactInfo(). See bgo #644298 for
1247 update_nickname_in_contact_info (EmpathyContactWidget *self,
1248 TpConnection *connection,
1249 const gchar *nickname)
1253 specs = tp_connection_get_contact_info_supported_fields (connection);
1255 for (l = self->details_to_set; l != NULL; l= g_list_next (l))
1257 TpContactInfoField *field = l->data;
1258 TpContactInfoFieldSpec *spec;
1260 spec = get_spec_from_list (specs, field->field_name);
1261 /* We shouldn't have added the field to details_to_set if it's not
1262 * supported by the CM */
1263 g_assert (spec != NULL);
1265 if (spec->flags & TP_CONTACT_INFO_FIELD_FLAG_OVERWRITTEN_BY_NICKNAME)
1267 const gchar *strv[] = { nickname, NULL };
1269 DEBUG ("Updating field '%s' to '%s' as it has the "
1270 "Overwritten_By_Nickname flag and Account.Nickname has "
1271 "been updated", field->field_name, nickname);
1273 if (field->field_value != NULL)
1274 g_strfreev (field->field_value);
1275 field->field_value = g_strdupv ((GStrv) strv);
1279 g_list_free (specs);
1283 contact_widget_entry_alias_focus_event_cb (GtkEditable *editable,
1284 GdkEventFocus *event,
1285 EmpathyContactWidget *information)
1287 if (information->contact)
1291 alias = gtk_entry_get_text (GTK_ENTRY (editable));
1293 if (empathy_contact_is_user (information->contact))
1295 TpAccount * account;
1296 const gchar *current_nickname;
1298 account = empathy_contact_get_account (information->contact);
1299 current_nickname = tp_account_get_nickname (account);
1301 if (tp_strdiff (current_nickname, alias))
1303 DEBUG ("Set Account.Nickname to %s", alias);
1305 tp_account_set_nickname_async (account, alias, set_nickname_cb,
1308 update_nickname_in_contact_info (information,
1309 empathy_contact_get_connection (information->contact), alias);
1314 empathy_contact_set_alias (information->contact, alias);
1322 update_avatar_chooser_account_cb (EmpathyAccountChooser *account_chooser,
1323 EmpathyAvatarChooser *avatar_chooser)
1327 account = empathy_account_chooser_get_account (account_chooser);
1328 if (account == NULL)
1331 empathy_avatar_chooser_set_account (avatar_chooser, account);
1335 contact_widget_avatar_notify_cb (EmpathyContactWidget *information)
1337 EmpathyAvatar *avatar = NULL;
1339 if (information->contact)
1340 avatar = empathy_contact_get_avatar (information->contact);
1342 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_AVATAR)
1344 g_signal_handlers_block_by_func (information->widget_avatar,
1345 contact_widget_avatar_changed_cb,
1347 empathy_avatar_chooser_set (
1348 EMPATHY_AVATAR_CHOOSER (information->widget_avatar), avatar);
1349 g_signal_handlers_unblock_by_func (information->widget_avatar,
1350 contact_widget_avatar_changed_cb, information);
1353 empathy_avatar_image_set (
1354 EMPATHY_AVATAR_IMAGE (information->widget_avatar), avatar);
1358 contact_widget_name_notify_cb (EmpathyContactWidget *information)
1360 if (GTK_IS_ENTRY (information->widget_alias))
1361 gtk_entry_set_text (GTK_ENTRY (information->widget_alias),
1362 empathy_contact_get_alias (information->contact));
1364 gtk_label_set_label (GTK_LABEL (information->widget_alias),
1365 empathy_contact_get_alias (information->contact));
1369 contact_widget_presence_notify_cb (EmpathyContactWidget *information)
1371 const gchar *status;
1372 gchar *markup_text = NULL;
1374 status = empathy_contact_get_status (information->contact);
1376 markup_text = empathy_add_link_markup (status);
1377 gtk_label_set_markup (GTK_LABEL (information->label_status), markup_text);
1378 g_free (markup_text);
1380 gtk_image_set_from_icon_name (GTK_IMAGE (information->image_state),
1381 empathy_icon_name_for_contact (information->contact),
1382 GTK_ICON_SIZE_BUTTON);
1383 gtk_widget_show (information->image_state);
1387 contact_widget_favourites_changed_cb (EmpathyContactManager *manager,
1388 EmpathyContact *contact,
1389 gboolean is_favourite,
1390 EmpathyContactWidget *information)
1392 if (contact != information->contact)
1395 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (
1396 information->favourite_checkbox), is_favourite);
1400 contact_widget_remove_contact (EmpathyContactWidget *information)
1402 if (information->contact)
1404 TpContact *tp_contact;
1406 contact_widget_save (information);
1408 g_signal_handlers_disconnect_by_func (information->contact,
1409 contact_widget_name_notify_cb, information);
1410 g_signal_handlers_disconnect_by_func (information->contact,
1411 contact_widget_presence_notify_cb, information);
1412 g_signal_handlers_disconnect_by_func (information->contact,
1413 contact_widget_avatar_notify_cb, information);
1415 tp_contact = empathy_contact_get_tp_contact (information->contact);
1416 if (tp_contact != NULL)
1418 g_signal_handlers_disconnect_by_func (tp_contact,
1419 contact_widget_details_notify_cb, information);
1422 g_object_unref (information->contact);
1423 information->contact = NULL;
1426 if (information->details_cancellable != NULL)
1428 g_cancellable_cancel (information->details_cancellable);
1429 tp_clear_object (&information->details_cancellable);
1433 static void contact_widget_change_contact (EmpathyContactWidget *information);
1436 contact_widget_contact_update (EmpathyContactWidget *information)
1438 TpAccount *account = NULL;
1439 const gchar *id = NULL;
1441 /* Connect and get info from new contact */
1442 if (information->contact)
1444 g_signal_connect_swapped (information->contact, "notify::name",
1445 G_CALLBACK (contact_widget_name_notify_cb), information);
1446 g_signal_connect_swapped (information->contact, "notify::presence",
1447 G_CALLBACK (contact_widget_presence_notify_cb), information);
1448 g_signal_connect_swapped (information->contact,
1449 "notify::presence-message",
1450 G_CALLBACK (contact_widget_presence_notify_cb), information);
1451 g_signal_connect_swapped (information->contact, "notify::avatar",
1452 G_CALLBACK (contact_widget_avatar_notify_cb), information);
1454 account = empathy_contact_get_account (information->contact);
1455 id = empathy_contact_get_id (information->contact);
1458 /* Update account widget */
1459 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ACCOUNT)
1463 g_signal_handlers_block_by_func (information->widget_account,
1464 contact_widget_change_contact,
1466 empathy_account_chooser_set_account (
1467 EMPATHY_ACCOUNT_CHOOSER (information->widget_account), account);
1468 g_signal_handlers_unblock_by_func (information->widget_account,
1469 contact_widget_change_contact, information);
1478 name = tp_account_get_display_name (account);
1479 gtk_label_set_label (GTK_LABEL (information->label_account), name);
1481 name = tp_account_get_icon_name (account);
1482 gtk_image_set_from_icon_name (GTK_IMAGE (information->image_account),
1483 name, GTK_ICON_SIZE_MENU);
1487 /* Update id widget */
1488 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ID)
1489 gtk_entry_set_text (GTK_ENTRY (information->widget_id), id ? id : "");
1491 gtk_label_set_label (GTK_LABEL (information->widget_id), id ? id : "");
1493 /* Update other widgets */
1494 if (information->contact)
1496 contact_widget_name_notify_cb (information);
1497 contact_widget_presence_notify_cb (information);
1498 contact_widget_avatar_notify_cb (information);
1500 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_FAVOURITE)
1502 FolksPersona *persona = empathy_contact_get_persona (
1503 information->contact);
1505 if (persona != NULL && FOLKS_IS_FAVOURITE_DETAILS (persona))
1507 gboolean is_favourite = folks_favourite_details_get_is_favourite (
1508 FOLKS_FAVOURITE_DETAILS (persona));
1509 contact_widget_favourites_changed_cb (information->manager,
1510 information->contact, is_favourite, information);
1514 gtk_widget_show (information->label_alias);
1515 gtk_widget_show (information->widget_alias);
1516 gtk_widget_show (information->hbox_presence);
1517 gtk_widget_show (information->widget_avatar);
1521 gtk_widget_hide (information->label_alias);
1522 gtk_widget_hide (information->widget_alias);
1523 gtk_widget_hide (information->hbox_presence);
1524 gtk_widget_hide (information->widget_avatar);
1529 contact_widget_set_contact (EmpathyContactWidget *information,
1530 EmpathyContact *contact)
1532 if (contact == information->contact)
1535 contact_widget_remove_contact (information);
1537 information->contact = g_object_ref (contact);
1539 /* set the selected account to be the account this contact came from */
1540 if (contact && EMPATHY_IS_ACCOUNT_CHOOSER (information->widget_account)) {
1541 empathy_account_chooser_set_account (
1542 EMPATHY_ACCOUNT_CHOOSER (information->widget_account),
1543 empathy_contact_get_account (contact));
1546 /* Update information for widgets */
1547 contact_widget_contact_update (information);
1548 contact_widget_groups_update (information);
1549 contact_widget_details_update (information);
1550 contact_widget_client_update (information);
1551 contact_widget_location_update (information);
1555 contact_widget_got_contact_cb (TpConnection *connection,
1556 EmpathyContact *contact,
1557 const GError *error,
1559 GObject *weak_object)
1561 EmpathyContactWidget *information = user_data;
1565 DEBUG ("Error: %s", error->message);
1569 contact_widget_set_contact (information, contact);
1573 contact_widget_change_contact (EmpathyContactWidget *information)
1575 TpConnection *connection;
1577 connection = empathy_account_chooser_get_connection (
1578 EMPATHY_ACCOUNT_CHOOSER (information->widget_account));
1582 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ID)
1586 id = gtk_entry_get_text (GTK_ENTRY (information->widget_id));
1587 if (!EMP_STR_EMPTY (id))
1589 empathy_tp_contact_factory_get_from_id (connection, id,
1590 contact_widget_got_contact_cb, information, NULL,
1591 G_OBJECT (information->vbox_contact_widget));
1596 empathy_tp_contact_factory_get_from_handle (connection,
1597 tp_connection_get_self_handle (connection),
1598 contact_widget_got_contact_cb, information, NULL,
1599 G_OBJECT (information->vbox_contact_widget));
1604 contact_widget_id_activate_timeout (EmpathyContactWidget *self)
1606 contact_widget_change_contact (self);
1611 contact_widget_id_changed_cb (GtkEntry *entry,
1612 EmpathyContactWidget *self)
1614 if (self->widget_id_timeout != 0)
1616 g_source_remove (self->widget_id_timeout);
1619 self->widget_id_timeout =
1620 g_timeout_add_seconds (ID_CHANGED_TIMEOUT,
1621 (GSourceFunc) contact_widget_id_activate_timeout, self);
1625 contact_widget_id_focus_out_cb (GtkWidget *widget,
1626 GdkEventFocus *event,
1627 EmpathyContactWidget *information)
1629 contact_widget_change_contact (information);
1634 favourite_toggled_cb (GtkToggleButton *button,
1635 EmpathyContactWidget *information)
1637 FolksPersona *persona = empathy_contact_get_persona (information->contact);
1639 if (persona != NULL && FOLKS_IS_FAVOURITE_DETAILS (persona))
1641 gboolean active = gtk_toggle_button_get_active (button);
1642 folks_favourite_details_set_is_favourite (
1643 FOLKS_FAVOURITE_DETAILS (persona), active);
1648 contact_widget_contact_setup (EmpathyContactWidget *information)
1650 information->label_status = gtk_label_new ("");
1651 gtk_label_set_line_wrap_mode (GTK_LABEL (information->label_status),
1652 PANGO_WRAP_WORD_CHAR);
1653 gtk_label_set_line_wrap (GTK_LABEL (information->label_status),
1655 gtk_misc_set_alignment (GTK_MISC (information->label_status), 0, 0.5);
1657 if (!(information->flags & EMPATHY_CONTACT_WIDGET_FOR_TOOLTIP))
1658 gtk_label_set_selectable (GTK_LABEL (information->label_status), TRUE);
1660 gtk_box_pack_start (GTK_BOX (information->hbox_presence),
1661 information->label_status, TRUE, TRUE, 0);
1662 gtk_widget_show (information->label_status);
1664 /* Setup account label/chooser */
1665 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ACCOUNT)
1667 information->widget_account = empathy_account_chooser_new ();
1669 g_signal_connect_swapped (information->widget_account, "changed",
1670 G_CALLBACK (contact_widget_change_contact),
1675 /* Pack the protocol icon with the account name in an hbox */
1676 information->widget_account = gtk_hbox_new (FALSE, 6);
1678 information->label_account = gtk_label_new (NULL);
1679 if (!(information->flags & EMPATHY_CONTACT_WIDGET_FOR_TOOLTIP)) {
1680 gtk_label_set_selectable (GTK_LABEL (information->label_account), TRUE);
1682 gtk_misc_set_alignment (GTK_MISC (information->label_account), 0, 0.5);
1683 gtk_widget_show (information->label_account);
1685 information->image_account = gtk_image_new ();
1686 gtk_widget_show (information->image_account);
1688 gtk_box_pack_start (GTK_BOX (information->widget_account),
1689 information->image_account, FALSE, FALSE, 0);
1690 gtk_box_pack_start (GTK_BOX (information->widget_account),
1691 information->label_account, FALSE, TRUE, 0);
1694 gtk_grid_attach (GTK_GRID (information->grid_contact),
1695 information->widget_account,
1698 gtk_widget_show (information->widget_account);
1700 /* Set up avatar chooser/display */
1701 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_AVATAR)
1703 information->widget_avatar = empathy_avatar_chooser_new ();
1704 g_signal_connect (information->widget_avatar, "changed",
1705 G_CALLBACK (contact_widget_avatar_changed_cb),
1707 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ACCOUNT)
1709 g_signal_connect (information->widget_account, "changed",
1710 G_CALLBACK (update_avatar_chooser_account_cb),
1711 information->widget_avatar);
1712 update_avatar_chooser_account_cb (
1713 EMPATHY_ACCOUNT_CHOOSER (information->widget_account),
1714 EMPATHY_AVATAR_CHOOSER (information->widget_avatar));
1719 information->widget_avatar = empathy_avatar_image_new ();
1721 g_signal_connect (information->widget_avatar, "popup-menu",
1722 G_CALLBACK (widget_avatar_popup_menu_cb), information);
1723 g_signal_connect (information->widget_avatar, "button-press-event",
1724 G_CALLBACK (widget_avatar_button_press_event_cb), information);
1727 gtk_box_pack_start (GTK_BOX (information->vbox_avatar),
1728 information->widget_avatar,
1731 gtk_widget_show (information->widget_avatar);
1733 /* Setup id label/entry */
1734 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ID)
1736 information->widget_id = gtk_entry_new ();
1737 g_signal_connect (information->widget_id, "focus-out-event",
1738 G_CALLBACK (contact_widget_id_focus_out_cb),
1740 g_signal_connect (information->widget_id, "changed",
1741 G_CALLBACK (contact_widget_id_changed_cb),
1746 information->widget_id = gtk_label_new (NULL);
1747 if (!(information->flags & EMPATHY_CONTACT_WIDGET_FOR_TOOLTIP)) {
1748 gtk_label_set_selectable (GTK_LABEL (information->widget_id), TRUE);
1750 gtk_misc_set_alignment (GTK_MISC (information->widget_id), 0, 0.5);
1753 gtk_grid_attach (GTK_GRID (information->grid_contact), information->widget_id,
1756 gtk_widget_show (information->widget_id);
1758 /* Setup alias label/entry */
1759 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ALIAS)
1761 information->widget_alias = gtk_entry_new ();
1763 if (!(information->flags & EMPATHY_CONTACT_WIDGET_NO_SET_ALIAS))
1764 g_signal_connect (information->widget_alias, "focus-out-event",
1765 G_CALLBACK (contact_widget_entry_alias_focus_event_cb),
1768 /* Make return activate the window default (the Close button) */
1769 gtk_entry_set_activates_default (GTK_ENTRY (information->widget_alias),
1774 information->widget_alias = gtk_label_new (NULL);
1775 if (!(information->flags & EMPATHY_CONTACT_WIDGET_FOR_TOOLTIP)) {
1776 gtk_label_set_selectable (GTK_LABEL (information->widget_alias), TRUE);
1778 gtk_misc_set_alignment (GTK_MISC (information->widget_alias), 0, 0.5);
1781 gtk_grid_attach (GTK_GRID (information->grid_contact),
1782 information->widget_alias, 1, 2, 1, 1);
1784 if (information->flags & EMPATHY_CONTACT_WIDGET_FOR_TOOLTIP) {
1785 gtk_label_set_selectable (GTK_LABEL (information->label_status), FALSE);
1787 gtk_widget_show (information->widget_alias);
1790 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_FAVOURITE)
1792 information->favourite_checkbox = gtk_check_button_new_with_label (
1795 g_signal_connect (information->favourite_checkbox, "toggled",
1796 G_CALLBACK (favourite_toggled_cb), information);
1798 gtk_grid_attach (GTK_GRID (information->grid_contact),
1799 information->favourite_checkbox, 0, 3, 1, 1);
1801 information->fav_sig_id = g_signal_connect (information->manager,
1802 "favourites-changed",
1803 G_CALLBACK (contact_widget_favourites_changed_cb), information);
1805 gtk_widget_show (information->favourite_checkbox);
1810 contact_widget_destroy_cb (GtkWidget *widget,
1811 EmpathyContactWidget *information)
1813 contact_widget_remove_contact (information);
1815 if (information->widget_id_timeout != 0)
1817 g_source_remove (information->widget_id_timeout);
1820 if (information->fav_sig_id != 0)
1821 g_signal_handler_disconnect (information->manager, information->fav_sig_id);
1823 g_object_unref (information->manager);
1825 g_slice_free (EmpathyContactWidget, information);
1829 * empathy_contact_widget_new:
1830 * @contact: an #EmpathyContact
1831 * @flags: #EmpathyContactWidgetFlags for the new contact widget
1833 * Creates a new #EmpathyContactWidget.
1835 * Return value: a new #EmpathyContactWidget
1838 empathy_contact_widget_new (EmpathyContact *contact,
1839 EmpathyContactWidgetFlags flags)
1841 EmpathyContactWidget *information;
1845 g_return_val_if_fail (contact == NULL || EMPATHY_IS_CONTACT (contact), NULL);
1847 information = g_slice_new0 (EmpathyContactWidget);
1848 information->flags = flags;
1850 filename = empathy_file_lookup ("empathy-contact-widget.ui",
1852 gui = empathy_builder_get_file (filename,
1853 "vbox_contact_widget", &information->vbox_contact_widget,
1854 "hbox_contact", &information->hbox_contact,
1855 "hbox_presence", &information->hbox_presence,
1856 "label_alias", &information->label_alias,
1857 "image_state", &information->image_state,
1858 "grid_contact", &information->grid_contact,
1859 "vbox_avatar", &information->vbox_avatar,
1860 "vbox_location", &information->vbox_location,
1861 "subvbox_location", &information->subvbox_location,
1862 "label_location", &information->label_location,
1863 #ifdef HAVE_LIBCHAMPLAIN
1864 "viewport_map", &information->viewport_map,
1866 "groups_widget", &information->groups_widget,
1867 "vbox_details", &information->vbox_details,
1868 "grid_details", &information->grid_details,
1869 "hbox_details_requested", &information->hbox_details_requested,
1870 "vbox_client", &information->vbox_client,
1871 "grid_client", &information->grid_client,
1872 "hbox_client_requested", &information->hbox_client_requested,
1876 empathy_builder_connect (gui, information,
1877 "vbox_contact_widget", "destroy", contact_widget_destroy_cb,
1879 information->grid_location = NULL;
1881 g_object_set_data (G_OBJECT (information->vbox_contact_widget),
1882 "EmpathyContactWidget",
1885 information->manager = empathy_contact_manager_dup_singleton ();
1887 /* Create widgets */
1888 contact_widget_contact_setup (information);
1889 contact_widget_details_setup (information);
1890 contact_widget_client_setup (information);
1892 if (contact != NULL)
1893 contact_widget_set_contact (information, contact);
1894 else if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ACCOUNT ||
1895 information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ID)
1896 contact_widget_change_contact (information);
1898 return empathy_builder_unref_and_keep_widget (gui,
1899 information->vbox_contact_widget);
1903 * empathy_contact_widget_get_contact:
1904 * @widget: an #EmpathyContactWidget
1906 * Get the #EmpathyContact related with the #EmpathyContactWidget @widget.
1908 * Returns: the #EmpathyContact associated with @widget
1911 empathy_contact_widget_get_contact (GtkWidget *widget)
1913 EmpathyContactWidget *information;
1915 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
1917 information = g_object_get_data (G_OBJECT (widget), "EmpathyContactWidget");
1921 return information->contact;
1925 empathy_contact_widget_get_alias (GtkWidget *widget)
1927 EmpathyContactWidget *information;
1929 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
1931 information = g_object_get_data (G_OBJECT (widget), "EmpathyContactWidget");
1935 return gtk_entry_get_text (GTK_ENTRY (information->widget_alias));
1939 * empathy_contact_widget_set_contact:
1940 * @widget: an #EmpathyContactWidget
1941 * @contact: a different #EmpathyContact
1943 * Change the #EmpathyContact related with the #EmpathyContactWidget @widget.
1946 empathy_contact_widget_set_contact (GtkWidget *widget,
1947 EmpathyContact *contact)
1949 EmpathyContactWidget *information;
1951 g_return_if_fail (GTK_IS_WIDGET (widget));
1952 g_return_if_fail (EMPATHY_IS_CONTACT (contact));
1954 information = g_object_get_data (G_OBJECT (widget), "EmpathyContactWidget");
1958 contact_widget_set_contact (information, contact);
1962 * empathy_contact_widget_set_account_filter:
1963 * @widget: an #EmpathyContactWidget
1964 * @filter: a #EmpathyAccountChooserFilterFunc
1965 * @user_data: user data to pass to @filter, or %NULL
1967 * Set a filter on the #EmpathyAccountChooser included in the
1968 * #EmpathyContactWidget.
1971 empathy_contact_widget_set_account_filter (
1973 EmpathyAccountChooserFilterFunc filter,
1976 EmpathyContactWidget *information;
1977 EmpathyAccountChooser *chooser;
1979 g_return_if_fail (GTK_IS_WIDGET (widget));
1981 information = g_object_get_data (G_OBJECT (widget), "EmpathyContactWidget");
1985 chooser = EMPATHY_ACCOUNT_CHOOSER (information->widget_account);
1987 empathy_account_chooser_set_filter (chooser, filter, user_data);