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;
162 g_return_val_if_fail (contact == NULL || EMPATHY_IS_CONTACT (contact), NULL);
164 information = g_slice_new0 (EmpathyContactWidget);
165 information->flags = flags;
167 filename = empathy_file_lookup ("empathy-contact-widget.ui",
169 gui = empathy_builder_get_file (filename,
170 "vbox_contact_widget", &information->vbox_contact_widget,
171 "vbox_contact", &information->vbox_contact,
172 "hbox_presence", &information->hbox_presence,
173 "label_alias", &information->label_alias,
174 "image_state", &information->image_state,
175 "label_status", &information->label_status,
176 "table_contact", &information->table_contact,
177 "vbox_avatar", &information->vbox_avatar,
178 "vbox_groups", &information->vbox_groups,
179 "entry_group", &information->entry_group,
180 "button_group", &information->button_group,
181 "treeview_groups", &information->treeview_groups,
182 "vbox_details", &information->vbox_details,
183 "table_details", &information->table_details,
184 "hbox_details_requested", &information->hbox_details_requested,
185 "vbox_client", &information->vbox_client,
186 "table_client", &information->table_client,
187 "hbox_client_requested", &information->hbox_client_requested,
191 empathy_builder_connect (gui, information,
192 "vbox_contact_widget", "destroy", contact_widget_destroy_cb,
193 "entry_group", "changed", contact_widget_entry_group_changed_cb,
194 "entry_group", "activate", contact_widget_entry_group_activate_cb,
195 "button_group", "clicked", contact_widget_button_group_clicked_cb,
198 g_object_set_data (G_OBJECT (information->vbox_contact_widget),
199 "EmpathyContactWidget",
203 contact_widget_contact_setup (information);
204 contact_widget_groups_setup (information);
205 contact_widget_details_setup (information);
206 contact_widget_client_setup (information);
209 contact_widget_set_contact (information, contact);
211 return empathy_builder_unref_and_keep_widget (gui,
212 information->vbox_contact_widget);
216 empathy_contact_widget_get_contact (GtkWidget *widget)
218 EmpathyContactWidget *information;
220 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
222 information = g_object_get_data (G_OBJECT (widget), "EmpathyContactWidget");
226 return information->contact;
230 empathy_contact_widget_set_contact (GtkWidget *widget,
231 EmpathyContact *contact)
233 EmpathyContactWidget *information;
235 g_return_if_fail (GTK_IS_WIDGET (widget));
236 g_return_if_fail (EMPATHY_IS_CONTACT (contact));
238 information = g_object_get_data (G_OBJECT (widget), "EmpathyContactWidget");
242 contact_widget_set_contact (information, contact);
246 empathy_contact_widget_set_account_filter (
248 EmpathyAccountChooserFilterFunc filter,
251 EmpathyContactWidget *information;
252 EmpathyAccountChooser *chooser;
254 g_return_if_fail (GTK_IS_WIDGET (widget));
256 information = g_object_get_data (G_OBJECT (widget), "EmpathyContactWidget");
260 chooser = EMPATHY_ACCOUNT_CHOOSER (information->widget_account);
262 empathy_account_chooser_set_filter (chooser, filter, user_data);
266 contact_widget_destroy_cb (GtkWidget *widget,
267 EmpathyContactWidget *information)
269 contact_widget_remove_contact (information);
271 if (information->widget_id_timeout != 0)
273 g_source_remove (information->widget_id_timeout);
275 if (information->manager)
277 g_object_unref (information->manager);
280 g_slice_free (EmpathyContactWidget, information);
284 contact_widget_remove_contact (EmpathyContactWidget *information)
286 if (information->contact)
288 g_signal_handlers_disconnect_by_func (information->contact,
289 contact_widget_name_notify_cb, information);
290 g_signal_handlers_disconnect_by_func (information->contact,
291 contact_widget_presence_notify_cb, information);
292 g_signal_handlers_disconnect_by_func (information->contact,
293 contact_widget_avatar_notify_cb, information);
294 g_signal_handlers_disconnect_by_func (information->contact,
295 contact_widget_groups_notify_cb, information);
297 g_object_unref (information->contact);
298 g_object_unref (information->factory);
299 information->contact = NULL;
300 information->factory = NULL;
305 contact_widget_set_contact (EmpathyContactWidget *information,
306 EmpathyContact *contact)
308 if (contact == information->contact)
311 contact_widget_remove_contact (information);
314 TpConnection *connection;
316 connection = empathy_contact_get_connection (contact);
317 information->contact = g_object_ref (contact);
318 information->factory = empathy_tp_contact_factory_dup_singleton (connection);
321 /* Update information for widgets */
322 contact_widget_contact_update (information);
323 contact_widget_groups_update (information);
324 contact_widget_details_update (information);
325 contact_widget_client_update (information);
329 contact_widget_id_activate_timeout (EmpathyContactWidget *self)
331 contact_widget_change_contact (self);
336 contact_widget_id_changed_cb (GtkEntry *entry,
337 EmpathyContactWidget *self)
339 if (self->widget_id_timeout != 0)
341 g_source_remove (self->widget_id_timeout);
344 self->widget_id_timeout =
345 g_timeout_add_seconds (ID_CHANGED_TIMEOUT,
346 (GSourceFunc) contact_widget_id_activate_timeout, self);
350 save_avatar_menu_activate_cb (GtkWidget *widget,
351 EmpathyContactWidget *information)
354 EmpathyAvatar *avatar;
355 gchar *ext = NULL, *filename;
357 dialog = gtk_file_chooser_dialog_new (_("Save Avatar"),
359 GTK_FILE_CHOOSER_ACTION_SAVE,
360 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
361 GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT,
364 gtk_file_chooser_set_do_overwrite_confirmation (GTK_FILE_CHOOSER (dialog),
367 /* look for the avatar extension */
368 avatar = empathy_contact_get_avatar (information->contact);
369 if (avatar->format != NULL)
373 splitted = g_strsplit (avatar->format, "/", 2);
374 if (splitted[0] != NULL && splitted[1] != NULL)
375 ext = g_strdup (splitted[1]);
377 g_strfreev (splitted);
381 /* Avatar was loaded from the cache so was converted to PNG */
382 ext = g_strdup ("png");
389 id = tp_escape_as_identifier (empathy_contact_get_id (
390 information->contact));
392 filename = g_strdup_printf ("%s.%s", id, ext);
393 gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (dialog), filename);
400 if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT)
402 GError *error = NULL;
404 filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
406 if (!empathy_avatar_save_to_file (avatar, filename, &error))
411 dialog = gtk_message_dialog_new (NULL, 0,
412 GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE,
413 _("Unable to save avatar"));
415 gtk_message_dialog_format_secondary_text (
416 GTK_MESSAGE_DIALOG (dialog), "%s", error->message);
418 g_signal_connect (dialog, "response",
419 G_CALLBACK (gtk_widget_destroy), NULL);
421 gtk_window_present (GTK_WINDOW (dialog));
423 g_clear_error (&error);
429 gtk_widget_destroy (dialog);
433 popup_avatar_menu (EmpathyContactWidget *information,
435 GdkEventButton *event)
437 GtkWidget *menu, *item;
438 gint button, event_time;
440 if (information->contact == NULL ||
441 empathy_contact_get_avatar (information->contact) == NULL)
444 menu = gtk_menu_new ();
446 /* Add "Save as..." entry */
447 item = gtk_image_menu_item_new_from_stock (GTK_STOCK_SAVE_AS, NULL);
448 gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
449 gtk_widget_show (item);
451 g_signal_connect (item, "activate",
452 G_CALLBACK (save_avatar_menu_activate_cb), information);
456 button = event->button;
457 event_time = event->time;
462 event_time = gtk_get_current_event_time ();
465 gtk_menu_attach_to_widget (GTK_MENU (menu), parent, NULL);
466 gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
471 widget_avatar_popup_menu_cb (GtkWidget *widget,
472 EmpathyContactWidget *information)
474 popup_avatar_menu (information, widget, NULL);
480 widget_avatar_button_press_event_cb (GtkWidget *widget,
481 GdkEventButton *event,
482 EmpathyContactWidget *information)
484 /* Ignore double-clicks and triple-clicks */
485 if (event->button == 3 && event->type == GDK_BUTTON_PRESS)
487 popup_avatar_menu (information, widget, event);
495 update_avatar_chooser_account_cb (EmpathyAccountChooser *account_chooser,
496 EmpathyAvatarChooser *avatar_chooser)
498 TpConnection *connection;
500 connection = empathy_account_chooser_get_connection (account_chooser);
501 g_object_set (avatar_chooser, "connection", connection, NULL);
505 contact_widget_contact_setup (EmpathyContactWidget *information)
507 /* Setup account label/chooser */
508 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ACCOUNT)
510 information->widget_account = empathy_account_chooser_new ();
512 contact_widget_change_contact (information);
513 g_signal_connect_swapped (information->widget_account, "changed",
514 G_CALLBACK (contact_widget_change_contact),
519 information->widget_account = gtk_label_new (NULL);
520 if (!(information->flags & EMPATHY_CONTACT_WIDGET_FOR_TOOLTIP)) {
521 gtk_label_set_selectable (GTK_LABEL (information->widget_account), TRUE);
523 gtk_misc_set_alignment (GTK_MISC (information->widget_account), 0, 0.5);
525 gtk_table_attach_defaults (GTK_TABLE (information->table_contact),
526 information->widget_account,
528 gtk_widget_show (information->widget_account);
530 /* Set up avatar chooser/display */
531 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_AVATAR)
533 information->widget_avatar = empathy_avatar_chooser_new ();
534 g_signal_connect (information->widget_avatar, "changed",
535 G_CALLBACK (contact_widget_avatar_changed_cb),
537 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ACCOUNT)
539 g_signal_connect (information->widget_account, "changed",
540 G_CALLBACK (update_avatar_chooser_account_cb),
541 information->widget_avatar);
542 update_avatar_chooser_account_cb (
543 EMPATHY_ACCOUNT_CHOOSER (information->widget_account),
544 EMPATHY_AVATAR_CHOOSER (information->widget_avatar));
549 information->widget_avatar = empathy_avatar_image_new ();
551 g_signal_connect (information->widget_avatar, "popup-menu",
552 G_CALLBACK (widget_avatar_popup_menu_cb), information);
553 g_signal_connect (information->widget_avatar, "button-press-event",
554 G_CALLBACK (widget_avatar_button_press_event_cb), information);
557 gtk_box_pack_start (GTK_BOX (information->vbox_avatar),
558 information->widget_avatar,
561 gtk_widget_show (information->widget_avatar);
563 /* Setup id label/entry */
564 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ID)
566 information->widget_id = gtk_entry_new ();
567 g_signal_connect (information->widget_id, "focus-out-event",
568 G_CALLBACK (contact_widget_id_focus_out_cb),
570 g_signal_connect (information->widget_id, "changed",
571 G_CALLBACK (contact_widget_id_changed_cb),
576 information->widget_id = gtk_label_new (NULL);
577 if (!(information->flags & EMPATHY_CONTACT_WIDGET_FOR_TOOLTIP)) {
578 gtk_label_set_selectable (GTK_LABEL (information->widget_id), TRUE);
580 gtk_misc_set_alignment (GTK_MISC (information->widget_id), 0, 0.5);
582 gtk_table_attach_defaults (GTK_TABLE (information->table_contact),
583 information->widget_id,
585 gtk_widget_show (information->widget_id);
587 /* Setup alias label/entry */
588 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ALIAS)
590 information->widget_alias = gtk_entry_new ();
591 g_signal_connect (information->widget_alias, "focus-out-event",
592 G_CALLBACK (contact_widget_entry_alias_focus_event_cb),
594 /* Make return activate the window default (the Close button) */
595 gtk_entry_set_activates_default (GTK_ENTRY (information->widget_alias),
600 information->widget_alias = gtk_label_new (NULL);
601 if (!(information->flags & EMPATHY_CONTACT_WIDGET_FOR_TOOLTIP)) {
602 gtk_label_set_selectable (GTK_LABEL (information->widget_alias), TRUE);
604 gtk_misc_set_alignment (GTK_MISC (information->widget_alias), 0, 0.5);
606 gtk_table_attach_defaults (GTK_TABLE (information->table_contact),
607 information->widget_alias,
609 if (information->flags & EMPATHY_CONTACT_WIDGET_FOR_TOOLTIP) {
610 gtk_label_set_selectable (GTK_LABEL (information->label_status), FALSE);
612 gtk_widget_show (information->widget_alias);
616 contact_widget_contact_update (EmpathyContactWidget *information)
618 McAccount *account = NULL;
619 const gchar *id = NULL;
621 /* Connect and get info from new contact */
622 if (information->contact)
624 g_signal_connect_swapped (information->contact, "notify::name",
625 G_CALLBACK (contact_widget_name_notify_cb), information);
626 g_signal_connect_swapped (information->contact, "notify::presence",
627 G_CALLBACK (contact_widget_presence_notify_cb), information);
628 g_signal_connect_swapped (information->contact,
629 "notify::presence-message",
630 G_CALLBACK (contact_widget_presence_notify_cb), information);
631 g_signal_connect_swapped (information->contact, "notify::avatar",
632 G_CALLBACK (contact_widget_avatar_notify_cb), information);
634 account = empathy_contact_get_account (information->contact);
635 id = empathy_contact_get_id (information->contact);
638 /* Update account widget */
639 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ACCOUNT)
643 g_signal_handlers_block_by_func (information->widget_account,
644 contact_widget_change_contact,
646 empathy_account_chooser_set_account (
647 EMPATHY_ACCOUNT_CHOOSER (information->widget_account), account);
648 g_signal_handlers_unblock_by_func (information->widget_account,
649 contact_widget_change_contact, information);
658 name = mc_account_get_display_name (account);
659 gtk_label_set_label (GTK_LABEL (information->widget_account), name);
663 /* Update id widget */
664 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ID)
665 gtk_entry_set_text (GTK_ENTRY (information->widget_id), id ? id : "");
667 gtk_label_set_label (GTK_LABEL (information->widget_id), id ? id : "");
669 /* Update other widgets */
670 if (information->contact)
672 contact_widget_name_notify_cb (information);
673 contact_widget_presence_notify_cb (information);
674 contact_widget_avatar_notify_cb (information);
676 gtk_widget_show (information->label_alias);
677 gtk_widget_show (information->widget_alias);
678 gtk_widget_show (information->hbox_presence);
679 gtk_widget_show (information->widget_avatar);
683 gtk_widget_hide (information->label_alias);
684 gtk_widget_hide (information->widget_alias);
685 gtk_widget_hide (information->hbox_presence);
686 gtk_widget_hide (information->widget_avatar);
691 contact_widget_got_contact_cb (EmpathyTpContactFactory *factory,
692 EmpathyContact *contact,
695 GObject *weak_object)
697 EmpathyContactWidget *information = user_data;
701 DEBUG ("Error: %s", error->message);
705 contact_widget_set_contact (information, contact);
709 contact_widget_change_contact (EmpathyContactWidget *information)
711 EmpathyTpContactFactory *factory;
712 TpConnection *connection;
714 connection = empathy_account_chooser_get_connection (
715 EMPATHY_ACCOUNT_CHOOSER (information->widget_account));
719 factory = empathy_tp_contact_factory_dup_singleton (connection);
720 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ID)
724 id = gtk_entry_get_text (GTK_ENTRY (information->widget_id));
725 if (!EMP_STR_EMPTY (id))
727 empathy_tp_contact_factory_get_from_id (factory, id,
728 contact_widget_got_contact_cb, information, NULL,
729 G_OBJECT (information->vbox_contact_widget));
734 empathy_tp_contact_factory_get_from_handle (factory,
735 tp_connection_get_self_handle (connection),
736 contact_widget_got_contact_cb, information, NULL,
737 G_OBJECT (information->vbox_contact_widget));
740 g_object_unref (factory);
744 contact_widget_avatar_changed_cb (EmpathyAvatarChooser *chooser,
745 EmpathyContactWidget *information)
749 const gchar *mime_type;
751 empathy_avatar_chooser_get_image_data (
752 EMPATHY_AVATAR_CHOOSER (information->widget_avatar),
753 &data, &size, &mime_type);
754 empathy_tp_contact_factory_set_avatar (information->factory,
755 data, size, mime_type);
759 contact_widget_id_focus_out_cb (GtkWidget *widget,
760 GdkEventFocus *event,
761 EmpathyContactWidget *information)
763 contact_widget_change_contact (information);
768 contact_widget_entry_alias_focus_event_cb (GtkEditable *editable,
769 GdkEventFocus *event,
770 EmpathyContactWidget *information)
772 if (information->contact)
776 alias = gtk_entry_get_text (GTK_ENTRY (editable));
777 empathy_tp_contact_factory_set_alias (information->factory,
778 information->contact, alias);
785 contact_widget_name_notify_cb (EmpathyContactWidget *information)
787 if (GTK_IS_ENTRY (information->widget_alias))
788 gtk_entry_set_text (GTK_ENTRY (information->widget_alias),
789 empathy_contact_get_name (information->contact));
791 gtk_label_set_label (GTK_LABEL (information->widget_alias),
792 empathy_contact_get_name (information->contact));
796 contact_widget_presence_notify_cb (EmpathyContactWidget *information)
798 gtk_label_set_text (GTK_LABEL (information->label_status),
799 empathy_contact_get_status (information->contact));
800 gtk_image_set_from_icon_name (GTK_IMAGE (information->image_state),
801 empathy_icon_name_for_contact (information->contact),
802 GTK_ICON_SIZE_BUTTON);
806 contact_widget_avatar_notify_cb (EmpathyContactWidget *information)
808 EmpathyAvatar *avatar = NULL;
810 if (information->contact)
811 avatar = empathy_contact_get_avatar (information->contact);
813 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_AVATAR)
815 g_signal_handlers_block_by_func (information->widget_avatar,
816 contact_widget_avatar_changed_cb,
818 empathy_avatar_chooser_set (
819 EMPATHY_AVATAR_CHOOSER (information->widget_avatar), avatar);
820 g_signal_handlers_unblock_by_func (information->widget_avatar,
821 contact_widget_avatar_changed_cb, information);
824 empathy_avatar_image_set (
825 EMPATHY_AVATAR_IMAGE (information->widget_avatar), avatar);
829 contact_widget_groups_setup (EmpathyContactWidget *information)
831 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_GROUPS)
833 information->manager = empathy_contact_manager_dup_singleton ();
834 contact_widget_model_setup (information);
839 contact_widget_groups_update (EmpathyContactWidget *information)
841 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_GROUPS &&
842 information->contact)
844 g_signal_connect_swapped (information->contact, "notify::groups",
845 G_CALLBACK (contact_widget_groups_notify_cb), information);
846 contact_widget_groups_populate_data (information);
848 gtk_widget_show (information->vbox_groups);
851 gtk_widget_hide (information->vbox_groups);
855 contact_widget_model_setup (EmpathyContactWidget *information)
859 GtkTreeSelection *selection;
861 view = GTK_TREE_VIEW (information->treeview_groups);
863 store = gtk_list_store_new (COL_COUNT,
864 G_TYPE_STRING, /* name */
865 G_TYPE_BOOLEAN, /* enabled */
866 G_TYPE_BOOLEAN); /* editable */
868 gtk_tree_view_set_model (view, GTK_TREE_MODEL (store));
870 selection = gtk_tree_view_get_selection (view);
871 gtk_tree_selection_set_mode (selection, GTK_SELECTION_SINGLE);
873 contact_widget_model_populate_columns (information);
875 gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (store),
876 COL_NAME, GTK_SORT_ASCENDING);
878 g_object_unref (store);
882 contact_widget_model_populate_columns (EmpathyContactWidget *information)
886 GtkTreeViewColumn *column;
887 GtkCellRenderer *renderer;
890 view = GTK_TREE_VIEW (information->treeview_groups);
891 model = gtk_tree_view_get_model (view);
893 renderer = gtk_cell_renderer_toggle_new ();
894 g_signal_connect (renderer, "toggled",
895 G_CALLBACK (contact_widget_cell_toggled), information);
897 column = gtk_tree_view_column_new_with_attributes (_("Select"), renderer,
898 "active", COL_ENABLED, NULL);
900 gtk_tree_view_column_set_sizing (column, GTK_TREE_VIEW_COLUMN_FIXED);
901 gtk_tree_view_column_set_fixed_width (column, 50);
902 gtk_tree_view_append_column (view, column);
904 renderer = gtk_cell_renderer_text_new ();
905 col_offset = gtk_tree_view_insert_column_with_attributes (view,
909 /* "editable", COL_EDITABLE, */
912 g_object_set_data (G_OBJECT (renderer),
913 "column", GINT_TO_POINTER (COL_NAME));
915 column = gtk_tree_view_get_column (view, col_offset - 1);
916 gtk_tree_view_column_set_sort_column_id (column, COL_NAME);
917 gtk_tree_view_column_set_resizable (column,FALSE);
918 gtk_tree_view_column_set_clickable (GTK_TREE_VIEW_COLUMN (column), TRUE);
922 contact_widget_groups_populate_data (EmpathyContactWidget *information)
927 GList *my_groups, *l;
930 view = GTK_TREE_VIEW (information->treeview_groups);
931 store = GTK_LIST_STORE (gtk_tree_view_get_model (view));
932 gtk_list_store_clear (store);
934 all_groups = empathy_contact_list_get_all_groups (
935 EMPATHY_CONTACT_LIST (information->manager));
936 my_groups = empathy_contact_list_get_groups (
937 EMPATHY_CONTACT_LIST (information->manager),
938 information->contact);
940 for (l = all_groups; l; l = l->next)
942 const gchar *group_str;
947 enabled = g_list_find_custom (my_groups,
948 group_str, (GCompareFunc) strcmp) != NULL;
950 gtk_list_store_append (store, &iter);
951 gtk_list_store_set (store, &iter,
954 COL_ENABLED, enabled,
958 g_list_foreach (all_groups, (GFunc) g_free, NULL);
959 g_list_foreach (my_groups, (GFunc) g_free, NULL);
960 g_list_free (all_groups);
961 g_list_free (my_groups);
965 contact_widget_groups_notify_cb (EmpathyContactWidget *information)
967 /* FIXME: not implemented */
971 contact_widget_model_find_name (EmpathyContactWidget *information,
979 if (EMP_STR_EMPTY (name))
982 data.information = information;
986 view = GTK_TREE_VIEW (information->treeview_groups);
987 model = gtk_tree_view_get_model (view);
989 gtk_tree_model_foreach (model,
990 (GtkTreeModelForeachFunc) contact_widget_model_find_name_foreach,
993 if (data.found == TRUE)
995 *iter = data.found_iter;
1003 contact_widget_model_find_name_foreach (GtkTreeModel *model,
1010 gtk_tree_model_get (model, iter,
1017 if (data->name && strcmp (data->name, name) == 0)
1020 data->found_iter = *iter;
1033 contact_widget_cell_toggled (GtkCellRendererToggle *cell,
1035 EmpathyContactWidget *information)
1038 GtkTreeModel *model;
1039 GtkListStore *store;
1045 view = GTK_TREE_VIEW (information->treeview_groups);
1046 model = gtk_tree_view_get_model (view);
1047 store = GTK_LIST_STORE (model);
1049 path = gtk_tree_path_new_from_string (path_string);
1051 gtk_tree_model_get_iter (model, &iter, path);
1052 gtk_tree_model_get (model, &iter,
1053 COL_ENABLED, &enabled,
1057 gtk_list_store_set (store, &iter, COL_ENABLED, !enabled, -1);
1058 gtk_tree_path_free (path);
1064 empathy_contact_list_remove_from_group (
1065 EMPATHY_CONTACT_LIST (information->manager), information->contact,
1070 empathy_contact_list_add_to_group (
1071 EMPATHY_CONTACT_LIST (information->manager), information->contact,
1079 contact_widget_entry_group_changed_cb (GtkEditable *editable,
1080 EmpathyContactWidget *information)
1085 group = gtk_entry_get_text (GTK_ENTRY (information->entry_group));
1087 if (contact_widget_model_find_name (information, group, &iter))
1088 gtk_widget_set_sensitive (GTK_WIDGET (information->button_group), FALSE);
1090 gtk_widget_set_sensitive (GTK_WIDGET (information->button_group),
1091 !EMP_STR_EMPTY (group));
1095 contact_widget_entry_group_activate_cb (GtkEntry *entry,
1096 EmpathyContactWidget *information)
1098 gtk_widget_activate (GTK_WIDGET (information->button_group));
1102 contact_widget_button_group_clicked_cb (GtkButton *button,
1103 EmpathyContactWidget *information)
1106 GtkListStore *store;
1110 view = GTK_TREE_VIEW (information->treeview_groups);
1111 store = GTK_LIST_STORE (gtk_tree_view_get_model (view));
1113 group = gtk_entry_get_text (GTK_ENTRY (information->entry_group));
1115 gtk_list_store_append (store, &iter);
1116 gtk_list_store_set (store, &iter,
1121 empathy_contact_list_add_to_group (
1122 EMPATHY_CONTACT_LIST (information->manager), information->contact,
1127 contact_widget_details_setup (EmpathyContactWidget *information)
1129 /* FIXME: Needs new telepathy spec */
1130 gtk_widget_hide (information->vbox_details);
1134 contact_widget_details_update (EmpathyContactWidget *information)
1136 /* FIXME: Needs new telepathy spec */
1140 contact_widget_client_setup (EmpathyContactWidget *information)
1142 /* FIXME: Needs new telepathy spec */
1143 gtk_widget_hide (information->vbox_client);
1147 contact_widget_client_update (EmpathyContactWidget *information)
1149 /* FIXME: Needs new telepathy spec */