1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
3 * Copyright (C) 2007-2008 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-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 EmpathyContactFactory *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 void contact_widget_account_changed_cb (GtkComboBox *widget,
110 EmpathyContactWidget *information);
111 static gboolean contact_widget_id_focus_out_cb (GtkWidget *widget,
112 GdkEventFocus *event, EmpathyContactWidget *information);
113 static gboolean contact_widget_entry_alias_focus_event_cb (
114 GtkEditable *editable, GdkEventFocus *event,
115 EmpathyContactWidget *information);
116 static void contact_widget_name_notify_cb (EmpathyContactWidget *information);
117 static void contact_widget_presence_notify_cb (
118 EmpathyContactWidget *information);
119 static void contact_widget_avatar_notify_cb (
120 EmpathyContactWidget *information);
121 static void contact_widget_groups_setup (
122 EmpathyContactWidget *information);
123 static void contact_widget_groups_update (EmpathyContactWidget *information);
124 static void contact_widget_model_setup (EmpathyContactWidget *information);
125 static void contact_widget_model_populate_columns (
126 EmpathyContactWidget *information);
127 static void contact_widget_groups_populate_data (
128 EmpathyContactWidget *information);
129 static void contact_widget_groups_notify_cb (
130 EmpathyContactWidget *information);
131 static gboolean contact_widget_model_find_name (
132 EmpathyContactWidget *information,const gchar *name, GtkTreeIter *iter);
133 static gboolean contact_widget_model_find_name_foreach (GtkTreeModel *model,
134 GtkTreePath *path, GtkTreeIter *iter, FindName *data);
135 static void contact_widget_cell_toggled (GtkCellRendererToggle *cell,
136 gchar *path_string, EmpathyContactWidget *information);
137 static void contact_widget_entry_group_changed_cb (GtkEditable *editable,
138 EmpathyContactWidget *information);
139 static void contact_widget_entry_group_activate_cb (GtkEntry *entry,
140 EmpathyContactWidget *information);
141 static void contact_widget_button_group_clicked_cb (GtkButton *button,
142 EmpathyContactWidget *information);
143 static void contact_widget_details_setup (EmpathyContactWidget *information);
144 static void contact_widget_details_update (EmpathyContactWidget *information);
145 static void contact_widget_client_setup (EmpathyContactWidget *information);
146 static void contact_widget_client_update (EmpathyContactWidget *information);
157 empathy_contact_widget_new (EmpathyContact *contact,
158 EmpathyContactWidgetFlags flags)
160 EmpathyContactWidget *information;
164 information = g_slice_new0 (EmpathyContactWidget);
165 information->flags = flags;
166 information->factory = empathy_contact_factory_dup_singleton ();
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);
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->factory)
277 g_object_unref (information->factory);
279 if (information->manager)
281 g_object_unref (information->manager);
284 g_slice_free (EmpathyContactWidget, information);
288 contact_widget_remove_contact (EmpathyContactWidget *information)
290 if (information->contact)
292 g_signal_handlers_disconnect_by_func (information->contact,
293 contact_widget_name_notify_cb, information);
294 g_signal_handlers_disconnect_by_func (information->contact,
295 contact_widget_presence_notify_cb, information);
296 g_signal_handlers_disconnect_by_func (information->contact,
297 contact_widget_avatar_notify_cb, information);
298 g_signal_handlers_disconnect_by_func (information->contact,
299 contact_widget_groups_notify_cb, information);
301 g_object_unref (information->contact);
302 information->contact = NULL;
307 contact_widget_set_contact (EmpathyContactWidget *information,
308 EmpathyContact *contact)
310 if (contact == information->contact)
313 contact_widget_remove_contact (information);
315 information->contact = g_object_ref (contact);
317 /* Update information for widgets */
318 contact_widget_contact_update (information);
319 contact_widget_groups_update (information);
320 contact_widget_details_update (information);
321 contact_widget_client_update (information);
325 contact_widget_id_activate_timeout (EmpathyContactWidget *self)
327 contact_widget_change_contact (self);
332 contact_widget_id_changed_cb (GtkEntry *entry,
333 EmpathyContactWidget *self)
335 if (self->widget_id_timeout != 0)
337 g_source_remove (self->widget_id_timeout);
340 self->widget_id_timeout =
341 g_timeout_add_seconds (ID_CHANGED_TIMEOUT,
342 (GSourceFunc) contact_widget_id_activate_timeout, self);
346 save_avatar_menu_activate_cb (GtkWidget *widget,
347 EmpathyContactWidget *information)
350 EmpathyAvatar *avatar;
351 gchar *ext = NULL, *filename;
353 dialog = gtk_file_chooser_dialog_new (_("Save Avatar"),
355 GTK_FILE_CHOOSER_ACTION_SAVE,
356 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
357 GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT,
360 gtk_file_chooser_set_do_overwrite_confirmation (GTK_FILE_CHOOSER (dialog),
363 /* look for the avatar extension */
364 avatar = empathy_contact_get_avatar (information->contact);
365 if (avatar->format != NULL)
369 splitted = g_strsplit (avatar->format, "/", 2);
370 if (splitted[0] != NULL && splitted[1] != NULL)
371 ext = g_strdup (splitted[1]);
373 g_strfreev (splitted);
377 /* Avatar was loaded from the cache so was converted to PNG */
378 ext = g_strdup ("png");
385 id = tp_escape_as_identifier (empathy_contact_get_id (
386 information->contact));
388 filename = g_strdup_printf ("%s.%s", id, ext);
389 gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (dialog), filename);
396 if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT)
398 GError *error = NULL;
400 filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
402 if (!empathy_avatar_save_to_file (avatar, filename, &error))
407 dialog = gtk_message_dialog_new (NULL, 0,
408 GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE,
409 _("Unable to save avatar"));
411 gtk_message_dialog_format_secondary_text (
412 GTK_MESSAGE_DIALOG (dialog), "%s", error->message);
414 g_signal_connect (dialog, "response",
415 G_CALLBACK (gtk_widget_destroy), NULL);
417 gtk_window_present (GTK_WINDOW (dialog));
419 g_clear_error (&error);
425 gtk_widget_destroy (dialog);
429 popup_avatar_menu (EmpathyContactWidget *information,
431 GdkEventButton *event)
433 GtkWidget *menu, *item;
434 gint button, event_time;
436 if (information->contact == NULL ||
437 empathy_contact_get_avatar (information->contact) == NULL)
440 menu = gtk_menu_new ();
442 /* Add "Save as..." entry */
443 item = gtk_image_menu_item_new_from_stock (GTK_STOCK_SAVE_AS, NULL);
444 gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
445 gtk_widget_show (item);
447 g_signal_connect (item, "activate",
448 G_CALLBACK (save_avatar_menu_activate_cb), information);
452 button = event->button;
453 event_time = event->time;
458 event_time = gtk_get_current_event_time ();
461 gtk_menu_attach_to_widget (GTK_MENU (menu), parent, NULL);
462 gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
467 widget_avatar_popup_menu_cb (GtkWidget *widget,
468 EmpathyContactWidget *information)
470 popup_avatar_menu (information, widget, NULL);
476 widget_avatar_button_press_event_cb (GtkWidget *widget,
477 GdkEventButton *event,
478 EmpathyContactWidget *information)
480 /* Ignore double-clicks and triple-clicks */
481 if (event->button == 3 && event->type == GDK_BUTTON_PRESS)
483 popup_avatar_menu (information, widget, event);
491 update_avatar_chooser_account_cb (EmpathyAccountChooser *account_chooser,
492 EmpathyAvatarChooser *avatar_chooser)
496 account = empathy_account_chooser_get_account (account_chooser);
497 g_object_set (avatar_chooser, "account", account, NULL);
501 contact_widget_contact_setup (EmpathyContactWidget *information)
503 /* Setup account label/chooser */
504 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ACCOUNT)
506 information->widget_account = empathy_account_chooser_new ();
508 g_signal_connect (information->widget_account, "changed",
509 G_CALLBACK (contact_widget_account_changed_cb),
514 information->widget_account = gtk_label_new (NULL);
515 if (!(information->flags & EMPATHY_CONTACT_WIDGET_FOR_TOOLTIP)) {
516 gtk_label_set_selectable (GTK_LABEL (information->widget_account), TRUE);
518 gtk_misc_set_alignment (GTK_MISC (information->widget_account), 0, 0.5);
520 gtk_table_attach_defaults (GTK_TABLE (information->table_contact),
521 information->widget_account,
523 gtk_widget_show (information->widget_account);
525 /* Set up avatar chooser/display */
526 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_AVATAR)
528 information->widget_avatar = empathy_avatar_chooser_new ();
529 g_signal_connect (information->widget_avatar, "changed",
530 G_CALLBACK (contact_widget_avatar_changed_cb),
532 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ACCOUNT)
534 g_signal_connect (information->widget_account, "changed",
535 G_CALLBACK (update_avatar_chooser_account_cb),
536 information->widget_avatar);
537 update_avatar_chooser_account_cb (
538 EMPATHY_ACCOUNT_CHOOSER (information->widget_account),
539 EMPATHY_AVATAR_CHOOSER (information->widget_avatar));
544 information->widget_avatar = empathy_avatar_image_new ();
546 g_signal_connect (information->widget_avatar, "popup-menu",
547 G_CALLBACK (widget_avatar_popup_menu_cb), information);
548 g_signal_connect (information->widget_avatar, "button-press-event",
549 G_CALLBACK (widget_avatar_button_press_event_cb), information);
552 gtk_box_pack_start (GTK_BOX (information->vbox_avatar),
553 information->widget_avatar,
556 gtk_widget_show (information->widget_avatar);
558 /* Setup id label/entry */
559 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ID)
561 information->widget_id = gtk_entry_new ();
562 g_signal_connect (information->widget_id, "focus-out-event",
563 G_CALLBACK (contact_widget_id_focus_out_cb),
565 g_signal_connect (information->widget_id, "changed",
566 G_CALLBACK (contact_widget_id_changed_cb),
571 information->widget_id = gtk_label_new (NULL);
572 if (!(information->flags & EMPATHY_CONTACT_WIDGET_FOR_TOOLTIP)) {
573 gtk_label_set_selectable (GTK_LABEL (information->widget_id), TRUE);
575 gtk_misc_set_alignment (GTK_MISC (information->widget_id), 0, 0.5);
577 gtk_table_attach_defaults (GTK_TABLE (information->table_contact),
578 information->widget_id,
580 gtk_widget_show (information->widget_id);
582 /* Setup alias label/entry */
583 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ALIAS)
585 information->widget_alias = gtk_entry_new ();
586 g_signal_connect (information->widget_alias, "focus-out-event",
587 G_CALLBACK (contact_widget_entry_alias_focus_event_cb),
589 /* Make return activate the window default (the Close button) */
590 gtk_entry_set_activates_default (GTK_ENTRY (information->widget_alias),
595 information->widget_alias = gtk_label_new (NULL);
596 if (!(information->flags & EMPATHY_CONTACT_WIDGET_FOR_TOOLTIP)) {
597 gtk_label_set_selectable (GTK_LABEL (information->widget_alias), TRUE);
599 gtk_misc_set_alignment (GTK_MISC (information->widget_alias), 0, 0.5);
601 gtk_table_attach_defaults (GTK_TABLE (information->table_contact),
602 information->widget_alias,
604 if (information->flags & EMPATHY_CONTACT_WIDGET_FOR_TOOLTIP) {
605 gtk_label_set_selectable (GTK_LABEL (information->label_status), FALSE);
607 gtk_widget_show (information->widget_alias);
611 contact_widget_contact_update (EmpathyContactWidget *information)
613 McAccount *account = NULL;
614 const gchar *id = NULL;
616 /* Connect and get info from new contact */
617 if (information->contact)
619 g_signal_connect_swapped (information->contact, "notify::name",
620 G_CALLBACK (contact_widget_name_notify_cb), information);
621 g_signal_connect_swapped (information->contact, "notify::presence",
622 G_CALLBACK (contact_widget_presence_notify_cb), information);
623 g_signal_connect_swapped (information->contact,
624 "notify::presence-message",
625 G_CALLBACK (contact_widget_presence_notify_cb), information);
626 g_signal_connect_swapped (information->contact, "notify::avatar",
627 G_CALLBACK (contact_widget_avatar_notify_cb), information);
629 account = empathy_contact_get_account (information->contact);
630 id = empathy_contact_get_id (information->contact);
633 /* Update account widget */
634 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ACCOUNT)
638 g_signal_handlers_block_by_func (information->widget_account,
639 contact_widget_account_changed_cb,
641 empathy_account_chooser_set_account (
642 EMPATHY_ACCOUNT_CHOOSER (information->widget_account), account);
643 g_signal_handlers_unblock_by_func (information->widget_account,
644 contact_widget_account_changed_cb, information);
653 name = mc_account_get_display_name (account);
654 gtk_label_set_label (GTK_LABEL (information->widget_account), name);
658 /* Update id widget */
659 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ID)
660 gtk_entry_set_text (GTK_ENTRY (information->widget_id), id ? id : "");
662 gtk_label_set_label (GTK_LABEL (information->widget_id), id ? id : "");
664 /* Update other widgets */
665 if (information->contact)
667 contact_widget_name_notify_cb (information);
668 contact_widget_presence_notify_cb (information);
669 contact_widget_avatar_notify_cb (information);
671 gtk_widget_show (information->label_alias);
672 gtk_widget_show (information->widget_alias);
673 gtk_widget_show (information->hbox_presence);
674 gtk_widget_show (information->widget_avatar);
678 gtk_widget_hide (information->label_alias);
679 gtk_widget_hide (information->widget_alias);
680 gtk_widget_hide (information->hbox_presence);
681 gtk_widget_hide (information->widget_avatar);
686 contact_widget_change_contact_cb (EmpathyContact *contact,
688 gpointer information,
689 GObject *weak_object)
692 DEBUG ("Error: %s", error->message);
694 contact_widget_set_contact (information, contact);
695 g_object_unref (contact);
699 contact_widget_change_contact (EmpathyContactWidget *information)
701 EmpathyContact *contact;
704 account = empathy_account_chooser_get_account (
705 EMPATHY_ACCOUNT_CHOOSER (information->widget_account));
709 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ID)
713 id = gtk_entry_get_text (GTK_ENTRY (information->widget_id));
714 if (EMP_STR_EMPTY (id))
717 contact = empathy_contact_factory_get_from_id (information->factory,
722 contact = empathy_contact_factory_get_user (information->factory,
728 /* Give the contact ref to the callback */
729 empathy_contact_call_when_ready (contact,
730 EMPATHY_CONTACT_READY_HANDLE |
731 EMPATHY_CONTACT_READY_ID,
732 contact_widget_change_contact_cb,
734 G_OBJECT (information->vbox_contact_widget));
739 contact_widget_avatar_changed_cb (EmpathyAvatarChooser *chooser,
740 EmpathyContactWidget *information)
742 if (information->contact && empathy_contact_is_user (information->contact))
747 const gchar *mime_type;
749 account = empathy_contact_get_account (information->contact);
750 empathy_avatar_chooser_get_image_data (
751 EMPATHY_AVATAR_CHOOSER (information->widget_avatar),
752 &data, &size, &mime_type);
753 empathy_contact_factory_set_avatar (information->factory, account,
754 data, size, mime_type);
759 contact_widget_account_changed_cb (GtkComboBox *widget,
760 EmpathyContactWidget *information)
762 contact_widget_change_contact (information);
766 contact_widget_id_focus_out_cb (GtkWidget *widget,
767 GdkEventFocus *event,
768 EmpathyContactWidget *information)
770 contact_widget_change_contact (information);
775 contact_widget_entry_alias_focus_event_cb (GtkEditable *editable,
776 GdkEventFocus *event,
777 EmpathyContactWidget *information)
779 if (information->contact)
783 alias = gtk_entry_get_text (GTK_ENTRY (editable));
784 empathy_contact_factory_set_alias (information->factory,
785 information->contact, alias);
792 contact_widget_name_notify_cb (EmpathyContactWidget *information)
794 if (GTK_IS_ENTRY (information->widget_alias))
795 gtk_entry_set_text (GTK_ENTRY (information->widget_alias),
796 empathy_contact_get_name (information->contact));
798 gtk_label_set_label (GTK_LABEL (information->widget_alias),
799 empathy_contact_get_name (information->contact));
803 contact_widget_presence_notify_cb (EmpathyContactWidget *information)
805 gtk_label_set_text (GTK_LABEL (information->label_status),
806 empathy_contact_get_status (information->contact));
807 gtk_image_set_from_icon_name (GTK_IMAGE (information->image_state),
808 empathy_icon_name_for_contact (information->contact),
809 GTK_ICON_SIZE_BUTTON);
813 contact_widget_avatar_notify_cb (EmpathyContactWidget *information)
815 EmpathyAvatar *avatar = NULL;
817 if (information->contact)
818 avatar = empathy_contact_get_avatar (information->contact);
820 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_AVATAR)
822 g_signal_handlers_block_by_func (information->widget_avatar,
823 contact_widget_avatar_changed_cb,
825 empathy_avatar_chooser_set (
826 EMPATHY_AVATAR_CHOOSER (information->widget_avatar), avatar);
827 g_signal_handlers_unblock_by_func (information->widget_avatar,
828 contact_widget_avatar_changed_cb, information);
831 empathy_avatar_image_set (
832 EMPATHY_AVATAR_IMAGE (information->widget_avatar), avatar);
836 contact_widget_groups_setup (EmpathyContactWidget *information)
838 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_GROUPS)
840 information->manager = empathy_contact_manager_dup_singleton ();
841 contact_widget_model_setup (information);
846 contact_widget_groups_update (EmpathyContactWidget *information)
848 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_GROUPS &&
849 information->contact)
851 g_signal_connect_swapped (information->contact, "notify::groups",
852 G_CALLBACK (contact_widget_groups_notify_cb), information);
853 contact_widget_groups_populate_data (information);
855 gtk_widget_show (information->vbox_groups);
858 gtk_widget_hide (information->vbox_groups);
862 contact_widget_model_setup (EmpathyContactWidget *information)
866 GtkTreeSelection *selection;
868 view = GTK_TREE_VIEW (information->treeview_groups);
870 store = gtk_list_store_new (COL_COUNT,
871 G_TYPE_STRING, /* name */
872 G_TYPE_BOOLEAN, /* enabled */
873 G_TYPE_BOOLEAN); /* editable */
875 gtk_tree_view_set_model (view, GTK_TREE_MODEL (store));
877 selection = gtk_tree_view_get_selection (view);
878 gtk_tree_selection_set_mode (selection, GTK_SELECTION_SINGLE);
880 contact_widget_model_populate_columns (information);
882 gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (store),
883 COL_NAME, GTK_SORT_ASCENDING);
885 g_object_unref (store);
889 contact_widget_model_populate_columns (EmpathyContactWidget *information)
893 GtkTreeViewColumn *column;
894 GtkCellRenderer *renderer;
897 view = GTK_TREE_VIEW (information->treeview_groups);
898 model = gtk_tree_view_get_model (view);
900 renderer = gtk_cell_renderer_toggle_new ();
901 g_signal_connect (renderer, "toggled",
902 G_CALLBACK (contact_widget_cell_toggled), information);
904 column = gtk_tree_view_column_new_with_attributes (_("Select"), renderer,
905 "active", COL_ENABLED, NULL);
907 gtk_tree_view_column_set_sizing (column, GTK_TREE_VIEW_COLUMN_FIXED);
908 gtk_tree_view_column_set_fixed_width (column, 50);
909 gtk_tree_view_append_column (view, column);
911 renderer = gtk_cell_renderer_text_new ();
912 col_offset = gtk_tree_view_insert_column_with_attributes (view,
916 /* "editable", COL_EDITABLE, */
919 g_object_set_data (G_OBJECT (renderer),
920 "column", GINT_TO_POINTER (COL_NAME));
922 column = gtk_tree_view_get_column (view, col_offset - 1);
923 gtk_tree_view_column_set_sort_column_id (column, COL_NAME);
924 gtk_tree_view_column_set_resizable (column,FALSE);
925 gtk_tree_view_column_set_clickable (GTK_TREE_VIEW_COLUMN (column), TRUE);
929 contact_widget_groups_populate_data (EmpathyContactWidget *information)
934 GList *my_groups, *l;
937 view = GTK_TREE_VIEW (information->treeview_groups);
938 store = GTK_LIST_STORE (gtk_tree_view_get_model (view));
939 gtk_list_store_clear (store);
941 all_groups = empathy_contact_list_get_all_groups (
942 EMPATHY_CONTACT_LIST (information->manager));
943 my_groups = empathy_contact_list_get_groups (
944 EMPATHY_CONTACT_LIST (information->manager),
945 information->contact);
947 for (l = all_groups; l; l = l->next)
949 const gchar *group_str;
954 enabled = g_list_find_custom (my_groups,
955 group_str, (GCompareFunc) strcmp) != NULL;
957 gtk_list_store_append (store, &iter);
958 gtk_list_store_set (store, &iter,
961 COL_ENABLED, enabled,
965 g_list_foreach (all_groups, (GFunc) g_free, NULL);
966 g_list_foreach (my_groups, (GFunc) g_free, NULL);
967 g_list_free (all_groups);
968 g_list_free (my_groups);
972 contact_widget_groups_notify_cb (EmpathyContactWidget *information)
974 /* FIXME: not implemented */
978 contact_widget_model_find_name (EmpathyContactWidget *information,
986 if (EMP_STR_EMPTY (name))
989 data.information = information;
993 view = GTK_TREE_VIEW (information->treeview_groups);
994 model = gtk_tree_view_get_model (view);
996 gtk_tree_model_foreach (model,
997 (GtkTreeModelForeachFunc) contact_widget_model_find_name_foreach,
1000 if (data.found == TRUE)
1002 *iter = data.found_iter;
1010 contact_widget_model_find_name_foreach (GtkTreeModel *model,
1017 gtk_tree_model_get (model, iter,
1024 if (data->name && strcmp (data->name, name) == 0)
1027 data->found_iter = *iter;
1040 contact_widget_cell_toggled (GtkCellRendererToggle *cell,
1042 EmpathyContactWidget *information)
1045 GtkTreeModel *model;
1046 GtkListStore *store;
1052 view = GTK_TREE_VIEW (information->treeview_groups);
1053 model = gtk_tree_view_get_model (view);
1054 store = GTK_LIST_STORE (model);
1056 path = gtk_tree_path_new_from_string (path_string);
1058 gtk_tree_model_get_iter (model, &iter, path);
1059 gtk_tree_model_get (model, &iter,
1060 COL_ENABLED, &enabled,
1064 gtk_list_store_set (store, &iter, COL_ENABLED, !enabled, -1);
1065 gtk_tree_path_free (path);
1071 empathy_contact_list_remove_from_group (
1072 EMPATHY_CONTACT_LIST (information->manager), information->contact,
1077 empathy_contact_list_add_to_group (
1078 EMPATHY_CONTACT_LIST (information->manager), information->contact,
1086 contact_widget_entry_group_changed_cb (GtkEditable *editable,
1087 EmpathyContactWidget *information)
1092 group = gtk_entry_get_text (GTK_ENTRY (information->entry_group));
1094 if (contact_widget_model_find_name (information, group, &iter))
1095 gtk_widget_set_sensitive (GTK_WIDGET (information->button_group), FALSE);
1097 gtk_widget_set_sensitive (GTK_WIDGET (information->button_group),
1098 !EMP_STR_EMPTY (group));
1102 contact_widget_entry_group_activate_cb (GtkEntry *entry,
1103 EmpathyContactWidget *information)
1105 gtk_widget_activate (GTK_WIDGET (information->button_group));
1109 contact_widget_button_group_clicked_cb (GtkButton *button,
1110 EmpathyContactWidget *information)
1113 GtkListStore *store;
1117 view = GTK_TREE_VIEW (information->treeview_groups);
1118 store = GTK_LIST_STORE (gtk_tree_view_get_model (view));
1120 group = gtk_entry_get_text (GTK_ENTRY (information->entry_group));
1122 gtk_list_store_append (store, &iter);
1123 gtk_list_store_set (store, &iter,
1128 empathy_contact_list_add_to_group (
1129 EMPATHY_CONTACT_LIST (information->manager), information->contact,
1134 contact_widget_details_setup (EmpathyContactWidget *information)
1136 /* FIXME: Needs new telepathy spec */
1137 gtk_widget_hide (information->vbox_details);
1141 contact_widget_details_update (EmpathyContactWidget *information)
1143 /* FIXME: Needs new telepathy spec */
1147 contact_widget_client_setup (EmpathyContactWidget *information)
1149 /* FIXME: Needs new telepathy spec */
1150 gtk_widget_hide (information->vbox_client);
1154 contact_widget_client_update (EmpathyContactWidget *information)
1156 /* FIXME: Needs new telepathy spec */