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 <glade/glade.h>
29 #include <glib/gi18n.h>
31 #include <libmissioncontrol/mc-account.h>
32 #include <telepathy-glib/util.h>
34 #include <libempathy/empathy-contact-factory.h>
35 #include <libempathy/empathy-contact-manager.h>
36 #include <libempathy/empathy-contact-list.h>
37 #include <libempathy/empathy-utils.h>
39 #include "empathy-contact-widget.h"
40 #include "empathy-account-chooser.h"
41 #include "empathy-avatar-chooser.h"
42 #include "empathy-avatar-image.h"
43 #include "empathy-ui-utils.h"
45 /* Delay before updating the widget when the id entry changed (seconds) */
46 #define ID_CHANGED_TIMEOUT 1
49 EmpathyContactFactory *factory;
50 EmpathyContactManager *manager;
51 EmpathyContact *contact;
52 EmpathyContactWidgetFlags flags;
53 GtkCellRenderer *renderer;
54 guint widget_id_timeout;
56 GtkWidget *vbox_contact_widget;
59 GtkWidget *vbox_contact;
60 GtkWidget *widget_avatar;
61 GtkWidget *widget_account;
63 GtkWidget *widget_alias;
64 GtkWidget *label_alias;
65 GtkWidget *entry_alias;
66 GtkWidget *hbox_presence;
67 GtkWidget *image_state;
68 GtkWidget *label_status;
69 GtkWidget *table_contact;
70 GtkWidget *vbox_avatar;
73 GtkWidget *vbox_groups;
74 GtkWidget *entry_group;
75 GtkWidget *button_group;
76 GtkWidget *treeview_groups;
79 GtkWidget *vbox_details;
80 GtkWidget *table_details;
81 GtkWidget *hbox_details_requested;
84 GtkWidget *vbox_client;
85 GtkWidget *table_client;
86 GtkWidget *hbow_client_requested;
87 } EmpathyContactWidget;
90 EmpathyContactWidget *information;
93 GtkTreeIter found_iter;
96 static void contact_widget_destroy_cb (GtkWidget *widget,
97 EmpathyContactWidget *information);
98 static void contact_widget_remove_contact (EmpathyContactWidget *information);
99 static void contact_widget_set_contact (EmpathyContactWidget *information,
100 EmpathyContact *contact);
101 static void contact_widget_contact_setup (EmpathyContactWidget *information);
102 static void contact_widget_contact_update (EmpathyContactWidget *information);
103 static void contact_widget_change_contact (EmpathyContactWidget *information);
104 static void contact_widget_avatar_changed_cb (EmpathyAvatarChooser *chooser,
105 EmpathyContactWidget *information);
106 static void contact_widget_account_changed_cb (GtkComboBox *widget,
107 EmpathyContactWidget *information);
108 static gboolean contact_widget_id_focus_out_cb (GtkWidget *widget,
109 GdkEventFocus *event,
110 EmpathyContactWidget *information);
111 static gboolean contact_widget_entry_alias_focus_event_cb (GtkEditable *editable,
112 GdkEventFocus *event,
113 EmpathyContactWidget *information);
114 static void contact_widget_name_notify_cb (EmpathyContactWidget *information);
115 static void contact_widget_presence_notify_cb (EmpathyContactWidget *information);
116 static void contact_widget_avatar_notify_cb (EmpathyContactWidget *information);
117 static void contact_widget_groups_setup (EmpathyContactWidget *information);
118 static void contact_widget_groups_update (EmpathyContactWidget *information);
119 static void contact_widget_model_setup (EmpathyContactWidget *information);
120 static void contact_widget_model_populate_columns (EmpathyContactWidget *information);
121 static void contact_widget_groups_populate_data (EmpathyContactWidget *information);
122 static void contact_widget_groups_notify_cb (EmpathyContactWidget *information);
123 static gboolean contact_widget_model_find_name (EmpathyContactWidget *information,
126 static gboolean contact_widget_model_find_name_foreach (GtkTreeModel *model,
130 static void contact_widget_cell_toggled (GtkCellRendererToggle *cell,
132 EmpathyContactWidget *information);
133 static void contact_widget_entry_group_changed_cb (GtkEditable *editable,
134 EmpathyContactWidget *information);
135 static void contact_widget_entry_group_activate_cb (GtkEntry *entry,
136 EmpathyContactWidget *information);
137 static void contact_widget_button_group_clicked_cb (GtkButton *button,
138 EmpathyContactWidget *information);
139 static void contact_widget_details_setup (EmpathyContactWidget *information);
140 static void contact_widget_details_update (EmpathyContactWidget *information);
141 static void contact_widget_client_setup (EmpathyContactWidget *information);
142 static void contact_widget_client_update (EmpathyContactWidget *information);
152 empathy_contact_widget_new (EmpathyContact *contact,
153 EmpathyContactWidgetFlags flags)
155 EmpathyContactWidget *information;
159 information = g_slice_new0 (EmpathyContactWidget);
160 information->flags = flags;
161 information->factory = empathy_contact_factory_new ();
163 filename = empathy_file_lookup ("empathy-contact-widget.glade",
165 glade = empathy_glade_get_file (filename,
166 "vbox_contact_widget",
168 "vbox_contact_widget", &information->vbox_contact_widget,
169 "vbox_contact", &information->vbox_contact,
170 "hbox_presence", &information->hbox_presence,
171 "label_alias", &information->label_alias,
172 "image_state", &information->image_state,
173 "label_status", &information->label_status,
174 "table_contact", &information->table_contact,
175 "vbox_avatar", &information->vbox_avatar,
176 "vbox_groups", &information->vbox_groups,
177 "entry_group", &information->entry_group,
178 "button_group", &information->button_group,
179 "treeview_groups", &information->treeview_groups,
180 "vbox_details", &information->vbox_details,
181 "table_details", &information->table_details,
182 "hbox_details_requested", &information->hbox_details_requested,
183 "vbox_client", &information->vbox_client,
184 "table_client", &information->table_client,
185 "hbox_client_requested", &information->hbow_client_requested,
189 empathy_glade_connect (glade,
191 "vbox_contact_widget", "destroy", contact_widget_destroy_cb,
192 "entry_group", "changed", contact_widget_entry_group_changed_cb,
193 "entry_group", "activate", contact_widget_entry_group_activate_cb,
194 "button_group", "clicked", contact_widget_button_group_clicked_cb,
197 g_object_unref (glade);
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 gtk_widget_show (information->vbox_contact_widget);
213 return 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");
228 return information->contact;
232 empathy_contact_widget_set_contact (GtkWidget *widget,
233 EmpathyContact *contact)
235 EmpathyContactWidget *information;
237 g_return_if_fail (GTK_IS_WIDGET (widget));
238 g_return_if_fail (EMPATHY_IS_CONTACT (contact));
240 information = g_object_get_data (G_OBJECT (widget), "EmpathyContactWidget");
245 contact_widget_set_contact (information, contact);
249 empathy_contact_widget_set_account_filter (GtkWidget *widget,
250 EmpathyAccountChooserFilterFunc filter,
253 EmpathyContactWidget *information;
254 EmpathyAccountChooser *chooser;
256 g_return_if_fail (GTK_IS_WIDGET (widget));
258 information = g_object_get_data (G_OBJECT (widget), "EmpathyContactWidget");
263 chooser = EMPATHY_ACCOUNT_CHOOSER (information->widget_account);
265 empathy_account_chooser_set_filter (chooser, filter, user_data);
270 contact_widget_destroy_cb (GtkWidget *widget,
271 EmpathyContactWidget *information)
273 contact_widget_remove_contact (information);
275 if (information->widget_id_timeout != 0) {
276 g_source_remove (information->widget_id_timeout);
278 if (information->factory) {
279 g_object_unref (information->factory);
281 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) {
292 g_signal_handlers_disconnect_by_func (information->contact,
293 contact_widget_name_notify_cb,
295 g_signal_handlers_disconnect_by_func (information->contact,
296 contact_widget_presence_notify_cb,
298 g_signal_handlers_disconnect_by_func (information->contact,
299 contact_widget_avatar_notify_cb,
301 g_signal_handlers_disconnect_by_func (information->contact,
302 contact_widget_groups_notify_cb,
305 g_object_unref (information->contact);
306 information->contact = NULL;
311 contact_widget_set_contact (EmpathyContactWidget *information,
312 EmpathyContact *contact)
314 if (contact == information->contact) {
318 contact_widget_remove_contact (information);
320 information->contact = g_object_ref (contact);
323 /* Update information for widgets */
324 contact_widget_contact_update (information);
325 contact_widget_groups_update (information);
326 contact_widget_details_update (information);
327 contact_widget_client_update (information);
331 contact_widget_id_activate_timeout (EmpathyContactWidget *self)
333 contact_widget_change_contact (self);
338 contact_widget_id_changed_cb (GtkEntry *entry,
339 EmpathyContactWidget *self)
341 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,
352 save_avatar_menu_activate_cb (GtkWidget *widget,
353 EmpathyContactWidget *information)
356 EmpathyAvatar *avatar;
357 gchar *ext = NULL, *filename;
359 dialog = gtk_file_chooser_dialog_new (_("Save Avatar"),
361 GTK_FILE_CHOOSER_ACTION_SAVE,
362 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
363 GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT,
366 gtk_file_chooser_set_do_overwrite_confirmation (GTK_FILE_CHOOSER (dialog),
369 /* look for the avatar extension */
370 avatar = empathy_contact_get_avatar (information->contact);
371 if (avatar->format != NULL)
375 splitted = g_strsplit (avatar->format, "/", 2);
376 if (splitted[0] != NULL && splitted[1] != NULL)
378 ext = g_strdup (splitted[1]);
381 g_strfreev (splitted);
385 /* Avatar was loaded from the cache so was converted to PNG */
386 ext = g_strdup ("png");
393 id = tp_escape_as_identifier (empathy_contact_get_id (
394 information->contact));
396 filename = g_strdup_printf ("%s.%s", id, ext);
397 gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (dialog), filename);
404 if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT)
406 GError *error = NULL;
408 filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
410 if (!empathy_avatar_save_to_file (avatar, filename, &error))
415 dialog = gtk_message_dialog_new (NULL, 0,
416 GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE,
417 _("Unable to save avatar"));
419 gtk_message_dialog_format_secondary_text (
420 GTK_MESSAGE_DIALOG (dialog), "%s", error->message);
422 g_signal_connect (dialog, "response",
423 G_CALLBACK (gtk_widget_destroy), NULL);
425 gtk_window_present (GTK_WINDOW (dialog));
427 g_clear_error (&error);
433 gtk_widget_destroy (dialog);
437 popup_avatar_menu (EmpathyContactWidget *information,
439 GdkEventButton *event)
441 GtkWidget *menu, *item, *image;
442 gint button, event_time;
444 menu = gtk_menu_new ();
446 /* Add "Save as..." entry */
447 item = gtk_image_menu_item_new_with_mnemonic (_("_Save As..."));
448 image = gtk_image_new_from_icon_name (GTK_STOCK_SAVE, GTK_ICON_SIZE_MENU);
449 gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image);
450 gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
451 gtk_widget_show (item);
453 g_signal_connect (item, "activate",
454 G_CALLBACK (save_avatar_menu_activate_cb), information);
458 button = event->button;
459 event_time = event->time;
464 event_time = gtk_get_current_event_time ();
467 gtk_menu_attach_to_widget (GTK_MENU (menu), parent, NULL);
468 gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
473 widget_avatar_popup_menu_cb (GtkWidget *widget,
474 EmpathyContactWidget *information)
476 popup_avatar_menu (information, widget, NULL);
482 widget_avatar_button_press_event_cb (GtkWidget *widget,
483 GdkEventButton *event,
484 EmpathyContactWidget *information)
486 /* Ignore double-clicks and triple-clicks */
487 if (event->button == 3 && event->type == GDK_BUTTON_PRESS)
489 popup_avatar_menu (information, widget, event);
497 contact_widget_contact_setup (EmpathyContactWidget *information)
499 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_AVATAR) {
500 information->widget_avatar = empathy_avatar_chooser_new ();
501 g_signal_connect (information->widget_avatar, "changed",
502 G_CALLBACK (contact_widget_avatar_changed_cb),
505 information->widget_avatar = empathy_avatar_image_new ();
507 g_signal_connect (information->widget_avatar, "popup-menu",
508 G_CALLBACK (widget_avatar_popup_menu_cb), information);
509 g_signal_connect (information->widget_avatar, "button-press-event",
510 G_CALLBACK (widget_avatar_button_press_event_cb), information);
513 gtk_box_pack_start (GTK_BOX (information->vbox_avatar),
514 information->widget_avatar,
517 gtk_widget_show (information->widget_avatar);
519 /* Setup account label/chooser */
520 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ACCOUNT) {
521 information->widget_account = empathy_account_chooser_new ();
523 g_signal_connect (information->widget_account, "changed",
524 G_CALLBACK (contact_widget_account_changed_cb),
527 information->widget_account = gtk_label_new (NULL);
528 gtk_label_set_selectable (GTK_LABEL (information->widget_account), TRUE);
529 gtk_misc_set_alignment (GTK_MISC (information->widget_account), 0, 0.5);
531 gtk_table_attach_defaults (GTK_TABLE (information->table_contact),
532 information->widget_account,
534 gtk_widget_show (information->widget_account);
536 /* Setup id label/entry */
537 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ID) {
538 information->widget_id = gtk_entry_new ();
539 g_signal_connect (information->widget_id, "focus-out-event",
540 G_CALLBACK (contact_widget_id_focus_out_cb),
542 g_signal_connect (information->widget_id, "changed",
543 G_CALLBACK (contact_widget_id_changed_cb),
546 information->widget_id = gtk_label_new (NULL);
547 gtk_label_set_selectable (GTK_LABEL (information->widget_id), TRUE);
548 gtk_misc_set_alignment (GTK_MISC (information->widget_id), 0, 0.5);
550 gtk_table_attach_defaults (GTK_TABLE (information->table_contact),
551 information->widget_id,
553 gtk_widget_show (information->widget_id);
555 /* Setup alias label/entry */
556 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ALIAS) {
557 information->widget_alias = gtk_entry_new ();
558 g_signal_connect (information->widget_alias, "focus-out-event",
559 G_CALLBACK (contact_widget_entry_alias_focus_event_cb),
561 /* Make return activate the window default (the Close button) */
562 gtk_entry_set_activates_default (GTK_ENTRY (information->widget_alias), TRUE);
564 information->widget_alias = gtk_label_new (NULL);
565 gtk_label_set_selectable (GTK_LABEL (information->widget_alias), TRUE);
566 gtk_misc_set_alignment (GTK_MISC (information->widget_alias), 0, 0.5);
568 gtk_table_attach_defaults (GTK_TABLE (information->table_contact),
569 information->widget_alias,
571 gtk_widget_show (information->widget_alias);
575 contact_widget_contact_update (EmpathyContactWidget *information)
577 McAccount *account = NULL;
578 const gchar *id = NULL;
580 /* Connect and get info from new contact */
581 if (information->contact) {
582 g_signal_connect_swapped (information->contact, "notify::name",
583 G_CALLBACK (contact_widget_name_notify_cb),
585 g_signal_connect_swapped (information->contact, "notify::presence",
586 G_CALLBACK (contact_widget_presence_notify_cb),
588 g_signal_connect_swapped (information->contact, "notify::presence-message",
589 G_CALLBACK (contact_widget_presence_notify_cb),
591 g_signal_connect_swapped (information->contact, "notify::avatar",
592 G_CALLBACK (contact_widget_avatar_notify_cb),
595 account = empathy_contact_get_account (information->contact);
596 id = empathy_contact_get_id (information->contact);
599 /* Update account widget */
600 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ACCOUNT) {
602 g_signal_handlers_block_by_func (information->widget_account,
603 contact_widget_account_changed_cb,
605 empathy_account_chooser_set_account (EMPATHY_ACCOUNT_CHOOSER (information->widget_account),
607 g_signal_handlers_unblock_by_func (information->widget_account,
608 contact_widget_account_changed_cb,
615 name = mc_account_get_display_name (account);
616 gtk_label_set_label (GTK_LABEL (information->widget_account), name);
620 /* Update id widget */
621 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ID) {
622 gtk_entry_set_text (GTK_ENTRY (information->widget_id), id ? id : "");
624 gtk_label_set_label (GTK_LABEL (information->widget_id), id ? id : "");
626 /* Update other widgets */
627 if (information->contact) {
628 contact_widget_name_notify_cb (information);
629 contact_widget_presence_notify_cb (information);
630 contact_widget_avatar_notify_cb (information);
632 gtk_widget_show (information->label_alias);
633 gtk_widget_show (information->widget_alias);
634 gtk_widget_show (information->hbox_presence);
635 gtk_widget_show (information->widget_avatar);
637 gtk_widget_hide (information->label_alias);
638 gtk_widget_hide (information->widget_alias);
639 gtk_widget_hide (information->hbox_presence);
640 gtk_widget_hide (information->widget_avatar);
645 contact_widget_change_contact (EmpathyContactWidget *information)
647 EmpathyContact *contact;
650 account = empathy_account_chooser_get_account (EMPATHY_ACCOUNT_CHOOSER (information->widget_account));
655 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ID) {
658 id = gtk_entry_get_text (GTK_ENTRY (information->widget_id));
659 if (G_STR_EMPTY (id)) {
663 contact = empathy_contact_factory_get_from_id (information->factory,
666 contact = empathy_contact_factory_get_user (information->factory,
671 empathy_contact_run_until_ready (contact,
672 EMPATHY_CONTACT_READY_HANDLE |
673 EMPATHY_CONTACT_READY_ID,
675 contact_widget_set_contact (information, contact);
676 g_object_unref (contact);
681 contact_widget_avatar_changed_cb (EmpathyAvatarChooser *chooser,
682 EmpathyContactWidget *information)
684 if (information->contact &&
685 empathy_contact_is_user (information->contact)) {
689 const gchar *mime_type;
691 account = empathy_contact_get_account (information->contact);
692 empathy_avatar_chooser_get_image_data (EMPATHY_AVATAR_CHOOSER (information->widget_avatar),
693 &data, &size, &mime_type);
694 empathy_contact_factory_set_avatar (information->factory,
696 data, size, mime_type);
701 contact_widget_account_changed_cb (GtkComboBox *widget,
702 EmpathyContactWidget *information)
704 contact_widget_change_contact (information);
708 contact_widget_id_focus_out_cb (GtkWidget *widget,
709 GdkEventFocus *event,
710 EmpathyContactWidget *information)
712 contact_widget_change_contact (information);
717 contact_widget_entry_alias_focus_event_cb (GtkEditable *editable,
718 GdkEventFocus *event,
719 EmpathyContactWidget *information)
721 if (information->contact) {
724 alias = gtk_entry_get_text (GTK_ENTRY (editable));
725 empathy_contact_factory_set_alias (information->factory,
726 information->contact,
734 contact_widget_name_notify_cb (EmpathyContactWidget *information)
736 if (GTK_IS_ENTRY (information->widget_alias)) {
737 gtk_entry_set_text (GTK_ENTRY (information->widget_alias),
738 empathy_contact_get_name (information->contact));
740 gtk_label_set_label (GTK_LABEL (information->widget_alias),
741 empathy_contact_get_name (information->contact));
746 contact_widget_presence_notify_cb (EmpathyContactWidget *information)
748 gtk_label_set_text (GTK_LABEL (information->label_status),
749 empathy_contact_get_status (information->contact));
750 gtk_image_set_from_icon_name (GTK_IMAGE (information->image_state),
751 empathy_icon_name_for_contact (information->contact),
752 GTK_ICON_SIZE_BUTTON);
757 contact_widget_avatar_notify_cb (EmpathyContactWidget *information)
759 EmpathyAvatar *avatar = NULL;
761 if (information->contact) {
762 avatar = empathy_contact_get_avatar (information->contact);
764 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_AVATAR) {
765 g_signal_handlers_block_by_func (information->widget_avatar,
766 contact_widget_avatar_changed_cb,
768 empathy_avatar_chooser_set (EMPATHY_AVATAR_CHOOSER (information->widget_avatar),
770 g_signal_handlers_unblock_by_func (information->widget_avatar,
771 contact_widget_avatar_changed_cb,
774 empathy_avatar_image_set (EMPATHY_AVATAR_IMAGE (information->widget_avatar),
780 contact_widget_groups_setup (EmpathyContactWidget *information)
782 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_GROUPS) {
783 information->manager = empathy_contact_manager_new ();
784 contact_widget_model_setup (information);
789 contact_widget_groups_update (EmpathyContactWidget *information)
791 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_GROUPS &&
792 information->contact) {
793 g_signal_connect_swapped (information->contact, "notify::groups",
794 G_CALLBACK (contact_widget_groups_notify_cb),
796 contact_widget_groups_populate_data (information);
798 gtk_widget_show (information->vbox_groups);
800 gtk_widget_hide (information->vbox_groups);
805 contact_widget_model_setup (EmpathyContactWidget *information)
809 GtkTreeSelection *selection;
811 view = GTK_TREE_VIEW (information->treeview_groups);
813 store = gtk_list_store_new (COL_COUNT,
814 G_TYPE_STRING, /* name */
815 G_TYPE_BOOLEAN, /* enabled */
816 G_TYPE_BOOLEAN); /* editable */
818 gtk_tree_view_set_model (view, GTK_TREE_MODEL (store));
820 selection = gtk_tree_view_get_selection (view);
821 gtk_tree_selection_set_mode (selection, GTK_SELECTION_SINGLE);
823 contact_widget_model_populate_columns (information);
825 gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (store),
826 COL_NAME, GTK_SORT_ASCENDING);
828 g_object_unref (store);
832 contact_widget_model_populate_columns (EmpathyContactWidget *information)
836 GtkTreeViewColumn *column;
837 GtkCellRenderer *renderer;
840 view = GTK_TREE_VIEW (information->treeview_groups);
841 model = gtk_tree_view_get_model (view);
843 renderer = gtk_cell_renderer_toggle_new ();
844 g_signal_connect (renderer, "toggled",
845 G_CALLBACK (contact_widget_cell_toggled),
848 column = gtk_tree_view_column_new_with_attributes (_("Select"), renderer,
849 "active", COL_ENABLED,
852 gtk_tree_view_column_set_sizing (column, GTK_TREE_VIEW_COLUMN_FIXED);
853 gtk_tree_view_column_set_fixed_width (column, 50);
854 gtk_tree_view_append_column (view, column);
856 renderer = gtk_cell_renderer_text_new ();
857 col_offset = gtk_tree_view_insert_column_with_attributes (view,
861 /* "editable", COL_EDITABLE, */
864 g_object_set_data (G_OBJECT (renderer),
865 "column", GINT_TO_POINTER (COL_NAME));
867 column = gtk_tree_view_get_column (view, col_offset - 1);
868 gtk_tree_view_column_set_sort_column_id (column, COL_NAME);
869 gtk_tree_view_column_set_resizable (column,FALSE);
870 gtk_tree_view_column_set_clickable (GTK_TREE_VIEW_COLUMN (column), TRUE);
872 if (information->renderer) {
873 g_object_unref (information->renderer);
876 information->renderer = g_object_ref (renderer);
880 contact_widget_groups_populate_data (EmpathyContactWidget *information)
885 GList *my_groups, *l;
888 view = GTK_TREE_VIEW (information->treeview_groups);
889 store = GTK_LIST_STORE (gtk_tree_view_get_model (view));
890 gtk_list_store_clear (store);
892 all_groups = empathy_contact_list_get_all_groups (EMPATHY_CONTACT_LIST (information->manager));
893 my_groups = empathy_contact_list_get_groups (EMPATHY_CONTACT_LIST (information->manager),
894 information->contact);
896 for (l = all_groups; l; l = l->next) {
897 const gchar *group_str;
902 enabled = g_list_find_custom (my_groups,
904 (GCompareFunc) strcmp) != NULL;
906 gtk_list_store_append (store, &iter);
907 gtk_list_store_set (store, &iter,
910 COL_ENABLED, enabled,
914 g_list_foreach (all_groups, (GFunc) g_free, NULL);
915 g_list_foreach (my_groups, (GFunc) g_free, NULL);
916 g_list_free (all_groups);
917 g_list_free (my_groups);
921 contact_widget_groups_notify_cb (EmpathyContactWidget *information)
923 /* FIXME: not implemented */
927 contact_widget_model_find_name (EmpathyContactWidget *information,
935 if (G_STR_EMPTY (name)) {
939 data.information = information;
943 view = GTK_TREE_VIEW (information->treeview_groups);
944 model = gtk_tree_view_get_model (view);
946 gtk_tree_model_foreach (model,
947 (GtkTreeModelForeachFunc) contact_widget_model_find_name_foreach,
950 if (data.found == TRUE) {
951 *iter = data.found_iter;
959 contact_widget_model_find_name_foreach (GtkTreeModel *model,
966 gtk_tree_model_get (model, iter,
974 if (data->name && strcmp (data->name, name) == 0) {
976 data->found_iter = *iter;
989 contact_widget_cell_toggled (GtkCellRendererToggle *cell,
991 EmpathyContactWidget *information)
1001 view = GTK_TREE_VIEW (information->treeview_groups);
1002 model = gtk_tree_view_get_model (view);
1003 store = GTK_LIST_STORE (model);
1005 path = gtk_tree_path_new_from_string (path_string);
1007 gtk_tree_model_get_iter (model, &iter, path);
1008 gtk_tree_model_get (model, &iter,
1009 COL_ENABLED, &enabled,
1013 gtk_list_store_set (store, &iter, COL_ENABLED, !enabled, -1);
1014 gtk_tree_path_free (path);
1018 empathy_contact_list_remove_from_group (EMPATHY_CONTACT_LIST (information->manager),
1019 information->contact,
1022 empathy_contact_list_add_to_group (EMPATHY_CONTACT_LIST (information->manager),
1023 information->contact,
1032 contact_widget_entry_group_changed_cb (GtkEditable *editable,
1033 EmpathyContactWidget *information)
1038 group = gtk_entry_get_text (GTK_ENTRY (information->entry_group));
1040 if (contact_widget_model_find_name (information, group, &iter)) {
1041 gtk_widget_set_sensitive (GTK_WIDGET (information->button_group), FALSE);
1044 gtk_widget_set_sensitive (GTK_WIDGET (information->button_group),
1045 !G_STR_EMPTY (group));
1050 contact_widget_entry_group_activate_cb (GtkEntry *entry,
1051 EmpathyContactWidget *information)
1053 gtk_widget_activate (GTK_WIDGET (information->button_group));
1057 contact_widget_button_group_clicked_cb (GtkButton *button,
1058 EmpathyContactWidget *information)
1061 GtkListStore *store;
1065 view = GTK_TREE_VIEW (information->treeview_groups);
1066 store = GTK_LIST_STORE (gtk_tree_view_get_model (view));
1068 group = gtk_entry_get_text (GTK_ENTRY (information->entry_group));
1070 gtk_list_store_append (store, &iter);
1071 gtk_list_store_set (store, &iter,
1076 empathy_contact_list_add_to_group (EMPATHY_CONTACT_LIST (information->manager),
1077 information->contact,
1082 contact_widget_details_setup (EmpathyContactWidget *information)
1084 /* FIXME: Needs new telepathy spec */
1085 gtk_widget_hide (information->vbox_details);
1089 contact_widget_details_update (EmpathyContactWidget *information)
1091 /* FIXME: Needs new telepathy spec */
1095 contact_widget_client_setup (EmpathyContactWidget *information)
1097 /* FIXME: Needs new telepathy spec */
1098 gtk_widget_hide (information->vbox_client);
1102 contact_widget_client_update (EmpathyContactWidget *information)
1104 /* FIXME: Needs new telepathy spec */