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
81 EmpathyContactManager *manager;
82 EmpathyContact *contact;
83 EmpathyContactWidgetFlags flags;
84 guint widget_id_timeout;
87 GtkWidget *vbox_contact_widget;
90 GtkWidget *hbox_contact;
91 GtkWidget *widget_avatar;
92 GtkWidget *widget_account;
93 GtkWidget *image_account;
94 GtkWidget *label_account;
96 GtkWidget *widget_alias;
97 GtkWidget *label_alias;
98 GtkWidget *hbox_presence;
99 GtkWidget *image_state;
100 GtkWidget *label_status;
101 GtkWidget *table_contact;
102 GtkWidget *vbox_avatar;
103 GtkWidget *favourite_checkbox;
106 GtkWidget *vbox_location;
107 GtkWidget *subvbox_location;
108 GtkWidget *table_location;
109 GtkWidget *label_location;
110 #ifdef HAVE_LIBCHAMPLAIN
111 GtkWidget *viewport_map;
112 GtkWidget *map_view_embed;
113 ChamplainView *map_view;
117 GtkWidget *groups_widget;
120 GtkWidget *vbox_details;
121 GtkWidget *table_details;
122 GtkWidget *hbox_details_requested;
123 GtkWidget *spinner_details;
124 GList *details_to_set;
125 GCancellable *details_cancellable;
128 GtkWidget *vbox_client;
129 GtkWidget *table_client;
130 GtkWidget *hbox_client_requested;
131 } EmpathyContactWidget;
135 EmpathyContactWidget *information;
138 GtkTreeIter found_iter;
150 field_value_is_empty (TpContactInfoField *field)
154 if (field->field_value == NULL)
157 /* Field is empty if all its values are empty */
158 for (i = 0; field->field_value[i] != NULL; i++)
160 if (!tp_str_empty (field->field_value[i]))
168 set_contact_info_cb (GObject *source,
169 GAsyncResult *result,
172 GError *error = NULL;
174 if (!tp_connection_set_contact_info_finish (TP_CONNECTION (source), result,
177 DEBUG ("SetContactInfo() failed: %s", error->message);
178 g_error_free (error);
182 DEBUG ("SetContactInfo() succeeded");
186 contact_widget_save (EmpathyContactWidget *information)
188 TpConnection *connection;
191 connection = empathy_contact_get_connection (information->contact);
193 /* Remove empty fields */
194 for (l = information->details_to_set; l != NULL; l = next)
196 TpContactInfoField *field = l->data;
199 if (field_value_is_empty (field))
201 DEBUG ("Drop empty field: %s", field->field_name);
202 tp_contact_info_field_free (field);
203 information->details_to_set =
204 g_list_delete_link (information->details_to_set, l);
208 if (information->details_to_set != NULL)
210 tp_connection_set_contact_info_async (connection,
211 information->details_to_set, set_contact_info_cb, NULL);
212 tp_contact_info_list_free (information->details_to_set);
213 information->details_to_set = NULL;
218 contact_widget_details_setup (EmpathyContactWidget *information)
220 gtk_widget_hide (information->vbox_details);
222 information->spinner_details = gtk_spinner_new ();
223 gtk_box_pack_end (GTK_BOX (information->hbox_details_requested),
224 information->spinner_details, TRUE, TRUE, 0);
225 gtk_widget_show (information->spinner_details);
229 contact_widget_details_changed_cb (GtkEntry *entry,
230 TpContactInfoField *field)
232 const gchar *strv[] = { NULL, NULL };
234 strv[0] = gtk_entry_get_text (entry);
236 if (field->field_value != NULL)
237 g_strfreev (field->field_value);
238 field->field_value = g_strdupv ((GStrv) strv);
241 static void contact_widget_details_notify_cb (EmpathyContactWidget *information);
245 const gchar *field_name;
250 static InfoFieldData info_field_datas[] =
252 { "fn", N_("Full name:"), FALSE },
253 { "tel", N_("Phone number:"), FALSE },
254 { "email", N_("E-mail address:"), TRUE },
255 { "url", N_("Website:"), TRUE },
256 { "bday", N_("Birthday:"), FALSE },
260 static InfoFieldData *
261 find_info_field_data (const gchar *field_name)
265 for (i = 0; info_field_datas[i].field_name != NULL; i++)
267 if (!tp_strdiff (info_field_datas[i].field_name, field_name))
268 return info_field_datas + i;
274 contact_info_field_name_cmp (const gchar *name1,
279 if (!tp_strdiff (name1, name2))
282 /* We use the order of info_field_datas */
283 for (i = 0; info_field_datas[i].field_name != NULL; i++)
285 if (!tp_strdiff (info_field_datas[i].field_name, name1))
287 if (!tp_strdiff (info_field_datas[i].field_name, name2))
291 return g_strcmp0 (name1, name2);
295 contact_info_field_cmp (TpContactInfoField *field1,
296 TpContactInfoField *field2)
298 return contact_info_field_name_cmp (field1->field_name, field2->field_name);
302 contact_widget_details_update_edit (EmpathyContactWidget *information)
305 TpConnection *connection;
310 g_assert (information->details_to_set == NULL);
312 contact = empathy_contact_get_tp_contact (information->contact);
313 connection = tp_contact_get_connection (contact);
315 info = tp_contact_get_contact_info (contact);
317 specs = tp_connection_get_contact_info_supported_fields (connection);
319 /* Look at the fields set in our vCard */
320 for (l = info; l != NULL; l = l->next)
322 TpContactInfoField *field = l->data;
324 /* make a copy for the details_to_set list */
325 field = tp_contact_info_field_copy (field);
326 DEBUG ("Field %s is in our vCard", field->field_name);
328 information->details_to_set = g_list_prepend (information->details_to_set,
332 /* Add widgets for supported fields */
333 information->details_to_set = g_list_sort (information->details_to_set,
334 (GCompareFunc) contact_info_field_cmp);
336 for (l = information->details_to_set; l != NULL; l= g_list_next (l))
338 TpContactInfoField *field = l->data;
339 InfoFieldData *field_data;
342 field_data = find_info_field_data (field->field_name);
343 if (field_data == NULL)
345 /* Empathy doesn't display this field so we can't change it.
346 * But we put it in the details_to_set list so it won't be erased
347 * when calling SetContactInfo (bgo #630427) */
348 DEBUG ("Unhandled ContactInfo field spec: %s", field->field_name);
353 w = gtk_label_new (_(field_data->title));
354 gtk_table_attach (GTK_TABLE (information->table_details),
355 w, 0, 1, n_rows, n_rows + 1, GTK_FILL, 0, 0, 0);
356 gtk_misc_set_alignment (GTK_MISC (w), 0, 0.5);
360 w = gtk_entry_new ();
361 gtk_entry_set_text (GTK_ENTRY (w),
362 field->field_value[0] ? field->field_value[0] : "");
363 gtk_table_attach_defaults (GTK_TABLE (information->table_details),
364 w, 1, 2, n_rows, n_rows + 1);
367 g_signal_connect (w, "changed",
368 G_CALLBACK (contact_widget_details_changed_cb), field);
380 contact_widget_details_update_show (EmpathyContactWidget *information)
386 contact = empathy_contact_get_tp_contact (information->contact);
387 info = tp_contact_get_contact_info (contact);
388 info = g_list_sort (info, (GCompareFunc) contact_info_field_cmp);
389 for (l = info; l != NULL; l = l->next)
391 TpContactInfoField *field = l->data;
392 InfoFieldData *field_data;
396 if (field->field_value == NULL || field->field_value[0] == NULL)
399 value = field->field_value[0];
401 field_data = find_info_field_data (field->field_name);
402 if (field_data == NULL)
404 DEBUG ("Unhandled ContactInfo field: %s", field->field_name);
409 w = gtk_label_new (_(field_data->title));
410 gtk_table_attach (GTK_TABLE (information->table_details),
411 w, 0, 1, n_rows, n_rows + 1, GTK_FILL, 0, 0, 0);
412 gtk_misc_set_alignment (GTK_MISC (w), 0, 0.5);
416 w = gtk_label_new (value);
417 if (field_data->linkify)
421 markup = empathy_add_link_markup (value);
422 gtk_label_set_markup (GTK_LABEL (w), markup);
426 if ((information->flags & EMPATHY_CONTACT_WIDGET_FOR_TOOLTIP) == 0)
427 gtk_label_set_selectable (GTK_LABEL (w), TRUE);
429 gtk_table_attach_defaults (GTK_TABLE (information->table_details),
430 w, 1, 2, n_rows, n_rows + 1);
431 gtk_misc_set_alignment (GTK_MISC (w), 0, 0.5);
442 contact_widget_details_notify_cb (EmpathyContactWidget *information)
446 gtk_container_foreach (GTK_CONTAINER (information->table_details),
447 (GtkCallback) gtk_widget_destroy, NULL);
449 if ((information->flags & EMPATHY_CONTACT_WIDGET_EDIT_DETAILS) != 0)
450 n_rows = contact_widget_details_update_edit (information);
452 n_rows = contact_widget_details_update_show (information);
456 gtk_widget_show (information->vbox_details);
457 gtk_widget_show (information->table_details);
461 gtk_widget_hide (information->vbox_details);
464 gtk_widget_hide (information->hbox_details_requested);
465 gtk_spinner_stop (GTK_SPINNER (information->spinner_details));
469 contact_widget_details_request_cb (GObject *object,
473 TpContact *contact = TP_CONTACT (object);
474 EmpathyContactWidget *information = user_data;
475 GError *error = NULL;
477 if (!tp_contact_request_contact_info_finish (contact, res, &error))
479 /* If the request got cancelled it could mean the contact widget is
480 * destroyed, so we should not dereference information */
481 if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
483 g_clear_error (&error);
487 gtk_widget_hide (information->vbox_details);
488 g_clear_error (&error);
492 contact_widget_details_notify_cb (information);
495 /* If we are going to edit ContactInfo, we don't want live updates */
496 if ((information->flags & EMPATHY_CONTACT_WIDGET_EDIT_DETAILS) == 0)
498 g_signal_connect_swapped (contact, "notify::contact-info",
499 G_CALLBACK (contact_widget_details_notify_cb), information);
502 tp_clear_object (&information->details_cancellable);
506 contact_widget_details_feature_prepared_cb (GObject *object,
510 TpConnection *connection = TP_CONNECTION (object);
511 EmpathyContactWidget *information = user_data;
513 TpContactInfoFlags flags;
515 if (!tp_proxy_prepare_finish (connection, res, NULL))
517 gtk_widget_hide (information->vbox_details);
521 /* If we want to edit info, but connection does not support that, stop */
522 flags = tp_connection_get_contact_info_flags (connection);
523 if ((flags & TP_CONTACT_INFO_FLAG_CAN_SET) == 0 &&
524 (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_DETAILS) != 0)
526 gtk_widget_hide (information->vbox_details);
530 /* Request the contact's info */
531 gtk_widget_show (information->vbox_details);
532 gtk_widget_show (information->hbox_details_requested);
533 gtk_widget_hide (information->table_details);
534 gtk_spinner_start (GTK_SPINNER (information->spinner_details));
536 contact = empathy_contact_get_tp_contact (information->contact);
537 g_assert (information->details_cancellable == NULL);
538 information->details_cancellable = g_cancellable_new ();
539 tp_contact_request_contact_info_async (contact,
540 information->details_cancellable, contact_widget_details_request_cb,
545 contact_widget_details_update (EmpathyContactWidget *information)
547 TpContact *tp_contact = NULL;
549 if ((information->flags & EMPATHY_CONTACT_WIDGET_SHOW_DETAILS) == 0 &&
550 (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_DETAILS) == 0)
553 gtk_widget_hide (information->vbox_details);
555 if (information->contact != NULL)
556 tp_contact = empathy_contact_get_tp_contact (information->contact);
558 if (tp_contact != NULL)
560 GQuark features[] = { TP_CONNECTION_FEATURE_CONTACT_INFO, 0 };
561 TpConnection *connection;
563 /* First, make sure the CONTACT_INFO feature is ready on the connection */
564 connection = tp_contact_get_connection (tp_contact);
565 tp_proxy_prepare_async (connection, features,
566 contact_widget_details_feature_prepared_cb, information);
571 contact_widget_client_update (EmpathyContactWidget *information)
573 /* FIXME: Needs new telepathy spec */
577 contact_widget_client_setup (EmpathyContactWidget *information)
579 /* FIXME: Needs new telepathy spec */
580 gtk_widget_hide (information->vbox_client);
584 contact_widget_groups_update (EmpathyContactWidget *information)
586 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_GROUPS &&
587 information->contact != NULL)
589 FolksPersona *persona =
590 empathy_contact_get_persona (information->contact);
592 if (FOLKS_IS_GROUPABLE (persona))
594 empathy_groups_widget_set_groupable (
595 EMPATHY_GROUPS_WIDGET (information->groups_widget),
596 FOLKS_GROUPABLE (persona));
597 gtk_widget_show (information->groups_widget);
603 /* In case of failure */
604 gtk_widget_hide (information->groups_widget);
607 /* Converts the Location's GHashTable's key to a user readable string */
609 location_key_to_label (const gchar *key)
611 if (tp_strdiff (key, EMPATHY_LOCATION_COUNTRY_CODE) == FALSE)
612 return _("Country ISO Code:");
613 else if (tp_strdiff (key, EMPATHY_LOCATION_COUNTRY) == FALSE)
614 return _("Country:");
615 else if (tp_strdiff (key, EMPATHY_LOCATION_REGION) == FALSE)
617 else if (tp_strdiff (key, EMPATHY_LOCATION_LOCALITY) == FALSE)
619 else if (tp_strdiff (key, EMPATHY_LOCATION_AREA) == FALSE)
621 else if (tp_strdiff (key, EMPATHY_LOCATION_POSTAL_CODE) == FALSE)
622 return _("Postal Code:");
623 else if (tp_strdiff (key, EMPATHY_LOCATION_STREET) == FALSE)
625 else if (tp_strdiff (key, EMPATHY_LOCATION_BUILDING) == FALSE)
626 return _("Building:");
627 else if (tp_strdiff (key, EMPATHY_LOCATION_FLOOR) == FALSE)
629 else if (tp_strdiff (key, EMPATHY_LOCATION_ROOM) == FALSE)
631 else if (tp_strdiff (key, EMPATHY_LOCATION_TEXT) == FALSE)
633 else if (tp_strdiff (key, EMPATHY_LOCATION_DESCRIPTION) == FALSE)
634 return _("Description:");
635 else if (tp_strdiff (key, EMPATHY_LOCATION_URI) == FALSE)
637 else if (tp_strdiff (key, EMPATHY_LOCATION_ACCURACY_LEVEL) == FALSE)
638 return _("Accuracy Level:");
639 else if (tp_strdiff (key, EMPATHY_LOCATION_ERROR) == FALSE)
641 else if (tp_strdiff (key, EMPATHY_LOCATION_VERTICAL_ERROR_M) == FALSE)
642 return _("Vertical Error (meters):");
643 else if (tp_strdiff (key, EMPATHY_LOCATION_HORIZONTAL_ERROR_M) == FALSE)
644 return _("Horizontal Error (meters):");
645 else if (tp_strdiff (key, EMPATHY_LOCATION_SPEED) == FALSE)
647 else if (tp_strdiff (key, EMPATHY_LOCATION_BEARING) == FALSE)
648 return _("Bearing:");
649 else if (tp_strdiff (key, EMPATHY_LOCATION_CLIMB) == FALSE)
650 return _("Climb Speed:");
651 else if (tp_strdiff (key, EMPATHY_LOCATION_TIMESTAMP) == FALSE)
652 return _("Last Updated on:");
653 else if (tp_strdiff (key, EMPATHY_LOCATION_LON) == FALSE)
654 return _("Longitude:");
655 else if (tp_strdiff (key, EMPATHY_LOCATION_LAT) == FALSE)
656 return _("Latitude:");
657 else if (tp_strdiff (key, EMPATHY_LOCATION_ALT) == FALSE)
658 return _("Altitude:");
661 DEBUG ("Unexpected Location key: %s", key);
667 contact_widget_location_update (EmpathyContactWidget *information)
669 GHashTable *location;
671 gdouble lat = 0.0, lon = 0.0;
672 gboolean has_position = TRUE;
675 static const gchar* ordered_geolocation_keys[] = {
676 EMPATHY_LOCATION_TEXT,
677 EMPATHY_LOCATION_URI,
678 EMPATHY_LOCATION_DESCRIPTION,
679 EMPATHY_LOCATION_BUILDING,
680 EMPATHY_LOCATION_FLOOR,
681 EMPATHY_LOCATION_ROOM,
682 EMPATHY_LOCATION_STREET,
683 EMPATHY_LOCATION_AREA,
684 EMPATHY_LOCATION_LOCALITY,
685 EMPATHY_LOCATION_REGION,
686 EMPATHY_LOCATION_COUNTRY,
691 gboolean display_map = FALSE;
693 if (!(information->flags & EMPATHY_CONTACT_WIDGET_SHOW_LOCATION))
695 gtk_widget_hide (information->vbox_location);
699 location = empathy_contact_get_location (information->contact);
700 if (location == NULL || g_hash_table_size (location) == 0)
702 gtk_widget_hide (information->vbox_location);
706 value = g_hash_table_lookup (location, EMPATHY_LOCATION_LAT);
708 has_position = FALSE;
710 lat = g_value_get_double (value);
712 value = g_hash_table_lookup (location, EMPATHY_LOCATION_LON);
714 has_position = FALSE;
716 lon = g_value_get_double (value);
718 value = g_hash_table_lookup (location, EMPATHY_LOCATION_TIMESTAMP);
721 gchar *loc = g_strdup_printf ("<b>%s</b>", _("Location"));
722 gtk_label_set_markup (GTK_LABEL (information->label_location), loc);
733 stamp = g_value_get_int64 (value);
736 user_date = empathy_time_to_string_relative (time_);
738 tmp = g_strdup_printf ("<b>%s</b>", _("Location"));
739 /* translators: format is "Location, $date" */
740 text = g_strdup_printf (_("%s, %s"), tmp, user_date);
742 gtk_label_set_markup (GTK_LABEL (information->label_location), text);
748 /* Prepare the location information table */
749 if (information->table_location != NULL)
751 gtk_widget_destroy (information->table_location);
754 information->table_location = gtk_table_new (1, 2, FALSE);
755 gtk_box_pack_start (GTK_BOX (information->subvbox_location),
756 information->table_location, FALSE, FALSE, 5);
759 for (i = 0; (skey = ordered_geolocation_keys[i]); i++)
761 const gchar* user_label;
765 gvalue = g_hash_table_lookup (location, (gpointer) skey);
769 user_label = location_key_to_label (skey);
771 label = gtk_label_new (user_label);
772 gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
773 gtk_table_attach (GTK_TABLE (information->table_location),
774 label, 0, 1, row, row + 1, GTK_FILL, GTK_FILL, 10, 0);
775 gtk_widget_show (label);
777 if (G_VALUE_TYPE (gvalue) == G_TYPE_DOUBLE)
780 dvalue = g_value_get_double (gvalue);
781 svalue = g_strdup_printf ("%f", dvalue);
783 else if (G_VALUE_TYPE (gvalue) == G_TYPE_STRING)
785 svalue = g_value_dup_string (gvalue);
787 else if (G_VALUE_TYPE (gvalue) == G_TYPE_INT64)
791 time_ = g_value_get_int64 (value);
792 svalue = empathy_time_to_string_utc (time_, _("%B %e, %Y at %R UTC"));
797 label = gtk_label_new (svalue);
798 gtk_table_attach_defaults (GTK_TABLE (information->table_location),
799 label, 1, 2, row, row + 1);
800 gtk_misc_set_alignment (GTK_MISC (label), 0, 0);
801 gtk_widget_show (label);
803 if (!(information->flags & EMPATHY_CONTACT_WIDGET_FOR_TOOLTIP))
804 gtk_label_set_selectable (GTK_LABEL (label), TRUE);
811 #ifdef HAVE_LIBCHAMPLAIN
813 !(information->flags & EMPATHY_CONTACT_WIDGET_FOR_TOOLTIP))
815 /* Cannot be displayed in tooltips until Clutter-Gtk can deal with such
823 /* We can display some fields */
824 gtk_widget_show (information->table_location);
826 else if (!display_map)
828 /* Can't display either fields or map */
829 gtk_widget_hide (information->vbox_location);
833 #ifdef HAVE_LIBCHAMPLAIN
836 ClutterActor *marker;
837 ChamplainLayer *layer;
839 information->map_view_embed = gtk_champlain_embed_new ();
840 information->map_view = gtk_champlain_embed_get_view (
841 GTK_CHAMPLAIN_EMBED (information->map_view_embed));
843 gtk_container_add (GTK_CONTAINER (information->viewport_map),
844 information->map_view_embed);
845 g_object_set (G_OBJECT (information->map_view),
846 "show-license", TRUE,
847 "scroll-mode", CHAMPLAIN_SCROLL_MODE_KINETIC,
851 layer = champlain_layer_new ();
852 champlain_view_add_layer (information->map_view, layer);
854 marker = champlain_marker_new_with_text (
855 empathy_contact_get_alias (information->contact), NULL, NULL, NULL);
856 champlain_base_marker_set_position (CHAMPLAIN_BASE_MARKER (marker), lat, lon);
857 clutter_container_add (CLUTTER_CONTAINER (layer), marker, NULL);
859 champlain_view_center_on (information->map_view, lat, lon);
860 gtk_widget_show_all (information->viewport_map);
864 gtk_widget_show (information->vbox_location);
868 save_avatar_menu_activate_cb (GtkWidget *widget,
869 EmpathyContactWidget *information)
872 EmpathyAvatar *avatar;
873 gchar *ext = NULL, *filename;
875 dialog = gtk_file_chooser_dialog_new (_("Save Avatar"),
877 GTK_FILE_CHOOSER_ACTION_SAVE,
878 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
879 GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT,
882 gtk_file_chooser_set_do_overwrite_confirmation (GTK_FILE_CHOOSER (dialog),
885 /* look for the avatar extension */
886 avatar = empathy_contact_get_avatar (information->contact);
887 if (avatar->format != NULL)
891 splitted = g_strsplit (avatar->format, "/", 2);
892 if (splitted[0] != NULL && splitted[1] != NULL)
893 ext = g_strdup (splitted[1]);
895 g_strfreev (splitted);
899 /* Avatar was loaded from the cache so was converted to PNG */
900 ext = g_strdup ("png");
907 id = tp_escape_as_identifier (empathy_contact_get_id (
908 information->contact));
910 filename = g_strdup_printf ("%s.%s", id, ext);
911 gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (dialog), filename);
918 if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT)
920 GError *error = NULL;
922 filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
924 if (!empathy_avatar_save_to_file (avatar, filename, &error))
927 GtkWidget *error_dialog;
929 error_dialog = gtk_message_dialog_new (NULL, 0,
930 GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE,
931 _("Unable to save avatar"));
933 gtk_message_dialog_format_secondary_text (
934 GTK_MESSAGE_DIALOG (error_dialog), "%s", error->message);
936 g_signal_connect (error_dialog, "response",
937 G_CALLBACK (gtk_widget_destroy), NULL);
939 gtk_window_present (GTK_WINDOW (error_dialog));
941 g_clear_error (&error);
947 gtk_widget_destroy (dialog);
951 popup_avatar_menu (EmpathyContactWidget *information,
953 GdkEventButton *event)
955 GtkWidget *menu, *item;
956 gint button, event_time;
958 if (information->contact == NULL ||
959 empathy_contact_get_avatar (information->contact) == NULL)
962 menu = gtk_menu_new ();
964 /* Add "Save as..." entry */
965 item = gtk_image_menu_item_new_from_stock (GTK_STOCK_SAVE_AS, NULL);
966 gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
967 gtk_widget_show (item);
969 g_signal_connect (item, "activate",
970 G_CALLBACK (save_avatar_menu_activate_cb), information);
974 button = event->button;
975 event_time = event->time;
980 event_time = gtk_get_current_event_time ();
983 gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
985 g_object_ref_sink (menu);
986 g_object_unref (menu);
990 widget_avatar_popup_menu_cb (GtkWidget *widget,
991 EmpathyContactWidget *information)
993 popup_avatar_menu (information, widget, NULL);
999 widget_avatar_button_press_event_cb (GtkWidget *widget,
1000 GdkEventButton *event,
1001 EmpathyContactWidget *information)
1003 /* Ignore double-clicks and triple-clicks */
1004 if (event->button == 3 && event->type == GDK_BUTTON_PRESS)
1006 popup_avatar_menu (information, widget, event);
1014 set_avatar_cb (GObject *source,
1018 GError *error = NULL;
1020 if (!tp_account_set_avatar_finish (TP_ACCOUNT (source), res, &error)) {
1021 DEBUG ("Failed to set Account.Avatar: %s", error->message);
1022 g_error_free (error);
1027 set_avatar_on_account (TpAccount *account,
1030 const gchar *mime_type)
1032 DEBUG ("%s Account.Avatar on %s", size > 0 ? "Set": "Clear",
1033 tp_proxy_get_object_path (account));
1035 tp_account_set_avatar_async (account, (const guchar *) data, size,
1036 mime_type, set_avatar_cb, NULL);
1040 contact_widget_avatar_changed_cb (EmpathyAvatarChooser *chooser,
1041 EmpathyContactWidget *information)
1045 const gchar *mime_type;
1048 empathy_avatar_chooser_get_image_data (
1049 EMPATHY_AVATAR_CHOOSER (information->widget_avatar),
1050 &data, &size, &mime_type);
1052 account = empathy_contact_get_account (information->contact);
1053 set_avatar_on_account (account, data, size, mime_type);
1057 set_nickname_cb (GObject *source,
1061 GError *error = NULL;
1063 if (!tp_account_set_nickname_finish (TP_ACCOUNT (source), res, &error))
1065 DEBUG ("Failed to set Account.Nickname: %s", error->message);
1066 g_error_free (error);
1071 set_alias_on_account (TpAccount *account,
1074 DEBUG ("Set Account.Nickname to %s", alias);
1076 tp_account_set_nickname_async (account, alias, set_nickname_cb, NULL);
1080 contact_widget_entry_alias_focus_event_cb (GtkEditable *editable,
1081 GdkEventFocus *event,
1082 EmpathyContactWidget *information)
1084 if (information->contact)
1088 alias = gtk_entry_get_text (GTK_ENTRY (editable));
1090 if (empathy_contact_is_user (information->contact))
1092 TpAccount * account;
1094 account = empathy_contact_get_account (information->contact);
1095 set_alias_on_account (account, alias);
1099 empathy_contact_set_alias (information->contact, alias);
1107 update_avatar_chooser_account_cb (EmpathyAccountChooser *account_chooser,
1108 EmpathyAvatarChooser *avatar_chooser)
1112 account = empathy_account_chooser_get_account (account_chooser);
1113 if (account == NULL)
1116 empathy_avatar_chooser_set_account (avatar_chooser, account);
1120 contact_widget_avatar_notify_cb (EmpathyContactWidget *information)
1122 EmpathyAvatar *avatar = NULL;
1124 if (information->contact)
1125 avatar = empathy_contact_get_avatar (information->contact);
1127 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_AVATAR)
1129 g_signal_handlers_block_by_func (information->widget_avatar,
1130 contact_widget_avatar_changed_cb,
1132 empathy_avatar_chooser_set (
1133 EMPATHY_AVATAR_CHOOSER (information->widget_avatar), avatar);
1134 g_signal_handlers_unblock_by_func (information->widget_avatar,
1135 contact_widget_avatar_changed_cb, information);
1138 empathy_avatar_image_set (
1139 EMPATHY_AVATAR_IMAGE (information->widget_avatar), avatar);
1143 contact_widget_name_notify_cb (EmpathyContactWidget *information)
1145 if (GTK_IS_ENTRY (information->widget_alias))
1146 gtk_entry_set_text (GTK_ENTRY (information->widget_alias),
1147 empathy_contact_get_alias (information->contact));
1149 gtk_label_set_label (GTK_LABEL (information->widget_alias),
1150 empathy_contact_get_alias (information->contact));
1154 contact_widget_presence_notify_cb (EmpathyContactWidget *information)
1156 const gchar *status;
1157 gchar *markup_text = NULL;
1159 status = empathy_contact_get_status (information->contact);
1161 markup_text = empathy_add_link_markup (status);
1162 gtk_label_set_markup (GTK_LABEL (information->label_status), markup_text);
1163 g_free (markup_text);
1165 gtk_image_set_from_icon_name (GTK_IMAGE (information->image_state),
1166 empathy_icon_name_for_contact (information->contact),
1167 GTK_ICON_SIZE_BUTTON);
1168 gtk_widget_show (information->image_state);
1172 contact_widget_favourites_changed_cb (EmpathyContactManager *manager,
1173 EmpathyContact *contact,
1174 gboolean is_favourite,
1175 EmpathyContactWidget *information)
1177 if (contact != information->contact)
1180 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (
1181 information->favourite_checkbox), is_favourite);
1185 contact_widget_remove_contact (EmpathyContactWidget *information)
1187 if (information->contact)
1189 TpContact *tp_contact;
1191 contact_widget_save (information);
1193 g_signal_handlers_disconnect_by_func (information->contact,
1194 contact_widget_name_notify_cb, information);
1195 g_signal_handlers_disconnect_by_func (information->contact,
1196 contact_widget_presence_notify_cb, information);
1197 g_signal_handlers_disconnect_by_func (information->contact,
1198 contact_widget_avatar_notify_cb, information);
1200 tp_contact = empathy_contact_get_tp_contact (information->contact);
1201 if (tp_contact != NULL)
1203 g_signal_handlers_disconnect_by_func (tp_contact,
1204 contact_widget_details_notify_cb, information);
1207 g_object_unref (information->contact);
1208 information->contact = NULL;
1211 if (information->details_cancellable != NULL)
1213 g_cancellable_cancel (information->details_cancellable);
1214 tp_clear_object (&information->details_cancellable);
1218 static void contact_widget_change_contact (EmpathyContactWidget *information);
1221 contact_widget_contact_update (EmpathyContactWidget *information)
1223 TpAccount *account = NULL;
1224 const gchar *id = NULL;
1226 /* Connect and get info from new contact */
1227 if (information->contact)
1229 g_signal_connect_swapped (information->contact, "notify::name",
1230 G_CALLBACK (contact_widget_name_notify_cb), information);
1231 g_signal_connect_swapped (information->contact, "notify::presence",
1232 G_CALLBACK (contact_widget_presence_notify_cb), information);
1233 g_signal_connect_swapped (information->contact,
1234 "notify::presence-message",
1235 G_CALLBACK (contact_widget_presence_notify_cb), information);
1236 g_signal_connect_swapped (information->contact, "notify::avatar",
1237 G_CALLBACK (contact_widget_avatar_notify_cb), information);
1239 account = empathy_contact_get_account (information->contact);
1240 id = empathy_contact_get_id (information->contact);
1243 /* Update account widget */
1244 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ACCOUNT)
1248 g_signal_handlers_block_by_func (information->widget_account,
1249 contact_widget_change_contact,
1251 empathy_account_chooser_set_account (
1252 EMPATHY_ACCOUNT_CHOOSER (information->widget_account), account);
1253 g_signal_handlers_unblock_by_func (information->widget_account,
1254 contact_widget_change_contact, information);
1263 name = tp_account_get_display_name (account);
1264 gtk_label_set_label (GTK_LABEL (information->label_account), name);
1266 name = tp_account_get_icon_name (account);
1267 gtk_image_set_from_icon_name (GTK_IMAGE (information->image_account),
1268 name, GTK_ICON_SIZE_MENU);
1272 /* Update id widget */
1273 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ID)
1274 gtk_entry_set_text (GTK_ENTRY (information->widget_id), id ? id : "");
1276 gtk_label_set_label (GTK_LABEL (information->widget_id), id ? id : "");
1278 /* Update other widgets */
1279 if (information->contact)
1281 contact_widget_name_notify_cb (information);
1282 contact_widget_presence_notify_cb (information);
1283 contact_widget_avatar_notify_cb (information);
1285 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_FAVOURITE)
1287 FolksPersona *persona = empathy_contact_get_persona (
1288 information->contact);
1290 if (persona != NULL && FOLKS_IS_FAVOURITE (persona))
1292 gboolean is_favourite = folks_favourite_get_is_favourite (
1293 FOLKS_FAVOURITE (persona));
1294 contact_widget_favourites_changed_cb (information->manager,
1295 information->contact, is_favourite, information);
1299 gtk_widget_show (information->label_alias);
1300 gtk_widget_show (information->widget_alias);
1301 gtk_widget_show (information->hbox_presence);
1302 gtk_widget_show (information->widget_avatar);
1306 gtk_widget_hide (information->label_alias);
1307 gtk_widget_hide (information->widget_alias);
1308 gtk_widget_hide (information->hbox_presence);
1309 gtk_widget_hide (information->widget_avatar);
1314 contact_widget_set_contact (EmpathyContactWidget *information,
1315 EmpathyContact *contact)
1317 if (contact == information->contact)
1320 contact_widget_remove_contact (information);
1322 information->contact = g_object_ref (contact);
1324 /* set the selected account to be the account this contact came from */
1325 if (contact && EMPATHY_IS_ACCOUNT_CHOOSER (information->widget_account)) {
1326 empathy_account_chooser_set_account (
1327 EMPATHY_ACCOUNT_CHOOSER (information->widget_account),
1328 empathy_contact_get_account (contact));
1331 /* Update information for widgets */
1332 contact_widget_contact_update (information);
1333 contact_widget_groups_update (information);
1334 contact_widget_details_update (information);
1335 contact_widget_client_update (information);
1336 contact_widget_location_update (information);
1340 contact_widget_got_contact_cb (TpConnection *connection,
1341 EmpathyContact *contact,
1342 const GError *error,
1344 GObject *weak_object)
1346 EmpathyContactWidget *information = user_data;
1350 DEBUG ("Error: %s", error->message);
1354 contact_widget_set_contact (information, contact);
1358 contact_widget_change_contact (EmpathyContactWidget *information)
1360 TpConnection *connection;
1362 connection = empathy_account_chooser_get_connection (
1363 EMPATHY_ACCOUNT_CHOOSER (information->widget_account));
1367 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ID)
1371 id = gtk_entry_get_text (GTK_ENTRY (information->widget_id));
1372 if (!EMP_STR_EMPTY (id))
1374 empathy_tp_contact_factory_get_from_id (connection, id,
1375 contact_widget_got_contact_cb, information, NULL,
1376 G_OBJECT (information->vbox_contact_widget));
1381 empathy_tp_contact_factory_get_from_handle (connection,
1382 tp_connection_get_self_handle (connection),
1383 contact_widget_got_contact_cb, information, NULL,
1384 G_OBJECT (information->vbox_contact_widget));
1389 contact_widget_id_activate_timeout (EmpathyContactWidget *self)
1391 contact_widget_change_contact (self);
1396 contact_widget_id_changed_cb (GtkEntry *entry,
1397 EmpathyContactWidget *self)
1399 if (self->widget_id_timeout != 0)
1401 g_source_remove (self->widget_id_timeout);
1404 self->widget_id_timeout =
1405 g_timeout_add_seconds (ID_CHANGED_TIMEOUT,
1406 (GSourceFunc) contact_widget_id_activate_timeout, self);
1410 contact_widget_id_focus_out_cb (GtkWidget *widget,
1411 GdkEventFocus *event,
1412 EmpathyContactWidget *information)
1414 contact_widget_change_contact (information);
1419 favourite_toggled_cb (GtkToggleButton *button,
1420 EmpathyContactWidget *information)
1422 FolksPersona *persona = empathy_contact_get_persona (information->contact);
1424 if (persona != NULL && FOLKS_IS_FAVOURITE (persona))
1426 gboolean active = gtk_toggle_button_get_active (button);
1427 folks_favourite_set_is_favourite (FOLKS_FAVOURITE (persona), active);
1432 contact_widget_contact_setup (EmpathyContactWidget *information)
1434 information->label_status = gtk_label_new ("");
1435 gtk_label_set_line_wrap_mode (GTK_LABEL (information->label_status),
1436 PANGO_WRAP_WORD_CHAR);
1437 gtk_label_set_line_wrap (GTK_LABEL (information->label_status),
1440 if (!(information->flags & EMPATHY_CONTACT_WIDGET_FOR_TOOLTIP))
1441 gtk_label_set_selectable (GTK_LABEL (information->label_status), TRUE);
1443 gtk_box_pack_start (GTK_BOX (information->hbox_presence),
1444 information->label_status, TRUE, TRUE, 0);
1445 gtk_widget_show (information->label_status);
1447 /* Setup account label/chooser */
1448 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ACCOUNT)
1450 information->widget_account = empathy_account_chooser_new ();
1452 g_signal_connect_swapped (information->widget_account, "changed",
1453 G_CALLBACK (contact_widget_change_contact),
1458 /* Pack the protocol icon with the account name in an hbox */
1459 information->widget_account = gtk_hbox_new (FALSE, 6);
1461 information->label_account = gtk_label_new (NULL);
1462 if (!(information->flags & EMPATHY_CONTACT_WIDGET_FOR_TOOLTIP)) {
1463 gtk_label_set_selectable (GTK_LABEL (information->label_account), TRUE);
1465 gtk_misc_set_alignment (GTK_MISC (information->label_account), 0, 0.5);
1466 gtk_widget_show (information->label_account);
1468 information->image_account = gtk_image_new ();
1469 gtk_widget_show (information->image_account);
1471 gtk_box_pack_start (GTK_BOX (information->widget_account),
1472 information->image_account, FALSE, FALSE, 0);
1473 gtk_box_pack_start (GTK_BOX (information->widget_account),
1474 information->label_account, FALSE, TRUE, 0);
1476 gtk_table_attach_defaults (GTK_TABLE (information->table_contact),
1477 information->widget_account,
1479 gtk_widget_show (information->widget_account);
1481 /* Set up avatar chooser/display */
1482 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_AVATAR)
1484 information->widget_avatar = empathy_avatar_chooser_new ();
1485 g_signal_connect (information->widget_avatar, "changed",
1486 G_CALLBACK (contact_widget_avatar_changed_cb),
1488 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ACCOUNT)
1490 g_signal_connect (information->widget_account, "changed",
1491 G_CALLBACK (update_avatar_chooser_account_cb),
1492 information->widget_avatar);
1493 update_avatar_chooser_account_cb (
1494 EMPATHY_ACCOUNT_CHOOSER (information->widget_account),
1495 EMPATHY_AVATAR_CHOOSER (information->widget_avatar));
1500 information->widget_avatar = empathy_avatar_image_new ();
1502 g_signal_connect (information->widget_avatar, "popup-menu",
1503 G_CALLBACK (widget_avatar_popup_menu_cb), information);
1504 g_signal_connect (information->widget_avatar, "button-press-event",
1505 G_CALLBACK (widget_avatar_button_press_event_cb), information);
1508 gtk_box_pack_start (GTK_BOX (information->vbox_avatar),
1509 information->widget_avatar,
1512 gtk_widget_show (information->widget_avatar);
1514 /* Setup id label/entry */
1515 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ID)
1517 information->widget_id = gtk_entry_new ();
1518 g_signal_connect (information->widget_id, "focus-out-event",
1519 G_CALLBACK (contact_widget_id_focus_out_cb),
1521 g_signal_connect (information->widget_id, "changed",
1522 G_CALLBACK (contact_widget_id_changed_cb),
1527 information->widget_id = gtk_label_new (NULL);
1528 if (!(information->flags & EMPATHY_CONTACT_WIDGET_FOR_TOOLTIP)) {
1529 gtk_label_set_selectable (GTK_LABEL (information->widget_id), TRUE);
1531 gtk_misc_set_alignment (GTK_MISC (information->widget_id), 0, 0.5);
1533 gtk_table_attach_defaults (GTK_TABLE (information->table_contact),
1534 information->widget_id,
1536 gtk_widget_show (information->widget_id);
1538 /* Setup alias label/entry */
1539 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ALIAS)
1541 information->widget_alias = gtk_entry_new ();
1543 if (!(information->flags & EMPATHY_CONTACT_WIDGET_NO_SET_ALIAS))
1544 g_signal_connect (information->widget_alias, "focus-out-event",
1545 G_CALLBACK (contact_widget_entry_alias_focus_event_cb),
1548 /* Make return activate the window default (the Close button) */
1549 gtk_entry_set_activates_default (GTK_ENTRY (information->widget_alias),
1554 information->widget_alias = gtk_label_new (NULL);
1555 if (!(information->flags & EMPATHY_CONTACT_WIDGET_FOR_TOOLTIP)) {
1556 gtk_label_set_selectable (GTK_LABEL (information->widget_alias), TRUE);
1558 gtk_misc_set_alignment (GTK_MISC (information->widget_alias), 0, 0.5);
1560 gtk_table_attach_defaults (GTK_TABLE (information->table_contact),
1561 information->widget_alias,
1563 if (information->flags & EMPATHY_CONTACT_WIDGET_FOR_TOOLTIP) {
1564 gtk_label_set_selectable (GTK_LABEL (information->label_status), FALSE);
1566 gtk_widget_show (information->widget_alias);
1569 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_FAVOURITE)
1571 information->favourite_checkbox = gtk_check_button_new_with_label (
1574 g_signal_connect (information->favourite_checkbox, "toggled",
1575 G_CALLBACK (favourite_toggled_cb), information);
1577 gtk_table_attach_defaults (GTK_TABLE (information->table_contact),
1578 information->favourite_checkbox, 0, 2, 3, 4);
1580 information->fav_sig_id = g_signal_connect (information->manager,
1581 "favourites-changed",
1582 G_CALLBACK (contact_widget_favourites_changed_cb), information);
1584 gtk_widget_show (information->favourite_checkbox);
1589 contact_widget_destroy_cb (GtkWidget *widget,
1590 EmpathyContactWidget *information)
1592 contact_widget_remove_contact (information);
1594 if (information->widget_id_timeout != 0)
1596 g_source_remove (information->widget_id_timeout);
1599 if (information->fav_sig_id != 0)
1600 g_signal_handler_disconnect (information->manager, information->fav_sig_id);
1602 g_object_unref (information->manager);
1604 g_slice_free (EmpathyContactWidget, information);
1608 * empathy_contact_widget_new:
1609 * @contact: an #EmpathyContact
1610 * @flags: #EmpathyContactWidgetFlags for the new contact widget
1612 * Creates a new #EmpathyContactWidget.
1614 * Return value: a new #EmpathyContactWidget
1617 empathy_contact_widget_new (EmpathyContact *contact,
1618 EmpathyContactWidgetFlags flags)
1620 EmpathyContactWidget *information;
1624 g_return_val_if_fail (contact == NULL || EMPATHY_IS_CONTACT (contact), NULL);
1626 information = g_slice_new0 (EmpathyContactWidget);
1627 information->flags = flags;
1629 filename = empathy_file_lookup ("empathy-contact-widget.ui",
1631 gui = empathy_builder_get_file (filename,
1632 "vbox_contact_widget", &information->vbox_contact_widget,
1633 "hbox_contact", &information->hbox_contact,
1634 "hbox_presence", &information->hbox_presence,
1635 "label_alias", &information->label_alias,
1636 "image_state", &information->image_state,
1637 "table_contact", &information->table_contact,
1638 "vbox_avatar", &information->vbox_avatar,
1639 "vbox_location", &information->vbox_location,
1640 "subvbox_location", &information->subvbox_location,
1641 "label_location", &information->label_location,
1642 #ifdef HAVE_LIBCHAMPLAIN
1643 "viewport_map", &information->viewport_map,
1645 "groups_widget", &information->groups_widget,
1646 "vbox_details", &information->vbox_details,
1647 "table_details", &information->table_details,
1648 "hbox_details_requested", &information->hbox_details_requested,
1649 "vbox_client", &information->vbox_client,
1650 "table_client", &information->table_client,
1651 "hbox_client_requested", &information->hbox_client_requested,
1655 empathy_builder_connect (gui, information,
1656 "vbox_contact_widget", "destroy", contact_widget_destroy_cb,
1658 information->table_location = NULL;
1660 g_object_set_data (G_OBJECT (information->vbox_contact_widget),
1661 "EmpathyContactWidget",
1664 information->manager = empathy_contact_manager_dup_singleton ();
1666 /* Create widgets */
1667 contact_widget_contact_setup (information);
1668 contact_widget_details_setup (information);
1669 contact_widget_client_setup (information);
1671 if (contact != NULL)
1672 contact_widget_set_contact (information, contact);
1673 else if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ACCOUNT ||
1674 information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ID)
1675 contact_widget_change_contact (information);
1677 return empathy_builder_unref_and_keep_widget (gui,
1678 information->vbox_contact_widget);
1682 * empathy_contact_widget_get_contact:
1683 * @widget: an #EmpathyContactWidget
1685 * Get the #EmpathyContact related with the #EmpathyContactWidget @widget.
1687 * Returns: the #EmpathyContact associated with @widget
1690 empathy_contact_widget_get_contact (GtkWidget *widget)
1692 EmpathyContactWidget *information;
1694 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
1696 information = g_object_get_data (G_OBJECT (widget), "EmpathyContactWidget");
1700 return information->contact;
1704 empathy_contact_widget_get_alias (GtkWidget *widget)
1706 EmpathyContactWidget *information;
1708 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
1710 information = g_object_get_data (G_OBJECT (widget), "EmpathyContactWidget");
1714 return gtk_entry_get_text (GTK_ENTRY (information->widget_alias));
1718 * empathy_contact_widget_set_contact:
1719 * @widget: an #EmpathyContactWidget
1720 * @contact: a different #EmpathyContact
1722 * Change the #EmpathyContact related with the #EmpathyContactWidget @widget.
1725 empathy_contact_widget_set_contact (GtkWidget *widget,
1726 EmpathyContact *contact)
1728 EmpathyContactWidget *information;
1730 g_return_if_fail (GTK_IS_WIDGET (widget));
1731 g_return_if_fail (EMPATHY_IS_CONTACT (contact));
1733 information = g_object_get_data (G_OBJECT (widget), "EmpathyContactWidget");
1737 contact_widget_set_contact (information, contact);
1741 * empathy_contact_widget_set_account_filter:
1742 * @widget: an #EmpathyContactWidget
1743 * @filter: a #EmpathyAccountChooserFilterFunc
1744 * @user_data: user data to pass to @filter, or %NULL
1746 * Set a filter on the #EmpathyAccountChooser included in the
1747 * #EmpathyContactWidget.
1750 empathy_contact_widget_set_account_filter (
1752 EmpathyAccountChooserFilterFunc filter,
1755 EmpathyContactWidget *information;
1756 EmpathyAccountChooser *chooser;
1758 g_return_if_fail (GTK_IS_WIDGET (widget));
1760 information = g_object_get_data (G_OBJECT (widget), "EmpathyContactWidget");
1764 chooser = EMPATHY_ACCOUNT_CHOOSER (information->widget_account);
1766 empathy_account_chooser_set_filter (chooser, filter, user_data);