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_info_field_spec_cmp (TpContactInfoFieldSpec *spec1,
303 TpContactInfoFieldSpec *spec2)
305 return contact_info_field_name_cmp (spec1->name, spec2->name);
309 field_spec_match_field (TpContactInfoFieldSpec *spec,
310 TpContactInfoField *field)
314 if (tp_strdiff (field->field_name, spec->name))
317 if (g_strv_length (field->parameters) != g_strv_length (spec->parameters))
320 for (i = 0; field->parameters[i] != NULL; i++)
322 if (tp_strdiff (field->parameters[i], spec->parameters[i]))
330 contact_widget_details_update_edit (EmpathyContactWidget *information)
333 TpConnection *connection;
338 g_assert (information->details_to_set == NULL);
340 contact = empathy_contact_get_tp_contact (information->contact);
341 connection = tp_contact_get_connection (contact);
342 info = tp_contact_get_contact_info (contact);
344 specs = tp_connection_get_contact_info_supported_fields (connection);
345 specs = g_list_sort (specs, (GCompareFunc) contact_info_field_spec_cmp);
346 for (l = specs; l != NULL; l = l->next)
348 TpContactInfoFieldSpec *spec = l->data;
349 TpContactInfoField *field = NULL;
350 InfoFieldData *field_data;
354 field_data = find_info_field_data (spec->name);
355 if (field_data == NULL)
357 DEBUG ("Unhandled ContactInfo field spec: %s", spec->name);
360 /* Search initial value */
361 for (ll = info; ll != NULL && field == NULL; ll = ll->next)
363 TpContactInfoField *tmp = ll->data;
365 if (field_spec_match_field (spec, tmp))
371 /* We found the field, make a copy for the details_to_set list */
372 field = tp_contact_info_field_copy (field);
373 DEBUG ("Field %s is in our vCard", spec->name);
377 /* Empathy doesn't support editing this field and it's not in the
378 * contact's fields so we can't do much with it. */
379 DEBUG ("Field %s is not in our vCard", spec->name);
381 if (field_data == NULL)
384 field = tp_contact_info_field_new (spec->name, spec->parameters,
388 information->details_to_set = g_list_prepend (information->details_to_set,
391 /* Empathy doesn't display this field so we can't change it. But we put
392 * it in the details_to_set list so it won't be erased when calling
393 * SetContactInfo (bgo #630427) */
394 if (field_data == NULL)
398 w = gtk_label_new (_(field_data->title));
399 gtk_table_attach (GTK_TABLE (information->table_details),
400 w, 0, 1, n_rows, n_rows + 1, GTK_FILL, 0, 0, 0);
401 gtk_misc_set_alignment (GTK_MISC (w), 0, 0.5);
405 w = gtk_entry_new ();
406 gtk_entry_set_text (GTK_ENTRY (w),
407 field->field_value[0] ? field->field_value[0] : "");
408 gtk_table_attach_defaults (GTK_TABLE (information->table_details),
409 w, 1, 2, n_rows, n_rows + 1);
412 g_signal_connect (w, "changed",
413 G_CALLBACK (contact_widget_details_changed_cb), field);
424 contact_widget_details_update_show (EmpathyContactWidget *information)
430 contact = empathy_contact_get_tp_contact (information->contact);
431 info = tp_contact_get_contact_info (contact);
432 info = g_list_sort (info, (GCompareFunc) contact_info_field_cmp);
433 for (l = info; l != NULL; l = l->next)
435 TpContactInfoField *field = l->data;
436 InfoFieldData *field_data;
440 if (field->field_value == NULL || field->field_value[0] == NULL)
443 value = field->field_value[0];
445 field_data = find_info_field_data (field->field_name);
446 if (field_data == NULL)
448 DEBUG ("Unhandled ContactInfo field: %s", field->field_name);
453 w = gtk_label_new (_(field_data->title));
454 gtk_table_attach (GTK_TABLE (information->table_details),
455 w, 0, 1, n_rows, n_rows + 1, GTK_FILL, 0, 0, 0);
456 gtk_misc_set_alignment (GTK_MISC (w), 0, 0.5);
460 w = gtk_label_new (value);
461 if (field_data->linkify)
465 markup = empathy_add_link_markup (value);
466 gtk_label_set_markup (GTK_LABEL (w), markup);
470 if ((information->flags & EMPATHY_CONTACT_WIDGET_FOR_TOOLTIP) == 0)
471 gtk_label_set_selectable (GTK_LABEL (w), TRUE);
473 gtk_table_attach_defaults (GTK_TABLE (information->table_details),
474 w, 1, 2, n_rows, n_rows + 1);
475 gtk_misc_set_alignment (GTK_MISC (w), 0, 0.5);
486 contact_widget_details_notify_cb (EmpathyContactWidget *information)
490 gtk_container_foreach (GTK_CONTAINER (information->table_details),
491 (GtkCallback) gtk_widget_destroy, NULL);
493 if ((information->flags & EMPATHY_CONTACT_WIDGET_EDIT_DETAILS) != 0)
494 n_rows = contact_widget_details_update_edit (information);
496 n_rows = contact_widget_details_update_show (information);
500 gtk_widget_show (information->vbox_details);
501 gtk_widget_show (information->table_details);
505 gtk_widget_hide (information->vbox_details);
508 gtk_widget_hide (information->hbox_details_requested);
509 gtk_spinner_stop (GTK_SPINNER (information->spinner_details));
513 contact_widget_details_request_cb (GObject *object,
517 TpContact *contact = TP_CONTACT (object);
518 EmpathyContactWidget *information = user_data;
519 GError *error = NULL;
521 if (!tp_contact_request_contact_info_finish (contact, res, &error))
523 /* If the request got cancelled it could mean the contact widget is
524 * destroyed, so we should not dereference information */
525 if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
527 g_clear_error (&error);
531 gtk_widget_hide (information->vbox_details);
532 g_clear_error (&error);
536 contact_widget_details_notify_cb (information);
539 /* If we are going to edit ContactInfo, we don't want live updates */
540 if ((information->flags & EMPATHY_CONTACT_WIDGET_EDIT_DETAILS) == 0)
542 g_signal_connect_swapped (contact, "notify::contact-info",
543 G_CALLBACK (contact_widget_details_notify_cb), information);
546 tp_clear_object (&information->details_cancellable);
550 contact_widget_details_feature_prepared_cb (GObject *object,
554 TpConnection *connection = TP_CONNECTION (object);
555 EmpathyContactWidget *information = user_data;
557 TpContactInfoFlags flags;
559 if (!tp_proxy_prepare_finish (connection, res, NULL))
561 gtk_widget_hide (information->vbox_details);
565 /* If we want to edit info, but connection does not support that, stop */
566 flags = tp_connection_get_contact_info_flags (connection);
567 if ((flags & TP_CONTACT_INFO_FLAG_CAN_SET) == 0 &&
568 (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_DETAILS) != 0)
570 gtk_widget_hide (information->vbox_details);
574 /* Request the contact's info */
575 gtk_widget_show (information->vbox_details);
576 gtk_widget_show (information->hbox_details_requested);
577 gtk_widget_hide (information->table_details);
578 gtk_spinner_start (GTK_SPINNER (information->spinner_details));
580 contact = empathy_contact_get_tp_contact (information->contact);
581 g_assert (information->details_cancellable == NULL);
582 information->details_cancellable = g_cancellable_new ();
583 tp_contact_request_contact_info_async (contact,
584 information->details_cancellable, contact_widget_details_request_cb,
589 contact_widget_details_update (EmpathyContactWidget *information)
591 TpContact *tp_contact = NULL;
593 if ((information->flags & EMPATHY_CONTACT_WIDGET_SHOW_DETAILS) == 0 &&
594 (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_DETAILS) == 0)
597 gtk_widget_hide (information->vbox_details);
599 if (information->contact != NULL)
600 tp_contact = empathy_contact_get_tp_contact (information->contact);
602 if (tp_contact != NULL)
604 GQuark features[] = { TP_CONNECTION_FEATURE_CONTACT_INFO, 0 };
605 TpConnection *connection;
607 /* First, make sure the CONTACT_INFO feature is ready on the connection */
608 connection = tp_contact_get_connection (tp_contact);
609 tp_proxy_prepare_async (connection, features,
610 contact_widget_details_feature_prepared_cb, information);
615 contact_widget_client_update (EmpathyContactWidget *information)
617 /* FIXME: Needs new telepathy spec */
621 contact_widget_client_setup (EmpathyContactWidget *information)
623 /* FIXME: Needs new telepathy spec */
624 gtk_widget_hide (information->vbox_client);
628 contact_widget_groups_update (EmpathyContactWidget *information)
630 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_GROUPS &&
631 information->contact != NULL)
633 FolksPersona *persona =
634 empathy_contact_get_persona (information->contact);
636 if (FOLKS_IS_GROUPABLE (persona))
638 empathy_groups_widget_set_groupable (
639 EMPATHY_GROUPS_WIDGET (information->groups_widget),
640 FOLKS_GROUPABLE (persona));
641 gtk_widget_show (information->groups_widget);
647 /* In case of failure */
648 gtk_widget_hide (information->groups_widget);
651 /* Converts the Location's GHashTable's key to a user readable string */
653 location_key_to_label (const gchar *key)
655 if (tp_strdiff (key, EMPATHY_LOCATION_COUNTRY_CODE) == FALSE)
656 return _("Country ISO Code:");
657 else if (tp_strdiff (key, EMPATHY_LOCATION_COUNTRY) == FALSE)
658 return _("Country:");
659 else if (tp_strdiff (key, EMPATHY_LOCATION_REGION) == FALSE)
661 else if (tp_strdiff (key, EMPATHY_LOCATION_LOCALITY) == FALSE)
663 else if (tp_strdiff (key, EMPATHY_LOCATION_AREA) == FALSE)
665 else if (tp_strdiff (key, EMPATHY_LOCATION_POSTAL_CODE) == FALSE)
666 return _("Postal Code:");
667 else if (tp_strdiff (key, EMPATHY_LOCATION_STREET) == FALSE)
669 else if (tp_strdiff (key, EMPATHY_LOCATION_BUILDING) == FALSE)
670 return _("Building:");
671 else if (tp_strdiff (key, EMPATHY_LOCATION_FLOOR) == FALSE)
673 else if (tp_strdiff (key, EMPATHY_LOCATION_ROOM) == FALSE)
675 else if (tp_strdiff (key, EMPATHY_LOCATION_TEXT) == FALSE)
677 else if (tp_strdiff (key, EMPATHY_LOCATION_DESCRIPTION) == FALSE)
678 return _("Description:");
679 else if (tp_strdiff (key, EMPATHY_LOCATION_URI) == FALSE)
681 else if (tp_strdiff (key, EMPATHY_LOCATION_ACCURACY_LEVEL) == FALSE)
682 return _("Accuracy Level:");
683 else if (tp_strdiff (key, EMPATHY_LOCATION_ERROR) == FALSE)
685 else if (tp_strdiff (key, EMPATHY_LOCATION_VERTICAL_ERROR_M) == FALSE)
686 return _("Vertical Error (meters):");
687 else if (tp_strdiff (key, EMPATHY_LOCATION_HORIZONTAL_ERROR_M) == FALSE)
688 return _("Horizontal Error (meters):");
689 else if (tp_strdiff (key, EMPATHY_LOCATION_SPEED) == FALSE)
691 else if (tp_strdiff (key, EMPATHY_LOCATION_BEARING) == FALSE)
692 return _("Bearing:");
693 else if (tp_strdiff (key, EMPATHY_LOCATION_CLIMB) == FALSE)
694 return _("Climb Speed:");
695 else if (tp_strdiff (key, EMPATHY_LOCATION_TIMESTAMP) == FALSE)
696 return _("Last Updated on:");
697 else if (tp_strdiff (key, EMPATHY_LOCATION_LON) == FALSE)
698 return _("Longitude:");
699 else if (tp_strdiff (key, EMPATHY_LOCATION_LAT) == FALSE)
700 return _("Latitude:");
701 else if (tp_strdiff (key, EMPATHY_LOCATION_ALT) == FALSE)
702 return _("Altitude:");
705 DEBUG ("Unexpected Location key: %s", key);
711 contact_widget_location_update (EmpathyContactWidget *information)
713 GHashTable *location;
715 gdouble lat = 0.0, lon = 0.0;
716 gboolean has_position = TRUE;
719 static const gchar* ordered_geolocation_keys[] = {
720 EMPATHY_LOCATION_TEXT,
721 EMPATHY_LOCATION_URI,
722 EMPATHY_LOCATION_DESCRIPTION,
723 EMPATHY_LOCATION_BUILDING,
724 EMPATHY_LOCATION_FLOOR,
725 EMPATHY_LOCATION_ROOM,
726 EMPATHY_LOCATION_STREET,
727 EMPATHY_LOCATION_AREA,
728 EMPATHY_LOCATION_LOCALITY,
729 EMPATHY_LOCATION_REGION,
730 EMPATHY_LOCATION_COUNTRY,
735 gboolean display_map = FALSE;
737 if (!(information->flags & EMPATHY_CONTACT_WIDGET_SHOW_LOCATION))
739 gtk_widget_hide (information->vbox_location);
743 location = empathy_contact_get_location (information->contact);
744 if (location == NULL || g_hash_table_size (location) == 0)
746 gtk_widget_hide (information->vbox_location);
750 value = g_hash_table_lookup (location, EMPATHY_LOCATION_LAT);
752 has_position = FALSE;
754 lat = g_value_get_double (value);
756 value = g_hash_table_lookup (location, EMPATHY_LOCATION_LON);
758 has_position = FALSE;
760 lon = g_value_get_double (value);
762 value = g_hash_table_lookup (location, EMPATHY_LOCATION_TIMESTAMP);
765 gchar *loc = g_strdup_printf ("<b>%s</b>", _("Location"));
766 gtk_label_set_markup (GTK_LABEL (information->label_location), loc);
777 stamp = g_value_get_int64 (value);
780 user_date = empathy_time_to_string_relative (time_);
782 tmp = g_strdup_printf ("<b>%s</b>", _("Location"));
783 /* translators: format is "Location, $date" */
784 text = g_strdup_printf (_("%s, %s"), tmp, user_date);
786 gtk_label_set_markup (GTK_LABEL (information->label_location), text);
792 /* Prepare the location information table */
793 if (information->table_location != NULL)
795 gtk_widget_destroy (information->table_location);
798 information->table_location = gtk_table_new (1, 2, FALSE);
799 gtk_box_pack_start (GTK_BOX (information->subvbox_location),
800 information->table_location, FALSE, FALSE, 5);
803 for (i = 0; (skey = ordered_geolocation_keys[i]); i++)
805 const gchar* user_label;
809 gvalue = g_hash_table_lookup (location, (gpointer) skey);
813 user_label = location_key_to_label (skey);
815 label = gtk_label_new (user_label);
816 gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
817 gtk_table_attach (GTK_TABLE (information->table_location),
818 label, 0, 1, row, row + 1, GTK_FILL, GTK_FILL, 10, 0);
819 gtk_widget_show (label);
821 if (G_VALUE_TYPE (gvalue) == G_TYPE_DOUBLE)
824 dvalue = g_value_get_double (gvalue);
825 svalue = g_strdup_printf ("%f", dvalue);
827 else if (G_VALUE_TYPE (gvalue) == G_TYPE_STRING)
829 svalue = g_value_dup_string (gvalue);
831 else if (G_VALUE_TYPE (gvalue) == G_TYPE_INT64)
835 time_ = g_value_get_int64 (value);
836 svalue = empathy_time_to_string_utc (time_, _("%B %e, %Y at %R UTC"));
841 label = gtk_label_new (svalue);
842 gtk_table_attach_defaults (GTK_TABLE (information->table_location),
843 label, 1, 2, row, row + 1);
844 gtk_misc_set_alignment (GTK_MISC (label), 0, 0);
845 gtk_widget_show (label);
847 if (!(information->flags & EMPATHY_CONTACT_WIDGET_FOR_TOOLTIP))
848 gtk_label_set_selectable (GTK_LABEL (label), TRUE);
855 #ifdef HAVE_LIBCHAMPLAIN
857 !(information->flags & EMPATHY_CONTACT_WIDGET_FOR_TOOLTIP))
859 /* Cannot be displayed in tooltips until Clutter-Gtk can deal with such
867 /* We can display some fields */
868 gtk_widget_show (information->table_location);
870 else if (!display_map)
872 /* Can't display either fields or map */
873 gtk_widget_hide (information->vbox_location);
877 #ifdef HAVE_LIBCHAMPLAIN
880 ClutterActor *marker;
881 ChamplainLayer *layer;
883 information->map_view_embed = gtk_champlain_embed_new ();
884 information->map_view = gtk_champlain_embed_get_view (
885 GTK_CHAMPLAIN_EMBED (information->map_view_embed));
887 gtk_container_add (GTK_CONTAINER (information->viewport_map),
888 information->map_view_embed);
889 g_object_set (G_OBJECT (information->map_view),
890 "show-license", TRUE,
891 "scroll-mode", CHAMPLAIN_SCROLL_MODE_KINETIC,
895 layer = champlain_layer_new ();
896 champlain_view_add_layer (information->map_view, layer);
898 marker = champlain_marker_new_with_text (
899 empathy_contact_get_alias (information->contact), NULL, NULL, NULL);
900 champlain_base_marker_set_position (CHAMPLAIN_BASE_MARKER (marker), lat, lon);
901 clutter_container_add (CLUTTER_CONTAINER (layer), marker, NULL);
903 champlain_view_center_on (information->map_view, lat, lon);
904 gtk_widget_show_all (information->viewport_map);
908 gtk_widget_show (information->vbox_location);
912 save_avatar_menu_activate_cb (GtkWidget *widget,
913 EmpathyContactWidget *information)
916 EmpathyAvatar *avatar;
917 gchar *ext = NULL, *filename;
919 dialog = gtk_file_chooser_dialog_new (_("Save Avatar"),
921 GTK_FILE_CHOOSER_ACTION_SAVE,
922 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
923 GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT,
926 gtk_file_chooser_set_do_overwrite_confirmation (GTK_FILE_CHOOSER (dialog),
929 /* look for the avatar extension */
930 avatar = empathy_contact_get_avatar (information->contact);
931 if (avatar->format != NULL)
935 splitted = g_strsplit (avatar->format, "/", 2);
936 if (splitted[0] != NULL && splitted[1] != NULL)
937 ext = g_strdup (splitted[1]);
939 g_strfreev (splitted);
943 /* Avatar was loaded from the cache so was converted to PNG */
944 ext = g_strdup ("png");
951 id = tp_escape_as_identifier (empathy_contact_get_id (
952 information->contact));
954 filename = g_strdup_printf ("%s.%s", id, ext);
955 gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (dialog), filename);
962 if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT)
964 GError *error = NULL;
966 filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
968 if (!empathy_avatar_save_to_file (avatar, filename, &error))
971 GtkWidget *error_dialog;
973 error_dialog = gtk_message_dialog_new (NULL, 0,
974 GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE,
975 _("Unable to save avatar"));
977 gtk_message_dialog_format_secondary_text (
978 GTK_MESSAGE_DIALOG (error_dialog), "%s", error->message);
980 g_signal_connect (error_dialog, "response",
981 G_CALLBACK (gtk_widget_destroy), NULL);
983 gtk_window_present (GTK_WINDOW (error_dialog));
985 g_clear_error (&error);
991 gtk_widget_destroy (dialog);
995 popup_avatar_menu (EmpathyContactWidget *information,
997 GdkEventButton *event)
999 GtkWidget *menu, *item;
1000 gint button, event_time;
1002 if (information->contact == NULL ||
1003 empathy_contact_get_avatar (information->contact) == NULL)
1006 menu = gtk_menu_new ();
1008 /* Add "Save as..." entry */
1009 item = gtk_image_menu_item_new_from_stock (GTK_STOCK_SAVE_AS, NULL);
1010 gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
1011 gtk_widget_show (item);
1013 g_signal_connect (item, "activate",
1014 G_CALLBACK (save_avatar_menu_activate_cb), information);
1018 button = event->button;
1019 event_time = event->time;
1024 event_time = gtk_get_current_event_time ();
1027 gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
1028 button, event_time);
1029 g_object_ref_sink (menu);
1030 g_object_unref (menu);
1034 widget_avatar_popup_menu_cb (GtkWidget *widget,
1035 EmpathyContactWidget *information)
1037 popup_avatar_menu (information, widget, NULL);
1043 widget_avatar_button_press_event_cb (GtkWidget *widget,
1044 GdkEventButton *event,
1045 EmpathyContactWidget *information)
1047 /* Ignore double-clicks and triple-clicks */
1048 if (event->button == 3 && event->type == GDK_BUTTON_PRESS)
1050 popup_avatar_menu (information, widget, event);
1058 set_avatar_cb (GObject *source,
1062 GError *error = NULL;
1064 if (!tp_account_set_avatar_finish (TP_ACCOUNT (source), res, &error)) {
1065 DEBUG ("Failed to set Account.Avatar: %s", error->message);
1066 g_error_free (error);
1071 set_avatar_on_account (TpAccount *account,
1074 const gchar *mime_type)
1076 DEBUG ("%s Account.Avatar on %s", size > 0 ? "Set": "Clear",
1077 tp_proxy_get_object_path (account));
1079 tp_account_set_avatar_async (account, (const guchar *) data, size,
1080 mime_type, set_avatar_cb, NULL);
1084 contact_widget_avatar_changed_cb (EmpathyAvatarChooser *chooser,
1085 EmpathyContactWidget *information)
1089 const gchar *mime_type;
1092 empathy_avatar_chooser_get_image_data (
1093 EMPATHY_AVATAR_CHOOSER (information->widget_avatar),
1094 &data, &size, &mime_type);
1096 account = empathy_contact_get_account (information->contact);
1097 set_avatar_on_account (account, data, size, mime_type);
1101 set_nickname_cb (GObject *source,
1105 GError *error = NULL;
1107 if (!tp_account_set_nickname_finish (TP_ACCOUNT (source), res, &error))
1109 DEBUG ("Failed to set Account.Nickname: %s", error->message);
1110 g_error_free (error);
1115 set_alias_on_account (TpAccount *account,
1118 DEBUG ("Set Account.Nickname to %s", alias);
1120 tp_account_set_nickname_async (account, alias, set_nickname_cb, NULL);
1124 contact_widget_entry_alias_focus_event_cb (GtkEditable *editable,
1125 GdkEventFocus *event,
1126 EmpathyContactWidget *information)
1128 if (information->contact)
1132 alias = gtk_entry_get_text (GTK_ENTRY (editable));
1134 if (empathy_contact_is_user (information->contact))
1136 TpAccount * account;
1138 account = empathy_contact_get_account (information->contact);
1139 set_alias_on_account (account, alias);
1143 empathy_contact_set_alias (information->contact, alias);
1151 update_avatar_chooser_account_cb (EmpathyAccountChooser *account_chooser,
1152 EmpathyAvatarChooser *avatar_chooser)
1156 account = empathy_account_chooser_get_account (account_chooser);
1157 if (account == NULL)
1160 empathy_avatar_chooser_set_account (avatar_chooser, account);
1164 contact_widget_avatar_notify_cb (EmpathyContactWidget *information)
1166 EmpathyAvatar *avatar = NULL;
1168 if (information->contact)
1169 avatar = empathy_contact_get_avatar (information->contact);
1171 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_AVATAR)
1173 g_signal_handlers_block_by_func (information->widget_avatar,
1174 contact_widget_avatar_changed_cb,
1176 empathy_avatar_chooser_set (
1177 EMPATHY_AVATAR_CHOOSER (information->widget_avatar), avatar);
1178 g_signal_handlers_unblock_by_func (information->widget_avatar,
1179 contact_widget_avatar_changed_cb, information);
1182 empathy_avatar_image_set (
1183 EMPATHY_AVATAR_IMAGE (information->widget_avatar), avatar);
1187 contact_widget_name_notify_cb (EmpathyContactWidget *information)
1189 if (GTK_IS_ENTRY (information->widget_alias))
1190 gtk_entry_set_text (GTK_ENTRY (information->widget_alias),
1191 empathy_contact_get_alias (information->contact));
1193 gtk_label_set_label (GTK_LABEL (information->widget_alias),
1194 empathy_contact_get_alias (information->contact));
1198 contact_widget_presence_notify_cb (EmpathyContactWidget *information)
1200 const gchar *status;
1201 gchar *markup_text = NULL;
1203 status = empathy_contact_get_status (information->contact);
1205 markup_text = empathy_add_link_markup (status);
1206 gtk_label_set_markup (GTK_LABEL (information->label_status), markup_text);
1207 g_free (markup_text);
1209 gtk_image_set_from_icon_name (GTK_IMAGE (information->image_state),
1210 empathy_icon_name_for_contact (information->contact),
1211 GTK_ICON_SIZE_BUTTON);
1212 gtk_widget_show (information->image_state);
1216 contact_widget_favourites_changed_cb (EmpathyContactManager *manager,
1217 EmpathyContact *contact,
1218 gboolean is_favourite,
1219 EmpathyContactWidget *information)
1221 if (contact != information->contact)
1224 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (
1225 information->favourite_checkbox), is_favourite);
1229 contact_widget_remove_contact (EmpathyContactWidget *information)
1231 if (information->contact)
1233 TpContact *tp_contact;
1235 contact_widget_save (information);
1237 g_signal_handlers_disconnect_by_func (information->contact,
1238 contact_widget_name_notify_cb, information);
1239 g_signal_handlers_disconnect_by_func (information->contact,
1240 contact_widget_presence_notify_cb, information);
1241 g_signal_handlers_disconnect_by_func (information->contact,
1242 contact_widget_avatar_notify_cb, information);
1244 tp_contact = empathy_contact_get_tp_contact (information->contact);
1245 if (tp_contact != NULL)
1247 g_signal_handlers_disconnect_by_func (tp_contact,
1248 contact_widget_details_notify_cb, information);
1251 g_object_unref (information->contact);
1252 information->contact = NULL;
1255 if (information->details_cancellable != NULL)
1257 g_cancellable_cancel (information->details_cancellable);
1258 tp_clear_object (&information->details_cancellable);
1262 static void contact_widget_change_contact (EmpathyContactWidget *information);
1265 contact_widget_contact_update (EmpathyContactWidget *information)
1267 TpAccount *account = NULL;
1268 const gchar *id = NULL;
1270 /* Connect and get info from new contact */
1271 if (information->contact)
1273 g_signal_connect_swapped (information->contact, "notify::name",
1274 G_CALLBACK (contact_widget_name_notify_cb), information);
1275 g_signal_connect_swapped (information->contact, "notify::presence",
1276 G_CALLBACK (contact_widget_presence_notify_cb), information);
1277 g_signal_connect_swapped (information->contact,
1278 "notify::presence-message",
1279 G_CALLBACK (contact_widget_presence_notify_cb), information);
1280 g_signal_connect_swapped (information->contact, "notify::avatar",
1281 G_CALLBACK (contact_widget_avatar_notify_cb), information);
1283 account = empathy_contact_get_account (information->contact);
1284 id = empathy_contact_get_id (information->contact);
1287 /* Update account widget */
1288 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ACCOUNT)
1292 g_signal_handlers_block_by_func (information->widget_account,
1293 contact_widget_change_contact,
1295 empathy_account_chooser_set_account (
1296 EMPATHY_ACCOUNT_CHOOSER (information->widget_account), account);
1297 g_signal_handlers_unblock_by_func (information->widget_account,
1298 contact_widget_change_contact, information);
1307 name = tp_account_get_display_name (account);
1308 gtk_label_set_label (GTK_LABEL (information->label_account), name);
1310 name = tp_account_get_icon_name (account);
1311 gtk_image_set_from_icon_name (GTK_IMAGE (information->image_account),
1312 name, GTK_ICON_SIZE_MENU);
1316 /* Update id widget */
1317 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ID)
1318 gtk_entry_set_text (GTK_ENTRY (information->widget_id), id ? id : "");
1320 gtk_label_set_label (GTK_LABEL (information->widget_id), id ? id : "");
1322 /* Update other widgets */
1323 if (information->contact)
1325 contact_widget_name_notify_cb (information);
1326 contact_widget_presence_notify_cb (information);
1327 contact_widget_avatar_notify_cb (information);
1329 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_FAVOURITE)
1331 FolksPersona *persona = empathy_contact_get_persona (
1332 information->contact);
1334 if (persona != NULL && FOLKS_IS_FAVOURITE (persona))
1336 gboolean is_favourite = folks_favourite_get_is_favourite (
1337 FOLKS_FAVOURITE (persona));
1338 contact_widget_favourites_changed_cb (information->manager,
1339 information->contact, is_favourite, information);
1343 gtk_widget_show (information->label_alias);
1344 gtk_widget_show (information->widget_alias);
1345 gtk_widget_show (information->hbox_presence);
1346 gtk_widget_show (information->widget_avatar);
1350 gtk_widget_hide (information->label_alias);
1351 gtk_widget_hide (information->widget_alias);
1352 gtk_widget_hide (information->hbox_presence);
1353 gtk_widget_hide (information->widget_avatar);
1358 contact_widget_set_contact (EmpathyContactWidget *information,
1359 EmpathyContact *contact)
1361 if (contact == information->contact)
1364 contact_widget_remove_contact (information);
1366 information->contact = g_object_ref (contact);
1368 /* set the selected account to be the account this contact came from */
1369 if (contact && EMPATHY_IS_ACCOUNT_CHOOSER (information->widget_account)) {
1370 empathy_account_chooser_set_account (
1371 EMPATHY_ACCOUNT_CHOOSER (information->widget_account),
1372 empathy_contact_get_account (contact));
1375 /* Update information for widgets */
1376 contact_widget_contact_update (information);
1377 contact_widget_groups_update (information);
1378 contact_widget_details_update (information);
1379 contact_widget_client_update (information);
1380 contact_widget_location_update (information);
1384 contact_widget_got_contact_cb (TpConnection *connection,
1385 EmpathyContact *contact,
1386 const GError *error,
1388 GObject *weak_object)
1390 EmpathyContactWidget *information = user_data;
1394 DEBUG ("Error: %s", error->message);
1398 contact_widget_set_contact (information, contact);
1402 contact_widget_change_contact (EmpathyContactWidget *information)
1404 TpConnection *connection;
1406 connection = empathy_account_chooser_get_connection (
1407 EMPATHY_ACCOUNT_CHOOSER (information->widget_account));
1411 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ID)
1415 id = gtk_entry_get_text (GTK_ENTRY (information->widget_id));
1416 if (!EMP_STR_EMPTY (id))
1418 empathy_tp_contact_factory_get_from_id (connection, id,
1419 contact_widget_got_contact_cb, information, NULL,
1420 G_OBJECT (information->vbox_contact_widget));
1425 empathy_tp_contact_factory_get_from_handle (connection,
1426 tp_connection_get_self_handle (connection),
1427 contact_widget_got_contact_cb, information, NULL,
1428 G_OBJECT (information->vbox_contact_widget));
1433 contact_widget_id_activate_timeout (EmpathyContactWidget *self)
1435 contact_widget_change_contact (self);
1440 contact_widget_id_changed_cb (GtkEntry *entry,
1441 EmpathyContactWidget *self)
1443 if (self->widget_id_timeout != 0)
1445 g_source_remove (self->widget_id_timeout);
1448 self->widget_id_timeout =
1449 g_timeout_add_seconds (ID_CHANGED_TIMEOUT,
1450 (GSourceFunc) contact_widget_id_activate_timeout, self);
1454 contact_widget_id_focus_out_cb (GtkWidget *widget,
1455 GdkEventFocus *event,
1456 EmpathyContactWidget *information)
1458 contact_widget_change_contact (information);
1463 favourite_toggled_cb (GtkToggleButton *button,
1464 EmpathyContactWidget *information)
1466 FolksPersona *persona = empathy_contact_get_persona (information->contact);
1468 if (persona != NULL && FOLKS_IS_FAVOURITE (persona))
1470 gboolean active = gtk_toggle_button_get_active (button);
1471 folks_favourite_set_is_favourite (FOLKS_FAVOURITE (persona), active);
1476 contact_widget_contact_setup (EmpathyContactWidget *information)
1478 information->label_status = gtk_label_new ("");
1479 gtk_label_set_line_wrap_mode (GTK_LABEL (information->label_status),
1480 PANGO_WRAP_WORD_CHAR);
1481 gtk_label_set_line_wrap (GTK_LABEL (information->label_status),
1484 if (!(information->flags & EMPATHY_CONTACT_WIDGET_FOR_TOOLTIP))
1485 gtk_label_set_selectable (GTK_LABEL (information->label_status), TRUE);
1487 gtk_box_pack_start (GTK_BOX (information->hbox_presence),
1488 information->label_status, TRUE, TRUE, 0);
1489 gtk_widget_show (information->label_status);
1491 /* Setup account label/chooser */
1492 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ACCOUNT)
1494 information->widget_account = empathy_account_chooser_new ();
1496 g_signal_connect_swapped (information->widget_account, "changed",
1497 G_CALLBACK (contact_widget_change_contact),
1502 /* Pack the protocol icon with the account name in an hbox */
1503 information->widget_account = gtk_hbox_new (FALSE, 6);
1505 information->label_account = gtk_label_new (NULL);
1506 if (!(information->flags & EMPATHY_CONTACT_WIDGET_FOR_TOOLTIP)) {
1507 gtk_label_set_selectable (GTK_LABEL (information->label_account), TRUE);
1509 gtk_misc_set_alignment (GTK_MISC (information->label_account), 0, 0.5);
1510 gtk_widget_show (information->label_account);
1512 information->image_account = gtk_image_new ();
1513 gtk_widget_show (information->image_account);
1515 gtk_box_pack_start (GTK_BOX (information->widget_account),
1516 information->image_account, FALSE, FALSE, 0);
1517 gtk_box_pack_start (GTK_BOX (information->widget_account),
1518 information->label_account, FALSE, TRUE, 0);
1520 gtk_table_attach_defaults (GTK_TABLE (information->table_contact),
1521 information->widget_account,
1523 gtk_widget_show (information->widget_account);
1525 /* Set up avatar chooser/display */
1526 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_AVATAR)
1528 information->widget_avatar = empathy_avatar_chooser_new ();
1529 g_signal_connect (information->widget_avatar, "changed",
1530 G_CALLBACK (contact_widget_avatar_changed_cb),
1532 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ACCOUNT)
1534 g_signal_connect (information->widget_account, "changed",
1535 G_CALLBACK (update_avatar_chooser_account_cb),
1536 information->widget_avatar);
1537 update_avatar_chooser_account_cb (
1538 EMPATHY_ACCOUNT_CHOOSER (information->widget_account),
1539 EMPATHY_AVATAR_CHOOSER (information->widget_avatar));
1544 information->widget_avatar = empathy_avatar_image_new ();
1546 g_signal_connect (information->widget_avatar, "popup-menu",
1547 G_CALLBACK (widget_avatar_popup_menu_cb), information);
1548 g_signal_connect (information->widget_avatar, "button-press-event",
1549 G_CALLBACK (widget_avatar_button_press_event_cb), information);
1552 gtk_box_pack_start (GTK_BOX (information->vbox_avatar),
1553 information->widget_avatar,
1556 gtk_widget_show (information->widget_avatar);
1558 /* Setup id label/entry */
1559 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ID)
1561 information->widget_id = gtk_entry_new ();
1562 g_signal_connect (information->widget_id, "focus-out-event",
1563 G_CALLBACK (contact_widget_id_focus_out_cb),
1565 g_signal_connect (information->widget_id, "changed",
1566 G_CALLBACK (contact_widget_id_changed_cb),
1571 information->widget_id = gtk_label_new (NULL);
1572 if (!(information->flags & EMPATHY_CONTACT_WIDGET_FOR_TOOLTIP)) {
1573 gtk_label_set_selectable (GTK_LABEL (information->widget_id), TRUE);
1575 gtk_misc_set_alignment (GTK_MISC (information->widget_id), 0, 0.5);
1577 gtk_table_attach_defaults (GTK_TABLE (information->table_contact),
1578 information->widget_id,
1580 gtk_widget_show (information->widget_id);
1582 /* Setup alias label/entry */
1583 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ALIAS)
1585 information->widget_alias = gtk_entry_new ();
1587 if (!(information->flags & EMPATHY_CONTACT_WIDGET_NO_SET_ALIAS))
1588 g_signal_connect (information->widget_alias, "focus-out-event",
1589 G_CALLBACK (contact_widget_entry_alias_focus_event_cb),
1592 /* Make return activate the window default (the Close button) */
1593 gtk_entry_set_activates_default (GTK_ENTRY (information->widget_alias),
1598 information->widget_alias = gtk_label_new (NULL);
1599 if (!(information->flags & EMPATHY_CONTACT_WIDGET_FOR_TOOLTIP)) {
1600 gtk_label_set_selectable (GTK_LABEL (information->widget_alias), TRUE);
1602 gtk_misc_set_alignment (GTK_MISC (information->widget_alias), 0, 0.5);
1604 gtk_table_attach_defaults (GTK_TABLE (information->table_contact),
1605 information->widget_alias,
1607 if (information->flags & EMPATHY_CONTACT_WIDGET_FOR_TOOLTIP) {
1608 gtk_label_set_selectable (GTK_LABEL (information->label_status), FALSE);
1610 gtk_widget_show (information->widget_alias);
1613 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_FAVOURITE)
1615 information->favourite_checkbox = gtk_check_button_new_with_label (
1618 g_signal_connect (information->favourite_checkbox, "toggled",
1619 G_CALLBACK (favourite_toggled_cb), information);
1621 gtk_table_attach_defaults (GTK_TABLE (information->table_contact),
1622 information->favourite_checkbox, 0, 2, 3, 4);
1624 information->fav_sig_id = g_signal_connect (information->manager,
1625 "favourites-changed",
1626 G_CALLBACK (contact_widget_favourites_changed_cb), information);
1628 gtk_widget_show (information->favourite_checkbox);
1633 contact_widget_destroy_cb (GtkWidget *widget,
1634 EmpathyContactWidget *information)
1636 contact_widget_remove_contact (information);
1638 if (information->widget_id_timeout != 0)
1640 g_source_remove (information->widget_id_timeout);
1643 if (information->fav_sig_id != 0)
1644 g_signal_handler_disconnect (information->manager, information->fav_sig_id);
1646 g_object_unref (information->manager);
1648 g_slice_free (EmpathyContactWidget, information);
1652 * empathy_contact_widget_new:
1653 * @contact: an #EmpathyContact
1654 * @flags: #EmpathyContactWidgetFlags for the new contact widget
1656 * Creates a new #EmpathyContactWidget.
1658 * Return value: a new #EmpathyContactWidget
1661 empathy_contact_widget_new (EmpathyContact *contact,
1662 EmpathyContactWidgetFlags flags)
1664 EmpathyContactWidget *information;
1668 g_return_val_if_fail (contact == NULL || EMPATHY_IS_CONTACT (contact), NULL);
1670 information = g_slice_new0 (EmpathyContactWidget);
1671 information->flags = flags;
1673 filename = empathy_file_lookup ("empathy-contact-widget.ui",
1675 gui = empathy_builder_get_file (filename,
1676 "vbox_contact_widget", &information->vbox_contact_widget,
1677 "hbox_contact", &information->hbox_contact,
1678 "hbox_presence", &information->hbox_presence,
1679 "label_alias", &information->label_alias,
1680 "image_state", &information->image_state,
1681 "table_contact", &information->table_contact,
1682 "vbox_avatar", &information->vbox_avatar,
1683 "vbox_location", &information->vbox_location,
1684 "subvbox_location", &information->subvbox_location,
1685 "label_location", &information->label_location,
1686 #ifdef HAVE_LIBCHAMPLAIN
1687 "viewport_map", &information->viewport_map,
1689 "groups_widget", &information->groups_widget,
1690 "vbox_details", &information->vbox_details,
1691 "table_details", &information->table_details,
1692 "hbox_details_requested", &information->hbox_details_requested,
1693 "vbox_client", &information->vbox_client,
1694 "table_client", &information->table_client,
1695 "hbox_client_requested", &information->hbox_client_requested,
1699 empathy_builder_connect (gui, information,
1700 "vbox_contact_widget", "destroy", contact_widget_destroy_cb,
1702 information->table_location = NULL;
1704 g_object_set_data (G_OBJECT (information->vbox_contact_widget),
1705 "EmpathyContactWidget",
1708 information->manager = empathy_contact_manager_dup_singleton ();
1710 /* Create widgets */
1711 contact_widget_contact_setup (information);
1712 contact_widget_details_setup (information);
1713 contact_widget_client_setup (information);
1715 if (contact != NULL)
1716 contact_widget_set_contact (information, contact);
1717 else if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ACCOUNT ||
1718 information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ID)
1719 contact_widget_change_contact (information);
1721 return empathy_builder_unref_and_keep_widget (gui,
1722 information->vbox_contact_widget);
1726 * empathy_contact_widget_get_contact:
1727 * @widget: an #EmpathyContactWidget
1729 * Get the #EmpathyContact related with the #EmpathyContactWidget @widget.
1731 * Returns: the #EmpathyContact associated with @widget
1734 empathy_contact_widget_get_contact (GtkWidget *widget)
1736 EmpathyContactWidget *information;
1738 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
1740 information = g_object_get_data (G_OBJECT (widget), "EmpathyContactWidget");
1744 return information->contact;
1748 empathy_contact_widget_get_alias (GtkWidget *widget)
1750 EmpathyContactWidget *information;
1752 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
1754 information = g_object_get_data (G_OBJECT (widget), "EmpathyContactWidget");
1758 return gtk_entry_get_text (GTK_ENTRY (information->widget_alias));
1762 * empathy_contact_widget_set_contact:
1763 * @widget: an #EmpathyContactWidget
1764 * @contact: a different #EmpathyContact
1766 * Change the #EmpathyContact related with the #EmpathyContactWidget @widget.
1769 empathy_contact_widget_set_contact (GtkWidget *widget,
1770 EmpathyContact *contact)
1772 EmpathyContactWidget *information;
1774 g_return_if_fail (GTK_IS_WIDGET (widget));
1775 g_return_if_fail (EMPATHY_IS_CONTACT (contact));
1777 information = g_object_get_data (G_OBJECT (widget), "EmpathyContactWidget");
1781 contact_widget_set_contact (information, contact);
1785 * empathy_contact_widget_set_account_filter:
1786 * @widget: an #EmpathyContactWidget
1787 * @filter: a #EmpathyAccountChooserFilterFunc
1788 * @user_data: user data to pass to @filter, or %NULL
1790 * Set a filter on the #EmpathyAccountChooser included in the
1791 * #EmpathyContactWidget.
1794 empathy_contact_widget_set_account_filter (
1796 EmpathyAccountChooserFilterFunc filter,
1799 EmpathyContactWidget *information;
1800 EmpathyAccountChooser *chooser;
1802 g_return_if_fail (GTK_IS_WIDGET (widget));
1804 information = g_object_get_data (G_OBJECT (widget), "EmpathyContactWidget");
1808 chooser = EMPATHY_ACCOUNT_CHOOSER (information->widget_account);
1810 empathy_account_chooser_set_filter (chooser, filter, user_data);