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 <libmissioncontrol/mc-account.h>
35 #include <libmissioncontrol/mission-control.h>
37 #include <libempathy/empathy-contact-factory.h>
38 #include <libempathy/empathy-contact-list.h>
39 #include <libempathy/empathy-log-manager.h>
40 #include <libempathy/empathy-tp-group.h>
41 #include <libempathy/empathy-contact-groups.h>
42 #include <libempathy/empathy-debug.h>
43 #include <libempathy/empathy-utils.h>
45 #include "empathy-contact-list-view.h"
46 #include "empathy-contact-list-store.h"
47 #include "empathy-images.h"
48 #include "empathy-cell-renderer-expander.h"
49 #include "empathy-cell-renderer-text.h"
50 #include "empathy-cell-renderer-activatable.h"
51 #include "empathy-ui-utils.h"
52 #include "empathy-contact-dialogs.h"
53 //#include "empathy-chat-invite.h"
54 //#include "empathy-ft-window.h"
55 #include "empathy-log-window.h"
56 #include "empathy-gtk-enum-types.h"
57 #include "empathy-gtk-marshal.h"
59 #define DEBUG_DOMAIN "ContactListView"
61 /* Flashing delay for icons (milliseconds). */
62 #define FLASH_TIMEOUT 500
64 /* Active users are those which have recently changed state
65 * (e.g. online, offline or from normal to a busy state).
68 #define GET_PRIV(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), EMPATHY_TYPE_CONTACT_LIST_VIEW, EmpathyContactListViewPriv))
71 EmpathyContactListStore *store;
73 GtkTreeRowReference *drag_row;
74 EmpathyContactListFeatures features;
75 } EmpathyContactListViewPriv;
78 EmpathyContactListView *view;
84 EmpathyContactListView *view;
85 EmpathyContact *contact;
89 static void empathy_contact_list_view_class_init (EmpathyContactListViewClass *klass);
90 static void empathy_contact_list_view_init (EmpathyContactListView *list);
91 static void contact_list_view_finalize (GObject *object);
92 static void contact_list_view_get_property (GObject *object,
96 static void contact_list_view_set_property (GObject *object,
100 static void contact_list_view_setup (EmpathyContactListView *view);
101 static void contact_list_view_row_has_child_toggled_cb (GtkTreeModel *model,
104 EmpathyContactListView *view);
105 static void contact_list_view_drag_data_received (GtkWidget *widget,
106 GdkDragContext *context,
109 GtkSelectionData *selection,
112 static gboolean contact_list_view_drag_motion (GtkWidget *widget,
113 GdkDragContext *context,
117 static gboolean contact_list_view_drag_motion_cb (DragMotionData *data);
118 static void contact_list_view_drag_begin (GtkWidget *widget,
119 GdkDragContext *context);
120 static void contact_list_view_drag_data_get (GtkWidget *widget,
121 GdkDragContext *context,
122 GtkSelectionData *selection,
125 static void contact_list_view_drag_end (GtkWidget *widget,
126 GdkDragContext *context);
127 static gboolean contact_list_view_drag_drop (GtkWidget *widget,
128 GdkDragContext *drag_context,
132 static void contact_list_view_cell_set_background (EmpathyContactListView *view,
133 GtkCellRenderer *cell,
136 static void contact_list_view_pixbuf_cell_data_func (GtkTreeViewColumn *tree_column,
137 GtkCellRenderer *cell,
140 EmpathyContactListView *view);
141 static void contact_list_view_voip_cell_data_func (GtkTreeViewColumn *tree_column,
142 GtkCellRenderer *cell,
145 EmpathyContactListView *view);
146 static void contact_list_view_avatar_cell_data_func (GtkTreeViewColumn *tree_column,
147 GtkCellRenderer *cell,
150 EmpathyContactListView *view);
151 static void contact_list_view_text_cell_data_func (GtkTreeViewColumn *tree_column,
152 GtkCellRenderer *cell,
155 EmpathyContactListView *view);
156 static void contact_list_view_expander_cell_data_func (GtkTreeViewColumn *column,
157 GtkCellRenderer *cell,
160 EmpathyContactListView *view);
161 static GtkWidget * contact_list_view_get_contact_menu (EmpathyContactListView *view,
162 gboolean can_send_file,
163 gboolean can_show_log,
165 static gboolean contact_list_view_button_press_event_cb (EmpathyContactListView *view,
166 GdkEventButton *event,
168 static void contact_list_view_row_activated_cb (EmpathyContactListView *view,
170 GtkTreeViewColumn *col,
172 static void contact_list_view_voip_activated_cb (EmpathyCellRendererActivatable *cell,
173 const gchar *path_string,
174 EmpathyContactListView *view);
175 static void contact_list_view_row_expand_or_collapse_cb (EmpathyContactListView *view,
179 static void contact_list_view_action_cb (GtkAction *action,
180 EmpathyContactListView *view);
181 static void contact_list_view_voip_activated (EmpathyContactListView *view,
182 EmpathyContact *contact);
183 static gboolean contact_list_view_remove_dialog_show (GtkWindow *parent,
184 const gchar *window_title,
192 static const GtkActionEntry entries[] = {
193 { "ContactMenu", NULL,
194 N_("_Contact"), NULL, NULL,
198 N_("_Group"),NULL, NULL,
201 { "Chat", EMPATHY_IMAGE_MESSAGE,
202 N_("_Chat"), NULL, N_("Chat with contact"),
203 G_CALLBACK (contact_list_view_action_cb)
205 { "Information", EMPATHY_IMAGE_CONTACT_INFORMATION,
206 N_("Infor_mation"), "<control>I", N_("View contact information"),
207 G_CALLBACK (contact_list_view_action_cb)
210 N_("Re_name"), NULL, N_("Rename"),
211 G_CALLBACK (contact_list_view_action_cb)
213 { "Edit", GTK_STOCK_EDIT,
214 N_("_Edit"), NULL, N_("Edit the groups and name for this contact"),
215 G_CALLBACK (contact_list_view_action_cb)
217 { "Remove", GTK_STOCK_REMOVE,
218 N_("_Remove"), NULL, N_("Remove contact"),
219 G_CALLBACK (contact_list_view_action_cb)
221 { "Invite", EMPATHY_IMAGE_GROUP_MESSAGE,
222 N_("_Invite to Chat Room"), NULL, N_("Invite to a currently open chat room"),
223 G_CALLBACK (contact_list_view_action_cb)
226 N_("_Send File..."), NULL, N_("Send a file"),
227 G_CALLBACK (contact_list_view_action_cb)
229 { "Log", EMPATHY_IMAGE_LOG,
230 N_("_View Previous Conversations"), NULL, N_("View previous conversations with this contact"),
231 G_CALLBACK (contact_list_view_action_cb)
233 { "Call", EMPATHY_IMAGE_VOIP,
234 N_("_Call"), NULL, N_("Start a voice or video conversation with this contact"),
235 G_CALLBACK (contact_list_view_action_cb)
239 static guint n_entries = G_N_ELEMENTS (entries);
241 static const gchar *ui_info =
243 " <popup name='Contact'>"
244 " <menuitem action='Chat'/>"
245 " <menuitem action='Call'/>"
246 " <menuitem action='Log'/>"
247 " <menuitem action='SendFile'/>"
249 " <menuitem action='Invite'/>"
251 " <menuitem action='Edit'/>"
252 " <menuitem action='Remove'/>"
254 " <menuitem action='Information'/>"
256 " <popup name='Group'>"
257 " <menuitem action='Rename'/>"
258 " <menuitem action='Remove'/>"
263 DND_DRAG_TYPE_CONTACT_ID,
265 DND_DRAG_TYPE_STRING,
268 static const GtkTargetEntry drag_types_dest[] = {
269 { "text/contact-id", 0, DND_DRAG_TYPE_CONTACT_ID },
270 { "text/uri-list", 0, DND_DRAG_TYPE_URL },
271 { "text/plain", 0, DND_DRAG_TYPE_STRING },
272 { "STRING", 0, DND_DRAG_TYPE_STRING },
275 static const GtkTargetEntry drag_types_source[] = {
276 { "text/contact-id", 0, DND_DRAG_TYPE_CONTACT_ID },
279 static GdkAtom drag_atoms_dest[G_N_ELEMENTS (drag_types_dest)];
280 static GdkAtom drag_atoms_source[G_N_ELEMENTS (drag_types_source)];
283 DRAG_CONTACT_RECEIVED,
287 static guint signals[LAST_SIGNAL];
289 G_DEFINE_TYPE (EmpathyContactListView, empathy_contact_list_view, GTK_TYPE_TREE_VIEW);
292 empathy_contact_list_view_class_init (EmpathyContactListViewClass *klass)
294 GObjectClass *object_class = G_OBJECT_CLASS (klass);
295 GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
297 object_class->finalize = contact_list_view_finalize;
298 object_class->get_property = contact_list_view_get_property;
299 object_class->set_property = contact_list_view_set_property;
301 widget_class->drag_data_received = contact_list_view_drag_data_received;
302 widget_class->drag_drop = contact_list_view_drag_drop;
303 widget_class->drag_begin = contact_list_view_drag_begin;
304 widget_class->drag_data_get = contact_list_view_drag_data_get;
305 widget_class->drag_end = contact_list_view_drag_end;
306 /* FIXME: noticed but when you drag the row over the treeview
307 * fast, it seems to stop redrawing itself, if we don't
308 * connect this signal, all is fine.
310 widget_class->drag_motion = contact_list_view_drag_motion;
312 signals[DRAG_CONTACT_RECEIVED] =
313 g_signal_new ("drag-contact-received",
314 G_OBJECT_CLASS_TYPE (klass),
318 _empathy_gtk_marshal_VOID__OBJECT_STRING_STRING,
320 3, EMPATHY_TYPE_CONTACT, G_TYPE_STRING, G_TYPE_STRING);
322 g_object_class_install_property (object_class,
324 g_param_spec_flags ("features",
325 "Features of the view",
326 "Falgs for all enabled features",
327 EMPATHY_TYPE_CONTACT_LIST_FEATURES,
331 g_type_class_add_private (object_class, sizeof (EmpathyContactListViewPriv));
335 empathy_contact_list_view_init (EmpathyContactListView *view)
337 EmpathyContactListViewPriv *priv;
338 GtkActionGroup *action_group;
339 GError *error = NULL;
341 priv = GET_PRIV (view);
343 /* Get saved group states. */
344 empathy_contact_groups_get_all ();
346 /* Set up UI Manager */
347 priv->ui = gtk_ui_manager_new ();
349 action_group = gtk_action_group_new ("Actions");
350 gtk_action_group_set_translation_domain (action_group, GETTEXT_PACKAGE);
351 gtk_action_group_add_actions (action_group, entries, n_entries, view);
352 gtk_ui_manager_insert_action_group (priv->ui, action_group, 0);
354 if (!gtk_ui_manager_add_ui_from_string (priv->ui, ui_info, -1, &error)) {
355 g_warning ("Could not build contact menus from string:'%s'", error->message);
356 g_error_free (error);
359 g_object_unref (action_group);
361 gtk_tree_view_set_row_separator_func (GTK_TREE_VIEW (view),
362 empathy_contact_list_store_row_separator_func,
365 /* Connect to tree view signals rather than override. */
366 g_signal_connect (view,
367 "button-press-event",
368 G_CALLBACK (contact_list_view_button_press_event_cb),
370 g_signal_connect (view,
372 G_CALLBACK (contact_list_view_row_activated_cb),
374 g_signal_connect (view,
376 G_CALLBACK (contact_list_view_row_expand_or_collapse_cb),
377 GINT_TO_POINTER (TRUE));
378 g_signal_connect (view,
380 G_CALLBACK (contact_list_view_row_expand_or_collapse_cb),
381 GINT_TO_POINTER (FALSE));
385 contact_list_view_finalize (GObject *object)
387 EmpathyContactListViewPriv *priv;
389 priv = GET_PRIV (object);
392 g_object_unref (priv->ui);
395 g_object_unref (priv->store);
398 G_OBJECT_CLASS (empathy_contact_list_view_parent_class)->finalize (object);
402 contact_list_view_get_property (GObject *object,
407 EmpathyContactListViewPriv *priv;
409 priv = GET_PRIV (object);
413 g_value_set_flags (value, priv->features);
416 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
422 contact_list_view_set_property (GObject *object,
427 EmpathyContactListView *view = EMPATHY_CONTACT_LIST_VIEW (object);
428 EmpathyContactListViewPriv *priv;
430 priv = GET_PRIV (object);
434 empathy_contact_list_view_set_features (view, g_value_get_flags (value));
437 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
442 EmpathyContactListView *
443 empathy_contact_list_view_new (EmpathyContactListStore *store,
444 EmpathyContactListFeatures features)
446 EmpathyContactListView *view;
447 EmpathyContactListViewPriv *priv;
449 g_return_val_if_fail (EMPATHY_IS_CONTACT_LIST_STORE (store), NULL);
451 view = g_object_new (EMPATHY_TYPE_CONTACT_LIST_VIEW,
452 "features", features,
455 priv = GET_PRIV (view);
456 priv->store = g_object_ref (store);
457 contact_list_view_setup (EMPATHY_CONTACT_LIST_VIEW (view));
463 empathy_contact_list_view_set_features (EmpathyContactListView *view,
464 EmpathyContactListFeatures features)
466 EmpathyContactListViewPriv *priv = GET_PRIV (view);
468 g_return_if_fail (EMPATHY_IS_CONTACT_LIST_VIEW (view));
470 priv->features = features;
472 /* Update DnD source/dest */
473 if (features & EMPATHY_CONTACT_LIST_FEATURE_CONTACT_DRAG) {
474 gtk_drag_source_set (GTK_WIDGET (view),
477 G_N_ELEMENTS (drag_types_source),
478 GDK_ACTION_MOVE | GDK_ACTION_COPY);
480 gtk_drag_source_unset (GTK_WIDGET (view));
484 if (features & EMPATHY_CONTACT_LIST_FEATURE_CONTACT_DROP) {
485 gtk_drag_dest_set (GTK_WIDGET (view),
486 GTK_DEST_DEFAULT_ALL,
488 G_N_ELEMENTS (drag_types_dest),
489 GDK_ACTION_MOVE | GDK_ACTION_COPY);
491 /* FIXME: URI could still be droped depending on FT feature */
492 gtk_drag_dest_unset (GTK_WIDGET (view));
495 g_object_notify (G_OBJECT (view), "features");
498 EmpathyContactListFeatures
499 empathy_contact_list_view_get_features (EmpathyContactListView *view)
501 EmpathyContactListViewPriv *priv = GET_PRIV (view);
503 g_return_val_if_fail (EMPATHY_IS_CONTACT_LIST_VIEW (view), FALSE);
505 return priv->features;
509 empathy_contact_list_view_get_selected (EmpathyContactListView *view)
511 EmpathyContactListViewPriv *priv;
512 GtkTreeSelection *selection;
515 EmpathyContact *contact;
517 g_return_val_if_fail (EMPATHY_IS_CONTACT_LIST_VIEW (view), NULL);
519 priv = GET_PRIV (view);
521 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (view));
522 if (!gtk_tree_selection_get_selected (selection, &model, &iter)) {
526 gtk_tree_model_get (model, &iter,
527 EMPATHY_CONTACT_LIST_STORE_COL_CONTACT, &contact,
534 empathy_contact_list_view_get_selected_group (EmpathyContactListView *view)
536 EmpathyContactListViewPriv *priv;
537 GtkTreeSelection *selection;
543 g_return_val_if_fail (EMPATHY_IS_CONTACT_LIST_VIEW (view), NULL);
545 priv = GET_PRIV (view);
547 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (view));
548 if (!gtk_tree_selection_get_selected (selection, &model, &iter)) {
552 gtk_tree_model_get (model, &iter,
553 EMPATHY_CONTACT_LIST_STORE_COL_IS_GROUP, &is_group,
554 EMPATHY_CONTACT_LIST_STORE_COL_NAME, &name,
566 contact_list_view_setup (EmpathyContactListView *view)
568 EmpathyContactListViewPriv *priv;
569 GtkCellRenderer *cell;
570 GtkTreeViewColumn *col;
573 priv = GET_PRIV (view);
575 gtk_tree_view_set_search_equal_func (GTK_TREE_VIEW (view),
576 empathy_contact_list_store_search_equal_func,
579 g_signal_connect (priv->store, "row-has-child-toggled",
580 G_CALLBACK (contact_list_view_row_has_child_toggled_cb),
582 gtk_tree_view_set_model (GTK_TREE_VIEW (view),
583 GTK_TREE_MODEL (priv->store));
587 "headers-visible", FALSE,
589 "show-expanders", FALSE,
592 col = gtk_tree_view_column_new ();
595 cell = gtk_cell_renderer_pixbuf_new ();
596 gtk_tree_view_column_pack_start (col, cell, FALSE);
597 gtk_tree_view_column_set_cell_data_func (
599 (GtkTreeCellDataFunc) contact_list_view_pixbuf_cell_data_func,
609 cell = empathy_cell_renderer_text_new ();
610 gtk_tree_view_column_pack_start (col, cell, TRUE);
611 gtk_tree_view_column_set_cell_data_func (
613 (GtkTreeCellDataFunc) contact_list_view_text_cell_data_func,
616 gtk_tree_view_column_add_attribute (col, cell,
617 "name", EMPATHY_CONTACT_LIST_STORE_COL_NAME);
618 gtk_tree_view_column_add_attribute (col, cell,
619 "status", EMPATHY_CONTACT_LIST_STORE_COL_STATUS);
620 gtk_tree_view_column_add_attribute (col, cell,
621 "is_group", EMPATHY_CONTACT_LIST_STORE_COL_IS_GROUP);
623 /* Voip Capability Icon */
624 cell = empathy_cell_renderer_activatable_new ();
625 gtk_tree_view_column_pack_start (col, cell, FALSE);
626 gtk_tree_view_column_set_cell_data_func (
628 (GtkTreeCellDataFunc) contact_list_view_voip_cell_data_func,
635 g_signal_connect (cell, "path-activated",
636 G_CALLBACK (contact_list_view_voip_activated_cb),
640 cell = gtk_cell_renderer_pixbuf_new ();
641 gtk_tree_view_column_pack_start (col, cell, FALSE);
642 gtk_tree_view_column_set_cell_data_func (
644 (GtkTreeCellDataFunc) contact_list_view_avatar_cell_data_func,
656 cell = empathy_cell_renderer_expander_new ();
657 gtk_tree_view_column_pack_end (col, cell, FALSE);
658 gtk_tree_view_column_set_cell_data_func (
660 (GtkTreeCellDataFunc) contact_list_view_expander_cell_data_func,
663 /* Actually add the column now we have added all cell renderers */
664 gtk_tree_view_append_column (GTK_TREE_VIEW (view), col);
667 for (i = 0; i < G_N_ELEMENTS (drag_types_dest); ++i) {
668 drag_atoms_dest[i] = gdk_atom_intern (drag_types_dest[i].target,
672 for (i = 0; i < G_N_ELEMENTS (drag_types_source); ++i) {
673 drag_atoms_source[i] = gdk_atom_intern (drag_types_source[i].target,
679 contact_list_view_row_has_child_toggled_cb (GtkTreeModel *model,
682 EmpathyContactListView *view)
684 EmpathyContactListViewPriv *priv = GET_PRIV (view);
685 gboolean is_group = FALSE;
688 gtk_tree_model_get (model, iter,
689 EMPATHY_CONTACT_LIST_STORE_COL_IS_GROUP, &is_group,
690 EMPATHY_CONTACT_LIST_STORE_COL_NAME, &name,
693 if (!is_group || G_STR_EMPTY (name)) {
698 if (!(priv->features & EMPATHY_CONTACT_LIST_FEATURE_GROUPS_SAVE) ||
699 empathy_contact_group_get_expanded (name)) {
700 g_signal_handlers_block_by_func (view,
701 contact_list_view_row_expand_or_collapse_cb,
702 GINT_TO_POINTER (TRUE));
703 gtk_tree_view_expand_row (GTK_TREE_VIEW (view), path, TRUE);
704 g_signal_handlers_unblock_by_func (view,
705 contact_list_view_row_expand_or_collapse_cb,
706 GINT_TO_POINTER (TRUE));
708 g_signal_handlers_block_by_func (view,
709 contact_list_view_row_expand_or_collapse_cb,
710 GINT_TO_POINTER (FALSE));
711 gtk_tree_view_collapse_row (GTK_TREE_VIEW (view), path);
712 g_signal_handlers_unblock_by_func (view,
713 contact_list_view_row_expand_or_collapse_cb,
714 GINT_TO_POINTER (FALSE));
721 contact_list_view_drag_data_received (GtkWidget *widget,
722 GdkDragContext *context,
725 GtkSelectionData *selection,
729 EmpathyContactListViewPriv *priv;
730 EmpathyContactList *list;
731 EmpathyContactFactory *factory;
735 GtkTreeViewDropPosition position;
736 EmpathyContact *contact = NULL;
739 gchar *new_group = NULL;
740 gchar *old_group = NULL;
743 priv = GET_PRIV (widget);
745 id = (const gchar*) selection->data;
746 empathy_debug (DEBUG_DOMAIN, "Received %s%s drag & drop contact from roster with id:'%s'",
747 context->action == GDK_ACTION_MOVE ? "move" : "",
748 context->action == GDK_ACTION_COPY ? "copy" : "",
751 strv = g_strsplit (id, "/", 2);
752 factory = empathy_contact_factory_new ();
753 account = mc_account_lookup (strv[0]);
755 contact = empathy_contact_factory_get_from_id (factory,
758 g_object_unref (account);
760 g_object_unref (factory);
764 empathy_debug (DEBUG_DOMAIN, "No contact found associated with drag & drop");
768 empathy_contact_run_until_ready (contact,
769 EMPATHY_CONTACT_READY_HANDLE,
772 model = gtk_tree_view_get_model (GTK_TREE_VIEW (widget));
774 /* Get source group information. */
775 if (priv->drag_row) {
776 path = gtk_tree_row_reference_get_path (priv->drag_row);
778 old_group = empathy_contact_list_store_get_parent_group (model, path, NULL);
779 gtk_tree_path_free (path);
783 /* Get destination group information. */
784 is_row = gtk_tree_view_get_dest_row_at_pos (GTK_TREE_VIEW (widget),
791 new_group = empathy_contact_list_store_get_parent_group (model, path, NULL);
792 gtk_tree_path_free (path);
795 empathy_debug (DEBUG_DOMAIN,
796 "contact %s (%d) dragged from '%s' to '%s'",
797 empathy_contact_get_id (contact),
798 empathy_contact_get_handle (contact),
799 old_group, new_group);
801 list = empathy_contact_list_store_get_list_iface (priv->store);
803 empathy_contact_list_add_to_group (list, contact, new_group);
805 if (old_group && context->action == GDK_ACTION_MOVE) {
806 empathy_contact_list_remove_from_group (list, contact, old_group);
812 gtk_drag_finish (context, TRUE, FALSE, GDK_CURRENT_TIME);
816 contact_list_view_drag_motion (GtkWidget *widget,
817 GdkDragContext *context,
822 static DragMotionData *dm = NULL;
825 gboolean is_different = FALSE;
826 gboolean cleanup = TRUE;
828 is_row = gtk_tree_view_get_path_at_pos (GTK_TREE_VIEW (widget),
839 cleanup &= (dm && gtk_tree_path_compare (dm->path, path) != 0);
840 is_different = (!dm || (dm && gtk_tree_path_compare (dm->path, path) != 0));
845 if (!is_different && !cleanup) {
850 gtk_tree_path_free (dm->path);
851 if (dm->timeout_id) {
852 g_source_remove (dm->timeout_id);
860 if (!gtk_tree_view_row_expanded (GTK_TREE_VIEW (widget), path)) {
861 dm = g_new0 (DragMotionData, 1);
863 dm->view = EMPATHY_CONTACT_LIST_VIEW (widget);
864 dm->path = gtk_tree_path_copy (path);
866 dm->timeout_id = g_timeout_add_seconds (1,
867 (GSourceFunc) contact_list_view_drag_motion_cb,
875 contact_list_view_drag_motion_cb (DragMotionData *data)
877 gtk_tree_view_expand_row (GTK_TREE_VIEW (data->view),
881 data->timeout_id = 0;
887 contact_list_view_drag_begin (GtkWidget *widget,
888 GdkDragContext *context)
890 EmpathyContactListViewPriv *priv;
891 GtkTreeSelection *selection;
896 priv = GET_PRIV (widget);
898 GTK_WIDGET_CLASS (empathy_contact_list_view_parent_class)->drag_begin (widget,
901 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (widget));
902 if (!gtk_tree_selection_get_selected (selection, &model, &iter)) {
906 path = gtk_tree_model_get_path (model, &iter);
907 priv->drag_row = gtk_tree_row_reference_new (model, path);
908 gtk_tree_path_free (path);
912 contact_list_view_drag_data_get (GtkWidget *widget,
913 GdkDragContext *context,
914 GtkSelectionData *selection,
918 EmpathyContactListViewPriv *priv;
919 GtkTreePath *src_path;
922 EmpathyContact *contact;
924 const gchar *contact_id;
925 const gchar *account_id;
928 priv = GET_PRIV (widget);
930 model = gtk_tree_view_get_model (GTK_TREE_VIEW (widget));
931 if (!priv->drag_row) {
935 src_path = gtk_tree_row_reference_get_path (priv->drag_row);
940 if (!gtk_tree_model_get_iter (model, &iter, src_path)) {
941 gtk_tree_path_free (src_path);
945 gtk_tree_path_free (src_path);
947 contact = empathy_contact_list_view_get_selected (EMPATHY_CONTACT_LIST_VIEW (widget));
952 account = empathy_contact_get_account (contact);
953 account_id = mc_account_get_unique_name (account);
954 contact_id = empathy_contact_get_id (contact);
955 g_object_unref (contact);
956 str = g_strconcat (account_id, "/", contact_id, NULL);
959 case DND_DRAG_TYPE_CONTACT_ID:
960 gtk_selection_data_set (selection, drag_atoms_source[info], 8,
961 (guchar*)str, strlen (str) + 1);
969 contact_list_view_drag_end (GtkWidget *widget,
970 GdkDragContext *context)
972 EmpathyContactListViewPriv *priv;
974 priv = GET_PRIV (widget);
976 GTK_WIDGET_CLASS (empathy_contact_list_view_parent_class)->drag_end (widget,
979 if (priv->drag_row) {
980 gtk_tree_row_reference_free (priv->drag_row);
981 priv->drag_row = NULL;
986 contact_list_view_drag_drop (GtkWidget *widget,
987 GdkDragContext *drag_context,
996 contact_list_view_cell_set_background (EmpathyContactListView *view,
997 GtkCellRenderer *cell,
1004 style = gtk_widget_get_style (GTK_WIDGET (view));
1006 if (!is_group && is_active) {
1007 color = style->bg[GTK_STATE_SELECTED];
1009 /* Here we take the current theme colour and add it to
1010 * the colour for white and average the two. This
1011 * gives a colour which is inline with the theme but
1014 color.red = (color.red + (style->white).red) / 2;
1015 color.green = (color.green + (style->white).green) / 2;
1016 color.blue = (color.blue + (style->white).blue) / 2;
1019 "cell-background-gdk", &color,
1023 "cell-background-gdk", NULL,
1029 contact_list_view_pixbuf_cell_data_func (GtkTreeViewColumn *tree_column,
1030 GtkCellRenderer *cell,
1031 GtkTreeModel *model,
1033 EmpathyContactListView *view)
1039 gtk_tree_model_get (model, iter,
1040 EMPATHY_CONTACT_LIST_STORE_COL_IS_GROUP, &is_group,
1041 EMPATHY_CONTACT_LIST_STORE_COL_IS_ACTIVE, &is_active,
1042 EMPATHY_CONTACT_LIST_STORE_COL_ICON_STATUS, &icon_name,
1046 "visible", !is_group,
1047 "icon-name", icon_name,
1052 contact_list_view_cell_set_background (view, cell, is_group, is_active);
1056 contact_list_view_voip_cell_data_func (GtkTreeViewColumn *tree_column,
1057 GtkCellRenderer *cell,
1058 GtkTreeModel *model,
1060 EmpathyContactListView *view)
1066 gtk_tree_model_get (model, iter,
1067 EMPATHY_CONTACT_LIST_STORE_COL_IS_GROUP, &is_group,
1068 EMPATHY_CONTACT_LIST_STORE_COL_IS_ACTIVE, &is_active,
1069 EMPATHY_CONTACT_LIST_STORE_COL_CAN_VOIP, &can_voip,
1073 "visible", !is_group && can_voip,
1074 "icon-name", EMPATHY_IMAGE_VOIP,
1077 contact_list_view_cell_set_background (view, cell, is_group, is_active);
1081 contact_list_view_avatar_cell_data_func (GtkTreeViewColumn *tree_column,
1082 GtkCellRenderer *cell,
1083 GtkTreeModel *model,
1085 EmpathyContactListView *view)
1088 gboolean show_avatar;
1092 gtk_tree_model_get (model, iter,
1093 EMPATHY_CONTACT_LIST_STORE_COL_PIXBUF_AVATAR, &pixbuf,
1094 EMPATHY_CONTACT_LIST_STORE_COL_PIXBUF_AVATAR_VISIBLE, &show_avatar,
1095 EMPATHY_CONTACT_LIST_STORE_COL_IS_GROUP, &is_group,
1096 EMPATHY_CONTACT_LIST_STORE_COL_IS_ACTIVE, &is_active,
1100 "visible", !is_group && show_avatar,
1105 g_object_unref (pixbuf);
1108 contact_list_view_cell_set_background (view, cell, is_group, is_active);
1112 contact_list_view_text_cell_data_func (GtkTreeViewColumn *tree_column,
1113 GtkCellRenderer *cell,
1114 GtkTreeModel *model,
1116 EmpathyContactListView *view)
1120 gboolean show_status;
1122 gtk_tree_model_get (model, iter,
1123 EMPATHY_CONTACT_LIST_STORE_COL_IS_GROUP, &is_group,
1124 EMPATHY_CONTACT_LIST_STORE_COL_IS_ACTIVE, &is_active,
1125 EMPATHY_CONTACT_LIST_STORE_COL_STATUS_VISIBLE, &show_status,
1129 "show-status", show_status,
1132 contact_list_view_cell_set_background (view, cell, is_group, is_active);
1136 contact_list_view_expander_cell_data_func (GtkTreeViewColumn *column,
1137 GtkCellRenderer *cell,
1138 GtkTreeModel *model,
1140 EmpathyContactListView *view)
1145 gtk_tree_model_get (model, iter,
1146 EMPATHY_CONTACT_LIST_STORE_COL_IS_GROUP, &is_group,
1147 EMPATHY_CONTACT_LIST_STORE_COL_IS_ACTIVE, &is_active,
1150 if (gtk_tree_model_iter_has_child (model, iter)) {
1152 gboolean row_expanded;
1154 path = gtk_tree_model_get_path (model, iter);
1155 row_expanded = gtk_tree_view_row_expanded (GTK_TREE_VIEW (column->tree_view), path);
1156 gtk_tree_path_free (path);
1160 "expander-style", row_expanded ? GTK_EXPANDER_EXPANDED : GTK_EXPANDER_COLLAPSED,
1163 g_object_set (cell, "visible", FALSE, NULL);
1166 contact_list_view_cell_set_background (view, cell, is_group, is_active);
1170 contact_list_view_get_contact_menu (EmpathyContactListView *view,
1171 gboolean can_send_file,
1172 gboolean can_show_log,
1175 EmpathyContactListViewPriv *priv = GET_PRIV (view);
1178 if (!(priv->features & (EMPATHY_CONTACT_LIST_FEATURE_CONTACT_CHAT |
1179 EMPATHY_CONTACT_LIST_FEATURE_CONTACT_CALL |
1180 EMPATHY_CONTACT_LIST_FEATURE_CONTACT_LOG |
1181 EMPATHY_CONTACT_LIST_FEATURE_CONTACT_FT |
1182 EMPATHY_CONTACT_LIST_FEATURE_CONTACT_INVITE |
1183 EMPATHY_CONTACT_LIST_FEATURE_CONTACT_EDIT |
1184 EMPATHY_CONTACT_LIST_FEATURE_CONTACT_INFO |
1185 EMPATHY_CONTACT_LIST_FEATURE_CONTACT_REMOVE))) {
1189 /* Sort out sensitive/visible items */
1190 action = gtk_ui_manager_get_action (priv->ui, "/Contact/Chat");
1191 gtk_action_set_visible (action, priv->features & EMPATHY_CONTACT_LIST_FEATURE_CONTACT_CHAT);
1193 action = gtk_ui_manager_get_action (priv->ui, "/Contact/Call");
1194 gtk_action_set_sensitive (action, can_voip);
1195 gtk_action_set_visible (action, priv->features & EMPATHY_CONTACT_LIST_FEATURE_CONTACT_CALL);
1197 action = gtk_ui_manager_get_action (priv->ui, "/Contact/Log");
1198 gtk_action_set_sensitive (action, can_show_log);
1199 gtk_action_set_visible (action, priv->features & EMPATHY_CONTACT_LIST_FEATURE_CONTACT_LOG);
1202 action = gtk_ui_manager_get_action (priv->ui, "/Contact/SendFile");
1203 gtk_action_set_visible (action, can_send_file && (priv->features & EMPATHY_CONTACT_LIST_FEATURE_CONTACT_FT));
1205 action = gtk_ui_manager_get_action (priv->ui, "/Contact/Invite");
1206 gtk_action_set_visible (action, priv->features & EMPATHY_CONTACT_LIST_FEATURE_CONTACT_INVITE);
1208 action = gtk_ui_manager_get_action (priv->ui, "/Contact/Edit");
1209 gtk_action_set_visible (action, priv->features & EMPATHY_CONTACT_LIST_FEATURE_CONTACT_EDIT);
1211 action = gtk_ui_manager_get_action (priv->ui, "/Contact/Information");
1212 gtk_action_set_visible (action, priv->features & EMPATHY_CONTACT_LIST_FEATURE_CONTACT_INFO);
1214 action = gtk_ui_manager_get_action (priv->ui, "/Contact/Remove");
1215 gtk_action_set_visible (action, priv->features & EMPATHY_CONTACT_LIST_FEATURE_CONTACT_REMOVE);
1217 return gtk_ui_manager_get_widget (priv->ui, "/Contact");
1221 empathy_contact_list_view_get_group_menu (EmpathyContactListView *view)
1223 EmpathyContactListViewPriv *priv = GET_PRIV (view);
1226 g_return_val_if_fail (EMPATHY_IS_CONTACT_LIST_VIEW (view), NULL);
1228 if (!(priv->features & (EMPATHY_CONTACT_LIST_FEATURE_GROUPS_RENAME |
1229 EMPATHY_CONTACT_LIST_FEATURE_GROUPS_REMOVE))) {
1233 action = gtk_ui_manager_get_action (priv->ui, "/Group/Rename");
1234 gtk_action_set_visible (action, priv->features & EMPATHY_CONTACT_LIST_FEATURE_GROUPS_RENAME);
1236 action = gtk_ui_manager_get_action (priv->ui, "/Group/Remove");
1237 gtk_action_set_visible (action, priv->features & EMPATHY_CONTACT_LIST_FEATURE_GROUPS_REMOVE);
1239 return gtk_ui_manager_get_widget (priv->ui, "/Group");
1243 empathy_contact_list_view_get_contact_menu (EmpathyContactListView *view,
1244 EmpathyContact *contact)
1246 EmpathyLogManager *log_manager;
1247 gboolean can_show_log;
1248 gboolean can_send_file;
1251 g_return_val_if_fail (EMPATHY_IS_CONTACT_LIST_VIEW (view), NULL);
1252 g_return_val_if_fail (EMPATHY_IS_CONTACT (contact), NULL);
1254 log_manager = empathy_log_manager_new ();
1255 can_show_log = empathy_log_manager_exists (log_manager,
1256 empathy_contact_get_account (contact),
1257 empathy_contact_get_id (contact),
1259 g_object_unref (log_manager);
1260 can_send_file = FALSE;
1261 can_voip = empathy_contact_can_voip (contact);
1263 return contact_list_view_get_contact_menu (view,
1270 contact_list_view_button_press_event_cb (EmpathyContactListView *view,
1271 GdkEventButton *event,
1274 EmpathyContactListViewPriv *priv;
1275 EmpathyContact *contact;
1277 GtkTreeSelection *selection;
1278 GtkTreeModel *model;
1280 gboolean row_exists;
1283 priv = GET_PRIV (view);
1285 if (event->button != 3) {
1289 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (view));
1290 model = gtk_tree_view_get_model (GTK_TREE_VIEW (view));
1292 gtk_widget_grab_focus (GTK_WIDGET (view));
1294 row_exists = gtk_tree_view_get_path_at_pos (GTK_TREE_VIEW (view),
1302 gtk_tree_selection_unselect_all (selection);
1303 gtk_tree_selection_select_path (selection, path);
1305 gtk_tree_model_get_iter (model, &iter, path);
1306 gtk_tree_path_free (path);
1308 gtk_tree_model_get (model, &iter,
1309 EMPATHY_CONTACT_LIST_STORE_COL_CONTACT, &contact,
1313 menu = empathy_contact_list_view_get_contact_menu (view, contact);
1314 g_object_unref (contact);
1316 menu = empathy_contact_list_view_get_group_menu (view);
1323 gtk_widget_show (menu);
1325 gtk_menu_popup (GTK_MENU (menu),
1326 NULL, NULL, NULL, NULL,
1327 event->button, event->time);
1333 contact_list_view_row_activated_cb (EmpathyContactListView *view,
1335 GtkTreeViewColumn *col,
1338 EmpathyContactListViewPriv *priv = GET_PRIV (view);
1339 EmpathyContact *contact;
1340 GtkTreeModel *model;
1343 if (!(priv->features & EMPATHY_CONTACT_LIST_FEATURE_CONTACT_CHAT)) {
1347 model = gtk_tree_view_get_model (GTK_TREE_VIEW (view));
1349 gtk_tree_model_get_iter (model, &iter, path);
1350 gtk_tree_model_get (model, &iter,
1351 EMPATHY_CONTACT_LIST_STORE_COL_CONTACT, &contact,
1355 empathy_chat_with_contact (contact);
1356 g_object_unref (contact);
1361 contact_list_view_voip_activated_cb (EmpathyCellRendererActivatable *cell,
1362 const gchar *path_string,
1363 EmpathyContactListView *view)
1365 EmpathyContactListViewPriv *priv = GET_PRIV (view);
1366 GtkTreeModel *model;
1368 EmpathyContact *contact;
1370 if (!(priv->features & EMPATHY_CONTACT_LIST_FEATURE_CONTACT_CALL)) {
1374 model = gtk_tree_view_get_model (GTK_TREE_VIEW (view));
1375 if (!gtk_tree_model_get_iter_from_string (model, &iter, path_string)) {
1379 gtk_tree_model_get (model, &iter,
1380 EMPATHY_CONTACT_LIST_STORE_COL_CONTACT, &contact,
1384 contact_list_view_voip_activated (view, contact);
1385 g_object_unref (contact);
1390 contact_list_view_row_expand_or_collapse_cb (EmpathyContactListView *view,
1395 EmpathyContactListViewPriv *priv = GET_PRIV (view);
1396 GtkTreeModel *model;
1400 if (!(priv->features & EMPATHY_CONTACT_LIST_FEATURE_GROUPS_SAVE)) {
1404 model = gtk_tree_view_get_model (GTK_TREE_VIEW (view));
1406 gtk_tree_model_get (model, iter,
1407 EMPATHY_CONTACT_LIST_STORE_COL_NAME, &name,
1410 expanded = GPOINTER_TO_INT (user_data);
1411 empathy_contact_group_set_expanded (name, expanded);
1417 contact_list_view_action_cb (GtkAction *action,
1418 EmpathyContactListView *view)
1420 EmpathyContactListViewPriv *priv;
1421 EmpathyContact *contact;
1426 priv = GET_PRIV (view);
1428 name = gtk_action_get_name (action);
1433 empathy_debug (DEBUG_DOMAIN, "Action:'%s' activated", name);
1435 contact = empathy_contact_list_view_get_selected (view);
1436 group = empathy_contact_list_view_get_selected_group (view);
1437 parent = empathy_get_toplevel_window (GTK_WIDGET (view));
1439 if (contact && strcmp (name, "Chat") == 0) {
1440 empathy_chat_with_contact (contact);
1442 else if (contact && strcmp (name, "Call") == 0) {
1443 contact_list_view_voip_activated (view, contact);
1445 else if (contact && strcmp (name, "Information") == 0) {
1446 empathy_contact_information_dialog_show (contact, parent, FALSE, FALSE);
1448 else if (contact && strcmp (name, "Edit") == 0) {
1449 empathy_contact_information_dialog_show (contact, parent, TRUE, FALSE);
1451 else if (contact && strcmp (name, "Remove") == 0) {
1452 EmpathyContactList *list;
1455 text = g_strdup_printf (_("Do you really want to remove the contact '%s' ?"),
1456 empathy_contact_get_name (contact));
1458 /* TRUE if user wants to remove the contact. FALSE otherwise.*/
1459 if (contact_list_view_remove_dialog_show (parent, _("Removing contact"), text)) {
1460 list = empathy_contact_list_store_get_list_iface (priv->store);
1461 empathy_contact_list_remove (list, contact,
1462 _("Sorry, I don't want you in my contact list anymore."));
1467 else if (contact && strcmp (name, "Invite") == 0) {
1469 else if (contact && strcmp (name, "SendFile") == 0) {
1471 else if (contact && strcmp (name, "Log") == 0) {
1472 empathy_log_window_show (empathy_contact_get_account (contact),
1473 empathy_contact_get_id (contact),
1477 else if (group && strcmp (name, "Rename") == 0) {
1479 else if (group && strcmp (name, "Remove") == 0) {
1480 EmpathyContactList *list;
1483 text = g_strdup_printf (_("Do you really want to remove the group '%s' ?"), group);
1485 if (contact_list_view_remove_dialog_show (parent, _("Removing group"), text)) {
1486 list = empathy_contact_list_store_get_list_iface (priv->store);
1487 empathy_contact_list_remove_group (list, group);
1495 g_object_unref (contact);
1500 contact_list_view_remove_dialog_show (GtkWindow *parent,
1501 const gchar *window_title,
1504 GtkWidget *dialog, *label, *image, *hbox;
1507 dialog = gtk_dialog_new_with_buttons (window_title, parent,
1509 GTK_STOCK_DELETE, GTK_RESPONSE_YES,
1510 GTK_STOCK_CANCEL, GTK_RESPONSE_NO,
1512 gtk_dialog_set_has_separator (GTK_DIALOG(dialog), FALSE);
1514 label = gtk_label_new (text);
1515 image = gtk_image_new_from_stock (GTK_STOCK_DIALOG_QUESTION, GTK_ICON_SIZE_DIALOG);
1517 hbox = gtk_hbox_new (FALSE, 5);
1518 gtk_container_set_border_width (GTK_CONTAINER (hbox), 5);
1519 gtk_box_pack_start_defaults (GTK_BOX (hbox), image);
1520 gtk_box_pack_start_defaults (GTK_BOX (hbox), label);
1521 gtk_box_pack_start_defaults (GTK_BOX(GTK_DIALOG(dialog)->vbox), hbox);
1523 gtk_widget_show (image);
1524 gtk_widget_show (label);
1525 gtk_widget_show (hbox);
1526 gtk_widget_show (dialog);
1528 res = gtk_dialog_run (GTK_DIALOG (dialog));
1529 gtk_widget_destroy (dialog);
1531 return (res == GTK_RESPONSE_YES);
1535 contact_list_view_voip_activated (EmpathyContactListView *view,
1536 EmpathyContact *contact)
1538 empathy_call_with_contact (contact);