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