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-time.h>
44 #include <libempathy/empathy-utils.h>
46 #include "empathy-contact-widget.h"
47 #include "empathy-account-chooser.h"
48 #include "empathy-avatar-chooser.h"
49 #include "empathy-avatar-image.h"
50 #include "empathy-groups-widget.h"
51 #include "empathy-ui-utils.h"
52 #include "empathy-string-parser.h"
54 #define DEBUG_FLAG EMPATHY_DEBUG_CONTACT
55 #include <libempathy/empathy-debug.h>
58 * SECTION:empathy-contact-widget
59 * @title:EmpathyContactWidget
60 * @short_description: A widget used to display and edit details about a contact
61 * @include: libempathy-empathy-contact-widget.h
63 * #EmpathyContactWidget is a widget which displays appropriate widgets
64 * with details about a contact, also allowing changing these details,
69 * EmpathyContactWidget:
70 * @parent: parent object
72 * Widget which displays appropriate widgets with details about a contact,
73 * also allowing changing these details, if desired.
76 /* Delay before updating the widget when the id entry changed (seconds) */
77 #define ID_CHANGED_TIMEOUT 1
79 #define DATA_FIELD "contact-info-field"
83 EmpathyContactManager *manager;
84 EmpathyContact *contact;
85 EmpathyContactWidgetFlags flags;
86 guint widget_id_timeout;
89 GtkWidget *vbox_contact_widget;
92 GtkWidget *hbox_contact;
93 GtkWidget *widget_avatar;
94 GtkWidget *widget_account;
95 GtkWidget *image_account;
96 GtkWidget *label_account;
98 GtkWidget *widget_alias;
99 GtkWidget *label_alias;
100 GtkWidget *hbox_presence;
101 GtkWidget *image_state;
102 GtkWidget *label_status;
103 GtkWidget *table_contact;
104 GtkWidget *vbox_avatar;
105 GtkWidget *favourite_checkbox;
108 GtkWidget *vbox_location;
109 GtkWidget *subvbox_location;
110 GtkWidget *table_location;
111 GtkWidget *label_location;
112 #ifdef HAVE_LIBCHAMPLAIN
113 GtkWidget *viewport_map;
114 GtkWidget *map_view_embed;
115 ChamplainView *map_view;
119 GtkWidget *groups_widget;
122 GtkWidget *vbox_details;
123 GtkWidget *table_details;
124 GtkWidget *hbox_details_requested;
125 GtkWidget *spinner_details;
126 GList *details_to_set;
127 GCancellable *details_cancellable;
128 gboolean details_changed;
131 GtkWidget *vbox_client;
132 GtkWidget *table_client;
133 GtkWidget *hbox_client_requested;
134 } EmpathyContactWidget;
138 EmpathyContactWidget *information;
141 GtkTreeIter found_iter;
153 field_value_is_empty (TpContactInfoField *field)
157 if (field->field_value == NULL)
160 /* Field is empty if all its values are empty */
161 for (i = 0; field->field_value[i] != NULL; i++)
163 if (!tp_str_empty (field->field_value[i]))
171 set_contact_info_cb (GObject *source,
172 GAsyncResult *result,
175 GError *error = NULL;
177 if (!tp_connection_set_contact_info_finish (TP_CONNECTION (source), result,
180 DEBUG ("SetContactInfo() failed: %s", error->message);
181 g_error_free (error);
185 DEBUG ("SetContactInfo() succeeded");
189 contact_widget_save (EmpathyContactWidget *information)
191 TpConnection *connection;
194 connection = empathy_contact_get_connection (information->contact);
196 /* Remove empty fields */
197 for (l = information->details_to_set; l != NULL; l = next)
199 TpContactInfoField *field = l->data;
202 if (field_value_is_empty (field))
204 DEBUG ("Drop empty field: %s", field->field_name);
205 tp_contact_info_field_free (field);
206 information->details_to_set =
207 g_list_delete_link (information->details_to_set, l);
211 if (information->details_to_set != NULL)
213 if (information->details_changed)
215 tp_connection_set_contact_info_async (connection,
216 information->details_to_set, set_contact_info_cb, NULL);
219 tp_contact_info_list_free (information->details_to_set);
220 information->details_to_set = NULL;
225 contact_widget_details_setup (EmpathyContactWidget *information)
227 gtk_widget_hide (information->vbox_details);
229 information->spinner_details = gtk_spinner_new ();
230 gtk_box_pack_end (GTK_BOX (information->hbox_details_requested),
231 information->spinner_details, TRUE, TRUE, 0);
232 gtk_widget_show (information->spinner_details);
236 contact_widget_details_changed_cb (GtkEntry *entry,
237 EmpathyContactWidget *self)
239 const gchar *strv[] = { NULL, NULL };
240 TpContactInfoField *field;
242 self->details_changed = TRUE;
244 field = g_object_get_data ((GObject *) entry, DATA_FIELD);
245 g_assert (field != NULL);
247 strv[0] = gtk_entry_get_text (entry);
249 if (field->field_value != NULL)
250 g_strfreev (field->field_value);
251 field->field_value = g_strdupv ((GStrv) strv);
255 contact_widget_bday_changed_cb (GtkCalendar *calendar,
256 EmpathyContactWidget *self)
258 guint year, month, day;
261 const gchar *strv[] = { NULL, NULL };
262 TpContactInfoField *field;
264 self->details_changed = TRUE;
266 field = g_object_get_data ((GObject *) calendar, DATA_FIELD);
267 g_assert (field != NULL);
269 gtk_calendar_get_date (calendar, &year, &month, &day);
270 date = g_date_new_dmy (day, month+1, year);
272 gtk_calendar_clear_marks (calendar);
273 gtk_calendar_mark_day (calendar, g_date_get_day (date));
275 g_date_strftime (tmp, sizeof (tmp), EMPATHY_DATE_FORMAT_DISPLAY_SHORT, date);
277 if (field->field_value != NULL)
278 g_strfreev (field->field_value);
279 field->field_value = g_strdupv ((GStrv) strv);
284 static void contact_widget_details_notify_cb (EmpathyContactWidget *information);
288 const gchar *field_name;
293 static InfoFieldData info_field_datas[] =
295 { "fn", N_("Full name:"), FALSE },
296 { "tel", N_("Phone number:"), FALSE },
297 { "email", N_("E-mail address:"), TRUE },
298 { "url", N_("Website:"), TRUE },
299 { "bday", N_("Birthday:"), FALSE },
303 static InfoFieldData *
304 find_info_field_data (const gchar *field_name)
308 for (i = 0; info_field_datas[i].field_name != NULL; i++)
310 if (!tp_strdiff (info_field_datas[i].field_name, field_name))
311 return info_field_datas + i;
317 contact_info_field_name_cmp (const gchar *name1,
322 if (!tp_strdiff (name1, name2))
325 /* We use the order of info_field_datas */
326 for (i = 0; info_field_datas[i].field_name != NULL; i++)
328 if (!tp_strdiff (info_field_datas[i].field_name, name1))
330 if (!tp_strdiff (info_field_datas[i].field_name, name2))
334 return g_strcmp0 (name1, name2);
338 contact_info_field_cmp (TpContactInfoField *field1,
339 TpContactInfoField *field2)
341 return contact_info_field_name_cmp (field1->field_name, field2->field_name);
345 field_name_in_field_list (GList *list,
350 for (l = list; l != NULL; l = g_list_next (l))
352 TpContactInfoField *field = l->data;
354 if (!tp_strdiff (field->field_name, name))
361 static TpContactInfoFieldSpec *
362 get_spec_from_list (GList *list,
367 for (l = list; l != NULL; l = g_list_next (l))
369 TpContactInfoFieldSpec *spec = l->data;
371 if (!tp_strdiff (spec->name, name))
379 contact_widget_details_update_edit (EmpathyContactWidget *information)
382 TpConnection *connection;
388 g_assert (information->details_to_set == NULL);
390 information->details_changed = FALSE;
392 contact = empathy_contact_get_tp_contact (information->contact);
393 connection = tp_contact_get_connection (contact);
395 info = tp_contact_get_contact_info (contact);
397 specs = tp_connection_get_contact_info_supported_fields (connection);
399 /* Look at the fields set in our vCard */
400 for (l = info; l != NULL; l = l->next)
402 TpContactInfoField *field = l->data;
404 /* make a copy for the details_to_set list */
405 field = tp_contact_info_field_copy (field);
406 DEBUG ("Field %s is in our vCard", field->field_name);
408 information->details_to_set = g_list_prepend (information->details_to_set,
412 /* Add fields which are supported but not in the vCard */
413 for (i = 0; info_field_datas[i].field_name != NULL; i++)
415 TpContactInfoFieldSpec *spec;
416 TpContactInfoField *field;
418 /* Check if the field was in the vCard */
419 if (field_name_in_field_list (information->details_to_set,
420 info_field_datas[i].field_name))
423 /* Check if the CM supports the field */
424 spec = get_spec_from_list (specs, info_field_datas[i].field_name);
428 /* add an empty field so user can set a value */
429 field = tp_contact_info_field_new (spec->name, spec->parameters, NULL);
431 information->details_to_set = g_list_prepend (information->details_to_set,
435 /* Add widgets for supported fields */
436 information->details_to_set = g_list_sort (information->details_to_set,
437 (GCompareFunc) contact_info_field_cmp);
439 for (l = information->details_to_set; l != NULL; l= g_list_next (l))
441 TpContactInfoField *field = l->data;
442 InfoFieldData *field_data;
444 TpContactInfoFieldSpec *spec;
446 field_data = find_info_field_data (field->field_name);
447 if (field_data == NULL)
449 /* Empathy doesn't display this field so we can't change it.
450 * But we put it in the details_to_set list so it won't be erased
451 * when calling SetContactInfo (bgo #630427) */
452 DEBUG ("Unhandled ContactInfo field spec: %s", field->field_name);
456 spec = get_spec_from_list (specs, field->field_name);
457 /* We shouldn't have added the field to details_to_set if it's not
458 * supported by the CM */
459 g_assert (spec != NULL);
461 if (spec->flags & TP_CONTACT_INFO_FIELD_FLAG_OVERWRITTEN_BY_NICKNAME)
463 DEBUG ("Ignoring field '%s' due it to having the "
464 "Overwritten_By_Nickname flag", field->field_name);
469 w = gtk_label_new (_(field_data->title));
470 gtk_table_attach (GTK_TABLE (information->table_details),
471 w, 0, 1, n_rows, n_rows + 1, GTK_FILL, 0, 0, 0);
472 gtk_misc_set_alignment (GTK_MISC (w), 0, 0.5);
476 if (!tp_strdiff (field->field_name, "bday"))
478 w = gtk_calendar_new ();
479 if (field->field_value[0])
483 g_date_set_parse (&date, field->field_value[0]);
484 if (g_date_valid (&date))
486 gtk_calendar_select_day (GTK_CALENDAR (w),
487 g_date_get_day (&date));
488 gtk_calendar_select_month (GTK_CALENDAR (w),
489 g_date_get_month (&date) - 1, g_date_get_year (&date));
490 gtk_calendar_mark_day (GTK_CALENDAR (w),
491 g_date_get_day (&date));
494 gtk_table_attach_defaults (GTK_TABLE (information->table_details),
495 w, 1, 2, n_rows, n_rows + 1);
498 g_object_set_data ((GObject *) w, DATA_FIELD, field);
500 g_signal_connect (w, "day-selected-double-click",
501 G_CALLBACK (contact_widget_bday_changed_cb), information);
502 g_signal_connect (w, "month-changed",
503 G_CALLBACK (contact_widget_bday_changed_cb), information);
507 w = gtk_entry_new ();
508 gtk_entry_set_text (GTK_ENTRY (w),
509 field->field_value[0] ? field->field_value[0] : "");
510 gtk_table_attach_defaults (GTK_TABLE (information->table_details),
511 w, 1, 2, n_rows, n_rows + 1);
514 g_object_set_data ((GObject *) w, DATA_FIELD, field);
516 g_signal_connect (w, "changed",
517 G_CALLBACK (contact_widget_details_changed_cb), information);
530 channel_name_activated_cb (
533 EmpathyContactWidget *information)
535 TpAccount *account = empathy_contact_get_account (information->contact);
537 empathy_join_muc (account, uri, empathy_get_current_action_time ());
543 EmpathyContactWidget *information,
548 GString *label_markup = g_string_new ("");
551 w = gtk_label_new (_("Channels:"));
552 gtk_table_attach (GTK_TABLE (information->table_details),
553 w, 0, 1, row, row + 1, GTK_FILL, 0, 0, 0);
554 gtk_misc_set_alignment (GTK_MISC (w), 0, 0.5);
557 for (i = 0; i < channels->len; i++)
559 const gchar *channel_name = g_ptr_array_index (channels, i);
560 /* We abuse the URI of the link to hold the channel name. It seems to
561 * be okay to just use it essentially verbatim, rather than trying to
562 * ensure it's actually a valid URI. g_string_append_uri_escaped()
563 * escapes way more than we actually need to; so we're just using
564 * g_markup_escape_text directly.
566 gchar *escaped = g_markup_escape_text (channel_name, -1);
569 g_string_append (label_markup, ", ");
571 g_string_append_printf (label_markup, "<a href='%s'>%s</a>",
572 escaped, channel_name);
576 w = gtk_label_new (NULL);
577 gtk_label_set_markup (GTK_LABEL (w), label_markup->str);
578 gtk_label_set_line_wrap (GTK_LABEL (w), TRUE);
579 g_signal_connect (w, "activate-link",
580 (GCallback) channel_name_activated_cb, information);
581 gtk_table_attach_defaults (GTK_TABLE (information->table_details),
582 w, 1, 2, row, row + 1);
583 gtk_misc_set_alignment (GTK_MISC (w), 0, 0.5);
586 g_string_free (label_markup, TRUE);
590 contact_widget_details_update_show (EmpathyContactWidget *information)
595 GPtrArray *channels = g_ptr_array_new ();
597 contact = empathy_contact_get_tp_contact (information->contact);
598 info = tp_contact_get_contact_info (contact);
599 info = g_list_sort (info, (GCompareFunc) contact_info_field_cmp);
600 for (l = info; l != NULL; l = l->next)
602 TpContactInfoField *field = l->data;
603 InfoFieldData *field_data;
607 if (field->field_value == NULL || field->field_value[0] == NULL)
610 value = field->field_value[0];
612 if (!tp_strdiff (field->field_name, "x-irc-channel"))
614 g_ptr_array_add (channels, (gpointer) value);
618 field_data = find_info_field_data (field->field_name);
619 if (field_data == NULL)
621 DEBUG ("Unhandled ContactInfo field: %s", field->field_name);
626 w = gtk_label_new (_(field_data->title));
627 gtk_table_attach (GTK_TABLE (information->table_details),
628 w, 0, 1, n_rows, n_rows + 1, GTK_FILL, 0, 0, 0);
629 gtk_misc_set_alignment (GTK_MISC (w), 0, 0.5);
633 w = gtk_label_new (value);
634 if (field_data->linkify)
638 markup = empathy_add_link_markup (value);
639 gtk_label_set_markup (GTK_LABEL (w), markup);
643 if ((information->flags & EMPATHY_CONTACT_WIDGET_FOR_TOOLTIP) == 0)
644 gtk_label_set_selectable (GTK_LABEL (w), TRUE);
646 gtk_table_attach_defaults (GTK_TABLE (information->table_details),
647 w, 1, 2, n_rows, n_rows + 1);
648 gtk_misc_set_alignment (GTK_MISC (w), 0, 0.5);
655 if (channels->len > 0)
657 add_channel_list (information, channels, n_rows);
661 g_ptr_array_unref (channels);
666 contact_widget_details_notify_cb (EmpathyContactWidget *information)
670 gtk_container_foreach (GTK_CONTAINER (information->table_details),
671 (GtkCallback) gtk_widget_destroy, NULL);
673 if ((information->flags & EMPATHY_CONTACT_WIDGET_EDIT_DETAILS) != 0)
674 n_rows = contact_widget_details_update_edit (information);
676 n_rows = contact_widget_details_update_show (information);
680 gtk_widget_show (information->vbox_details);
681 gtk_widget_show (information->table_details);
685 gtk_widget_hide (information->vbox_details);
688 gtk_widget_hide (information->hbox_details_requested);
689 gtk_spinner_stop (GTK_SPINNER (information->spinner_details));
693 contact_widget_details_request_cb (GObject *object,
697 TpContact *contact = TP_CONTACT (object);
698 EmpathyContactWidget *information = user_data;
699 GError *error = NULL;
701 if (!tp_contact_request_contact_info_finish (contact, res, &error))
703 /* If the request got cancelled it could mean the contact widget is
704 * destroyed, so we should not dereference information */
705 if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
707 g_clear_error (&error);
711 gtk_widget_hide (information->vbox_details);
712 g_clear_error (&error);
716 contact_widget_details_notify_cb (information);
719 /* If we are going to edit ContactInfo, we don't want live updates */
720 if ((information->flags & EMPATHY_CONTACT_WIDGET_EDIT_DETAILS) == 0)
722 g_signal_connect_swapped (contact, "notify::contact-info",
723 G_CALLBACK (contact_widget_details_notify_cb), information);
726 tp_clear_object (&information->details_cancellable);
730 contact_widget_details_feature_prepared_cb (GObject *object,
734 TpConnection *connection = TP_CONNECTION (object);
735 EmpathyContactWidget *information = user_data;
737 TpContactInfoFlags flags;
739 if (!tp_proxy_prepare_finish (connection, res, NULL))
741 gtk_widget_hide (information->vbox_details);
745 /* If we want to edit info, but connection does not support that, stop */
746 flags = tp_connection_get_contact_info_flags (connection);
747 if ((flags & TP_CONTACT_INFO_FLAG_CAN_SET) == 0 &&
748 (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_DETAILS) != 0)
750 gtk_widget_hide (information->vbox_details);
754 /* Request the contact's info */
755 gtk_widget_show (information->vbox_details);
756 gtk_widget_show (information->hbox_details_requested);
757 gtk_widget_hide (information->table_details);
758 gtk_spinner_start (GTK_SPINNER (information->spinner_details));
760 contact = empathy_contact_get_tp_contact (information->contact);
761 g_assert (information->details_cancellable == NULL);
762 information->details_cancellable = g_cancellable_new ();
763 tp_contact_request_contact_info_async (contact,
764 information->details_cancellable, contact_widget_details_request_cb,
769 contact_widget_details_update (EmpathyContactWidget *information)
771 TpContact *tp_contact = NULL;
773 if ((information->flags & EMPATHY_CONTACT_WIDGET_SHOW_DETAILS) == 0 &&
774 (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_DETAILS) == 0)
777 gtk_widget_hide (information->vbox_details);
779 if (information->contact != NULL)
780 tp_contact = empathy_contact_get_tp_contact (information->contact);
782 if (tp_contact != NULL)
784 GQuark features[] = { TP_CONNECTION_FEATURE_CONTACT_INFO, 0 };
785 TpConnection *connection;
787 /* First, make sure the CONTACT_INFO feature is ready on the connection */
788 connection = tp_contact_get_connection (tp_contact);
789 tp_proxy_prepare_async (connection, features,
790 contact_widget_details_feature_prepared_cb, information);
795 contact_widget_client_update (EmpathyContactWidget *information)
797 /* FIXME: Needs new telepathy spec */
801 contact_widget_client_setup (EmpathyContactWidget *information)
803 /* FIXME: Needs new telepathy spec */
804 gtk_widget_hide (information->vbox_client);
808 contact_widget_groups_update (EmpathyContactWidget *information)
810 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_GROUPS &&
811 information->contact != NULL)
813 FolksPersona *persona =
814 empathy_contact_get_persona (information->contact);
816 if (FOLKS_IS_GROUP_DETAILS (persona))
818 empathy_groups_widget_set_group_details (
819 EMPATHY_GROUPS_WIDGET (information->groups_widget),
820 FOLKS_GROUP_DETAILS (persona));
821 gtk_widget_show (information->groups_widget);
827 /* In case of failure */
828 gtk_widget_hide (information->groups_widget);
831 /* Converts the Location's GHashTable's key to a user readable string */
833 location_key_to_label (const gchar *key)
835 if (tp_strdiff (key, EMPATHY_LOCATION_COUNTRY_CODE) == FALSE)
836 return _("Country ISO Code:");
837 else if (tp_strdiff (key, EMPATHY_LOCATION_COUNTRY) == FALSE)
838 return _("Country:");
839 else if (tp_strdiff (key, EMPATHY_LOCATION_REGION) == FALSE)
841 else if (tp_strdiff (key, EMPATHY_LOCATION_LOCALITY) == FALSE)
843 else if (tp_strdiff (key, EMPATHY_LOCATION_AREA) == FALSE)
845 else if (tp_strdiff (key, EMPATHY_LOCATION_POSTAL_CODE) == FALSE)
846 return _("Postal Code:");
847 else if (tp_strdiff (key, EMPATHY_LOCATION_STREET) == FALSE)
849 else if (tp_strdiff (key, EMPATHY_LOCATION_BUILDING) == FALSE)
850 return _("Building:");
851 else if (tp_strdiff (key, EMPATHY_LOCATION_FLOOR) == FALSE)
853 else if (tp_strdiff (key, EMPATHY_LOCATION_ROOM) == FALSE)
855 else if (tp_strdiff (key, EMPATHY_LOCATION_TEXT) == FALSE)
857 else if (tp_strdiff (key, EMPATHY_LOCATION_DESCRIPTION) == FALSE)
858 return _("Description:");
859 else if (tp_strdiff (key, EMPATHY_LOCATION_URI) == FALSE)
861 else if (tp_strdiff (key, EMPATHY_LOCATION_ACCURACY_LEVEL) == FALSE)
862 return _("Accuracy Level:");
863 else if (tp_strdiff (key, EMPATHY_LOCATION_ERROR) == FALSE)
865 else if (tp_strdiff (key, EMPATHY_LOCATION_VERTICAL_ERROR_M) == FALSE)
866 return _("Vertical Error (meters):");
867 else if (tp_strdiff (key, EMPATHY_LOCATION_HORIZONTAL_ERROR_M) == FALSE)
868 return _("Horizontal Error (meters):");
869 else if (tp_strdiff (key, EMPATHY_LOCATION_SPEED) == FALSE)
871 else if (tp_strdiff (key, EMPATHY_LOCATION_BEARING) == FALSE)
872 return _("Bearing:");
873 else if (tp_strdiff (key, EMPATHY_LOCATION_CLIMB) == FALSE)
874 return _("Climb Speed:");
875 else if (tp_strdiff (key, EMPATHY_LOCATION_TIMESTAMP) == FALSE)
876 return _("Last Updated on:");
877 else if (tp_strdiff (key, EMPATHY_LOCATION_LON) == FALSE)
878 return _("Longitude:");
879 else if (tp_strdiff (key, EMPATHY_LOCATION_LAT) == FALSE)
880 return _("Latitude:");
881 else if (tp_strdiff (key, EMPATHY_LOCATION_ALT) == FALSE)
882 return _("Altitude:");
885 DEBUG ("Unexpected Location key: %s", key);
891 contact_widget_location_update (EmpathyContactWidget *information)
893 GHashTable *location;
895 #ifdef HAVE_LIBCHAMPLAIN
896 gdouble lat = 0.0, lon = 0.0;
897 gboolean has_position = TRUE;
901 static const gchar* ordered_geolocation_keys[] = {
902 EMPATHY_LOCATION_TEXT,
903 EMPATHY_LOCATION_URI,
904 EMPATHY_LOCATION_DESCRIPTION,
905 EMPATHY_LOCATION_BUILDING,
906 EMPATHY_LOCATION_FLOOR,
907 EMPATHY_LOCATION_ROOM,
908 EMPATHY_LOCATION_STREET,
909 EMPATHY_LOCATION_AREA,
910 EMPATHY_LOCATION_LOCALITY,
911 EMPATHY_LOCATION_REGION,
912 EMPATHY_LOCATION_COUNTRY,
917 gboolean display_map = FALSE;
919 if (!(information->flags & EMPATHY_CONTACT_WIDGET_SHOW_LOCATION))
921 gtk_widget_hide (information->vbox_location);
925 location = empathy_contact_get_location (information->contact);
926 if (location == NULL || g_hash_table_size (location) == 0)
928 gtk_widget_hide (information->vbox_location);
932 value = g_hash_table_lookup (location, EMPATHY_LOCATION_TIMESTAMP);
935 gchar *loc = g_strdup_printf ("<b>%s</b>", _("Location"));
936 gtk_label_set_markup (GTK_LABEL (information->label_location), loc);
946 stamp = g_value_get_int64 (value);
948 user_date = empathy_time_to_string_relative (stamp);
950 tmp = g_strdup_printf ("<b>%s</b>", _("Location"));
951 /* translators: format is "Location, $date" */
952 text = g_strdup_printf (_("%s, %s"), tmp, user_date);
954 gtk_label_set_markup (GTK_LABEL (information->label_location), text);
960 /* Prepare the location information table */
961 if (information->table_location != NULL)
963 gtk_widget_destroy (information->table_location);
966 information->table_location = gtk_table_new (1, 2, FALSE);
967 gtk_box_pack_start (GTK_BOX (information->subvbox_location),
968 information->table_location, FALSE, FALSE, 5);
971 for (i = 0; (skey = ordered_geolocation_keys[i]); i++)
973 const gchar* user_label;
977 gvalue = g_hash_table_lookup (location, (gpointer) skey);
981 user_label = location_key_to_label (skey);
983 label = gtk_label_new (user_label);
984 gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
985 gtk_table_attach (GTK_TABLE (information->table_location),
986 label, 0, 1, row, row + 1, GTK_FILL, GTK_FILL, 10, 0);
987 gtk_widget_show (label);
989 if (G_VALUE_TYPE (gvalue) == G_TYPE_DOUBLE)
992 dvalue = g_value_get_double (gvalue);
993 svalue = g_strdup_printf ("%f", dvalue);
995 else if (G_VALUE_TYPE (gvalue) == G_TYPE_STRING)
997 svalue = g_value_dup_string (gvalue);
999 else if (G_VALUE_TYPE (gvalue) == G_TYPE_INT64)
1003 time_ = g_value_get_int64 (value);
1004 svalue = empathy_time_to_string_utc (time_, _("%B %e, %Y at %R UTC"));
1009 label = gtk_label_new (svalue);
1010 gtk_table_attach_defaults (GTK_TABLE (information->table_location),
1011 label, 1, 2, row, row + 1);
1012 gtk_misc_set_alignment (GTK_MISC (label), 0, 0);
1013 gtk_widget_show (label);
1015 if (!(information->flags & EMPATHY_CONTACT_WIDGET_FOR_TOOLTIP))
1016 gtk_label_set_selectable (GTK_LABEL (label), TRUE);
1023 #ifdef HAVE_LIBCHAMPLAIN
1025 !(information->flags & EMPATHY_CONTACT_WIDGET_FOR_TOOLTIP))
1027 /* Cannot be displayed in tooltips until Clutter-Gtk can deal with such
1035 /* We can display some fields */
1036 gtk_widget_show (information->table_location);
1038 else if (!display_map)
1040 /* Can't display either fields or map */
1041 gtk_widget_hide (information->vbox_location);
1045 #ifdef HAVE_LIBCHAMPLAIN
1048 ClutterActor *marker;
1049 ChamplainMarkerLayer *layer;
1051 information->map_view_embed = gtk_champlain_embed_new ();
1052 information->map_view = gtk_champlain_embed_get_view (
1053 GTK_CHAMPLAIN_EMBED (information->map_view_embed));
1055 gtk_container_add (GTK_CONTAINER (information->viewport_map),
1056 information->map_view_embed);
1057 g_object_set (G_OBJECT (information->map_view),
1058 "kinetic-mode", TRUE,
1062 layer = champlain_marker_layer_new ();
1063 champlain_view_add_layer (information->map_view, CHAMPLAIN_LAYER (layer));
1065 marker = champlain_label_new_with_text (
1066 empathy_contact_get_alias (information->contact), NULL, NULL, NULL);
1067 champlain_location_set_location (CHAMPLAIN_LOCATION (marker), lat, lon);
1068 champlain_marker_layer_add_marker (layer, CHAMPLAIN_MARKER (marker));
1070 champlain_view_center_on (information->map_view, lat, lon);
1071 gtk_widget_show_all (information->viewport_map);
1075 gtk_widget_show (information->vbox_location);
1079 save_avatar_menu_activate_cb (GtkWidget *widget,
1080 EmpathyContactWidget *information)
1083 EmpathyAvatar *avatar;
1084 gchar *ext = NULL, *filename;
1086 dialog = gtk_file_chooser_dialog_new (_("Save Avatar"),
1088 GTK_FILE_CHOOSER_ACTION_SAVE,
1089 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
1090 GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT,
1093 gtk_file_chooser_set_do_overwrite_confirmation (GTK_FILE_CHOOSER (dialog),
1096 /* look for the avatar extension */
1097 avatar = empathy_contact_get_avatar (information->contact);
1098 if (avatar->format != NULL)
1102 splitted = g_strsplit (avatar->format, "/", 2);
1103 if (splitted[0] != NULL && splitted[1] != NULL)
1104 ext = g_strdup (splitted[1]);
1106 g_strfreev (splitted);
1110 /* Avatar was loaded from the cache so was converted to PNG */
1111 ext = g_strdup ("png");
1118 id = tp_escape_as_identifier (empathy_contact_get_id (
1119 information->contact));
1121 filename = g_strdup_printf ("%s.%s", id, ext);
1122 gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (dialog), filename);
1129 if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT)
1131 GError *error = NULL;
1133 filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
1135 if (!empathy_avatar_save_to_file (avatar, filename, &error))
1138 GtkWidget *error_dialog;
1140 error_dialog = gtk_message_dialog_new (NULL, 0,
1141 GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE,
1142 _("Unable to save avatar"));
1144 gtk_message_dialog_format_secondary_text (
1145 GTK_MESSAGE_DIALOG (error_dialog), "%s", error->message);
1147 g_signal_connect (error_dialog, "response",
1148 G_CALLBACK (gtk_widget_destroy), NULL);
1150 gtk_window_present (GTK_WINDOW (error_dialog));
1152 g_clear_error (&error);
1158 gtk_widget_destroy (dialog);
1162 popup_avatar_menu (EmpathyContactWidget *information,
1164 GdkEventButton *event)
1166 GtkWidget *menu, *item;
1167 gint button, event_time;
1169 if (information->contact == NULL ||
1170 empathy_contact_get_avatar (information->contact) == NULL)
1173 menu = empathy_context_menu_new (parent);
1175 /* Add "Save as..." entry */
1176 item = gtk_image_menu_item_new_from_stock (GTK_STOCK_SAVE_AS, NULL);
1177 gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
1178 gtk_widget_show (item);
1180 g_signal_connect (item, "activate",
1181 G_CALLBACK (save_avatar_menu_activate_cb), information);
1185 button = event->button;
1186 event_time = event->time;
1191 event_time = gtk_get_current_event_time ();
1194 gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
1195 button, event_time);
1199 widget_avatar_popup_menu_cb (GtkWidget *widget,
1200 EmpathyContactWidget *information)
1202 popup_avatar_menu (information, widget, NULL);
1208 widget_avatar_button_press_event_cb (GtkWidget *widget,
1209 GdkEventButton *event,
1210 EmpathyContactWidget *information)
1212 /* Ignore double-clicks and triple-clicks */
1213 if (event->button == 3 && event->type == GDK_BUTTON_PRESS)
1215 popup_avatar_menu (information, widget, event);
1223 set_avatar_cb (GObject *source,
1227 GError *error = NULL;
1229 if (!tp_account_set_avatar_finish (TP_ACCOUNT (source), res, &error)) {
1230 DEBUG ("Failed to set Account.Avatar: %s", error->message);
1231 g_error_free (error);
1236 set_avatar_on_account (TpAccount *account,
1239 const gchar *mime_type)
1241 DEBUG ("%s Account.Avatar on %s", size > 0 ? "Set": "Clear",
1242 tp_proxy_get_object_path (account));
1244 tp_account_set_avatar_async (account, (const guchar *) data, size,
1245 mime_type, set_avatar_cb, NULL);
1249 contact_widget_avatar_changed_cb (EmpathyAvatarChooser *chooser,
1250 EmpathyContactWidget *information)
1254 const gchar *mime_type;
1257 empathy_avatar_chooser_get_image_data (
1258 EMPATHY_AVATAR_CHOOSER (information->widget_avatar),
1259 &data, &size, &mime_type);
1261 account = empathy_contact_get_account (information->contact);
1262 set_avatar_on_account (account, data, size, mime_type);
1266 set_nickname_cb (GObject *source,
1270 GError *error = NULL;
1272 if (!tp_account_set_nickname_finish (TP_ACCOUNT (source), res, &error))
1274 DEBUG ("Failed to set Account.Nickname: %s", error->message);
1275 g_error_free (error);
1279 /* Update all the contact info fields having the
1280 * Overwritten_By_Nickname flag to the new alias. This avoid accidentally
1281 * reseting the alias when calling SetContactInfo(). See bgo #644298 for
1284 update_nickname_in_contact_info (EmpathyContactWidget *self,
1285 TpConnection *connection,
1286 const gchar *nickname)
1290 specs = tp_connection_get_contact_info_supported_fields (connection);
1292 for (l = self->details_to_set; l != NULL; l= g_list_next (l))
1294 TpContactInfoField *field = l->data;
1295 TpContactInfoFieldSpec *spec;
1297 spec = get_spec_from_list (specs, field->field_name);
1298 /* We shouldn't have added the field to details_to_set if it's not
1299 * supported by the CM */
1300 g_assert (spec != NULL);
1302 if (spec->flags & TP_CONTACT_INFO_FIELD_FLAG_OVERWRITTEN_BY_NICKNAME)
1304 const gchar *strv[] = { nickname, NULL };
1306 DEBUG ("Updating field '%s' to '%s' as it has the "
1307 "Overwritten_By_Nickname flag and Account.Nickname has "
1308 "been updated", field->field_name, nickname);
1310 if (field->field_value != NULL)
1311 g_strfreev (field->field_value);
1312 field->field_value = g_strdupv ((GStrv) strv);
1316 g_list_free (specs);
1320 contact_widget_entry_alias_focus_event_cb (GtkEditable *editable,
1321 GdkEventFocus *event,
1322 EmpathyContactWidget *information)
1324 if (information->contact)
1328 alias = gtk_entry_get_text (GTK_ENTRY (editable));
1330 if (empathy_contact_is_user (information->contact))
1332 TpAccount * account;
1333 const gchar *current_nickname;
1335 account = empathy_contact_get_account (information->contact);
1336 current_nickname = tp_account_get_nickname (account);
1338 if (tp_strdiff (current_nickname, alias))
1340 DEBUG ("Set Account.Nickname to %s", alias);
1342 tp_account_set_nickname_async (account, alias, set_nickname_cb,
1345 update_nickname_in_contact_info (information,
1346 empathy_contact_get_connection (information->contact), alias);
1351 empathy_contact_set_alias (information->contact, alias);
1359 update_avatar_chooser_account_cb (EmpathyAccountChooser *account_chooser,
1360 EmpathyAvatarChooser *avatar_chooser)
1364 account = empathy_account_chooser_get_account (account_chooser);
1365 if (account == NULL)
1368 empathy_avatar_chooser_set_account (avatar_chooser, account);
1372 contact_widget_avatar_notify_cb (EmpathyContactWidget *information)
1374 EmpathyAvatar *avatar = NULL;
1376 if (information->contact)
1377 avatar = empathy_contact_get_avatar (information->contact);
1379 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_AVATAR)
1381 g_signal_handlers_block_by_func (information->widget_avatar,
1382 contact_widget_avatar_changed_cb,
1384 empathy_avatar_chooser_set (
1385 EMPATHY_AVATAR_CHOOSER (information->widget_avatar), avatar);
1386 g_signal_handlers_unblock_by_func (information->widget_avatar,
1387 contact_widget_avatar_changed_cb, information);
1390 empathy_avatar_image_set (
1391 EMPATHY_AVATAR_IMAGE (information->widget_avatar), avatar);
1395 contact_widget_name_notify_cb (EmpathyContactWidget *information)
1397 if (GTK_IS_ENTRY (information->widget_alias))
1398 gtk_entry_set_text (GTK_ENTRY (information->widget_alias),
1399 empathy_contact_get_alias (information->contact));
1401 gtk_label_set_label (GTK_LABEL (information->widget_alias),
1402 empathy_contact_get_alias (information->contact));
1406 contact_widget_presence_notify_cb (EmpathyContactWidget *information)
1408 const gchar *status;
1409 gchar *markup_text = NULL;
1411 status = empathy_contact_get_status (information->contact);
1413 markup_text = empathy_add_link_markup (status);
1414 gtk_label_set_markup (GTK_LABEL (information->label_status), markup_text);
1415 g_free (markup_text);
1417 gtk_image_set_from_icon_name (GTK_IMAGE (information->image_state),
1418 empathy_icon_name_for_contact (information->contact),
1419 GTK_ICON_SIZE_BUTTON);
1420 gtk_widget_show (information->image_state);
1424 contact_widget_favourites_changed_cb (EmpathyContactManager *manager,
1425 EmpathyContact *contact,
1426 gboolean is_favourite,
1427 EmpathyContactWidget *information)
1429 if (contact != information->contact)
1432 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (
1433 information->favourite_checkbox), is_favourite);
1437 contact_widget_remove_contact (EmpathyContactWidget *information)
1439 if (information->contact)
1441 TpContact *tp_contact;
1443 contact_widget_save (information);
1445 g_signal_handlers_disconnect_by_func (information->contact,
1446 contact_widget_name_notify_cb, information);
1447 g_signal_handlers_disconnect_by_func (information->contact,
1448 contact_widget_presence_notify_cb, information);
1449 g_signal_handlers_disconnect_by_func (information->contact,
1450 contact_widget_avatar_notify_cb, information);
1452 tp_contact = empathy_contact_get_tp_contact (information->contact);
1453 if (tp_contact != NULL)
1455 g_signal_handlers_disconnect_by_func (tp_contact,
1456 contact_widget_details_notify_cb, information);
1459 g_object_unref (information->contact);
1460 information->contact = NULL;
1463 if (information->details_cancellable != NULL)
1465 g_cancellable_cancel (information->details_cancellable);
1466 tp_clear_object (&information->details_cancellable);
1470 static void contact_widget_change_contact (EmpathyContactWidget *information);
1473 contact_widget_contact_update (EmpathyContactWidget *information)
1475 TpAccount *account = NULL;
1476 const gchar *id = NULL;
1478 /* Connect and get info from new contact */
1479 if (information->contact)
1481 g_signal_connect_swapped (information->contact, "notify::name",
1482 G_CALLBACK (contact_widget_name_notify_cb), information);
1483 g_signal_connect_swapped (information->contact, "notify::presence",
1484 G_CALLBACK (contact_widget_presence_notify_cb), information);
1485 g_signal_connect_swapped (information->contact,
1486 "notify::presence-message",
1487 G_CALLBACK (contact_widget_presence_notify_cb), information);
1488 g_signal_connect_swapped (information->contact, "notify::avatar",
1489 G_CALLBACK (contact_widget_avatar_notify_cb), information);
1491 account = empathy_contact_get_account (information->contact);
1492 id = empathy_contact_get_id (information->contact);
1495 /* Update account widget */
1496 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ACCOUNT)
1500 g_signal_handlers_block_by_func (information->widget_account,
1501 contact_widget_change_contact,
1503 empathy_account_chooser_set_account (
1504 EMPATHY_ACCOUNT_CHOOSER (information->widget_account), account);
1505 g_signal_handlers_unblock_by_func (information->widget_account,
1506 contact_widget_change_contact, information);
1515 name = tp_account_get_display_name (account);
1516 gtk_label_set_label (GTK_LABEL (information->label_account), name);
1518 name = tp_account_get_icon_name (account);
1519 gtk_image_set_from_icon_name (GTK_IMAGE (information->image_account),
1520 name, GTK_ICON_SIZE_MENU);
1524 /* Update id widget */
1525 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ID)
1526 gtk_entry_set_text (GTK_ENTRY (information->widget_id), id ? id : "");
1528 gtk_label_set_label (GTK_LABEL (information->widget_id), id ? id : "");
1530 /* Update other widgets */
1531 if (information->contact)
1533 contact_widget_name_notify_cb (information);
1534 contact_widget_presence_notify_cb (information);
1535 contact_widget_avatar_notify_cb (information);
1537 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_FAVOURITE)
1539 FolksPersona *persona = empathy_contact_get_persona (
1540 information->contact);
1542 if (persona != NULL && FOLKS_IS_FAVOURITE_DETAILS (persona))
1544 gboolean is_favourite = folks_favourite_details_get_is_favourite (
1545 FOLKS_FAVOURITE_DETAILS (persona));
1546 contact_widget_favourites_changed_cb (information->manager,
1547 information->contact, is_favourite, information);
1551 gtk_widget_show (information->label_alias);
1552 gtk_widget_show (information->widget_alias);
1553 gtk_widget_show (information->hbox_presence);
1554 gtk_widget_show (information->widget_avatar);
1558 gtk_widget_hide (information->label_alias);
1559 gtk_widget_hide (information->widget_alias);
1560 gtk_widget_hide (information->hbox_presence);
1561 gtk_widget_hide (information->widget_avatar);
1566 contact_widget_set_contact (EmpathyContactWidget *information,
1567 EmpathyContact *contact)
1569 if (contact == information->contact)
1572 contact_widget_remove_contact (information);
1574 information->contact = g_object_ref (contact);
1576 /* set the selected account to be the account this contact came from */
1577 if (contact && EMPATHY_IS_ACCOUNT_CHOOSER (information->widget_account)) {
1578 empathy_account_chooser_set_account (
1579 EMPATHY_ACCOUNT_CHOOSER (information->widget_account),
1580 empathy_contact_get_account (contact));
1583 /* Update information for widgets */
1584 contact_widget_contact_update (information);
1585 contact_widget_groups_update (information);
1586 contact_widget_details_update (information);
1587 contact_widget_client_update (information);
1588 contact_widget_location_update (information);
1592 contact_widget_got_contact_cb (TpConnection *connection,
1593 EmpathyContact *contact,
1594 const GError *error,
1596 GObject *weak_object)
1598 EmpathyContactWidget *information = user_data;
1602 DEBUG ("Error: %s", error->message);
1606 contact_widget_set_contact (information, contact);
1610 contact_widget_change_contact (EmpathyContactWidget *information)
1612 TpConnection *connection;
1614 connection = empathy_account_chooser_get_connection (
1615 EMPATHY_ACCOUNT_CHOOSER (information->widget_account));
1619 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ID)
1623 id = gtk_entry_get_text (GTK_ENTRY (information->widget_id));
1624 if (!EMP_STR_EMPTY (id))
1626 empathy_tp_contact_factory_get_from_id (connection, id,
1627 contact_widget_got_contact_cb, information, NULL,
1628 G_OBJECT (information->vbox_contact_widget));
1633 empathy_tp_contact_factory_get_from_handle (connection,
1634 tp_connection_get_self_handle (connection),
1635 contact_widget_got_contact_cb, information, NULL,
1636 G_OBJECT (information->vbox_contact_widget));
1641 contact_widget_id_activate_timeout (EmpathyContactWidget *self)
1643 contact_widget_change_contact (self);
1648 contact_widget_id_changed_cb (GtkEntry *entry,
1649 EmpathyContactWidget *self)
1651 if (self->widget_id_timeout != 0)
1653 g_source_remove (self->widget_id_timeout);
1656 self->widget_id_timeout =
1657 g_timeout_add_seconds (ID_CHANGED_TIMEOUT,
1658 (GSourceFunc) contact_widget_id_activate_timeout, self);
1662 contact_widget_id_focus_out_cb (GtkWidget *widget,
1663 GdkEventFocus *event,
1664 EmpathyContactWidget *information)
1666 contact_widget_change_contact (information);
1671 favourite_toggled_cb (GtkToggleButton *button,
1672 EmpathyContactWidget *information)
1674 FolksPersona *persona = empathy_contact_get_persona (information->contact);
1676 if (persona != NULL && FOLKS_IS_FAVOURITE_DETAILS (persona))
1678 gboolean active = gtk_toggle_button_get_active (button);
1679 folks_favourite_details_set_is_favourite (
1680 FOLKS_FAVOURITE_DETAILS (persona), active);
1685 contact_widget_contact_setup (EmpathyContactWidget *information)
1687 information->label_status = gtk_label_new ("");
1688 gtk_label_set_line_wrap_mode (GTK_LABEL (information->label_status),
1689 PANGO_WRAP_WORD_CHAR);
1690 gtk_label_set_line_wrap (GTK_LABEL (information->label_status),
1693 if (!(information->flags & EMPATHY_CONTACT_WIDGET_FOR_TOOLTIP))
1694 gtk_label_set_selectable (GTK_LABEL (information->label_status), TRUE);
1696 gtk_box_pack_start (GTK_BOX (information->hbox_presence),
1697 information->label_status, TRUE, TRUE, 0);
1698 gtk_widget_show (information->label_status);
1700 /* Setup account label/chooser */
1701 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ACCOUNT)
1703 information->widget_account = empathy_account_chooser_new ();
1705 g_signal_connect_swapped (information->widget_account, "changed",
1706 G_CALLBACK (contact_widget_change_contact),
1711 /* Pack the protocol icon with the account name in an hbox */
1712 information->widget_account = gtk_hbox_new (FALSE, 6);
1714 information->label_account = gtk_label_new (NULL);
1715 if (!(information->flags & EMPATHY_CONTACT_WIDGET_FOR_TOOLTIP)) {
1716 gtk_label_set_selectable (GTK_LABEL (information->label_account), TRUE);
1718 gtk_misc_set_alignment (GTK_MISC (information->label_account), 0, 0.5);
1719 gtk_widget_show (information->label_account);
1721 information->image_account = gtk_image_new ();
1722 gtk_widget_show (information->image_account);
1724 gtk_box_pack_start (GTK_BOX (information->widget_account),
1725 information->image_account, FALSE, FALSE, 0);
1726 gtk_box_pack_start (GTK_BOX (information->widget_account),
1727 information->label_account, FALSE, TRUE, 0);
1729 gtk_table_attach_defaults (GTK_TABLE (information->table_contact),
1730 information->widget_account,
1732 gtk_widget_show (information->widget_account);
1734 /* Set up avatar chooser/display */
1735 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_AVATAR)
1737 information->widget_avatar = empathy_avatar_chooser_new ();
1738 g_signal_connect (information->widget_avatar, "changed",
1739 G_CALLBACK (contact_widget_avatar_changed_cb),
1741 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ACCOUNT)
1743 g_signal_connect (information->widget_account, "changed",
1744 G_CALLBACK (update_avatar_chooser_account_cb),
1745 information->widget_avatar);
1746 update_avatar_chooser_account_cb (
1747 EMPATHY_ACCOUNT_CHOOSER (information->widget_account),
1748 EMPATHY_AVATAR_CHOOSER (information->widget_avatar));
1753 information->widget_avatar = empathy_avatar_image_new ();
1755 g_signal_connect (information->widget_avatar, "popup-menu",
1756 G_CALLBACK (widget_avatar_popup_menu_cb), information);
1757 g_signal_connect (information->widget_avatar, "button-press-event",
1758 G_CALLBACK (widget_avatar_button_press_event_cb), information);
1761 gtk_box_pack_start (GTK_BOX (information->vbox_avatar),
1762 information->widget_avatar,
1765 gtk_widget_show (information->widget_avatar);
1767 /* Setup id label/entry */
1768 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ID)
1770 information->widget_id = gtk_entry_new ();
1771 g_signal_connect (information->widget_id, "focus-out-event",
1772 G_CALLBACK (contact_widget_id_focus_out_cb),
1774 g_signal_connect (information->widget_id, "changed",
1775 G_CALLBACK (contact_widget_id_changed_cb),
1780 information->widget_id = gtk_label_new (NULL);
1781 if (!(information->flags & EMPATHY_CONTACT_WIDGET_FOR_TOOLTIP)) {
1782 gtk_label_set_selectable (GTK_LABEL (information->widget_id), TRUE);
1784 gtk_misc_set_alignment (GTK_MISC (information->widget_id), 0, 0.5);
1786 gtk_table_attach_defaults (GTK_TABLE (information->table_contact),
1787 information->widget_id,
1789 gtk_widget_show (information->widget_id);
1791 /* Setup alias label/entry */
1792 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ALIAS)
1794 information->widget_alias = gtk_entry_new ();
1796 if (!(information->flags & EMPATHY_CONTACT_WIDGET_NO_SET_ALIAS))
1797 g_signal_connect (information->widget_alias, "focus-out-event",
1798 G_CALLBACK (contact_widget_entry_alias_focus_event_cb),
1801 /* Make return activate the window default (the Close button) */
1802 gtk_entry_set_activates_default (GTK_ENTRY (information->widget_alias),
1807 information->widget_alias = gtk_label_new (NULL);
1808 if (!(information->flags & EMPATHY_CONTACT_WIDGET_FOR_TOOLTIP)) {
1809 gtk_label_set_selectable (GTK_LABEL (information->widget_alias), TRUE);
1811 gtk_misc_set_alignment (GTK_MISC (information->widget_alias), 0, 0.5);
1813 gtk_table_attach_defaults (GTK_TABLE (information->table_contact),
1814 information->widget_alias,
1816 if (information->flags & EMPATHY_CONTACT_WIDGET_FOR_TOOLTIP) {
1817 gtk_label_set_selectable (GTK_LABEL (information->label_status), FALSE);
1819 gtk_widget_show (information->widget_alias);
1822 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_FAVOURITE)
1824 information->favourite_checkbox = gtk_check_button_new_with_label (
1827 g_signal_connect (information->favourite_checkbox, "toggled",
1828 G_CALLBACK (favourite_toggled_cb), information);
1830 gtk_table_attach_defaults (GTK_TABLE (information->table_contact),
1831 information->favourite_checkbox, 0, 2, 3, 4);
1833 information->fav_sig_id = g_signal_connect (information->manager,
1834 "favourites-changed",
1835 G_CALLBACK (contact_widget_favourites_changed_cb), information);
1837 gtk_widget_show (information->favourite_checkbox);
1842 contact_widget_destroy_cb (GtkWidget *widget,
1843 EmpathyContactWidget *information)
1845 contact_widget_remove_contact (information);
1847 if (information->widget_id_timeout != 0)
1849 g_source_remove (information->widget_id_timeout);
1852 if (information->fav_sig_id != 0)
1853 g_signal_handler_disconnect (information->manager, information->fav_sig_id);
1855 g_object_unref (information->manager);
1857 g_slice_free (EmpathyContactWidget, information);
1861 * empathy_contact_widget_new:
1862 * @contact: an #EmpathyContact
1863 * @flags: #EmpathyContactWidgetFlags for the new contact widget
1865 * Creates a new #EmpathyContactWidget.
1867 * Return value: a new #EmpathyContactWidget
1870 empathy_contact_widget_new (EmpathyContact *contact,
1871 EmpathyContactWidgetFlags flags)
1873 EmpathyContactWidget *information;
1877 g_return_val_if_fail (contact == NULL || EMPATHY_IS_CONTACT (contact), NULL);
1879 information = g_slice_new0 (EmpathyContactWidget);
1880 information->flags = flags;
1882 filename = empathy_file_lookup ("empathy-contact-widget.ui",
1884 gui = empathy_builder_get_file (filename,
1885 "vbox_contact_widget", &information->vbox_contact_widget,
1886 "hbox_contact", &information->hbox_contact,
1887 "hbox_presence", &information->hbox_presence,
1888 "label_alias", &information->label_alias,
1889 "image_state", &information->image_state,
1890 "table_contact", &information->table_contact,
1891 "vbox_avatar", &information->vbox_avatar,
1892 "vbox_location", &information->vbox_location,
1893 "subvbox_location", &information->subvbox_location,
1894 "label_location", &information->label_location,
1895 #ifdef HAVE_LIBCHAMPLAIN
1896 "viewport_map", &information->viewport_map,
1898 "groups_widget", &information->groups_widget,
1899 "vbox_details", &information->vbox_details,
1900 "table_details", &information->table_details,
1901 "hbox_details_requested", &information->hbox_details_requested,
1902 "vbox_client", &information->vbox_client,
1903 "table_client", &information->table_client,
1904 "hbox_client_requested", &information->hbox_client_requested,
1908 empathy_builder_connect (gui, information,
1909 "vbox_contact_widget", "destroy", contact_widget_destroy_cb,
1911 information->table_location = NULL;
1913 g_object_set_data (G_OBJECT (information->vbox_contact_widget),
1914 "EmpathyContactWidget",
1917 information->manager = empathy_contact_manager_dup_singleton ();
1919 /* Create widgets */
1920 contact_widget_contact_setup (information);
1921 contact_widget_details_setup (information);
1922 contact_widget_client_setup (information);
1924 if (contact != NULL)
1925 contact_widget_set_contact (information, contact);
1926 else if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ACCOUNT ||
1927 information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ID)
1928 contact_widget_change_contact (information);
1930 return empathy_builder_unref_and_keep_widget (gui,
1931 information->vbox_contact_widget);
1935 * empathy_contact_widget_get_contact:
1936 * @widget: an #EmpathyContactWidget
1938 * Get the #EmpathyContact related with the #EmpathyContactWidget @widget.
1940 * Returns: the #EmpathyContact associated with @widget
1943 empathy_contact_widget_get_contact (GtkWidget *widget)
1945 EmpathyContactWidget *information;
1947 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
1949 information = g_object_get_data (G_OBJECT (widget), "EmpathyContactWidget");
1953 return information->contact;
1957 empathy_contact_widget_get_alias (GtkWidget *widget)
1959 EmpathyContactWidget *information;
1961 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
1963 information = g_object_get_data (G_OBJECT (widget), "EmpathyContactWidget");
1967 return gtk_entry_get_text (GTK_ENTRY (information->widget_alias));
1971 * empathy_contact_widget_set_contact:
1972 * @widget: an #EmpathyContactWidget
1973 * @contact: a different #EmpathyContact
1975 * Change the #EmpathyContact related with the #EmpathyContactWidget @widget.
1978 empathy_contact_widget_set_contact (GtkWidget *widget,
1979 EmpathyContact *contact)
1981 EmpathyContactWidget *information;
1983 g_return_if_fail (GTK_IS_WIDGET (widget));
1984 g_return_if_fail (EMPATHY_IS_CONTACT (contact));
1986 information = g_object_get_data (G_OBJECT (widget), "EmpathyContactWidget");
1990 contact_widget_set_contact (information, contact);
1994 * empathy_contact_widget_set_account_filter:
1995 * @widget: an #EmpathyContactWidget
1996 * @filter: a #EmpathyAccountChooserFilterFunc
1997 * @user_data: user data to pass to @filter, or %NULL
1999 * Set a filter on the #EmpathyAccountChooser included in the
2000 * #EmpathyContactWidget.
2003 empathy_contact_widget_set_account_filter (
2005 EmpathyAccountChooserFilterFunc filter,
2008 EmpathyContactWidget *information;
2009 EmpathyAccountChooser *chooser;
2011 g_return_if_fail (GTK_IS_WIDGET (widget));
2013 information = g_object_get_data (G_OBJECT (widget), "EmpathyContactWidget");
2017 chooser = EMPATHY_ACCOUNT_CHOOSER (information->widget_account);
2019 empathy_account_chooser_set_filter (chooser, filter, user_data);