1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
3 * Copyright (C) 2005-2007 Imendio AB
4 * Copyright (C) 2007 Collabora Ltd.
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation; either version 2 of the
9 * License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
16 * You should have received a copy of the GNU General Public
17 * License along with this program; if not, write to the
18 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 * Boston, MA 02111-1307, USA.
21 * Authors: Mikael Hallendal <micke@imendio.com>
22 * Martyn Russell <martyn@imendio.com>
23 * Xavier Claessens <xclaesse@gmail.com>
30 #include <glib/gi18n.h>
32 #include <glade/glade.h>
34 #include <libtelepathy/tp-helpers.h>
36 #include <libmissioncontrol/mc-account.h>
37 #include <libmissioncontrol/mission-control.h>
39 #include <libempathy/empathy-contact-factory.h>
40 #include <libempathy/empathy-contact-list.h>
41 #include <libempathy/empathy-log-manager.h>
42 #include <libempathy/empathy-tp-group.h>
43 #include <libempathy/empathy-debug.h>
44 #include <libempathy/empathy-utils.h>
45 #include <libempathy/empathy-marshal.h>
47 #include "empathy-contact-list-view.h"
48 #include "empathy-contact-list-store.h"
49 #include "empathy-images.h"
50 #include "empathy-contact-groups.h"
51 #include "empathy-cell-renderer-expander.h"
52 #include "empathy-cell-renderer-text.h"
53 #include "empathy-cell-renderer-activatable.h"
54 #include "empathy-ui-utils.h"
55 #include "empathy-contact-dialogs.h"
56 //#include "empathy-chat-invite.h"
57 //#include "empathy-ft-window.h"
58 #include "empathy-log-window.h"
60 #define DEBUG_DOMAIN "ContactListView"
62 /* Flashing delay for icons (milliseconds). */
63 #define FLASH_TIMEOUT 500
65 /* Active users are those which have recently changed state
66 * (e.g. online, offline or from normal to a busy state).
69 #define GET_PRIV(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), EMPATHY_TYPE_CONTACT_LIST_VIEW, EmpathyContactListViewPriv))
71 struct _EmpathyContactListViewPriv {
72 EmpathyContactListStore *store;
74 GtkTreeRowReference *drag_row;
79 EmpathyContactListView *view;
85 EmpathyContactListView *view;
86 EmpathyContact *contact;
90 static void empathy_contact_list_view_class_init (EmpathyContactListViewClass *klass);
91 static void empathy_contact_list_view_init (EmpathyContactListView *list);
92 static void contact_list_view_finalize (GObject *object);
93 static void contact_list_view_get_property (GObject *object,
97 static void contact_list_view_set_property (GObject *object,
101 static void contact_list_view_setup (EmpathyContactListView *view);
102 static void contact_list_view_row_has_child_toggled_cb (GtkTreeModel *model,
105 EmpathyContactListView *view);
106 static void contact_list_view_drag_data_received (GtkWidget *widget,
107 GdkDragContext *context,
110 GtkSelectionData *selection,
113 static gboolean contact_list_view_drag_motion (GtkWidget *widget,
114 GdkDragContext *context,
118 static gboolean contact_list_view_drag_motion_cb (DragMotionData *data);
119 static void contact_list_view_drag_begin (GtkWidget *widget,
120 GdkDragContext *context);
121 static void contact_list_view_drag_data_get (GtkWidget *widget,
122 GdkDragContext *context,
123 GtkSelectionData *selection,
126 static void contact_list_view_drag_end (GtkWidget *widget,
127 GdkDragContext *context);
128 static gboolean contact_list_view_drag_drop (GtkWidget *widget,
129 GdkDragContext *drag_context,
133 static void contact_list_view_cell_set_background (EmpathyContactListView *view,
134 GtkCellRenderer *cell,
137 static void contact_list_view_pixbuf_cell_data_func (GtkTreeViewColumn *tree_column,
138 GtkCellRenderer *cell,
141 EmpathyContactListView *view);
143 static void contact_list_view_voip_cell_data_func (GtkTreeViewColumn *tree_column,
144 GtkCellRenderer *cell,
147 EmpathyContactListView *view);
149 static void contact_list_view_avatar_cell_data_func (GtkTreeViewColumn *tree_column,
150 GtkCellRenderer *cell,
153 EmpathyContactListView *view);
154 static void contact_list_view_text_cell_data_func (GtkTreeViewColumn *tree_column,
155 GtkCellRenderer *cell,
158 EmpathyContactListView *view);
159 static void contact_list_view_expander_cell_data_func (GtkTreeViewColumn *column,
160 GtkCellRenderer *cell,
163 EmpathyContactListView *view);
164 static GtkWidget * contact_list_view_get_contact_menu (EmpathyContactListView *view,
165 gboolean can_send_file,
166 gboolean can_show_log,
168 static gboolean contact_list_view_button_press_event_cb (EmpathyContactListView *view,
169 GdkEventButton *event,
171 static void contact_list_view_row_activated_cb (EmpathyContactListView *view,
173 GtkTreeViewColumn *col,
176 static void contact_list_view_voip_activated_cb (EmpathyCellRendererActivatable *cell,
177 const gchar *path_string,
178 EmpathyContactListView *view);
180 static void contact_list_view_row_expand_or_collapse_cb (EmpathyContactListView *view,
184 static void contact_list_view_action_cb (GtkAction *action,
185 EmpathyContactListView *view);
186 static void contact_list_view_action_activated (EmpathyContactListView *view,
187 EmpathyContact *contact);
188 static void contact_list_view_voip_activated (EmpathyContactListView *view,
189 EmpathyContact *contact);
196 static const GtkActionEntry entries[] = {
197 { "ContactMenu", NULL,
198 N_("_Contact"), NULL, NULL,
202 N_("_Group"),NULL, NULL,
205 { "Chat", EMPATHY_IMAGE_MESSAGE,
206 N_("_Chat"), NULL, N_("Chat with contact"),
207 G_CALLBACK (contact_list_view_action_cb)
209 { "Information", EMPATHY_IMAGE_CONTACT_INFORMATION,
210 N_("Infor_mation"), "<control>I", N_("View contact information"),
211 G_CALLBACK (contact_list_view_action_cb)
214 N_("Re_name"), NULL, N_("Rename"),
215 G_CALLBACK (contact_list_view_action_cb)
217 { "Edit", GTK_STOCK_EDIT,
218 N_("_Edit"), NULL, N_("Edit the groups and name for this contact"),
219 G_CALLBACK (contact_list_view_action_cb)
221 { "Remove", GTK_STOCK_REMOVE,
222 N_("_Remove"), NULL, N_("Remove contact"),
223 G_CALLBACK (contact_list_view_action_cb)
225 { "Invite", EMPATHY_IMAGE_GROUP_MESSAGE,
226 N_("_Invite to Chat Room"), NULL, N_("Invite to a currently open chat room"),
227 G_CALLBACK (contact_list_view_action_cb)
230 N_("_Send File..."), NULL, N_("Send a file"),
231 G_CALLBACK (contact_list_view_action_cb)
233 { "Log", EMPATHY_IMAGE_LOG,
234 N_("_View Previous Conversations"), NULL, N_("View previous conversations with this contact"),
235 G_CALLBACK (contact_list_view_action_cb)
238 { "Call", EMPATHY_IMAGE_VOIP,
239 N_("_Call"), NULL, N_("Start a voice or video conversation with this contact"),
240 G_CALLBACK (contact_list_view_action_cb)
245 static guint n_entries = G_N_ELEMENTS (entries);
247 static const gchar *ui_info =
249 " <popup name='Contact'>"
250 " <menuitem action='Chat'/>"
252 " <menuitem action='Call'/>"
254 " <menuitem action='Log'/>"
255 " <menuitem action='SendFile'/>"
257 " <menuitem action='Invite'/>"
259 " <menuitem action='Edit'/>"
260 " <menuitem action='Remove'/>"
262 " <menuitem action='Information'/>"
264 " <popup name='Group'>"
265 " <menuitem action='Rename'/>"
270 DND_DRAG_TYPE_CONTACT_ID,
272 DND_DRAG_TYPE_STRING,
275 static const GtkTargetEntry drag_types_dest[] = {
276 { "text/contact-id", 0, DND_DRAG_TYPE_CONTACT_ID },
277 { "text/uri-list", 0, DND_DRAG_TYPE_URL },
278 { "text/plain", 0, DND_DRAG_TYPE_STRING },
279 { "STRING", 0, DND_DRAG_TYPE_STRING },
282 static const GtkTargetEntry drag_types_source[] = {
283 { "text/contact-id", 0, DND_DRAG_TYPE_CONTACT_ID },
286 static GdkAtom drag_atoms_dest[G_N_ELEMENTS (drag_types_dest)];
287 static GdkAtom drag_atoms_source[G_N_ELEMENTS (drag_types_source)];
290 DRAG_CONTACT_RECEIVED,
294 static guint signals[LAST_SIGNAL];
296 G_DEFINE_TYPE (EmpathyContactListView, empathy_contact_list_view, GTK_TYPE_TREE_VIEW);
299 empathy_contact_list_view_class_init (EmpathyContactListViewClass *klass)
301 GObjectClass *object_class = G_OBJECT_CLASS (klass);
302 GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
304 object_class->finalize = contact_list_view_finalize;
305 object_class->get_property = contact_list_view_get_property;
306 object_class->set_property = contact_list_view_set_property;
308 widget_class->drag_data_received = contact_list_view_drag_data_received;
309 widget_class->drag_drop = contact_list_view_drag_drop;
310 widget_class->drag_begin = contact_list_view_drag_begin;
311 widget_class->drag_data_get = contact_list_view_drag_data_get;
312 widget_class->drag_end = contact_list_view_drag_end;
313 /* FIXME: noticed but when you drag the row over the treeview
314 * fast, it seems to stop redrawing itself, if we don't
315 * connect this signal, all is fine.
317 widget_class->drag_motion = contact_list_view_drag_motion;
319 signals[DRAG_CONTACT_RECEIVED] =
320 g_signal_new ("drag-contact-received",
321 G_OBJECT_CLASS_TYPE (klass),
325 empathy_marshal_VOID__OBJECT_STRING_STRING,
327 3, EMPATHY_TYPE_CONTACT, G_TYPE_STRING, G_TYPE_STRING);
329 g_object_class_install_property (object_class,
331 g_param_spec_boolean ("interactive",
332 "View is interactive",
333 "Is the view interactive",
337 g_type_class_add_private (object_class, sizeof (EmpathyContactListViewPriv));
341 empathy_contact_list_view_init (EmpathyContactListView *view)
343 EmpathyContactListViewPriv *priv;
344 GtkActionGroup *action_group;
345 GError *error = NULL;
347 priv = GET_PRIV (view);
349 /* Get saved group states. */
350 empathy_contact_groups_get_all ();
352 /* Set up UI Manager */
353 priv->ui = gtk_ui_manager_new ();
355 action_group = gtk_action_group_new ("Actions");
356 gtk_action_group_set_translation_domain (action_group, GETTEXT_PACKAGE);
357 gtk_action_group_add_actions (action_group, entries, n_entries, view);
358 gtk_ui_manager_insert_action_group (priv->ui, action_group, 0);
360 if (!gtk_ui_manager_add_ui_from_string (priv->ui, ui_info, -1, &error)) {
361 g_warning ("Could not build contact menus from string:'%s'", error->message);
362 g_error_free (error);
365 g_object_unref (action_group);
367 gtk_tree_view_set_row_separator_func (GTK_TREE_VIEW (view),
368 empathy_contact_list_store_row_separator_func,
371 /* Connect to tree view signals rather than override. */
372 g_signal_connect (view,
373 "button-press-event",
374 G_CALLBACK (contact_list_view_button_press_event_cb),
376 g_signal_connect (view,
378 G_CALLBACK (contact_list_view_row_activated_cb),
380 g_signal_connect (view,
382 G_CALLBACK (contact_list_view_row_expand_or_collapse_cb),
383 GINT_TO_POINTER (TRUE));
384 g_signal_connect (view,
386 G_CALLBACK (contact_list_view_row_expand_or_collapse_cb),
387 GINT_TO_POINTER (FALSE));
391 contact_list_view_finalize (GObject *object)
393 EmpathyContactListViewPriv *priv;
395 priv = GET_PRIV (object);
398 g_object_unref (priv->ui);
401 g_object_unref (priv->store);
404 G_OBJECT_CLASS (empathy_contact_list_view_parent_class)->finalize (object);
408 contact_list_view_get_property (GObject *object,
413 EmpathyContactListViewPriv *priv;
415 priv = GET_PRIV (object);
418 case PROP_INTERACTIVE:
419 g_value_set_boolean (value, priv->interactive);
422 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
428 contact_list_view_set_property (GObject *object,
433 EmpathyContactListView *view = EMPATHY_CONTACT_LIST_VIEW (object);
434 EmpathyContactListViewPriv *priv;
436 priv = GET_PRIV (object);
439 case PROP_INTERACTIVE:
440 empathy_contact_list_view_set_interactive (view, g_value_get_boolean (value));
443 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
448 EmpathyContactListView *
449 empathy_contact_list_view_new (EmpathyContactListStore *store)
451 EmpathyContactListViewPriv *priv;
452 EmpathyContactListView *view;
454 view = g_object_new (EMPATHY_TYPE_CONTACT_LIST_VIEW, NULL);
455 priv = GET_PRIV (view);
457 priv->store = g_object_ref (store);
458 contact_list_view_setup (view);
464 empathy_contact_list_view_set_interactive (EmpathyContactListView *view,
465 gboolean interactive)
467 EmpathyContactListViewPriv *priv = GET_PRIV (view);
469 g_return_if_fail (EMPATHY_IS_CONTACT_LIST_VIEW (view));
471 priv->interactive = interactive;
472 g_object_notify (G_OBJECT (view), "interactive");
476 empathy_contact_list_view_get_interactive (EmpathyContactListView *view)
478 EmpathyContactListViewPriv *priv = GET_PRIV (view);
480 g_return_val_if_fail (EMPATHY_IS_CONTACT_LIST_VIEW (view), FALSE);
482 return priv->interactive;
486 empathy_contact_list_view_get_selected (EmpathyContactListView *view)
488 EmpathyContactListViewPriv *priv;
489 GtkTreeSelection *selection;
492 EmpathyContact *contact;
494 g_return_val_if_fail (EMPATHY_IS_CONTACT_LIST_VIEW (view), NULL);
496 priv = GET_PRIV (view);
498 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (view));
499 if (!gtk_tree_selection_get_selected (selection, &model, &iter)) {
503 gtk_tree_model_get (model, &iter, COL_CONTACT, &contact, -1);
509 empathy_contact_list_view_get_selected_group (EmpathyContactListView *view)
511 EmpathyContactListViewPriv *priv;
512 GtkTreeSelection *selection;
518 g_return_val_if_fail (EMPATHY_IS_CONTACT_LIST_VIEW (view), NULL);
520 priv = GET_PRIV (view);
522 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (view));
523 if (!gtk_tree_selection_get_selected (selection, &model, &iter)) {
527 gtk_tree_model_get (model, &iter,
528 COL_IS_GROUP, &is_group,
541 empathy_contact_list_view_get_group_menu (EmpathyContactListView *view)
543 EmpathyContactListViewPriv *priv;
546 g_return_val_if_fail (EMPATHY_IS_CONTACT_LIST_VIEW (view), NULL);
548 priv = GET_PRIV (view);
550 widget = gtk_ui_manager_get_widget (priv->ui, "/Group");
556 empathy_contact_list_view_get_contact_menu (EmpathyContactListView *view,
557 EmpathyContact *contact)
559 EmpathyLogManager *log_manager;
560 gboolean can_show_log;
561 gboolean can_send_file;
564 g_return_val_if_fail (EMPATHY_IS_CONTACT_LIST_VIEW (view), NULL);
565 g_return_val_if_fail (EMPATHY_IS_CONTACT (contact), NULL);
567 log_manager = empathy_log_manager_new ();
568 can_show_log = empathy_log_manager_exists (log_manager,
569 empathy_contact_get_account (contact),
570 empathy_contact_get_id (contact),
572 g_object_unref (log_manager);
573 can_send_file = FALSE;
574 can_voip = empathy_contact_can_voip (contact);
576 return contact_list_view_get_contact_menu (view,
583 contact_list_view_setup (EmpathyContactListView *view)
585 EmpathyContactListViewPriv *priv;
586 GtkCellRenderer *cell;
587 GtkTreeViewColumn *col;
590 priv = GET_PRIV (view);
592 gtk_tree_view_set_search_equal_func (GTK_TREE_VIEW (view),
593 empathy_contact_list_store_search_equal_func,
596 g_signal_connect (priv->store, "row-has-child-toggled",
597 G_CALLBACK (contact_list_view_row_has_child_toggled_cb),
599 gtk_tree_view_set_model (GTK_TREE_VIEW (view),
600 GTK_TREE_MODEL (priv->store));
604 "headers-visible", FALSE,
606 "show-expanders", FALSE,
609 col = gtk_tree_view_column_new ();
612 cell = gtk_cell_renderer_pixbuf_new ();
613 gtk_tree_view_column_pack_start (col, cell, FALSE);
614 gtk_tree_view_column_set_cell_data_func (
616 (GtkTreeCellDataFunc) contact_list_view_pixbuf_cell_data_func,
626 cell = empathy_cell_renderer_text_new ();
627 gtk_tree_view_column_pack_start (col, cell, TRUE);
628 gtk_tree_view_column_set_cell_data_func (
630 (GtkTreeCellDataFunc) contact_list_view_text_cell_data_func,
633 gtk_tree_view_column_add_attribute (col, cell,
635 gtk_tree_view_column_add_attribute (col, cell,
636 "status", COL_STATUS);
637 gtk_tree_view_column_add_attribute (col, cell,
638 "is_group", COL_IS_GROUP);
641 /* Voip Capability Icon */
642 cell = empathy_cell_renderer_activatable_new ();
643 gtk_tree_view_column_pack_start (col, cell, FALSE);
644 gtk_tree_view_column_set_cell_data_func (
646 (GtkTreeCellDataFunc) contact_list_view_voip_cell_data_func,
653 g_signal_connect (cell, "path-activated",
654 G_CALLBACK (contact_list_view_voip_activated_cb),
659 cell = gtk_cell_renderer_pixbuf_new ();
660 gtk_tree_view_column_pack_start (col, cell, FALSE);
661 gtk_tree_view_column_set_cell_data_func (
663 (GtkTreeCellDataFunc) contact_list_view_avatar_cell_data_func,
675 cell = empathy_cell_renderer_expander_new ();
676 gtk_tree_view_column_pack_end (col, cell, FALSE);
677 gtk_tree_view_column_set_cell_data_func (
679 (GtkTreeCellDataFunc) contact_list_view_expander_cell_data_func,
682 /* Actually add the column now we have added all cell renderers */
683 gtk_tree_view_append_column (GTK_TREE_VIEW (view), col);
686 for (i = 0; i < G_N_ELEMENTS (drag_types_dest); ++i) {
687 drag_atoms_dest[i] = gdk_atom_intern (drag_types_dest[i].target,
691 for (i = 0; i < G_N_ELEMENTS (drag_types_source); ++i) {
692 drag_atoms_source[i] = gdk_atom_intern (drag_types_source[i].target,
696 /* Note: We support the COPY action too, but need to make the
697 * MOVE action the default.
699 gtk_drag_source_set (GTK_WIDGET (view),
702 G_N_ELEMENTS (drag_types_source),
703 GDK_ACTION_MOVE | GDK_ACTION_COPY);
705 gtk_drag_dest_set (GTK_WIDGET (view),
706 GTK_DEST_DEFAULT_ALL,
708 G_N_ELEMENTS (drag_types_dest),
709 GDK_ACTION_MOVE | GDK_ACTION_COPY);
713 contact_list_view_row_has_child_toggled_cb (GtkTreeModel *model,
716 EmpathyContactListView *view)
718 gboolean is_group = FALSE;
721 gtk_tree_model_get (model, iter,
722 COL_IS_GROUP, &is_group,
726 if (!is_group || G_STR_EMPTY (name)) {
731 if (empathy_contact_group_get_expanded (name)) {
732 g_signal_handlers_block_by_func (view,
733 contact_list_view_row_expand_or_collapse_cb,
734 GINT_TO_POINTER (TRUE));
735 gtk_tree_view_expand_row (GTK_TREE_VIEW (view), path, TRUE);
736 g_signal_handlers_unblock_by_func (view,
737 contact_list_view_row_expand_or_collapse_cb,
738 GINT_TO_POINTER (TRUE));
740 g_signal_handlers_block_by_func (view,
741 contact_list_view_row_expand_or_collapse_cb,
742 GINT_TO_POINTER (FALSE));
743 gtk_tree_view_collapse_row (GTK_TREE_VIEW (view), path);
744 g_signal_handlers_unblock_by_func (view,
745 contact_list_view_row_expand_or_collapse_cb,
746 GINT_TO_POINTER (FALSE));
753 contact_list_view_drag_data_received (GtkWidget *widget,
754 GdkDragContext *context,
757 GtkSelectionData *selection,
761 EmpathyContactListViewPriv *priv;
762 EmpathyContactList *list;
763 EmpathyContactFactory *factory;
767 GtkTreeViewDropPosition position;
768 EmpathyContact *contact = NULL;
771 gchar *new_group = NULL;
772 gchar *old_group = NULL;
775 priv = GET_PRIV (widget);
777 id = (const gchar*) selection->data;
778 empathy_debug (DEBUG_DOMAIN, "Received %s%s drag & drop contact from roster with id:'%s'",
779 context->action == GDK_ACTION_MOVE ? "move" : "",
780 context->action == GDK_ACTION_COPY ? "copy" : "",
783 strv = g_strsplit (id, "/", 2);
784 factory = empathy_contact_factory_new ();
785 account = mc_account_lookup (strv[0]);
787 contact = empathy_contact_factory_get_from_id (factory,
790 g_object_unref (account);
792 g_object_unref (factory);
796 empathy_debug (DEBUG_DOMAIN, "No contact found associated with drag & drop");
800 model = gtk_tree_view_get_model (GTK_TREE_VIEW (widget));
802 /* Get source group information. */
803 if (priv->drag_row) {
804 path = gtk_tree_row_reference_get_path (priv->drag_row);
806 old_group = empathy_contact_list_store_get_parent_group (model, path, NULL);
807 gtk_tree_path_free (path);
811 /* Get destination group information. */
812 is_row = gtk_tree_view_get_dest_row_at_pos (GTK_TREE_VIEW (widget),
819 new_group = empathy_contact_list_store_get_parent_group (model, path, NULL);
820 gtk_tree_path_free (path);
823 empathy_debug (DEBUG_DOMAIN,
824 "contact %s (%d) dragged from '%s' to '%s'",
825 empathy_contact_get_id (contact),
826 empathy_contact_get_handle (contact),
827 old_group, new_group);
829 list = empathy_contact_list_store_get_list_iface (priv->store);
831 empathy_contact_list_add_to_group (list, contact, new_group);
833 if (old_group && context->action == GDK_ACTION_MOVE) {
834 empathy_contact_list_remove_from_group (list, contact, old_group);
840 gtk_drag_finish (context, TRUE, FALSE, GDK_CURRENT_TIME);
844 contact_list_view_drag_motion (GtkWidget *widget,
845 GdkDragContext *context,
850 static DragMotionData *dm = NULL;
853 gboolean is_different = FALSE;
854 gboolean cleanup = TRUE;
856 is_row = gtk_tree_view_get_path_at_pos (GTK_TREE_VIEW (widget),
867 cleanup &= (dm && gtk_tree_path_compare (dm->path, path) != 0);
868 is_different = (!dm || (dm && gtk_tree_path_compare (dm->path, path) != 0));
873 if (!is_different && !cleanup) {
878 gtk_tree_path_free (dm->path);
879 if (dm->timeout_id) {
880 g_source_remove (dm->timeout_id);
888 if (!gtk_tree_view_row_expanded (GTK_TREE_VIEW (widget), path)) {
889 dm = g_new0 (DragMotionData, 1);
891 dm->view = EMPATHY_CONTACT_LIST_VIEW (widget);
892 dm->path = gtk_tree_path_copy (path);
894 dm->timeout_id = g_timeout_add_seconds (1,
895 (GSourceFunc) contact_list_view_drag_motion_cb,
903 contact_list_view_drag_motion_cb (DragMotionData *data)
905 gtk_tree_view_expand_row (GTK_TREE_VIEW (data->view),
909 data->timeout_id = 0;
915 contact_list_view_drag_begin (GtkWidget *widget,
916 GdkDragContext *context)
918 EmpathyContactListViewPriv *priv;
919 GtkTreeSelection *selection;
924 priv = GET_PRIV (widget);
926 GTK_WIDGET_CLASS (empathy_contact_list_view_parent_class)->drag_begin (widget,
929 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (widget));
930 if (!gtk_tree_selection_get_selected (selection, &model, &iter)) {
934 path = gtk_tree_model_get_path (model, &iter);
935 priv->drag_row = gtk_tree_row_reference_new (model, path);
936 gtk_tree_path_free (path);
940 contact_list_view_drag_data_get (GtkWidget *widget,
941 GdkDragContext *context,
942 GtkSelectionData *selection,
946 EmpathyContactListViewPriv *priv;
947 GtkTreePath *src_path;
950 EmpathyContact *contact;
952 const gchar *contact_id;
953 const gchar *account_id;
957 priv = GET_PRIV (widget);
959 model = gtk_tree_view_get_model (GTK_TREE_VIEW (widget));
960 if (!priv->drag_row) {
964 src_path = gtk_tree_row_reference_get_path (priv->drag_row);
969 if (!gtk_tree_model_get_iter (model, &iter, src_path)) {
970 gtk_tree_path_free (src_path);
974 gtk_tree_path_free (src_path);
976 contact = empathy_contact_list_view_get_selected (EMPATHY_CONTACT_LIST_VIEW (widget));
981 account = empathy_contact_get_account (contact);
982 account_id = mc_account_get_unique_name (account);
983 contact_id = empathy_contact_get_id (contact);
984 g_object_unref (contact);
985 str = g_strconcat (account_id, "/", contact_id, NULL);
988 case DND_DRAG_TYPE_CONTACT_ID:
989 gtk_selection_data_set (selection, drag_atoms_source[info], 8,
990 (guchar*)str, strlen (str) + 1);
998 contact_list_view_drag_end (GtkWidget *widget,
999 GdkDragContext *context)
1001 EmpathyContactListViewPriv *priv;
1003 priv = GET_PRIV (widget);
1005 GTK_WIDGET_CLASS (empathy_contact_list_view_parent_class)->drag_end (widget,
1008 if (priv->drag_row) {
1009 gtk_tree_row_reference_free (priv->drag_row);
1010 priv->drag_row = NULL;
1015 contact_list_view_drag_drop (GtkWidget *widget,
1016 GdkDragContext *drag_context,
1025 contact_list_view_cell_set_background (EmpathyContactListView *view,
1026 GtkCellRenderer *cell,
1033 style = gtk_widget_get_style (GTK_WIDGET (view));
1037 color = style->bg[GTK_STATE_SELECTED];
1039 /* Here we take the current theme colour and add it to
1040 * the colour for white and average the two. This
1041 * gives a colour which is inline with the theme but
1044 color.red = (color.red + (style->white).red) / 2;
1045 color.green = (color.green + (style->white).green) / 2;
1046 color.blue = (color.blue + (style->white).blue) / 2;
1049 "cell-background-gdk", &color,
1053 "cell-background-gdk", NULL,
1058 "cell-background-gdk", NULL,
1064 contact_list_view_pixbuf_cell_data_func (GtkTreeViewColumn *tree_column,
1065 GtkCellRenderer *cell,
1066 GtkTreeModel *model,
1068 EmpathyContactListView *view)
1074 gtk_tree_model_get (model, iter,
1075 COL_IS_GROUP, &is_group,
1076 COL_IS_ACTIVE, &is_active,
1077 COL_ICON_STATUS, &icon_name,
1081 "visible", !is_group,
1082 "icon-name", icon_name,
1087 contact_list_view_cell_set_background (view, cell, is_group, is_active);
1092 contact_list_view_voip_cell_data_func (GtkTreeViewColumn *tree_column,
1093 GtkCellRenderer *cell,
1094 GtkTreeModel *model,
1096 EmpathyContactListView *view)
1102 gtk_tree_model_get (model, iter,
1103 COL_IS_GROUP, &is_group,
1104 COL_IS_ACTIVE, &is_active,
1105 COL_CAN_VOIP, &can_voip,
1109 "visible", !is_group && can_voip,
1110 "icon-name", EMPATHY_IMAGE_VOIP,
1113 contact_list_view_cell_set_background (view, cell, is_group, is_active);
1118 contact_list_view_avatar_cell_data_func (GtkTreeViewColumn *tree_column,
1119 GtkCellRenderer *cell,
1120 GtkTreeModel *model,
1122 EmpathyContactListView *view)
1125 gboolean show_avatar;
1129 gtk_tree_model_get (model, iter,
1130 COL_PIXBUF_AVATAR, &pixbuf,
1131 COL_PIXBUF_AVATAR_VISIBLE, &show_avatar,
1132 COL_IS_GROUP, &is_group,
1133 COL_IS_ACTIVE, &is_active,
1137 "visible", !is_group && show_avatar,
1142 g_object_unref (pixbuf);
1145 contact_list_view_cell_set_background (view, cell, is_group, is_active);
1149 contact_list_view_text_cell_data_func (GtkTreeViewColumn *tree_column,
1150 GtkCellRenderer *cell,
1151 GtkTreeModel *model,
1153 EmpathyContactListView *view)
1157 gboolean show_status;
1159 gtk_tree_model_get (model, iter,
1160 COL_IS_GROUP, &is_group,
1161 COL_IS_ACTIVE, &is_active,
1162 COL_STATUS_VISIBLE, &show_status,
1166 "show-status", show_status,
1169 contact_list_view_cell_set_background (view, cell, is_group, is_active);
1173 contact_list_view_expander_cell_data_func (GtkTreeViewColumn *column,
1174 GtkCellRenderer *cell,
1175 GtkTreeModel *model,
1177 EmpathyContactListView *view)
1182 gtk_tree_model_get (model, iter,
1183 COL_IS_GROUP, &is_group,
1184 COL_IS_ACTIVE, &is_active,
1187 if (gtk_tree_model_iter_has_child (model, iter)) {
1189 gboolean row_expanded;
1191 path = gtk_tree_model_get_path (model, iter);
1192 row_expanded = gtk_tree_view_row_expanded (GTK_TREE_VIEW (column->tree_view), path);
1193 gtk_tree_path_free (path);
1197 "expander-style", row_expanded ? GTK_EXPANDER_EXPANDED : GTK_EXPANDER_COLLAPSED,
1200 g_object_set (cell, "visible", FALSE, NULL);
1203 contact_list_view_cell_set_background (view, cell, is_group, is_active);
1207 contact_list_view_get_contact_menu (EmpathyContactListView *view,
1208 gboolean can_send_file,
1209 gboolean can_show_log,
1212 EmpathyContactListViewPriv *priv;
1216 priv = GET_PRIV (view);
1218 /* Sort out sensitive items */
1219 action = gtk_ui_manager_get_action (priv->ui, "/Contact/Log");
1220 gtk_action_set_sensitive (action, can_show_log);
1223 action = gtk_ui_manager_get_action (priv->ui, "/Contact/Call");
1224 gtk_action_set_sensitive (action, can_voip);
1227 action = gtk_ui_manager_get_action (priv->ui, "/Contact/SendFile");
1228 gtk_action_set_visible (action, can_send_file);
1230 widget = gtk_ui_manager_get_widget (priv->ui, "/Contact");
1236 contact_list_view_button_press_event_cb (EmpathyContactListView *view,
1237 GdkEventButton *event,
1240 EmpathyContactListViewPriv *priv;
1241 EmpathyContact *contact;
1243 GtkTreeSelection *selection;
1244 GtkTreeModel *model;
1246 gboolean row_exists;
1249 priv = GET_PRIV (view);
1251 if (!priv->interactive || event->button != 3) {
1255 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (view));
1256 model = gtk_tree_view_get_model (GTK_TREE_VIEW (view));
1258 gtk_widget_grab_focus (GTK_WIDGET (view));
1260 row_exists = gtk_tree_view_get_path_at_pos (GTK_TREE_VIEW (view),
1268 gtk_tree_selection_unselect_all (selection);
1269 gtk_tree_selection_select_path (selection, path);
1271 gtk_tree_model_get_iter (model, &iter, path);
1272 gtk_tree_path_free (path);
1274 gtk_tree_model_get (model, &iter, COL_CONTACT, &contact, -1);
1277 menu = empathy_contact_list_view_get_contact_menu (view, contact);
1278 g_object_unref (contact);
1280 menu = empathy_contact_list_view_get_group_menu (view);
1287 gtk_widget_show (menu);
1289 gtk_menu_popup (GTK_MENU (menu),
1290 NULL, NULL, NULL, NULL,
1291 event->button, event->time);
1297 contact_list_view_row_activated_cb (EmpathyContactListView *view,
1299 GtkTreeViewColumn *col,
1302 EmpathyContactListViewPriv *priv = GET_PRIV (view);
1303 EmpathyContact *contact;
1304 GtkTreeModel *model;
1307 if (!priv->interactive) {
1311 model = gtk_tree_view_get_model (GTK_TREE_VIEW (view));
1313 gtk_tree_model_get_iter (model, &iter, path);
1314 gtk_tree_model_get (model, &iter, COL_CONTACT, &contact, -1);
1317 contact_list_view_action_activated (view, contact);
1318 g_object_unref (contact);
1324 contact_list_view_voip_activated_cb (EmpathyCellRendererActivatable *cell,
1325 const gchar *path_string,
1326 EmpathyContactListView *view)
1328 EmpathyContactListViewPriv *priv = GET_PRIV (view);
1329 GtkTreeModel *model;
1331 EmpathyContact *contact;
1333 if (!priv->interactive) {
1337 model = gtk_tree_view_get_model (GTK_TREE_VIEW (view));
1338 if (!gtk_tree_model_get_iter_from_string (model, &iter, path_string)) {
1342 gtk_tree_model_get (model, &iter, COL_CONTACT, &contact, -1);
1345 contact_list_view_voip_activated (view, contact);
1346 g_object_unref (contact);
1353 contact_list_view_row_expand_or_collapse_cb (EmpathyContactListView *view,
1358 GtkTreeModel *model;
1362 model = gtk_tree_view_get_model (GTK_TREE_VIEW (view));
1364 gtk_tree_model_get (model, iter,
1368 expanded = GPOINTER_TO_INT (user_data);
1369 empathy_contact_group_set_expanded (name, expanded);
1375 contact_list_view_action_cb (GtkAction *action,
1376 EmpathyContactListView *view)
1378 EmpathyContactListViewPriv *priv;
1379 EmpathyContact *contact;
1384 priv = GET_PRIV (view);
1386 name = gtk_action_get_name (action);
1391 empathy_debug (DEBUG_DOMAIN, "Action:'%s' activated", name);
1393 contact = empathy_contact_list_view_get_selected (view);
1394 group = empathy_contact_list_view_get_selected_group (view);
1395 parent = empathy_get_toplevel_window (GTK_WIDGET (view));
1397 if (contact && strcmp (name, "Chat") == 0) {
1398 contact_list_view_action_activated (view, contact);
1400 else if (contact && strcmp (name, "Call") == 0) {
1401 contact_list_view_voip_activated (view, contact);
1403 else if (contact && strcmp (name, "Information") == 0) {
1404 empathy_contact_information_dialog_show (contact, parent, FALSE, FALSE);
1406 else if (contact && strcmp (name, "Edit") == 0) {
1407 empathy_contact_information_dialog_show (contact, parent, TRUE, FALSE);
1409 else if (contact && strcmp (name, "Remove") == 0) {
1410 /* FIXME: Ask for confirmation */
1411 EmpathyContactList *list;
1413 list = empathy_contact_list_store_get_list_iface (priv->store);
1414 empathy_contact_list_remove (list, contact,
1415 _("Sorry, I don't want you in my contact list anymore."));
1417 else if (contact && strcmp (name, "Invite") == 0) {
1419 else if (contact && strcmp (name, "SendFile") == 0) {
1421 else if (contact && strcmp (name, "Log") == 0) {
1422 empathy_log_window_show (empathy_contact_get_account (contact),
1423 empathy_contact_get_id (contact),
1427 else if (group && strcmp (name, "Rename") == 0) {
1432 g_object_unref (contact);
1437 contact_list_view_action_activated (EmpathyContactListView *view,
1438 EmpathyContact *contact)
1442 mc = empathy_mission_control_new ();
1443 mission_control_request_channel (mc,
1444 empathy_contact_get_account (contact),
1445 TP_IFACE_CHANNEL_TYPE_TEXT,
1446 empathy_contact_get_handle (contact),
1447 TP_HANDLE_TYPE_CONTACT,
1449 g_object_unref (mc);
1453 contact_list_view_voip_activated (EmpathyContactListView *view,
1454 EmpathyContact *contact)
1456 empathy_call_contact (contact);