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 GtkCellRenderer *renderer;
57 guint widget_id_timeout;
59 GtkWidget *vbox_contact_widget;
62 GtkWidget *vbox_contact;
63 GtkWidget *widget_avatar;
64 GtkWidget *widget_account;
66 GtkWidget *widget_alias;
67 GtkWidget *label_alias;
68 GtkWidget *entry_alias;
69 GtkWidget *hbox_presence;
70 GtkWidget *image_state;
71 GtkWidget *label_status;
72 GtkWidget *table_contact;
73 GtkWidget *vbox_avatar;
76 GtkWidget *vbox_groups;
77 GtkWidget *entry_group;
78 GtkWidget *button_group;
79 GtkWidget *treeview_groups;
82 GtkWidget *vbox_details;
83 GtkWidget *table_details;
84 GtkWidget *hbox_details_requested;
87 GtkWidget *vbox_client;
88 GtkWidget *table_client;
89 GtkWidget *hbox_client_requested;
90 } EmpathyContactWidget;
94 EmpathyContactWidget *information;
97 GtkTreeIter found_iter;
100 static void contact_widget_destroy_cb (GtkWidget *widget,
101 EmpathyContactWidget *information);
102 static void contact_widget_remove_contact (EmpathyContactWidget *information);
103 static void contact_widget_set_contact (EmpathyContactWidget *information,
104 EmpathyContact *contact);
105 static void contact_widget_contact_setup (EmpathyContactWidget *information);
106 static void contact_widget_contact_update (EmpathyContactWidget *information);
107 static void contact_widget_change_contact (EmpathyContactWidget *information);
108 static void contact_widget_avatar_changed_cb (EmpathyAvatarChooser *chooser,
109 EmpathyContactWidget *information);
110 static void contact_widget_account_changed_cb (GtkComboBox *widget,
111 EmpathyContactWidget *information);
112 static gboolean contact_widget_id_focus_out_cb (GtkWidget *widget,
113 GdkEventFocus *event, EmpathyContactWidget *information);
114 static gboolean contact_widget_entry_alias_focus_event_cb (
115 GtkEditable *editable, GdkEventFocus *event,
116 EmpathyContactWidget *information);
117 static void contact_widget_name_notify_cb (EmpathyContactWidget *information);
118 static void contact_widget_presence_notify_cb (
119 EmpathyContactWidget *information);
120 static void contact_widget_avatar_notify_cb (
121 EmpathyContactWidget *information);
122 static void contact_widget_groups_setup (
123 EmpathyContactWidget *information);
124 static void contact_widget_groups_update (EmpathyContactWidget *information);
125 static void contact_widget_model_setup (EmpathyContactWidget *information);
126 static void contact_widget_model_populate_columns (
127 EmpathyContactWidget *information);
128 static void contact_widget_groups_populate_data (
129 EmpathyContactWidget *information);
130 static void contact_widget_groups_notify_cb (
131 EmpathyContactWidget *information);
132 static gboolean contact_widget_model_find_name (
133 EmpathyContactWidget *information,const gchar *name, GtkTreeIter *iter);
134 static gboolean contact_widget_model_find_name_foreach (GtkTreeModel *model,
135 GtkTreePath *path, GtkTreeIter *iter, FindName *data);
136 static void contact_widget_cell_toggled (GtkCellRendererToggle *cell,
137 gchar *path_string, EmpathyContactWidget *information);
138 static void contact_widget_entry_group_changed_cb (GtkEditable *editable,
139 EmpathyContactWidget *information);
140 static void contact_widget_entry_group_activate_cb (GtkEntry *entry,
141 EmpathyContactWidget *information);
142 static void contact_widget_button_group_clicked_cb (GtkButton *button,
143 EmpathyContactWidget *information);
144 static void contact_widget_details_setup (EmpathyContactWidget *information);
145 static void contact_widget_details_update (EmpathyContactWidget *information);
146 static void contact_widget_client_setup (EmpathyContactWidget *information);
147 static void contact_widget_client_update (EmpathyContactWidget *information);
158 empathy_contact_widget_new (EmpathyContact *contact,
159 EmpathyContactWidgetFlags flags)
161 EmpathyContactWidget *information;
165 information = g_slice_new0 (EmpathyContactWidget);
166 information->flags = flags;
167 information->factory = empathy_contact_factory_dup_singleton ();
169 filename = empathy_file_lookup ("empathy-contact-widget.ui",
171 gui = empathy_builder_get_file (filename,
172 "vbox_contact_widget", &information->vbox_contact_widget,
173 "vbox_contact", &information->vbox_contact,
174 "hbox_presence", &information->hbox_presence,
175 "label_alias", &information->label_alias,
176 "image_state", &information->image_state,
177 "label_status", &information->label_status,
178 "table_contact", &information->table_contact,
179 "vbox_avatar", &information->vbox_avatar,
180 "vbox_groups", &information->vbox_groups,
181 "entry_group", &information->entry_group,
182 "button_group", &information->button_group,
183 "treeview_groups", &information->treeview_groups,
184 "vbox_details", &information->vbox_details,
185 "table_details", &information->table_details,
186 "hbox_details_requested", &information->hbox_details_requested,
187 "vbox_client", &information->vbox_client,
188 "table_client", &information->table_client,
189 "hbox_client_requested", &information->hbox_client_requested,
193 empathy_builder_connect (gui, information,
194 "vbox_contact_widget", "destroy", contact_widget_destroy_cb,
195 "entry_group", "changed", contact_widget_entry_group_changed_cb,
196 "entry_group", "activate", contact_widget_entry_group_activate_cb,
197 "button_group", "clicked", contact_widget_button_group_clicked_cb,
200 g_object_set_data (G_OBJECT (information->vbox_contact_widget),
201 "EmpathyContactWidget",
205 contact_widget_contact_setup (information);
206 contact_widget_groups_setup (information);
207 contact_widget_details_setup (information);
208 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->factory)
278 g_object_unref (information->factory);
280 if (information->manager)
282 g_object_unref (information->manager);
285 g_slice_free (EmpathyContactWidget, information);
289 contact_widget_remove_contact (EmpathyContactWidget *information)
291 if (information->contact)
293 g_signal_handlers_disconnect_by_func (information->contact,
294 contact_widget_name_notify_cb, information);
295 g_signal_handlers_disconnect_by_func (information->contact,
296 contact_widget_presence_notify_cb, information);
297 g_signal_handlers_disconnect_by_func (information->contact,
298 contact_widget_avatar_notify_cb, information);
299 g_signal_handlers_disconnect_by_func (information->contact,
300 contact_widget_groups_notify_cb, information);
302 g_object_unref (information->contact);
303 information->contact = NULL;
308 contact_widget_set_contact (EmpathyContactWidget *information,
309 EmpathyContact *contact)
311 if (contact == information->contact)
314 contact_widget_remove_contact (information);
316 information->contact = g_object_ref (contact);
318 /* Update information for widgets */
319 contact_widget_contact_update (information);
320 contact_widget_groups_update (information);
321 contact_widget_details_update (information);
322 contact_widget_client_update (information);
326 contact_widget_id_activate_timeout (EmpathyContactWidget *self)
328 contact_widget_change_contact (self);
333 contact_widget_id_changed_cb (GtkEntry *entry,
334 EmpathyContactWidget *self)
336 if (self->widget_id_timeout != 0)
338 g_source_remove (self->widget_id_timeout);
341 self->widget_id_timeout =
342 g_timeout_add_seconds (ID_CHANGED_TIMEOUT,
343 (GSourceFunc) contact_widget_id_activate_timeout, self);
347 save_avatar_menu_activate_cb (GtkWidget *widget,
348 EmpathyContactWidget *information)
351 EmpathyAvatar *avatar;
352 gchar *ext = NULL, *filename;
354 dialog = gtk_file_chooser_dialog_new (_("Save Avatar"),
356 GTK_FILE_CHOOSER_ACTION_SAVE,
357 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
358 GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT,
361 gtk_file_chooser_set_do_overwrite_confirmation (GTK_FILE_CHOOSER (dialog),
364 /* look for the avatar extension */
365 avatar = empathy_contact_get_avatar (information->contact);
366 if (avatar->format != NULL)
370 splitted = g_strsplit (avatar->format, "/", 2);
371 if (splitted[0] != NULL && splitted[1] != NULL)
372 ext = g_strdup (splitted[1]);
374 g_strfreev (splitted);
378 /* Avatar was loaded from the cache so was converted to PNG */
379 ext = g_strdup ("png");
386 id = tp_escape_as_identifier (empathy_contact_get_id (
387 information->contact));
389 filename = g_strdup_printf ("%s.%s", id, ext);
390 gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (dialog), filename);
397 if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT)
399 GError *error = NULL;
401 filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
403 if (!empathy_avatar_save_to_file (avatar, filename, &error))
408 dialog = gtk_message_dialog_new (NULL, 0,
409 GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE,
410 _("Unable to save avatar"));
412 gtk_message_dialog_format_secondary_text (
413 GTK_MESSAGE_DIALOG (dialog), "%s", error->message);
415 g_signal_connect (dialog, "response",
416 G_CALLBACK (gtk_widget_destroy), NULL);
418 gtk_window_present (GTK_WINDOW (dialog));
420 g_clear_error (&error);
426 gtk_widget_destroy (dialog);
430 popup_avatar_menu (EmpathyContactWidget *information,
432 GdkEventButton *event)
434 GtkWidget *menu, *item;
435 gint button, event_time;
437 if (information->contact == NULL ||
438 empathy_contact_get_avatar (information->contact) == NULL)
441 menu = gtk_menu_new ();
443 /* Add "Save as..." entry */
444 item = gtk_image_menu_item_new_from_stock (GTK_STOCK_SAVE_AS, NULL);
445 gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
446 gtk_widget_show (item);
448 g_signal_connect (item, "activate",
449 G_CALLBACK (save_avatar_menu_activate_cb), information);
453 button = event->button;
454 event_time = event->time;
459 event_time = gtk_get_current_event_time ();
462 gtk_menu_attach_to_widget (GTK_MENU (menu), parent, NULL);
463 gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
468 widget_avatar_popup_menu_cb (GtkWidget *widget,
469 EmpathyContactWidget *information)
471 popup_avatar_menu (information, widget, NULL);
477 widget_avatar_button_press_event_cb (GtkWidget *widget,
478 GdkEventButton *event,
479 EmpathyContactWidget *information)
481 /* Ignore double-clicks and triple-clicks */
482 if (event->button == 3 && event->type == GDK_BUTTON_PRESS)
484 popup_avatar_menu (information, widget, event);
492 update_avatar_chooser_account_cb (EmpathyAccountChooser *account_chooser,
493 EmpathyAvatarChooser *avatar_chooser)
497 account = empathy_account_chooser_get_account (account_chooser);
498 g_object_set (avatar_chooser, "account", account, NULL);
502 contact_widget_contact_setup (EmpathyContactWidget *information)
504 /* Setup account label/chooser */
505 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ACCOUNT)
507 information->widget_account = empathy_account_chooser_new ();
509 g_signal_connect (information->widget_account, "changed",
510 G_CALLBACK (contact_widget_account_changed_cb),
515 information->widget_account = gtk_label_new (NULL);
516 if (!(information->flags & EMPATHY_CONTACT_WIDGET_FOR_TOOLTIP)) {
517 gtk_label_set_selectable (GTK_LABEL (information->widget_account), TRUE);
519 gtk_misc_set_alignment (GTK_MISC (information->widget_account), 0, 0.5);
521 gtk_table_attach_defaults (GTK_TABLE (information->table_contact),
522 information->widget_account,
524 gtk_widget_show (information->widget_account);
526 /* Set up avatar chooser/display */
527 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_AVATAR)
529 information->widget_avatar = empathy_avatar_chooser_new ();
530 g_signal_connect (information->widget_avatar, "changed",
531 G_CALLBACK (contact_widget_avatar_changed_cb),
533 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ACCOUNT)
535 g_signal_connect (information->widget_account, "changed",
536 G_CALLBACK (update_avatar_chooser_account_cb),
537 information->widget_avatar);
538 update_avatar_chooser_account_cb (
539 EMPATHY_ACCOUNT_CHOOSER (information->widget_account),
540 EMPATHY_AVATAR_CHOOSER (information->widget_avatar));
545 information->widget_avatar = empathy_avatar_image_new ();
547 g_signal_connect (information->widget_avatar, "popup-menu",
548 G_CALLBACK (widget_avatar_popup_menu_cb), information);
549 g_signal_connect (information->widget_avatar, "button-press-event",
550 G_CALLBACK (widget_avatar_button_press_event_cb), information);
553 gtk_box_pack_start (GTK_BOX (information->vbox_avatar),
554 information->widget_avatar,
557 gtk_widget_show (information->widget_avatar);
559 /* Setup id label/entry */
560 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ID)
562 information->widget_id = gtk_entry_new ();
563 g_signal_connect (information->widget_id, "focus-out-event",
564 G_CALLBACK (contact_widget_id_focus_out_cb),
566 g_signal_connect (information->widget_id, "changed",
567 G_CALLBACK (contact_widget_id_changed_cb),
572 information->widget_id = gtk_label_new (NULL);
573 if (!(information->flags & EMPATHY_CONTACT_WIDGET_FOR_TOOLTIP)) {
574 gtk_label_set_selectable (GTK_LABEL (information->widget_id), TRUE);
576 gtk_misc_set_alignment (GTK_MISC (information->widget_id), 0, 0.5);
578 gtk_table_attach_defaults (GTK_TABLE (information->table_contact),
579 information->widget_id,
581 gtk_widget_show (information->widget_id);
583 /* Setup alias label/entry */
584 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ALIAS)
586 information->widget_alias = gtk_entry_new ();
587 g_signal_connect (information->widget_alias, "focus-out-event",
588 G_CALLBACK (contact_widget_entry_alias_focus_event_cb),
590 /* Make return activate the window default (the Close button) */
591 gtk_entry_set_activates_default (GTK_ENTRY (information->widget_alias),
596 information->widget_alias = gtk_label_new (NULL);
597 if (!(information->flags & EMPATHY_CONTACT_WIDGET_FOR_TOOLTIP)) {
598 gtk_label_set_selectable (GTK_LABEL (information->widget_alias), TRUE);
600 gtk_misc_set_alignment (GTK_MISC (information->widget_alias), 0, 0.5);
602 gtk_table_attach_defaults (GTK_TABLE (information->table_contact),
603 information->widget_alias,
605 if (information->flags & EMPATHY_CONTACT_WIDGET_FOR_TOOLTIP) {
606 gtk_label_set_selectable (GTK_LABEL (information->label_status), FALSE);
608 gtk_widget_show (information->widget_alias);
612 contact_widget_contact_update (EmpathyContactWidget *information)
614 McAccount *account = NULL;
615 const gchar *id = NULL;
617 /* Connect and get info from new contact */
618 if (information->contact)
620 g_signal_connect_swapped (information->contact, "notify::name",
621 G_CALLBACK (contact_widget_name_notify_cb), information);
622 g_signal_connect_swapped (information->contact, "notify::presence",
623 G_CALLBACK (contact_widget_presence_notify_cb), information);
624 g_signal_connect_swapped (information->contact,
625 "notify::presence-message",
626 G_CALLBACK (contact_widget_presence_notify_cb), information);
627 g_signal_connect_swapped (information->contact, "notify::avatar",
628 G_CALLBACK (contact_widget_avatar_notify_cb), information);
630 account = empathy_contact_get_account (information->contact);
631 id = empathy_contact_get_id (information->contact);
634 /* Update account widget */
635 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ACCOUNT)
639 g_signal_handlers_block_by_func (information->widget_account,
640 contact_widget_account_changed_cb,
642 empathy_account_chooser_set_account (
643 EMPATHY_ACCOUNT_CHOOSER (information->widget_account), account);
644 g_signal_handlers_unblock_by_func (information->widget_account,
645 contact_widget_account_changed_cb, information);
654 name = mc_account_get_display_name (account);
655 gtk_label_set_label (GTK_LABEL (information->widget_account), name);
659 /* Update id widget */
660 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ID)
661 gtk_entry_set_text (GTK_ENTRY (information->widget_id), id ? id : "");
663 gtk_label_set_label (GTK_LABEL (information->widget_id), id ? id : "");
665 /* Update other widgets */
666 if (information->contact)
668 contact_widget_name_notify_cb (information);
669 contact_widget_presence_notify_cb (information);
670 contact_widget_avatar_notify_cb (information);
672 gtk_widget_show (information->label_alias);
673 gtk_widget_show (information->widget_alias);
674 gtk_widget_show (information->hbox_presence);
675 gtk_widget_show (information->widget_avatar);
679 gtk_widget_hide (information->label_alias);
680 gtk_widget_hide (information->widget_alias);
681 gtk_widget_hide (information->hbox_presence);
682 gtk_widget_hide (information->widget_avatar);
687 contact_widget_change_contact_cb (EmpathyContact *contact,
689 gpointer information,
690 GObject *weak_object)
693 DEBUG ("Error: %s", error->message);
695 contact_widget_set_contact (information, contact);
696 g_object_unref (contact);
700 contact_widget_change_contact (EmpathyContactWidget *information)
702 EmpathyContact *contact;
705 account = empathy_account_chooser_get_account (
706 EMPATHY_ACCOUNT_CHOOSER (information->widget_account));
710 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ID)
714 id = gtk_entry_get_text (GTK_ENTRY (information->widget_id));
715 if (EMP_STR_EMPTY (id))
718 contact = empathy_contact_factory_get_from_id (information->factory,
723 contact = empathy_contact_factory_get_user (information->factory,
729 /* Give the contact ref to the callback */
730 empathy_contact_call_when_ready (contact,
731 EMPATHY_CONTACT_READY_HANDLE |
732 EMPATHY_CONTACT_READY_ID,
733 contact_widget_change_contact_cb,
735 G_OBJECT (information->vbox_contact_widget));
740 contact_widget_avatar_changed_cb (EmpathyAvatarChooser *chooser,
741 EmpathyContactWidget *information)
743 if (information->contact && empathy_contact_is_user (information->contact))
748 const gchar *mime_type;
750 account = empathy_contact_get_account (information->contact);
751 empathy_avatar_chooser_get_image_data (
752 EMPATHY_AVATAR_CHOOSER (information->widget_avatar),
753 &data, &size, &mime_type);
754 empathy_contact_factory_set_avatar (information->factory, account,
755 data, size, mime_type);
760 contact_widget_account_changed_cb (GtkComboBox *widget,
761 EmpathyContactWidget *information)
763 contact_widget_change_contact (information);
767 contact_widget_id_focus_out_cb (GtkWidget *widget,
768 GdkEventFocus *event,
769 EmpathyContactWidget *information)
771 contact_widget_change_contact (information);
776 contact_widget_entry_alias_focus_event_cb (GtkEditable *editable,
777 GdkEventFocus *event,
778 EmpathyContactWidget *information)
780 if (information->contact)
784 alias = gtk_entry_get_text (GTK_ENTRY (editable));
785 empathy_contact_factory_set_alias (information->factory,
786 information->contact, alias);
793 contact_widget_name_notify_cb (EmpathyContactWidget *information)
795 if (GTK_IS_ENTRY (information->widget_alias))
796 gtk_entry_set_text (GTK_ENTRY (information->widget_alias),
797 empathy_contact_get_name (information->contact));
799 gtk_label_set_label (GTK_LABEL (information->widget_alias),
800 empathy_contact_get_name (information->contact));
804 contact_widget_presence_notify_cb (EmpathyContactWidget *information)
806 gtk_label_set_text (GTK_LABEL (information->label_status),
807 empathy_contact_get_status (information->contact));
808 gtk_image_set_from_icon_name (GTK_IMAGE (information->image_state),
809 empathy_icon_name_for_contact (information->contact),
810 GTK_ICON_SIZE_BUTTON);
814 contact_widget_avatar_notify_cb (EmpathyContactWidget *information)
816 EmpathyAvatar *avatar = NULL;
818 if (information->contact)
819 avatar = empathy_contact_get_avatar (information->contact);
821 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_AVATAR)
823 g_signal_handlers_block_by_func (information->widget_avatar,
824 contact_widget_avatar_changed_cb,
826 empathy_avatar_chooser_set (
827 EMPATHY_AVATAR_CHOOSER (information->widget_avatar), avatar);
828 g_signal_handlers_unblock_by_func (information->widget_avatar,
829 contact_widget_avatar_changed_cb, information);
832 empathy_avatar_image_set (
833 EMPATHY_AVATAR_IMAGE (information->widget_avatar), avatar);
837 contact_widget_groups_setup (EmpathyContactWidget *information)
839 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_GROUPS)
841 information->manager = empathy_contact_manager_dup_singleton ();
842 contact_widget_model_setup (information);
847 contact_widget_groups_update (EmpathyContactWidget *information)
849 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_GROUPS &&
850 information->contact)
852 g_signal_connect_swapped (information->contact, "notify::groups",
853 G_CALLBACK (contact_widget_groups_notify_cb), information);
854 contact_widget_groups_populate_data (information);
856 gtk_widget_show (information->vbox_groups);
859 gtk_widget_hide (information->vbox_groups);
863 contact_widget_model_setup (EmpathyContactWidget *information)
867 GtkTreeSelection *selection;
869 view = GTK_TREE_VIEW (information->treeview_groups);
871 store = gtk_list_store_new (COL_COUNT,
872 G_TYPE_STRING, /* name */
873 G_TYPE_BOOLEAN, /* enabled */
874 G_TYPE_BOOLEAN); /* editable */
876 gtk_tree_view_set_model (view, GTK_TREE_MODEL (store));
878 selection = gtk_tree_view_get_selection (view);
879 gtk_tree_selection_set_mode (selection, GTK_SELECTION_SINGLE);
881 contact_widget_model_populate_columns (information);
883 gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (store),
884 COL_NAME, GTK_SORT_ASCENDING);
886 g_object_unref (store);
890 contact_widget_model_populate_columns (EmpathyContactWidget *information)
894 GtkTreeViewColumn *column;
895 GtkCellRenderer *renderer;
898 view = GTK_TREE_VIEW (information->treeview_groups);
899 model = gtk_tree_view_get_model (view);
901 renderer = gtk_cell_renderer_toggle_new ();
902 g_signal_connect (renderer, "toggled",
903 G_CALLBACK (contact_widget_cell_toggled), information);
905 column = gtk_tree_view_column_new_with_attributes (_("Select"), renderer,
906 "active", COL_ENABLED, NULL);
908 gtk_tree_view_column_set_sizing (column, GTK_TREE_VIEW_COLUMN_FIXED);
909 gtk_tree_view_column_set_fixed_width (column, 50);
910 gtk_tree_view_append_column (view, column);
912 renderer = gtk_cell_renderer_text_new ();
913 col_offset = gtk_tree_view_insert_column_with_attributes (view,
917 /* "editable", COL_EDITABLE, */
920 g_object_set_data (G_OBJECT (renderer),
921 "column", GINT_TO_POINTER (COL_NAME));
923 column = gtk_tree_view_get_column (view, col_offset - 1);
924 gtk_tree_view_column_set_sort_column_id (column, COL_NAME);
925 gtk_tree_view_column_set_resizable (column,FALSE);
926 gtk_tree_view_column_set_clickable (GTK_TREE_VIEW_COLUMN (column), TRUE);
928 if (information->renderer)
929 g_object_unref (information->renderer);
931 information->renderer = g_object_ref (renderer);
935 contact_widget_groups_populate_data (EmpathyContactWidget *information)
940 GList *my_groups, *l;
943 view = GTK_TREE_VIEW (information->treeview_groups);
944 store = GTK_LIST_STORE (gtk_tree_view_get_model (view));
945 gtk_list_store_clear (store);
947 all_groups = empathy_contact_list_get_all_groups (
948 EMPATHY_CONTACT_LIST (information->manager));
949 my_groups = empathy_contact_list_get_groups (
950 EMPATHY_CONTACT_LIST (information->manager),
951 information->contact);
953 for (l = all_groups; l; l = l->next)
955 const gchar *group_str;
960 enabled = g_list_find_custom (my_groups,
961 group_str, (GCompareFunc) strcmp) != NULL;
963 gtk_list_store_append (store, &iter);
964 gtk_list_store_set (store, &iter,
967 COL_ENABLED, enabled,
971 g_list_foreach (all_groups, (GFunc) g_free, NULL);
972 g_list_foreach (my_groups, (GFunc) g_free, NULL);
973 g_list_free (all_groups);
974 g_list_free (my_groups);
978 contact_widget_groups_notify_cb (EmpathyContactWidget *information)
980 /* FIXME: not implemented */
984 contact_widget_model_find_name (EmpathyContactWidget *information,
992 if (EMP_STR_EMPTY (name))
995 data.information = information;
999 view = GTK_TREE_VIEW (information->treeview_groups);
1000 model = gtk_tree_view_get_model (view);
1002 gtk_tree_model_foreach (model,
1003 (GtkTreeModelForeachFunc) contact_widget_model_find_name_foreach,
1006 if (data.found == TRUE)
1008 *iter = data.found_iter;
1016 contact_widget_model_find_name_foreach (GtkTreeModel *model,
1023 gtk_tree_model_get (model, iter,
1030 if (data->name && strcmp (data->name, name) == 0)
1033 data->found_iter = *iter;
1046 contact_widget_cell_toggled (GtkCellRendererToggle *cell,
1048 EmpathyContactWidget *information)
1051 GtkTreeModel *model;
1052 GtkListStore *store;
1058 view = GTK_TREE_VIEW (information->treeview_groups);
1059 model = gtk_tree_view_get_model (view);
1060 store = GTK_LIST_STORE (model);
1062 path = gtk_tree_path_new_from_string (path_string);
1064 gtk_tree_model_get_iter (model, &iter, path);
1065 gtk_tree_model_get (model, &iter,
1066 COL_ENABLED, &enabled,
1070 gtk_list_store_set (store, &iter, COL_ENABLED, !enabled, -1);
1071 gtk_tree_path_free (path);
1077 empathy_contact_list_remove_from_group (
1078 EMPATHY_CONTACT_LIST (information->manager), information->contact,
1083 empathy_contact_list_add_to_group (
1084 EMPATHY_CONTACT_LIST (information->manager), information->contact,
1092 contact_widget_entry_group_changed_cb (GtkEditable *editable,
1093 EmpathyContactWidget *information)
1098 group = gtk_entry_get_text (GTK_ENTRY (information->entry_group));
1100 if (contact_widget_model_find_name (information, group, &iter))
1101 gtk_widget_set_sensitive (GTK_WIDGET (information->button_group), FALSE);
1103 gtk_widget_set_sensitive (GTK_WIDGET (information->button_group),
1104 !EMP_STR_EMPTY (group));
1108 contact_widget_entry_group_activate_cb (GtkEntry *entry,
1109 EmpathyContactWidget *information)
1111 gtk_widget_activate (GTK_WIDGET (information->button_group));
1115 contact_widget_button_group_clicked_cb (GtkButton *button,
1116 EmpathyContactWidget *information)
1119 GtkListStore *store;
1123 view = GTK_TREE_VIEW (information->treeview_groups);
1124 store = GTK_LIST_STORE (gtk_tree_view_get_model (view));
1126 group = gtk_entry_get_text (GTK_ENTRY (information->entry_group));
1128 gtk_list_store_append (store, &iter);
1129 gtk_list_store_set (store, &iter,
1134 empathy_contact_list_add_to_group (
1135 EMPATHY_CONTACT_LIST (information->manager), information->contact,
1140 contact_widget_details_setup (EmpathyContactWidget *information)
1142 /* FIXME: Needs new telepathy spec */
1143 gtk_widget_hide (information->vbox_details);
1147 contact_widget_details_update (EmpathyContactWidget *information)
1149 /* FIXME: Needs new telepathy spec */
1153 contact_widget_client_setup (EmpathyContactWidget *information)
1155 /* FIXME: Needs new telepathy spec */
1156 gtk_widget_hide (information->vbox_client);
1160 contact_widget_client_update (EmpathyContactWidget *information)
1162 /* FIXME: Needs new telepathy spec */