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 <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-debug.h>
41 #include <libempathy/empathy-utils.h>
42 #include <libempathy/empathy-marshal.h>
44 #include "empathy-contact-list-view.h"
45 #include "empathy-contact-list-store.h"
46 #include "empathy-images.h"
47 #include "empathy-contact-groups.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"
57 #define DEBUG_DOMAIN "ContactListView"
59 /* Flashing delay for icons (milliseconds). */
60 #define FLASH_TIMEOUT 500
62 /* Active users are those which have recently changed state
63 * (e.g. online, offline or from normal to a busy state).
66 #define GET_PRIV(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), EMPATHY_TYPE_CONTACT_LIST_VIEW, EmpathyContactListViewPriv))
68 struct _EmpathyContactListViewPriv {
69 EmpathyContactListStore *store;
71 GtkTreeRowReference *drag_row;
75 EmpathyContactListView *view;
81 EmpathyContactListView *view;
82 EmpathyContact *contact;
86 static void empathy_contact_list_view_class_init (EmpathyContactListViewClass *klass);
87 static void empathy_contact_list_view_init (EmpathyContactListView *list);
88 static void contact_list_view_finalize (GObject *object);
89 static void contact_list_view_get_property (GObject *object,
93 static void contact_list_view_set_property (GObject *object,
97 static void contact_list_view_setup (EmpathyContactListView *view);
98 static void contact_list_view_row_has_child_toggled_cb (GtkTreeModel *model,
101 EmpathyContactListView *view);
102 static void contact_list_view_drag_data_received (GtkWidget *widget,
103 GdkDragContext *context,
106 GtkSelectionData *selection,
109 static gboolean contact_list_view_drag_motion (GtkWidget *widget,
110 GdkDragContext *context,
114 static gboolean contact_list_view_drag_motion_cb (DragMotionData *data);
115 static void contact_list_view_drag_begin (GtkWidget *widget,
116 GdkDragContext *context);
117 static void contact_list_view_drag_data_get (GtkWidget *widget,
118 GdkDragContext *context,
119 GtkSelectionData *selection,
122 static void contact_list_view_drag_end (GtkWidget *widget,
123 GdkDragContext *context);
124 static gboolean contact_list_view_drag_drop (GtkWidget *widget,
125 GdkDragContext *drag_context,
129 static void contact_list_view_cell_set_background (EmpathyContactListView *view,
130 GtkCellRenderer *cell,
133 static void contact_list_view_pixbuf_cell_data_func (GtkTreeViewColumn *tree_column,
134 GtkCellRenderer *cell,
137 EmpathyContactListView *view);
138 static void contact_list_view_voip_cell_data_func (GtkTreeViewColumn *tree_column,
139 GtkCellRenderer *cell,
142 EmpathyContactListView *view);
143 static void contact_list_view_avatar_cell_data_func (GtkTreeViewColumn *tree_column,
144 GtkCellRenderer *cell,
147 EmpathyContactListView *view);
148 static void contact_list_view_text_cell_data_func (GtkTreeViewColumn *tree_column,
149 GtkCellRenderer *cell,
152 EmpathyContactListView *view);
153 static void contact_list_view_expander_cell_data_func (GtkTreeViewColumn *column,
154 GtkCellRenderer *cell,
157 EmpathyContactListView *view);
158 static GtkWidget * contact_list_view_get_contact_menu (EmpathyContactListView *view,
159 gboolean can_send_file,
160 gboolean can_show_log,
162 static gboolean contact_list_view_button_press_event_cb (EmpathyContactListView *view,
163 GdkEventButton *event,
165 static void contact_list_view_row_activated_cb (EmpathyContactListView *view,
167 GtkTreeViewColumn *col,
169 static void contact_list_view_voip_activated_cb (EmpathyCellRendererActivatable *cell,
170 const gchar *path_string,
171 EmpathyContactListView *view);
172 static void contact_list_view_row_expand_or_collapse_cb (EmpathyContactListView *view,
176 static void contact_list_view_action_cb (GtkAction *action,
177 EmpathyContactListView *view);
178 static void contact_list_view_action_activated (EmpathyContactListView *view,
179 EmpathyContact *contact);
180 static void contact_list_view_voip_activated (EmpathyContactListView *view,
181 EmpathyContact *contact);
187 static const GtkActionEntry entries[] = {
188 { "ContactMenu", NULL,
189 N_("_Contact"), NULL, NULL,
193 N_("_Group"),NULL, NULL,
196 { "Chat", EMPATHY_IMAGE_MESSAGE,
197 N_("_Chat"), NULL, N_("Chat with contact"),
198 G_CALLBACK (contact_list_view_action_cb)
200 { "Information", EMPATHY_IMAGE_CONTACT_INFORMATION,
201 N_("Infor_mation"), "<control>I", N_("View contact information"),
202 G_CALLBACK (contact_list_view_action_cb)
205 N_("Re_name"), NULL, N_("Rename"),
206 G_CALLBACK (contact_list_view_action_cb)
208 { "Edit", GTK_STOCK_EDIT,
209 N_("_Edit"), NULL, N_("Edit the groups and name for this contact"),
210 G_CALLBACK (contact_list_view_action_cb)
212 { "Remove", GTK_STOCK_REMOVE,
213 N_("_Remove"), NULL, N_("Remove contact"),
214 G_CALLBACK (contact_list_view_action_cb)
216 { "Invite", EMPATHY_IMAGE_GROUP_MESSAGE,
217 N_("_Invite to Chat Room"), NULL, N_("Invite to a currently open chat room"),
218 G_CALLBACK (contact_list_view_action_cb)
221 N_("_Send File..."), NULL, N_("Send a file"),
222 G_CALLBACK (contact_list_view_action_cb)
224 { "Log", GTK_STOCK_JUSTIFY_LEFT,
225 N_("_View Previous Conversations"), NULL, N_("View previous conversations with this contact"),
226 G_CALLBACK (contact_list_view_action_cb)
228 { "Call", EMPATHY_IMAGE_VOIP,
229 N_("_Call"), NULL, N_("Start a voice or video conversation with this contact"),
230 G_CALLBACK (contact_list_view_action_cb)
234 static guint n_entries = G_N_ELEMENTS (entries);
236 static const gchar *ui_info =
238 " <popup name='Contact'>"
239 " <menuitem action='Chat'/>"
240 " <menuitem action='Call'/>"
241 " <menuitem action='Log'/>"
242 " <menuitem action='SendFile'/>"
244 " <menuitem action='Invite'/>"
246 " <menuitem action='Edit'/>"
247 " <menuitem action='Remove'/>"
249 " <menuitem action='Information'/>"
251 " <popup name='Group'>"
252 " <menuitem action='Rename'/>"
257 DND_DRAG_TYPE_CONTACT_ID,
259 DND_DRAG_TYPE_STRING,
262 static const GtkTargetEntry drag_types_dest[] = {
263 { "text/contact-id", 0, DND_DRAG_TYPE_CONTACT_ID },
264 { "text/uri-list", 0, DND_DRAG_TYPE_URL },
265 { "text/plain", 0, DND_DRAG_TYPE_STRING },
266 { "STRING", 0, DND_DRAG_TYPE_STRING },
269 static const GtkTargetEntry drag_types_source[] = {
270 { "text/contact-id", 0, DND_DRAG_TYPE_CONTACT_ID },
273 static GdkAtom drag_atoms_dest[G_N_ELEMENTS (drag_types_dest)];
274 static GdkAtom drag_atoms_source[G_N_ELEMENTS (drag_types_source)];
277 DRAG_CONTACT_RECEIVED,
281 static guint signals[LAST_SIGNAL];
283 G_DEFINE_TYPE (EmpathyContactListView, empathy_contact_list_view, GTK_TYPE_TREE_VIEW);
286 empathy_contact_list_view_class_init (EmpathyContactListViewClass *klass)
288 GObjectClass *object_class = G_OBJECT_CLASS (klass);
289 GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
291 object_class->finalize = contact_list_view_finalize;
292 object_class->get_property = contact_list_view_get_property;
293 object_class->set_property = contact_list_view_set_property;
295 widget_class->drag_data_received = contact_list_view_drag_data_received;
296 widget_class->drag_drop = contact_list_view_drag_drop;
297 widget_class->drag_begin = contact_list_view_drag_begin;
298 widget_class->drag_data_get = contact_list_view_drag_data_get;
299 widget_class->drag_end = contact_list_view_drag_end;
300 /* FIXME: noticed but when you drag the row over the treeview
301 * fast, it seems to stop redrawing itself, if we don't
302 * connect this signal, all is fine.
304 widget_class->drag_motion = contact_list_view_drag_motion;
306 signals[DRAG_CONTACT_RECEIVED] =
307 g_signal_new ("drag-contact-received",
308 G_OBJECT_CLASS_TYPE (klass),
312 empathy_marshal_VOID__OBJECT_STRING_STRING,
314 3, EMPATHY_TYPE_CONTACT, G_TYPE_STRING, G_TYPE_STRING);
316 g_type_class_add_private (object_class, sizeof (EmpathyContactListViewPriv));
320 empathy_contact_list_view_init (EmpathyContactListView *view)
322 EmpathyContactListViewPriv *priv;
323 GtkActionGroup *action_group;
324 GError *error = NULL;
326 priv = GET_PRIV (view);
328 /* Get saved group states. */
329 empathy_contact_groups_get_all ();
331 /* Set up UI Manager */
332 priv->ui = gtk_ui_manager_new ();
334 action_group = gtk_action_group_new ("Actions");
335 gtk_action_group_set_translation_domain (action_group, GETTEXT_PACKAGE);
336 gtk_action_group_add_actions (action_group, entries, n_entries, view);
337 gtk_ui_manager_insert_action_group (priv->ui, action_group, 0);
339 if (!gtk_ui_manager_add_ui_from_string (priv->ui, ui_info, -1, &error)) {
340 g_warning ("Could not build contact menus from string:'%s'", error->message);
341 g_error_free (error);
344 g_object_unref (action_group);
346 gtk_tree_view_set_row_separator_func (GTK_TREE_VIEW (view),
347 empathy_contact_list_store_row_separator_func,
350 /* Connect to tree view signals rather than override. */
351 g_signal_connect (view,
352 "button-press-event",
353 G_CALLBACK (contact_list_view_button_press_event_cb),
355 g_signal_connect (view,
357 G_CALLBACK (contact_list_view_row_activated_cb),
359 g_signal_connect (view,
361 G_CALLBACK (contact_list_view_row_expand_or_collapse_cb),
362 GINT_TO_POINTER (TRUE));
363 g_signal_connect (view,
365 G_CALLBACK (contact_list_view_row_expand_or_collapse_cb),
366 GINT_TO_POINTER (FALSE));
370 contact_list_view_finalize (GObject *object)
372 EmpathyContactListViewPriv *priv;
374 priv = GET_PRIV (object);
377 g_object_unref (priv->ui);
380 g_object_unref (priv->store);
383 G_OBJECT_CLASS (empathy_contact_list_view_parent_class)->finalize (object);
387 contact_list_view_get_property (GObject *object,
392 EmpathyContactListViewPriv *priv;
394 priv = GET_PRIV (object);
398 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
404 contact_list_view_set_property (GObject *object,
409 EmpathyContactListViewPriv *priv;
411 priv = GET_PRIV (object);
415 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
420 EmpathyContactListView *
421 empathy_contact_list_view_new (EmpathyContactListStore *store)
423 EmpathyContactListViewPriv *priv;
424 EmpathyContactListView *view;
426 view = g_object_new (EMPATHY_TYPE_CONTACT_LIST_VIEW, NULL);
427 priv = GET_PRIV (view);
429 priv->store = g_object_ref (store);
430 contact_list_view_setup (view);
436 empathy_contact_list_view_get_selected (EmpathyContactListView *view)
438 EmpathyContactListViewPriv *priv;
439 GtkTreeSelection *selection;
442 EmpathyContact *contact;
444 g_return_val_if_fail (EMPATHY_IS_CONTACT_LIST_VIEW (view), NULL);
446 priv = GET_PRIV (view);
448 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (view));
449 if (!gtk_tree_selection_get_selected (selection, &model, &iter)) {
453 gtk_tree_model_get (model, &iter, COL_CONTACT, &contact, -1);
459 empathy_contact_list_view_get_selected_group (EmpathyContactListView *view)
461 EmpathyContactListViewPriv *priv;
462 GtkTreeSelection *selection;
468 g_return_val_if_fail (EMPATHY_IS_CONTACT_LIST_VIEW (view), NULL);
470 priv = GET_PRIV (view);
472 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (view));
473 if (!gtk_tree_selection_get_selected (selection, &model, &iter)) {
477 gtk_tree_model_get (model, &iter,
478 COL_IS_GROUP, &is_group,
491 empathy_contact_list_view_get_group_menu (EmpathyContactListView *view)
493 EmpathyContactListViewPriv *priv;
496 g_return_val_if_fail (EMPATHY_IS_CONTACT_LIST_VIEW (view), NULL);
498 priv = GET_PRIV (view);
500 widget = gtk_ui_manager_get_widget (priv->ui, "/Group");
506 empathy_contact_list_view_get_contact_menu (EmpathyContactListView *view,
507 EmpathyContact *contact)
509 EmpathyLogManager *log_manager;
510 gboolean can_show_log;
511 gboolean can_send_file;
514 g_return_val_if_fail (EMPATHY_IS_CONTACT_LIST_VIEW (view), NULL);
515 g_return_val_if_fail (EMPATHY_IS_CONTACT (contact), NULL);
517 log_manager = empathy_log_manager_new ();
518 can_show_log = empathy_log_manager_exists (log_manager,
519 empathy_contact_get_account (contact),
520 empathy_contact_get_id (contact),
522 g_object_unref (log_manager);
523 can_send_file = FALSE;
524 can_voip = empathy_contact_can_voip (contact);
526 return contact_list_view_get_contact_menu (view,
533 contact_list_view_setup (EmpathyContactListView *view)
535 EmpathyContactListViewPriv *priv;
536 GtkCellRenderer *cell;
537 GtkTreeViewColumn *col;
540 priv = GET_PRIV (view);
542 gtk_tree_view_set_search_equal_func (GTK_TREE_VIEW (view),
543 empathy_contact_list_store_search_equal_func,
546 g_signal_connect (priv->store, "row-has-child-toggled",
547 G_CALLBACK (contact_list_view_row_has_child_toggled_cb),
549 gtk_tree_view_set_model (GTK_TREE_VIEW (view),
550 GTK_TREE_MODEL (priv->store));
554 "headers-visible", FALSE,
556 "show-expanders", FALSE,
559 col = gtk_tree_view_column_new ();
562 cell = gtk_cell_renderer_pixbuf_new ();
563 gtk_tree_view_column_pack_start (col, cell, FALSE);
564 gtk_tree_view_column_set_cell_data_func (
566 (GtkTreeCellDataFunc) contact_list_view_pixbuf_cell_data_func,
576 cell = empathy_cell_renderer_text_new ();
577 gtk_tree_view_column_pack_start (col, cell, TRUE);
578 gtk_tree_view_column_set_cell_data_func (
580 (GtkTreeCellDataFunc) contact_list_view_text_cell_data_func,
583 gtk_tree_view_column_add_attribute (col, cell,
585 gtk_tree_view_column_add_attribute (col, cell,
586 "status", COL_STATUS);
587 gtk_tree_view_column_add_attribute (col, cell,
588 "is_group", COL_IS_GROUP);
590 /* Voip Capability Icon */
591 cell = empathy_cell_renderer_activatable_new ();
592 gtk_tree_view_column_pack_start (col, cell, FALSE);
593 gtk_tree_view_column_set_cell_data_func (
595 (GtkTreeCellDataFunc) contact_list_view_voip_cell_data_func,
602 g_signal_connect (cell, "path-activated",
603 G_CALLBACK (contact_list_view_voip_activated_cb),
607 cell = gtk_cell_renderer_pixbuf_new ();
608 gtk_tree_view_column_pack_start (col, cell, FALSE);
609 gtk_tree_view_column_set_cell_data_func (
611 (GtkTreeCellDataFunc) contact_list_view_avatar_cell_data_func,
623 cell = empathy_cell_renderer_expander_new ();
624 gtk_tree_view_column_pack_end (col, cell, FALSE);
625 gtk_tree_view_column_set_cell_data_func (
627 (GtkTreeCellDataFunc) contact_list_view_expander_cell_data_func,
630 /* Actually add the column now we have added all cell renderers */
631 gtk_tree_view_append_column (GTK_TREE_VIEW (view), col);
634 for (i = 0; i < G_N_ELEMENTS (drag_types_dest); ++i) {
635 drag_atoms_dest[i] = gdk_atom_intern (drag_types_dest[i].target,
639 for (i = 0; i < G_N_ELEMENTS (drag_types_source); ++i) {
640 drag_atoms_source[i] = gdk_atom_intern (drag_types_source[i].target,
644 /* Note: We support the COPY action too, but need to make the
645 * MOVE action the default.
647 gtk_drag_source_set (GTK_WIDGET (view),
650 G_N_ELEMENTS (drag_types_source),
651 GDK_ACTION_MOVE | GDK_ACTION_COPY);
653 gtk_drag_dest_set (GTK_WIDGET (view),
654 GTK_DEST_DEFAULT_ALL,
656 G_N_ELEMENTS (drag_types_dest),
657 GDK_ACTION_MOVE | GDK_ACTION_COPY);
661 contact_list_view_row_has_child_toggled_cb (GtkTreeModel *model,
664 EmpathyContactListView *view)
666 gboolean is_group = FALSE;
669 gtk_tree_model_get (model, iter,
670 COL_IS_GROUP, &is_group,
674 if (!is_group || G_STR_EMPTY (name)) {
679 if (empathy_contact_group_get_expanded (name)) {
680 g_signal_handlers_block_by_func (view,
681 contact_list_view_row_expand_or_collapse_cb,
682 GINT_TO_POINTER (TRUE));
683 gtk_tree_view_expand_row (GTK_TREE_VIEW (view), path, TRUE);
684 g_signal_handlers_unblock_by_func (view,
685 contact_list_view_row_expand_or_collapse_cb,
686 GINT_TO_POINTER (TRUE));
688 g_signal_handlers_block_by_func (view,
689 contact_list_view_row_expand_or_collapse_cb,
690 GINT_TO_POINTER (FALSE));
691 gtk_tree_view_collapse_row (GTK_TREE_VIEW (view), path);
692 g_signal_handlers_unblock_by_func (view,
693 contact_list_view_row_expand_or_collapse_cb,
694 GINT_TO_POINTER (FALSE));
701 contact_list_view_drag_data_received (GtkWidget *widget,
702 GdkDragContext *context,
705 GtkSelectionData *selection,
709 EmpathyContactListViewPriv *priv;
710 EmpathyContactList *list;
711 EmpathyContactFactory *factory;
715 GtkTreeViewDropPosition position;
716 EmpathyContact *contact = NULL;
719 gchar *new_group = NULL;
720 gchar *old_group = NULL;
723 priv = GET_PRIV (widget);
725 id = (const gchar*) selection->data;
726 empathy_debug (DEBUG_DOMAIN, "Received %s%s drag & drop contact from roster with id:'%s'",
727 context->action == GDK_ACTION_MOVE ? "move" : "",
728 context->action == GDK_ACTION_COPY ? "copy" : "",
731 strv = g_strsplit (id, "/", 2);
732 factory = empathy_contact_factory_new ();
733 account = mc_account_lookup (strv[0]);
735 contact = empathy_contact_factory_get_from_id (factory,
738 g_object_unref (account);
740 g_object_unref (factory);
741 g_object_unref (account);
745 empathy_debug (DEBUG_DOMAIN, "No contact found associated with drag & drop");
749 model = gtk_tree_view_get_model (GTK_TREE_VIEW (widget));
751 /* Get source group information. */
752 if (priv->drag_row) {
753 path = gtk_tree_row_reference_get_path (priv->drag_row);
755 old_group = empathy_contact_list_store_get_parent_group (model, path, NULL);
756 gtk_tree_path_free (path);
760 /* Get destination group information. */
761 is_row = gtk_tree_view_get_dest_row_at_pos (GTK_TREE_VIEW (widget),
768 new_group = empathy_contact_list_store_get_parent_group (model, path, NULL);
769 gtk_tree_path_free (path);
772 empathy_debug (DEBUG_DOMAIN,
773 "contact %s (%d) dragged from '%s' to '%s'",
774 empathy_contact_get_id (contact),
775 empathy_contact_get_handle (contact),
776 old_group, new_group);
778 list = empathy_contact_list_store_get_list_iface (priv->store);
780 empathy_contact_list_add_to_group (list, contact, new_group);
782 if (old_group && context->action == GDK_ACTION_MOVE) {
783 empathy_contact_list_remove_from_group (list, contact, old_group);
789 gtk_drag_finish (context, TRUE, FALSE, GDK_CURRENT_TIME);
793 contact_list_view_drag_motion (GtkWidget *widget,
794 GdkDragContext *context,
799 static DragMotionData *dm = NULL;
802 gboolean is_different = FALSE;
803 gboolean cleanup = TRUE;
805 is_row = gtk_tree_view_get_path_at_pos (GTK_TREE_VIEW (widget),
816 cleanup &= (dm && gtk_tree_path_compare (dm->path, path) != 0);
817 is_different = (!dm || (dm && gtk_tree_path_compare (dm->path, path) != 0));
822 if (!is_different && !cleanup) {
827 gtk_tree_path_free (dm->path);
828 if (dm->timeout_id) {
829 g_source_remove (dm->timeout_id);
837 if (!gtk_tree_view_row_expanded (GTK_TREE_VIEW (widget), path)) {
838 dm = g_new0 (DragMotionData, 1);
840 dm->view = EMPATHY_CONTACT_LIST_VIEW (widget);
841 dm->path = gtk_tree_path_copy (path);
843 dm->timeout_id = g_timeout_add (
845 (GSourceFunc) contact_list_view_drag_motion_cb,
853 contact_list_view_drag_motion_cb (DragMotionData *data)
855 gtk_tree_view_expand_row (GTK_TREE_VIEW (data->view),
859 data->timeout_id = 0;
865 contact_list_view_drag_begin (GtkWidget *widget,
866 GdkDragContext *context)
868 EmpathyContactListViewPriv *priv;
869 GtkTreeSelection *selection;
874 priv = GET_PRIV (widget);
876 GTK_WIDGET_CLASS (empathy_contact_list_view_parent_class)->drag_begin (widget,
879 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (widget));
880 if (!gtk_tree_selection_get_selected (selection, &model, &iter)) {
884 path = gtk_tree_model_get_path (model, &iter);
885 priv->drag_row = gtk_tree_row_reference_new (model, path);
886 gtk_tree_path_free (path);
890 contact_list_view_drag_data_get (GtkWidget *widget,
891 GdkDragContext *context,
892 GtkSelectionData *selection,
896 EmpathyContactListViewPriv *priv;
897 GtkTreePath *src_path;
900 EmpathyContact *contact;
902 const gchar *contact_id;
903 const gchar *account_id;
907 priv = GET_PRIV (widget);
909 model = gtk_tree_view_get_model (GTK_TREE_VIEW (widget));
910 if (!priv->drag_row) {
914 src_path = gtk_tree_row_reference_get_path (priv->drag_row);
919 if (!gtk_tree_model_get_iter (model, &iter, src_path)) {
920 gtk_tree_path_free (src_path);
924 gtk_tree_path_free (src_path);
926 contact = empathy_contact_list_view_get_selected (EMPATHY_CONTACT_LIST_VIEW (widget));
931 account = empathy_contact_get_account (contact);
932 account_id = mc_account_get_unique_name (account);
933 contact_id = empathy_contact_get_id (contact);
934 g_object_unref (contact);
935 str = g_strconcat (account_id, "/", contact_id, NULL);
938 case DND_DRAG_TYPE_CONTACT_ID:
939 gtk_selection_data_set (selection, drag_atoms_source[info], 8,
940 (guchar*)str, strlen (str) + 1);
948 contact_list_view_drag_end (GtkWidget *widget,
949 GdkDragContext *context)
951 EmpathyContactListViewPriv *priv;
953 priv = GET_PRIV (widget);
955 GTK_WIDGET_CLASS (empathy_contact_list_view_parent_class)->drag_end (widget,
958 if (priv->drag_row) {
959 gtk_tree_row_reference_free (priv->drag_row);
960 priv->drag_row = NULL;
965 contact_list_view_drag_drop (GtkWidget *widget,
966 GdkDragContext *drag_context,
975 contact_list_view_cell_set_background (EmpathyContactListView *view,
976 GtkCellRenderer *cell,
983 style = gtk_widget_get_style (GTK_WIDGET (view));
987 color = style->bg[GTK_STATE_SELECTED];
989 /* Here we take the current theme colour and add it to
990 * the colour for white and average the two. This
991 * gives a colour which is inline with the theme but
994 color.red = (color.red + (style->white).red) / 2;
995 color.green = (color.green + (style->white).green) / 2;
996 color.blue = (color.blue + (style->white).blue) / 2;
999 "cell-background-gdk", &color,
1003 "cell-background-gdk", NULL,
1008 "cell-background-gdk", NULL,
1014 contact_list_view_pixbuf_cell_data_func (GtkTreeViewColumn *tree_column,
1015 GtkCellRenderer *cell,
1016 GtkTreeModel *model,
1018 EmpathyContactListView *view)
1024 gtk_tree_model_get (model, iter,
1025 COL_IS_GROUP, &is_group,
1026 COL_IS_ACTIVE, &is_active,
1027 COL_ICON_STATUS, &icon_name,
1031 "visible", !is_group,
1032 "icon-name", icon_name,
1037 contact_list_view_cell_set_background (view, cell, is_group, is_active);
1041 contact_list_view_voip_cell_data_func (GtkTreeViewColumn *tree_column,
1042 GtkCellRenderer *cell,
1043 GtkTreeModel *model,
1045 EmpathyContactListView *view)
1051 gtk_tree_model_get (model, iter,
1052 COL_IS_GROUP, &is_group,
1053 COL_IS_ACTIVE, &is_active,
1054 COL_CAN_VOIP, &can_voip,
1058 "visible", !is_group && can_voip,
1059 "icon-name", EMPATHY_IMAGE_VOIP,
1062 contact_list_view_cell_set_background (view, cell, is_group, is_active);
1066 contact_list_view_avatar_cell_data_func (GtkTreeViewColumn *tree_column,
1067 GtkCellRenderer *cell,
1068 GtkTreeModel *model,
1070 EmpathyContactListView *view)
1073 gboolean show_avatar;
1077 gtk_tree_model_get (model, iter,
1078 COL_PIXBUF_AVATAR, &pixbuf,
1079 COL_PIXBUF_AVATAR_VISIBLE, &show_avatar,
1080 COL_IS_GROUP, &is_group,
1081 COL_IS_ACTIVE, &is_active,
1085 "visible", !is_group && show_avatar,
1090 g_object_unref (pixbuf);
1093 contact_list_view_cell_set_background (view, cell, is_group, is_active);
1097 contact_list_view_text_cell_data_func (GtkTreeViewColumn *tree_column,
1098 GtkCellRenderer *cell,
1099 GtkTreeModel *model,
1101 EmpathyContactListView *view)
1105 gboolean show_status;
1107 gtk_tree_model_get (model, iter,
1108 COL_IS_GROUP, &is_group,
1109 COL_IS_ACTIVE, &is_active,
1110 COL_STATUS_VISIBLE, &show_status,
1114 "show-status", show_status,
1117 contact_list_view_cell_set_background (view, cell, is_group, is_active);
1121 contact_list_view_expander_cell_data_func (GtkTreeViewColumn *column,
1122 GtkCellRenderer *cell,
1123 GtkTreeModel *model,
1125 EmpathyContactListView *view)
1130 gtk_tree_model_get (model, iter,
1131 COL_IS_GROUP, &is_group,
1132 COL_IS_ACTIVE, &is_active,
1135 if (gtk_tree_model_iter_has_child (model, iter)) {
1137 gboolean row_expanded;
1139 path = gtk_tree_model_get_path (model, iter);
1140 row_expanded = gtk_tree_view_row_expanded (GTK_TREE_VIEW (column->tree_view), path);
1141 gtk_tree_path_free (path);
1145 "expander-style", row_expanded ? GTK_EXPANDER_EXPANDED : GTK_EXPANDER_COLLAPSED,
1148 g_object_set (cell, "visible", FALSE, NULL);
1151 contact_list_view_cell_set_background (view, cell, is_group, is_active);
1155 contact_list_view_get_contact_menu (EmpathyContactListView *view,
1156 gboolean can_send_file,
1157 gboolean can_show_log,
1160 EmpathyContactListViewPriv *priv;
1164 priv = GET_PRIV (view);
1166 /* Sort out sensitive items */
1167 action = gtk_ui_manager_get_action (priv->ui, "/Contact/Log");
1168 gtk_action_set_sensitive (action, can_show_log);
1170 action = gtk_ui_manager_get_action (priv->ui, "/Contact/Call");
1171 gtk_action_set_sensitive (action, can_voip);
1173 action = gtk_ui_manager_get_action (priv->ui, "/Contact/SendFile");
1174 gtk_action_set_visible (action, can_send_file);
1176 widget = gtk_ui_manager_get_widget (priv->ui, "/Contact");
1182 contact_list_view_button_press_event_cb (EmpathyContactListView *view,
1183 GdkEventButton *event,
1186 EmpathyContactListViewPriv *priv;
1187 EmpathyContact *contact;
1189 GtkTreeSelection *selection;
1190 GtkTreeModel *model;
1192 gboolean row_exists;
1195 if (event->button != 3) {
1199 priv = GET_PRIV (view);
1201 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (view));
1202 model = gtk_tree_view_get_model (GTK_TREE_VIEW (view));
1204 gtk_widget_grab_focus (GTK_WIDGET (view));
1206 row_exists = gtk_tree_view_get_path_at_pos (GTK_TREE_VIEW (view),
1214 gtk_tree_selection_unselect_all (selection);
1215 gtk_tree_selection_select_path (selection, path);
1217 gtk_tree_model_get_iter (model, &iter, path);
1218 gtk_tree_path_free (path);
1220 gtk_tree_model_get (model, &iter, COL_CONTACT, &contact, -1);
1223 menu = empathy_contact_list_view_get_contact_menu (view, contact);
1224 g_object_unref (contact);
1226 menu = empathy_contact_list_view_get_group_menu (view);
1233 gtk_widget_show (menu);
1235 gtk_menu_popup (GTK_MENU (menu),
1236 NULL, NULL, NULL, NULL,
1237 event->button, event->time);
1243 contact_list_view_row_activated_cb (EmpathyContactListView *view,
1245 GtkTreeViewColumn *col,
1248 EmpathyContact *contact;
1249 GtkTreeModel *model;
1252 model = gtk_tree_view_get_model (GTK_TREE_VIEW (view));
1254 gtk_tree_model_get_iter (model, &iter, path);
1255 gtk_tree_model_get (model, &iter, COL_CONTACT, &contact, -1);
1258 contact_list_view_action_activated (view, contact);
1259 g_object_unref (contact);
1264 contact_list_view_voip_activated_cb (EmpathyCellRendererActivatable *cell,
1265 const gchar *path_string,
1266 EmpathyContactListView *view)
1268 GtkTreeModel *model;
1270 EmpathyContact *contact;
1272 model = gtk_tree_view_get_model (GTK_TREE_VIEW (view));
1273 if (!gtk_tree_model_get_iter_from_string (model, &iter, path_string)) {
1277 gtk_tree_model_get (model, &iter, COL_CONTACT, &contact, -1);
1280 contact_list_view_voip_activated (view, contact);
1281 g_object_unref (contact);
1287 contact_list_view_row_expand_or_collapse_cb (EmpathyContactListView *view,
1292 GtkTreeModel *model;
1296 model = gtk_tree_view_get_model (GTK_TREE_VIEW (view));
1298 gtk_tree_model_get (model, iter,
1302 expanded = GPOINTER_TO_INT (user_data);
1303 empathy_contact_group_set_expanded (name, expanded);
1309 contact_list_view_action_cb (GtkAction *action,
1310 EmpathyContactListView *view)
1312 EmpathyContactListViewPriv *priv;
1313 EmpathyContact *contact;
1318 priv = GET_PRIV (view);
1320 name = gtk_action_get_name (action);
1325 empathy_debug (DEBUG_DOMAIN, "Action:'%s' activated", name);
1327 contact = empathy_contact_list_view_get_selected (view);
1328 group = empathy_contact_list_view_get_selected_group (view);
1329 parent = empathy_get_toplevel_window (GTK_WIDGET (view));
1331 if (contact && strcmp (name, "Chat") == 0) {
1332 contact_list_view_action_activated (view, contact);
1334 else if (contact && strcmp (name, "Call") == 0) {
1335 contact_list_view_voip_activated (view, contact);
1337 else if (contact && strcmp (name, "Information") == 0) {
1338 empathy_contact_information_dialog_show (contact, parent, FALSE);
1340 else if (contact && strcmp (name, "Edit") == 0) {
1341 empathy_contact_information_dialog_show (contact, parent, TRUE);
1343 else if (contact && strcmp (name, "Remove") == 0) {
1344 /* FIXME: Ask for confirmation */
1345 EmpathyContactList *list;
1347 list = empathy_contact_list_store_get_list_iface (priv->store);
1348 empathy_contact_list_remove (list, contact,
1349 _("Sorry, I don't want you in my contact list anymore."));
1351 else if (contact && strcmp (name, "Invite") == 0) {
1353 else if (contact && strcmp (name, "SendFile") == 0) {
1355 else if (contact && strcmp (name, "Log") == 0) {
1356 empathy_log_window_show (empathy_contact_get_account (contact),
1357 empathy_contact_get_id (contact),
1361 else if (group && strcmp (name, "Rename") == 0) {
1366 g_object_unref (contact);
1371 contact_list_view_action_activated (EmpathyContactListView *view,
1372 EmpathyContact *contact)
1376 mc = empathy_mission_control_new ();
1377 mission_control_request_channel (mc,
1378 empathy_contact_get_account (contact),
1379 TP_IFACE_CHANNEL_TYPE_TEXT,
1380 empathy_contact_get_handle (contact),
1381 TP_HANDLE_TYPE_CONTACT,
1383 g_object_unref (mc);
1387 contact_list_view_voip_activated (EmpathyContactListView *view,
1388 EmpathyContact *contact)
1390 /* FIXME: Not implemented */