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 *hbow_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->hbow_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 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 contact_widget_contact_setup (EmpathyContactWidget *information)
494 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_AVATAR)
496 information->widget_avatar = empathy_avatar_chooser_new ();
497 g_signal_connect (information->widget_avatar, "changed",
498 G_CALLBACK (contact_widget_avatar_changed_cb),
503 information->widget_avatar = empathy_avatar_image_new ();
505 g_signal_connect (information->widget_avatar, "popup-menu",
506 G_CALLBACK (widget_avatar_popup_menu_cb), information);
507 g_signal_connect (information->widget_avatar, "button-press-event",
508 G_CALLBACK (widget_avatar_button_press_event_cb), information);
511 gtk_box_pack_start (GTK_BOX (information->vbox_avatar),
512 information->widget_avatar,
515 gtk_widget_show (information->widget_avatar);
517 /* Setup account label/chooser */
518 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ACCOUNT)
520 information->widget_account = empathy_account_chooser_new ();
522 g_signal_connect (information->widget_account, "changed",
523 G_CALLBACK (contact_widget_account_changed_cb),
528 information->widget_account = gtk_label_new (NULL);
529 gtk_label_set_selectable (GTK_LABEL (information->widget_account), TRUE);
530 gtk_misc_set_alignment (GTK_MISC (information->widget_account), 0, 0.5);
532 gtk_table_attach_defaults (GTK_TABLE (information->table_contact),
533 information->widget_account,
535 gtk_widget_show (information->widget_account);
537 /* Setup id label/entry */
538 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ID)
540 information->widget_id = gtk_entry_new ();
541 g_signal_connect (information->widget_id, "focus-out-event",
542 G_CALLBACK (contact_widget_id_focus_out_cb),
544 g_signal_connect (information->widget_id, "changed",
545 G_CALLBACK (contact_widget_id_changed_cb),
550 information->widget_id = gtk_label_new (NULL);
551 gtk_label_set_selectable (GTK_LABEL (information->widget_id), TRUE);
552 gtk_misc_set_alignment (GTK_MISC (information->widget_id), 0, 0.5);
554 gtk_table_attach_defaults (GTK_TABLE (information->table_contact),
555 information->widget_id,
557 gtk_widget_show (information->widget_id);
559 /* Setup alias label/entry */
560 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ALIAS)
562 information->widget_alias = gtk_entry_new ();
563 g_signal_connect (information->widget_alias, "focus-out-event",
564 G_CALLBACK (contact_widget_entry_alias_focus_event_cb),
566 /* Make return activate the window default (the Close button) */
567 gtk_entry_set_activates_default (GTK_ENTRY (information->widget_alias),
572 information->widget_alias = gtk_label_new (NULL);
573 gtk_label_set_selectable (GTK_LABEL (information->widget_alias), TRUE);
574 gtk_misc_set_alignment (GTK_MISC (information->widget_alias), 0, 0.5);
576 gtk_table_attach_defaults (GTK_TABLE (information->table_contact),
577 information->widget_alias,
579 gtk_widget_show (information->widget_alias);
583 contact_widget_contact_update (EmpathyContactWidget *information)
585 McAccount *account = NULL;
586 const gchar *id = NULL;
588 /* Connect and get info from new contact */
589 if (information->contact)
591 g_signal_connect_swapped (information->contact, "notify::name",
592 G_CALLBACK (contact_widget_name_notify_cb), information);
593 g_signal_connect_swapped (information->contact, "notify::presence",
594 G_CALLBACK (contact_widget_presence_notify_cb), information);
595 g_signal_connect_swapped (information->contact,
596 "notify::presence-message",
597 G_CALLBACK (contact_widget_presence_notify_cb), information);
598 g_signal_connect_swapped (information->contact, "notify::avatar",
599 G_CALLBACK (contact_widget_avatar_notify_cb), information);
601 account = empathy_contact_get_account (information->contact);
602 id = empathy_contact_get_id (information->contact);
605 /* Update account widget */
606 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ACCOUNT)
610 g_signal_handlers_block_by_func (information->widget_account,
611 contact_widget_account_changed_cb,
613 empathy_account_chooser_set_account (
614 EMPATHY_ACCOUNT_CHOOSER (information->widget_account), account);
615 g_signal_handlers_unblock_by_func (information->widget_account,
616 contact_widget_account_changed_cb, information);
625 name = mc_account_get_display_name (account);
626 gtk_label_set_label (GTK_LABEL (information->widget_account), name);
630 /* Update id widget */
631 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ID)
632 gtk_entry_set_text (GTK_ENTRY (information->widget_id), id ? id : "");
634 gtk_label_set_label (GTK_LABEL (information->widget_id), id ? id : "");
636 /* Update other widgets */
637 if (information->contact)
639 contact_widget_name_notify_cb (information);
640 contact_widget_presence_notify_cb (information);
641 contact_widget_avatar_notify_cb (information);
643 gtk_widget_show (information->label_alias);
644 gtk_widget_show (information->widget_alias);
645 gtk_widget_show (information->hbox_presence);
646 gtk_widget_show (information->widget_avatar);
650 gtk_widget_hide (information->label_alias);
651 gtk_widget_hide (information->widget_alias);
652 gtk_widget_hide (information->hbox_presence);
653 gtk_widget_hide (information->widget_avatar);
658 contact_widget_change_contact (EmpathyContactWidget *information)
660 EmpathyContact *contact;
663 account = empathy_account_chooser_get_account (
664 EMPATHY_ACCOUNT_CHOOSER (information->widget_account));
668 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ID)
672 id = gtk_entry_get_text (GTK_ENTRY (information->widget_id));
673 if (G_STR_EMPTY (id))
676 contact = empathy_contact_factory_get_from_id (information->factory,
681 contact = empathy_contact_factory_get_user (information->factory,
687 empathy_contact_run_until_ready (contact,
688 EMPATHY_CONTACT_READY_HANDLE |
689 EMPATHY_CONTACT_READY_ID,
691 contact_widget_set_contact (information, contact);
692 g_object_unref (contact);
697 contact_widget_avatar_changed_cb (EmpathyAvatarChooser *chooser,
698 EmpathyContactWidget *information)
700 if (information->contact && empathy_contact_is_user (information->contact))
705 const gchar *mime_type;
707 account = empathy_contact_get_account (information->contact);
708 empathy_avatar_chooser_get_image_data (
709 EMPATHY_AVATAR_CHOOSER (information->widget_avatar),
710 &data, &size, &mime_type);
711 empathy_contact_factory_set_avatar (information->factory, account,
712 data, size, mime_type);
717 contact_widget_account_changed_cb (GtkComboBox *widget,
718 EmpathyContactWidget *information)
720 contact_widget_change_contact (information);
724 contact_widget_id_focus_out_cb (GtkWidget *widget,
725 GdkEventFocus *event,
726 EmpathyContactWidget *information)
728 contact_widget_change_contact (information);
733 contact_widget_entry_alias_focus_event_cb (GtkEditable *editable,
734 GdkEventFocus *event,
735 EmpathyContactWidget *information)
737 if (information->contact)
741 alias = gtk_entry_get_text (GTK_ENTRY (editable));
742 empathy_contact_factory_set_alias (information->factory,
743 information->contact, alias);
750 contact_widget_name_notify_cb (EmpathyContactWidget *information)
752 if (GTK_IS_ENTRY (information->widget_alias))
753 gtk_entry_set_text (GTK_ENTRY (information->widget_alias),
754 empathy_contact_get_name (information->contact));
756 gtk_label_set_label (GTK_LABEL (information->widget_alias),
757 empathy_contact_get_name (information->contact));
761 contact_widget_presence_notify_cb (EmpathyContactWidget *information)
763 gtk_label_set_text (GTK_LABEL (information->label_status),
764 empathy_contact_get_status (information->contact));
765 gtk_image_set_from_icon_name (GTK_IMAGE (information->image_state),
766 empathy_icon_name_for_contact (information->contact),
767 GTK_ICON_SIZE_BUTTON);
771 contact_widget_avatar_notify_cb (EmpathyContactWidget *information)
773 EmpathyAvatar *avatar = NULL;
775 if (information->contact)
776 avatar = empathy_contact_get_avatar (information->contact);
778 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_AVATAR)
780 g_signal_handlers_block_by_func (information->widget_avatar,
781 contact_widget_avatar_changed_cb,
783 empathy_avatar_chooser_set (
784 EMPATHY_AVATAR_CHOOSER (information->widget_avatar), avatar);
785 g_signal_handlers_unblock_by_func (information->widget_avatar,
786 contact_widget_avatar_changed_cb, information);
789 empathy_avatar_image_set (
790 EMPATHY_AVATAR_IMAGE (information->widget_avatar), avatar);
794 contact_widget_groups_setup (EmpathyContactWidget *information)
796 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_GROUPS)
798 information->manager = empathy_contact_manager_new ();
799 contact_widget_model_setup (information);
804 contact_widget_groups_update (EmpathyContactWidget *information)
806 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_GROUPS &&
807 information->contact)
809 g_signal_connect_swapped (information->contact, "notify::groups",
810 G_CALLBACK (contact_widget_groups_notify_cb), information);
811 contact_widget_groups_populate_data (information);
813 gtk_widget_show (information->vbox_groups);
816 gtk_widget_hide (information->vbox_groups);
820 contact_widget_model_setup (EmpathyContactWidget *information)
824 GtkTreeSelection *selection;
826 view = GTK_TREE_VIEW (information->treeview_groups);
828 store = gtk_list_store_new (COL_COUNT,
829 G_TYPE_STRING, /* name */
830 G_TYPE_BOOLEAN, /* enabled */
831 G_TYPE_BOOLEAN); /* editable */
833 gtk_tree_view_set_model (view, GTK_TREE_MODEL (store));
835 selection = gtk_tree_view_get_selection (view);
836 gtk_tree_selection_set_mode (selection, GTK_SELECTION_SINGLE);
838 contact_widget_model_populate_columns (information);
840 gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (store),
841 COL_NAME, GTK_SORT_ASCENDING);
843 g_object_unref (store);
847 contact_widget_model_populate_columns (EmpathyContactWidget *information)
851 GtkTreeViewColumn *column;
852 GtkCellRenderer *renderer;
855 view = GTK_TREE_VIEW (information->treeview_groups);
856 model = gtk_tree_view_get_model (view);
858 renderer = gtk_cell_renderer_toggle_new ();
859 g_signal_connect (renderer, "toggled",
860 G_CALLBACK (contact_widget_cell_toggled), information);
862 column = gtk_tree_view_column_new_with_attributes (_("Select"), renderer,
863 "active", COL_ENABLED, NULL);
865 gtk_tree_view_column_set_sizing (column, GTK_TREE_VIEW_COLUMN_FIXED);
866 gtk_tree_view_column_set_fixed_width (column, 50);
867 gtk_tree_view_append_column (view, column);
869 renderer = gtk_cell_renderer_text_new ();
870 col_offset = gtk_tree_view_insert_column_with_attributes (view,
874 /* "editable", COL_EDITABLE, */
877 g_object_set_data (G_OBJECT (renderer),
878 "column", GINT_TO_POINTER (COL_NAME));
880 column = gtk_tree_view_get_column (view, col_offset - 1);
881 gtk_tree_view_column_set_sort_column_id (column, COL_NAME);
882 gtk_tree_view_column_set_resizable (column,FALSE);
883 gtk_tree_view_column_set_clickable (GTK_TREE_VIEW_COLUMN (column), TRUE);
885 if (information->renderer)
886 g_object_unref (information->renderer);
888 information->renderer = g_object_ref (renderer);
892 contact_widget_groups_populate_data (EmpathyContactWidget *information)
897 GList *my_groups, *l;
900 view = GTK_TREE_VIEW (information->treeview_groups);
901 store = GTK_LIST_STORE (gtk_tree_view_get_model (view));
902 gtk_list_store_clear (store);
904 all_groups = empathy_contact_list_get_all_groups (
905 EMPATHY_CONTACT_LIST (information->manager));
906 my_groups = empathy_contact_list_get_groups (
907 EMPATHY_CONTACT_LIST (information->manager),
908 information->contact);
910 for (l = all_groups; l; l = l->next)
912 const gchar *group_str;
917 enabled = g_list_find_custom (my_groups,
918 group_str, (GCompareFunc) strcmp) != NULL;
920 gtk_list_store_append (store, &iter);
921 gtk_list_store_set (store, &iter,
924 COL_ENABLED, enabled,
928 g_list_foreach (all_groups, (GFunc) g_free, NULL);
929 g_list_foreach (my_groups, (GFunc) g_free, NULL);
930 g_list_free (all_groups);
931 g_list_free (my_groups);
935 contact_widget_groups_notify_cb (EmpathyContactWidget *information)
937 /* FIXME: not implemented */
941 contact_widget_model_find_name (EmpathyContactWidget *information,
949 if (G_STR_EMPTY (name))
952 data.information = information;
956 view = GTK_TREE_VIEW (information->treeview_groups);
957 model = gtk_tree_view_get_model (view);
959 gtk_tree_model_foreach (model,
960 (GtkTreeModelForeachFunc) contact_widget_model_find_name_foreach,
963 if (data.found == TRUE)
965 *iter = data.found_iter;
973 contact_widget_model_find_name_foreach (GtkTreeModel *model,
980 gtk_tree_model_get (model, iter,
987 if (data->name && strcmp (data->name, name) == 0)
990 data->found_iter = *iter;
1003 contact_widget_cell_toggled (GtkCellRendererToggle *cell,
1005 EmpathyContactWidget *information)
1008 GtkTreeModel *model;
1009 GtkListStore *store;
1015 view = GTK_TREE_VIEW (information->treeview_groups);
1016 model = gtk_tree_view_get_model (view);
1017 store = GTK_LIST_STORE (model);
1019 path = gtk_tree_path_new_from_string (path_string);
1021 gtk_tree_model_get_iter (model, &iter, path);
1022 gtk_tree_model_get (model, &iter,
1023 COL_ENABLED, &enabled,
1027 gtk_list_store_set (store, &iter, COL_ENABLED, !enabled, -1);
1028 gtk_tree_path_free (path);
1034 empathy_contact_list_remove_from_group (
1035 EMPATHY_CONTACT_LIST (information->manager), information->contact,
1040 empathy_contact_list_add_to_group (
1041 EMPATHY_CONTACT_LIST (information->manager), information->contact,
1049 contact_widget_entry_group_changed_cb (GtkEditable *editable,
1050 EmpathyContactWidget *information)
1055 group = gtk_entry_get_text (GTK_ENTRY (information->entry_group));
1057 if (contact_widget_model_find_name (information, group, &iter))
1058 gtk_widget_set_sensitive (GTK_WIDGET (information->button_group), FALSE);
1060 gtk_widget_set_sensitive (GTK_WIDGET (information->button_group),
1061 !G_STR_EMPTY (group));
1065 contact_widget_entry_group_activate_cb (GtkEntry *entry,
1066 EmpathyContactWidget *information)
1068 gtk_widget_activate (GTK_WIDGET (information->button_group));
1072 contact_widget_button_group_clicked_cb (GtkButton *button,
1073 EmpathyContactWidget *information)
1076 GtkListStore *store;
1080 view = GTK_TREE_VIEW (information->treeview_groups);
1081 store = GTK_LIST_STORE (gtk_tree_view_get_model (view));
1083 group = gtk_entry_get_text (GTK_ENTRY (information->entry_group));
1085 gtk_list_store_append (store, &iter);
1086 gtk_list_store_set (store, &iter,
1091 empathy_contact_list_add_to_group (
1092 EMPATHY_CONTACT_LIST (information->manager), information->contact,
1097 contact_widget_details_setup (EmpathyContactWidget *information)
1099 /* FIXME: Needs new telepathy spec */
1100 gtk_widget_hide (information->vbox_details);
1104 contact_widget_details_update (EmpathyContactWidget *information)
1106 /* FIXME: Needs new telepathy spec */
1110 contact_widget_client_setup (EmpathyContactWidget *information)
1112 /* FIXME: Needs new telepathy spec */
1113 gtk_widget_hide (information->vbox_client);
1117 contact_widget_client_update (EmpathyContactWidget *information)
1119 /* FIXME: Needs new telepathy spec */