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>
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-ui-utils.h"
51 #include "empathy-string-parser.h"
52 #include "empathy-kludge-label.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 #if HAVE_LIBCHAMPLAIN
111 GtkWidget *viewport_map;
112 GtkWidget *map_view_embed;
113 ChamplainView *map_view;
117 GtkWidget *vbox_groups;
118 GtkWidget *entry_group;
119 GtkWidget *button_group;
120 GtkWidget *treeview_groups;
123 GtkWidget *vbox_details;
124 GtkWidget *table_details;
125 GtkWidget *hbox_details_requested;
126 GtkWidget *spinner_details;
127 GList *details_to_set;
128 GCancellable *details_cancellable;
131 GtkWidget *vbox_client;
132 GtkWidget *table_client;
133 GtkWidget *hbox_client_requested;
134 } EmpathyContactWidget;
138 EmpathyContactWidget *information;
141 GtkTreeIter found_iter;
153 contact_widget_save (EmpathyContactWidget *information)
155 TpConnection *connection;
158 connection = empathy_contact_get_connection (information->contact);
160 /* Remove empty fields */
161 for (l = information->details_to_set; l != NULL; l = next)
163 TpContactInfoField *field = l->data;
166 if (field->field_value == NULL || EMP_STR_EMPTY (field->field_value[0]))
168 DEBUG ("Drop empty field: %s", field->field_name);
169 tp_contact_info_field_free (field);
170 information->details_to_set =
171 g_list_delete_link (information->details_to_set, l);
175 if (information->details_to_set != NULL)
177 tp_connection_set_contact_info_async (connection,
178 information->details_to_set, NULL, NULL);
179 tp_contact_info_list_free (information->details_to_set);
180 information->details_to_set = NULL;
185 contact_widget_details_setup (EmpathyContactWidget *information)
187 gtk_widget_hide (information->vbox_details);
189 information->spinner_details = gtk_spinner_new ();
190 gtk_box_pack_end (GTK_BOX (information->hbox_details_requested),
191 information->spinner_details, TRUE, TRUE, 0);
192 gtk_widget_show (information->spinner_details);
196 contact_widget_details_changed_cb (GtkEntry *entry,
197 TpContactInfoField *field)
199 const gchar *strv[] = { NULL, NULL };
201 strv[0] = gtk_entry_get_text (entry);
203 if (field->field_value != NULL)
204 g_strfreev (field->field_value);
205 field->field_value = g_strdupv ((GStrv) strv);
208 static void contact_widget_details_notify_cb (EmpathyContactWidget *information);
212 const gchar *field_name;
217 static InfoFieldData info_field_datas[] =
219 { "fn", N_("Full name:"), FALSE },
220 { "tel", N_("Phone number:"), FALSE },
221 { "email", N_("E-mail address:"), TRUE },
222 { "url", N_("Website:"), TRUE },
223 { "bday", N_("Birthday:"), FALSE },
227 static InfoFieldData *
228 find_info_field_data (const gchar *field_name)
232 for (i = 0; info_field_datas[i].field_name != NULL; i++)
234 if (!tp_strdiff (info_field_datas[i].field_name, field_name))
235 return info_field_datas + i;
241 contact_info_field_name_cmp (const gchar *name1,
246 if (!tp_strdiff (name1, name2))
249 /* We use the order of info_field_datas */
250 for (i = 0; info_field_datas[i].field_name != NULL; i++)
252 if (!tp_strdiff (info_field_datas[i].field_name, name1))
254 if (!tp_strdiff (info_field_datas[i].field_name, name2))
258 return g_strcmp0 (name1, name2);
262 contact_info_field_cmp (TpContactInfoField *field1,
263 TpContactInfoField *field2)
265 return contact_info_field_name_cmp (field1->field_name, field2->field_name);
269 contact_info_field_spec_cmp (TpContactInfoFieldSpec *spec1,
270 TpContactInfoFieldSpec *spec2)
272 return contact_info_field_name_cmp (spec1->name, spec2->name);
276 contact_widget_details_update_edit (EmpathyContactWidget *information)
279 TpConnection *connection;
283 g_assert (information->details_to_set == NULL);
285 contact = empathy_contact_get_tp_contact (information->contact);
286 connection = tp_contact_get_connection (contact);
288 specs = tp_connection_get_contact_info_supported_fields (connection);
289 specs = g_list_sort (specs, (GCompareFunc) contact_info_field_spec_cmp);
290 for (l = specs; l != NULL; l = l->next)
292 TpContactInfoFieldSpec *spec = l->data;
293 TpContactInfoField *field;
294 InfoFieldData *field_data;
299 field_data = find_info_field_data (spec->name);
300 if (field_data == NULL)
302 DEBUG ("Unhandled ContactInfo field spec: %s", spec->name);
306 /* Search initial value */
307 info = tp_contact_get_contact_info (contact);
308 for (ll = info; ll != NULL; ll = ll->next)
311 if (!tp_strdiff (field->field_name, spec->name))
313 value = field->field_value;
318 field = tp_contact_info_field_new (spec->name, spec->parameters, value);
319 information->details_to_set = g_list_prepend (information->details_to_set,
323 w = gtk_label_new (_(field_data->title));
324 gtk_table_attach (GTK_TABLE (information->table_details),
325 w, 0, 1, n_rows, n_rows + 1, GTK_FILL, 0, 0, 0);
326 gtk_misc_set_alignment (GTK_MISC (w), 0, 0.5);
330 w = gtk_entry_new ();
331 gtk_entry_set_text (GTK_ENTRY (w),
332 field->field_value[0] ? field->field_value[0] : "");
333 gtk_table_attach_defaults (GTK_TABLE (information->table_details),
334 w, 1, 2, n_rows, n_rows + 1);
337 g_signal_connect (w, "changed",
338 G_CALLBACK (contact_widget_details_changed_cb), field);
348 contact_widget_details_update_show (EmpathyContactWidget *information)
354 contact = empathy_contact_get_tp_contact (information->contact);
355 info = tp_contact_get_contact_info (contact);
356 info = g_list_sort (info, (GCompareFunc) contact_info_field_cmp);
357 for (l = info; l != NULL; l = l->next)
359 TpContactInfoField *field = l->data;
360 InfoFieldData *field_data;
364 if (field->field_value == NULL || field->field_value[0] == NULL)
367 value = field->field_value[0];
369 field_data = find_info_field_data (field->field_name);
370 if (field_data == NULL)
372 DEBUG ("Unhandled ContactInfo field: %s", field->field_name);
377 w = gtk_label_new (_(field_data->title));
378 gtk_table_attach (GTK_TABLE (information->table_details),
379 w, 0, 1, n_rows, n_rows + 1, GTK_FILL, 0, 0, 0);
380 gtk_misc_set_alignment (GTK_MISC (w), 0, 0.5);
384 w = gtk_label_new (value);
385 if (field_data->linkify)
389 markup = empathy_add_link_markup (value);
390 gtk_label_set_markup (GTK_LABEL (w), markup);
394 if ((information->flags & EMPATHY_CONTACT_WIDGET_FOR_TOOLTIP) == 0)
395 gtk_label_set_selectable (GTK_LABEL (w), TRUE);
397 gtk_table_attach_defaults (GTK_TABLE (information->table_details),
398 w, 1, 2, n_rows, n_rows + 1);
399 gtk_misc_set_alignment (GTK_MISC (w), 0, 0.5);
410 contact_widget_details_notify_cb (EmpathyContactWidget *information)
414 gtk_container_foreach (GTK_CONTAINER (information->table_details),
415 (GtkCallback) gtk_widget_destroy, NULL);
417 if ((information->flags & EMPATHY_CONTACT_WIDGET_EDIT_DETAILS) != 0)
418 n_rows = contact_widget_details_update_edit (information);
420 n_rows = contact_widget_details_update_show (information);
424 gtk_widget_show (information->vbox_details);
425 gtk_widget_show (information->table_details);
429 gtk_widget_hide (information->vbox_details);
432 gtk_widget_hide (information->hbox_details_requested);
433 gtk_spinner_stop (GTK_SPINNER (information->spinner_details));
437 contact_widget_details_request_cb (GObject *object,
441 TpContact *contact = TP_CONTACT (object);
442 EmpathyContactWidget *information = user_data;
443 GError *error = NULL;
445 if (!tp_contact_request_contact_info_finish (contact, res, &error))
447 /* If the request got cancelled it could mean the contact widget is
448 * destroyed, so we should not dereference information */
449 if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
451 g_clear_error (&error);
455 gtk_widget_hide (information->vbox_details);
456 g_clear_error (&error);
460 contact_widget_details_notify_cb (information);
463 /* If we are going to edit ContactInfo, we don't want live updates */
464 if ((information->flags & EMPATHY_CONTACT_WIDGET_EDIT_DETAILS) == 0)
466 g_signal_connect_swapped (contact, "notify::contact-info",
467 G_CALLBACK (contact_widget_details_notify_cb), information);
470 g_object_unref (information->details_cancellable);
471 information->details_cancellable = NULL;
475 contact_widget_details_feature_prepared_cb (GObject *object,
479 TpConnection *connection = TP_CONNECTION (object);
480 EmpathyContactWidget *information = user_data;
482 TpContactInfoFlags flags;
484 if (!tp_proxy_prepare_finish (connection, res, NULL))
486 gtk_widget_hide (information->vbox_details);
490 /* If we want to edit info, but connection does not support that, stop */
491 flags = tp_connection_get_contact_info_flags (connection);
492 if ((flags & TP_CONTACT_INFO_FLAG_CAN_SET) == 0 &&
493 (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_DETAILS) != 0)
495 gtk_widget_hide (information->vbox_details);
499 /* Request the contact's info */
500 gtk_widget_show (information->vbox_details);
501 gtk_widget_show (information->hbox_details_requested);
502 gtk_widget_hide (information->table_details);
503 gtk_spinner_start (GTK_SPINNER (information->spinner_details));
505 contact = empathy_contact_get_tp_contact (information->contact);
506 g_assert (information->details_cancellable == NULL);
507 information->details_cancellable = g_cancellable_new ();
508 tp_contact_request_contact_info_async (contact,
509 information->details_cancellable, contact_widget_details_request_cb,
514 contact_widget_details_update (EmpathyContactWidget *information)
516 TpContact *tp_contact = NULL;
518 if ((information->flags & EMPATHY_CONTACT_WIDGET_SHOW_DETAILS) == 0 &&
519 (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_DETAILS) == 0)
522 gtk_widget_hide (information->vbox_details);
524 if (information->contact != NULL)
525 tp_contact = empathy_contact_get_tp_contact (information->contact);
527 if (tp_contact != NULL)
529 GQuark features[] = { TP_CONNECTION_FEATURE_CONTACT_INFO, 0 };
530 TpConnection *connection;
532 /* First, make sure the CONTACT_INFO feature is ready on the connection */
533 connection = tp_contact_get_connection (tp_contact);
534 tp_proxy_prepare_async (connection, features,
535 contact_widget_details_feature_prepared_cb, information);
540 contact_widget_client_update (EmpathyContactWidget *information)
542 /* FIXME: Needs new telepathy spec */
546 contact_widget_client_setup (EmpathyContactWidget *information)
548 /* FIXME: Needs new telepathy spec */
549 gtk_widget_hide (information->vbox_client);
553 contact_widget_cell_toggled (GtkCellRendererToggle *cell,
555 EmpathyContactWidget *information)
562 gboolean was_enabled;
565 view = GTK_TREE_VIEW (information->treeview_groups);
566 model = gtk_tree_view_get_model (view);
567 store = GTK_LIST_STORE (model);
569 path = gtk_tree_path_new_from_string (path_string);
571 gtk_tree_model_get_iter (model, &iter, path);
572 gtk_tree_model_get (model, &iter,
573 COL_ENABLED, &was_enabled,
577 gtk_list_store_set (store, &iter, COL_ENABLED, !was_enabled, -1);
578 gtk_tree_path_free (path);
582 FolksIndividual *individual = folks_individual_from_empathy_contact (
583 information->contact);
585 if (individual != NULL)
587 folks_groups_change_group (FOLKS_GROUPS (individual), group,
589 g_object_unref (individual);
597 contact_widget_model_populate_columns (EmpathyContactWidget *information)
601 GtkTreeViewColumn *column;
602 GtkCellRenderer *renderer;
605 view = GTK_TREE_VIEW (information->treeview_groups);
606 model = gtk_tree_view_get_model (view);
608 renderer = gtk_cell_renderer_toggle_new ();
609 g_signal_connect (renderer, "toggled",
610 G_CALLBACK (contact_widget_cell_toggled), information);
612 column = gtk_tree_view_column_new_with_attributes (_("Select"), renderer,
613 "active", COL_ENABLED, NULL);
615 gtk_tree_view_column_set_sizing (column, GTK_TREE_VIEW_COLUMN_FIXED);
616 gtk_tree_view_column_set_fixed_width (column, 50);
617 gtk_tree_view_append_column (view, column);
619 renderer = gtk_cell_renderer_text_new ();
620 col_offset = gtk_tree_view_insert_column_with_attributes (view,
624 /* "editable", COL_EDITABLE, */
627 g_object_set_data (G_OBJECT (renderer),
628 "column", GINT_TO_POINTER (COL_NAME));
630 column = gtk_tree_view_get_column (view, col_offset - 1);
631 gtk_tree_view_column_set_sort_column_id (column, COL_NAME);
632 gtk_tree_view_column_set_resizable (column,FALSE);
633 gtk_tree_view_column_set_clickable (GTK_TREE_VIEW_COLUMN (column), TRUE);
637 contact_widget_model_setup (EmpathyContactWidget *information)
641 GtkTreeSelection *selection;
643 view = GTK_TREE_VIEW (information->treeview_groups);
645 store = gtk_list_store_new (COL_COUNT,
646 G_TYPE_STRING, /* name */
647 G_TYPE_BOOLEAN, /* enabled */
648 G_TYPE_BOOLEAN); /* editable */
650 gtk_tree_view_set_model (view, GTK_TREE_MODEL (store));
652 selection = gtk_tree_view_get_selection (view);
653 gtk_tree_selection_set_mode (selection, GTK_SELECTION_SINGLE);
655 contact_widget_model_populate_columns (information);
657 gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (store),
658 COL_NAME, GTK_SORT_ASCENDING);
660 g_object_unref (store);
664 contact_widget_groups_populate_data (EmpathyContactWidget *information)
669 GList *my_groups, *l;
672 view = GTK_TREE_VIEW (information->treeview_groups);
673 store = GTK_LIST_STORE (gtk_tree_view_get_model (view));
674 gtk_list_store_clear (store);
676 all_groups = empathy_contact_list_get_all_groups (
677 EMPATHY_CONTACT_LIST (information->manager));
678 my_groups = empathy_contact_list_get_groups (
679 EMPATHY_CONTACT_LIST (information->manager),
680 information->contact);
682 for (l = all_groups; l; l = l->next)
684 const gchar *group_str;
689 enabled = g_list_find_custom (my_groups,
690 group_str, (GCompareFunc) strcmp) != NULL;
692 gtk_list_store_append (store, &iter);
693 gtk_list_store_set (store, &iter,
696 COL_ENABLED, enabled,
700 g_list_foreach (all_groups, (GFunc) g_free, NULL);
701 g_list_foreach (my_groups, (GFunc) g_free, NULL);
702 g_list_free (all_groups);
703 g_list_free (my_groups);
707 contact_widget_model_find_name_foreach (GtkTreeModel *model,
714 gtk_tree_model_get (model, iter,
721 if (data->name && strcmp (data->name, name) == 0)
724 data->found_iter = *iter;
737 contact_widget_model_find_name (EmpathyContactWidget *information,
745 if (EMP_STR_EMPTY (name))
748 data.information = information;
752 view = GTK_TREE_VIEW (information->treeview_groups);
753 model = gtk_tree_view_get_model (view);
755 gtk_tree_model_foreach (model,
756 (GtkTreeModelForeachFunc) contact_widget_model_find_name_foreach,
759 if (data.found == TRUE)
761 *iter = data.found_iter;
769 contact_widget_entry_group_changed_cb (GtkEditable *editable,
770 EmpathyContactWidget *information)
775 group = gtk_entry_get_text (GTK_ENTRY (information->entry_group));
777 if (contact_widget_model_find_name (information, group, &iter))
778 gtk_widget_set_sensitive (GTK_WIDGET (information->button_group), FALSE);
780 gtk_widget_set_sensitive (GTK_WIDGET (information->button_group),
781 !EMP_STR_EMPTY (group));
785 contact_widget_entry_group_activate_cb (GtkEntry *entry,
786 EmpathyContactWidget *information)
788 gtk_widget_activate (GTK_WIDGET (information->button_group));
792 contact_widget_button_group_clicked_cb (GtkButton *button,
793 EmpathyContactWidget *information)
798 FolksIndividual *individual;
801 view = GTK_TREE_VIEW (information->treeview_groups);
802 store = GTK_LIST_STORE (gtk_tree_view_get_model (view));
804 group = gtk_entry_get_text (GTK_ENTRY (information->entry_group));
806 gtk_list_store_append (store, &iter);
807 gtk_list_store_set (store, &iter,
812 individual = folks_individual_from_empathy_contact (information->contact);
814 if (individual != NULL)
816 folks_groups_change_group (FOLKS_GROUPS (individual), group, TRUE);
817 g_object_unref (individual);
822 contact_widget_groups_notify_cb (EmpathyContactWidget *information)
824 /* FIXME: not implemented */
828 contact_widget_groups_setup (EmpathyContactWidget *information)
830 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_GROUPS)
832 contact_widget_model_setup (information);
837 contact_widget_groups_update (EmpathyContactWidget *information)
839 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_GROUPS &&
840 information->contact)
842 g_signal_connect_swapped (information->contact, "notify::groups",
843 G_CALLBACK (contact_widget_groups_notify_cb), information);
844 contact_widget_groups_populate_data (information);
846 gtk_widget_show (information->vbox_groups);
849 gtk_widget_hide (information->vbox_groups);
852 /* Converts the Location's GHashTable's key to a user readable string */
854 location_key_to_label (const gchar *key)
856 if (tp_strdiff (key, EMPATHY_LOCATION_COUNTRY_CODE) == FALSE)
857 return _("Country ISO Code:");
858 else if (tp_strdiff (key, EMPATHY_LOCATION_COUNTRY) == FALSE)
859 return _("Country:");
860 else if (tp_strdiff (key, EMPATHY_LOCATION_REGION) == FALSE)
862 else if (tp_strdiff (key, EMPATHY_LOCATION_LOCALITY) == FALSE)
864 else if (tp_strdiff (key, EMPATHY_LOCATION_AREA) == FALSE)
866 else if (tp_strdiff (key, EMPATHY_LOCATION_POSTAL_CODE) == FALSE)
867 return _("Postal Code:");
868 else if (tp_strdiff (key, EMPATHY_LOCATION_STREET) == FALSE)
870 else if (tp_strdiff (key, EMPATHY_LOCATION_BUILDING) == FALSE)
871 return _("Building:");
872 else if (tp_strdiff (key, EMPATHY_LOCATION_FLOOR) == FALSE)
874 else if (tp_strdiff (key, EMPATHY_LOCATION_ROOM) == FALSE)
876 else if (tp_strdiff (key, EMPATHY_LOCATION_TEXT) == FALSE)
878 else if (tp_strdiff (key, EMPATHY_LOCATION_DESCRIPTION) == FALSE)
879 return _("Description:");
880 else if (tp_strdiff (key, EMPATHY_LOCATION_URI) == FALSE)
882 else if (tp_strdiff (key, EMPATHY_LOCATION_ACCURACY_LEVEL) == FALSE)
883 return _("Accuracy Level:");
884 else if (tp_strdiff (key, EMPATHY_LOCATION_ERROR) == FALSE)
886 else if (tp_strdiff (key, EMPATHY_LOCATION_VERTICAL_ERROR_M) == FALSE)
887 return _("Vertical Error (meters):");
888 else if (tp_strdiff (key, EMPATHY_LOCATION_HORIZONTAL_ERROR_M) == FALSE)
889 return _("Horizontal Error (meters):");
890 else if (tp_strdiff (key, EMPATHY_LOCATION_SPEED) == FALSE)
892 else if (tp_strdiff (key, EMPATHY_LOCATION_BEARING) == FALSE)
893 return _("Bearing:");
894 else if (tp_strdiff (key, EMPATHY_LOCATION_CLIMB) == FALSE)
895 return _("Climb Speed:");
896 else if (tp_strdiff (key, EMPATHY_LOCATION_TIMESTAMP) == FALSE)
897 return _("Last Updated on:");
898 else if (tp_strdiff (key, EMPATHY_LOCATION_LON) == FALSE)
899 return _("Longitude:");
900 else if (tp_strdiff (key, EMPATHY_LOCATION_LAT) == FALSE)
901 return _("Latitude:");
902 else if (tp_strdiff (key, EMPATHY_LOCATION_ALT) == FALSE)
903 return _("Altitude:");
906 DEBUG ("Unexpected Location key: %s", key);
912 contact_widget_location_update (EmpathyContactWidget *information)
914 GHashTable *location;
916 gdouble lat = 0.0, lon = 0.0;
917 gboolean has_position = TRUE;
920 static const gchar* ordered_geolocation_keys[] = {
921 EMPATHY_LOCATION_TEXT,
922 EMPATHY_LOCATION_URI,
923 EMPATHY_LOCATION_DESCRIPTION,
924 EMPATHY_LOCATION_BUILDING,
925 EMPATHY_LOCATION_FLOOR,
926 EMPATHY_LOCATION_ROOM,
927 EMPATHY_LOCATION_STREET,
928 EMPATHY_LOCATION_AREA,
929 EMPATHY_LOCATION_LOCALITY,
930 EMPATHY_LOCATION_REGION,
931 EMPATHY_LOCATION_COUNTRY,
936 gboolean display_map = FALSE;
938 if (!(information->flags & EMPATHY_CONTACT_WIDGET_SHOW_LOCATION))
940 gtk_widget_hide (information->vbox_location);
944 location = empathy_contact_get_location (information->contact);
945 if (location == NULL || g_hash_table_size (location) == 0)
947 gtk_widget_hide (information->vbox_location);
951 value = g_hash_table_lookup (location, EMPATHY_LOCATION_LAT);
953 has_position = FALSE;
955 lat = g_value_get_double (value);
957 value = g_hash_table_lookup (location, EMPATHY_LOCATION_LON);
959 has_position = FALSE;
961 lon = g_value_get_double (value);
963 value = g_hash_table_lookup (location, EMPATHY_LOCATION_TIMESTAMP);
966 gchar *loc = g_strdup_printf ("<b>%s</b>", _("Location"));
967 gtk_label_set_markup (GTK_LABEL (information->label_location), loc);
977 stamp = g_value_get_int64 (value);
980 user_date = empathy_time_to_string_relative (time_);
982 text = g_strconcat ( _("<b>Location</b>, "), user_date, NULL);
983 gtk_label_set_markup (GTK_LABEL (information->label_location), text);
989 /* Prepare the location information table */
990 if (information->table_location != NULL)
992 gtk_widget_destroy (information->table_location);
995 information->table_location = gtk_table_new (1, 2, FALSE);
996 gtk_box_pack_start (GTK_BOX (information->subvbox_location),
997 information->table_location, FALSE, FALSE, 5);
1000 for (i = 0; (skey = ordered_geolocation_keys[i]); i++)
1002 const gchar* user_label;
1004 char *svalue = NULL;
1006 gvalue = g_hash_table_lookup (location, (gpointer) skey);
1010 user_label = location_key_to_label (skey);
1012 label = gtk_label_new (user_label);
1013 gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
1014 gtk_table_attach (GTK_TABLE (information->table_location),
1015 label, 0, 1, row, row + 1, GTK_FILL, GTK_FILL, 10, 0);
1016 gtk_widget_show (label);
1018 if (G_VALUE_TYPE (gvalue) == G_TYPE_DOUBLE)
1021 dvalue = g_value_get_double (gvalue);
1022 svalue = g_strdup_printf ("%f", dvalue);
1024 else if (G_VALUE_TYPE (gvalue) == G_TYPE_STRING)
1026 svalue = g_value_dup_string (gvalue);
1028 else if (G_VALUE_TYPE (gvalue) == G_TYPE_INT64)
1032 time_ = g_value_get_int64 (value);
1033 svalue = empathy_time_to_string_utc (time_, _("%B %e, %Y at %R UTC"));
1038 label = gtk_label_new (svalue);
1039 gtk_table_attach_defaults (GTK_TABLE (information->table_location),
1040 label, 1, 2, row, row + 1);
1041 gtk_misc_set_alignment (GTK_MISC (label), 0, 0);
1042 gtk_widget_show (label);
1044 if (!(information->flags & EMPATHY_CONTACT_WIDGET_FOR_TOOLTIP))
1045 gtk_label_set_selectable (GTK_LABEL (label), TRUE);
1052 #if HAVE_LIBCHAMPLAIN
1054 !(information->flags & EMPATHY_CONTACT_WIDGET_FOR_TOOLTIP))
1056 /* Cannot be displayed in tooltips until Clutter-Gtk can deal with such
1064 /* We can display some fields */
1065 gtk_widget_show (information->table_location);
1067 else if (!display_map)
1069 /* Can't display either fields or map */
1070 gtk_widget_hide (information->vbox_location);
1074 #if HAVE_LIBCHAMPLAIN
1077 ClutterActor *marker;
1078 ChamplainLayer *layer;
1080 information->map_view_embed = gtk_champlain_embed_new ();
1081 information->map_view = gtk_champlain_embed_get_view (
1082 GTK_CHAMPLAIN_EMBED (information->map_view_embed));
1084 gtk_container_add (GTK_CONTAINER (information->viewport_map),
1085 information->map_view_embed);
1086 g_object_set (G_OBJECT (information->map_view),
1087 "show-license", TRUE,
1088 "scroll-mode", CHAMPLAIN_SCROLL_MODE_KINETIC,
1092 layer = champlain_layer_new ();
1093 champlain_view_add_layer (information->map_view, layer);
1095 marker = champlain_marker_new_with_text (
1096 empathy_contact_get_name (information->contact), NULL, NULL, NULL);
1097 champlain_base_marker_set_position (CHAMPLAIN_BASE_MARKER (marker), lat, lon);
1098 clutter_container_add (CLUTTER_CONTAINER (layer), marker, NULL);
1100 champlain_view_center_on (information->map_view, lat, lon);
1101 gtk_widget_show_all (information->viewport_map);
1105 gtk_widget_show (information->vbox_location);
1109 save_avatar_menu_activate_cb (GtkWidget *widget,
1110 EmpathyContactWidget *information)
1113 EmpathyAvatar *avatar;
1114 gchar *ext = NULL, *filename;
1116 dialog = gtk_file_chooser_dialog_new (_("Save Avatar"),
1118 GTK_FILE_CHOOSER_ACTION_SAVE,
1119 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
1120 GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT,
1123 gtk_file_chooser_set_do_overwrite_confirmation (GTK_FILE_CHOOSER (dialog),
1126 /* look for the avatar extension */
1127 avatar = empathy_contact_get_avatar (information->contact);
1128 if (avatar->format != NULL)
1132 splitted = g_strsplit (avatar->format, "/", 2);
1133 if (splitted[0] != NULL && splitted[1] != NULL)
1134 ext = g_strdup (splitted[1]);
1136 g_strfreev (splitted);
1140 /* Avatar was loaded from the cache so was converted to PNG */
1141 ext = g_strdup ("png");
1148 id = tp_escape_as_identifier (empathy_contact_get_id (
1149 information->contact));
1151 filename = g_strdup_printf ("%s.%s", id, ext);
1152 gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (dialog), filename);
1159 if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT)
1161 GError *error = NULL;
1163 filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
1165 if (!empathy_avatar_save_to_file (avatar, filename, &error))
1168 GtkWidget *error_dialog;
1170 error_dialog = gtk_message_dialog_new (NULL, 0,
1171 GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE,
1172 _("Unable to save avatar"));
1174 gtk_message_dialog_format_secondary_text (
1175 GTK_MESSAGE_DIALOG (error_dialog), "%s", error->message);
1177 g_signal_connect (error_dialog, "response",
1178 G_CALLBACK (gtk_widget_destroy), NULL);
1180 gtk_window_present (GTK_WINDOW (error_dialog));
1182 g_clear_error (&error);
1188 gtk_widget_destroy (dialog);
1192 popup_avatar_menu (EmpathyContactWidget *information,
1194 GdkEventButton *event)
1196 GtkWidget *menu, *item;
1197 gint button, event_time;
1199 if (information->contact == NULL ||
1200 empathy_contact_get_avatar (information->contact) == NULL)
1203 menu = gtk_menu_new ();
1205 /* Add "Save as..." entry */
1206 item = gtk_image_menu_item_new_from_stock (GTK_STOCK_SAVE_AS, NULL);
1207 gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
1208 gtk_widget_show (item);
1210 g_signal_connect (item, "activate",
1211 G_CALLBACK (save_avatar_menu_activate_cb), information);
1215 button = event->button;
1216 event_time = event->time;
1221 event_time = gtk_get_current_event_time ();
1224 gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
1225 button, event_time);
1226 g_object_ref_sink (menu);
1227 g_object_unref (menu);
1231 widget_avatar_popup_menu_cb (GtkWidget *widget,
1232 EmpathyContactWidget *information)
1234 popup_avatar_menu (information, widget, NULL);
1240 widget_avatar_button_press_event_cb (GtkWidget *widget,
1241 GdkEventButton *event,
1242 EmpathyContactWidget *information)
1244 /* Ignore double-clicks and triple-clicks */
1245 if (event->button == 3 && event->type == GDK_BUTTON_PRESS)
1247 popup_avatar_menu (information, widget, event);
1255 set_avatar_cb (GObject *source,
1259 GError *error = NULL;
1261 if (!tp_account_set_avatar_finish (TP_ACCOUNT (source), res, &error)) {
1262 DEBUG ("Failed to set Account.Avatar: %s", error->message);
1263 g_error_free (error);
1268 set_avatar_on_account (TpAccount *account,
1271 const gchar *mime_type)
1273 DEBUG ("%s Account.Avatar on %s", size > 0 ? "Set": "Clear",
1274 tp_proxy_get_object_path (account));
1276 tp_account_set_avatar_async (account, (const guchar *) data, size,
1277 mime_type, set_avatar_cb, NULL);
1281 contact_widget_avatar_changed_cb (EmpathyAvatarChooser *chooser,
1282 EmpathyContactWidget *information)
1286 const gchar *mime_type;
1289 empathy_avatar_chooser_get_image_data (
1290 EMPATHY_AVATAR_CHOOSER (information->widget_avatar),
1291 &data, &size, &mime_type);
1293 account = empathy_contact_get_account (information->contact);
1294 set_avatar_on_account (account, data, size, mime_type);
1298 set_nickname_cb (GObject *source,
1302 GError *error = NULL;
1304 if (!tp_account_set_nickname_finish (TP_ACCOUNT (source), res, &error))
1306 DEBUG ("Failed to set Account.Nickname: %s", error->message);
1307 g_error_free (error);
1312 set_alias_on_account (TpAccount *account,
1315 DEBUG ("Set Account.Nickname to %s", alias);
1317 tp_account_set_nickname_async (account, alias, set_nickname_cb, NULL);
1321 contact_widget_entry_alias_focus_event_cb (GtkEditable *editable,
1322 GdkEventFocus *event,
1323 EmpathyContactWidget *information)
1325 if (information->contact)
1329 alias = gtk_entry_get_text (GTK_ENTRY (editable));
1331 if (empathy_contact_is_user (information->contact))
1333 TpAccount * account;
1335 account = empathy_contact_get_account (information->contact);
1336 set_alias_on_account (account, alias);
1340 FolksIndividual *individual = folks_individual_from_empathy_contact (
1341 information->contact);
1343 if (individual != NULL)
1345 folks_alias_set_alias (FOLKS_ALIAS (individual), alias);
1346 g_object_unref (individual);
1355 update_avatar_chooser_account_cb (EmpathyAccountChooser *account_chooser,
1356 EmpathyAvatarChooser *avatar_chooser)
1360 account = empathy_account_chooser_get_account (account_chooser);
1361 if (account == NULL)
1364 empathy_avatar_chooser_set_account (avatar_chooser, account);
1368 contact_widget_avatar_notify_cb (EmpathyContactWidget *information)
1370 EmpathyAvatar *avatar = NULL;
1372 if (information->contact)
1373 avatar = empathy_contact_get_avatar (information->contact);
1375 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_AVATAR)
1377 g_signal_handlers_block_by_func (information->widget_avatar,
1378 contact_widget_avatar_changed_cb,
1380 empathy_avatar_chooser_set (
1381 EMPATHY_AVATAR_CHOOSER (information->widget_avatar), avatar);
1382 g_signal_handlers_unblock_by_func (information->widget_avatar,
1383 contact_widget_avatar_changed_cb, information);
1386 empathy_avatar_image_set (
1387 EMPATHY_AVATAR_IMAGE (information->widget_avatar), avatar);
1391 contact_widget_name_notify_cb (EmpathyContactWidget *information)
1393 if (GTK_IS_ENTRY (information->widget_alias))
1394 gtk_entry_set_text (GTK_ENTRY (information->widget_alias),
1395 empathy_contact_get_name (information->contact));
1397 gtk_label_set_label (GTK_LABEL (information->widget_alias),
1398 empathy_contact_get_name (information->contact));
1402 contact_widget_presence_notify_cb (EmpathyContactWidget *information)
1404 const gchar *status;
1405 gchar *markup_text = NULL;
1407 status = empathy_contact_get_status (information->contact);
1409 markup_text = empathy_add_link_markup (status);
1410 gtk_label_set_markup (GTK_LABEL (information->label_status), markup_text);
1411 g_free (markup_text);
1413 gtk_image_set_from_icon_name (GTK_IMAGE (information->image_state),
1414 empathy_icon_name_for_contact (information->contact),
1415 GTK_ICON_SIZE_BUTTON);
1416 gtk_widget_show (information->image_state);
1420 contact_widget_favourites_changed_cb (EmpathyContactManager *manager,
1421 EmpathyContact *contact,
1422 gboolean is_favourite,
1423 EmpathyContactWidget *information)
1425 if (contact != information->contact)
1428 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (
1429 information->favourite_checkbox), is_favourite);
1433 contact_widget_remove_contact (EmpathyContactWidget *information)
1435 if (information->contact)
1437 TpContact *tp_contact;
1439 contact_widget_save (information);
1441 g_signal_handlers_disconnect_by_func (information->contact,
1442 contact_widget_name_notify_cb, information);
1443 g_signal_handlers_disconnect_by_func (information->contact,
1444 contact_widget_presence_notify_cb, information);
1445 g_signal_handlers_disconnect_by_func (information->contact,
1446 contact_widget_avatar_notify_cb, information);
1447 g_signal_handlers_disconnect_by_func (information->contact,
1448 contact_widget_groups_notify_cb, information);
1450 tp_contact = empathy_contact_get_tp_contact (information->contact);
1451 if (tp_contact != NULL)
1453 g_signal_handlers_disconnect_by_func (tp_contact,
1454 contact_widget_details_notify_cb, information);
1457 g_object_unref (information->contact);
1458 information->contact = NULL;
1461 if (information->details_cancellable != NULL)
1463 g_cancellable_cancel (information->details_cancellable);
1464 g_object_unref (information->details_cancellable);
1465 information->details_cancellable = NULL;
1469 static void contact_widget_change_contact (EmpathyContactWidget *information);
1472 contact_widget_contact_update (EmpathyContactWidget *information)
1474 TpAccount *account = NULL;
1475 const gchar *id = NULL;
1477 /* Connect and get info from new contact */
1478 if (information->contact)
1480 g_signal_connect_swapped (information->contact, "notify::name",
1481 G_CALLBACK (contact_widget_name_notify_cb), information);
1482 g_signal_connect_swapped (information->contact, "notify::presence",
1483 G_CALLBACK (contact_widget_presence_notify_cb), information);
1484 g_signal_connect_swapped (information->contact,
1485 "notify::presence-message",
1486 G_CALLBACK (contact_widget_presence_notify_cb), information);
1487 g_signal_connect_swapped (information->contact, "notify::avatar",
1488 G_CALLBACK (contact_widget_avatar_notify_cb), information);
1490 account = empathy_contact_get_account (information->contact);
1491 id = empathy_contact_get_id (information->contact);
1494 /* Update account widget */
1495 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ACCOUNT)
1499 g_signal_handlers_block_by_func (information->widget_account,
1500 contact_widget_change_contact,
1502 empathy_account_chooser_set_account (
1503 EMPATHY_ACCOUNT_CHOOSER (information->widget_account), account);
1504 g_signal_handlers_unblock_by_func (information->widget_account,
1505 contact_widget_change_contact, information);
1514 name = tp_account_get_display_name (account);
1515 gtk_label_set_label (GTK_LABEL (information->label_account), name);
1517 name = tp_account_get_icon_name (account);
1518 gtk_image_set_from_icon_name (GTK_IMAGE (information->image_account),
1519 name, GTK_ICON_SIZE_MENU);
1523 /* Update id widget */
1524 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ID)
1525 gtk_entry_set_text (GTK_ENTRY (information->widget_id), id ? id : "");
1527 gtk_label_set_label (GTK_LABEL (information->widget_id), id ? id : "");
1529 /* Update other widgets */
1530 if (information->contact)
1532 contact_widget_name_notify_cb (information);
1533 contact_widget_presence_notify_cb (information);
1534 contact_widget_avatar_notify_cb (information);
1536 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_FAVOURITE)
1538 FolksIndividual *individual = folks_individual_from_empathy_contact (
1539 information->contact);
1541 if (individual != NULL)
1543 gboolean is_favourite = folks_favourite_get_is_favourite (
1544 FOLKS_FAVOURITE (individual));
1545 contact_widget_favourites_changed_cb (information->manager,
1546 information->contact, is_favourite, information);
1548 g_object_unref (individual);
1552 gtk_widget_show (information->label_alias);
1553 gtk_widget_show (information->widget_alias);
1554 gtk_widget_show (information->hbox_presence);
1555 gtk_widget_show (information->widget_avatar);
1559 gtk_widget_hide (information->label_alias);
1560 gtk_widget_hide (information->widget_alias);
1561 gtk_widget_hide (information->hbox_presence);
1562 gtk_widget_hide (information->widget_avatar);
1567 contact_widget_set_contact (EmpathyContactWidget *information,
1568 EmpathyContact *contact)
1570 if (contact == information->contact)
1573 contact_widget_remove_contact (information);
1575 information->contact = g_object_ref (contact);
1577 /* set the selected account to be the account this contact came from */
1578 if (contact && EMPATHY_IS_ACCOUNT_CHOOSER (information->widget_account)) {
1579 empathy_account_chooser_set_account (
1580 EMPATHY_ACCOUNT_CHOOSER (information->widget_account),
1581 empathy_contact_get_account (contact));
1584 /* Update information for widgets */
1585 contact_widget_contact_update (information);
1586 contact_widget_groups_update (information);
1587 contact_widget_details_update (information);
1588 contact_widget_client_update (information);
1589 contact_widget_location_update (information);
1593 contact_widget_got_contact_cb (TpConnection *connection,
1594 EmpathyContact *contact,
1595 const GError *error,
1597 GObject *weak_object)
1599 EmpathyContactWidget *information = user_data;
1603 DEBUG ("Error: %s", error->message);
1607 contact_widget_set_contact (information, contact);
1611 contact_widget_change_contact (EmpathyContactWidget *information)
1613 TpConnection *connection;
1615 connection = empathy_account_chooser_get_connection (
1616 EMPATHY_ACCOUNT_CHOOSER (information->widget_account));
1620 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ID)
1624 id = gtk_entry_get_text (GTK_ENTRY (information->widget_id));
1625 if (!EMP_STR_EMPTY (id))
1627 empathy_tp_contact_factory_get_from_id (connection, id,
1628 contact_widget_got_contact_cb, information, NULL,
1629 G_OBJECT (information->vbox_contact_widget));
1634 empathy_tp_contact_factory_get_from_handle (connection,
1635 tp_connection_get_self_handle (connection),
1636 contact_widget_got_contact_cb, information, NULL,
1637 G_OBJECT (information->vbox_contact_widget));
1642 contact_widget_id_activate_timeout (EmpathyContactWidget *self)
1644 contact_widget_change_contact (self);
1649 contact_widget_id_changed_cb (GtkEntry *entry,
1650 EmpathyContactWidget *self)
1652 if (self->widget_id_timeout != 0)
1654 g_source_remove (self->widget_id_timeout);
1657 self->widget_id_timeout =
1658 g_timeout_add_seconds (ID_CHANGED_TIMEOUT,
1659 (GSourceFunc) contact_widget_id_activate_timeout, self);
1663 contact_widget_id_focus_out_cb (GtkWidget *widget,
1664 GdkEventFocus *event,
1665 EmpathyContactWidget *information)
1667 contact_widget_change_contact (information);
1672 favourite_toggled_cb (GtkToggleButton *button,
1673 EmpathyContactWidget *information)
1675 FolksIndividual *individual = folks_individual_from_empathy_contact (
1676 information->contact);
1678 if (individual != NULL)
1680 gboolean active = gtk_toggle_button_get_active (button);
1681 folks_favourite_set_is_favourite (FOLKS_FAVOURITE (individual), active);
1682 g_object_unref (individual);
1687 contact_widget_contact_setup (EmpathyContactWidget *information)
1689 /* Setup label_status as a KludgeLabel */
1690 information->label_status = empathy_kludge_label_new ("");
1691 gtk_label_set_line_wrap_mode (GTK_LABEL (information->label_status),
1692 PANGO_WRAP_WORD_CHAR);
1693 gtk_label_set_line_wrap (GTK_LABEL (information->label_status),
1696 if (!(information->flags & EMPATHY_CONTACT_WIDGET_FOR_TOOLTIP))
1697 gtk_label_set_selectable (GTK_LABEL (information->label_status), TRUE);
1699 gtk_box_pack_start (GTK_BOX (information->hbox_presence),
1700 information->label_status, TRUE, TRUE, 0);
1701 gtk_widget_show (information->label_status);
1703 /* Setup account label/chooser */
1704 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ACCOUNT)
1706 information->widget_account = empathy_account_chooser_new ();
1708 g_signal_connect_swapped (information->widget_account, "changed",
1709 G_CALLBACK (contact_widget_change_contact),
1714 /* Pack the protocol icon with the account name in an hbox */
1715 information->widget_account = gtk_hbox_new (FALSE, 6);
1717 information->label_account = gtk_label_new (NULL);
1718 if (!(information->flags & EMPATHY_CONTACT_WIDGET_FOR_TOOLTIP)) {
1719 gtk_label_set_selectable (GTK_LABEL (information->label_account), TRUE);
1721 gtk_misc_set_alignment (GTK_MISC (information->label_account), 0, 0.5);
1722 gtk_widget_show (information->label_account);
1724 information->image_account = gtk_image_new ();
1725 gtk_widget_show (information->image_account);
1727 gtk_box_pack_start (GTK_BOX (information->widget_account),
1728 information->image_account, FALSE, FALSE, 0);
1729 gtk_box_pack_start (GTK_BOX (information->widget_account),
1730 information->label_account, FALSE, TRUE, 0);
1732 gtk_table_attach_defaults (GTK_TABLE (information->table_contact),
1733 information->widget_account,
1735 gtk_widget_show (information->widget_account);
1737 /* Set up avatar chooser/display */
1738 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_AVATAR)
1740 information->widget_avatar = empathy_avatar_chooser_new ();
1741 g_signal_connect (information->widget_avatar, "changed",
1742 G_CALLBACK (contact_widget_avatar_changed_cb),
1744 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ACCOUNT)
1746 g_signal_connect (information->widget_account, "changed",
1747 G_CALLBACK (update_avatar_chooser_account_cb),
1748 information->widget_avatar);
1749 update_avatar_chooser_account_cb (
1750 EMPATHY_ACCOUNT_CHOOSER (information->widget_account),
1751 EMPATHY_AVATAR_CHOOSER (information->widget_avatar));
1756 information->widget_avatar = empathy_avatar_image_new ();
1758 g_signal_connect (information->widget_avatar, "popup-menu",
1759 G_CALLBACK (widget_avatar_popup_menu_cb), information);
1760 g_signal_connect (information->widget_avatar, "button-press-event",
1761 G_CALLBACK (widget_avatar_button_press_event_cb), information);
1764 gtk_box_pack_start (GTK_BOX (information->vbox_avatar),
1765 information->widget_avatar,
1768 gtk_widget_show (information->widget_avatar);
1770 /* Setup id label/entry */
1771 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ID)
1773 information->widget_id = gtk_entry_new ();
1774 g_signal_connect (information->widget_id, "focus-out-event",
1775 G_CALLBACK (contact_widget_id_focus_out_cb),
1777 g_signal_connect (information->widget_id, "changed",
1778 G_CALLBACK (contact_widget_id_changed_cb),
1783 information->widget_id = gtk_label_new (NULL);
1784 if (!(information->flags & EMPATHY_CONTACT_WIDGET_FOR_TOOLTIP)) {
1785 gtk_label_set_selectable (GTK_LABEL (information->widget_id), TRUE);
1787 gtk_misc_set_alignment (GTK_MISC (information->widget_id), 0, 0.5);
1789 gtk_table_attach_defaults (GTK_TABLE (information->table_contact),
1790 information->widget_id,
1792 gtk_widget_show (information->widget_id);
1794 /* Setup alias label/entry */
1795 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ALIAS)
1797 information->widget_alias = gtk_entry_new ();
1799 if (!(information->flags & EMPATHY_CONTACT_WIDGET_NO_SET_ALIAS))
1800 g_signal_connect (information->widget_alias, "focus-out-event",
1801 G_CALLBACK (contact_widget_entry_alias_focus_event_cb),
1804 /* Make return activate the window default (the Close button) */
1805 gtk_entry_set_activates_default (GTK_ENTRY (information->widget_alias),
1810 information->widget_alias = gtk_label_new (NULL);
1811 if (!(information->flags & EMPATHY_CONTACT_WIDGET_FOR_TOOLTIP)) {
1812 gtk_label_set_selectable (GTK_LABEL (information->widget_alias), TRUE);
1814 gtk_misc_set_alignment (GTK_MISC (information->widget_alias), 0, 0.5);
1816 gtk_table_attach_defaults (GTK_TABLE (information->table_contact),
1817 information->widget_alias,
1819 if (information->flags & EMPATHY_CONTACT_WIDGET_FOR_TOOLTIP) {
1820 gtk_label_set_selectable (GTK_LABEL (information->label_status), FALSE);
1822 gtk_widget_show (information->widget_alias);
1825 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_FAVOURITE)
1827 information->favourite_checkbox = gtk_check_button_new_with_label (
1830 g_signal_connect (information->favourite_checkbox, "toggled",
1831 G_CALLBACK (favourite_toggled_cb), information);
1833 gtk_table_attach_defaults (GTK_TABLE (information->table_contact),
1834 information->favourite_checkbox, 0, 2, 3, 4);
1836 information->fav_sig_id = g_signal_connect (information->manager,
1837 "favourites-changed",
1838 G_CALLBACK (contact_widget_favourites_changed_cb), information);
1840 gtk_widget_show (information->favourite_checkbox);
1845 contact_widget_destroy_cb (GtkWidget *widget,
1846 EmpathyContactWidget *information)
1848 contact_widget_remove_contact (information);
1850 if (information->widget_id_timeout != 0)
1852 g_source_remove (information->widget_id_timeout);
1855 if (information->fav_sig_id != 0)
1856 g_signal_handler_disconnect (information->manager, information->fav_sig_id);
1858 g_object_unref (information->manager);
1860 g_slice_free (EmpathyContactWidget, information);
1864 * empathy_contact_widget_new:
1865 * @contact: an #EmpathyContact
1866 * @flags: #EmpathyContactWidgetFlags for the new contact widget
1868 * Creates a new #EmpathyContactWidget.
1870 * Return value: a new #EmpathyContactWidget
1873 empathy_contact_widget_new (EmpathyContact *contact,
1874 EmpathyContactWidgetFlags flags)
1876 EmpathyContactWidget *information;
1880 g_return_val_if_fail (contact == NULL || EMPATHY_IS_CONTACT (contact), NULL);
1882 information = g_slice_new0 (EmpathyContactWidget);
1883 information->flags = flags;
1885 filename = empathy_file_lookup ("empathy-contact-widget.ui",
1887 gui = empathy_builder_get_file (filename,
1888 "vbox_contact_widget", &information->vbox_contact_widget,
1889 "hbox_contact", &information->hbox_contact,
1890 "hbox_presence", &information->hbox_presence,
1891 "label_alias", &information->label_alias,
1892 "image_state", &information->image_state,
1893 "table_contact", &information->table_contact,
1894 "vbox_avatar", &information->vbox_avatar,
1895 "vbox_location", &information->vbox_location,
1896 "subvbox_location", &information->subvbox_location,
1897 "label_location", &information->label_location,
1898 #if HAVE_LIBCHAMPLAIN
1899 "viewport_map", &information->viewport_map,
1901 "vbox_groups", &information->vbox_groups,
1902 "entry_group", &information->entry_group,
1903 "button_group", &information->button_group,
1904 "treeview_groups", &information->treeview_groups,
1905 "vbox_details", &information->vbox_details,
1906 "table_details", &information->table_details,
1907 "hbox_details_requested", &information->hbox_details_requested,
1908 "vbox_client", &information->vbox_client,
1909 "table_client", &information->table_client,
1910 "hbox_client_requested", &information->hbox_client_requested,
1914 empathy_builder_connect (gui, information,
1915 "vbox_contact_widget", "destroy", contact_widget_destroy_cb,
1916 "entry_group", "changed", contact_widget_entry_group_changed_cb,
1917 "entry_group", "activate", contact_widget_entry_group_activate_cb,
1918 "button_group", "clicked", contact_widget_button_group_clicked_cb,
1920 information->table_location = NULL;
1922 g_object_set_data (G_OBJECT (information->vbox_contact_widget),
1923 "EmpathyContactWidget",
1926 information->manager = empathy_contact_manager_dup_singleton ();
1928 /* Create widgets */
1929 contact_widget_contact_setup (information);
1930 contact_widget_groups_setup (information);
1931 contact_widget_details_setup (information);
1932 contact_widget_client_setup (information);
1934 if (contact != NULL)
1935 contact_widget_set_contact (information, contact);
1936 else if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ACCOUNT ||
1937 information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ID)
1938 contact_widget_change_contact (information);
1940 return empathy_builder_unref_and_keep_widget (gui,
1941 information->vbox_contact_widget);
1945 * empathy_contact_widget_get_contact:
1946 * @widget: an #EmpathyContactWidget
1948 * Get the #EmpathyContact related with the #EmpathyContactWidget @widget.
1950 * Returns: the #EmpathyContact associated with @widget
1953 empathy_contact_widget_get_contact (GtkWidget *widget)
1955 EmpathyContactWidget *information;
1957 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
1959 information = g_object_get_data (G_OBJECT (widget), "EmpathyContactWidget");
1963 return information->contact;
1967 empathy_contact_widget_get_alias (GtkWidget *widget)
1969 EmpathyContactWidget *information;
1971 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
1973 information = g_object_get_data (G_OBJECT (widget), "EmpathyContactWidget");
1977 return gtk_entry_get_text (GTK_ENTRY (information->widget_alias));
1981 * empathy_contact_widget_set_contact:
1982 * @widget: an #EmpathyContactWidget
1983 * @contact: a different #EmpathyContact
1985 * Change the #EmpathyContact related with the #EmpathyContactWidget @widget.
1988 empathy_contact_widget_set_contact (GtkWidget *widget,
1989 EmpathyContact *contact)
1991 EmpathyContactWidget *information;
1993 g_return_if_fail (GTK_IS_WIDGET (widget));
1994 g_return_if_fail (EMPATHY_IS_CONTACT (contact));
1996 information = g_object_get_data (G_OBJECT (widget), "EmpathyContactWidget");
2000 contact_widget_set_contact (information, contact);
2004 * empathy_contact_widget_set_account_filter:
2005 * @widget: an #EmpathyContactWidget
2006 * @filter: a #EmpathyAccountChooserFilterFunc
2007 * @user_data: user data to pass to @filter, or %NULL
2009 * Set a filter on the #EmpathyAccountChooser included in the
2010 * #EmpathyContactWidget.
2013 empathy_contact_widget_set_account_filter (
2015 EmpathyAccountChooserFilterFunc filter,
2018 EmpathyContactWidget *information;
2019 EmpathyAccountChooser *chooser;
2021 g_return_if_fail (GTK_IS_WIDGET (widget));
2023 information = g_object_get_data (G_OBJECT (widget), "EmpathyContactWidget");
2027 chooser = EMPATHY_ACCOUNT_CHOOSER (information->widget_account);
2029 empathy_account_chooser_set_filter (chooser, filter, user_data);