1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
3 * Copyright (C) 2007-2009 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-tp-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>
48 * SECTION:empathy-contact-widget
49 * @title:EmpathyContactWidget
50 * @short_description: A widget used to display and edit details about a contact
51 * @include: libempathy-empathy-contact-widget.h
53 * #EmpathyContactWidget is a widget which displays appropriate widgets
54 * with details about a contact, also allowing changing these details,
59 * EmpathyContactWidget:
60 * @parent: parent object
62 * Widget which displays appropriate widgets with details about a contact,
63 * also allowing changing these details, if desired.
66 /* Delay before updating the widget when the id entry changed (seconds) */
67 #define ID_CHANGED_TIMEOUT 1
71 EmpathyTpContactFactory *factory;
72 EmpathyContactManager *manager;
73 EmpathyContact *contact;
74 EmpathyContactWidgetFlags flags;
75 guint widget_id_timeout;
77 GtkWidget *vbox_contact_widget;
80 GtkWidget *vbox_contact;
81 GtkWidget *widget_avatar;
82 GtkWidget *widget_account;
84 GtkWidget *widget_alias;
85 GtkWidget *label_alias;
86 GtkWidget *entry_alias;
87 GtkWidget *hbox_presence;
88 GtkWidget *image_state;
89 GtkWidget *label_status;
90 GtkWidget *table_contact;
91 GtkWidget *vbox_avatar;
94 GtkWidget *vbox_groups;
95 GtkWidget *entry_group;
96 GtkWidget *button_group;
97 GtkWidget *treeview_groups;
100 GtkWidget *vbox_details;
101 GtkWidget *table_details;
102 GtkWidget *hbox_details_requested;
105 GtkWidget *vbox_client;
106 GtkWidget *table_client;
107 GtkWidget *hbox_client_requested;
108 } EmpathyContactWidget;
112 EmpathyContactWidget *information;
115 GtkTreeIter found_iter;
118 static void contact_widget_destroy_cb (GtkWidget *widget,
119 EmpathyContactWidget *information);
120 static void contact_widget_remove_contact (EmpathyContactWidget *information);
121 static void contact_widget_set_contact (EmpathyContactWidget *information,
122 EmpathyContact *contact);
123 static void contact_widget_contact_setup (EmpathyContactWidget *information);
124 static void contact_widget_contact_update (EmpathyContactWidget *information);
125 static void contact_widget_change_contact (EmpathyContactWidget *information);
126 static void contact_widget_avatar_changed_cb (EmpathyAvatarChooser *chooser,
127 EmpathyContactWidget *information);
128 static gboolean contact_widget_id_focus_out_cb (GtkWidget *widget,
129 GdkEventFocus *event, EmpathyContactWidget *information);
130 static gboolean contact_widget_entry_alias_focus_event_cb (
131 GtkEditable *editable, GdkEventFocus *event,
132 EmpathyContactWidget *information);
133 static void contact_widget_name_notify_cb (EmpathyContactWidget *information);
134 static void contact_widget_presence_notify_cb (
135 EmpathyContactWidget *information);
136 static void contact_widget_avatar_notify_cb (
137 EmpathyContactWidget *information);
138 static void contact_widget_groups_setup (
139 EmpathyContactWidget *information);
140 static void contact_widget_groups_update (EmpathyContactWidget *information);
141 static void contact_widget_model_setup (EmpathyContactWidget *information);
142 static void contact_widget_model_populate_columns (
143 EmpathyContactWidget *information);
144 static void contact_widget_groups_populate_data (
145 EmpathyContactWidget *information);
146 static void contact_widget_groups_notify_cb (
147 EmpathyContactWidget *information);
148 static gboolean contact_widget_model_find_name (
149 EmpathyContactWidget *information,const gchar *name, GtkTreeIter *iter);
150 static gboolean contact_widget_model_find_name_foreach (GtkTreeModel *model,
151 GtkTreePath *path, GtkTreeIter *iter, FindName *data);
152 static void contact_widget_cell_toggled (GtkCellRendererToggle *cell,
153 gchar *path_string, EmpathyContactWidget *information);
154 static void contact_widget_entry_group_changed_cb (GtkEditable *editable,
155 EmpathyContactWidget *information);
156 static void contact_widget_entry_group_activate_cb (GtkEntry *entry,
157 EmpathyContactWidget *information);
158 static void contact_widget_button_group_clicked_cb (GtkButton *button,
159 EmpathyContactWidget *information);
160 static void contact_widget_details_setup (EmpathyContactWidget *information);
161 static void contact_widget_details_update (EmpathyContactWidget *information);
162 static void contact_widget_client_setup (EmpathyContactWidget *information);
163 static void contact_widget_client_update (EmpathyContactWidget *information);
174 * empathy_contact_widget_new:
175 * @contact: an #EmpathyContact
176 * @flags: #EmpathyContactWidgetFlags for the new contact widget
178 * Creates a new #EmpathyContactWidget.
180 * Return value: a new #EmpathyContactWidget
183 empathy_contact_widget_new (EmpathyContact *contact,
184 EmpathyContactWidgetFlags flags)
186 EmpathyContactWidget *information;
190 g_return_val_if_fail (contact == NULL || EMPATHY_IS_CONTACT (contact), NULL);
192 information = g_slice_new0 (EmpathyContactWidget);
193 information->flags = flags;
195 filename = empathy_file_lookup ("empathy-contact-widget.ui",
197 gui = empathy_builder_get_file (filename,
198 "vbox_contact_widget", &information->vbox_contact_widget,
199 "vbox_contact", &information->vbox_contact,
200 "hbox_presence", &information->hbox_presence,
201 "label_alias", &information->label_alias,
202 "image_state", &information->image_state,
203 "label_status", &information->label_status,
204 "table_contact", &information->table_contact,
205 "vbox_avatar", &information->vbox_avatar,
206 "vbox_groups", &information->vbox_groups,
207 "entry_group", &information->entry_group,
208 "button_group", &information->button_group,
209 "treeview_groups", &information->treeview_groups,
210 "vbox_details", &information->vbox_details,
211 "table_details", &information->table_details,
212 "hbox_details_requested", &information->hbox_details_requested,
213 "vbox_client", &information->vbox_client,
214 "table_client", &information->table_client,
215 "hbox_client_requested", &information->hbox_client_requested,
219 empathy_builder_connect (gui, information,
220 "vbox_contact_widget", "destroy", contact_widget_destroy_cb,
221 "entry_group", "changed", contact_widget_entry_group_changed_cb,
222 "entry_group", "activate", contact_widget_entry_group_activate_cb,
223 "button_group", "clicked", contact_widget_button_group_clicked_cb,
226 g_object_set_data (G_OBJECT (information->vbox_contact_widget),
227 "EmpathyContactWidget",
231 contact_widget_contact_setup (information);
232 contact_widget_groups_setup (information);
233 contact_widget_details_setup (information);
234 contact_widget_client_setup (information);
237 contact_widget_set_contact (information, contact);
239 return empathy_builder_unref_and_keep_widget (gui,
240 information->vbox_contact_widget);
244 * empathy_contact_widget_get_contact:
245 * @widget: an #EmpathyContactWidget
247 * Get the #EmpathyContact related with the #EmpathyContactWidget @widget.
249 * Returns: the #EmpathyContact associated with @widget
252 empathy_contact_widget_get_contact (GtkWidget *widget)
254 EmpathyContactWidget *information;
256 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
258 information = g_object_get_data (G_OBJECT (widget), "EmpathyContactWidget");
262 return information->contact;
266 * empathy_contact_widget_set_contact:
267 * @widget: an #EmpathyContactWidget
268 * @contact: a different #EmpathyContact
270 * Change the #EmpathyContact related with the #EmpathyContactWidget @widget.
273 empathy_contact_widget_set_contact (GtkWidget *widget,
274 EmpathyContact *contact)
276 EmpathyContactWidget *information;
278 g_return_if_fail (GTK_IS_WIDGET (widget));
279 g_return_if_fail (EMPATHY_IS_CONTACT (contact));
281 information = g_object_get_data (G_OBJECT (widget), "EmpathyContactWidget");
285 contact_widget_set_contact (information, contact);
289 * empathy_contact_widget_set_account_filter:
290 * @widget: an #EmpathyContactWidget
291 * @filter: a #EmpathyAccountChooserFilterFunc
292 * @user_data: user data to pass to @filter, or %NULL
294 * Set a filter on the #EmpathyAccountChooser included in the
295 * #EmpathyContactWidget.
298 empathy_contact_widget_set_account_filter (
300 EmpathyAccountChooserFilterFunc filter,
303 EmpathyContactWidget *information;
304 EmpathyAccountChooser *chooser;
306 g_return_if_fail (GTK_IS_WIDGET (widget));
308 information = g_object_get_data (G_OBJECT (widget), "EmpathyContactWidget");
312 chooser = EMPATHY_ACCOUNT_CHOOSER (information->widget_account);
314 empathy_account_chooser_set_filter (chooser, filter, user_data);
318 contact_widget_destroy_cb (GtkWidget *widget,
319 EmpathyContactWidget *information)
321 contact_widget_remove_contact (information);
323 if (information->widget_id_timeout != 0)
325 g_source_remove (information->widget_id_timeout);
327 if (information->manager)
329 g_object_unref (information->manager);
332 g_slice_free (EmpathyContactWidget, information);
336 contact_widget_remove_contact (EmpathyContactWidget *information)
338 if (information->contact)
340 g_signal_handlers_disconnect_by_func (information->contact,
341 contact_widget_name_notify_cb, information);
342 g_signal_handlers_disconnect_by_func (information->contact,
343 contact_widget_presence_notify_cb, information);
344 g_signal_handlers_disconnect_by_func (information->contact,
345 contact_widget_avatar_notify_cb, information);
346 g_signal_handlers_disconnect_by_func (information->contact,
347 contact_widget_groups_notify_cb, information);
349 g_object_unref (information->contact);
350 g_object_unref (information->factory);
351 information->contact = NULL;
352 information->factory = NULL;
357 contact_widget_set_contact (EmpathyContactWidget *information,
358 EmpathyContact *contact)
360 if (contact == information->contact)
363 contact_widget_remove_contact (information);
366 TpConnection *connection;
368 connection = empathy_contact_get_connection (contact);
369 information->contact = g_object_ref (contact);
370 information->factory = empathy_tp_contact_factory_dup_singleton (connection);
373 /* Update information for widgets */
374 contact_widget_contact_update (information);
375 contact_widget_groups_update (information);
376 contact_widget_details_update (information);
377 contact_widget_client_update (information);
381 contact_widget_id_activate_timeout (EmpathyContactWidget *self)
383 contact_widget_change_contact (self);
388 contact_widget_id_changed_cb (GtkEntry *entry,
389 EmpathyContactWidget *self)
391 if (self->widget_id_timeout != 0)
393 g_source_remove (self->widget_id_timeout);
396 self->widget_id_timeout =
397 g_timeout_add_seconds (ID_CHANGED_TIMEOUT,
398 (GSourceFunc) contact_widget_id_activate_timeout, self);
402 save_avatar_menu_activate_cb (GtkWidget *widget,
403 EmpathyContactWidget *information)
406 EmpathyAvatar *avatar;
407 gchar *ext = NULL, *filename;
409 dialog = gtk_file_chooser_dialog_new (_("Save Avatar"),
411 GTK_FILE_CHOOSER_ACTION_SAVE,
412 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
413 GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT,
416 gtk_file_chooser_set_do_overwrite_confirmation (GTK_FILE_CHOOSER (dialog),
419 /* look for the avatar extension */
420 avatar = empathy_contact_get_avatar (information->contact);
421 if (avatar->format != NULL)
425 splitted = g_strsplit (avatar->format, "/", 2);
426 if (splitted[0] != NULL && splitted[1] != NULL)
427 ext = g_strdup (splitted[1]);
429 g_strfreev (splitted);
433 /* Avatar was loaded from the cache so was converted to PNG */
434 ext = g_strdup ("png");
441 id = tp_escape_as_identifier (empathy_contact_get_id (
442 information->contact));
444 filename = g_strdup_printf ("%s.%s", id, ext);
445 gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (dialog), filename);
452 if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT)
454 GError *error = NULL;
456 filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
458 if (!empathy_avatar_save_to_file (avatar, filename, &error))
463 dialog = gtk_message_dialog_new (NULL, 0,
464 GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE,
465 _("Unable to save avatar"));
467 gtk_message_dialog_format_secondary_text (
468 GTK_MESSAGE_DIALOG (dialog), "%s", error->message);
470 g_signal_connect (dialog, "response",
471 G_CALLBACK (gtk_widget_destroy), NULL);
473 gtk_window_present (GTK_WINDOW (dialog));
475 g_clear_error (&error);
481 gtk_widget_destroy (dialog);
485 popup_avatar_menu (EmpathyContactWidget *information,
487 GdkEventButton *event)
489 GtkWidget *menu, *item;
490 gint button, event_time;
492 if (information->contact == NULL ||
493 empathy_contact_get_avatar (information->contact) == NULL)
496 menu = gtk_menu_new ();
498 /* Add "Save as..." entry */
499 item = gtk_image_menu_item_new_from_stock (GTK_STOCK_SAVE_AS, NULL);
500 gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
501 gtk_widget_show (item);
503 g_signal_connect (item, "activate",
504 G_CALLBACK (save_avatar_menu_activate_cb), information);
508 button = event->button;
509 event_time = event->time;
514 event_time = gtk_get_current_event_time ();
517 gtk_menu_attach_to_widget (GTK_MENU (menu), parent, NULL);
518 gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
523 widget_avatar_popup_menu_cb (GtkWidget *widget,
524 EmpathyContactWidget *information)
526 popup_avatar_menu (information, widget, NULL);
532 widget_avatar_button_press_event_cb (GtkWidget *widget,
533 GdkEventButton *event,
534 EmpathyContactWidget *information)
536 /* Ignore double-clicks and triple-clicks */
537 if (event->button == 3 && event->type == GDK_BUTTON_PRESS)
539 popup_avatar_menu (information, widget, event);
547 update_avatar_chooser_account_cb (EmpathyAccountChooser *account_chooser,
548 EmpathyAvatarChooser *avatar_chooser)
550 TpConnection *connection;
552 connection = empathy_account_chooser_get_connection (account_chooser);
553 g_object_set (avatar_chooser, "connection", connection, NULL);
557 contact_widget_contact_setup (EmpathyContactWidget *information)
559 /* Setup account label/chooser */
560 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ACCOUNT)
562 information->widget_account = empathy_account_chooser_new ();
564 contact_widget_change_contact (information);
565 g_signal_connect_swapped (information->widget_account, "changed",
566 G_CALLBACK (contact_widget_change_contact),
571 information->widget_account = gtk_label_new (NULL);
572 if (!(information->flags & EMPATHY_CONTACT_WIDGET_FOR_TOOLTIP)) {
573 gtk_label_set_selectable (GTK_LABEL (information->widget_account), TRUE);
575 gtk_misc_set_alignment (GTK_MISC (information->widget_account), 0, 0.5);
577 gtk_table_attach_defaults (GTK_TABLE (information->table_contact),
578 information->widget_account,
580 gtk_widget_show (information->widget_account);
582 /* Set up avatar chooser/display */
583 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_AVATAR)
585 information->widget_avatar = empathy_avatar_chooser_new ();
586 g_signal_connect (information->widget_avatar, "changed",
587 G_CALLBACK (contact_widget_avatar_changed_cb),
589 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ACCOUNT)
591 g_signal_connect (information->widget_account, "changed",
592 G_CALLBACK (update_avatar_chooser_account_cb),
593 information->widget_avatar);
594 update_avatar_chooser_account_cb (
595 EMPATHY_ACCOUNT_CHOOSER (information->widget_account),
596 EMPATHY_AVATAR_CHOOSER (information->widget_avatar));
601 information->widget_avatar = empathy_avatar_image_new ();
603 g_signal_connect (information->widget_avatar, "popup-menu",
604 G_CALLBACK (widget_avatar_popup_menu_cb), information);
605 g_signal_connect (information->widget_avatar, "button-press-event",
606 G_CALLBACK (widget_avatar_button_press_event_cb), information);
609 gtk_box_pack_start (GTK_BOX (information->vbox_avatar),
610 information->widget_avatar,
613 gtk_widget_show (information->widget_avatar);
615 /* Setup id label/entry */
616 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ID)
618 information->widget_id = gtk_entry_new ();
619 g_signal_connect (information->widget_id, "focus-out-event",
620 G_CALLBACK (contact_widget_id_focus_out_cb),
622 g_signal_connect (information->widget_id, "changed",
623 G_CALLBACK (contact_widget_id_changed_cb),
628 information->widget_id = gtk_label_new (NULL);
629 if (!(information->flags & EMPATHY_CONTACT_WIDGET_FOR_TOOLTIP)) {
630 gtk_label_set_selectable (GTK_LABEL (information->widget_id), TRUE);
632 gtk_misc_set_alignment (GTK_MISC (information->widget_id), 0, 0.5);
634 gtk_table_attach_defaults (GTK_TABLE (information->table_contact),
635 information->widget_id,
637 gtk_widget_show (information->widget_id);
639 /* Setup alias label/entry */
640 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ALIAS)
642 information->widget_alias = gtk_entry_new ();
643 g_signal_connect (information->widget_alias, "focus-out-event",
644 G_CALLBACK (contact_widget_entry_alias_focus_event_cb),
646 /* Make return activate the window default (the Close button) */
647 gtk_entry_set_activates_default (GTK_ENTRY (information->widget_alias),
652 information->widget_alias = gtk_label_new (NULL);
653 if (!(information->flags & EMPATHY_CONTACT_WIDGET_FOR_TOOLTIP)) {
654 gtk_label_set_selectable (GTK_LABEL (information->widget_alias), TRUE);
656 gtk_misc_set_alignment (GTK_MISC (information->widget_alias), 0, 0.5);
658 gtk_table_attach_defaults (GTK_TABLE (information->table_contact),
659 information->widget_alias,
661 if (information->flags & EMPATHY_CONTACT_WIDGET_FOR_TOOLTIP) {
662 gtk_label_set_selectable (GTK_LABEL (information->label_status), FALSE);
664 gtk_widget_show (information->widget_alias);
668 contact_widget_contact_update (EmpathyContactWidget *information)
670 McAccount *account = NULL;
671 const gchar *id = NULL;
673 /* Connect and get info from new contact */
674 if (information->contact)
676 g_signal_connect_swapped (information->contact, "notify::name",
677 G_CALLBACK (contact_widget_name_notify_cb), information);
678 g_signal_connect_swapped (information->contact, "notify::presence",
679 G_CALLBACK (contact_widget_presence_notify_cb), information);
680 g_signal_connect_swapped (information->contact,
681 "notify::presence-message",
682 G_CALLBACK (contact_widget_presence_notify_cb), information);
683 g_signal_connect_swapped (information->contact, "notify::avatar",
684 G_CALLBACK (contact_widget_avatar_notify_cb), information);
686 account = empathy_contact_get_account (information->contact);
687 id = empathy_contact_get_id (information->contact);
690 /* Update account widget */
691 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ACCOUNT)
695 g_signal_handlers_block_by_func (information->widget_account,
696 contact_widget_change_contact,
698 empathy_account_chooser_set_account (
699 EMPATHY_ACCOUNT_CHOOSER (information->widget_account), account);
700 g_signal_handlers_unblock_by_func (information->widget_account,
701 contact_widget_change_contact, information);
710 name = mc_account_get_display_name (account);
711 gtk_label_set_label (GTK_LABEL (information->widget_account), name);
715 /* Update id widget */
716 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ID)
717 gtk_entry_set_text (GTK_ENTRY (information->widget_id), id ? id : "");
719 gtk_label_set_label (GTK_LABEL (information->widget_id), id ? id : "");
721 /* Update other widgets */
722 if (information->contact)
724 contact_widget_name_notify_cb (information);
725 contact_widget_presence_notify_cb (information);
726 contact_widget_avatar_notify_cb (information);
728 gtk_widget_show (information->label_alias);
729 gtk_widget_show (information->widget_alias);
730 gtk_widget_show (information->hbox_presence);
731 gtk_widget_show (information->widget_avatar);
735 gtk_widget_hide (information->label_alias);
736 gtk_widget_hide (information->widget_alias);
737 gtk_widget_hide (information->hbox_presence);
738 gtk_widget_hide (information->widget_avatar);
743 contact_widget_got_contact_cb (EmpathyTpContactFactory *factory,
744 EmpathyContact *contact,
747 GObject *weak_object)
749 EmpathyContactWidget *information = user_data;
753 DEBUG ("Error: %s", error->message);
757 contact_widget_set_contact (information, contact);
761 contact_widget_change_contact (EmpathyContactWidget *information)
763 EmpathyTpContactFactory *factory;
764 TpConnection *connection;
766 connection = empathy_account_chooser_get_connection (
767 EMPATHY_ACCOUNT_CHOOSER (information->widget_account));
771 factory = empathy_tp_contact_factory_dup_singleton (connection);
772 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ID)
776 id = gtk_entry_get_text (GTK_ENTRY (information->widget_id));
777 if (!EMP_STR_EMPTY (id))
779 empathy_tp_contact_factory_get_from_id (factory, id,
780 contact_widget_got_contact_cb, information, NULL,
781 G_OBJECT (information->vbox_contact_widget));
786 empathy_tp_contact_factory_get_from_handle (factory,
787 tp_connection_get_self_handle (connection),
788 contact_widget_got_contact_cb, information, NULL,
789 G_OBJECT (information->vbox_contact_widget));
792 g_object_unref (factory);
796 contact_widget_avatar_changed_cb (EmpathyAvatarChooser *chooser,
797 EmpathyContactWidget *information)
801 const gchar *mime_type;
803 empathy_avatar_chooser_get_image_data (
804 EMPATHY_AVATAR_CHOOSER (information->widget_avatar),
805 &data, &size, &mime_type);
806 empathy_tp_contact_factory_set_avatar (information->factory,
807 data, size, mime_type);
811 contact_widget_id_focus_out_cb (GtkWidget *widget,
812 GdkEventFocus *event,
813 EmpathyContactWidget *information)
815 contact_widget_change_contact (information);
820 contact_widget_entry_alias_focus_event_cb (GtkEditable *editable,
821 GdkEventFocus *event,
822 EmpathyContactWidget *information)
824 if (information->contact)
828 alias = gtk_entry_get_text (GTK_ENTRY (editable));
829 empathy_tp_contact_factory_set_alias (information->factory,
830 information->contact, alias);
837 contact_widget_name_notify_cb (EmpathyContactWidget *information)
839 if (GTK_IS_ENTRY (information->widget_alias))
840 gtk_entry_set_text (GTK_ENTRY (information->widget_alias),
841 empathy_contact_get_name (information->contact));
843 gtk_label_set_label (GTK_LABEL (information->widget_alias),
844 empathy_contact_get_name (information->contact));
848 contact_widget_presence_notify_cb (EmpathyContactWidget *information)
850 gtk_label_set_text (GTK_LABEL (information->label_status),
851 empathy_contact_get_status (information->contact));
852 gtk_image_set_from_icon_name (GTK_IMAGE (information->image_state),
853 empathy_icon_name_for_contact (information->contact),
854 GTK_ICON_SIZE_BUTTON);
858 contact_widget_avatar_notify_cb (EmpathyContactWidget *information)
860 EmpathyAvatar *avatar = NULL;
862 if (information->contact)
863 avatar = empathy_contact_get_avatar (information->contact);
865 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_AVATAR)
867 g_signal_handlers_block_by_func (information->widget_avatar,
868 contact_widget_avatar_changed_cb,
870 empathy_avatar_chooser_set (
871 EMPATHY_AVATAR_CHOOSER (information->widget_avatar), avatar);
872 g_signal_handlers_unblock_by_func (information->widget_avatar,
873 contact_widget_avatar_changed_cb, information);
876 empathy_avatar_image_set (
877 EMPATHY_AVATAR_IMAGE (information->widget_avatar), avatar);
881 contact_widget_groups_setup (EmpathyContactWidget *information)
883 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_GROUPS)
885 information->manager = empathy_contact_manager_dup_singleton ();
886 contact_widget_model_setup (information);
891 contact_widget_groups_update (EmpathyContactWidget *information)
893 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_GROUPS &&
894 information->contact)
896 g_signal_connect_swapped (information->contact, "notify::groups",
897 G_CALLBACK (contact_widget_groups_notify_cb), information);
898 contact_widget_groups_populate_data (information);
900 gtk_widget_show (information->vbox_groups);
903 gtk_widget_hide (information->vbox_groups);
907 contact_widget_model_setup (EmpathyContactWidget *information)
911 GtkTreeSelection *selection;
913 view = GTK_TREE_VIEW (information->treeview_groups);
915 store = gtk_list_store_new (COL_COUNT,
916 G_TYPE_STRING, /* name */
917 G_TYPE_BOOLEAN, /* enabled */
918 G_TYPE_BOOLEAN); /* editable */
920 gtk_tree_view_set_model (view, GTK_TREE_MODEL (store));
922 selection = gtk_tree_view_get_selection (view);
923 gtk_tree_selection_set_mode (selection, GTK_SELECTION_SINGLE);
925 contact_widget_model_populate_columns (information);
927 gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (store),
928 COL_NAME, GTK_SORT_ASCENDING);
930 g_object_unref (store);
934 contact_widget_model_populate_columns (EmpathyContactWidget *information)
938 GtkTreeViewColumn *column;
939 GtkCellRenderer *renderer;
942 view = GTK_TREE_VIEW (information->treeview_groups);
943 model = gtk_tree_view_get_model (view);
945 renderer = gtk_cell_renderer_toggle_new ();
946 g_signal_connect (renderer, "toggled",
947 G_CALLBACK (contact_widget_cell_toggled), information);
949 column = gtk_tree_view_column_new_with_attributes (_("Select"), renderer,
950 "active", COL_ENABLED, NULL);
952 gtk_tree_view_column_set_sizing (column, GTK_TREE_VIEW_COLUMN_FIXED);
953 gtk_tree_view_column_set_fixed_width (column, 50);
954 gtk_tree_view_append_column (view, column);
956 renderer = gtk_cell_renderer_text_new ();
957 col_offset = gtk_tree_view_insert_column_with_attributes (view,
961 /* "editable", COL_EDITABLE, */
964 g_object_set_data (G_OBJECT (renderer),
965 "column", GINT_TO_POINTER (COL_NAME));
967 column = gtk_tree_view_get_column (view, col_offset - 1);
968 gtk_tree_view_column_set_sort_column_id (column, COL_NAME);
969 gtk_tree_view_column_set_resizable (column,FALSE);
970 gtk_tree_view_column_set_clickable (GTK_TREE_VIEW_COLUMN (column), TRUE);
974 contact_widget_groups_populate_data (EmpathyContactWidget *information)
979 GList *my_groups, *l;
982 view = GTK_TREE_VIEW (information->treeview_groups);
983 store = GTK_LIST_STORE (gtk_tree_view_get_model (view));
984 gtk_list_store_clear (store);
986 all_groups = empathy_contact_list_get_all_groups (
987 EMPATHY_CONTACT_LIST (information->manager));
988 my_groups = empathy_contact_list_get_groups (
989 EMPATHY_CONTACT_LIST (information->manager),
990 information->contact);
992 for (l = all_groups; l; l = l->next)
994 const gchar *group_str;
999 enabled = g_list_find_custom (my_groups,
1000 group_str, (GCompareFunc) strcmp) != NULL;
1002 gtk_list_store_append (store, &iter);
1003 gtk_list_store_set (store, &iter,
1004 COL_NAME, group_str,
1006 COL_ENABLED, enabled,
1010 g_list_foreach (all_groups, (GFunc) g_free, NULL);
1011 g_list_foreach (my_groups, (GFunc) g_free, NULL);
1012 g_list_free (all_groups);
1013 g_list_free (my_groups);
1017 contact_widget_groups_notify_cb (EmpathyContactWidget *information)
1019 /* FIXME: not implemented */
1023 contact_widget_model_find_name (EmpathyContactWidget *information,
1028 GtkTreeModel *model;
1031 if (EMP_STR_EMPTY (name))
1034 data.information = information;
1038 view = GTK_TREE_VIEW (information->treeview_groups);
1039 model = gtk_tree_view_get_model (view);
1041 gtk_tree_model_foreach (model,
1042 (GtkTreeModelForeachFunc) contact_widget_model_find_name_foreach,
1045 if (data.found == TRUE)
1047 *iter = data.found_iter;
1055 contact_widget_model_find_name_foreach (GtkTreeModel *model,
1062 gtk_tree_model_get (model, iter,
1069 if (data->name && strcmp (data->name, name) == 0)
1072 data->found_iter = *iter;
1085 contact_widget_cell_toggled (GtkCellRendererToggle *cell,
1087 EmpathyContactWidget *information)
1090 GtkTreeModel *model;
1091 GtkListStore *store;
1097 view = GTK_TREE_VIEW (information->treeview_groups);
1098 model = gtk_tree_view_get_model (view);
1099 store = GTK_LIST_STORE (model);
1101 path = gtk_tree_path_new_from_string (path_string);
1103 gtk_tree_model_get_iter (model, &iter, path);
1104 gtk_tree_model_get (model, &iter,
1105 COL_ENABLED, &enabled,
1109 gtk_list_store_set (store, &iter, COL_ENABLED, !enabled, -1);
1110 gtk_tree_path_free (path);
1116 empathy_contact_list_remove_from_group (
1117 EMPATHY_CONTACT_LIST (information->manager), information->contact,
1122 empathy_contact_list_add_to_group (
1123 EMPATHY_CONTACT_LIST (information->manager), information->contact,
1131 contact_widget_entry_group_changed_cb (GtkEditable *editable,
1132 EmpathyContactWidget *information)
1137 group = gtk_entry_get_text (GTK_ENTRY (information->entry_group));
1139 if (contact_widget_model_find_name (information, group, &iter))
1140 gtk_widget_set_sensitive (GTK_WIDGET (information->button_group), FALSE);
1142 gtk_widget_set_sensitive (GTK_WIDGET (information->button_group),
1143 !EMP_STR_EMPTY (group));
1147 contact_widget_entry_group_activate_cb (GtkEntry *entry,
1148 EmpathyContactWidget *information)
1150 gtk_widget_activate (GTK_WIDGET (information->button_group));
1154 contact_widget_button_group_clicked_cb (GtkButton *button,
1155 EmpathyContactWidget *information)
1158 GtkListStore *store;
1162 view = GTK_TREE_VIEW (information->treeview_groups);
1163 store = GTK_LIST_STORE (gtk_tree_view_get_model (view));
1165 group = gtk_entry_get_text (GTK_ENTRY (information->entry_group));
1167 gtk_list_store_append (store, &iter);
1168 gtk_list_store_set (store, &iter,
1173 empathy_contact_list_add_to_group (
1174 EMPATHY_CONTACT_LIST (information->manager), information->contact,
1179 contact_widget_details_setup (EmpathyContactWidget *information)
1181 /* FIXME: Needs new telepathy spec */
1182 gtk_widget_hide (information->vbox_details);
1186 contact_widget_details_update (EmpathyContactWidget *information)
1188 /* FIXME: Needs new telepathy spec */
1192 contact_widget_client_setup (EmpathyContactWidget *information)
1194 /* FIXME: Needs new telepathy spec */
1195 gtk_widget_hide (information->vbox_client);
1199 contact_widget_client_update (EmpathyContactWidget *information)
1201 /* FIXME: Needs new telepathy spec */