]> git.0d.be Git - empathy.git/blob - libempathy-gtk/empathy-contact-list-view.c
Add convinience functions empathy_chat_with_contact() and empathy_chat_with_contact_i...
[empathy.git] / libempathy-gtk / empathy-contact-list-view.c
1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2 /*
3  * Copyright (C) 2005-2007 Imendio AB
4  * Copyright (C) 2007 Collabora Ltd.
5  *
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.
10  *
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.
15  *
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.
20  *
21  * Authors: Mikael Hallendal <micke@imendio.com>
22  *          Martyn Russell <martyn@imendio.com>
23  *          Xavier Claessens <xclaesse@gmail.com>
24  */
25
26 #include "config.h"
27
28 #include <string.h>
29
30 #include <glib/gi18n.h>
31 #include <gtk/gtk.h>
32 #include <glade/glade.h>
33
34 #include <libtelepathy/tp-helpers.h>
35
36 #include <libmissioncontrol/mc-account.h>
37 #include <libmissioncontrol/mission-control.h>
38
39 #include <libempathy/empathy-contact-factory.h>
40 #include <libempathy/empathy-contact-list.h>
41 #include <libempathy/empathy-log-manager.h>
42 #include <libempathy/empathy-tp-group.h>
43 #include <libempathy/empathy-debug.h>
44 #include <libempathy/empathy-utils.h>
45 #include <libempathy/empathy-marshal.h>
46
47 #include "empathy-contact-list-view.h"
48 #include "empathy-contact-list-store.h"
49 #include "empathy-images.h"
50 #include "empathy-contact-groups.h"
51 #include "empathy-cell-renderer-expander.h"
52 #include "empathy-cell-renderer-text.h"
53 #include "empathy-cell-renderer-activatable.h"
54 #include "empathy-ui-utils.h"
55 #include "empathy-contact-dialogs.h"
56 //#include "empathy-chat-invite.h"
57 //#include "empathy-ft-window.h"
58 #include "empathy-log-window.h"
59
60 #define DEBUG_DOMAIN "ContactListView"
61
62 /* Flashing delay for icons (milliseconds). */
63 #define FLASH_TIMEOUT 500
64
65 /* Active users are those which have recently changed state
66  * (e.g. online, offline or from normal to a busy state).
67  */
68
69 #define GET_PRIV(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), EMPATHY_TYPE_CONTACT_LIST_VIEW, EmpathyContactListViewPriv))
70
71 struct _EmpathyContactListViewPriv {
72         EmpathyContactListStore *store;
73         GtkUIManager            *ui;
74         GtkTreeRowReference     *drag_row;
75         gboolean                 interactive;
76 };
77
78 typedef struct {
79         EmpathyContactListView *view;
80         GtkTreePath           *path;
81         guint                  timeout_id;
82 } DragMotionData;
83
84 typedef struct {
85         EmpathyContactListView *view;
86         EmpathyContact         *contact;
87         gboolean               remove;
88 } ShowActiveData;
89
90 static void        empathy_contact_list_view_class_init         (EmpathyContactListViewClass *klass);
91 static void        empathy_contact_list_view_init               (EmpathyContactListView      *list);
92 static void        contact_list_view_finalize                  (GObject                    *object);
93 static void        contact_list_view_get_property              (GObject                    *object,
94                                                                 guint                       param_id,
95                                                                 GValue                     *value,
96                                                                 GParamSpec                 *pspec);
97 static void        contact_list_view_set_property              (GObject                    *object,
98                                                                 guint                       param_id,
99                                                                 const GValue               *value,
100                                                                 GParamSpec                 *pspec);
101 static void        contact_list_view_setup                     (EmpathyContactListView      *view);
102 static void        contact_list_view_row_has_child_toggled_cb  (GtkTreeModel               *model,
103                                                                 GtkTreePath                *path,
104                                                                 GtkTreeIter                *iter,
105                                                                 EmpathyContactListView      *view);
106 static void        contact_list_view_drag_data_received        (GtkWidget                  *widget,
107                                                                 GdkDragContext             *context,
108                                                                 gint                        x,
109                                                                 gint                        y,
110                                                                 GtkSelectionData           *selection,
111                                                                 guint                       info,
112                                                                 guint                       time);
113 static gboolean    contact_list_view_drag_motion               (GtkWidget                  *widget,
114                                                                 GdkDragContext             *context,
115                                                                 gint                        x,
116                                                                 gint                        y,
117                                                                 guint                       time);
118 static gboolean    contact_list_view_drag_motion_cb            (DragMotionData             *data);
119 static void        contact_list_view_drag_begin                (GtkWidget                  *widget,
120                                                                 GdkDragContext             *context);
121 static void        contact_list_view_drag_data_get             (GtkWidget                  *widget,
122                                                                 GdkDragContext             *context,
123                                                                 GtkSelectionData           *selection,
124                                                                 guint                       info,
125                                                                 guint                       time);
126 static void        contact_list_view_drag_end                  (GtkWidget                  *widget,
127                                                                 GdkDragContext             *context);
128 static gboolean    contact_list_view_drag_drop                 (GtkWidget                  *widget,
129                                                                 GdkDragContext             *drag_context,
130                                                                 gint                        x,
131                                                                 gint                        y,
132                                                                 guint                       time);
133 static void        contact_list_view_cell_set_background       (EmpathyContactListView      *view,
134                                                                 GtkCellRenderer            *cell,
135                                                                 gboolean                    is_group,
136                                                                 gboolean                    is_active);
137 static void        contact_list_view_pixbuf_cell_data_func     (GtkTreeViewColumn          *tree_column,
138                                                                 GtkCellRenderer            *cell,
139                                                                 GtkTreeModel               *model,
140                                                                 GtkTreeIter                *iter,
141                                                                 EmpathyContactListView     *view);
142 #ifdef HAVE_VOIP
143 static void        contact_list_view_voip_cell_data_func       (GtkTreeViewColumn          *tree_column,
144                                                                 GtkCellRenderer            *cell,
145                                                                 GtkTreeModel               *model,
146                                                                 GtkTreeIter                *iter,
147                                                                 EmpathyContactListView     *view);
148 #endif
149 static void        contact_list_view_avatar_cell_data_func     (GtkTreeViewColumn          *tree_column,
150                                                                 GtkCellRenderer            *cell,
151                                                                 GtkTreeModel               *model,
152                                                                 GtkTreeIter                *iter,
153                                                                 EmpathyContactListView      *view);
154 static void        contact_list_view_text_cell_data_func       (GtkTreeViewColumn          *tree_column,
155                                                                 GtkCellRenderer            *cell,
156                                                                 GtkTreeModel               *model,
157                                                                 GtkTreeIter                *iter,
158                                                                 EmpathyContactListView      *view);
159 static void        contact_list_view_expander_cell_data_func   (GtkTreeViewColumn          *column,
160                                                                 GtkCellRenderer            *cell,
161                                                                 GtkTreeModel               *model,
162                                                                 GtkTreeIter                *iter,
163                                                                 EmpathyContactListView      *view);
164 static GtkWidget * contact_list_view_get_contact_menu          (EmpathyContactListView      *view,
165                                                                 gboolean                    can_send_file,
166                                                                 gboolean                    can_show_log,
167                                                                 gboolean                    can_voip);
168 static gboolean    contact_list_view_button_press_event_cb     (EmpathyContactListView      *view,
169                                                                 GdkEventButton             *event,
170                                                                 gpointer                    user_data);
171 static void        contact_list_view_row_activated_cb          (EmpathyContactListView      *view,
172                                                                 GtkTreePath                *path,
173                                                                 GtkTreeViewColumn          *col,
174                                                                 gpointer                    user_data);
175 #ifdef HAVE_VOIP
176 static void        contact_list_view_voip_activated_cb         (EmpathyCellRendererActivatable *cell,
177                                                                 const gchar                *path_string,
178                                                                 EmpathyContactListView     *view);
179 #endif
180 static void        contact_list_view_row_expand_or_collapse_cb (EmpathyContactListView      *view,
181                                                                 GtkTreeIter                *iter,
182                                                                 GtkTreePath                *path,
183                                                                 gpointer                    user_data);
184 static void        contact_list_view_action_cb                 (GtkAction                  *action,
185                                                                 EmpathyContactListView      *view);
186 static void        contact_list_view_voip_activated            (EmpathyContactListView      *view,
187                                                                 EmpathyContact              *contact);
188
189 enum {
190         PROP_0,
191         PROP_INTERACTIVE
192 };
193
194 static const GtkActionEntry entries[] = {
195         { "ContactMenu", NULL,
196           N_("_Contact"), NULL, NULL,
197           NULL
198         },
199         { "GroupMenu", NULL,
200           N_("_Group"),NULL, NULL,
201           NULL
202         },
203         { "Chat", EMPATHY_IMAGE_MESSAGE,
204           N_("_Chat"), NULL, N_("Chat with contact"),
205           G_CALLBACK (contact_list_view_action_cb)
206         },
207         { "Information", EMPATHY_IMAGE_CONTACT_INFORMATION,
208           N_("Infor_mation"), "<control>I", N_("View contact information"),
209           G_CALLBACK (contact_list_view_action_cb)
210         },
211         { "Rename", NULL,
212           N_("Re_name"), NULL, N_("Rename"),
213           G_CALLBACK (contact_list_view_action_cb)
214         },
215         { "Edit", GTK_STOCK_EDIT,
216           N_("_Edit"), NULL, N_("Edit the groups and name for this contact"),
217           G_CALLBACK (contact_list_view_action_cb)
218         },
219         { "Remove", GTK_STOCK_REMOVE,
220           N_("_Remove"), NULL, N_("Remove contact"),
221           G_CALLBACK (contact_list_view_action_cb)
222         },
223         { "Invite", EMPATHY_IMAGE_GROUP_MESSAGE,
224           N_("_Invite to Chat Room"), NULL, N_("Invite to a currently open chat room"),
225           G_CALLBACK (contact_list_view_action_cb)
226         },
227         { "SendFile", NULL,
228           N_("_Send File..."), NULL, N_("Send a file"),
229           G_CALLBACK (contact_list_view_action_cb)
230         },
231         { "Log", EMPATHY_IMAGE_LOG,
232           N_("_View Previous Conversations"), NULL, N_("View previous conversations with this contact"),
233           G_CALLBACK (contact_list_view_action_cb)
234         },
235 #ifdef HAVE_VOIP
236         { "Call", EMPATHY_IMAGE_VOIP,
237           N_("_Call"), NULL, N_("Start a voice or video conversation with this contact"),
238           G_CALLBACK (contact_list_view_action_cb)
239         },
240 #endif
241 };
242
243 static guint n_entries = G_N_ELEMENTS (entries);
244
245 static const gchar *ui_info =
246         "<ui>"
247         "  <popup name='Contact'>"
248         "    <menuitem action='Chat'/>"
249 #ifdef HAVE_VOIP
250         "    <menuitem action='Call'/>"
251 #endif
252         "    <menuitem action='Log'/>"
253         "    <menuitem action='SendFile'/>"
254         "    <separator/>"
255         "    <menuitem action='Invite'/>"
256         "    <separator/>"
257         "    <menuitem action='Edit'/>"
258         "    <menuitem action='Remove'/>"
259         "    <separator/>"
260         "    <menuitem action='Information'/>"
261         "  </popup>"
262         "  <popup name='Group'>"
263         "    <menuitem action='Rename'/>"
264         "  </popup>"
265         "</ui>";
266
267 enum DndDragType {
268         DND_DRAG_TYPE_CONTACT_ID,
269         DND_DRAG_TYPE_URL,
270         DND_DRAG_TYPE_STRING,
271 };
272
273 static const GtkTargetEntry drag_types_dest[] = {
274         { "text/contact-id", 0, DND_DRAG_TYPE_CONTACT_ID },
275         { "text/uri-list",   0, DND_DRAG_TYPE_URL },
276         { "text/plain",      0, DND_DRAG_TYPE_STRING },
277         { "STRING",          0, DND_DRAG_TYPE_STRING },
278 };
279
280 static const GtkTargetEntry drag_types_source[] = {
281         { "text/contact-id", 0, DND_DRAG_TYPE_CONTACT_ID },
282 };
283
284 static GdkAtom drag_atoms_dest[G_N_ELEMENTS (drag_types_dest)];
285 static GdkAtom drag_atoms_source[G_N_ELEMENTS (drag_types_source)];
286
287 enum {
288         DRAG_CONTACT_RECEIVED,
289         LAST_SIGNAL
290 };
291
292 static guint signals[LAST_SIGNAL];
293
294 G_DEFINE_TYPE (EmpathyContactListView, empathy_contact_list_view, GTK_TYPE_TREE_VIEW);
295
296 static void
297 empathy_contact_list_view_class_init (EmpathyContactListViewClass *klass)
298 {
299         GObjectClass   *object_class = G_OBJECT_CLASS (klass);
300         GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
301
302         object_class->finalize = contact_list_view_finalize;
303         object_class->get_property = contact_list_view_get_property;
304         object_class->set_property = contact_list_view_set_property;
305
306         widget_class->drag_data_received = contact_list_view_drag_data_received;
307         widget_class->drag_drop          = contact_list_view_drag_drop;
308         widget_class->drag_begin         = contact_list_view_drag_begin;
309         widget_class->drag_data_get      = contact_list_view_drag_data_get;
310         widget_class->drag_end           = contact_list_view_drag_end;
311         /* FIXME: noticed but when you drag the row over the treeview
312          * fast, it seems to stop redrawing itself, if we don't
313          * connect this signal, all is fine.
314          */
315         widget_class->drag_motion        = contact_list_view_drag_motion;
316
317         signals[DRAG_CONTACT_RECEIVED] =
318                 g_signal_new ("drag-contact-received",
319                               G_OBJECT_CLASS_TYPE (klass),
320                               G_SIGNAL_RUN_LAST,
321                               0,
322                               NULL, NULL,
323                               empathy_marshal_VOID__OBJECT_STRING_STRING,
324                               G_TYPE_NONE,
325                               3, EMPATHY_TYPE_CONTACT, G_TYPE_STRING, G_TYPE_STRING);
326
327         g_object_class_install_property (object_class,
328                                          PROP_INTERACTIVE,
329                                          g_param_spec_boolean ("interactive",
330                                                                "View is interactive",
331                                                                "Is the view interactive",
332                                                                FALSE,
333                                                                G_PARAM_READWRITE));
334
335         g_type_class_add_private (object_class, sizeof (EmpathyContactListViewPriv));
336 }
337
338 static void
339 empathy_contact_list_view_init (EmpathyContactListView *view)
340 {
341         EmpathyContactListViewPriv *priv;
342         GtkActionGroup            *action_group;
343         GError                    *error = NULL;
344
345         priv = GET_PRIV (view);
346
347         /* Get saved group states. */
348         empathy_contact_groups_get_all ();
349
350         /* Set up UI Manager */
351         priv->ui = gtk_ui_manager_new ();
352
353         action_group = gtk_action_group_new ("Actions");
354         gtk_action_group_set_translation_domain (action_group, GETTEXT_PACKAGE);
355         gtk_action_group_add_actions (action_group, entries, n_entries, view);
356         gtk_ui_manager_insert_action_group (priv->ui, action_group, 0);
357
358         if (!gtk_ui_manager_add_ui_from_string (priv->ui, ui_info, -1, &error)) {
359                 g_warning ("Could not build contact menus from string:'%s'", error->message);
360                 g_error_free (error);
361         }
362
363         g_object_unref (action_group);
364
365         gtk_tree_view_set_row_separator_func (GTK_TREE_VIEW (view), 
366                                               empathy_contact_list_store_row_separator_func,
367                                               NULL, NULL);
368
369         /* Connect to tree view signals rather than override. */
370         g_signal_connect (view,
371                           "button-press-event",
372                           G_CALLBACK (contact_list_view_button_press_event_cb),
373                           NULL);
374         g_signal_connect (view,
375                           "row-activated",
376                           G_CALLBACK (contact_list_view_row_activated_cb),
377                           NULL);
378         g_signal_connect (view,
379                           "row-expanded",
380                           G_CALLBACK (contact_list_view_row_expand_or_collapse_cb),
381                           GINT_TO_POINTER (TRUE));
382         g_signal_connect (view,
383                           "row-collapsed",
384                           G_CALLBACK (contact_list_view_row_expand_or_collapse_cb),
385                           GINT_TO_POINTER (FALSE));
386 }
387
388 static void
389 contact_list_view_finalize (GObject *object)
390 {
391         EmpathyContactListViewPriv *priv;
392
393         priv = GET_PRIV (object);
394
395         if (priv->ui) {
396                 g_object_unref (priv->ui);
397         }
398         if (priv->store) {
399                 g_object_unref (priv->store);
400         }
401
402         G_OBJECT_CLASS (empathy_contact_list_view_parent_class)->finalize (object);
403 }
404
405 static void
406 contact_list_view_get_property (GObject    *object,
407                                 guint       param_id,
408                                 GValue     *value,
409                                 GParamSpec *pspec)
410 {
411         EmpathyContactListViewPriv *priv;
412
413         priv = GET_PRIV (object);
414
415         switch (param_id) {
416         case PROP_INTERACTIVE:
417                 g_value_set_boolean (value, priv->interactive);
418                 break;
419         default:
420                 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
421                 break;
422         };
423 }
424
425 static void
426 contact_list_view_set_property (GObject      *object,
427                                 guint         param_id,
428                                 const GValue *value,
429                                 GParamSpec   *pspec)
430 {
431         EmpathyContactListView     *view = EMPATHY_CONTACT_LIST_VIEW (object);
432         EmpathyContactListViewPriv *priv;
433
434         priv = GET_PRIV (object);
435
436         switch (param_id) {
437         case PROP_INTERACTIVE:
438                 empathy_contact_list_view_set_interactive (view, g_value_get_boolean (value));
439                 break;
440         default:
441                 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
442                 break;
443         };
444 }
445
446 EmpathyContactListView *
447 empathy_contact_list_view_new (EmpathyContactListStore *store)
448 {
449         EmpathyContactListViewPriv *priv;
450         EmpathyContactListView     *view;
451         
452         view = g_object_new (EMPATHY_TYPE_CONTACT_LIST_VIEW, NULL);
453         priv = GET_PRIV (view);
454
455         priv->store = g_object_ref (store);
456         contact_list_view_setup (view);
457
458         return view;
459 }
460
461 void
462 empathy_contact_list_view_set_interactive (EmpathyContactListView  *view,
463                                            gboolean                 interactive)
464 {
465         EmpathyContactListViewPriv *priv = GET_PRIV (view);
466
467         g_return_if_fail (EMPATHY_IS_CONTACT_LIST_VIEW (view));
468
469         priv->interactive = interactive;
470         g_object_notify (G_OBJECT (view), "interactive");
471 }
472
473 gboolean
474 empathy_contact_list_view_get_interactive (EmpathyContactListView  *view)
475 {
476         EmpathyContactListViewPriv *priv = GET_PRIV (view);
477
478         g_return_val_if_fail (EMPATHY_IS_CONTACT_LIST_VIEW (view), FALSE);
479
480         return priv->interactive;
481 }
482
483 EmpathyContact *
484 empathy_contact_list_view_get_selected (EmpathyContactListView *view)
485 {
486         EmpathyContactListViewPriv *priv;
487         GtkTreeSelection          *selection;
488         GtkTreeIter                iter;
489         GtkTreeModel              *model;
490         EmpathyContact             *contact;
491
492         g_return_val_if_fail (EMPATHY_IS_CONTACT_LIST_VIEW (view), NULL);
493
494         priv = GET_PRIV (view);
495
496         selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (view));
497         if (!gtk_tree_selection_get_selected (selection, &model, &iter)) {
498                 return NULL;
499         }
500
501         gtk_tree_model_get (model, &iter,
502                             EMPATHY_CONTACT_LIST_STORE_COL_CONTACT, &contact,
503                             -1);
504
505         return contact;
506 }
507
508 gchar *
509 empathy_contact_list_view_get_selected_group (EmpathyContactListView *view)
510 {
511         EmpathyContactListViewPriv *priv;
512         GtkTreeSelection          *selection;
513         GtkTreeIter                iter;
514         GtkTreeModel              *model;
515         gboolean                   is_group;
516         gchar                     *name;
517
518         g_return_val_if_fail (EMPATHY_IS_CONTACT_LIST_VIEW (view), NULL);
519
520         priv = GET_PRIV (view);
521
522         selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (view));
523         if (!gtk_tree_selection_get_selected (selection, &model, &iter)) {
524                 return NULL;
525         }
526
527         gtk_tree_model_get (model, &iter,
528                             EMPATHY_CONTACT_LIST_STORE_COL_IS_GROUP, &is_group,
529                             EMPATHY_CONTACT_LIST_STORE_COL_NAME, &name,
530                             -1);
531
532         if (!is_group) {
533                 g_free (name);
534                 return NULL;
535         }
536
537         return name;
538 }
539
540 GtkWidget *
541 empathy_contact_list_view_get_group_menu (EmpathyContactListView *view)
542 {
543         EmpathyContactListViewPriv *priv;
544         GtkWidget                 *widget;
545
546         g_return_val_if_fail (EMPATHY_IS_CONTACT_LIST_VIEW (view), NULL);
547
548         priv = GET_PRIV (view);
549
550         widget = gtk_ui_manager_get_widget (priv->ui, "/Group");
551
552         return widget;
553 }
554
555 GtkWidget *
556 empathy_contact_list_view_get_contact_menu (EmpathyContactListView *view,
557                                             EmpathyContact         *contact)
558 {
559         EmpathyLogManager *log_manager;
560         gboolean           can_show_log;
561         gboolean           can_send_file;
562         gboolean           can_voip;
563
564         g_return_val_if_fail (EMPATHY_IS_CONTACT_LIST_VIEW (view), NULL);
565         g_return_val_if_fail (EMPATHY_IS_CONTACT (contact), NULL);
566
567         log_manager = empathy_log_manager_new ();
568         can_show_log = empathy_log_manager_exists (log_manager,
569                                                    empathy_contact_get_account (contact),
570                                                    empathy_contact_get_id (contact),
571                                                    FALSE);
572         g_object_unref (log_manager);
573         can_send_file = FALSE;
574         can_voip = empathy_contact_can_voip (contact);
575
576         return contact_list_view_get_contact_menu (view,
577                                                    can_send_file,
578                                                    can_show_log,
579                                                    can_voip);
580 }
581
582 static void
583 contact_list_view_setup (EmpathyContactListView *view)
584 {
585         EmpathyContactListViewPriv *priv;
586         GtkCellRenderer           *cell;
587         GtkTreeViewColumn         *col;
588         gint                       i;
589
590         priv = GET_PRIV (view);
591
592         gtk_tree_view_set_search_equal_func (GTK_TREE_VIEW (view),
593                                              empathy_contact_list_store_search_equal_func,
594                                              NULL, NULL);
595
596         g_signal_connect (priv->store, "row-has-child-toggled",
597                           G_CALLBACK (contact_list_view_row_has_child_toggled_cb),
598                           view);
599         gtk_tree_view_set_model (GTK_TREE_VIEW (view),
600                                  GTK_TREE_MODEL (priv->store));
601
602         /* Setup view */
603         g_object_set (view,
604                       "headers-visible", FALSE,
605                       "reorderable", TRUE,
606                       "show-expanders", FALSE,
607                       NULL);
608
609         col = gtk_tree_view_column_new ();
610
611         /* State */
612         cell = gtk_cell_renderer_pixbuf_new ();
613         gtk_tree_view_column_pack_start (col, cell, FALSE);
614         gtk_tree_view_column_set_cell_data_func (
615                 col, cell,
616                 (GtkTreeCellDataFunc) contact_list_view_pixbuf_cell_data_func,
617                 view, NULL);
618
619         g_object_set (cell,
620                       "xpad", 5,
621                       "ypad", 1,
622                       "visible", FALSE,
623                       NULL);
624
625         /* Name */
626         cell = empathy_cell_renderer_text_new ();
627         gtk_tree_view_column_pack_start (col, cell, TRUE);
628         gtk_tree_view_column_set_cell_data_func (
629                 col, cell,
630                 (GtkTreeCellDataFunc) contact_list_view_text_cell_data_func,
631                 view, NULL);
632
633         gtk_tree_view_column_add_attribute (col, cell,
634                                             "name", EMPATHY_CONTACT_LIST_STORE_COL_NAME);
635         gtk_tree_view_column_add_attribute (col, cell,
636                                             "status", EMPATHY_CONTACT_LIST_STORE_COL_STATUS);
637         gtk_tree_view_column_add_attribute (col, cell,
638                                             "is_group", EMPATHY_CONTACT_LIST_STORE_COL_IS_GROUP);
639
640 #ifdef HAVE_VOIP
641         /* Voip Capability Icon */
642         cell = empathy_cell_renderer_activatable_new ();
643         gtk_tree_view_column_pack_start (col, cell, FALSE);
644         gtk_tree_view_column_set_cell_data_func (
645                 col, cell,
646                 (GtkTreeCellDataFunc) contact_list_view_voip_cell_data_func,
647                 view, NULL);
648
649         g_object_set (cell,
650                       "visible", FALSE,
651                       NULL);
652
653         g_signal_connect (cell, "path-activated",
654                           G_CALLBACK (contact_list_view_voip_activated_cb),
655                           view);
656 #endif
657
658         /* Avatar */
659         cell = gtk_cell_renderer_pixbuf_new ();
660         gtk_tree_view_column_pack_start (col, cell, FALSE);
661         gtk_tree_view_column_set_cell_data_func (
662                 col, cell,
663                 (GtkTreeCellDataFunc) contact_list_view_avatar_cell_data_func,
664                 view, NULL);
665
666         g_object_set (cell,
667                       "xpad", 0,
668                       "ypad", 0,
669                       "visible", FALSE,
670                       "width", 32,
671                       "height", 32,
672                       NULL);
673
674         /* Expander */
675         cell = empathy_cell_renderer_expander_new ();
676         gtk_tree_view_column_pack_end (col, cell, FALSE);
677         gtk_tree_view_column_set_cell_data_func (
678                 col, cell,
679                 (GtkTreeCellDataFunc) contact_list_view_expander_cell_data_func,
680                 view, NULL);
681
682         /* Actually add the column now we have added all cell renderers */
683         gtk_tree_view_append_column (GTK_TREE_VIEW (view), col);
684
685         /* Drag & Drop. */
686         for (i = 0; i < G_N_ELEMENTS (drag_types_dest); ++i) {
687                 drag_atoms_dest[i] = gdk_atom_intern (drag_types_dest[i].target,
688                                                       FALSE);
689         }
690
691         for (i = 0; i < G_N_ELEMENTS (drag_types_source); ++i) {
692                 drag_atoms_source[i] = gdk_atom_intern (drag_types_source[i].target,
693                                                         FALSE);
694         }
695
696         /* Note: We support the COPY action too, but need to make the
697          * MOVE action the default.
698          */
699         gtk_drag_source_set (GTK_WIDGET (view),
700                              GDK_BUTTON1_MASK,
701                              drag_types_source,
702                              G_N_ELEMENTS (drag_types_source),
703                              GDK_ACTION_MOVE | GDK_ACTION_COPY);
704
705         gtk_drag_dest_set (GTK_WIDGET (view),
706                            GTK_DEST_DEFAULT_ALL,
707                            drag_types_dest,
708                            G_N_ELEMENTS (drag_types_dest),
709                            GDK_ACTION_MOVE | GDK_ACTION_COPY);
710 }
711
712 static void
713 contact_list_view_row_has_child_toggled_cb (GtkTreeModel          *model,
714                                             GtkTreePath           *path,
715                                             GtkTreeIter           *iter,
716                                             EmpathyContactListView *view)
717 {
718         gboolean  is_group = FALSE;
719         gchar    *name = NULL;
720
721         gtk_tree_model_get (model, iter,
722                             EMPATHY_CONTACT_LIST_STORE_COL_IS_GROUP, &is_group,
723                             EMPATHY_CONTACT_LIST_STORE_COL_NAME, &name,
724                             -1);
725
726         if (!is_group || G_STR_EMPTY (name)) {
727                 g_free (name);
728                 return;
729         }
730
731         if (empathy_contact_group_get_expanded (name)) {
732                 g_signal_handlers_block_by_func (view,
733                                                  contact_list_view_row_expand_or_collapse_cb,
734                                                  GINT_TO_POINTER (TRUE));
735                 gtk_tree_view_expand_row (GTK_TREE_VIEW (view), path, TRUE);
736                 g_signal_handlers_unblock_by_func (view,
737                                                    contact_list_view_row_expand_or_collapse_cb,
738                                                    GINT_TO_POINTER (TRUE));
739         } else {
740                 g_signal_handlers_block_by_func (view,
741                                                  contact_list_view_row_expand_or_collapse_cb,
742                                                  GINT_TO_POINTER (FALSE));
743                 gtk_tree_view_collapse_row (GTK_TREE_VIEW (view), path);
744                 g_signal_handlers_unblock_by_func (view,
745                                                    contact_list_view_row_expand_or_collapse_cb,
746                                                    GINT_TO_POINTER (FALSE));
747         }
748
749         g_free (name);
750 }
751
752 static void
753 contact_list_view_drag_data_received (GtkWidget         *widget,
754                                       GdkDragContext    *context,
755                                       gint               x,
756                                       gint               y,
757                                       GtkSelectionData  *selection,
758                                       guint              info,
759                                       guint              time)
760 {
761         EmpathyContactListViewPriv *priv;
762         EmpathyContactList         *list;
763         EmpathyContactFactory      *factory;
764         McAccount                  *account;
765         GtkTreeModel               *model;
766         GtkTreePath                *path;
767         GtkTreeViewDropPosition     position;
768         EmpathyContact             *contact = NULL;
769         const gchar                *id;
770         gchar                     **strv;
771         gchar                      *new_group = NULL;
772         gchar                      *old_group = NULL;
773         gboolean                    is_row;
774
775         priv = GET_PRIV (widget);
776
777         id = (const gchar*) selection->data;
778         empathy_debug (DEBUG_DOMAIN, "Received %s%s drag & drop contact from roster with id:'%s'",
779                       context->action == GDK_ACTION_MOVE ? "move" : "",
780                       context->action == GDK_ACTION_COPY ? "copy" : "",
781                       id);
782
783         strv = g_strsplit (id, "/", 2);
784         factory = empathy_contact_factory_new ();
785         account = mc_account_lookup (strv[0]);
786         if (account) {
787                 contact = empathy_contact_factory_get_from_id (factory,
788                                                                account,
789                                                                strv[1]);
790                 g_object_unref (account);
791         }
792         g_object_unref (factory);
793         g_strfreev (strv);
794
795         if (!contact) {
796                 empathy_debug (DEBUG_DOMAIN, "No contact found associated with drag & drop");
797                 return;
798         }
799
800         model = gtk_tree_view_get_model (GTK_TREE_VIEW (widget));
801
802         /* Get source group information. */
803         if (priv->drag_row) {
804                 path = gtk_tree_row_reference_get_path (priv->drag_row);
805                 if (path) {
806                         old_group = empathy_contact_list_store_get_parent_group (model, path, NULL);
807                         gtk_tree_path_free (path);
808                 }
809         }
810
811         /* Get destination group information. */
812         is_row = gtk_tree_view_get_dest_row_at_pos (GTK_TREE_VIEW (widget),
813                                                     x,
814                                                     y,
815                                                     &path,
816                                                     &position);
817
818         if (is_row) {
819                 new_group = empathy_contact_list_store_get_parent_group (model, path, NULL);
820                 gtk_tree_path_free (path);
821         }
822
823         empathy_debug (DEBUG_DOMAIN,
824                       "contact %s (%d) dragged from '%s' to '%s'",
825                       empathy_contact_get_id (contact),
826                       empathy_contact_get_handle (contact),
827                       old_group, new_group);
828
829         list = empathy_contact_list_store_get_list_iface (priv->store);
830         if (new_group) {
831                 empathy_contact_list_add_to_group (list, contact, new_group);
832         }
833         if (old_group && context->action == GDK_ACTION_MOVE) {  
834                 empathy_contact_list_remove_from_group (list, contact, old_group);
835         }
836
837         g_free (old_group);
838         g_free (new_group);
839
840         gtk_drag_finish (context, TRUE, FALSE, GDK_CURRENT_TIME);
841 }
842
843 static gboolean
844 contact_list_view_drag_motion (GtkWidget      *widget,
845                                GdkDragContext *context,
846                                gint            x,
847                                gint            y,
848                                guint           time)
849 {
850         static DragMotionData *dm = NULL;
851         GtkTreePath           *path;
852         gboolean               is_row;
853         gboolean               is_different = FALSE;
854         gboolean               cleanup = TRUE;
855
856         is_row = gtk_tree_view_get_path_at_pos (GTK_TREE_VIEW (widget),
857                                                 x,
858                                                 y,
859                                                 &path,
860                                                 NULL,
861                                                 NULL,
862                                                 NULL);
863
864         cleanup &= (!dm);
865
866         if (is_row) {
867                 cleanup &= (dm && gtk_tree_path_compare (dm->path, path) != 0);
868                 is_different = (!dm || (dm && gtk_tree_path_compare (dm->path, path) != 0));
869         } else {
870                 cleanup &= FALSE;
871         }
872
873         if (!is_different && !cleanup) {
874                 return TRUE;
875         }
876
877         if (dm) {
878                 gtk_tree_path_free (dm->path);
879                 if (dm->timeout_id) {
880                         g_source_remove (dm->timeout_id);
881                 }
882
883                 g_free (dm);
884
885                 dm = NULL;
886         }
887
888         if (!gtk_tree_view_row_expanded (GTK_TREE_VIEW (widget), path)) {
889                 dm = g_new0 (DragMotionData, 1);
890
891                 dm->view = EMPATHY_CONTACT_LIST_VIEW (widget);
892                 dm->path = gtk_tree_path_copy (path);
893
894                 dm->timeout_id = g_timeout_add_seconds (1,
895                         (GSourceFunc) contact_list_view_drag_motion_cb,
896                         dm);
897         }
898
899         return TRUE;
900 }
901
902 static gboolean
903 contact_list_view_drag_motion_cb (DragMotionData *data)
904 {
905         gtk_tree_view_expand_row (GTK_TREE_VIEW (data->view),
906                                   data->path,
907                                   FALSE);
908
909         data->timeout_id = 0;
910
911         return FALSE;
912 }
913
914 static void
915 contact_list_view_drag_begin (GtkWidget      *widget,
916                               GdkDragContext *context)
917 {
918         EmpathyContactListViewPriv *priv;
919         GtkTreeSelection          *selection;
920         GtkTreeModel              *model;
921         GtkTreePath               *path;
922         GtkTreeIter                iter;
923
924         priv = GET_PRIV (widget);
925
926         GTK_WIDGET_CLASS (empathy_contact_list_view_parent_class)->drag_begin (widget,
927                                                                               context);
928
929         selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (widget));
930         if (!gtk_tree_selection_get_selected (selection, &model, &iter)) {
931                 return;
932         }
933
934         path = gtk_tree_model_get_path (model, &iter);
935         priv->drag_row = gtk_tree_row_reference_new (model, path);
936         gtk_tree_path_free (path);
937 }
938
939 static void
940 contact_list_view_drag_data_get (GtkWidget        *widget,
941                                  GdkDragContext   *context,
942                                  GtkSelectionData *selection,
943                                  guint             info,
944                                  guint             time)
945 {
946         EmpathyContactListViewPriv *priv;
947         GtkTreePath                *src_path;
948         GtkTreeIter                 iter;
949         GtkTreeModel               *model;
950         EmpathyContact             *contact;
951         McAccount                  *account;
952         const gchar                *contact_id;
953         const gchar                *account_id;
954         gchar                      *str;
955         
956
957         priv = GET_PRIV (widget);
958
959         model = gtk_tree_view_get_model (GTK_TREE_VIEW (widget));
960         if (!priv->drag_row) {
961                 return;
962         }
963
964         src_path = gtk_tree_row_reference_get_path (priv->drag_row);
965         if (!src_path) {
966                 return;
967         }
968
969         if (!gtk_tree_model_get_iter (model, &iter, src_path)) {
970                 gtk_tree_path_free (src_path);
971                 return;
972         }
973
974         gtk_tree_path_free (src_path);
975
976         contact = empathy_contact_list_view_get_selected (EMPATHY_CONTACT_LIST_VIEW (widget));
977         if (!contact) {
978                 return;
979         }
980
981         account = empathy_contact_get_account (contact);
982         account_id = mc_account_get_unique_name (account);
983         contact_id = empathy_contact_get_id (contact);
984         g_object_unref (contact);
985         str = g_strconcat (account_id, "/", contact_id, NULL);
986
987         switch (info) {
988         case DND_DRAG_TYPE_CONTACT_ID:
989                 gtk_selection_data_set (selection, drag_atoms_source[info], 8,
990                                         (guchar*)str, strlen (str) + 1);
991                 break;
992         }
993
994         g_free (str);
995 }
996
997 static void
998 contact_list_view_drag_end (GtkWidget      *widget,
999                             GdkDragContext *context)
1000 {
1001         EmpathyContactListViewPriv *priv;
1002
1003         priv = GET_PRIV (widget);
1004
1005         GTK_WIDGET_CLASS (empathy_contact_list_view_parent_class)->drag_end (widget,
1006                                                                             context);
1007
1008         if (priv->drag_row) {
1009                 gtk_tree_row_reference_free (priv->drag_row);
1010                 priv->drag_row = NULL;
1011         }
1012 }
1013
1014 static gboolean
1015 contact_list_view_drag_drop (GtkWidget      *widget,
1016                              GdkDragContext *drag_context,
1017                              gint            x,
1018                              gint            y,
1019                              guint           time)
1020 {
1021         return FALSE;
1022 }
1023
1024 static void
1025 contact_list_view_cell_set_background (EmpathyContactListView *view,
1026                                        GtkCellRenderer       *cell,
1027                                        gboolean               is_group,
1028                                        gboolean               is_active)
1029 {
1030         GdkColor  color;
1031         GtkStyle *style;
1032
1033         style = gtk_widget_get_style (GTK_WIDGET (view));
1034
1035         if (!is_group && is_active) {
1036                 color = style->bg[GTK_STATE_SELECTED];
1037
1038                 /* Here we take the current theme colour and add it to
1039                  * the colour for white and average the two. This
1040                  * gives a colour which is inline with the theme but
1041                  * slightly whiter.
1042                  */
1043                 color.red = (color.red + (style->white).red) / 2;
1044                 color.green = (color.green + (style->white).green) / 2;
1045                 color.blue = (color.blue + (style->white).blue) / 2;
1046
1047                 g_object_set (cell,
1048                               "cell-background-gdk", &color,
1049                               NULL);
1050         } else {
1051                 g_object_set (cell,
1052                               "cell-background-gdk", NULL,
1053                               NULL);
1054         }
1055 }
1056
1057 static void
1058 contact_list_view_pixbuf_cell_data_func (GtkTreeViewColumn     *tree_column,
1059                                          GtkCellRenderer       *cell,
1060                                          GtkTreeModel          *model,
1061                                          GtkTreeIter           *iter,
1062                                          EmpathyContactListView *view)
1063 {
1064         gchar    *icon_name;
1065         gboolean  is_group;
1066         gboolean  is_active;
1067
1068         gtk_tree_model_get (model, iter,
1069                             EMPATHY_CONTACT_LIST_STORE_COL_IS_GROUP, &is_group,
1070                             EMPATHY_CONTACT_LIST_STORE_COL_IS_ACTIVE, &is_active,
1071                             EMPATHY_CONTACT_LIST_STORE_COL_ICON_STATUS, &icon_name,
1072                             -1);
1073
1074         g_object_set (cell,
1075                       "visible", !is_group,
1076                       "icon-name", icon_name,
1077                       NULL);
1078
1079         g_free (icon_name);
1080
1081         contact_list_view_cell_set_background (view, cell, is_group, is_active);
1082 }
1083
1084 #ifdef HAVE_VOIP
1085 static void
1086 contact_list_view_voip_cell_data_func (GtkTreeViewColumn      *tree_column,
1087                                        GtkCellRenderer        *cell,
1088                                        GtkTreeModel           *model,
1089                                        GtkTreeIter            *iter,
1090                                        EmpathyContactListView *view)
1091 {
1092         gboolean is_group;
1093         gboolean is_active;
1094         gboolean can_voip;
1095
1096         gtk_tree_model_get (model, iter,
1097                             EMPATHY_CONTACT_LIST_STORE_COL_IS_GROUP, &is_group,
1098                             EMPATHY_CONTACT_LIST_STORE_COL_IS_ACTIVE, &is_active,
1099                             EMPATHY_CONTACT_LIST_STORE_COL_CAN_VOIP, &can_voip,
1100                             -1);
1101
1102         g_object_set (cell,
1103                       "visible", !is_group && can_voip,
1104                       "icon-name", EMPATHY_IMAGE_VOIP,
1105                       NULL);
1106
1107         contact_list_view_cell_set_background (view, cell, is_group, is_active);
1108 }
1109 #endif
1110
1111 static void
1112 contact_list_view_avatar_cell_data_func (GtkTreeViewColumn     *tree_column,
1113                                          GtkCellRenderer       *cell,
1114                                          GtkTreeModel          *model,
1115                                          GtkTreeIter           *iter,
1116                                          EmpathyContactListView *view)
1117 {
1118         GdkPixbuf *pixbuf;
1119         gboolean   show_avatar;
1120         gboolean   is_group;
1121         gboolean   is_active;
1122
1123         gtk_tree_model_get (model, iter,
1124                             EMPATHY_CONTACT_LIST_STORE_COL_PIXBUF_AVATAR, &pixbuf,
1125                             EMPATHY_CONTACT_LIST_STORE_COL_PIXBUF_AVATAR_VISIBLE, &show_avatar,
1126                             EMPATHY_CONTACT_LIST_STORE_COL_IS_GROUP, &is_group,
1127                             EMPATHY_CONTACT_LIST_STORE_COL_IS_ACTIVE, &is_active,
1128                             -1);
1129
1130         g_object_set (cell,
1131                       "visible", !is_group && show_avatar,
1132                       "pixbuf", pixbuf,
1133                       NULL);
1134
1135         if (pixbuf) {
1136                 g_object_unref (pixbuf);
1137         }
1138
1139         contact_list_view_cell_set_background (view, cell, is_group, is_active);
1140 }
1141
1142 static void
1143 contact_list_view_text_cell_data_func (GtkTreeViewColumn     *tree_column,
1144                                        GtkCellRenderer       *cell,
1145                                        GtkTreeModel          *model,
1146                                        GtkTreeIter           *iter,
1147                                        EmpathyContactListView *view)
1148 {
1149         gboolean is_group;
1150         gboolean is_active;
1151         gboolean show_status;
1152
1153         gtk_tree_model_get (model, iter,
1154                             EMPATHY_CONTACT_LIST_STORE_COL_IS_GROUP, &is_group,
1155                             EMPATHY_CONTACT_LIST_STORE_COL_IS_ACTIVE, &is_active,
1156                             EMPATHY_CONTACT_LIST_STORE_COL_STATUS_VISIBLE, &show_status,
1157                             -1);
1158
1159         g_object_set (cell,
1160                       "show-status", show_status,
1161                       NULL);
1162
1163         contact_list_view_cell_set_background (view, cell, is_group, is_active);
1164 }
1165
1166 static void
1167 contact_list_view_expander_cell_data_func (GtkTreeViewColumn     *column,
1168                                            GtkCellRenderer       *cell,
1169                                            GtkTreeModel          *model,
1170                                            GtkTreeIter           *iter,
1171                                            EmpathyContactListView *view)
1172 {
1173         gboolean is_group;
1174         gboolean is_active;
1175
1176         gtk_tree_model_get (model, iter,
1177                             EMPATHY_CONTACT_LIST_STORE_COL_IS_GROUP, &is_group,
1178                             EMPATHY_CONTACT_LIST_STORE_COL_IS_ACTIVE, &is_active,
1179                             -1);
1180
1181         if (gtk_tree_model_iter_has_child (model, iter)) {
1182                 GtkTreePath *path;
1183                 gboolean     row_expanded;
1184
1185                 path = gtk_tree_model_get_path (model, iter);
1186                 row_expanded = gtk_tree_view_row_expanded (GTK_TREE_VIEW (column->tree_view), path);
1187                 gtk_tree_path_free (path);
1188
1189                 g_object_set (cell,
1190                               "visible", TRUE,
1191                               "expander-style", row_expanded ? GTK_EXPANDER_EXPANDED : GTK_EXPANDER_COLLAPSED,
1192                               NULL);
1193         } else {
1194                 g_object_set (cell, "visible", FALSE, NULL);
1195         }
1196
1197         contact_list_view_cell_set_background (view, cell, is_group, is_active);
1198 }
1199
1200 static GtkWidget *
1201 contact_list_view_get_contact_menu (EmpathyContactListView *view,
1202                                     gboolean               can_send_file,
1203                                     gboolean               can_show_log,
1204                                     gboolean               can_voip)
1205 {
1206         EmpathyContactListViewPriv *priv;
1207         GtkAction                 *action;
1208         GtkWidget                 *widget;
1209
1210         priv = GET_PRIV (view);
1211
1212         /* Sort out sensitive items */
1213         action = gtk_ui_manager_get_action (priv->ui, "/Contact/Log");
1214         gtk_action_set_sensitive (action, can_show_log);
1215
1216 #ifdef HAVE_VOIP
1217         action = gtk_ui_manager_get_action (priv->ui, "/Contact/Call");
1218         gtk_action_set_sensitive (action, can_voip);
1219 #endif
1220
1221         action = gtk_ui_manager_get_action (priv->ui, "/Contact/SendFile");
1222         gtk_action_set_visible (action, can_send_file);
1223
1224         widget = gtk_ui_manager_get_widget (priv->ui, "/Contact");
1225
1226         return widget;
1227 }
1228
1229 static gboolean
1230 contact_list_view_button_press_event_cb (EmpathyContactListView *view,
1231                                          GdkEventButton        *event,
1232                                          gpointer               user_data)
1233 {
1234         EmpathyContactListViewPriv *priv;
1235         EmpathyContact             *contact;
1236         GtkTreePath               *path;
1237         GtkTreeSelection          *selection;
1238         GtkTreeModel              *model;
1239         GtkTreeIter                iter;
1240         gboolean                   row_exists;
1241         GtkWidget                 *menu;
1242
1243         priv = GET_PRIV (view);
1244
1245         if (!priv->interactive || event->button != 3) {
1246                 return FALSE;
1247         }
1248
1249         selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (view));
1250         model = gtk_tree_view_get_model (GTK_TREE_VIEW (view));
1251
1252         gtk_widget_grab_focus (GTK_WIDGET (view));
1253
1254         row_exists = gtk_tree_view_get_path_at_pos (GTK_TREE_VIEW (view),
1255                                                     event->x, event->y,
1256                                                     &path,
1257                                                     NULL, NULL, NULL);
1258         if (!row_exists) {
1259                 return FALSE;
1260         }
1261
1262         gtk_tree_selection_unselect_all (selection);
1263         gtk_tree_selection_select_path (selection, path);
1264
1265         gtk_tree_model_get_iter (model, &iter, path);
1266         gtk_tree_path_free (path);
1267
1268         gtk_tree_model_get (model, &iter,
1269                             EMPATHY_CONTACT_LIST_STORE_COL_CONTACT, &contact,
1270                             -1);
1271
1272         if (contact) {
1273                 menu = empathy_contact_list_view_get_contact_menu (view, contact);
1274                 g_object_unref (contact);
1275         } else {
1276                 menu = empathy_contact_list_view_get_group_menu (view);
1277         }
1278
1279         if (!menu) {
1280                 return FALSE;
1281         }
1282
1283         gtk_widget_show (menu);
1284
1285         gtk_menu_popup (GTK_MENU (menu),
1286                         NULL, NULL, NULL, NULL,
1287                         event->button, event->time);
1288
1289         return TRUE;
1290 }
1291
1292 static void
1293 contact_list_view_row_activated_cb (EmpathyContactListView *view,
1294                                     GtkTreePath            *path,
1295                                     GtkTreeViewColumn      *col,
1296                                     gpointer                user_data)
1297 {
1298         EmpathyContactListViewPriv *priv = GET_PRIV (view);
1299         EmpathyContact             *contact;
1300         GtkTreeModel               *model;
1301         GtkTreeIter                 iter;
1302
1303         if (!priv->interactive) {
1304                 return;
1305         }
1306
1307         model = gtk_tree_view_get_model (GTK_TREE_VIEW (view));
1308
1309         gtk_tree_model_get_iter (model, &iter, path);
1310         gtk_tree_model_get (model, &iter,
1311                             EMPATHY_CONTACT_LIST_STORE_COL_CONTACT, &contact,
1312                             -1);
1313
1314         if (contact) {
1315                 empathy_chat_with_contact (contact);
1316                 g_object_unref (contact);
1317         }
1318 }
1319
1320 #ifdef HAVE_VOIP
1321 static void
1322 contact_list_view_voip_activated_cb (EmpathyCellRendererActivatable *cell,
1323                                      const gchar                    *path_string,
1324                                      EmpathyContactListView         *view)
1325 {
1326         EmpathyContactListViewPriv *priv = GET_PRIV (view);
1327         GtkTreeModel               *model;
1328         GtkTreeIter                 iter;
1329         EmpathyContact             *contact;
1330
1331         if (!priv->interactive) {
1332                 return;
1333         }
1334
1335         model = gtk_tree_view_get_model (GTK_TREE_VIEW (view));
1336         if (!gtk_tree_model_get_iter_from_string (model, &iter, path_string)) {
1337                 return;
1338         }
1339
1340         gtk_tree_model_get (model, &iter,
1341                             EMPATHY_CONTACT_LIST_STORE_COL_CONTACT, &contact,
1342                             -1);
1343
1344         if (contact) {
1345                 contact_list_view_voip_activated (view, contact);
1346                 g_object_unref (contact);
1347         }
1348 }
1349 #endif
1350
1351
1352 static void
1353 contact_list_view_row_expand_or_collapse_cb (EmpathyContactListView *view,
1354                                              GtkTreeIter           *iter,
1355                                              GtkTreePath           *path,
1356                                              gpointer               user_data)
1357 {
1358         GtkTreeModel *model;
1359         gchar        *name;
1360         gboolean      expanded;
1361
1362         model = gtk_tree_view_get_model (GTK_TREE_VIEW (view));
1363
1364         gtk_tree_model_get (model, iter,
1365                             EMPATHY_CONTACT_LIST_STORE_COL_NAME, &name,
1366                             -1);
1367
1368         expanded = GPOINTER_TO_INT (user_data);
1369         empathy_contact_group_set_expanded (name, expanded);
1370
1371         g_free (name);
1372 }
1373
1374 static void
1375 contact_list_view_action_cb (GtkAction             *action,
1376                              EmpathyContactListView *view)
1377 {
1378         EmpathyContactListViewPriv *priv;
1379         EmpathyContact             *contact;
1380         const gchar               *name;
1381         gchar                     *group;
1382         GtkWindow                 *parent;
1383
1384         priv = GET_PRIV (view);
1385
1386         name = gtk_action_get_name (action);
1387         if (!name) {
1388                 return;
1389         }
1390
1391         empathy_debug (DEBUG_DOMAIN, "Action:'%s' activated", name);
1392
1393         contact = empathy_contact_list_view_get_selected (view);
1394         group = empathy_contact_list_view_get_selected_group (view);
1395         parent = empathy_get_toplevel_window (GTK_WIDGET (view));
1396
1397         if (contact && strcmp (name, "Chat") == 0) {
1398                 empathy_chat_with_contact (contact);
1399         }
1400         else if (contact && strcmp (name, "Call") == 0) {
1401                 contact_list_view_voip_activated (view, contact);
1402         }
1403         else if (contact && strcmp (name, "Information") == 0) {
1404                 empathy_contact_information_dialog_show (contact, parent, FALSE, FALSE);
1405         }
1406         else if (contact && strcmp (name, "Edit") == 0) {
1407                 empathy_contact_information_dialog_show (contact, parent, TRUE, FALSE);
1408         }
1409         else if (contact && strcmp (name, "Remove") == 0) {
1410                 /* FIXME: Ask for confirmation */
1411                 EmpathyContactList *list;
1412
1413                 list = empathy_contact_list_store_get_list_iface (priv->store);
1414                 empathy_contact_list_remove (list, contact,
1415                                              _("Sorry, I don't want you in my contact list anymore."));
1416         }
1417         else if (contact && strcmp (name, "Invite") == 0) {
1418         }
1419         else if (contact && strcmp (name, "SendFile") == 0) {
1420         }
1421         else if (contact && strcmp (name, "Log") == 0) {
1422                 empathy_log_window_show (empathy_contact_get_account (contact),
1423                                         empathy_contact_get_id (contact),
1424                                         FALSE,
1425                                         parent);
1426         }
1427         else if (group && strcmp (name, "Rename") == 0) {
1428         }
1429
1430         g_free (group);
1431         if (contact) {
1432                 g_object_unref (contact);
1433         }
1434 }
1435
1436 static void
1437 contact_list_view_voip_activated (EmpathyContactListView *view,
1438                                   EmpathyContact         *contact)
1439 {
1440         empathy_call_contact (contact);
1441 }
1442