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 <libmissioncontrol/mc-account.h>
36 #include <telepathy-glib/util.h>
38 #include <libempathy/empathy-tp-contact-factory.h>
39 #include <libempathy/empathy-contact-manager.h>
40 #include <libempathy/empathy-contact-list.h>
41 #include <libempathy/empathy-utils.h>
43 #include "empathy-contact-widget.h"
44 #include "empathy-account-chooser.h"
45 #include "empathy-avatar-chooser.h"
46 #include "empathy-avatar-image.h"
47 #include "empathy-ui-utils.h"
49 #define DEBUG_FLAG EMPATHY_DEBUG_CONTACT
50 #include <libempathy/empathy-debug.h>
53 * SECTION:empathy-contact-widget
54 * @title:EmpathyContactWidget
55 * @short_description: A widget used to display and edit details about a contact
56 * @include: libempathy-empathy-contact-widget.h
58 * #EmpathyContactWidget is a widget which displays appropriate widgets
59 * with details about a contact, also allowing changing these details,
64 * EmpathyContactWidget:
65 * @parent: parent object
67 * Widget which displays appropriate widgets with details about a contact,
68 * also allowing changing these details, if desired.
71 /* Delay before updating the widget when the id entry changed (seconds) */
72 #define ID_CHANGED_TIMEOUT 1
76 EmpathyTpContactFactory *factory;
77 EmpathyContactManager *manager;
78 EmpathyContact *contact;
79 EmpathyContactWidgetFlags flags;
80 guint widget_id_timeout;
82 GtkWidget *vbox_contact_widget;
85 GtkWidget *vbox_contact;
86 GtkWidget *widget_avatar;
87 GtkWidget *widget_account;
89 GtkWidget *widget_alias;
90 GtkWidget *label_alias;
91 GtkWidget *entry_alias;
92 GtkWidget *hbox_presence;
93 GtkWidget *image_state;
94 GtkWidget *label_status;
95 GtkWidget *table_contact;
96 GtkWidget *vbox_avatar;
100 GtkWidget *vbox_location;
101 GtkWidget *label_location;
102 GtkWidget *viewport_map;
103 GtkWidget *map_view_embed;
104 ClutterActor *map_view;
108 GtkWidget *vbox_groups;
109 GtkWidget *entry_group;
110 GtkWidget *button_group;
111 GtkWidget *treeview_groups;
114 GtkWidget *vbox_details;
115 GtkWidget *table_details;
116 GtkWidget *hbox_details_requested;
119 GtkWidget *vbox_client;
120 GtkWidget *table_client;
121 GtkWidget *hbox_client_requested;
122 } EmpathyContactWidget;
126 EmpathyContactWidget *information;
129 GtkTreeIter found_iter;
132 static void contact_widget_destroy_cb (GtkWidget *widget,
133 EmpathyContactWidget *information);
134 static void contact_widget_remove_contact (EmpathyContactWidget *information);
135 static void contact_widget_set_contact (EmpathyContactWidget *information,
136 EmpathyContact *contact);
137 static void contact_widget_contact_setup (EmpathyContactWidget *information);
138 static void contact_widget_contact_update (EmpathyContactWidget *information);
139 static void contact_widget_change_contact (EmpathyContactWidget *information);
140 static void contact_widget_avatar_changed_cb (EmpathyAvatarChooser *chooser,
141 EmpathyContactWidget *information);
142 static gboolean contact_widget_id_focus_out_cb (GtkWidget *widget,
143 GdkEventFocus *event, EmpathyContactWidget *information);
144 static gboolean contact_widget_entry_alias_focus_event_cb (
145 GtkEditable *editable, GdkEventFocus *event,
146 EmpathyContactWidget *information);
147 static void contact_widget_name_notify_cb (EmpathyContactWidget *information);
148 static void contact_widget_presence_notify_cb (
149 EmpathyContactWidget *information);
150 static void contact_widget_avatar_notify_cb (
151 EmpathyContactWidget *information);
152 #if HAVE_LIBCHAMPLAIN
153 static void contact_widget_location_setup (
154 EmpathyContactWidget *information);
156 static void contact_widget_groups_setup (
157 EmpathyContactWidget *information);
158 static void contact_widget_groups_update (EmpathyContactWidget *information);
159 static void contact_widget_model_setup (EmpathyContactWidget *information);
160 static void contact_widget_model_populate_columns (
161 EmpathyContactWidget *information);
162 static void contact_widget_groups_populate_data (
163 EmpathyContactWidget *information);
164 static void contact_widget_groups_notify_cb (
165 EmpathyContactWidget *information);
166 static gboolean contact_widget_model_find_name (
167 EmpathyContactWidget *information,const gchar *name, GtkTreeIter *iter);
168 static gboolean contact_widget_model_find_name_foreach (GtkTreeModel *model,
169 GtkTreePath *path, GtkTreeIter *iter, FindName *data);
170 static void contact_widget_cell_toggled (GtkCellRendererToggle *cell,
171 gchar *path_string, EmpathyContactWidget *information);
172 static void contact_widget_entry_group_changed_cb (GtkEditable *editable,
173 EmpathyContactWidget *information);
174 static void contact_widget_entry_group_activate_cb (GtkEntry *entry,
175 EmpathyContactWidget *information);
176 static void contact_widget_button_group_clicked_cb (GtkButton *button,
177 EmpathyContactWidget *information);
178 static void contact_widget_details_setup (EmpathyContactWidget *information);
179 static void contact_widget_details_update (EmpathyContactWidget *information);
180 static void contact_widget_client_setup (EmpathyContactWidget *information);
181 static void contact_widget_client_update (EmpathyContactWidget *information);
192 * empathy_contact_widget_new:
193 * @contact: an #EmpathyContact
194 * @flags: #EmpathyContactWidgetFlags for the new contact widget
196 * Creates a new #EmpathyContactWidget.
198 * Return value: a new #EmpathyContactWidget
201 empathy_contact_widget_new (EmpathyContact *contact,
202 EmpathyContactWidgetFlags flags)
204 EmpathyContactWidget *information;
208 g_return_val_if_fail (contact == NULL || EMPATHY_IS_CONTACT (contact), NULL);
210 information = g_slice_new0 (EmpathyContactWidget);
211 information->flags = flags;
213 filename = empathy_file_lookup ("empathy-contact-widget.ui",
215 gui = empathy_builder_get_file (filename,
216 "vbox_contact_widget", &information->vbox_contact_widget,
217 "vbox_contact", &information->vbox_contact,
218 "hbox_presence", &information->hbox_presence,
219 "label_alias", &information->label_alias,
220 "image_state", &information->image_state,
221 "label_status", &information->label_status,
222 "table_contact", &information->table_contact,
223 "vbox_avatar", &information->vbox_avatar,
224 #if HAVE_LIBCHAMPLAIN
225 "vbox_location", &information->vbox_location,
226 "label_location", &information->label_location,
227 "viewport_map", &information->viewport_map,
229 "vbox_groups", &information->vbox_groups,
230 "entry_group", &information->entry_group,
231 "button_group", &information->button_group,
232 "treeview_groups", &information->treeview_groups,
233 "vbox_details", &information->vbox_details,
234 "table_details", &information->table_details,
235 "hbox_details_requested", &information->hbox_details_requested,
236 "vbox_client", &information->vbox_client,
237 "table_client", &information->table_client,
238 "hbox_client_requested", &information->hbox_client_requested,
242 empathy_builder_connect (gui, information,
243 "vbox_contact_widget", "destroy", contact_widget_destroy_cb,
244 "entry_group", "changed", contact_widget_entry_group_changed_cb,
245 "entry_group", "activate", contact_widget_entry_group_activate_cb,
246 "button_group", "clicked", contact_widget_button_group_clicked_cb,
249 g_object_set_data (G_OBJECT (information->vbox_contact_widget),
250 "EmpathyContactWidget",
254 contact_widget_contact_setup (information);
255 #if HAVE_LIBCHAMPLAIN
256 contact_widget_location_setup (information);
258 contact_widget_groups_setup (information);
259 contact_widget_details_setup (information);
260 contact_widget_client_setup (information);
263 contact_widget_set_contact (information, contact);
265 else if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ACCOUNT ||
266 information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ID)
267 contact_widget_change_contact (information);
269 return empathy_builder_unref_and_keep_widget (gui,
270 information->vbox_contact_widget);
274 * empathy_contact_widget_get_contact:
275 * @widget: an #EmpathyContactWidget
277 * Get the #EmpathyContact related with the #EmpathyContactWidget @widget.
279 * Returns: the #EmpathyContact associated with @widget
282 empathy_contact_widget_get_contact (GtkWidget *widget)
284 EmpathyContactWidget *information;
286 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
288 information = g_object_get_data (G_OBJECT (widget), "EmpathyContactWidget");
292 return information->contact;
296 * empathy_contact_widget_set_contact:
297 * @widget: an #EmpathyContactWidget
298 * @contact: a different #EmpathyContact
300 * Change the #EmpathyContact related with the #EmpathyContactWidget @widget.
303 empathy_contact_widget_set_contact (GtkWidget *widget,
304 EmpathyContact *contact)
306 EmpathyContactWidget *information;
308 g_return_if_fail (GTK_IS_WIDGET (widget));
309 g_return_if_fail (EMPATHY_IS_CONTACT (contact));
311 information = g_object_get_data (G_OBJECT (widget), "EmpathyContactWidget");
315 contact_widget_set_contact (information, contact);
319 * empathy_contact_widget_set_account_filter:
320 * @widget: an #EmpathyContactWidget
321 * @filter: a #EmpathyAccountChooserFilterFunc
322 * @user_data: user data to pass to @filter, or %NULL
324 * Set a filter on the #EmpathyAccountChooser included in the
325 * #EmpathyContactWidget.
328 empathy_contact_widget_set_account_filter (
330 EmpathyAccountChooserFilterFunc filter,
333 EmpathyContactWidget *information;
334 EmpathyAccountChooser *chooser;
336 g_return_if_fail (GTK_IS_WIDGET (widget));
338 information = g_object_get_data (G_OBJECT (widget), "EmpathyContactWidget");
342 chooser = EMPATHY_ACCOUNT_CHOOSER (information->widget_account);
344 empathy_account_chooser_set_filter (chooser, filter, user_data);
348 contact_widget_destroy_cb (GtkWidget *widget,
349 EmpathyContactWidget *information)
351 contact_widget_remove_contact (information);
353 if (information->widget_id_timeout != 0)
355 g_source_remove (information->widget_id_timeout);
357 if (information->manager)
359 g_object_unref (information->manager);
362 g_slice_free (EmpathyContactWidget, information);
366 contact_widget_remove_contact (EmpathyContactWidget *information)
368 if (information->contact)
370 g_signal_handlers_disconnect_by_func (information->contact,
371 contact_widget_name_notify_cb, information);
372 g_signal_handlers_disconnect_by_func (information->contact,
373 contact_widget_presence_notify_cb, information);
374 g_signal_handlers_disconnect_by_func (information->contact,
375 contact_widget_avatar_notify_cb, information);
376 g_signal_handlers_disconnect_by_func (information->contact,
377 contact_widget_groups_notify_cb, information);
379 g_object_unref (information->contact);
380 g_object_unref (information->factory);
381 information->contact = NULL;
382 information->factory = NULL;
387 contact_widget_set_contact (EmpathyContactWidget *information,
388 EmpathyContact *contact)
390 if (contact == information->contact)
393 contact_widget_remove_contact (information);
396 TpConnection *connection;
398 connection = empathy_contact_get_connection (contact);
399 information->contact = g_object_ref (contact);
400 information->factory = empathy_tp_contact_factory_dup_singleton (connection);
403 /* Update information for widgets */
404 contact_widget_contact_update (information);
405 contact_widget_groups_update (information);
406 contact_widget_details_update (information);
407 contact_widget_client_update (information);
411 contact_widget_id_activate_timeout (EmpathyContactWidget *self)
413 contact_widget_change_contact (self);
418 contact_widget_id_changed_cb (GtkEntry *entry,
419 EmpathyContactWidget *self)
421 if (self->widget_id_timeout != 0)
423 g_source_remove (self->widget_id_timeout);
426 self->widget_id_timeout =
427 g_timeout_add_seconds (ID_CHANGED_TIMEOUT,
428 (GSourceFunc) contact_widget_id_activate_timeout, self);
432 save_avatar_menu_activate_cb (GtkWidget *widget,
433 EmpathyContactWidget *information)
436 EmpathyAvatar *avatar;
437 gchar *ext = NULL, *filename;
439 dialog = gtk_file_chooser_dialog_new (_("Save Avatar"),
441 GTK_FILE_CHOOSER_ACTION_SAVE,
442 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
443 GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT,
446 gtk_file_chooser_set_do_overwrite_confirmation (GTK_FILE_CHOOSER (dialog),
449 /* look for the avatar extension */
450 avatar = empathy_contact_get_avatar (information->contact);
451 if (avatar->format != NULL)
455 splitted = g_strsplit (avatar->format, "/", 2);
456 if (splitted[0] != NULL && splitted[1] != NULL)
457 ext = g_strdup (splitted[1]);
459 g_strfreev (splitted);
463 /* Avatar was loaded from the cache so was converted to PNG */
464 ext = g_strdup ("png");
471 id = tp_escape_as_identifier (empathy_contact_get_id (
472 information->contact));
474 filename = g_strdup_printf ("%s.%s", id, ext);
475 gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (dialog), filename);
482 if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT)
484 GError *error = NULL;
486 filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
488 if (!empathy_avatar_save_to_file (avatar, filename, &error))
493 dialog = gtk_message_dialog_new (NULL, 0,
494 GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE,
495 _("Unable to save avatar"));
497 gtk_message_dialog_format_secondary_text (
498 GTK_MESSAGE_DIALOG (dialog), "%s", error->message);
500 g_signal_connect (dialog, "response",
501 G_CALLBACK (gtk_widget_destroy), NULL);
503 gtk_window_present (GTK_WINDOW (dialog));
505 g_clear_error (&error);
511 gtk_widget_destroy (dialog);
515 popup_avatar_menu (EmpathyContactWidget *information,
517 GdkEventButton *event)
519 GtkWidget *menu, *item;
520 gint button, event_time;
522 if (information->contact == NULL ||
523 empathy_contact_get_avatar (information->contact) == NULL)
526 menu = gtk_menu_new ();
528 /* Add "Save as..." entry */
529 item = gtk_image_menu_item_new_from_stock (GTK_STOCK_SAVE_AS, NULL);
530 gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
531 gtk_widget_show (item);
533 g_signal_connect (item, "activate",
534 G_CALLBACK (save_avatar_menu_activate_cb), information);
538 button = event->button;
539 event_time = event->time;
544 event_time = gtk_get_current_event_time ();
547 gtk_menu_attach_to_widget (GTK_MENU (menu), parent, NULL);
548 gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
553 widget_avatar_popup_menu_cb (GtkWidget *widget,
554 EmpathyContactWidget *information)
556 popup_avatar_menu (information, widget, NULL);
562 widget_avatar_button_press_event_cb (GtkWidget *widget,
563 GdkEventButton *event,
564 EmpathyContactWidget *information)
566 /* Ignore double-clicks and triple-clicks */
567 if (event->button == 3 && event->type == GDK_BUTTON_PRESS)
569 popup_avatar_menu (information, widget, event);
577 update_avatar_chooser_account_cb (EmpathyAccountChooser *account_chooser,
578 EmpathyAvatarChooser *avatar_chooser)
580 TpConnection *connection;
582 connection = empathy_account_chooser_get_connection (account_chooser);
583 g_object_set (avatar_chooser, "connection", connection, NULL);
587 contact_widget_contact_setup (EmpathyContactWidget *information)
589 /* Setup account label/chooser */
590 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ACCOUNT)
592 information->widget_account = empathy_account_chooser_new ();
594 g_signal_connect_swapped (information->widget_account, "changed",
595 G_CALLBACK (contact_widget_change_contact),
600 information->widget_account = gtk_label_new (NULL);
601 if (!(information->flags & EMPATHY_CONTACT_WIDGET_FOR_TOOLTIP)) {
602 gtk_label_set_selectable (GTK_LABEL (information->widget_account), TRUE);
604 gtk_misc_set_alignment (GTK_MISC (information->widget_account), 0, 0.5);
606 gtk_table_attach_defaults (GTK_TABLE (information->table_contact),
607 information->widget_account,
609 gtk_widget_show (information->widget_account);
611 /* Set up avatar chooser/display */
612 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_AVATAR)
614 information->widget_avatar = empathy_avatar_chooser_new ();
615 g_signal_connect (information->widget_avatar, "changed",
616 G_CALLBACK (contact_widget_avatar_changed_cb),
618 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ACCOUNT)
620 g_signal_connect (information->widget_account, "changed",
621 G_CALLBACK (update_avatar_chooser_account_cb),
622 information->widget_avatar);
623 update_avatar_chooser_account_cb (
624 EMPATHY_ACCOUNT_CHOOSER (information->widget_account),
625 EMPATHY_AVATAR_CHOOSER (information->widget_avatar));
630 information->widget_avatar = empathy_avatar_image_new ();
632 g_signal_connect (information->widget_avatar, "popup-menu",
633 G_CALLBACK (widget_avatar_popup_menu_cb), information);
634 g_signal_connect (information->widget_avatar, "button-press-event",
635 G_CALLBACK (widget_avatar_button_press_event_cb), information);
638 gtk_box_pack_start (GTK_BOX (information->vbox_avatar),
639 information->widget_avatar,
642 gtk_widget_show (information->widget_avatar);
644 /* Setup id label/entry */
645 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ID)
647 information->widget_id = gtk_entry_new ();
648 g_signal_connect (information->widget_id, "focus-out-event",
649 G_CALLBACK (contact_widget_id_focus_out_cb),
651 g_signal_connect (information->widget_id, "changed",
652 G_CALLBACK (contact_widget_id_changed_cb),
657 information->widget_id = gtk_label_new (NULL);
658 if (!(information->flags & EMPATHY_CONTACT_WIDGET_FOR_TOOLTIP)) {
659 gtk_label_set_selectable (GTK_LABEL (information->widget_id), TRUE);
661 gtk_misc_set_alignment (GTK_MISC (information->widget_id), 0, 0.5);
663 gtk_table_attach_defaults (GTK_TABLE (information->table_contact),
664 information->widget_id,
666 gtk_widget_show (information->widget_id);
668 /* Setup alias label/entry */
669 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ALIAS)
671 information->widget_alias = gtk_entry_new ();
672 g_signal_connect (information->widget_alias, "focus-out-event",
673 G_CALLBACK (contact_widget_entry_alias_focus_event_cb),
675 /* Make return activate the window default (the Close button) */
676 gtk_entry_set_activates_default (GTK_ENTRY (information->widget_alias),
681 information->widget_alias = gtk_label_new (NULL);
682 if (!(information->flags & EMPATHY_CONTACT_WIDGET_FOR_TOOLTIP)) {
683 gtk_label_set_selectable (GTK_LABEL (information->widget_alias), TRUE);
685 gtk_misc_set_alignment (GTK_MISC (information->widget_alias), 0, 0.5);
687 gtk_table_attach_defaults (GTK_TABLE (information->table_contact),
688 information->widget_alias,
690 if (information->flags & EMPATHY_CONTACT_WIDGET_FOR_TOOLTIP) {
691 gtk_label_set_selectable (GTK_LABEL (information->label_status), FALSE);
693 gtk_widget_show (information->widget_alias);
697 contact_widget_contact_update (EmpathyContactWidget *information)
699 McAccount *account = NULL;
700 const gchar *id = NULL;
702 /* Connect and get info from new contact */
703 if (information->contact)
705 g_signal_connect_swapped (information->contact, "notify::name",
706 G_CALLBACK (contact_widget_name_notify_cb), information);
707 g_signal_connect_swapped (information->contact, "notify::presence",
708 G_CALLBACK (contact_widget_presence_notify_cb), information);
709 g_signal_connect_swapped (information->contact,
710 "notify::presence-message",
711 G_CALLBACK (contact_widget_presence_notify_cb), information);
712 g_signal_connect_swapped (information->contact, "notify::avatar",
713 G_CALLBACK (contact_widget_avatar_notify_cb), information);
715 account = empathy_contact_get_account (information->contact);
716 id = empathy_contact_get_id (information->contact);
719 /* Update account widget */
720 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ACCOUNT)
724 g_signal_handlers_block_by_func (information->widget_account,
725 contact_widget_change_contact,
727 empathy_account_chooser_set_account (
728 EMPATHY_ACCOUNT_CHOOSER (information->widget_account), account);
729 g_signal_handlers_unblock_by_func (information->widget_account,
730 contact_widget_change_contact, information);
739 name = mc_account_get_display_name (account);
740 gtk_label_set_label (GTK_LABEL (information->widget_account), name);
744 /* Update id widget */
745 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ID)
746 gtk_entry_set_text (GTK_ENTRY (information->widget_id), id ? id : "");
748 gtk_label_set_label (GTK_LABEL (information->widget_id), id ? id : "");
750 /* Update other widgets */
751 if (information->contact)
753 contact_widget_name_notify_cb (information);
754 contact_widget_presence_notify_cb (information);
755 contact_widget_avatar_notify_cb (information);
757 gtk_widget_show (information->label_alias);
758 gtk_widget_show (information->widget_alias);
759 gtk_widget_show (information->hbox_presence);
760 gtk_widget_show (information->widget_avatar);
764 gtk_widget_hide (information->label_alias);
765 gtk_widget_hide (information->widget_alias);
766 gtk_widget_hide (information->hbox_presence);
767 gtk_widget_hide (information->widget_avatar);
772 contact_widget_got_contact_cb (EmpathyTpContactFactory *factory,
773 EmpathyContact *contact,
776 GObject *weak_object)
778 EmpathyContactWidget *information = user_data;
782 DEBUG ("Error: %s", error->message);
786 contact_widget_set_contact (information, contact);
790 contact_widget_change_contact (EmpathyContactWidget *information)
792 EmpathyTpContactFactory *factory;
793 TpConnection *connection;
795 connection = empathy_account_chooser_get_connection (
796 EMPATHY_ACCOUNT_CHOOSER (information->widget_account));
800 factory = empathy_tp_contact_factory_dup_singleton (connection);
801 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ID)
805 id = gtk_entry_get_text (GTK_ENTRY (information->widget_id));
806 if (!EMP_STR_EMPTY (id))
808 empathy_tp_contact_factory_get_from_id (factory, id,
809 contact_widget_got_contact_cb, information, NULL,
810 G_OBJECT (information->vbox_contact_widget));
815 empathy_tp_contact_factory_get_from_handle (factory,
816 tp_connection_get_self_handle (connection),
817 contact_widget_got_contact_cb, information, NULL,
818 G_OBJECT (information->vbox_contact_widget));
821 g_object_unref (factory);
825 contact_widget_avatar_changed_cb (EmpathyAvatarChooser *chooser,
826 EmpathyContactWidget *information)
830 const gchar *mime_type;
832 empathy_avatar_chooser_get_image_data (
833 EMPATHY_AVATAR_CHOOSER (information->widget_avatar),
834 &data, &size, &mime_type);
835 empathy_tp_contact_factory_set_avatar (information->factory,
836 data, size, mime_type);
840 contact_widget_id_focus_out_cb (GtkWidget *widget,
841 GdkEventFocus *event,
842 EmpathyContactWidget *information)
844 contact_widget_change_contact (information);
849 contact_widget_entry_alias_focus_event_cb (GtkEditable *editable,
850 GdkEventFocus *event,
851 EmpathyContactWidget *information)
853 if (information->contact)
857 alias = gtk_entry_get_text (GTK_ENTRY (editable));
858 empathy_tp_contact_factory_set_alias (information->factory,
859 information->contact, alias);
866 contact_widget_name_notify_cb (EmpathyContactWidget *information)
868 if (GTK_IS_ENTRY (information->widget_alias))
869 gtk_entry_set_text (GTK_ENTRY (information->widget_alias),
870 empathy_contact_get_name (information->contact));
872 gtk_label_set_label (GTK_LABEL (information->widget_alias),
873 empathy_contact_get_name (information->contact));
877 contact_widget_presence_notify_cb (EmpathyContactWidget *information)
879 gtk_label_set_text (GTK_LABEL (information->label_status),
880 empathy_contact_get_status (information->contact));
881 gtk_image_set_from_icon_name (GTK_IMAGE (information->image_state),
882 empathy_icon_name_for_contact (information->contact),
883 GTK_ICON_SIZE_BUTTON);
887 contact_widget_avatar_notify_cb (EmpathyContactWidget *information)
889 EmpathyAvatar *avatar = NULL;
891 if (information->contact)
892 avatar = empathy_contact_get_avatar (information->contact);
894 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_AVATAR)
896 g_signal_handlers_block_by_func (information->widget_avatar,
897 contact_widget_avatar_changed_cb,
899 empathy_avatar_chooser_set (
900 EMPATHY_AVATAR_CHOOSER (information->widget_avatar), avatar);
901 g_signal_handlers_unblock_by_func (information->widget_avatar,
902 contact_widget_avatar_changed_cb, information);
905 empathy_avatar_image_set (
906 EMPATHY_AVATAR_IMAGE (information->widget_avatar), avatar);
909 #if HAVE_LIBCHAMPLAIN
911 contact_widget_location_setup (EmpathyContactWidget *information)
913 if (/* information->flags & EMPATHY_CONTACT_WIDGET_FOR_TOOLTIP || */
914 information->flags & EMPATHY_CONTACT_WIDGET_SHOW_LOCATION)
916 information->map_view = champlain_view_new (CHAMPLAIN_VIEW_MODE_KINETIC);
917 information->map_view_embed = champlain_view_embed_new (
918 CHAMPLAIN_VIEW (information->map_view));
920 gtk_container_add (GTK_CONTAINER (information->viewport_map),
921 information->map_view_embed);
922 g_object_set (G_OBJECT (information->map_view), "show-license", FALSE,
924 champlain_view_center_on (CHAMPLAIN_VIEW(information->map_view), 45, -73);
926 gtk_widget_show_all (information->vbox_location);
932 contact_widget_groups_setup (EmpathyContactWidget *information)
934 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_GROUPS)
936 information->manager = empathy_contact_manager_dup_singleton ();
937 contact_widget_model_setup (information);
942 contact_widget_groups_update (EmpathyContactWidget *information)
944 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_GROUPS &&
945 information->contact)
947 g_signal_connect_swapped (information->contact, "notify::groups",
948 G_CALLBACK (contact_widget_groups_notify_cb), information);
949 contact_widget_groups_populate_data (information);
951 gtk_widget_show (information->vbox_groups);
954 gtk_widget_hide (information->vbox_groups);
958 contact_widget_model_setup (EmpathyContactWidget *information)
962 GtkTreeSelection *selection;
964 view = GTK_TREE_VIEW (information->treeview_groups);
966 store = gtk_list_store_new (COL_COUNT,
967 G_TYPE_STRING, /* name */
968 G_TYPE_BOOLEAN, /* enabled */
969 G_TYPE_BOOLEAN); /* editable */
971 gtk_tree_view_set_model (view, GTK_TREE_MODEL (store));
973 selection = gtk_tree_view_get_selection (view);
974 gtk_tree_selection_set_mode (selection, GTK_SELECTION_SINGLE);
976 contact_widget_model_populate_columns (information);
978 gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (store),
979 COL_NAME, GTK_SORT_ASCENDING);
981 g_object_unref (store);
985 contact_widget_model_populate_columns (EmpathyContactWidget *information)
989 GtkTreeViewColumn *column;
990 GtkCellRenderer *renderer;
993 view = GTK_TREE_VIEW (information->treeview_groups);
994 model = gtk_tree_view_get_model (view);
996 renderer = gtk_cell_renderer_toggle_new ();
997 g_signal_connect (renderer, "toggled",
998 G_CALLBACK (contact_widget_cell_toggled), information);
1000 column = gtk_tree_view_column_new_with_attributes (_("Select"), renderer,
1001 "active", COL_ENABLED, NULL);
1003 gtk_tree_view_column_set_sizing (column, GTK_TREE_VIEW_COLUMN_FIXED);
1004 gtk_tree_view_column_set_fixed_width (column, 50);
1005 gtk_tree_view_append_column (view, column);
1007 renderer = gtk_cell_renderer_text_new ();
1008 col_offset = gtk_tree_view_insert_column_with_attributes (view,
1012 /* "editable", COL_EDITABLE, */
1015 g_object_set_data (G_OBJECT (renderer),
1016 "column", GINT_TO_POINTER (COL_NAME));
1018 column = gtk_tree_view_get_column (view, col_offset - 1);
1019 gtk_tree_view_column_set_sort_column_id (column, COL_NAME);
1020 gtk_tree_view_column_set_resizable (column,FALSE);
1021 gtk_tree_view_column_set_clickable (GTK_TREE_VIEW_COLUMN (column), TRUE);
1025 contact_widget_groups_populate_data (EmpathyContactWidget *information)
1028 GtkListStore *store;
1030 GList *my_groups, *l;
1033 view = GTK_TREE_VIEW (information->treeview_groups);
1034 store = GTK_LIST_STORE (gtk_tree_view_get_model (view));
1035 gtk_list_store_clear (store);
1037 all_groups = empathy_contact_list_get_all_groups (
1038 EMPATHY_CONTACT_LIST (information->manager));
1039 my_groups = empathy_contact_list_get_groups (
1040 EMPATHY_CONTACT_LIST (information->manager),
1041 information->contact);
1043 for (l = all_groups; l; l = l->next)
1045 const gchar *group_str;
1048 group_str = l->data;
1050 enabled = g_list_find_custom (my_groups,
1051 group_str, (GCompareFunc) strcmp) != NULL;
1053 gtk_list_store_append (store, &iter);
1054 gtk_list_store_set (store, &iter,
1055 COL_NAME, group_str,
1057 COL_ENABLED, enabled,
1061 g_list_foreach (all_groups, (GFunc) g_free, NULL);
1062 g_list_foreach (my_groups, (GFunc) g_free, NULL);
1063 g_list_free (all_groups);
1064 g_list_free (my_groups);
1068 contact_widget_groups_notify_cb (EmpathyContactWidget *information)
1070 /* FIXME: not implemented */
1074 contact_widget_model_find_name (EmpathyContactWidget *information,
1079 GtkTreeModel *model;
1082 if (EMP_STR_EMPTY (name))
1085 data.information = information;
1089 view = GTK_TREE_VIEW (information->treeview_groups);
1090 model = gtk_tree_view_get_model (view);
1092 gtk_tree_model_foreach (model,
1093 (GtkTreeModelForeachFunc) contact_widget_model_find_name_foreach,
1096 if (data.found == TRUE)
1098 *iter = data.found_iter;
1106 contact_widget_model_find_name_foreach (GtkTreeModel *model,
1113 gtk_tree_model_get (model, iter,
1120 if (data->name && strcmp (data->name, name) == 0)
1123 data->found_iter = *iter;
1136 contact_widget_cell_toggled (GtkCellRendererToggle *cell,
1138 EmpathyContactWidget *information)
1141 GtkTreeModel *model;
1142 GtkListStore *store;
1148 view = GTK_TREE_VIEW (information->treeview_groups);
1149 model = gtk_tree_view_get_model (view);
1150 store = GTK_LIST_STORE (model);
1152 path = gtk_tree_path_new_from_string (path_string);
1154 gtk_tree_model_get_iter (model, &iter, path);
1155 gtk_tree_model_get (model, &iter,
1156 COL_ENABLED, &enabled,
1160 gtk_list_store_set (store, &iter, COL_ENABLED, !enabled, -1);
1161 gtk_tree_path_free (path);
1167 empathy_contact_list_remove_from_group (
1168 EMPATHY_CONTACT_LIST (information->manager), information->contact,
1173 empathy_contact_list_add_to_group (
1174 EMPATHY_CONTACT_LIST (information->manager), information->contact,
1182 contact_widget_entry_group_changed_cb (GtkEditable *editable,
1183 EmpathyContactWidget *information)
1188 group = gtk_entry_get_text (GTK_ENTRY (information->entry_group));
1190 if (contact_widget_model_find_name (information, group, &iter))
1191 gtk_widget_set_sensitive (GTK_WIDGET (information->button_group), FALSE);
1193 gtk_widget_set_sensitive (GTK_WIDGET (information->button_group),
1194 !EMP_STR_EMPTY (group));
1198 contact_widget_entry_group_activate_cb (GtkEntry *entry,
1199 EmpathyContactWidget *information)
1201 gtk_widget_activate (GTK_WIDGET (information->button_group));
1205 contact_widget_button_group_clicked_cb (GtkButton *button,
1206 EmpathyContactWidget *information)
1209 GtkListStore *store;
1213 view = GTK_TREE_VIEW (information->treeview_groups);
1214 store = GTK_LIST_STORE (gtk_tree_view_get_model (view));
1216 group = gtk_entry_get_text (GTK_ENTRY (information->entry_group));
1218 gtk_list_store_append (store, &iter);
1219 gtk_list_store_set (store, &iter,
1224 empathy_contact_list_add_to_group (
1225 EMPATHY_CONTACT_LIST (information->manager), information->contact,
1230 contact_widget_details_setup (EmpathyContactWidget *information)
1232 /* FIXME: Needs new telepathy spec */
1233 gtk_widget_hide (information->vbox_details);
1237 contact_widget_details_update (EmpathyContactWidget *information)
1239 /* FIXME: Needs new telepathy spec */
1243 contact_widget_client_setup (EmpathyContactWidget *information)
1245 /* FIXME: Needs new telepathy spec */
1246 gtk_widget_hide (information->vbox_client);
1250 contact_widget_client_update (EmpathyContactWidget *information)
1252 /* FIXME: Needs new telepathy spec */