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
50 EmpathyContactFactory *factory;
51 EmpathyContactManager *manager;
52 EmpathyContact *contact;
53 EmpathyContactWidgetFlags flags;
54 GtkCellRenderer *renderer;
55 guint widget_id_timeout;
57 GtkWidget *vbox_contact_widget;
60 GtkWidget *vbox_contact;
61 GtkWidget *widget_avatar;
62 GtkWidget *widget_account;
64 GtkWidget *widget_alias;
65 GtkWidget *label_alias;
66 GtkWidget *entry_alias;
67 GtkWidget *hbox_presence;
68 GtkWidget *image_state;
69 GtkWidget *label_status;
70 GtkWidget *table_contact;
71 GtkWidget *vbox_avatar;
74 GtkWidget *vbox_groups;
75 GtkWidget *entry_group;
76 GtkWidget *button_group;
77 GtkWidget *treeview_groups;
80 GtkWidget *vbox_details;
81 GtkWidget *table_details;
82 GtkWidget *hbox_details_requested;
85 GtkWidget *vbox_client;
86 GtkWidget *table_client;
87 GtkWidget *hbox_client_requested;
88 } EmpathyContactWidget;
92 EmpathyContactWidget *information;
95 GtkTreeIter found_iter;
98 static void contact_widget_destroy_cb (GtkWidget *widget,
99 EmpathyContactWidget *information);
100 static void contact_widget_remove_contact (EmpathyContactWidget *information);
101 static void contact_widget_set_contact (EmpathyContactWidget *information,
102 EmpathyContact *contact);
103 static void contact_widget_contact_setup (EmpathyContactWidget *information);
104 static void contact_widget_contact_update (EmpathyContactWidget *information);
105 static void contact_widget_change_contact (EmpathyContactWidget *information);
106 static void contact_widget_avatar_changed_cb (EmpathyAvatarChooser *chooser,
107 EmpathyContactWidget *information);
108 static void contact_widget_account_changed_cb (GtkComboBox *widget,
109 EmpathyContactWidget *information);
110 static gboolean contact_widget_id_focus_out_cb (GtkWidget *widget,
111 GdkEventFocus *event, EmpathyContactWidget *information);
112 static gboolean contact_widget_entry_alias_focus_event_cb (
113 GtkEditable *editable, GdkEventFocus *event,
114 EmpathyContactWidget *information);
115 static void contact_widget_name_notify_cb (EmpathyContactWidget *information);
116 static void contact_widget_presence_notify_cb (
117 EmpathyContactWidget *information);
118 static void contact_widget_avatar_notify_cb (
119 EmpathyContactWidget *information);
120 static void contact_widget_groups_setup (
121 EmpathyContactWidget *information);
122 static void contact_widget_groups_update (EmpathyContactWidget *information);
123 static void contact_widget_model_setup (EmpathyContactWidget *information);
124 static void contact_widget_model_populate_columns (
125 EmpathyContactWidget *information);
126 static void contact_widget_groups_populate_data (
127 EmpathyContactWidget *information);
128 static void contact_widget_groups_notify_cb (
129 EmpathyContactWidget *information);
130 static gboolean contact_widget_model_find_name (
131 EmpathyContactWidget *information,const gchar *name, GtkTreeIter *iter);
132 static gboolean contact_widget_model_find_name_foreach (GtkTreeModel *model,
133 GtkTreePath *path, GtkTreeIter *iter, FindName *data);
134 static void contact_widget_cell_toggled (GtkCellRendererToggle *cell,
135 gchar *path_string, EmpathyContactWidget *information);
136 static void contact_widget_entry_group_changed_cb (GtkEditable *editable,
137 EmpathyContactWidget *information);
138 static void contact_widget_entry_group_activate_cb (GtkEntry *entry,
139 EmpathyContactWidget *information);
140 static void contact_widget_button_group_clicked_cb (GtkButton *button,
141 EmpathyContactWidget *information);
142 static void contact_widget_details_setup (EmpathyContactWidget *information);
143 static void contact_widget_details_update (EmpathyContactWidget *information);
144 static void contact_widget_client_setup (EmpathyContactWidget *information);
145 static void contact_widget_client_update (EmpathyContactWidget *information);
156 empathy_contact_widget_new (EmpathyContact *contact,
157 EmpathyContactWidgetFlags flags)
159 EmpathyContactWidget *information;
163 information = g_slice_new0 (EmpathyContactWidget);
164 information->flags = flags;
165 information->factory = empathy_contact_factory_new ();
167 filename = empathy_file_lookup ("empathy-contact-widget.glade",
169 glade = empathy_glade_get_file (filename,
170 "vbox_contact_widget",
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_glade_connect (glade,
195 "vbox_contact_widget", "destroy", contact_widget_destroy_cb,
196 "entry_group", "changed", contact_widget_entry_group_changed_cb,
197 "entry_group", "activate", contact_widget_entry_group_activate_cb,
198 "button_group", "clicked", contact_widget_button_group_clicked_cb,
201 g_object_unref (glade);
203 g_object_set_data (G_OBJECT (information->vbox_contact_widget),
204 "EmpathyContactWidget",
208 contact_widget_contact_setup (information);
209 contact_widget_groups_setup (information);
210 contact_widget_details_setup (information);
211 contact_widget_client_setup (information);
213 contact_widget_set_contact (information, contact);
215 gtk_widget_show (information->vbox_contact_widget);
217 return information->vbox_contact_widget;
221 empathy_contact_widget_get_contact (GtkWidget *widget)
223 EmpathyContactWidget *information;
225 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
227 information = g_object_get_data (G_OBJECT (widget), "EmpathyContactWidget");
231 return information->contact;
235 empathy_contact_widget_set_contact (GtkWidget *widget,
236 EmpathyContact *contact)
238 EmpathyContactWidget *information;
240 g_return_if_fail (GTK_IS_WIDGET (widget));
241 g_return_if_fail (EMPATHY_IS_CONTACT (contact));
243 information = g_object_get_data (G_OBJECT (widget), "EmpathyContactWidget");
247 contact_widget_set_contact (information, contact);
251 empathy_contact_widget_set_account_filter (
253 EmpathyAccountChooserFilterFunc filter,
256 EmpathyContactWidget *information;
257 EmpathyAccountChooser *chooser;
259 g_return_if_fail (GTK_IS_WIDGET (widget));
261 information = g_object_get_data (G_OBJECT (widget), "EmpathyContactWidget");
265 chooser = EMPATHY_ACCOUNT_CHOOSER (information->widget_account);
267 empathy_account_chooser_set_filter (chooser, filter, user_data);
271 contact_widget_destroy_cb (GtkWidget *widget,
272 EmpathyContactWidget *information)
274 contact_widget_remove_contact (information);
276 if (information->widget_id_timeout != 0)
278 g_source_remove (information->widget_id_timeout);
280 if (information->factory)
282 g_object_unref (information->factory);
284 if (information->manager)
286 g_object_unref (information->manager);
289 g_slice_free (EmpathyContactWidget, information);
293 contact_widget_remove_contact (EmpathyContactWidget *information)
295 if (information->contact)
297 g_signal_handlers_disconnect_by_func (information->contact,
298 contact_widget_name_notify_cb, information);
299 g_signal_handlers_disconnect_by_func (information->contact,
300 contact_widget_presence_notify_cb, information);
301 g_signal_handlers_disconnect_by_func (information->contact,
302 contact_widget_avatar_notify_cb, information);
303 g_signal_handlers_disconnect_by_func (information->contact,
304 contact_widget_groups_notify_cb, information);
306 g_object_unref (information->contact);
307 information->contact = NULL;
312 contact_widget_set_contact (EmpathyContactWidget *information,
313 EmpathyContact *contact)
315 if (contact == information->contact)
318 contact_widget_remove_contact (information);
320 information->contact = g_object_ref (contact);
322 /* Update information for widgets */
323 contact_widget_contact_update (information);
324 contact_widget_groups_update (information);
325 contact_widget_details_update (information);
326 contact_widget_client_update (information);
330 contact_widget_id_activate_timeout (EmpathyContactWidget *self)
332 contact_widget_change_contact (self);
337 contact_widget_id_changed_cb (GtkEntry *entry,
338 EmpathyContactWidget *self)
340 if (self->widget_id_timeout != 0)
342 g_source_remove (self->widget_id_timeout);
345 self->widget_id_timeout =
346 g_timeout_add_seconds (ID_CHANGED_TIMEOUT,
347 (GSourceFunc) contact_widget_id_activate_timeout, self);
351 save_avatar_menu_activate_cb (GtkWidget *widget,
352 EmpathyContactWidget *information)
355 EmpathyAvatar *avatar;
356 gchar *ext = NULL, *filename;
358 dialog = gtk_file_chooser_dialog_new (_("Save Avatar"),
360 GTK_FILE_CHOOSER_ACTION_SAVE,
361 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
362 GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT,
365 gtk_file_chooser_set_do_overwrite_confirmation (GTK_FILE_CHOOSER (dialog),
368 /* look for the avatar extension */
369 avatar = empathy_contact_get_avatar (information->contact);
370 if (avatar->format != NULL)
374 splitted = g_strsplit (avatar->format, "/", 2);
375 if (splitted[0] != NULL && splitted[1] != NULL)
376 ext = g_strdup (splitted[1]);
378 g_strfreev (splitted);
382 /* Avatar was loaded from the cache so was converted to PNG */
383 ext = g_strdup ("png");
390 id = tp_escape_as_identifier (empathy_contact_get_id (
391 information->contact));
393 filename = g_strdup_printf ("%s.%s", id, ext);
394 gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (dialog), filename);
401 if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT)
403 GError *error = NULL;
405 filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
407 if (!empathy_avatar_save_to_file (avatar, filename, &error))
412 dialog = gtk_message_dialog_new (NULL, 0,
413 GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE,
414 _("Unable to save avatar"));
416 gtk_message_dialog_format_secondary_text (
417 GTK_MESSAGE_DIALOG (dialog), "%s", error->message);
419 g_signal_connect (dialog, "response",
420 G_CALLBACK (gtk_widget_destroy), NULL);
422 gtk_window_present (GTK_WINDOW (dialog));
424 g_clear_error (&error);
430 gtk_widget_destroy (dialog);
434 popup_avatar_menu (EmpathyContactWidget *information,
436 GdkEventButton *event)
438 GtkWidget *menu, *item;
439 gint button, event_time;
441 if (information->contact == NULL ||
442 empathy_contact_get_avatar (information->contact) == NULL)
445 menu = gtk_menu_new ();
447 /* Add "Save as..." entry */
448 item = gtk_image_menu_item_new_from_stock (GTK_STOCK_SAVE_AS, NULL);
449 gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
450 gtk_widget_show (item);
452 g_signal_connect (item, "activate",
453 G_CALLBACK (save_avatar_menu_activate_cb), information);
457 button = event->button;
458 event_time = event->time;
463 event_time = gtk_get_current_event_time ();
466 gtk_menu_attach_to_widget (GTK_MENU (menu), parent, NULL);
467 gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
472 widget_avatar_popup_menu_cb (GtkWidget *widget,
473 EmpathyContactWidget *information)
475 popup_avatar_menu (information, widget, NULL);
481 widget_avatar_button_press_event_cb (GtkWidget *widget,
482 GdkEventButton *event,
483 EmpathyContactWidget *information)
485 /* Ignore double-clicks and triple-clicks */
486 if (event->button == 3 && event->type == GDK_BUTTON_PRESS)
488 popup_avatar_menu (information, widget, event);
496 contact_widget_contact_setup (EmpathyContactWidget *information)
498 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),
507 information->widget_avatar = empathy_avatar_image_new ();
509 g_signal_connect (information->widget_avatar, "popup-menu",
510 G_CALLBACK (widget_avatar_popup_menu_cb), information);
511 g_signal_connect (information->widget_avatar, "button-press-event",
512 G_CALLBACK (widget_avatar_button_press_event_cb), information);
515 gtk_box_pack_start (GTK_BOX (information->vbox_avatar),
516 information->widget_avatar,
519 gtk_widget_show (information->widget_avatar);
521 /* Setup account label/chooser */
522 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ACCOUNT)
524 information->widget_account = empathy_account_chooser_new ();
526 g_signal_connect (information->widget_account, "changed",
527 G_CALLBACK (contact_widget_account_changed_cb),
532 information->widget_account = gtk_label_new (NULL);
533 if (!information->flags & EMPATHY_CONTACT_WIDGET_FOR_TOOLTIP) {
534 gtk_label_set_selectable (GTK_LABEL (information->widget_account), TRUE);
536 gtk_misc_set_alignment (GTK_MISC (information->widget_account), 0, 0.5);
538 gtk_table_attach_defaults (GTK_TABLE (information->table_contact),
539 information->widget_account,
541 gtk_widget_show (information->widget_account);
543 /* Setup id label/entry */
544 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ID)
546 information->widget_id = gtk_entry_new ();
547 g_signal_connect (information->widget_id, "focus-out-event",
548 G_CALLBACK (contact_widget_id_focus_out_cb),
550 g_signal_connect (information->widget_id, "changed",
551 G_CALLBACK (contact_widget_id_changed_cb),
556 information->widget_id = gtk_label_new (NULL);
557 if (!information->flags & EMPATHY_CONTACT_WIDGET_FOR_TOOLTIP) {
558 gtk_label_set_selectable (GTK_LABEL (information->widget_id), TRUE);
560 gtk_misc_set_alignment (GTK_MISC (information->widget_id), 0, 0.5);
562 gtk_table_attach_defaults (GTK_TABLE (information->table_contact),
563 information->widget_id,
565 gtk_widget_show (information->widget_id);
567 /* Setup alias label/entry */
568 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ALIAS)
570 information->widget_alias = gtk_entry_new ();
571 g_signal_connect (information->widget_alias, "focus-out-event",
572 G_CALLBACK (contact_widget_entry_alias_focus_event_cb),
574 /* Make return activate the window default (the Close button) */
575 gtk_entry_set_activates_default (GTK_ENTRY (information->widget_alias),
580 information->widget_alias = gtk_label_new (NULL);
581 if (!information->flags & EMPATHY_CONTACT_WIDGET_FOR_TOOLTIP) {
582 gtk_label_set_selectable (GTK_LABEL (information->widget_alias), TRUE);
584 gtk_misc_set_alignment (GTK_MISC (information->widget_alias), 0, 0.5);
586 gtk_table_attach_defaults (GTK_TABLE (information->table_contact),
587 information->widget_alias,
589 if (information->flags & EMPATHY_CONTACT_WIDGET_FOR_TOOLTIP) {
590 gtk_label_set_selectable (GTK_LABEL (information->label_status), FALSE);
592 gtk_widget_show (information->widget_alias);
596 contact_widget_contact_update (EmpathyContactWidget *information)
598 McAccount *account = NULL;
599 const gchar *id = NULL;
601 /* Connect and get info from new contact */
602 if (information->contact)
604 g_signal_connect_swapped (information->contact, "notify::name",
605 G_CALLBACK (contact_widget_name_notify_cb), information);
606 g_signal_connect_swapped (information->contact, "notify::presence",
607 G_CALLBACK (contact_widget_presence_notify_cb), information);
608 g_signal_connect_swapped (information->contact,
609 "notify::presence-message",
610 G_CALLBACK (contact_widget_presence_notify_cb), information);
611 g_signal_connect_swapped (information->contact, "notify::avatar",
612 G_CALLBACK (contact_widget_avatar_notify_cb), information);
614 account = empathy_contact_get_account (information->contact);
615 id = empathy_contact_get_id (information->contact);
618 /* Update account widget */
619 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ACCOUNT)
623 g_signal_handlers_block_by_func (information->widget_account,
624 contact_widget_account_changed_cb,
626 empathy_account_chooser_set_account (
627 EMPATHY_ACCOUNT_CHOOSER (information->widget_account), account);
628 g_signal_handlers_unblock_by_func (information->widget_account,
629 contact_widget_account_changed_cb, information);
638 name = mc_account_get_display_name (account);
639 gtk_label_set_label (GTK_LABEL (information->widget_account), name);
643 /* Update id widget */
644 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ID)
645 gtk_entry_set_text (GTK_ENTRY (information->widget_id), id ? id : "");
647 gtk_label_set_label (GTK_LABEL (information->widget_id), id ? id : "");
649 /* Update other widgets */
650 if (information->contact)
652 contact_widget_name_notify_cb (information);
653 contact_widget_presence_notify_cb (information);
654 contact_widget_avatar_notify_cb (information);
656 gtk_widget_show (information->label_alias);
657 gtk_widget_show (information->widget_alias);
658 gtk_widget_show (information->hbox_presence);
659 gtk_widget_show (information->widget_avatar);
663 gtk_widget_hide (information->label_alias);
664 gtk_widget_hide (information->widget_alias);
665 gtk_widget_hide (information->hbox_presence);
666 gtk_widget_hide (information->widget_avatar);
671 contact_widget_change_contact (EmpathyContactWidget *information)
673 EmpathyContact *contact;
676 account = empathy_account_chooser_get_account (
677 EMPATHY_ACCOUNT_CHOOSER (information->widget_account));
681 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ID)
685 id = gtk_entry_get_text (GTK_ENTRY (information->widget_id));
686 if (G_STR_EMPTY (id))
689 contact = empathy_contact_factory_get_from_id (information->factory,
694 contact = empathy_contact_factory_get_user (information->factory,
700 empathy_contact_run_until_ready (contact,
701 EMPATHY_CONTACT_READY_HANDLE |
702 EMPATHY_CONTACT_READY_ID,
704 contact_widget_set_contact (information, contact);
705 g_object_unref (contact);
710 contact_widget_avatar_changed_cb (EmpathyAvatarChooser *chooser,
711 EmpathyContactWidget *information)
713 if (information->contact && empathy_contact_is_user (information->contact))
718 const gchar *mime_type;
720 account = empathy_contact_get_account (information->contact);
721 empathy_avatar_chooser_get_image_data (
722 EMPATHY_AVATAR_CHOOSER (information->widget_avatar),
723 &data, &size, &mime_type);
724 empathy_contact_factory_set_avatar (information->factory, account,
725 data, size, mime_type);
730 contact_widget_account_changed_cb (GtkComboBox *widget,
731 EmpathyContactWidget *information)
733 contact_widget_change_contact (information);
737 contact_widget_id_focus_out_cb (GtkWidget *widget,
738 GdkEventFocus *event,
739 EmpathyContactWidget *information)
741 contact_widget_change_contact (information);
746 contact_widget_entry_alias_focus_event_cb (GtkEditable *editable,
747 GdkEventFocus *event,
748 EmpathyContactWidget *information)
750 if (information->contact)
754 alias = gtk_entry_get_text (GTK_ENTRY (editable));
755 empathy_contact_factory_set_alias (information->factory,
756 information->contact, alias);
763 contact_widget_name_notify_cb (EmpathyContactWidget *information)
765 if (GTK_IS_ENTRY (information->widget_alias))
766 gtk_entry_set_text (GTK_ENTRY (information->widget_alias),
767 empathy_contact_get_name (information->contact));
769 gtk_label_set_label (GTK_LABEL (information->widget_alias),
770 empathy_contact_get_name (information->contact));
774 contact_widget_presence_notify_cb (EmpathyContactWidget *information)
776 gtk_label_set_text (GTK_LABEL (information->label_status),
777 empathy_contact_get_status (information->contact));
778 gtk_image_set_from_icon_name (GTK_IMAGE (information->image_state),
779 empathy_icon_name_for_contact (information->contact),
780 GTK_ICON_SIZE_BUTTON);
784 contact_widget_avatar_notify_cb (EmpathyContactWidget *information)
786 EmpathyAvatar *avatar = NULL;
788 if (information->contact)
789 avatar = empathy_contact_get_avatar (information->contact);
791 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_AVATAR)
793 g_signal_handlers_block_by_func (information->widget_avatar,
794 contact_widget_avatar_changed_cb,
796 empathy_avatar_chooser_set (
797 EMPATHY_AVATAR_CHOOSER (information->widget_avatar), avatar);
798 g_signal_handlers_unblock_by_func (information->widget_avatar,
799 contact_widget_avatar_changed_cb, information);
802 empathy_avatar_image_set (
803 EMPATHY_AVATAR_IMAGE (information->widget_avatar), avatar);
807 contact_widget_groups_setup (EmpathyContactWidget *information)
809 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_GROUPS)
811 information->manager = empathy_contact_manager_new ();
812 contact_widget_model_setup (information);
817 contact_widget_groups_update (EmpathyContactWidget *information)
819 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_GROUPS &&
820 information->contact)
822 g_signal_connect_swapped (information->contact, "notify::groups",
823 G_CALLBACK (contact_widget_groups_notify_cb), information);
824 contact_widget_groups_populate_data (information);
826 gtk_widget_show (information->vbox_groups);
829 gtk_widget_hide (information->vbox_groups);
833 contact_widget_model_setup (EmpathyContactWidget *information)
837 GtkTreeSelection *selection;
839 view = GTK_TREE_VIEW (information->treeview_groups);
841 store = gtk_list_store_new (COL_COUNT,
842 G_TYPE_STRING, /* name */
843 G_TYPE_BOOLEAN, /* enabled */
844 G_TYPE_BOOLEAN); /* editable */
846 gtk_tree_view_set_model (view, GTK_TREE_MODEL (store));
848 selection = gtk_tree_view_get_selection (view);
849 gtk_tree_selection_set_mode (selection, GTK_SELECTION_SINGLE);
851 contact_widget_model_populate_columns (information);
853 gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (store),
854 COL_NAME, GTK_SORT_ASCENDING);
856 g_object_unref (store);
860 contact_widget_model_populate_columns (EmpathyContactWidget *information)
864 GtkTreeViewColumn *column;
865 GtkCellRenderer *renderer;
868 view = GTK_TREE_VIEW (information->treeview_groups);
869 model = gtk_tree_view_get_model (view);
871 renderer = gtk_cell_renderer_toggle_new ();
872 g_signal_connect (renderer, "toggled",
873 G_CALLBACK (contact_widget_cell_toggled), information);
875 column = gtk_tree_view_column_new_with_attributes (_("Select"), renderer,
876 "active", COL_ENABLED, NULL);
878 gtk_tree_view_column_set_sizing (column, GTK_TREE_VIEW_COLUMN_FIXED);
879 gtk_tree_view_column_set_fixed_width (column, 50);
880 gtk_tree_view_append_column (view, column);
882 renderer = gtk_cell_renderer_text_new ();
883 col_offset = gtk_tree_view_insert_column_with_attributes (view,
887 /* "editable", COL_EDITABLE, */
890 g_object_set_data (G_OBJECT (renderer),
891 "column", GINT_TO_POINTER (COL_NAME));
893 column = gtk_tree_view_get_column (view, col_offset - 1);
894 gtk_tree_view_column_set_sort_column_id (column, COL_NAME);
895 gtk_tree_view_column_set_resizable (column,FALSE);
896 gtk_tree_view_column_set_clickable (GTK_TREE_VIEW_COLUMN (column), TRUE);
898 if (information->renderer)
899 g_object_unref (information->renderer);
901 information->renderer = g_object_ref (renderer);
905 contact_widget_groups_populate_data (EmpathyContactWidget *information)
910 GList *my_groups, *l;
913 view = GTK_TREE_VIEW (information->treeview_groups);
914 store = GTK_LIST_STORE (gtk_tree_view_get_model (view));
915 gtk_list_store_clear (store);
917 all_groups = empathy_contact_list_get_all_groups (
918 EMPATHY_CONTACT_LIST (information->manager));
919 my_groups = empathy_contact_list_get_groups (
920 EMPATHY_CONTACT_LIST (information->manager),
921 information->contact);
923 for (l = all_groups; l; l = l->next)
925 const gchar *group_str;
930 enabled = g_list_find_custom (my_groups,
931 group_str, (GCompareFunc) strcmp) != NULL;
933 gtk_list_store_append (store, &iter);
934 gtk_list_store_set (store, &iter,
937 COL_ENABLED, enabled,
941 g_list_foreach (all_groups, (GFunc) g_free, NULL);
942 g_list_foreach (my_groups, (GFunc) g_free, NULL);
943 g_list_free (all_groups);
944 g_list_free (my_groups);
948 contact_widget_groups_notify_cb (EmpathyContactWidget *information)
950 /* FIXME: not implemented */
954 contact_widget_model_find_name (EmpathyContactWidget *information,
962 if (G_STR_EMPTY (name))
965 data.information = information;
969 view = GTK_TREE_VIEW (information->treeview_groups);
970 model = gtk_tree_view_get_model (view);
972 gtk_tree_model_foreach (model,
973 (GtkTreeModelForeachFunc) contact_widget_model_find_name_foreach,
976 if (data.found == TRUE)
978 *iter = data.found_iter;
986 contact_widget_model_find_name_foreach (GtkTreeModel *model,
993 gtk_tree_model_get (model, iter,
1000 if (data->name && strcmp (data->name, name) == 0)
1003 data->found_iter = *iter;
1016 contact_widget_cell_toggled (GtkCellRendererToggle *cell,
1018 EmpathyContactWidget *information)
1021 GtkTreeModel *model;
1022 GtkListStore *store;
1028 view = GTK_TREE_VIEW (information->treeview_groups);
1029 model = gtk_tree_view_get_model (view);
1030 store = GTK_LIST_STORE (model);
1032 path = gtk_tree_path_new_from_string (path_string);
1034 gtk_tree_model_get_iter (model, &iter, path);
1035 gtk_tree_model_get (model, &iter,
1036 COL_ENABLED, &enabled,
1040 gtk_list_store_set (store, &iter, COL_ENABLED, !enabled, -1);
1041 gtk_tree_path_free (path);
1047 empathy_contact_list_remove_from_group (
1048 EMPATHY_CONTACT_LIST (information->manager), information->contact,
1053 empathy_contact_list_add_to_group (
1054 EMPATHY_CONTACT_LIST (information->manager), information->contact,
1062 contact_widget_entry_group_changed_cb (GtkEditable *editable,
1063 EmpathyContactWidget *information)
1068 group = gtk_entry_get_text (GTK_ENTRY (information->entry_group));
1070 if (contact_widget_model_find_name (information, group, &iter))
1071 gtk_widget_set_sensitive (GTK_WIDGET (information->button_group), FALSE);
1073 gtk_widget_set_sensitive (GTK_WIDGET (information->button_group),
1074 !G_STR_EMPTY (group));
1078 contact_widget_entry_group_activate_cb (GtkEntry *entry,
1079 EmpathyContactWidget *information)
1081 gtk_widget_activate (GTK_WIDGET (information->button_group));
1085 contact_widget_button_group_clicked_cb (GtkButton *button,
1086 EmpathyContactWidget *information)
1089 GtkListStore *store;
1093 view = GTK_TREE_VIEW (information->treeview_groups);
1094 store = GTK_LIST_STORE (gtk_tree_view_get_model (view));
1096 group = gtk_entry_get_text (GTK_ENTRY (information->entry_group));
1098 gtk_list_store_append (store, &iter);
1099 gtk_list_store_set (store, &iter,
1104 empathy_contact_list_add_to_group (
1105 EMPATHY_CONTACT_LIST (information->manager), information->contact,
1110 contact_widget_details_setup (EmpathyContactWidget *information)
1112 /* FIXME: Needs new telepathy spec */
1113 gtk_widget_hide (information->vbox_details);
1117 contact_widget_details_update (EmpathyContactWidget *information)
1119 /* FIXME: Needs new telepathy spec */
1123 contact_widget_client_setup (EmpathyContactWidget *information)
1125 /* FIXME: Needs new telepathy spec */
1126 gtk_widget_hide (information->vbox_client);
1130 contact_widget_client_update (EmpathyContactWidget *information)
1132 /* FIXME: Needs new telepathy spec */