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 g_signal_connect (priv->store, "row-has-child-toggled",
523 G_CALLBACK (contact_list_view_row_has_child_toggled_cb),
525 gtk_tree_view_set_model (GTK_TREE_VIEW (view),
526 GTK_TREE_MODEL (priv->store));
530 "headers-visible", FALSE,
532 "show-expanders", FALSE,
535 col = gtk_tree_view_column_new ();
538 cell = gtk_cell_renderer_pixbuf_new ();
539 gtk_tree_view_column_pack_start (col, cell, FALSE);
540 gtk_tree_view_column_set_cell_data_func (
542 (GtkTreeCellDataFunc) contact_list_view_pixbuf_cell_data_func,
552 cell = empathy_cell_renderer_text_new ();
553 gtk_tree_view_column_pack_start (col, cell, TRUE);
554 gtk_tree_view_column_set_cell_data_func (
556 (GtkTreeCellDataFunc) contact_list_view_text_cell_data_func,
559 gtk_tree_view_column_add_attribute (col, cell,
561 gtk_tree_view_column_add_attribute (col, cell,
562 "status", COL_STATUS);
563 gtk_tree_view_column_add_attribute (col, cell,
564 "is_group", COL_IS_GROUP);
567 cell = gtk_cell_renderer_pixbuf_new ();
568 gtk_tree_view_column_pack_start (col, cell, FALSE);
569 gtk_tree_view_column_set_cell_data_func (
571 (GtkTreeCellDataFunc) contact_list_view_avatar_cell_data_func,
583 cell = empathy_cell_renderer_expander_new ();
584 gtk_tree_view_column_pack_end (col, cell, FALSE);
585 gtk_tree_view_column_set_cell_data_func (
587 (GtkTreeCellDataFunc) contact_list_view_expander_cell_data_func,
590 /* Actually add the column now we have added all cell renderers */
591 gtk_tree_view_append_column (GTK_TREE_VIEW (view), col);
594 for (i = 0; i < G_N_ELEMENTS (drag_types_dest); ++i) {
595 drag_atoms_dest[i] = gdk_atom_intern (drag_types_dest[i].target,
599 for (i = 0; i < G_N_ELEMENTS (drag_types_source); ++i) {
600 drag_atoms_source[i] = gdk_atom_intern (drag_types_source[i].target,
604 /* Note: We support the COPY action too, but need to make the
605 * MOVE action the default.
607 gtk_drag_source_set (GTK_WIDGET (view),
610 G_N_ELEMENTS (drag_types_source),
611 GDK_ACTION_MOVE | GDK_ACTION_COPY);
613 gtk_drag_dest_set (GTK_WIDGET (view),
614 GTK_DEST_DEFAULT_ALL,
616 G_N_ELEMENTS (drag_types_dest),
617 GDK_ACTION_MOVE | GDK_ACTION_COPY);
621 contact_list_view_row_has_child_toggled_cb (GtkTreeModel *model,
624 EmpathyContactListView *view)
626 gboolean is_group = FALSE;
629 gtk_tree_model_get (model, iter,
630 COL_IS_GROUP, &is_group,
634 if (!is_group || G_STR_EMPTY (name)) {
639 if (empathy_contact_group_get_expanded (name)) {
640 g_signal_handlers_block_by_func (view,
641 contact_list_view_row_expand_or_collapse_cb,
642 GINT_TO_POINTER (TRUE));
643 gtk_tree_view_expand_row (GTK_TREE_VIEW (view), path, TRUE);
644 g_signal_handlers_unblock_by_func (view,
645 contact_list_view_row_expand_or_collapse_cb,
646 GINT_TO_POINTER (TRUE));
648 g_signal_handlers_block_by_func (view,
649 contact_list_view_row_expand_or_collapse_cb,
650 GINT_TO_POINTER (FALSE));
651 gtk_tree_view_collapse_row (GTK_TREE_VIEW (view), path);
652 g_signal_handlers_unblock_by_func (view,
653 contact_list_view_row_expand_or_collapse_cb,
654 GINT_TO_POINTER (FALSE));
661 contact_list_view_drag_data_received (GtkWidget *widget,
662 GdkDragContext *context,
665 GtkSelectionData *selection,
669 EmpathyContactListViewPriv *priv;
670 EmpathyContactList *list;
671 EmpathyContactFactory *factory;
675 GtkTreeViewDropPosition position;
676 EmpathyContact *contact = NULL;
679 gchar *new_group = NULL;
680 gchar *old_group = NULL;
683 priv = GET_PRIV (widget);
685 id = (const gchar*) selection->data;
686 empathy_debug (DEBUG_DOMAIN, "Received %s%s drag & drop contact from roster with id:'%s'",
687 context->action == GDK_ACTION_MOVE ? "move" : "",
688 context->action == GDK_ACTION_COPY ? "copy" : "",
691 strv = g_strsplit (id, "/", 2);
692 factory = empathy_contact_factory_new ();
693 account = mc_account_lookup (strv[0]);
695 contact = empathy_contact_factory_get_from_id (factory,
698 g_object_unref (account);
700 g_object_unref (factory);
701 g_object_unref (account);
705 empathy_debug (DEBUG_DOMAIN, "No contact found associated with drag & drop");
709 model = gtk_tree_view_get_model (GTK_TREE_VIEW (widget));
711 /* Get source group information. */
712 if (priv->drag_row) {
713 path = gtk_tree_row_reference_get_path (priv->drag_row);
715 old_group = empathy_contact_list_store_get_parent_group (model, path, NULL);
716 gtk_tree_path_free (path);
720 /* Get destination group information. */
721 is_row = gtk_tree_view_get_dest_row_at_pos (GTK_TREE_VIEW (widget),
728 new_group = empathy_contact_list_store_get_parent_group (model, path, NULL);
729 gtk_tree_path_free (path);
732 empathy_debug (DEBUG_DOMAIN,
733 "contact %s (%d) dragged from '%s' to '%s'",
734 empathy_contact_get_id (contact),
735 empathy_contact_get_handle (contact),
736 old_group, new_group);
738 list = empathy_contact_list_store_get_list_iface (priv->store);
740 empathy_contact_list_add_to_group (list, contact, new_group);
742 if (old_group && context->action == GDK_ACTION_MOVE) {
743 empathy_contact_list_remove_from_group (list, contact, old_group);
749 gtk_drag_finish (context, TRUE, FALSE, GDK_CURRENT_TIME);
753 contact_list_view_drag_motion (GtkWidget *widget,
754 GdkDragContext *context,
759 static DragMotionData *dm = NULL;
762 gboolean is_different = FALSE;
763 gboolean cleanup = TRUE;
765 is_row = gtk_tree_view_get_path_at_pos (GTK_TREE_VIEW (widget),
776 cleanup &= (dm && gtk_tree_path_compare (dm->path, path) != 0);
777 is_different = (!dm || (dm && gtk_tree_path_compare (dm->path, path) != 0));
782 if (!is_different && !cleanup) {
787 gtk_tree_path_free (dm->path);
788 if (dm->timeout_id) {
789 g_source_remove (dm->timeout_id);
797 if (!gtk_tree_view_row_expanded (GTK_TREE_VIEW (widget), path)) {
798 dm = g_new0 (DragMotionData, 1);
800 dm->view = EMPATHY_CONTACT_LIST_VIEW (widget);
801 dm->path = gtk_tree_path_copy (path);
803 dm->timeout_id = g_timeout_add (
805 (GSourceFunc) contact_list_view_drag_motion_cb,
813 contact_list_view_drag_motion_cb (DragMotionData *data)
815 gtk_tree_view_expand_row (GTK_TREE_VIEW (data->view),
819 data->timeout_id = 0;
825 contact_list_view_drag_begin (GtkWidget *widget,
826 GdkDragContext *context)
828 EmpathyContactListViewPriv *priv;
829 GtkTreeSelection *selection;
834 priv = GET_PRIV (widget);
836 GTK_WIDGET_CLASS (empathy_contact_list_view_parent_class)->drag_begin (widget,
839 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (widget));
840 if (!gtk_tree_selection_get_selected (selection, &model, &iter)) {
844 path = gtk_tree_model_get_path (model, &iter);
845 priv->drag_row = gtk_tree_row_reference_new (model, path);
846 gtk_tree_path_free (path);
850 contact_list_view_drag_data_get (GtkWidget *widget,
851 GdkDragContext *context,
852 GtkSelectionData *selection,
856 EmpathyContactListViewPriv *priv;
857 GtkTreePath *src_path;
860 EmpathyContact *contact;
862 const gchar *contact_id;
863 const gchar *account_id;
867 priv = GET_PRIV (widget);
869 model = gtk_tree_view_get_model (GTK_TREE_VIEW (widget));
870 if (!priv->drag_row) {
874 src_path = gtk_tree_row_reference_get_path (priv->drag_row);
879 if (!gtk_tree_model_get_iter (model, &iter, src_path)) {
880 gtk_tree_path_free (src_path);
884 gtk_tree_path_free (src_path);
886 contact = empathy_contact_list_view_get_selected (EMPATHY_CONTACT_LIST_VIEW (widget));
891 account = empathy_contact_get_account (contact);
892 account_id = mc_account_get_unique_name (account);
893 contact_id = empathy_contact_get_id (contact);
894 g_object_unref (contact);
895 str = g_strconcat (account_id, "/", contact_id, NULL);
898 case DND_DRAG_TYPE_CONTACT_ID:
899 gtk_selection_data_set (selection, drag_atoms_source[info], 8,
900 (guchar*)str, strlen (str) + 1);
908 contact_list_view_drag_end (GtkWidget *widget,
909 GdkDragContext *context)
911 EmpathyContactListViewPriv *priv;
913 priv = GET_PRIV (widget);
915 GTK_WIDGET_CLASS (empathy_contact_list_view_parent_class)->drag_end (widget,
918 if (priv->drag_row) {
919 gtk_tree_row_reference_free (priv->drag_row);
920 priv->drag_row = NULL;
925 contact_list_view_drag_drop (GtkWidget *widget,
926 GdkDragContext *drag_context,
935 contact_list_view_cell_set_background (EmpathyContactListView *view,
936 GtkCellRenderer *cell,
943 style = gtk_widget_get_style (GTK_WIDGET (view));
947 color = style->bg[GTK_STATE_SELECTED];
949 /* Here we take the current theme colour and add it to
950 * the colour for white and average the two. This
951 * gives a colour which is inline with the theme but
954 color.red = (color.red + (style->white).red) / 2;
955 color.green = (color.green + (style->white).green) / 2;
956 color.blue = (color.blue + (style->white).blue) / 2;
959 "cell-background-gdk", &color,
963 "cell-background-gdk", NULL,
968 "cell-background-gdk", NULL,
974 contact_list_view_pixbuf_cell_data_func (GtkTreeViewColumn *tree_column,
975 GtkCellRenderer *cell,
978 EmpathyContactListView *view)
984 gtk_tree_model_get (model, iter,
985 COL_IS_GROUP, &is_group,
986 COL_IS_ACTIVE, &is_active,
987 COL_ICON_STATUS, &icon_name,
991 "visible", !is_group,
992 "icon-name", icon_name,
997 contact_list_view_cell_set_background (view, cell, is_group, is_active);
1001 contact_list_view_avatar_cell_data_func (GtkTreeViewColumn *tree_column,
1002 GtkCellRenderer *cell,
1003 GtkTreeModel *model,
1005 EmpathyContactListView *view)
1008 gboolean show_avatar;
1012 gtk_tree_model_get (model, iter,
1013 COL_PIXBUF_AVATAR, &pixbuf,
1014 COL_PIXBUF_AVATAR_VISIBLE, &show_avatar,
1015 COL_IS_GROUP, &is_group,
1016 COL_IS_ACTIVE, &is_active,
1020 "visible", !is_group && show_avatar,
1025 g_object_unref (pixbuf);
1028 contact_list_view_cell_set_background (view, cell, is_group, is_active);
1032 contact_list_view_text_cell_data_func (GtkTreeViewColumn *tree_column,
1033 GtkCellRenderer *cell,
1034 GtkTreeModel *model,
1036 EmpathyContactListView *view)
1040 gboolean show_status;
1042 gtk_tree_model_get (model, iter,
1043 COL_IS_GROUP, &is_group,
1044 COL_IS_ACTIVE, &is_active,
1045 COL_STATUS_VISIBLE, &show_status,
1049 "show-status", show_status,
1052 contact_list_view_cell_set_background (view, cell, is_group, is_active);
1056 contact_list_view_expander_cell_data_func (GtkTreeViewColumn *column,
1057 GtkCellRenderer *cell,
1058 GtkTreeModel *model,
1060 EmpathyContactListView *view)
1065 gtk_tree_model_get (model, iter,
1066 COL_IS_GROUP, &is_group,
1067 COL_IS_ACTIVE, &is_active,
1070 if (gtk_tree_model_iter_has_child (model, iter)) {
1072 gboolean row_expanded;
1074 path = gtk_tree_model_get_path (model, iter);
1075 row_expanded = gtk_tree_view_row_expanded (GTK_TREE_VIEW (column->tree_view), path);
1076 gtk_tree_path_free (path);
1080 "expander-style", row_expanded ? GTK_EXPANDER_EXPANDED : GTK_EXPANDER_COLLAPSED,
1083 g_object_set (cell, "visible", FALSE, NULL);
1086 contact_list_view_cell_set_background (view, cell, is_group, is_active);
1090 contact_list_view_get_contact_menu (EmpathyContactListView *view,
1091 gboolean can_send_file,
1092 gboolean can_show_log)
1094 EmpathyContactListViewPriv *priv;
1098 priv = GET_PRIV (view);
1100 /* Sort out sensitive items */
1101 action = gtk_ui_manager_get_action (priv->ui, "/Contact/Log");
1102 gtk_action_set_sensitive (action, can_show_log);
1104 action = gtk_ui_manager_get_action (priv->ui, "/Contact/SendFile");
1105 gtk_action_set_visible (action, can_send_file);
1107 widget = gtk_ui_manager_get_widget (priv->ui, "/Contact");
1113 contact_list_view_button_press_event_cb (EmpathyContactListView *view,
1114 GdkEventButton *event,
1117 EmpathyContactListViewPriv *priv;
1118 EmpathyContact *contact;
1120 GtkTreeSelection *selection;
1121 GtkTreeModel *model;
1123 gboolean row_exists;
1126 if (event->button != 3) {
1130 priv = GET_PRIV (view);
1132 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (view));
1133 model = gtk_tree_view_get_model (GTK_TREE_VIEW (view));
1135 gtk_widget_grab_focus (GTK_WIDGET (view));
1137 row_exists = gtk_tree_view_get_path_at_pos (GTK_TREE_VIEW (view),
1145 gtk_tree_selection_unselect_all (selection);
1146 gtk_tree_selection_select_path (selection, path);
1148 gtk_tree_model_get_iter (model, &iter, path);
1149 gtk_tree_path_free (path);
1151 gtk_tree_model_get (model, &iter, COL_CONTACT, &contact, -1);
1154 menu = empathy_contact_list_view_get_contact_menu (view, contact);
1155 g_object_unref (contact);
1157 menu = empathy_contact_list_view_get_group_menu (view);
1164 gtk_widget_show (menu);
1166 gtk_menu_popup (GTK_MENU (menu),
1167 NULL, NULL, NULL, NULL,
1168 event->button, event->time);
1174 contact_list_view_row_activated_cb (EmpathyContactListView *view,
1176 GtkTreeViewColumn *col,
1179 EmpathyContact *contact;
1180 GtkTreeModel *model;
1183 model = gtk_tree_view_get_model (GTK_TREE_VIEW (view));
1185 gtk_tree_model_get_iter (model, &iter, path);
1186 gtk_tree_model_get (model, &iter, COL_CONTACT, &contact, -1);
1189 contact_list_view_action_activated (view, contact);
1190 g_object_unref (contact);
1195 contact_list_view_row_expand_or_collapse_cb (EmpathyContactListView *view,
1200 GtkTreeModel *model;
1204 model = gtk_tree_view_get_model (GTK_TREE_VIEW (view));
1206 gtk_tree_model_get (model, iter,
1210 expanded = GPOINTER_TO_INT (user_data);
1211 empathy_contact_group_set_expanded (name, expanded);
1217 contact_list_view_action_cb (GtkAction *action,
1218 EmpathyContactListView *view)
1220 EmpathyContactListViewPriv *priv;
1221 EmpathyContact *contact;
1226 priv = GET_PRIV (view);
1228 name = gtk_action_get_name (action);
1233 empathy_debug (DEBUG_DOMAIN, "Action:'%s' activated", name);
1235 contact = empathy_contact_list_view_get_selected (view);
1236 group = empathy_contact_list_view_get_selected_group (view);
1237 parent = empathy_get_toplevel_window (GTK_WIDGET (view));
1239 if (contact && strcmp (name, "Chat") == 0) {
1240 contact_list_view_action_activated (view, contact);
1242 else if (contact && strcmp (name, "Information") == 0) {
1243 empathy_contact_information_dialog_show (contact, parent, FALSE);
1245 else if (contact && strcmp (name, "Edit") == 0) {
1246 empathy_contact_information_dialog_show (contact, parent, TRUE);
1248 else if (contact && strcmp (name, "Remove") == 0) {
1249 /* FIXME: Ask for confirmation */
1250 EmpathyContactList *list;
1252 list = empathy_contact_list_store_get_list_iface (priv->store);
1253 empathy_contact_list_remove (list, contact,
1254 _("Sorry, I don't want you in my contact list anymore."));
1256 else if (contact && strcmp (name, "Invite") == 0) {
1258 else if (contact && strcmp (name, "SendFile") == 0) {
1260 else if (contact && strcmp (name, "Log") == 0) {
1261 empathy_log_window_show (empathy_contact_get_account (contact),
1262 empathy_contact_get_id (contact),
1266 else if (group && strcmp (name, "Rename") == 0) {
1271 g_object_unref (contact);
1276 contact_list_view_action_activated (EmpathyContactListView *view,
1277 EmpathyContact *contact)
1281 mc = empathy_mission_control_new ();
1282 mission_control_request_channel (mc,
1283 empathy_contact_get_account (contact),
1284 TP_IFACE_CHANNEL_TYPE_TEXT,
1285 empathy_contact_get_handle (contact),
1286 TP_HANDLE_TYPE_CONTACT,
1288 g_object_unref (mc);