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-ui-utils.h"
51 #include "empathy-contact-dialogs.h"
52 //#include "empathy-chat-invite.h"
53 //#include "empathy-ft-window.h"
54 #include "empathy-log-window.h"
56 #define DEBUG_DOMAIN "ContactListView"
58 /* Flashing delay for icons (milliseconds). */
59 #define FLASH_TIMEOUT 500
61 /* Active users are those which have recently changed state
62 * (e.g. online, offline or from normal to a busy state).
65 #define GET_PRIV(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), EMPATHY_TYPE_CONTACT_LIST_VIEW, EmpathyContactListViewPriv))
67 struct _EmpathyContactListViewPriv {
68 EmpathyContactListStore *store;
70 GtkTreeRowReference *drag_row;
74 EmpathyContactListView *view;
80 EmpathyContactListView *view;
81 EmpathyContact *contact;
85 static void empathy_contact_list_view_class_init (EmpathyContactListViewClass *klass);
86 static void empathy_contact_list_view_init (EmpathyContactListView *list);
87 static void contact_list_view_finalize (GObject *object);
88 static void contact_list_view_get_property (GObject *object,
92 static void contact_list_view_set_property (GObject *object,
96 static void contact_list_view_setup (EmpathyContactListView *view);
97 static void contact_list_view_row_has_child_toggled_cb (GtkTreeModel *model,
100 EmpathyContactListView *view);
101 static void contact_list_view_drag_data_received (GtkWidget *widget,
102 GdkDragContext *context,
105 GtkSelectionData *selection,
108 static gboolean contact_list_view_drag_motion (GtkWidget *widget,
109 GdkDragContext *context,
113 static gboolean contact_list_view_drag_motion_cb (DragMotionData *data);
114 static void contact_list_view_drag_begin (GtkWidget *widget,
115 GdkDragContext *context);
116 static void contact_list_view_drag_data_get (GtkWidget *widget,
117 GdkDragContext *context,
118 GtkSelectionData *selection,
121 static void contact_list_view_drag_end (GtkWidget *widget,
122 GdkDragContext *context);
123 static gboolean contact_list_view_drag_drop (GtkWidget *widget,
124 GdkDragContext *drag_context,
128 static void contact_list_view_cell_set_background (EmpathyContactListView *view,
129 GtkCellRenderer *cell,
132 static void contact_list_view_pixbuf_cell_data_func (GtkTreeViewColumn *tree_column,
133 GtkCellRenderer *cell,
136 EmpathyContactListView *view);
137 static void contact_list_view_avatar_cell_data_func (GtkTreeViewColumn *tree_column,
138 GtkCellRenderer *cell,
141 EmpathyContactListView *view);
142 static void contact_list_view_text_cell_data_func (GtkTreeViewColumn *tree_column,
143 GtkCellRenderer *cell,
146 EmpathyContactListView *view);
147 static void contact_list_view_expander_cell_data_func (GtkTreeViewColumn *column,
148 GtkCellRenderer *cell,
151 EmpathyContactListView *view);
152 static GtkWidget * contact_list_view_get_contact_menu (EmpathyContactListView *view,
153 gboolean can_send_file,
154 gboolean can_show_log);
155 static gboolean contact_list_view_button_press_event_cb (EmpathyContactListView *view,
156 GdkEventButton *event,
158 static void contact_list_view_row_activated_cb (EmpathyContactListView *view,
160 GtkTreeViewColumn *col,
162 static void contact_list_view_row_expand_or_collapse_cb (EmpathyContactListView *view,
166 static void contact_list_view_action_cb (GtkAction *action,
167 EmpathyContactListView *view);
168 static void contact_list_view_action_activated (EmpathyContactListView *view,
169 EmpathyContact *contact);
175 static const GtkActionEntry entries[] = {
176 { "ContactMenu", NULL,
177 N_("_Contact"), NULL, NULL,
181 N_("_Group"),NULL, NULL,
184 { "Chat", EMPATHY_IMAGE_MESSAGE,
185 N_("_Chat"), NULL, N_("Chat with contact"),
186 G_CALLBACK (contact_list_view_action_cb)
188 { "Information", EMPATHY_IMAGE_CONTACT_INFORMATION,
189 N_("Infor_mation"), "<control>I", N_("View contact information"),
190 G_CALLBACK (contact_list_view_action_cb)
193 N_("Re_name"), NULL, N_("Rename"),
194 G_CALLBACK (contact_list_view_action_cb)
196 { "Edit", GTK_STOCK_EDIT,
197 N_("_Edit"), NULL, N_("Edit the groups and name for this contact"),
198 G_CALLBACK (contact_list_view_action_cb)
200 { "Remove", GTK_STOCK_REMOVE,
201 N_("_Remove"), NULL, N_("Remove contact"),
202 G_CALLBACK (contact_list_view_action_cb)
204 { "Invite", EMPATHY_IMAGE_GROUP_MESSAGE,
205 N_("_Invite to Chat Room"), NULL, N_("Invite to a currently open chat room"),
206 G_CALLBACK (contact_list_view_action_cb)
209 N_("_Send File..."), NULL, N_("Send a file"),
210 G_CALLBACK (contact_list_view_action_cb)
212 { "Log", GTK_STOCK_JUSTIFY_LEFT,
213 N_("_View Previous Conversations"), NULL, N_("View previous conversations with this contact"),
214 G_CALLBACK (contact_list_view_action_cb)
218 static guint n_entries = G_N_ELEMENTS (entries);
220 static const gchar *ui_info =
222 " <popup name='Contact'>"
223 " <menuitem action='Chat'/>"
224 " <menuitem action='Log'/>"
225 " <menuitem action='SendFile'/>"
227 " <menuitem action='Invite'/>"
229 " <menuitem action='Edit'/>"
230 " <menuitem action='Remove'/>"
232 " <menuitem action='Information'/>"
234 " <popup name='Group'>"
235 " <menuitem action='Rename'/>"
240 DND_DRAG_TYPE_CONTACT_ID,
242 DND_DRAG_TYPE_STRING,
245 static const GtkTargetEntry drag_types_dest[] = {
246 { "text/contact-id", 0, DND_DRAG_TYPE_CONTACT_ID },
247 { "text/uri-list", 0, DND_DRAG_TYPE_URL },
248 { "text/plain", 0, DND_DRAG_TYPE_STRING },
249 { "STRING", 0, DND_DRAG_TYPE_STRING },
252 static const GtkTargetEntry drag_types_source[] = {
253 { "text/contact-id", 0, DND_DRAG_TYPE_CONTACT_ID },
256 static GdkAtom drag_atoms_dest[G_N_ELEMENTS (drag_types_dest)];
257 static GdkAtom drag_atoms_source[G_N_ELEMENTS (drag_types_source)];
260 DRAG_CONTACT_RECEIVED,
264 static guint signals[LAST_SIGNAL];
266 G_DEFINE_TYPE (EmpathyContactListView, empathy_contact_list_view, GTK_TYPE_TREE_VIEW);
269 empathy_contact_list_view_class_init (EmpathyContactListViewClass *klass)
271 GObjectClass *object_class = G_OBJECT_CLASS (klass);
272 GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
274 object_class->finalize = contact_list_view_finalize;
275 object_class->get_property = contact_list_view_get_property;
276 object_class->set_property = contact_list_view_set_property;
278 widget_class->drag_data_received = contact_list_view_drag_data_received;
279 widget_class->drag_drop = contact_list_view_drag_drop;
280 widget_class->drag_begin = contact_list_view_drag_begin;
281 widget_class->drag_data_get = contact_list_view_drag_data_get;
282 widget_class->drag_end = contact_list_view_drag_end;
283 /* FIXME: noticed but when you drag the row over the treeview
284 * fast, it seems to stop redrawing itself, if we don't
285 * connect this signal, all is fine.
287 widget_class->drag_motion = contact_list_view_drag_motion;
289 signals[DRAG_CONTACT_RECEIVED] =
290 g_signal_new ("drag-contact-received",
291 G_OBJECT_CLASS_TYPE (klass),
295 empathy_marshal_VOID__OBJECT_STRING_STRING,
297 3, EMPATHY_TYPE_CONTACT, G_TYPE_STRING, G_TYPE_STRING);
299 g_type_class_add_private (object_class, sizeof (EmpathyContactListViewPriv));
303 empathy_contact_list_view_init (EmpathyContactListView *view)
305 EmpathyContactListViewPriv *priv;
306 GtkActionGroup *action_group;
307 GError *error = NULL;
309 priv = GET_PRIV (view);
311 /* Get saved group states. */
312 empathy_contact_groups_get_all ();
314 /* Set up UI Manager */
315 priv->ui = gtk_ui_manager_new ();
317 action_group = gtk_action_group_new ("Actions");
318 gtk_action_group_set_translation_domain (action_group, GETTEXT_PACKAGE);
319 gtk_action_group_add_actions (action_group, entries, n_entries, view);
320 gtk_ui_manager_insert_action_group (priv->ui, action_group, 0);
322 if (!gtk_ui_manager_add_ui_from_string (priv->ui, ui_info, -1, &error)) {
323 g_warning ("Could not build contact menus from string:'%s'", error->message);
324 g_error_free (error);
327 g_object_unref (action_group);
329 gtk_tree_view_set_row_separator_func (GTK_TREE_VIEW (view),
330 empathy_contact_list_store_row_separator_func,
333 /* Connect to tree view signals rather than override. */
334 g_signal_connect (view,
335 "button-press-event",
336 G_CALLBACK (contact_list_view_button_press_event_cb),
338 g_signal_connect (view,
340 G_CALLBACK (contact_list_view_row_activated_cb),
342 g_signal_connect (view,
344 G_CALLBACK (contact_list_view_row_expand_or_collapse_cb),
345 GINT_TO_POINTER (TRUE));
346 g_signal_connect (view,
348 G_CALLBACK (contact_list_view_row_expand_or_collapse_cb),
349 GINT_TO_POINTER (FALSE));
353 contact_list_view_finalize (GObject *object)
355 EmpathyContactListViewPriv *priv;
357 priv = GET_PRIV (object);
360 g_object_unref (priv->ui);
363 g_object_unref (priv->store);
366 G_OBJECT_CLASS (empathy_contact_list_view_parent_class)->finalize (object);
370 contact_list_view_get_property (GObject *object,
375 EmpathyContactListViewPriv *priv;
377 priv = GET_PRIV (object);
381 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
387 contact_list_view_set_property (GObject *object,
392 EmpathyContactListViewPriv *priv;
394 priv = GET_PRIV (object);
398 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
403 EmpathyContactListView *
404 empathy_contact_list_view_new (EmpathyContactListStore *store)
406 EmpathyContactListViewPriv *priv;
407 EmpathyContactListView *view;
409 view = g_object_new (EMPATHY_TYPE_CONTACT_LIST_VIEW, NULL);
410 priv = GET_PRIV (view);
412 priv->store = g_object_ref (store);
413 contact_list_view_setup (view);
419 empathy_contact_list_view_get_selected (EmpathyContactListView *view)
421 EmpathyContactListViewPriv *priv;
422 GtkTreeSelection *selection;
425 EmpathyContact *contact;
427 g_return_val_if_fail (EMPATHY_IS_CONTACT_LIST_VIEW (view), NULL);
429 priv = GET_PRIV (view);
431 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (view));
432 if (!gtk_tree_selection_get_selected (selection, &model, &iter)) {
436 gtk_tree_model_get (model, &iter, COL_CONTACT, &contact, -1);
442 empathy_contact_list_view_get_selected_group (EmpathyContactListView *view)
444 EmpathyContactListViewPriv *priv;
445 GtkTreeSelection *selection;
451 g_return_val_if_fail (EMPATHY_IS_CONTACT_LIST_VIEW (view), NULL);
453 priv = GET_PRIV (view);
455 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (view));
456 if (!gtk_tree_selection_get_selected (selection, &model, &iter)) {
460 gtk_tree_model_get (model, &iter,
461 COL_IS_GROUP, &is_group,
474 empathy_contact_list_view_get_group_menu (EmpathyContactListView *view)
476 EmpathyContactListViewPriv *priv;
479 g_return_val_if_fail (EMPATHY_IS_CONTACT_LIST_VIEW (view), NULL);
481 priv = GET_PRIV (view);
483 widget = gtk_ui_manager_get_widget (priv->ui, "/Group");
489 empathy_contact_list_view_get_contact_menu (EmpathyContactListView *view,
490 EmpathyContact *contact)
492 EmpathyLogManager *log_manager;
493 gboolean can_show_log;
494 gboolean can_send_file;
496 g_return_val_if_fail (EMPATHY_IS_CONTACT_LIST_VIEW (view), NULL);
497 g_return_val_if_fail (EMPATHY_IS_CONTACT (contact), NULL);
499 log_manager = empathy_log_manager_new ();
500 can_show_log = empathy_log_manager_exists (log_manager,
501 empathy_contact_get_account (contact),
502 empathy_contact_get_id (contact),
504 can_send_file = FALSE;
505 g_object_unref (log_manager);
507 return contact_list_view_get_contact_menu (view,
513 contact_list_view_setup (EmpathyContactListView *view)
515 EmpathyContactListViewPriv *priv;
516 GtkCellRenderer *cell;
517 GtkTreeViewColumn *col;
520 priv = GET_PRIV (view);
522 gtk_tree_view_set_search_equal_func (GTK_TREE_VIEW (view),
523 empathy_contact_list_store_search_equal_func,
526 g_signal_connect (priv->store, "row-has-child-toggled",
527 G_CALLBACK (contact_list_view_row_has_child_toggled_cb),
529 gtk_tree_view_set_model (GTK_TREE_VIEW (view),
530 GTK_TREE_MODEL (priv->store));
534 "headers-visible", FALSE,
536 "show-expanders", FALSE,
539 col = gtk_tree_view_column_new ();
542 cell = gtk_cell_renderer_pixbuf_new ();
543 gtk_tree_view_column_pack_start (col, cell, FALSE);
544 gtk_tree_view_column_set_cell_data_func (
546 (GtkTreeCellDataFunc) contact_list_view_pixbuf_cell_data_func,
556 cell = empathy_cell_renderer_text_new ();
557 gtk_tree_view_column_pack_start (col, cell, TRUE);
558 gtk_tree_view_column_set_cell_data_func (
560 (GtkTreeCellDataFunc) contact_list_view_text_cell_data_func,
563 gtk_tree_view_column_add_attribute (col, cell,
565 gtk_tree_view_column_add_attribute (col, cell,
566 "status", COL_STATUS);
567 gtk_tree_view_column_add_attribute (col, cell,
568 "is_group", COL_IS_GROUP);
571 cell = gtk_cell_renderer_pixbuf_new ();
572 gtk_tree_view_column_pack_start (col, cell, FALSE);
573 gtk_tree_view_column_set_cell_data_func (
575 (GtkTreeCellDataFunc) contact_list_view_avatar_cell_data_func,
587 cell = empathy_cell_renderer_expander_new ();
588 gtk_tree_view_column_pack_end (col, cell, FALSE);
589 gtk_tree_view_column_set_cell_data_func (
591 (GtkTreeCellDataFunc) contact_list_view_expander_cell_data_func,
594 /* Actually add the column now we have added all cell renderers */
595 gtk_tree_view_append_column (GTK_TREE_VIEW (view), col);
598 for (i = 0; i < G_N_ELEMENTS (drag_types_dest); ++i) {
599 drag_atoms_dest[i] = gdk_atom_intern (drag_types_dest[i].target,
603 for (i = 0; i < G_N_ELEMENTS (drag_types_source); ++i) {
604 drag_atoms_source[i] = gdk_atom_intern (drag_types_source[i].target,
608 /* Note: We support the COPY action too, but need to make the
609 * MOVE action the default.
611 gtk_drag_source_set (GTK_WIDGET (view),
614 G_N_ELEMENTS (drag_types_source),
615 GDK_ACTION_MOVE | GDK_ACTION_COPY);
617 gtk_drag_dest_set (GTK_WIDGET (view),
618 GTK_DEST_DEFAULT_ALL,
620 G_N_ELEMENTS (drag_types_dest),
621 GDK_ACTION_MOVE | GDK_ACTION_COPY);
625 contact_list_view_row_has_child_toggled_cb (GtkTreeModel *model,
628 EmpathyContactListView *view)
630 gboolean is_group = FALSE;
633 gtk_tree_model_get (model, iter,
634 COL_IS_GROUP, &is_group,
638 if (!is_group || G_STR_EMPTY (name)) {
643 if (empathy_contact_group_get_expanded (name)) {
644 g_signal_handlers_block_by_func (view,
645 contact_list_view_row_expand_or_collapse_cb,
646 GINT_TO_POINTER (TRUE));
647 gtk_tree_view_expand_row (GTK_TREE_VIEW (view), path, TRUE);
648 g_signal_handlers_unblock_by_func (view,
649 contact_list_view_row_expand_or_collapse_cb,
650 GINT_TO_POINTER (TRUE));
652 g_signal_handlers_block_by_func (view,
653 contact_list_view_row_expand_or_collapse_cb,
654 GINT_TO_POINTER (FALSE));
655 gtk_tree_view_collapse_row (GTK_TREE_VIEW (view), path);
656 g_signal_handlers_unblock_by_func (view,
657 contact_list_view_row_expand_or_collapse_cb,
658 GINT_TO_POINTER (FALSE));
665 contact_list_view_drag_data_received (GtkWidget *widget,
666 GdkDragContext *context,
669 GtkSelectionData *selection,
673 EmpathyContactListViewPriv *priv;
674 EmpathyContactList *list;
675 EmpathyContactFactory *factory;
679 GtkTreeViewDropPosition position;
680 EmpathyContact *contact = NULL;
683 gchar *new_group = NULL;
684 gchar *old_group = NULL;
687 priv = GET_PRIV (widget);
689 id = (const gchar*) selection->data;
690 empathy_debug (DEBUG_DOMAIN, "Received %s%s drag & drop contact from roster with id:'%s'",
691 context->action == GDK_ACTION_MOVE ? "move" : "",
692 context->action == GDK_ACTION_COPY ? "copy" : "",
695 strv = g_strsplit (id, "/", 2);
696 factory = empathy_contact_factory_new ();
697 account = mc_account_lookup (strv[0]);
699 contact = empathy_contact_factory_get_from_id (factory,
702 g_object_unref (account);
704 g_object_unref (factory);
705 g_object_unref (account);
709 empathy_debug (DEBUG_DOMAIN, "No contact found associated with drag & drop");
713 model = gtk_tree_view_get_model (GTK_TREE_VIEW (widget));
715 /* Get source group information. */
716 if (priv->drag_row) {
717 path = gtk_tree_row_reference_get_path (priv->drag_row);
719 old_group = empathy_contact_list_store_get_parent_group (model, path, NULL);
720 gtk_tree_path_free (path);
724 /* Get destination group information. */
725 is_row = gtk_tree_view_get_dest_row_at_pos (GTK_TREE_VIEW (widget),
732 new_group = empathy_contact_list_store_get_parent_group (model, path, NULL);
733 gtk_tree_path_free (path);
736 empathy_debug (DEBUG_DOMAIN,
737 "contact %s (%d) dragged from '%s' to '%s'",
738 empathy_contact_get_id (contact),
739 empathy_contact_get_handle (contact),
740 old_group, new_group);
742 list = empathy_contact_list_store_get_list_iface (priv->store);
744 empathy_contact_list_add_to_group (list, contact, new_group);
746 if (old_group && context->action == GDK_ACTION_MOVE) {
747 empathy_contact_list_remove_from_group (list, contact, old_group);
753 gtk_drag_finish (context, TRUE, FALSE, GDK_CURRENT_TIME);
757 contact_list_view_drag_motion (GtkWidget *widget,
758 GdkDragContext *context,
763 static DragMotionData *dm = NULL;
766 gboolean is_different = FALSE;
767 gboolean cleanup = TRUE;
769 is_row = gtk_tree_view_get_path_at_pos (GTK_TREE_VIEW (widget),
780 cleanup &= (dm && gtk_tree_path_compare (dm->path, path) != 0);
781 is_different = (!dm || (dm && gtk_tree_path_compare (dm->path, path) != 0));
786 if (!is_different && !cleanup) {
791 gtk_tree_path_free (dm->path);
792 if (dm->timeout_id) {
793 g_source_remove (dm->timeout_id);
801 if (!gtk_tree_view_row_expanded (GTK_TREE_VIEW (widget), path)) {
802 dm = g_new0 (DragMotionData, 1);
804 dm->view = EMPATHY_CONTACT_LIST_VIEW (widget);
805 dm->path = gtk_tree_path_copy (path);
807 dm->timeout_id = g_timeout_add (
809 (GSourceFunc) contact_list_view_drag_motion_cb,
817 contact_list_view_drag_motion_cb (DragMotionData *data)
819 gtk_tree_view_expand_row (GTK_TREE_VIEW (data->view),
823 data->timeout_id = 0;
829 contact_list_view_drag_begin (GtkWidget *widget,
830 GdkDragContext *context)
832 EmpathyContactListViewPriv *priv;
833 GtkTreeSelection *selection;
838 priv = GET_PRIV (widget);
840 GTK_WIDGET_CLASS (empathy_contact_list_view_parent_class)->drag_begin (widget,
843 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (widget));
844 if (!gtk_tree_selection_get_selected (selection, &model, &iter)) {
848 path = gtk_tree_model_get_path (model, &iter);
849 priv->drag_row = gtk_tree_row_reference_new (model, path);
850 gtk_tree_path_free (path);
854 contact_list_view_drag_data_get (GtkWidget *widget,
855 GdkDragContext *context,
856 GtkSelectionData *selection,
860 EmpathyContactListViewPriv *priv;
861 GtkTreePath *src_path;
864 EmpathyContact *contact;
866 const gchar *contact_id;
867 const gchar *account_id;
871 priv = GET_PRIV (widget);
873 model = gtk_tree_view_get_model (GTK_TREE_VIEW (widget));
874 if (!priv->drag_row) {
878 src_path = gtk_tree_row_reference_get_path (priv->drag_row);
883 if (!gtk_tree_model_get_iter (model, &iter, src_path)) {
884 gtk_tree_path_free (src_path);
888 gtk_tree_path_free (src_path);
890 contact = empathy_contact_list_view_get_selected (EMPATHY_CONTACT_LIST_VIEW (widget));
895 account = empathy_contact_get_account (contact);
896 account_id = mc_account_get_unique_name (account);
897 contact_id = empathy_contact_get_id (contact);
898 g_object_unref (contact);
899 str = g_strconcat (account_id, "/", contact_id, NULL);
902 case DND_DRAG_TYPE_CONTACT_ID:
903 gtk_selection_data_set (selection, drag_atoms_source[info], 8,
904 (guchar*)str, strlen (str) + 1);
912 contact_list_view_drag_end (GtkWidget *widget,
913 GdkDragContext *context)
915 EmpathyContactListViewPriv *priv;
917 priv = GET_PRIV (widget);
919 GTK_WIDGET_CLASS (empathy_contact_list_view_parent_class)->drag_end (widget,
922 if (priv->drag_row) {
923 gtk_tree_row_reference_free (priv->drag_row);
924 priv->drag_row = NULL;
929 contact_list_view_drag_drop (GtkWidget *widget,
930 GdkDragContext *drag_context,
939 contact_list_view_cell_set_background (EmpathyContactListView *view,
940 GtkCellRenderer *cell,
947 style = gtk_widget_get_style (GTK_WIDGET (view));
951 color = style->bg[GTK_STATE_SELECTED];
953 /* Here we take the current theme colour and add it to
954 * the colour for white and average the two. This
955 * gives a colour which is inline with the theme but
958 color.red = (color.red + (style->white).red) / 2;
959 color.green = (color.green + (style->white).green) / 2;
960 color.blue = (color.blue + (style->white).blue) / 2;
963 "cell-background-gdk", &color,
967 "cell-background-gdk", NULL,
972 "cell-background-gdk", NULL,
978 contact_list_view_pixbuf_cell_data_func (GtkTreeViewColumn *tree_column,
979 GtkCellRenderer *cell,
982 EmpathyContactListView *view)
988 gtk_tree_model_get (model, iter,
989 COL_IS_GROUP, &is_group,
990 COL_IS_ACTIVE, &is_active,
991 COL_ICON_STATUS, &icon_name,
995 "visible", !is_group,
996 "icon-name", icon_name,
1001 contact_list_view_cell_set_background (view, cell, is_group, is_active);
1005 contact_list_view_avatar_cell_data_func (GtkTreeViewColumn *tree_column,
1006 GtkCellRenderer *cell,
1007 GtkTreeModel *model,
1009 EmpathyContactListView *view)
1012 gboolean show_avatar;
1016 gtk_tree_model_get (model, iter,
1017 COL_PIXBUF_AVATAR, &pixbuf,
1018 COL_PIXBUF_AVATAR_VISIBLE, &show_avatar,
1019 COL_IS_GROUP, &is_group,
1020 COL_IS_ACTIVE, &is_active,
1024 "visible", !is_group && show_avatar,
1029 g_object_unref (pixbuf);
1032 contact_list_view_cell_set_background (view, cell, is_group, is_active);
1036 contact_list_view_text_cell_data_func (GtkTreeViewColumn *tree_column,
1037 GtkCellRenderer *cell,
1038 GtkTreeModel *model,
1040 EmpathyContactListView *view)
1044 gboolean show_status;
1046 gtk_tree_model_get (model, iter,
1047 COL_IS_GROUP, &is_group,
1048 COL_IS_ACTIVE, &is_active,
1049 COL_STATUS_VISIBLE, &show_status,
1053 "show-status", show_status,
1056 contact_list_view_cell_set_background (view, cell, is_group, is_active);
1060 contact_list_view_expander_cell_data_func (GtkTreeViewColumn *column,
1061 GtkCellRenderer *cell,
1062 GtkTreeModel *model,
1064 EmpathyContactListView *view)
1069 gtk_tree_model_get (model, iter,
1070 COL_IS_GROUP, &is_group,
1071 COL_IS_ACTIVE, &is_active,
1074 if (gtk_tree_model_iter_has_child (model, iter)) {
1076 gboolean row_expanded;
1078 path = gtk_tree_model_get_path (model, iter);
1079 row_expanded = gtk_tree_view_row_expanded (GTK_TREE_VIEW (column->tree_view), path);
1080 gtk_tree_path_free (path);
1084 "expander-style", row_expanded ? GTK_EXPANDER_EXPANDED : GTK_EXPANDER_COLLAPSED,
1087 g_object_set (cell, "visible", FALSE, NULL);
1090 contact_list_view_cell_set_background (view, cell, is_group, is_active);
1094 contact_list_view_get_contact_menu (EmpathyContactListView *view,
1095 gboolean can_send_file,
1096 gboolean can_show_log)
1098 EmpathyContactListViewPriv *priv;
1102 priv = GET_PRIV (view);
1104 /* Sort out sensitive items */
1105 action = gtk_ui_manager_get_action (priv->ui, "/Contact/Log");
1106 gtk_action_set_sensitive (action, can_show_log);
1108 action = gtk_ui_manager_get_action (priv->ui, "/Contact/SendFile");
1109 gtk_action_set_visible (action, can_send_file);
1111 widget = gtk_ui_manager_get_widget (priv->ui, "/Contact");
1117 contact_list_view_button_press_event_cb (EmpathyContactListView *view,
1118 GdkEventButton *event,
1121 EmpathyContactListViewPriv *priv;
1122 EmpathyContact *contact;
1124 GtkTreeSelection *selection;
1125 GtkTreeModel *model;
1127 gboolean row_exists;
1130 if (event->button != 3) {
1134 priv = GET_PRIV (view);
1136 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (view));
1137 model = gtk_tree_view_get_model (GTK_TREE_VIEW (view));
1139 gtk_widget_grab_focus (GTK_WIDGET (view));
1141 row_exists = gtk_tree_view_get_path_at_pos (GTK_TREE_VIEW (view),
1149 gtk_tree_selection_unselect_all (selection);
1150 gtk_tree_selection_select_path (selection, path);
1152 gtk_tree_model_get_iter (model, &iter, path);
1153 gtk_tree_path_free (path);
1155 gtk_tree_model_get (model, &iter, COL_CONTACT, &contact, -1);
1158 menu = empathy_contact_list_view_get_contact_menu (view, contact);
1159 g_object_unref (contact);
1161 menu = empathy_contact_list_view_get_group_menu (view);
1168 gtk_widget_show (menu);
1170 gtk_menu_popup (GTK_MENU (menu),
1171 NULL, NULL, NULL, NULL,
1172 event->button, event->time);
1178 contact_list_view_row_activated_cb (EmpathyContactListView *view,
1180 GtkTreeViewColumn *col,
1183 EmpathyContact *contact;
1184 GtkTreeModel *model;
1187 model = gtk_tree_view_get_model (GTK_TREE_VIEW (view));
1189 gtk_tree_model_get_iter (model, &iter, path);
1190 gtk_tree_model_get (model, &iter, COL_CONTACT, &contact, -1);
1193 contact_list_view_action_activated (view, contact);
1194 g_object_unref (contact);
1199 contact_list_view_row_expand_or_collapse_cb (EmpathyContactListView *view,
1204 GtkTreeModel *model;
1208 model = gtk_tree_view_get_model (GTK_TREE_VIEW (view));
1210 gtk_tree_model_get (model, iter,
1214 expanded = GPOINTER_TO_INT (user_data);
1215 empathy_contact_group_set_expanded (name, expanded);
1221 contact_list_view_action_cb (GtkAction *action,
1222 EmpathyContactListView *view)
1224 EmpathyContactListViewPriv *priv;
1225 EmpathyContact *contact;
1230 priv = GET_PRIV (view);
1232 name = gtk_action_get_name (action);
1237 empathy_debug (DEBUG_DOMAIN, "Action:'%s' activated", name);
1239 contact = empathy_contact_list_view_get_selected (view);
1240 group = empathy_contact_list_view_get_selected_group (view);
1241 parent = empathy_get_toplevel_window (GTK_WIDGET (view));
1243 if (contact && strcmp (name, "Chat") == 0) {
1244 contact_list_view_action_activated (view, contact);
1246 else if (contact && strcmp (name, "Information") == 0) {
1247 empathy_contact_information_dialog_show (contact, parent, FALSE);
1249 else if (contact && strcmp (name, "Edit") == 0) {
1250 empathy_contact_information_dialog_show (contact, parent, TRUE);
1252 else if (contact && strcmp (name, "Remove") == 0) {
1253 /* FIXME: Ask for confirmation */
1254 EmpathyContactList *list;
1256 list = empathy_contact_list_store_get_list_iface (priv->store);
1257 empathy_contact_list_remove (list, contact,
1258 _("Sorry, I don't want you in my contact list anymore."));
1260 else if (contact && strcmp (name, "Invite") == 0) {
1262 else if (contact && strcmp (name, "SendFile") == 0) {
1264 else if (contact && strcmp (name, "Log") == 0) {
1265 empathy_log_window_show (empathy_contact_get_account (contact),
1266 empathy_contact_get_id (contact),
1270 else if (group && strcmp (name, "Rename") == 0) {
1275 g_object_unref (contact);
1280 contact_list_view_action_activated (EmpathyContactListView *view,
1281 EmpathyContact *contact)
1285 mc = empathy_mission_control_new ();
1286 mission_control_request_channel (mc,
1287 empathy_contact_get_account (contact),
1288 TP_IFACE_CHANNEL_TYPE_TEXT,
1289 empathy_contact_get_handle (contact),
1290 TP_HANDLE_TYPE_CONTACT,
1292 g_object_unref (mc);