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 #include <libmissioncontrol/mc-account.h>
31 #include <telepathy-glib/util.h>
33 #include <libempathy/empathy-tp-contact-factory.h>
34 #include <libempathy/empathy-contact-manager.h>
35 #include <libempathy/empathy-contact-list.h>
36 #include <libempathy/empathy-utils.h>
38 #include "empathy-contact-widget.h"
39 #include "empathy-account-chooser.h"
40 #include "empathy-avatar-chooser.h"
41 #include "empathy-avatar-image.h"
42 #include "empathy-ui-utils.h"
44 #define DEBUG_FLAG EMPATHY_DEBUG_CONTACT
45 #include <libempathy/empathy-debug.h>
47 /* Delay before updating the widget when the id entry changed (seconds) */
48 #define ID_CHANGED_TIMEOUT 1
52 EmpathyTpContactFactory *factory;
53 EmpathyContactManager *manager;
54 EmpathyContact *contact;
55 EmpathyContactWidgetFlags flags;
56 guint widget_id_timeout;
58 GtkWidget *vbox_contact_widget;
61 GtkWidget *vbox_contact;
62 GtkWidget *widget_avatar;
63 GtkWidget *widget_account;
65 GtkWidget *widget_alias;
66 GtkWidget *label_alias;
67 GtkWidget *entry_alias;
68 GtkWidget *hbox_presence;
69 GtkWidget *image_state;
70 GtkWidget *label_status;
71 GtkWidget *table_contact;
72 GtkWidget *vbox_avatar;
75 GtkWidget *vbox_groups;
76 GtkWidget *entry_group;
77 GtkWidget *button_group;
78 GtkWidget *treeview_groups;
81 GtkWidget *vbox_details;
82 GtkWidget *table_details;
83 GtkWidget *hbox_details_requested;
86 GtkWidget *vbox_client;
87 GtkWidget *table_client;
88 GtkWidget *hbox_client_requested;
89 } EmpathyContactWidget;
93 EmpathyContactWidget *information;
96 GtkTreeIter found_iter;
99 static void contact_widget_destroy_cb (GtkWidget *widget,
100 EmpathyContactWidget *information);
101 static void contact_widget_remove_contact (EmpathyContactWidget *information);
102 static void contact_widget_set_contact (EmpathyContactWidget *information,
103 EmpathyContact *contact);
104 static void contact_widget_contact_setup (EmpathyContactWidget *information);
105 static void contact_widget_contact_update (EmpathyContactWidget *information);
106 static void contact_widget_change_contact (EmpathyContactWidget *information);
107 static void contact_widget_avatar_changed_cb (EmpathyAvatarChooser *chooser,
108 EmpathyContactWidget *information);
109 static gboolean contact_widget_id_focus_out_cb (GtkWidget *widget,
110 GdkEventFocus *event, EmpathyContactWidget *information);
111 static gboolean contact_widget_entry_alias_focus_event_cb (
112 GtkEditable *editable, GdkEventFocus *event,
113 EmpathyContactWidget *information);
114 static void contact_widget_name_notify_cb (EmpathyContactWidget *information);
115 static void contact_widget_presence_notify_cb (
116 EmpathyContactWidget *information);
117 static void contact_widget_avatar_notify_cb (
118 EmpathyContactWidget *information);
119 static void contact_widget_groups_setup (
120 EmpathyContactWidget *information);
121 static void contact_widget_groups_update (EmpathyContactWidget *information);
122 static void contact_widget_model_setup (EmpathyContactWidget *information);
123 static void contact_widget_model_populate_columns (
124 EmpathyContactWidget *information);
125 static void contact_widget_groups_populate_data (
126 EmpathyContactWidget *information);
127 static void contact_widget_groups_notify_cb (
128 EmpathyContactWidget *information);
129 static gboolean contact_widget_model_find_name (
130 EmpathyContactWidget *information,const gchar *name, GtkTreeIter *iter);
131 static gboolean contact_widget_model_find_name_foreach (GtkTreeModel *model,
132 GtkTreePath *path, GtkTreeIter *iter, FindName *data);
133 static void contact_widget_cell_toggled (GtkCellRendererToggle *cell,
134 gchar *path_string, EmpathyContactWidget *information);
135 static void contact_widget_entry_group_changed_cb (GtkEditable *editable,
136 EmpathyContactWidget *information);
137 static void contact_widget_entry_group_activate_cb (GtkEntry *entry,
138 EmpathyContactWidget *information);
139 static void contact_widget_button_group_clicked_cb (GtkButton *button,
140 EmpathyContactWidget *information);
141 static void contact_widget_details_setup (EmpathyContactWidget *information);
142 static void contact_widget_details_update (EmpathyContactWidget *information);
143 static void contact_widget_client_setup (EmpathyContactWidget *information);
144 static void contact_widget_client_update (EmpathyContactWidget *information);
155 empathy_contact_widget_new (EmpathyContact *contact,
156 EmpathyContactWidgetFlags flags)
158 EmpathyContactWidget *information;
160 TpConnection *connection;
163 g_return_val_if_fail (contact == NULL || EMPATHY_IS_CONTACT (contact), NULL);
165 information = g_slice_new0 (EmpathyContactWidget);
166 information->flags = flags;
168 filename = empathy_file_lookup ("empathy-contact-widget.ui",
170 gui = empathy_builder_get_file (filename,
171 "vbox_contact_widget", &information->vbox_contact_widget,
172 "vbox_contact", &information->vbox_contact,
173 "hbox_presence", &information->hbox_presence,
174 "label_alias", &information->label_alias,
175 "image_state", &information->image_state,
176 "label_status", &information->label_status,
177 "table_contact", &information->table_contact,
178 "vbox_avatar", &information->vbox_avatar,
179 "vbox_groups", &information->vbox_groups,
180 "entry_group", &information->entry_group,
181 "button_group", &information->button_group,
182 "treeview_groups", &information->treeview_groups,
183 "vbox_details", &information->vbox_details,
184 "table_details", &information->table_details,
185 "hbox_details_requested", &information->hbox_details_requested,
186 "vbox_client", &information->vbox_client,
187 "table_client", &information->table_client,
188 "hbox_client_requested", &information->hbox_client_requested,
192 empathy_builder_connect (gui, information,
193 "vbox_contact_widget", "destroy", contact_widget_destroy_cb,
194 "entry_group", "changed", contact_widget_entry_group_changed_cb,
195 "entry_group", "activate", contact_widget_entry_group_activate_cb,
196 "button_group", "clicked", contact_widget_button_group_clicked_cb,
199 g_object_set_data (G_OBJECT (information->vbox_contact_widget),
200 "EmpathyContactWidget",
204 contact_widget_contact_setup (information);
205 contact_widget_groups_setup (information);
206 contact_widget_details_setup (information);
207 contact_widget_client_setup (information);
210 contact_widget_set_contact (information, contact);
212 return empathy_builder_unref_and_keep_widget (gui,
213 information->vbox_contact_widget);
217 empathy_contact_widget_get_contact (GtkWidget *widget)
219 EmpathyContactWidget *information;
221 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
223 information = g_object_get_data (G_OBJECT (widget), "EmpathyContactWidget");
227 return information->contact;
231 empathy_contact_widget_set_contact (GtkWidget *widget,
232 EmpathyContact *contact)
234 EmpathyContactWidget *information;
236 g_return_if_fail (GTK_IS_WIDGET (widget));
237 g_return_if_fail (EMPATHY_IS_CONTACT (contact));
239 information = g_object_get_data (G_OBJECT (widget), "EmpathyContactWidget");
243 contact_widget_set_contact (information, contact);
247 empathy_contact_widget_set_account_filter (
249 EmpathyAccountChooserFilterFunc filter,
252 EmpathyContactWidget *information;
253 EmpathyAccountChooser *chooser;
255 g_return_if_fail (GTK_IS_WIDGET (widget));
257 information = g_object_get_data (G_OBJECT (widget), "EmpathyContactWidget");
261 chooser = EMPATHY_ACCOUNT_CHOOSER (information->widget_account);
263 empathy_account_chooser_set_filter (chooser, filter, user_data);
267 contact_widget_destroy_cb (GtkWidget *widget,
268 EmpathyContactWidget *information)
270 contact_widget_remove_contact (information);
272 if (information->widget_id_timeout != 0)
274 g_source_remove (information->widget_id_timeout);
276 if (information->manager)
278 g_object_unref (information->manager);
281 g_slice_free (EmpathyContactWidget, information);
285 contact_widget_remove_contact (EmpathyContactWidget *information)
287 if (information->contact)
289 g_signal_handlers_disconnect_by_func (information->contact,
290 contact_widget_name_notify_cb, information);
291 g_signal_handlers_disconnect_by_func (information->contact,
292 contact_widget_presence_notify_cb, information);
293 g_signal_handlers_disconnect_by_func (information->contact,
294 contact_widget_avatar_notify_cb, information);
295 g_signal_handlers_disconnect_by_func (information->contact,
296 contact_widget_groups_notify_cb, information);
298 g_object_unref (information->contact);
299 g_object_unref (information->factory);
300 information->contact = NULL;
301 information->factory = NULL;
306 contact_widget_set_contact (EmpathyContactWidget *information,
307 EmpathyContact *contact)
309 if (contact == information->contact)
312 contact_widget_remove_contact (information);
315 TpConnection *connection;
317 connection = empathy_contact_get_connection (contact);
318 information->contact = g_object_ref (contact);
319 information->factory = empathy_tp_contact_factory_dup_singleton (connection);
322 /* Update information for widgets */
323 contact_widget_contact_update (information);
324 contact_widget_groups_update (information);
325 contact_widget_details_update (information);
326 contact_widget_client_update (information);
330 contact_widget_id_activate_timeout (EmpathyContactWidget *self)
332 contact_widget_change_contact (self);
337 contact_widget_id_changed_cb (GtkEntry *entry,
338 EmpathyContactWidget *self)
340 if (self->widget_id_timeout != 0)
342 g_source_remove (self->widget_id_timeout);
345 self->widget_id_timeout =
346 g_timeout_add_seconds (ID_CHANGED_TIMEOUT,
347 (GSourceFunc) contact_widget_id_activate_timeout, self);
351 save_avatar_menu_activate_cb (GtkWidget *widget,
352 EmpathyContactWidget *information)
355 EmpathyAvatar *avatar;
356 gchar *ext = NULL, *filename;
358 dialog = gtk_file_chooser_dialog_new (_("Save Avatar"),
360 GTK_FILE_CHOOSER_ACTION_SAVE,
361 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
362 GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT,
365 gtk_file_chooser_set_do_overwrite_confirmation (GTK_FILE_CHOOSER (dialog),
368 /* look for the avatar extension */
369 avatar = empathy_contact_get_avatar (information->contact);
370 if (avatar->format != NULL)
374 splitted = g_strsplit (avatar->format, "/", 2);
375 if (splitted[0] != NULL && splitted[1] != NULL)
376 ext = g_strdup (splitted[1]);
378 g_strfreev (splitted);
382 /* Avatar was loaded from the cache so was converted to PNG */
383 ext = g_strdup ("png");
390 id = tp_escape_as_identifier (empathy_contact_get_id (
391 information->contact));
393 filename = g_strdup_printf ("%s.%s", id, ext);
394 gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (dialog), filename);
401 if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT)
403 GError *error = NULL;
405 filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
407 if (!empathy_avatar_save_to_file (avatar, filename, &error))
412 dialog = gtk_message_dialog_new (NULL, 0,
413 GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE,
414 _("Unable to save avatar"));
416 gtk_message_dialog_format_secondary_text (
417 GTK_MESSAGE_DIALOG (dialog), "%s", error->message);
419 g_signal_connect (dialog, "response",
420 G_CALLBACK (gtk_widget_destroy), NULL);
422 gtk_window_present (GTK_WINDOW (dialog));
424 g_clear_error (&error);
430 gtk_widget_destroy (dialog);
434 popup_avatar_menu (EmpathyContactWidget *information,
436 GdkEventButton *event)
438 GtkWidget *menu, *item;
439 gint button, event_time;
441 if (information->contact == NULL ||
442 empathy_contact_get_avatar (information->contact) == NULL)
445 menu = gtk_menu_new ();
447 /* Add "Save as..." entry */
448 item = gtk_image_menu_item_new_from_stock (GTK_STOCK_SAVE_AS, NULL);
449 gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
450 gtk_widget_show (item);
452 g_signal_connect (item, "activate",
453 G_CALLBACK (save_avatar_menu_activate_cb), information);
457 button = event->button;
458 event_time = event->time;
463 event_time = gtk_get_current_event_time ();
466 gtk_menu_attach_to_widget (GTK_MENU (menu), parent, NULL);
467 gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
472 widget_avatar_popup_menu_cb (GtkWidget *widget,
473 EmpathyContactWidget *information)
475 popup_avatar_menu (information, widget, NULL);
481 widget_avatar_button_press_event_cb (GtkWidget *widget,
482 GdkEventButton *event,
483 EmpathyContactWidget *information)
485 /* Ignore double-clicks and triple-clicks */
486 if (event->button == 3 && event->type == GDK_BUTTON_PRESS)
488 popup_avatar_menu (information, widget, event);
496 update_avatar_chooser_account_cb (EmpathyAccountChooser *account_chooser,
497 EmpathyAvatarChooser *avatar_chooser)
499 TpConnection *connection;
501 connection = empathy_account_chooser_get_connection (account_chooser);
502 g_object_set (avatar_chooser, "connection", connection, NULL);
506 contact_widget_contact_setup (EmpathyContactWidget *information)
508 /* Setup account label/chooser */
509 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ACCOUNT)
511 information->widget_account = empathy_account_chooser_new ();
513 contact_widget_change_contact (information);
514 g_signal_connect_swapped (information->widget_account, "changed",
515 G_CALLBACK (contact_widget_change_contact),
520 information->widget_account = gtk_label_new (NULL);
521 if (!(information->flags & EMPATHY_CONTACT_WIDGET_FOR_TOOLTIP)) {
522 gtk_label_set_selectable (GTK_LABEL (information->widget_account), TRUE);
524 gtk_misc_set_alignment (GTK_MISC (information->widget_account), 0, 0.5);
526 gtk_table_attach_defaults (GTK_TABLE (information->table_contact),
527 information->widget_account,
529 gtk_widget_show (information->widget_account);
531 /* Set up avatar chooser/display */
532 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_AVATAR)
534 information->widget_avatar = empathy_avatar_chooser_new ();
535 g_signal_connect (information->widget_avatar, "changed",
536 G_CALLBACK (contact_widget_avatar_changed_cb),
538 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ACCOUNT)
540 g_signal_connect (information->widget_account, "changed",
541 G_CALLBACK (update_avatar_chooser_account_cb),
542 information->widget_avatar);
543 update_avatar_chooser_account_cb (
544 EMPATHY_ACCOUNT_CHOOSER (information->widget_account),
545 EMPATHY_AVATAR_CHOOSER (information->widget_avatar));
550 information->widget_avatar = empathy_avatar_image_new ();
552 g_signal_connect (information->widget_avatar, "popup-menu",
553 G_CALLBACK (widget_avatar_popup_menu_cb), information);
554 g_signal_connect (information->widget_avatar, "button-press-event",
555 G_CALLBACK (widget_avatar_button_press_event_cb), information);
558 gtk_box_pack_start (GTK_BOX (information->vbox_avatar),
559 information->widget_avatar,
562 gtk_widget_show (information->widget_avatar);
564 /* Setup id label/entry */
565 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ID)
567 information->widget_id = gtk_entry_new ();
568 g_signal_connect (information->widget_id, "focus-out-event",
569 G_CALLBACK (contact_widget_id_focus_out_cb),
571 g_signal_connect (information->widget_id, "changed",
572 G_CALLBACK (contact_widget_id_changed_cb),
577 information->widget_id = gtk_label_new (NULL);
578 if (!(information->flags & EMPATHY_CONTACT_WIDGET_FOR_TOOLTIP)) {
579 gtk_label_set_selectable (GTK_LABEL (information->widget_id), TRUE);
581 gtk_misc_set_alignment (GTK_MISC (information->widget_id), 0, 0.5);
583 gtk_table_attach_defaults (GTK_TABLE (information->table_contact),
584 information->widget_id,
586 gtk_widget_show (information->widget_id);
588 /* Setup alias label/entry */
589 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ALIAS)
591 information->widget_alias = gtk_entry_new ();
592 g_signal_connect (information->widget_alias, "focus-out-event",
593 G_CALLBACK (contact_widget_entry_alias_focus_event_cb),
595 /* Make return activate the window default (the Close button) */
596 gtk_entry_set_activates_default (GTK_ENTRY (information->widget_alias),
601 information->widget_alias = gtk_label_new (NULL);
602 if (!(information->flags & EMPATHY_CONTACT_WIDGET_FOR_TOOLTIP)) {
603 gtk_label_set_selectable (GTK_LABEL (information->widget_alias), TRUE);
605 gtk_misc_set_alignment (GTK_MISC (information->widget_alias), 0, 0.5);
607 gtk_table_attach_defaults (GTK_TABLE (information->table_contact),
608 information->widget_alias,
610 if (information->flags & EMPATHY_CONTACT_WIDGET_FOR_TOOLTIP) {
611 gtk_label_set_selectable (GTK_LABEL (information->label_status), FALSE);
613 gtk_widget_show (information->widget_alias);
617 contact_widget_contact_update (EmpathyContactWidget *information)
619 McAccount *account = NULL;
620 const gchar *id = NULL;
622 /* Connect and get info from new contact */
623 if (information->contact)
625 g_signal_connect_swapped (information->contact, "notify::name",
626 G_CALLBACK (contact_widget_name_notify_cb), information);
627 g_signal_connect_swapped (information->contact, "notify::presence",
628 G_CALLBACK (contact_widget_presence_notify_cb), information);
629 g_signal_connect_swapped (information->contact,
630 "notify::presence-message",
631 G_CALLBACK (contact_widget_presence_notify_cb), information);
632 g_signal_connect_swapped (information->contact, "notify::avatar",
633 G_CALLBACK (contact_widget_avatar_notify_cb), information);
635 account = empathy_contact_get_account (information->contact);
636 id = empathy_contact_get_id (information->contact);
639 /* Update account widget */
640 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ACCOUNT)
644 g_signal_handlers_block_by_func (information->widget_account,
645 contact_widget_change_contact,
647 empathy_account_chooser_set_account (
648 EMPATHY_ACCOUNT_CHOOSER (information->widget_account), account);
649 g_signal_handlers_unblock_by_func (information->widget_account,
650 contact_widget_change_contact, information);
659 name = mc_account_get_display_name (account);
660 gtk_label_set_label (GTK_LABEL (information->widget_account), name);
664 /* Update id widget */
665 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ID)
666 gtk_entry_set_text (GTK_ENTRY (information->widget_id), id ? id : "");
668 gtk_label_set_label (GTK_LABEL (information->widget_id), id ? id : "");
670 /* Update other widgets */
671 if (information->contact)
673 contact_widget_name_notify_cb (information);
674 contact_widget_presence_notify_cb (information);
675 contact_widget_avatar_notify_cb (information);
677 gtk_widget_show (information->label_alias);
678 gtk_widget_show (information->widget_alias);
679 gtk_widget_show (information->hbox_presence);
680 gtk_widget_show (information->widget_avatar);
684 gtk_widget_hide (information->label_alias);
685 gtk_widget_hide (information->widget_alias);
686 gtk_widget_hide (information->hbox_presence);
687 gtk_widget_hide (information->widget_avatar);
692 contact_widget_got_contact_cb (EmpathyTpContactFactory *factory,
695 GObject *weak_object)
697 EmpathyContactWidget *information = user_data;
699 contact_widget_set_contact (information, contacts->data);
703 contact_widget_get_self_handle_cb (TpConnection *connection,
704 TpHandle self_handle,
706 gpointer information,
707 GObject *weak_object)
709 EmpathyTpContactFactory *factory;
713 DEBUG ("Error: %s", error->message);
717 factory = empathy_tp_contact_factory_dup_singleton (connection);
718 empathy_tp_contact_factory_get_from_handles (factory, 1, &self_handle,
719 contact_widget_got_contact_cb, information, NULL,
721 g_object_unref (factory);
725 contact_widget_change_contact (EmpathyContactWidget *information)
727 TpConnection *connection;
729 connection = empathy_account_chooser_get_connection (
730 EMPATHY_ACCOUNT_CHOOSER (information->widget_account));
734 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ID)
738 id = gtk_entry_get_text (GTK_ENTRY (information->widget_id));
739 if (!EMP_STR_EMPTY (id))
741 EmpathyTpContactFactory *factory;
743 factory = empathy_tp_contact_factory_dup_singleton (connection);
744 empathy_tp_contact_factory_get_from_ids (factory, 1, &id,
745 contact_widget_got_contact_cb, information, NULL,
746 G_OBJECT (information->vbox_contact_widget));
747 g_object_unref (factory);
752 /* FIXME: TpConnection should have a SelfHandle property */
753 tp_cli_connection_call_get_self_handle (connection, -1,
754 contact_widget_get_self_handle_cb, information, NULL,
755 G_OBJECT (information->vbox_contact_widget));
760 contact_widget_avatar_changed_cb (EmpathyAvatarChooser *chooser,
761 EmpathyContactWidget *information)
765 const gchar *mime_type;
767 empathy_avatar_chooser_get_image_data (
768 EMPATHY_AVATAR_CHOOSER (information->widget_avatar),
769 &data, &size, &mime_type);
770 empathy_tp_contact_factory_set_avatar (information->factory,
771 data, size, mime_type);
775 contact_widget_id_focus_out_cb (GtkWidget *widget,
776 GdkEventFocus *event,
777 EmpathyContactWidget *information)
779 contact_widget_change_contact (information);
784 contact_widget_entry_alias_focus_event_cb (GtkEditable *editable,
785 GdkEventFocus *event,
786 EmpathyContactWidget *information)
788 if (information->contact)
792 alias = gtk_entry_get_text (GTK_ENTRY (editable));
793 empathy_tp_contact_factory_set_alias (information->factory,
794 information->contact, alias);
801 contact_widget_name_notify_cb (EmpathyContactWidget *information)
803 if (GTK_IS_ENTRY (information->widget_alias))
804 gtk_entry_set_text (GTK_ENTRY (information->widget_alias),
805 empathy_contact_get_name (information->contact));
807 gtk_label_set_label (GTK_LABEL (information->widget_alias),
808 empathy_contact_get_name (information->contact));
812 contact_widget_presence_notify_cb (EmpathyContactWidget *information)
814 gtk_label_set_text (GTK_LABEL (information->label_status),
815 empathy_contact_get_status (information->contact));
816 gtk_image_set_from_icon_name (GTK_IMAGE (information->image_state),
817 empathy_icon_name_for_contact (information->contact),
818 GTK_ICON_SIZE_BUTTON);
822 contact_widget_avatar_notify_cb (EmpathyContactWidget *information)
824 EmpathyAvatar *avatar = NULL;
826 if (information->contact)
827 avatar = empathy_contact_get_avatar (information->contact);
829 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_AVATAR)
831 g_signal_handlers_block_by_func (information->widget_avatar,
832 contact_widget_avatar_changed_cb,
834 empathy_avatar_chooser_set (
835 EMPATHY_AVATAR_CHOOSER (information->widget_avatar), avatar);
836 g_signal_handlers_unblock_by_func (information->widget_avatar,
837 contact_widget_avatar_changed_cb, information);
840 empathy_avatar_image_set (
841 EMPATHY_AVATAR_IMAGE (information->widget_avatar), avatar);
845 contact_widget_groups_setup (EmpathyContactWidget *information)
847 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_GROUPS)
849 information->manager = empathy_contact_manager_dup_singleton ();
850 contact_widget_model_setup (information);
855 contact_widget_groups_update (EmpathyContactWidget *information)
857 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_GROUPS &&
858 information->contact)
860 g_signal_connect_swapped (information->contact, "notify::groups",
861 G_CALLBACK (contact_widget_groups_notify_cb), information);
862 contact_widget_groups_populate_data (information);
864 gtk_widget_show (information->vbox_groups);
867 gtk_widget_hide (information->vbox_groups);
871 contact_widget_model_setup (EmpathyContactWidget *information)
875 GtkTreeSelection *selection;
877 view = GTK_TREE_VIEW (information->treeview_groups);
879 store = gtk_list_store_new (COL_COUNT,
880 G_TYPE_STRING, /* name */
881 G_TYPE_BOOLEAN, /* enabled */
882 G_TYPE_BOOLEAN); /* editable */
884 gtk_tree_view_set_model (view, GTK_TREE_MODEL (store));
886 selection = gtk_tree_view_get_selection (view);
887 gtk_tree_selection_set_mode (selection, GTK_SELECTION_SINGLE);
889 contact_widget_model_populate_columns (information);
891 gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (store),
892 COL_NAME, GTK_SORT_ASCENDING);
894 g_object_unref (store);
898 contact_widget_model_populate_columns (EmpathyContactWidget *information)
902 GtkTreeViewColumn *column;
903 GtkCellRenderer *renderer;
906 view = GTK_TREE_VIEW (information->treeview_groups);
907 model = gtk_tree_view_get_model (view);
909 renderer = gtk_cell_renderer_toggle_new ();
910 g_signal_connect (renderer, "toggled",
911 G_CALLBACK (contact_widget_cell_toggled), information);
913 column = gtk_tree_view_column_new_with_attributes (_("Select"), renderer,
914 "active", COL_ENABLED, NULL);
916 gtk_tree_view_column_set_sizing (column, GTK_TREE_VIEW_COLUMN_FIXED);
917 gtk_tree_view_column_set_fixed_width (column, 50);
918 gtk_tree_view_append_column (view, column);
920 renderer = gtk_cell_renderer_text_new ();
921 col_offset = gtk_tree_view_insert_column_with_attributes (view,
925 /* "editable", COL_EDITABLE, */
928 g_object_set_data (G_OBJECT (renderer),
929 "column", GINT_TO_POINTER (COL_NAME));
931 column = gtk_tree_view_get_column (view, col_offset - 1);
932 gtk_tree_view_column_set_sort_column_id (column, COL_NAME);
933 gtk_tree_view_column_set_resizable (column,FALSE);
934 gtk_tree_view_column_set_clickable (GTK_TREE_VIEW_COLUMN (column), TRUE);
938 contact_widget_groups_populate_data (EmpathyContactWidget *information)
943 GList *my_groups, *l;
946 view = GTK_TREE_VIEW (information->treeview_groups);
947 store = GTK_LIST_STORE (gtk_tree_view_get_model (view));
948 gtk_list_store_clear (store);
950 all_groups = empathy_contact_list_get_all_groups (
951 EMPATHY_CONTACT_LIST (information->manager));
952 my_groups = empathy_contact_list_get_groups (
953 EMPATHY_CONTACT_LIST (information->manager),
954 information->contact);
956 for (l = all_groups; l; l = l->next)
958 const gchar *group_str;
963 enabled = g_list_find_custom (my_groups,
964 group_str, (GCompareFunc) strcmp) != NULL;
966 gtk_list_store_append (store, &iter);
967 gtk_list_store_set (store, &iter,
970 COL_ENABLED, enabled,
974 g_list_foreach (all_groups, (GFunc) g_free, NULL);
975 g_list_foreach (my_groups, (GFunc) g_free, NULL);
976 g_list_free (all_groups);
977 g_list_free (my_groups);
981 contact_widget_groups_notify_cb (EmpathyContactWidget *information)
983 /* FIXME: not implemented */
987 contact_widget_model_find_name (EmpathyContactWidget *information,
995 if (EMP_STR_EMPTY (name))
998 data.information = information;
1002 view = GTK_TREE_VIEW (information->treeview_groups);
1003 model = gtk_tree_view_get_model (view);
1005 gtk_tree_model_foreach (model,
1006 (GtkTreeModelForeachFunc) contact_widget_model_find_name_foreach,
1009 if (data.found == TRUE)
1011 *iter = data.found_iter;
1019 contact_widget_model_find_name_foreach (GtkTreeModel *model,
1026 gtk_tree_model_get (model, iter,
1033 if (data->name && strcmp (data->name, name) == 0)
1036 data->found_iter = *iter;
1049 contact_widget_cell_toggled (GtkCellRendererToggle *cell,
1051 EmpathyContactWidget *information)
1054 GtkTreeModel *model;
1055 GtkListStore *store;
1061 view = GTK_TREE_VIEW (information->treeview_groups);
1062 model = gtk_tree_view_get_model (view);
1063 store = GTK_LIST_STORE (model);
1065 path = gtk_tree_path_new_from_string (path_string);
1067 gtk_tree_model_get_iter (model, &iter, path);
1068 gtk_tree_model_get (model, &iter,
1069 COL_ENABLED, &enabled,
1073 gtk_list_store_set (store, &iter, COL_ENABLED, !enabled, -1);
1074 gtk_tree_path_free (path);
1080 empathy_contact_list_remove_from_group (
1081 EMPATHY_CONTACT_LIST (information->manager), information->contact,
1086 empathy_contact_list_add_to_group (
1087 EMPATHY_CONTACT_LIST (information->manager), information->contact,
1095 contact_widget_entry_group_changed_cb (GtkEditable *editable,
1096 EmpathyContactWidget *information)
1101 group = gtk_entry_get_text (GTK_ENTRY (information->entry_group));
1103 if (contact_widget_model_find_name (information, group, &iter))
1104 gtk_widget_set_sensitive (GTK_WIDGET (information->button_group), FALSE);
1106 gtk_widget_set_sensitive (GTK_WIDGET (information->button_group),
1107 !EMP_STR_EMPTY (group));
1111 contact_widget_entry_group_activate_cb (GtkEntry *entry,
1112 EmpathyContactWidget *information)
1114 gtk_widget_activate (GTK_WIDGET (information->button_group));
1118 contact_widget_button_group_clicked_cb (GtkButton *button,
1119 EmpathyContactWidget *information)
1122 GtkListStore *store;
1126 view = GTK_TREE_VIEW (information->treeview_groups);
1127 store = GTK_LIST_STORE (gtk_tree_view_get_model (view));
1129 group = gtk_entry_get_text (GTK_ENTRY (information->entry_group));
1131 gtk_list_store_append (store, &iter);
1132 gtk_list_store_set (store, &iter,
1137 empathy_contact_list_add_to_group (
1138 EMPATHY_CONTACT_LIST (information->manager), information->contact,
1143 contact_widget_details_setup (EmpathyContactWidget *information)
1145 /* FIXME: Needs new telepathy spec */
1146 gtk_widget_hide (information->vbox_details);
1150 contact_widget_details_update (EmpathyContactWidget *information)
1152 /* FIXME: Needs new telepathy spec */
1156 contact_widget_client_setup (EmpathyContactWidget *information)
1158 /* FIXME: Needs new telepathy spec */
1159 gtk_widget_hide (information->vbox_client);
1163 contact_widget_client_update (EmpathyContactWidget *information)
1165 /* FIXME: Needs new telepathy spec */