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 else if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ACCOUNT ||
240 information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ID)
241 contact_widget_change_contact (information);
243 return empathy_builder_unref_and_keep_widget (gui,
244 information->vbox_contact_widget);
248 * empathy_contact_widget_get_contact:
249 * @widget: an #EmpathyContactWidget
251 * Get the #EmpathyContact related with the #EmpathyContactWidget @widget.
253 * Returns: the #EmpathyContact associated with @widget
256 empathy_contact_widget_get_contact (GtkWidget *widget)
258 EmpathyContactWidget *information;
260 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
262 information = g_object_get_data (G_OBJECT (widget), "EmpathyContactWidget");
266 return information->contact;
270 * empathy_contact_widget_set_contact:
271 * @widget: an #EmpathyContactWidget
272 * @contact: a different #EmpathyContact
274 * Change the #EmpathyContact related with the #EmpathyContactWidget @widget.
277 empathy_contact_widget_set_contact (GtkWidget *widget,
278 EmpathyContact *contact)
280 EmpathyContactWidget *information;
282 g_return_if_fail (GTK_IS_WIDGET (widget));
283 g_return_if_fail (EMPATHY_IS_CONTACT (contact));
285 information = g_object_get_data (G_OBJECT (widget), "EmpathyContactWidget");
289 contact_widget_set_contact (information, contact);
293 * empathy_contact_widget_set_account_filter:
294 * @widget: an #EmpathyContactWidget
295 * @filter: a #EmpathyAccountChooserFilterFunc
296 * @user_data: user data to pass to @filter, or %NULL
298 * Set a filter on the #EmpathyAccountChooser included in the
299 * #EmpathyContactWidget.
302 empathy_contact_widget_set_account_filter (
304 EmpathyAccountChooserFilterFunc filter,
307 EmpathyContactWidget *information;
308 EmpathyAccountChooser *chooser;
310 g_return_if_fail (GTK_IS_WIDGET (widget));
312 information = g_object_get_data (G_OBJECT (widget), "EmpathyContactWidget");
316 chooser = EMPATHY_ACCOUNT_CHOOSER (information->widget_account);
318 empathy_account_chooser_set_filter (chooser, filter, user_data);
322 contact_widget_destroy_cb (GtkWidget *widget,
323 EmpathyContactWidget *information)
325 contact_widget_remove_contact (information);
327 if (information->widget_id_timeout != 0)
329 g_source_remove (information->widget_id_timeout);
331 if (information->manager)
333 g_object_unref (information->manager);
336 g_slice_free (EmpathyContactWidget, information);
340 contact_widget_remove_contact (EmpathyContactWidget *information)
342 if (information->contact)
344 g_signal_handlers_disconnect_by_func (information->contact,
345 contact_widget_name_notify_cb, information);
346 g_signal_handlers_disconnect_by_func (information->contact,
347 contact_widget_presence_notify_cb, information);
348 g_signal_handlers_disconnect_by_func (information->contact,
349 contact_widget_avatar_notify_cb, information);
350 g_signal_handlers_disconnect_by_func (information->contact,
351 contact_widget_groups_notify_cb, information);
353 g_object_unref (information->contact);
354 g_object_unref (information->factory);
355 information->contact = NULL;
356 information->factory = NULL;
361 contact_widget_set_contact (EmpathyContactWidget *information,
362 EmpathyContact *contact)
364 if (contact == information->contact)
367 contact_widget_remove_contact (information);
370 TpConnection *connection;
372 connection = empathy_contact_get_connection (contact);
373 information->contact = g_object_ref (contact);
374 information->factory = empathy_tp_contact_factory_dup_singleton (connection);
377 /* Update information for widgets */
378 contact_widget_contact_update (information);
379 contact_widget_groups_update (information);
380 contact_widget_details_update (information);
381 contact_widget_client_update (information);
385 contact_widget_id_activate_timeout (EmpathyContactWidget *self)
387 contact_widget_change_contact (self);
392 contact_widget_id_changed_cb (GtkEntry *entry,
393 EmpathyContactWidget *self)
395 if (self->widget_id_timeout != 0)
397 g_source_remove (self->widget_id_timeout);
400 self->widget_id_timeout =
401 g_timeout_add_seconds (ID_CHANGED_TIMEOUT,
402 (GSourceFunc) contact_widget_id_activate_timeout, self);
406 save_avatar_menu_activate_cb (GtkWidget *widget,
407 EmpathyContactWidget *information)
410 EmpathyAvatar *avatar;
411 gchar *ext = NULL, *filename;
413 dialog = gtk_file_chooser_dialog_new (_("Save Avatar"),
415 GTK_FILE_CHOOSER_ACTION_SAVE,
416 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
417 GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT,
420 gtk_file_chooser_set_do_overwrite_confirmation (GTK_FILE_CHOOSER (dialog),
423 /* look for the avatar extension */
424 avatar = empathy_contact_get_avatar (information->contact);
425 if (avatar->format != NULL)
429 splitted = g_strsplit (avatar->format, "/", 2);
430 if (splitted[0] != NULL && splitted[1] != NULL)
431 ext = g_strdup (splitted[1]);
433 g_strfreev (splitted);
437 /* Avatar was loaded from the cache so was converted to PNG */
438 ext = g_strdup ("png");
445 id = tp_escape_as_identifier (empathy_contact_get_id (
446 information->contact));
448 filename = g_strdup_printf ("%s.%s", id, ext);
449 gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (dialog), filename);
456 if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT)
458 GError *error = NULL;
460 filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
462 if (!empathy_avatar_save_to_file (avatar, filename, &error))
467 dialog = gtk_message_dialog_new (NULL, 0,
468 GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE,
469 _("Unable to save avatar"));
471 gtk_message_dialog_format_secondary_text (
472 GTK_MESSAGE_DIALOG (dialog), "%s", error->message);
474 g_signal_connect (dialog, "response",
475 G_CALLBACK (gtk_widget_destroy), NULL);
477 gtk_window_present (GTK_WINDOW (dialog));
479 g_clear_error (&error);
485 gtk_widget_destroy (dialog);
489 popup_avatar_menu (EmpathyContactWidget *information,
491 GdkEventButton *event)
493 GtkWidget *menu, *item;
494 gint button, event_time;
496 if (information->contact == NULL ||
497 empathy_contact_get_avatar (information->contact) == NULL)
500 menu = gtk_menu_new ();
502 /* Add "Save as..." entry */
503 item = gtk_image_menu_item_new_from_stock (GTK_STOCK_SAVE_AS, NULL);
504 gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
505 gtk_widget_show (item);
507 g_signal_connect (item, "activate",
508 G_CALLBACK (save_avatar_menu_activate_cb), information);
512 button = event->button;
513 event_time = event->time;
518 event_time = gtk_get_current_event_time ();
521 gtk_menu_attach_to_widget (GTK_MENU (menu), parent, NULL);
522 gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
527 widget_avatar_popup_menu_cb (GtkWidget *widget,
528 EmpathyContactWidget *information)
530 popup_avatar_menu (information, widget, NULL);
536 widget_avatar_button_press_event_cb (GtkWidget *widget,
537 GdkEventButton *event,
538 EmpathyContactWidget *information)
540 /* Ignore double-clicks and triple-clicks */
541 if (event->button == 3 && event->type == GDK_BUTTON_PRESS)
543 popup_avatar_menu (information, widget, event);
551 update_avatar_chooser_account_cb (EmpathyAccountChooser *account_chooser,
552 EmpathyAvatarChooser *avatar_chooser)
554 TpConnection *connection;
556 connection = empathy_account_chooser_get_connection (account_chooser);
557 g_object_set (avatar_chooser, "connection", connection, NULL);
561 contact_widget_contact_setup (EmpathyContactWidget *information)
563 /* Setup account label/chooser */
564 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ACCOUNT)
566 information->widget_account = empathy_account_chooser_new ();
568 g_signal_connect_swapped (information->widget_account, "changed",
569 G_CALLBACK (contact_widget_change_contact),
574 information->widget_account = gtk_label_new (NULL);
575 if (!(information->flags & EMPATHY_CONTACT_WIDGET_FOR_TOOLTIP)) {
576 gtk_label_set_selectable (GTK_LABEL (information->widget_account), TRUE);
578 gtk_misc_set_alignment (GTK_MISC (information->widget_account), 0, 0.5);
580 gtk_table_attach_defaults (GTK_TABLE (information->table_contact),
581 information->widget_account,
583 gtk_widget_show (information->widget_account);
585 /* Set up avatar chooser/display */
586 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_AVATAR)
588 information->widget_avatar = empathy_avatar_chooser_new ();
589 g_signal_connect (information->widget_avatar, "changed",
590 G_CALLBACK (contact_widget_avatar_changed_cb),
592 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ACCOUNT)
594 g_signal_connect (information->widget_account, "changed",
595 G_CALLBACK (update_avatar_chooser_account_cb),
596 information->widget_avatar);
597 update_avatar_chooser_account_cb (
598 EMPATHY_ACCOUNT_CHOOSER (information->widget_account),
599 EMPATHY_AVATAR_CHOOSER (information->widget_avatar));
604 information->widget_avatar = empathy_avatar_image_new ();
606 g_signal_connect (information->widget_avatar, "popup-menu",
607 G_CALLBACK (widget_avatar_popup_menu_cb), information);
608 g_signal_connect (information->widget_avatar, "button-press-event",
609 G_CALLBACK (widget_avatar_button_press_event_cb), information);
612 gtk_box_pack_start (GTK_BOX (information->vbox_avatar),
613 information->widget_avatar,
616 gtk_widget_show (information->widget_avatar);
618 /* Setup id label/entry */
619 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ID)
621 information->widget_id = gtk_entry_new ();
622 g_signal_connect (information->widget_id, "focus-out-event",
623 G_CALLBACK (contact_widget_id_focus_out_cb),
625 g_signal_connect (information->widget_id, "changed",
626 G_CALLBACK (contact_widget_id_changed_cb),
631 information->widget_id = gtk_label_new (NULL);
632 if (!(information->flags & EMPATHY_CONTACT_WIDGET_FOR_TOOLTIP)) {
633 gtk_label_set_selectable (GTK_LABEL (information->widget_id), TRUE);
635 gtk_misc_set_alignment (GTK_MISC (information->widget_id), 0, 0.5);
637 gtk_table_attach_defaults (GTK_TABLE (information->table_contact),
638 information->widget_id,
640 gtk_widget_show (information->widget_id);
642 /* Setup alias label/entry */
643 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ALIAS)
645 information->widget_alias = gtk_entry_new ();
646 g_signal_connect (information->widget_alias, "focus-out-event",
647 G_CALLBACK (contact_widget_entry_alias_focus_event_cb),
649 /* Make return activate the window default (the Close button) */
650 gtk_entry_set_activates_default (GTK_ENTRY (information->widget_alias),
655 information->widget_alias = gtk_label_new (NULL);
656 if (!(information->flags & EMPATHY_CONTACT_WIDGET_FOR_TOOLTIP)) {
657 gtk_label_set_selectable (GTK_LABEL (information->widget_alias), TRUE);
659 gtk_misc_set_alignment (GTK_MISC (information->widget_alias), 0, 0.5);
661 gtk_table_attach_defaults (GTK_TABLE (information->table_contact),
662 information->widget_alias,
664 if (information->flags & EMPATHY_CONTACT_WIDGET_FOR_TOOLTIP) {
665 gtk_label_set_selectable (GTK_LABEL (information->label_status), FALSE);
667 gtk_widget_show (information->widget_alias);
671 contact_widget_contact_update (EmpathyContactWidget *information)
673 McAccount *account = NULL;
674 const gchar *id = NULL;
676 /* Connect and get info from new contact */
677 if (information->contact)
679 g_signal_connect_swapped (information->contact, "notify::name",
680 G_CALLBACK (contact_widget_name_notify_cb), information);
681 g_signal_connect_swapped (information->contact, "notify::presence",
682 G_CALLBACK (contact_widget_presence_notify_cb), information);
683 g_signal_connect_swapped (information->contact,
684 "notify::presence-message",
685 G_CALLBACK (contact_widget_presence_notify_cb), information);
686 g_signal_connect_swapped (information->contact, "notify::avatar",
687 G_CALLBACK (contact_widget_avatar_notify_cb), information);
689 account = empathy_contact_get_account (information->contact);
690 id = empathy_contact_get_id (information->contact);
693 /* Update account widget */
694 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ACCOUNT)
698 g_signal_handlers_block_by_func (information->widget_account,
699 contact_widget_change_contact,
701 empathy_account_chooser_set_account (
702 EMPATHY_ACCOUNT_CHOOSER (information->widget_account), account);
703 g_signal_handlers_unblock_by_func (information->widget_account,
704 contact_widget_change_contact, information);
713 name = mc_account_get_display_name (account);
714 gtk_label_set_label (GTK_LABEL (information->widget_account), name);
718 /* Update id widget */
719 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ID)
720 gtk_entry_set_text (GTK_ENTRY (information->widget_id), id ? id : "");
722 gtk_label_set_label (GTK_LABEL (information->widget_id), id ? id : "");
724 /* Update other widgets */
725 if (information->contact)
727 contact_widget_name_notify_cb (information);
728 contact_widget_presence_notify_cb (information);
729 contact_widget_avatar_notify_cb (information);
731 gtk_widget_show (information->label_alias);
732 gtk_widget_show (information->widget_alias);
733 gtk_widget_show (information->hbox_presence);
734 gtk_widget_show (information->widget_avatar);
738 gtk_widget_hide (information->label_alias);
739 gtk_widget_hide (information->widget_alias);
740 gtk_widget_hide (information->hbox_presence);
741 gtk_widget_hide (information->widget_avatar);
746 contact_widget_got_contact_cb (EmpathyTpContactFactory *factory,
747 EmpathyContact *contact,
750 GObject *weak_object)
752 EmpathyContactWidget *information = user_data;
756 DEBUG ("Error: %s", error->message);
760 contact_widget_set_contact (information, contact);
764 contact_widget_change_contact (EmpathyContactWidget *information)
766 EmpathyTpContactFactory *factory;
767 TpConnection *connection;
769 connection = empathy_account_chooser_get_connection (
770 EMPATHY_ACCOUNT_CHOOSER (information->widget_account));
774 factory = empathy_tp_contact_factory_dup_singleton (connection);
775 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ID)
779 id = gtk_entry_get_text (GTK_ENTRY (information->widget_id));
780 if (!EMP_STR_EMPTY (id))
782 empathy_tp_contact_factory_get_from_id (factory, id,
783 contact_widget_got_contact_cb, information, NULL,
784 G_OBJECT (information->vbox_contact_widget));
789 empathy_tp_contact_factory_get_from_handle (factory,
790 tp_connection_get_self_handle (connection),
791 contact_widget_got_contact_cb, information, NULL,
792 G_OBJECT (information->vbox_contact_widget));
795 g_object_unref (factory);
799 contact_widget_avatar_changed_cb (EmpathyAvatarChooser *chooser,
800 EmpathyContactWidget *information)
804 const gchar *mime_type;
806 empathy_avatar_chooser_get_image_data (
807 EMPATHY_AVATAR_CHOOSER (information->widget_avatar),
808 &data, &size, &mime_type);
809 empathy_tp_contact_factory_set_avatar (information->factory,
810 data, size, mime_type);
814 contact_widget_id_focus_out_cb (GtkWidget *widget,
815 GdkEventFocus *event,
816 EmpathyContactWidget *information)
818 contact_widget_change_contact (information);
823 contact_widget_entry_alias_focus_event_cb (GtkEditable *editable,
824 GdkEventFocus *event,
825 EmpathyContactWidget *information)
827 if (information->contact)
831 alias = gtk_entry_get_text (GTK_ENTRY (editable));
832 empathy_tp_contact_factory_set_alias (information->factory,
833 information->contact, alias);
840 contact_widget_name_notify_cb (EmpathyContactWidget *information)
842 if (GTK_IS_ENTRY (information->widget_alias))
843 gtk_entry_set_text (GTK_ENTRY (information->widget_alias),
844 empathy_contact_get_name (information->contact));
846 gtk_label_set_label (GTK_LABEL (information->widget_alias),
847 empathy_contact_get_name (information->contact));
851 contact_widget_presence_notify_cb (EmpathyContactWidget *information)
853 gtk_label_set_text (GTK_LABEL (information->label_status),
854 empathy_contact_get_status (information->contact));
855 gtk_image_set_from_icon_name (GTK_IMAGE (information->image_state),
856 empathy_icon_name_for_contact (information->contact),
857 GTK_ICON_SIZE_BUTTON);
861 contact_widget_avatar_notify_cb (EmpathyContactWidget *information)
863 EmpathyAvatar *avatar = NULL;
865 if (information->contact)
866 avatar = empathy_contact_get_avatar (information->contact);
868 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_AVATAR)
870 g_signal_handlers_block_by_func (information->widget_avatar,
871 contact_widget_avatar_changed_cb,
873 empathy_avatar_chooser_set (
874 EMPATHY_AVATAR_CHOOSER (information->widget_avatar), avatar);
875 g_signal_handlers_unblock_by_func (information->widget_avatar,
876 contact_widget_avatar_changed_cb, information);
879 empathy_avatar_image_set (
880 EMPATHY_AVATAR_IMAGE (information->widget_avatar), avatar);
884 contact_widget_groups_setup (EmpathyContactWidget *information)
886 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_GROUPS)
888 information->manager = empathy_contact_manager_dup_singleton ();
889 contact_widget_model_setup (information);
894 contact_widget_groups_update (EmpathyContactWidget *information)
896 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_GROUPS &&
897 information->contact)
899 g_signal_connect_swapped (information->contact, "notify::groups",
900 G_CALLBACK (contact_widget_groups_notify_cb), information);
901 contact_widget_groups_populate_data (information);
903 gtk_widget_show (information->vbox_groups);
906 gtk_widget_hide (information->vbox_groups);
910 contact_widget_model_setup (EmpathyContactWidget *information)
914 GtkTreeSelection *selection;
916 view = GTK_TREE_VIEW (information->treeview_groups);
918 store = gtk_list_store_new (COL_COUNT,
919 G_TYPE_STRING, /* name */
920 G_TYPE_BOOLEAN, /* enabled */
921 G_TYPE_BOOLEAN); /* editable */
923 gtk_tree_view_set_model (view, GTK_TREE_MODEL (store));
925 selection = gtk_tree_view_get_selection (view);
926 gtk_tree_selection_set_mode (selection, GTK_SELECTION_SINGLE);
928 contact_widget_model_populate_columns (information);
930 gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (store),
931 COL_NAME, GTK_SORT_ASCENDING);
933 g_object_unref (store);
937 contact_widget_model_populate_columns (EmpathyContactWidget *information)
941 GtkTreeViewColumn *column;
942 GtkCellRenderer *renderer;
945 view = GTK_TREE_VIEW (information->treeview_groups);
946 model = gtk_tree_view_get_model (view);
948 renderer = gtk_cell_renderer_toggle_new ();
949 g_signal_connect (renderer, "toggled",
950 G_CALLBACK (contact_widget_cell_toggled), information);
952 column = gtk_tree_view_column_new_with_attributes (_("Select"), renderer,
953 "active", COL_ENABLED, NULL);
955 gtk_tree_view_column_set_sizing (column, GTK_TREE_VIEW_COLUMN_FIXED);
956 gtk_tree_view_column_set_fixed_width (column, 50);
957 gtk_tree_view_append_column (view, column);
959 renderer = gtk_cell_renderer_text_new ();
960 col_offset = gtk_tree_view_insert_column_with_attributes (view,
964 /* "editable", COL_EDITABLE, */
967 g_object_set_data (G_OBJECT (renderer),
968 "column", GINT_TO_POINTER (COL_NAME));
970 column = gtk_tree_view_get_column (view, col_offset - 1);
971 gtk_tree_view_column_set_sort_column_id (column, COL_NAME);
972 gtk_tree_view_column_set_resizable (column,FALSE);
973 gtk_tree_view_column_set_clickable (GTK_TREE_VIEW_COLUMN (column), TRUE);
977 contact_widget_groups_populate_data (EmpathyContactWidget *information)
982 GList *my_groups, *l;
985 view = GTK_TREE_VIEW (information->treeview_groups);
986 store = GTK_LIST_STORE (gtk_tree_view_get_model (view));
987 gtk_list_store_clear (store);
989 all_groups = empathy_contact_list_get_all_groups (
990 EMPATHY_CONTACT_LIST (information->manager));
991 my_groups = empathy_contact_list_get_groups (
992 EMPATHY_CONTACT_LIST (information->manager),
993 information->contact);
995 for (l = all_groups; l; l = l->next)
997 const gchar *group_str;
1000 group_str = l->data;
1002 enabled = g_list_find_custom (my_groups,
1003 group_str, (GCompareFunc) strcmp) != NULL;
1005 gtk_list_store_append (store, &iter);
1006 gtk_list_store_set (store, &iter,
1007 COL_NAME, group_str,
1009 COL_ENABLED, enabled,
1013 g_list_foreach (all_groups, (GFunc) g_free, NULL);
1014 g_list_foreach (my_groups, (GFunc) g_free, NULL);
1015 g_list_free (all_groups);
1016 g_list_free (my_groups);
1020 contact_widget_groups_notify_cb (EmpathyContactWidget *information)
1022 /* FIXME: not implemented */
1026 contact_widget_model_find_name (EmpathyContactWidget *information,
1031 GtkTreeModel *model;
1034 if (EMP_STR_EMPTY (name))
1037 data.information = information;
1041 view = GTK_TREE_VIEW (information->treeview_groups);
1042 model = gtk_tree_view_get_model (view);
1044 gtk_tree_model_foreach (model,
1045 (GtkTreeModelForeachFunc) contact_widget_model_find_name_foreach,
1048 if (data.found == TRUE)
1050 *iter = data.found_iter;
1058 contact_widget_model_find_name_foreach (GtkTreeModel *model,
1065 gtk_tree_model_get (model, iter,
1072 if (data->name && strcmp (data->name, name) == 0)
1075 data->found_iter = *iter;
1088 contact_widget_cell_toggled (GtkCellRendererToggle *cell,
1090 EmpathyContactWidget *information)
1093 GtkTreeModel *model;
1094 GtkListStore *store;
1100 view = GTK_TREE_VIEW (information->treeview_groups);
1101 model = gtk_tree_view_get_model (view);
1102 store = GTK_LIST_STORE (model);
1104 path = gtk_tree_path_new_from_string (path_string);
1106 gtk_tree_model_get_iter (model, &iter, path);
1107 gtk_tree_model_get (model, &iter,
1108 COL_ENABLED, &enabled,
1112 gtk_list_store_set (store, &iter, COL_ENABLED, !enabled, -1);
1113 gtk_tree_path_free (path);
1119 empathy_contact_list_remove_from_group (
1120 EMPATHY_CONTACT_LIST (information->manager), information->contact,
1125 empathy_contact_list_add_to_group (
1126 EMPATHY_CONTACT_LIST (information->manager), information->contact,
1134 contact_widget_entry_group_changed_cb (GtkEditable *editable,
1135 EmpathyContactWidget *information)
1140 group = gtk_entry_get_text (GTK_ENTRY (information->entry_group));
1142 if (contact_widget_model_find_name (information, group, &iter))
1143 gtk_widget_set_sensitive (GTK_WIDGET (information->button_group), FALSE);
1145 gtk_widget_set_sensitive (GTK_WIDGET (information->button_group),
1146 !EMP_STR_EMPTY (group));
1150 contact_widget_entry_group_activate_cb (GtkEntry *entry,
1151 EmpathyContactWidget *information)
1153 gtk_widget_activate (GTK_WIDGET (information->button_group));
1157 contact_widget_button_group_clicked_cb (GtkButton *button,
1158 EmpathyContactWidget *information)
1161 GtkListStore *store;
1165 view = GTK_TREE_VIEW (information->treeview_groups);
1166 store = GTK_LIST_STORE (gtk_tree_view_get_model (view));
1168 group = gtk_entry_get_text (GTK_ENTRY (information->entry_group));
1170 gtk_list_store_append (store, &iter);
1171 gtk_list_store_set (store, &iter,
1176 empathy_contact_list_add_to_group (
1177 EMPATHY_CONTACT_LIST (information->manager), information->contact,
1182 contact_widget_details_setup (EmpathyContactWidget *information)
1184 /* FIXME: Needs new telepathy spec */
1185 gtk_widget_hide (information->vbox_details);
1189 contact_widget_details_update (EmpathyContactWidget *information)
1191 /* FIXME: Needs new telepathy spec */
1195 contact_widget_client_setup (EmpathyContactWidget *information)
1197 /* FIXME: Needs new telepathy spec */
1198 gtk_widget_hide (information->vbox_client);
1202 contact_widget_client_update (EmpathyContactWidget *information)
1204 /* FIXME: Needs new telepathy spec */