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-2008 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-contact-groups.h>
44 #include <libempathy/empathy-debug.h>
45 #include <libempathy/empathy-utils.h>
47 #include "empathy-contact-list-view.h"
48 #include "empathy-contact-list-store.h"
49 #include "empathy-images.h"
50 #include "empathy-cell-renderer-expander.h"
51 #include "empathy-cell-renderer-text.h"
52 #include "empathy-cell-renderer-activatable.h"
53 #include "empathy-ui-utils.h"
54 #include "empathy-contact-dialogs.h"
55 //#include "empathy-chat-invite.h"
56 //#include "empathy-ft-window.h"
57 #include "empathy-log-window.h"
58 #include "empathy-gtk-enum-types.h"
59 #include "empathy-gtk-marshal.h"
61 #define DEBUG_DOMAIN "ContactListView"
63 /* Flashing delay for icons (milliseconds). */
64 #define FLASH_TIMEOUT 500
66 /* Active users are those which have recently changed state
67 * (e.g. online, offline or from normal to a busy state).
70 #define GET_PRIV(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), EMPATHY_TYPE_CONTACT_LIST_VIEW, EmpathyContactListViewPriv))
73 EmpathyContactListStore *store;
75 GtkTreeRowReference *drag_row;
76 EmpathyContactListFeatures features;
77 } EmpathyContactListViewPriv;
80 EmpathyContactListView *view;
86 EmpathyContactListView *view;
87 EmpathyContact *contact;
91 static void empathy_contact_list_view_class_init (EmpathyContactListViewClass *klass);
92 static void empathy_contact_list_view_init (EmpathyContactListView *list);
93 static void contact_list_view_finalize (GObject *object);
94 static void contact_list_view_get_property (GObject *object,
98 static void contact_list_view_set_property (GObject *object,
102 static void contact_list_view_setup (EmpathyContactListView *view);
103 static void contact_list_view_row_has_child_toggled_cb (GtkTreeModel *model,
106 EmpathyContactListView *view);
107 static void contact_list_view_drag_data_received (GtkWidget *widget,
108 GdkDragContext *context,
111 GtkSelectionData *selection,
114 static gboolean contact_list_view_drag_motion (GtkWidget *widget,
115 GdkDragContext *context,
119 static gboolean contact_list_view_drag_motion_cb (DragMotionData *data);
120 static void contact_list_view_drag_begin (GtkWidget *widget,
121 GdkDragContext *context);
122 static void contact_list_view_drag_data_get (GtkWidget *widget,
123 GdkDragContext *context,
124 GtkSelectionData *selection,
127 static void contact_list_view_drag_end (GtkWidget *widget,
128 GdkDragContext *context);
129 static gboolean contact_list_view_drag_drop (GtkWidget *widget,
130 GdkDragContext *drag_context,
134 static void contact_list_view_cell_set_background (EmpathyContactListView *view,
135 GtkCellRenderer *cell,
138 static void contact_list_view_pixbuf_cell_data_func (GtkTreeViewColumn *tree_column,
139 GtkCellRenderer *cell,
142 EmpathyContactListView *view);
144 static void contact_list_view_voip_cell_data_func (GtkTreeViewColumn *tree_column,
145 GtkCellRenderer *cell,
148 EmpathyContactListView *view);
150 static void contact_list_view_avatar_cell_data_func (GtkTreeViewColumn *tree_column,
151 GtkCellRenderer *cell,
154 EmpathyContactListView *view);
155 static void contact_list_view_text_cell_data_func (GtkTreeViewColumn *tree_column,
156 GtkCellRenderer *cell,
159 EmpathyContactListView *view);
160 static void contact_list_view_expander_cell_data_func (GtkTreeViewColumn *column,
161 GtkCellRenderer *cell,
164 EmpathyContactListView *view);
165 static GtkWidget * contact_list_view_get_contact_menu (EmpathyContactListView *view,
166 gboolean can_send_file,
167 gboolean can_show_log,
169 static gboolean contact_list_view_button_press_event_cb (EmpathyContactListView *view,
170 GdkEventButton *event,
172 static void contact_list_view_row_activated_cb (EmpathyContactListView *view,
174 GtkTreeViewColumn *col,
177 static void contact_list_view_voip_activated_cb (EmpathyCellRendererActivatable *cell,
178 const gchar *path_string,
179 EmpathyContactListView *view);
181 static void contact_list_view_row_expand_or_collapse_cb (EmpathyContactListView *view,
185 static void contact_list_view_action_cb (GtkAction *action,
186 EmpathyContactListView *view);
187 static void contact_list_view_voip_activated (EmpathyContactListView *view,
188 EmpathyContact *contact);
195 static const GtkActionEntry entries[] = {
196 { "ContactMenu", NULL,
197 N_("_Contact"), NULL, NULL,
201 N_("_Group"),NULL, NULL,
204 { "Chat", EMPATHY_IMAGE_MESSAGE,
205 N_("_Chat"), NULL, N_("Chat with contact"),
206 G_CALLBACK (contact_list_view_action_cb)
208 { "Information", EMPATHY_IMAGE_CONTACT_INFORMATION,
209 N_("Infor_mation"), "<control>I", N_("View contact information"),
210 G_CALLBACK (contact_list_view_action_cb)
213 N_("Re_name"), NULL, N_("Rename"),
214 G_CALLBACK (contact_list_view_action_cb)
216 { "Edit", GTK_STOCK_EDIT,
217 N_("_Edit"), NULL, N_("Edit the groups and name for this contact"),
218 G_CALLBACK (contact_list_view_action_cb)
220 { "Remove", GTK_STOCK_REMOVE,
221 N_("_Remove"), NULL, N_("Remove contact"),
222 G_CALLBACK (contact_list_view_action_cb)
224 { "Invite", EMPATHY_IMAGE_GROUP_MESSAGE,
225 N_("_Invite to Chat Room"), NULL, N_("Invite to a currently open chat room"),
226 G_CALLBACK (contact_list_view_action_cb)
229 N_("_Send File..."), NULL, N_("Send a file"),
230 G_CALLBACK (contact_list_view_action_cb)
232 { "Log", EMPATHY_IMAGE_LOG,
233 N_("_View Previous Conversations"), NULL, N_("View previous conversations with this contact"),
234 G_CALLBACK (contact_list_view_action_cb)
237 { "Call", EMPATHY_IMAGE_VOIP,
238 N_("_Call"), NULL, N_("Start a voice or video conversation with this contact"),
239 G_CALLBACK (contact_list_view_action_cb)
244 static guint n_entries = G_N_ELEMENTS (entries);
246 static const gchar *ui_info =
248 " <popup name='Contact'>"
249 " <menuitem action='Chat'/>"
251 " <menuitem action='Call'/>"
253 " <menuitem action='Log'/>"
254 " <menuitem action='SendFile'/>"
256 " <menuitem action='Invite'/>"
258 " <menuitem action='Edit'/>"
259 " <menuitem action='Remove'/>"
261 " <menuitem action='Information'/>"
263 " <popup name='Group'>"
264 " <menuitem action='Rename'/>"
265 " <menuitem action='Remove'/>"
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_gtk_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_flags ("features",
332 "Features of the view",
333 "Falgs for all enabled features",
334 EMPATHY_TYPE_CONTACT_LIST_FEATURES,
338 g_type_class_add_private (object_class, sizeof (EmpathyContactListViewPriv));
342 empathy_contact_list_view_init (EmpathyContactListView *view)
344 EmpathyContactListViewPriv *priv;
345 GtkActionGroup *action_group;
346 GError *error = NULL;
348 priv = GET_PRIV (view);
350 /* Get saved group states. */
351 empathy_contact_groups_get_all ();
353 /* Set up UI Manager */
354 priv->ui = gtk_ui_manager_new ();
356 action_group = gtk_action_group_new ("Actions");
357 gtk_action_group_set_translation_domain (action_group, GETTEXT_PACKAGE);
358 gtk_action_group_add_actions (action_group, entries, n_entries, view);
359 gtk_ui_manager_insert_action_group (priv->ui, action_group, 0);
361 if (!gtk_ui_manager_add_ui_from_string (priv->ui, ui_info, -1, &error)) {
362 g_warning ("Could not build contact menus from string:'%s'", error->message);
363 g_error_free (error);
366 g_object_unref (action_group);
368 gtk_tree_view_set_row_separator_func (GTK_TREE_VIEW (view),
369 empathy_contact_list_store_row_separator_func,
372 /* Connect to tree view signals rather than override. */
373 g_signal_connect (view,
374 "button-press-event",
375 G_CALLBACK (contact_list_view_button_press_event_cb),
377 g_signal_connect (view,
379 G_CALLBACK (contact_list_view_row_activated_cb),
381 g_signal_connect (view,
383 G_CALLBACK (contact_list_view_row_expand_or_collapse_cb),
384 GINT_TO_POINTER (TRUE));
385 g_signal_connect (view,
387 G_CALLBACK (contact_list_view_row_expand_or_collapse_cb),
388 GINT_TO_POINTER (FALSE));
392 contact_list_view_finalize (GObject *object)
394 EmpathyContactListViewPriv *priv;
396 priv = GET_PRIV (object);
399 g_object_unref (priv->ui);
402 g_object_unref (priv->store);
405 G_OBJECT_CLASS (empathy_contact_list_view_parent_class)->finalize (object);
409 contact_list_view_get_property (GObject *object,
414 EmpathyContactListViewPriv *priv;
416 priv = GET_PRIV (object);
420 g_value_set_flags (value, priv->features);
423 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
429 contact_list_view_set_property (GObject *object,
434 EmpathyContactListView *view = EMPATHY_CONTACT_LIST_VIEW (object);
435 EmpathyContactListViewPriv *priv;
437 priv = GET_PRIV (object);
441 empathy_contact_list_view_set_features (view, g_value_get_flags (value));
444 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
449 EmpathyContactListView *
450 empathy_contact_list_view_new (EmpathyContactListStore *store,
451 EmpathyContactListFeatures features)
453 EmpathyContactListView *view;
454 EmpathyContactListViewPriv *priv;
456 g_return_val_if_fail (EMPATHY_IS_CONTACT_LIST_STORE (store), NULL);
458 view = g_object_new (EMPATHY_TYPE_CONTACT_LIST_VIEW,
459 "features", features,
462 priv = GET_PRIV (view);
463 priv->store = g_object_ref (store);
464 contact_list_view_setup (EMPATHY_CONTACT_LIST_VIEW (view));
470 empathy_contact_list_view_set_features (EmpathyContactListView *view,
471 EmpathyContactListFeatures features)
473 EmpathyContactListViewPriv *priv = GET_PRIV (view);
475 g_return_if_fail (EMPATHY_IS_CONTACT_LIST_VIEW (view));
477 priv->features = features;
479 /* Update DnD source/dest */
480 if (features & EMPATHY_CONTACT_LIST_FEATURE_CONTACT_DRAG) {
481 gtk_drag_source_set (GTK_WIDGET (view),
484 G_N_ELEMENTS (drag_types_source),
485 GDK_ACTION_MOVE | GDK_ACTION_COPY);
487 gtk_drag_source_unset (GTK_WIDGET (view));
491 if (features & EMPATHY_CONTACT_LIST_FEATURE_CONTACT_DROP) {
492 gtk_drag_dest_set (GTK_WIDGET (view),
493 GTK_DEST_DEFAULT_ALL,
495 G_N_ELEMENTS (drag_types_dest),
496 GDK_ACTION_MOVE | GDK_ACTION_COPY);
498 /* FIXME: URI could still be droped depending on FT feature */
499 gtk_drag_dest_unset (GTK_WIDGET (view));
502 g_object_notify (G_OBJECT (view), "features");
505 EmpathyContactListFeatures
506 empathy_contact_list_view_get_features (EmpathyContactListView *view)
508 EmpathyContactListViewPriv *priv = GET_PRIV (view);
510 g_return_val_if_fail (EMPATHY_IS_CONTACT_LIST_VIEW (view), FALSE);
512 return priv->features;
516 empathy_contact_list_view_get_selected (EmpathyContactListView *view)
518 EmpathyContactListViewPriv *priv;
519 GtkTreeSelection *selection;
522 EmpathyContact *contact;
524 g_return_val_if_fail (EMPATHY_IS_CONTACT_LIST_VIEW (view), NULL);
526 priv = GET_PRIV (view);
528 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (view));
529 if (!gtk_tree_selection_get_selected (selection, &model, &iter)) {
533 gtk_tree_model_get (model, &iter,
534 EMPATHY_CONTACT_LIST_STORE_COL_CONTACT, &contact,
541 empathy_contact_list_view_get_selected_group (EmpathyContactListView *view)
543 EmpathyContactListViewPriv *priv;
544 GtkTreeSelection *selection;
550 g_return_val_if_fail (EMPATHY_IS_CONTACT_LIST_VIEW (view), NULL);
552 priv = GET_PRIV (view);
554 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (view));
555 if (!gtk_tree_selection_get_selected (selection, &model, &iter)) {
559 gtk_tree_model_get (model, &iter,
560 EMPATHY_CONTACT_LIST_STORE_COL_IS_GROUP, &is_group,
561 EMPATHY_CONTACT_LIST_STORE_COL_NAME, &name,
573 contact_list_view_setup (EmpathyContactListView *view)
575 EmpathyContactListViewPriv *priv;
576 GtkCellRenderer *cell;
577 GtkTreeViewColumn *col;
580 priv = GET_PRIV (view);
582 gtk_tree_view_set_search_equal_func (GTK_TREE_VIEW (view),
583 empathy_contact_list_store_search_equal_func,
586 g_signal_connect (priv->store, "row-has-child-toggled",
587 G_CALLBACK (contact_list_view_row_has_child_toggled_cb),
589 gtk_tree_view_set_model (GTK_TREE_VIEW (view),
590 GTK_TREE_MODEL (priv->store));
594 "headers-visible", FALSE,
596 "show-expanders", FALSE,
599 col = gtk_tree_view_column_new ();
602 cell = gtk_cell_renderer_pixbuf_new ();
603 gtk_tree_view_column_pack_start (col, cell, FALSE);
604 gtk_tree_view_column_set_cell_data_func (
606 (GtkTreeCellDataFunc) contact_list_view_pixbuf_cell_data_func,
616 cell = empathy_cell_renderer_text_new ();
617 gtk_tree_view_column_pack_start (col, cell, TRUE);
618 gtk_tree_view_column_set_cell_data_func (
620 (GtkTreeCellDataFunc) contact_list_view_text_cell_data_func,
623 gtk_tree_view_column_add_attribute (col, cell,
624 "name", EMPATHY_CONTACT_LIST_STORE_COL_NAME);
625 gtk_tree_view_column_add_attribute (col, cell,
626 "status", EMPATHY_CONTACT_LIST_STORE_COL_STATUS);
627 gtk_tree_view_column_add_attribute (col, cell,
628 "is_group", EMPATHY_CONTACT_LIST_STORE_COL_IS_GROUP);
631 /* Voip Capability Icon */
632 cell = empathy_cell_renderer_activatable_new ();
633 gtk_tree_view_column_pack_start (col, cell, FALSE);
634 gtk_tree_view_column_set_cell_data_func (
636 (GtkTreeCellDataFunc) contact_list_view_voip_cell_data_func,
643 g_signal_connect (cell, "path-activated",
644 G_CALLBACK (contact_list_view_voip_activated_cb),
649 cell = gtk_cell_renderer_pixbuf_new ();
650 gtk_tree_view_column_pack_start (col, cell, FALSE);
651 gtk_tree_view_column_set_cell_data_func (
653 (GtkTreeCellDataFunc) contact_list_view_avatar_cell_data_func,
665 cell = empathy_cell_renderer_expander_new ();
666 gtk_tree_view_column_pack_end (col, cell, FALSE);
667 gtk_tree_view_column_set_cell_data_func (
669 (GtkTreeCellDataFunc) contact_list_view_expander_cell_data_func,
672 /* Actually add the column now we have added all cell renderers */
673 gtk_tree_view_append_column (GTK_TREE_VIEW (view), col);
676 for (i = 0; i < G_N_ELEMENTS (drag_types_dest); ++i) {
677 drag_atoms_dest[i] = gdk_atom_intern (drag_types_dest[i].target,
681 for (i = 0; i < G_N_ELEMENTS (drag_types_source); ++i) {
682 drag_atoms_source[i] = gdk_atom_intern (drag_types_source[i].target,
688 contact_list_view_row_has_child_toggled_cb (GtkTreeModel *model,
691 EmpathyContactListView *view)
693 EmpathyContactListViewPriv *priv = GET_PRIV (view);
694 gboolean is_group = FALSE;
697 gtk_tree_model_get (model, iter,
698 EMPATHY_CONTACT_LIST_STORE_COL_IS_GROUP, &is_group,
699 EMPATHY_CONTACT_LIST_STORE_COL_NAME, &name,
702 if (!is_group || G_STR_EMPTY (name)) {
707 if (!(priv->features & EMPATHY_CONTACT_LIST_FEATURE_GROUPS_SAVE) ||
708 empathy_contact_group_get_expanded (name)) {
709 g_signal_handlers_block_by_func (view,
710 contact_list_view_row_expand_or_collapse_cb,
711 GINT_TO_POINTER (TRUE));
712 gtk_tree_view_expand_row (GTK_TREE_VIEW (view), path, TRUE);
713 g_signal_handlers_unblock_by_func (view,
714 contact_list_view_row_expand_or_collapse_cb,
715 GINT_TO_POINTER (TRUE));
717 g_signal_handlers_block_by_func (view,
718 contact_list_view_row_expand_or_collapse_cb,
719 GINT_TO_POINTER (FALSE));
720 gtk_tree_view_collapse_row (GTK_TREE_VIEW (view), path);
721 g_signal_handlers_unblock_by_func (view,
722 contact_list_view_row_expand_or_collapse_cb,
723 GINT_TO_POINTER (FALSE));
730 contact_list_view_drag_data_received (GtkWidget *widget,
731 GdkDragContext *context,
734 GtkSelectionData *selection,
738 EmpathyContactListViewPriv *priv;
739 EmpathyContactList *list;
740 EmpathyContactFactory *factory;
744 GtkTreeViewDropPosition position;
745 EmpathyContact *contact = NULL;
748 gchar *new_group = NULL;
749 gchar *old_group = NULL;
752 priv = GET_PRIV (widget);
754 id = (const gchar*) selection->data;
755 empathy_debug (DEBUG_DOMAIN, "Received %s%s drag & drop contact from roster with id:'%s'",
756 context->action == GDK_ACTION_MOVE ? "move" : "",
757 context->action == GDK_ACTION_COPY ? "copy" : "",
760 strv = g_strsplit (id, "/", 2);
761 factory = empathy_contact_factory_new ();
762 account = mc_account_lookup (strv[0]);
764 contact = empathy_contact_factory_get_from_id (factory,
767 g_object_unref (account);
769 g_object_unref (factory);
773 empathy_debug (DEBUG_DOMAIN, "No contact found associated with drag & drop");
777 empathy_contact_run_until_ready (contact,
778 EMPATHY_CONTACT_READY_HANDLE,
781 model = gtk_tree_view_get_model (GTK_TREE_VIEW (widget));
783 /* Get source group information. */
784 if (priv->drag_row) {
785 path = gtk_tree_row_reference_get_path (priv->drag_row);
787 old_group = empathy_contact_list_store_get_parent_group (model, path, NULL);
788 gtk_tree_path_free (path);
792 /* Get destination group information. */
793 is_row = gtk_tree_view_get_dest_row_at_pos (GTK_TREE_VIEW (widget),
800 new_group = empathy_contact_list_store_get_parent_group (model, path, NULL);
801 gtk_tree_path_free (path);
804 empathy_debug (DEBUG_DOMAIN,
805 "contact %s (%d) dragged from '%s' to '%s'",
806 empathy_contact_get_id (contact),
807 empathy_contact_get_handle (contact),
808 old_group, new_group);
810 list = empathy_contact_list_store_get_list_iface (priv->store);
812 empathy_contact_list_add_to_group (list, contact, new_group);
814 if (old_group && context->action == GDK_ACTION_MOVE) {
815 empathy_contact_list_remove_from_group (list, contact, old_group);
821 gtk_drag_finish (context, TRUE, FALSE, GDK_CURRENT_TIME);
825 contact_list_view_drag_motion (GtkWidget *widget,
826 GdkDragContext *context,
831 static DragMotionData *dm = NULL;
834 gboolean is_different = FALSE;
835 gboolean cleanup = TRUE;
837 is_row = gtk_tree_view_get_path_at_pos (GTK_TREE_VIEW (widget),
848 cleanup &= (dm && gtk_tree_path_compare (dm->path, path) != 0);
849 is_different = (!dm || (dm && gtk_tree_path_compare (dm->path, path) != 0));
854 if (!is_different && !cleanup) {
859 gtk_tree_path_free (dm->path);
860 if (dm->timeout_id) {
861 g_source_remove (dm->timeout_id);
869 if (!gtk_tree_view_row_expanded (GTK_TREE_VIEW (widget), path)) {
870 dm = g_new0 (DragMotionData, 1);
872 dm->view = EMPATHY_CONTACT_LIST_VIEW (widget);
873 dm->path = gtk_tree_path_copy (path);
875 dm->timeout_id = g_timeout_add_seconds (1,
876 (GSourceFunc) contact_list_view_drag_motion_cb,
884 contact_list_view_drag_motion_cb (DragMotionData *data)
886 gtk_tree_view_expand_row (GTK_TREE_VIEW (data->view),
890 data->timeout_id = 0;
896 contact_list_view_drag_begin (GtkWidget *widget,
897 GdkDragContext *context)
899 EmpathyContactListViewPriv *priv;
900 GtkTreeSelection *selection;
905 priv = GET_PRIV (widget);
907 GTK_WIDGET_CLASS (empathy_contact_list_view_parent_class)->drag_begin (widget,
910 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (widget));
911 if (!gtk_tree_selection_get_selected (selection, &model, &iter)) {
915 path = gtk_tree_model_get_path (model, &iter);
916 priv->drag_row = gtk_tree_row_reference_new (model, path);
917 gtk_tree_path_free (path);
921 contact_list_view_drag_data_get (GtkWidget *widget,
922 GdkDragContext *context,
923 GtkSelectionData *selection,
927 EmpathyContactListViewPriv *priv;
928 GtkTreePath *src_path;
931 EmpathyContact *contact;
933 const gchar *contact_id;
934 const gchar *account_id;
937 priv = GET_PRIV (widget);
939 model = gtk_tree_view_get_model (GTK_TREE_VIEW (widget));
940 if (!priv->drag_row) {
944 src_path = gtk_tree_row_reference_get_path (priv->drag_row);
949 if (!gtk_tree_model_get_iter (model, &iter, src_path)) {
950 gtk_tree_path_free (src_path);
954 gtk_tree_path_free (src_path);
956 contact = empathy_contact_list_view_get_selected (EMPATHY_CONTACT_LIST_VIEW (widget));
961 account = empathy_contact_get_account (contact);
962 account_id = mc_account_get_unique_name (account);
963 contact_id = empathy_contact_get_id (contact);
964 g_object_unref (contact);
965 str = g_strconcat (account_id, "/", contact_id, NULL);
968 case DND_DRAG_TYPE_CONTACT_ID:
969 gtk_selection_data_set (selection, drag_atoms_source[info], 8,
970 (guchar*)str, strlen (str) + 1);
978 contact_list_view_drag_end (GtkWidget *widget,
979 GdkDragContext *context)
981 EmpathyContactListViewPriv *priv;
983 priv = GET_PRIV (widget);
985 GTK_WIDGET_CLASS (empathy_contact_list_view_parent_class)->drag_end (widget,
988 if (priv->drag_row) {
989 gtk_tree_row_reference_free (priv->drag_row);
990 priv->drag_row = NULL;
995 contact_list_view_drag_drop (GtkWidget *widget,
996 GdkDragContext *drag_context,
1005 contact_list_view_cell_set_background (EmpathyContactListView *view,
1006 GtkCellRenderer *cell,
1013 style = gtk_widget_get_style (GTK_WIDGET (view));
1015 if (!is_group && is_active) {
1016 color = style->bg[GTK_STATE_SELECTED];
1018 /* Here we take the current theme colour and add it to
1019 * the colour for white and average the two. This
1020 * gives a colour which is inline with the theme but
1023 color.red = (color.red + (style->white).red) / 2;
1024 color.green = (color.green + (style->white).green) / 2;
1025 color.blue = (color.blue + (style->white).blue) / 2;
1028 "cell-background-gdk", &color,
1032 "cell-background-gdk", NULL,
1038 contact_list_view_pixbuf_cell_data_func (GtkTreeViewColumn *tree_column,
1039 GtkCellRenderer *cell,
1040 GtkTreeModel *model,
1042 EmpathyContactListView *view)
1048 gtk_tree_model_get (model, iter,
1049 EMPATHY_CONTACT_LIST_STORE_COL_IS_GROUP, &is_group,
1050 EMPATHY_CONTACT_LIST_STORE_COL_IS_ACTIVE, &is_active,
1051 EMPATHY_CONTACT_LIST_STORE_COL_ICON_STATUS, &icon_name,
1055 "visible", !is_group,
1056 "icon-name", icon_name,
1061 contact_list_view_cell_set_background (view, cell, is_group, is_active);
1066 contact_list_view_voip_cell_data_func (GtkTreeViewColumn *tree_column,
1067 GtkCellRenderer *cell,
1068 GtkTreeModel *model,
1070 EmpathyContactListView *view)
1076 gtk_tree_model_get (model, iter,
1077 EMPATHY_CONTACT_LIST_STORE_COL_IS_GROUP, &is_group,
1078 EMPATHY_CONTACT_LIST_STORE_COL_IS_ACTIVE, &is_active,
1079 EMPATHY_CONTACT_LIST_STORE_COL_CAN_VOIP, &can_voip,
1083 "visible", !is_group && can_voip,
1084 "icon-name", EMPATHY_IMAGE_VOIP,
1087 contact_list_view_cell_set_background (view, cell, is_group, is_active);
1092 contact_list_view_avatar_cell_data_func (GtkTreeViewColumn *tree_column,
1093 GtkCellRenderer *cell,
1094 GtkTreeModel *model,
1096 EmpathyContactListView *view)
1099 gboolean show_avatar;
1103 gtk_tree_model_get (model, iter,
1104 EMPATHY_CONTACT_LIST_STORE_COL_PIXBUF_AVATAR, &pixbuf,
1105 EMPATHY_CONTACT_LIST_STORE_COL_PIXBUF_AVATAR_VISIBLE, &show_avatar,
1106 EMPATHY_CONTACT_LIST_STORE_COL_IS_GROUP, &is_group,
1107 EMPATHY_CONTACT_LIST_STORE_COL_IS_ACTIVE, &is_active,
1111 "visible", !is_group && show_avatar,
1116 g_object_unref (pixbuf);
1119 contact_list_view_cell_set_background (view, cell, is_group, is_active);
1123 contact_list_view_text_cell_data_func (GtkTreeViewColumn *tree_column,
1124 GtkCellRenderer *cell,
1125 GtkTreeModel *model,
1127 EmpathyContactListView *view)
1131 gboolean show_status;
1133 gtk_tree_model_get (model, iter,
1134 EMPATHY_CONTACT_LIST_STORE_COL_IS_GROUP, &is_group,
1135 EMPATHY_CONTACT_LIST_STORE_COL_IS_ACTIVE, &is_active,
1136 EMPATHY_CONTACT_LIST_STORE_COL_STATUS_VISIBLE, &show_status,
1140 "show-status", show_status,
1143 contact_list_view_cell_set_background (view, cell, is_group, is_active);
1147 contact_list_view_expander_cell_data_func (GtkTreeViewColumn *column,
1148 GtkCellRenderer *cell,
1149 GtkTreeModel *model,
1151 EmpathyContactListView *view)
1156 gtk_tree_model_get (model, iter,
1157 EMPATHY_CONTACT_LIST_STORE_COL_IS_GROUP, &is_group,
1158 EMPATHY_CONTACT_LIST_STORE_COL_IS_ACTIVE, &is_active,
1161 if (gtk_tree_model_iter_has_child (model, iter)) {
1163 gboolean row_expanded;
1165 path = gtk_tree_model_get_path (model, iter);
1166 row_expanded = gtk_tree_view_row_expanded (GTK_TREE_VIEW (column->tree_view), path);
1167 gtk_tree_path_free (path);
1171 "expander-style", row_expanded ? GTK_EXPANDER_EXPANDED : GTK_EXPANDER_COLLAPSED,
1174 g_object_set (cell, "visible", FALSE, NULL);
1177 contact_list_view_cell_set_background (view, cell, is_group, is_active);
1181 contact_list_view_get_contact_menu (EmpathyContactListView *view,
1182 gboolean can_send_file,
1183 gboolean can_show_log,
1186 EmpathyContactListViewPriv *priv = GET_PRIV (view);
1189 if (!(priv->features & (EMPATHY_CONTACT_LIST_FEATURE_CONTACT_CHAT |
1190 EMPATHY_CONTACT_LIST_FEATURE_CONTACT_CALL |
1191 EMPATHY_CONTACT_LIST_FEATURE_CONTACT_LOG |
1192 EMPATHY_CONTACT_LIST_FEATURE_CONTACT_FT |
1193 EMPATHY_CONTACT_LIST_FEATURE_CONTACT_INVITE |
1194 EMPATHY_CONTACT_LIST_FEATURE_CONTACT_EDIT |
1195 EMPATHY_CONTACT_LIST_FEATURE_CONTACT_INFO |
1196 EMPATHY_CONTACT_LIST_FEATURE_CONTACT_REMOVE))) {
1200 /* Sort out sensitive/visible items */
1201 action = gtk_ui_manager_get_action (priv->ui, "/Contact/Chat");
1202 gtk_action_set_visible (action, priv->features & EMPATHY_CONTACT_LIST_FEATURE_CONTACT_CHAT);
1205 action = gtk_ui_manager_get_action (priv->ui, "/Contact/Call");
1206 gtk_action_set_sensitive (action, can_voip);
1207 gtk_action_set_visible (action, priv->features & EMPATHY_CONTACT_LIST_FEATURE_CONTACT_CALL);
1210 action = gtk_ui_manager_get_action (priv->ui, "/Contact/Log");
1211 gtk_action_set_sensitive (action, can_show_log);
1212 gtk_action_set_visible (action, priv->features & EMPATHY_CONTACT_LIST_FEATURE_CONTACT_LOG);
1215 action = gtk_ui_manager_get_action (priv->ui, "/Contact/SendFile");
1216 gtk_action_set_visible (action, can_send_file && (priv->features & EMPATHY_CONTACT_LIST_FEATURE_CONTACT_FT));
1218 action = gtk_ui_manager_get_action (priv->ui, "/Contact/Invite");
1219 gtk_action_set_visible (action, priv->features & EMPATHY_CONTACT_LIST_FEATURE_CONTACT_INVITE);
1221 action = gtk_ui_manager_get_action (priv->ui, "/Contact/Edit");
1222 gtk_action_set_visible (action, priv->features & EMPATHY_CONTACT_LIST_FEATURE_CONTACT_EDIT);
1224 action = gtk_ui_manager_get_action (priv->ui, "/Contact/Information");
1225 gtk_action_set_visible (action, priv->features & EMPATHY_CONTACT_LIST_FEATURE_CONTACT_INFO);
1227 action = gtk_ui_manager_get_action (priv->ui, "/Contact/Remove");
1228 gtk_action_set_visible (action, priv->features & EMPATHY_CONTACT_LIST_FEATURE_CONTACT_REMOVE);
1230 return gtk_ui_manager_get_widget (priv->ui, "/Contact");
1234 empathy_contact_list_view_get_group_menu (EmpathyContactListView *view)
1236 EmpathyContactListViewPriv *priv = GET_PRIV (view);
1239 g_return_val_if_fail (EMPATHY_IS_CONTACT_LIST_VIEW (view), NULL);
1241 if (!(priv->features & (EMPATHY_CONTACT_LIST_FEATURE_GROUPS_RENAME |
1242 EMPATHY_CONTACT_LIST_FEATURE_GROUPS_REMOVE))) {
1246 action = gtk_ui_manager_get_action (priv->ui, "/Group/Rename");
1247 gtk_action_set_visible (action, priv->features & EMPATHY_CONTACT_LIST_FEATURE_GROUPS_RENAME);
1249 action = gtk_ui_manager_get_action (priv->ui, "/Group/Remove");
1250 gtk_action_set_visible (action, priv->features & EMPATHY_CONTACT_LIST_FEATURE_GROUPS_REMOVE);
1252 return gtk_ui_manager_get_widget (priv->ui, "/Group");
1256 empathy_contact_list_view_get_contact_menu (EmpathyContactListView *view,
1257 EmpathyContact *contact)
1259 EmpathyLogManager *log_manager;
1260 gboolean can_show_log;
1261 gboolean can_send_file;
1264 g_return_val_if_fail (EMPATHY_IS_CONTACT_LIST_VIEW (view), NULL);
1265 g_return_val_if_fail (EMPATHY_IS_CONTACT (contact), NULL);
1267 log_manager = empathy_log_manager_new ();
1268 can_show_log = empathy_log_manager_exists (log_manager,
1269 empathy_contact_get_account (contact),
1270 empathy_contact_get_id (contact),
1272 g_object_unref (log_manager);
1273 can_send_file = FALSE;
1274 can_voip = empathy_contact_can_voip (contact);
1276 return contact_list_view_get_contact_menu (view,
1283 contact_list_view_button_press_event_cb (EmpathyContactListView *view,
1284 GdkEventButton *event,
1287 EmpathyContactListViewPriv *priv;
1288 EmpathyContact *contact;
1290 GtkTreeSelection *selection;
1291 GtkTreeModel *model;
1293 gboolean row_exists;
1296 priv = GET_PRIV (view);
1298 if (event->button != 3) {
1302 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (view));
1303 model = gtk_tree_view_get_model (GTK_TREE_VIEW (view));
1305 gtk_widget_grab_focus (GTK_WIDGET (view));
1307 row_exists = gtk_tree_view_get_path_at_pos (GTK_TREE_VIEW (view),
1315 gtk_tree_selection_unselect_all (selection);
1316 gtk_tree_selection_select_path (selection, path);
1318 gtk_tree_model_get_iter (model, &iter, path);
1319 gtk_tree_path_free (path);
1321 gtk_tree_model_get (model, &iter,
1322 EMPATHY_CONTACT_LIST_STORE_COL_CONTACT, &contact,
1326 menu = empathy_contact_list_view_get_contact_menu (view, contact);
1327 g_object_unref (contact);
1329 menu = empathy_contact_list_view_get_group_menu (view);
1336 gtk_widget_show (menu);
1338 gtk_menu_popup (GTK_MENU (menu),
1339 NULL, NULL, NULL, NULL,
1340 event->button, event->time);
1346 contact_list_view_row_activated_cb (EmpathyContactListView *view,
1348 GtkTreeViewColumn *col,
1351 EmpathyContactListViewPriv *priv = GET_PRIV (view);
1352 EmpathyContact *contact;
1353 GtkTreeModel *model;
1356 if (!(priv->features & EMPATHY_CONTACT_LIST_FEATURE_CONTACT_CHAT)) {
1360 model = gtk_tree_view_get_model (GTK_TREE_VIEW (view));
1362 gtk_tree_model_get_iter (model, &iter, path);
1363 gtk_tree_model_get (model, &iter,
1364 EMPATHY_CONTACT_LIST_STORE_COL_CONTACT, &contact,
1368 empathy_chat_with_contact (contact);
1369 g_object_unref (contact);
1375 contact_list_view_voip_activated_cb (EmpathyCellRendererActivatable *cell,
1376 const gchar *path_string,
1377 EmpathyContactListView *view)
1379 EmpathyContactListViewPriv *priv = GET_PRIV (view);
1380 GtkTreeModel *model;
1382 EmpathyContact *contact;
1384 if (!(priv->features & EMPATHY_CONTACT_LIST_FEATURE_CONTACT_CALL)) {
1388 model = gtk_tree_view_get_model (GTK_TREE_VIEW (view));
1389 if (!gtk_tree_model_get_iter_from_string (model, &iter, path_string)) {
1393 gtk_tree_model_get (model, &iter,
1394 EMPATHY_CONTACT_LIST_STORE_COL_CONTACT, &contact,
1398 contact_list_view_voip_activated (view, contact);
1399 g_object_unref (contact);
1406 contact_list_view_row_expand_or_collapse_cb (EmpathyContactListView *view,
1411 EmpathyContactListViewPriv *priv = GET_PRIV (view);
1412 GtkTreeModel *model;
1416 if (!(priv->features & EMPATHY_CONTACT_LIST_FEATURE_GROUPS_SAVE)) {
1420 model = gtk_tree_view_get_model (GTK_TREE_VIEW (view));
1422 gtk_tree_model_get (model, iter,
1423 EMPATHY_CONTACT_LIST_STORE_COL_NAME, &name,
1426 expanded = GPOINTER_TO_INT (user_data);
1427 empathy_contact_group_set_expanded (name, expanded);
1433 contact_list_view_action_cb (GtkAction *action,
1434 EmpathyContactListView *view)
1436 EmpathyContactListViewPriv *priv;
1437 EmpathyContact *contact;
1442 priv = GET_PRIV (view);
1444 name = gtk_action_get_name (action);
1449 empathy_debug (DEBUG_DOMAIN, "Action:'%s' activated", name);
1451 contact = empathy_contact_list_view_get_selected (view);
1452 group = empathy_contact_list_view_get_selected_group (view);
1453 parent = empathy_get_toplevel_window (GTK_WIDGET (view));
1455 if (contact && strcmp (name, "Chat") == 0) {
1456 empathy_chat_with_contact (contact);
1458 else if (contact && strcmp (name, "Call") == 0) {
1459 contact_list_view_voip_activated (view, contact);
1461 else if (contact && strcmp (name, "Information") == 0) {
1462 empathy_contact_information_dialog_show (contact, parent, FALSE, FALSE);
1464 else if (contact && strcmp (name, "Edit") == 0) {
1465 empathy_contact_information_dialog_show (contact, parent, TRUE, FALSE);
1467 else if (contact && strcmp (name, "Remove") == 0) {
1468 /* FIXME: Ask for confirmation */
1469 EmpathyContactList *list;
1471 list = empathy_contact_list_store_get_list_iface (priv->store);
1472 empathy_contact_list_remove (list, contact,
1473 _("Sorry, I don't want you in my contact list anymore."));
1475 else if (contact && strcmp (name, "Invite") == 0) {
1477 else if (contact && strcmp (name, "SendFile") == 0) {
1479 else if (contact && strcmp (name, "Log") == 0) {
1480 empathy_log_window_show (empathy_contact_get_account (contact),
1481 empathy_contact_get_id (contact),
1485 else if (group && strcmp (name, "Rename") == 0) {
1487 else if (group && strcmp (name, "Remove") == 0) {
1488 EmpathyContactList *list;
1490 list = empathy_contact_list_store_get_list_iface (priv->store);
1491 empathy_contact_list_remove_group (list, group);
1496 g_object_unref (contact);
1501 contact_list_view_voip_activated (EmpathyContactListView *view,
1502 EmpathyContact *contact)
1504 empathy_call_with_contact (contact);