X-Git-Url: https://git.0d.be/?p=empathy.git;a=blobdiff_plain;f=libempathy-gtk%2Fempathy-contact-list-view.c;h=dd3dc54a6d5d5d682189711a42c6cd85e490c2fe;hp=2a5cf3406c107d24edea38045ccbda31e2094cef;hb=f014e7c05ae05ec40926e8fdc4e7cd69bcf3359a;hpb=58505161bcc63ba91190f6b38a3c52c0c564ca32 diff --git a/libempathy-gtk/empathy-contact-list-view.c b/libempathy-gtk/empathy-contact-list-view.c index 2a5cf340..dd3dc54a 100644 --- a/libempathy-gtk/empathy-contact-list-view.c +++ b/libempathy-gtk/empathy-contact-list-view.c @@ -1,7 +1,7 @@ /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ /* * Copyright (C) 2005-2007 Imendio AB - * Copyright (C) 2007 Collabora Ltd. + * Copyright (C) 2007-2008 Collabora Ltd. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as @@ -28,52 +28,43 @@ #include #include +#include #include #include #include -#include -#include +#include #include -#include -#include +#include +#include #include -#include #include "empathy-contact-list-view.h" #include "empathy-contact-list-store.h" #include "empathy-images.h" -#include "empathy-contact-groups.h" #include "empathy-cell-renderer-expander.h" #include "empathy-cell-renderer-text.h" +#include "empathy-cell-renderer-activatable.h" #include "empathy-ui-utils.h" -#include "empathy-contact-dialogs.h" -//#include "empathy-chat-invite.h" -//#include "empathy-ft-window.h" -#include "empathy-log-window.h" - -#define DEBUG_DOMAIN "ContactListView" +#include "empathy-gtk-enum-types.h" +#include "empathy-gtk-marshal.h" -/* Flashing delay for icons (milliseconds). */ -#define FLASH_TIMEOUT 500 +#define DEBUG_FLAG EMPATHY_DEBUG_CONTACT +#include /* Active users are those which have recently changed state * (e.g. online, offline or from normal to a busy state). */ -#define GET_PRIV(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), EMPATHY_TYPE_CONTACT_LIST_VIEW, EmpathyContactListViewPriv)) - -struct _EmpathyContactListViewPriv { - EmpathyContactListStore *store; - GtkUIManager *ui; - GtkTreeRowReference *drag_row; - GtkTreeModel *filter; - gchar *filter_text; - - EmpathyContactListViewDragReceivedFunc drag_received; - gpointer drag_received_data; -}; +#define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyContactListView) +typedef struct { + EmpathyContactListStore *store; + GtkTreeRowReference *drag_row; + EmpathyContactListFeatureFlags list_features; + EmpathyContactFeatureFlags contact_features; + GtkWidget *tooltip_widget; +} EmpathyContactListViewPriv; typedef struct { EmpathyContactListView *view; @@ -87,174 +78,13 @@ typedef struct { gboolean remove; } ShowActiveData; -static void empathy_contact_list_view_class_init (EmpathyContactListViewClass *klass); -static void empathy_contact_list_view_init (EmpathyContactListView *list); -static void contact_list_view_finalize (GObject *object); -static void contact_list_view_get_property (GObject *object, - guint param_id, - GValue *value, - GParamSpec *pspec); -static void contact_list_view_set_property (GObject *object, - guint param_id, - const GValue *value, - GParamSpec *pspec); -static void contact_list_view_setup (EmpathyContactListView *view); -static void contact_list_view_row_has_child_toggled_cb (GtkTreeModel *model, - GtkTreePath *path, - GtkTreeIter *iter, - EmpathyContactListView *view); -static void contact_list_view_contact_received (EmpathyContactListView *view, - EmpathyContact *contact, - GdkDragAction action, - const gchar *old_group, - const gchar *new_group); -static void contact_list_view_drag_data_received (GtkWidget *widget, - GdkDragContext *context, - gint x, - gint y, - GtkSelectionData *selection, - guint info, - guint time); -static gboolean contact_list_view_drag_motion (GtkWidget *widget, - GdkDragContext *context, - gint x, - gint y, - guint time); -static gboolean contact_list_view_drag_motion_cb (DragMotionData *data); -static void contact_list_view_drag_begin (GtkWidget *widget, - GdkDragContext *context); -static void contact_list_view_drag_data_get (GtkWidget *widget, - GdkDragContext *context, - GtkSelectionData *selection, - guint info, - guint time); -static void contact_list_view_drag_end (GtkWidget *widget, - GdkDragContext *context); -static gboolean contact_list_view_drag_drop (GtkWidget *widget, - GdkDragContext *drag_context, - gint x, - gint y, - guint time); -static void contact_list_view_cell_set_background (EmpathyContactListView *view, - GtkCellRenderer *cell, - gboolean is_group, - gboolean is_active); -static void contact_list_view_pixbuf_cell_data_func (GtkTreeViewColumn *tree_column, - GtkCellRenderer *cell, - GtkTreeModel *model, - GtkTreeIter *iter, - EmpathyContactListView *view); -static void contact_list_view_avatar_cell_data_func (GtkTreeViewColumn *tree_column, - GtkCellRenderer *cell, - GtkTreeModel *model, - GtkTreeIter *iter, - EmpathyContactListView *view); -static void contact_list_view_text_cell_data_func (GtkTreeViewColumn *tree_column, - GtkCellRenderer *cell, - GtkTreeModel *model, - GtkTreeIter *iter, - EmpathyContactListView *view); -static void contact_list_view_expander_cell_data_func (GtkTreeViewColumn *column, - GtkCellRenderer *cell, - GtkTreeModel *model, - GtkTreeIter *iter, - EmpathyContactListView *view); -static GtkWidget * contact_list_view_get_contact_menu (EmpathyContactListView *view, - gboolean can_send_file, - gboolean can_show_log); -static gboolean contact_list_view_button_press_event_cb (EmpathyContactListView *view, - GdkEventButton *event, - gpointer user_data); -static void contact_list_view_row_activated_cb (EmpathyContactListView *view, - GtkTreePath *path, - GtkTreeViewColumn *col, - gpointer user_data); -static void contact_list_view_row_expand_or_collapse_cb (EmpathyContactListView *view, - GtkTreeIter *iter, - GtkTreePath *path, - gpointer user_data); -static gboolean contact_list_view_filter_show_contact (EmpathyContact *contact, - const gchar *filter); -static gboolean contact_list_view_filter_show_group (EmpathyContactListView *view, - const gchar *group, - const gchar *filter); -static gboolean contact_list_view_filter_func (GtkTreeModel *model, - GtkTreeIter *iter, - EmpathyContactListView *view); -static void contact_list_view_action_cb (GtkAction *action, - EmpathyContactListView *view); -static void contact_list_view_action_activated (EmpathyContactListView *view, - EmpathyContact *contact); - enum { PROP_0, - PROP_FILTER, + PROP_STORE, + PROP_LIST_FEATURES, + PROP_CONTACT_FEATURES, }; -static const GtkActionEntry entries[] = { - { "ContactMenu", NULL, - N_("_Contact"), NULL, NULL, - NULL - }, - { "GroupMenu", NULL, - N_("_Group"),NULL, NULL, - NULL - }, - { "Chat", EMPATHY_IMAGE_MESSAGE, - N_("_Chat"), NULL, N_("Chat with contact"), - G_CALLBACK (contact_list_view_action_cb) - }, - { "Information", EMPATHY_IMAGE_CONTACT_INFORMATION, - N_("Infor_mation"), "I", N_("View contact information"), - G_CALLBACK (contact_list_view_action_cb) - }, - { "Rename", NULL, - N_("Re_name"), NULL, N_("Rename"), - G_CALLBACK (contact_list_view_action_cb) - }, - { "Edit", GTK_STOCK_EDIT, - N_("_Edit"), NULL, N_("Edit the groups and name for this contact"), - G_CALLBACK (contact_list_view_action_cb) - }, - { "Remove", GTK_STOCK_REMOVE, - N_("_Remove"), NULL, N_("Remove contact"), - G_CALLBACK (contact_list_view_action_cb) - }, - { "Invite", EMPATHY_IMAGE_GROUP_MESSAGE, - N_("_Invite to Chat Room"), NULL, N_("Invite to a currently open chat room"), - G_CALLBACK (contact_list_view_action_cb) - }, - { "SendFile", NULL, - N_("_Send File..."), NULL, N_("Send a file"), - G_CALLBACK (contact_list_view_action_cb) - }, - { "Log", GTK_STOCK_JUSTIFY_LEFT, - N_("_View Previous Conversations"), NULL, N_("View previous conversations with this contact"), - G_CALLBACK (contact_list_view_action_cb) - }, -}; - -static guint n_entries = G_N_ELEMENTS (entries); - -static const gchar *ui_info = - "" - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - ""; - enum DndDragType { DND_DRAG_TYPE_CONTACT_ID, DND_DRAG_TYPE_URL, @@ -284,1241 +114,1268 @@ static guint signals[LAST_SIGNAL]; G_DEFINE_TYPE (EmpathyContactListView, empathy_contact_list_view, GTK_TYPE_TREE_VIEW); -static void -empathy_contact_list_view_class_init (EmpathyContactListViewClass *klass) +static gboolean +contact_list_view_query_tooltip_cb (EmpathyContactListView *view, + gint x, + gint y, + gboolean keyboard_mode, + GtkTooltip *tooltip, + gpointer user_data) { - GObjectClass *object_class = G_OBJECT_CLASS (klass); - GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); + EmpathyContactListViewPriv *priv = GET_PRIV (view); + EmpathyContact *contact; + GtkTreeModel *model; + GtkTreeIter iter; + GtkTreePath *path; - object_class->finalize = contact_list_view_finalize; - object_class->get_property = contact_list_view_get_property; - object_class->set_property = contact_list_view_set_property; + /* FIXME: We need GTK version >= 2.12.10. See GNOME bug #504087 */ + if (gtk_check_version (2, 12, 10)) { + return FALSE; + } - widget_class->drag_data_received = contact_list_view_drag_data_received; - widget_class->drag_drop = contact_list_view_drag_drop; - widget_class->drag_begin = contact_list_view_drag_begin; - widget_class->drag_data_get = contact_list_view_drag_data_get; - widget_class->drag_end = contact_list_view_drag_end; - /* FIXME: noticed but when you drag the row over the treeview - * fast, it seems to stop redrawing itself, if we don't - * connect this signal, all is fine. - */ - widget_class->drag_motion = contact_list_view_drag_motion; + if (!gtk_tree_view_get_tooltip_context (GTK_TREE_VIEW (view), &x, &y, + keyboard_mode, + &model, &path, &iter)) { + return FALSE; + } - signals[DRAG_CONTACT_RECEIVED] = - g_signal_new ("drag-contact-received", - G_OBJECT_CLASS_TYPE (klass), - G_SIGNAL_RUN_LAST, - 0, - NULL, NULL, - empathy_marshal_VOID__OBJECT_STRING_STRING, - G_TYPE_NONE, - 3, EMPATHY_TYPE_CONTACT, G_TYPE_STRING, G_TYPE_STRING); + gtk_tree_view_set_tooltip_row (GTK_TREE_VIEW (view), tooltip, path); + gtk_tree_path_free (path); - g_object_class_install_property (object_class, - PROP_FILTER, - g_param_spec_string ("filter", - "Filter", - "The text to use to filter the contact list", - NULL, - G_PARAM_READWRITE)); + gtk_tree_model_get (model, &iter, + EMPATHY_CONTACT_LIST_STORE_COL_CONTACT, &contact, + -1); + if (!contact) { + return FALSE; + } - g_type_class_add_private (object_class, sizeof (EmpathyContactListViewPriv)); + if (!priv->tooltip_widget) { + priv->tooltip_widget = empathy_contact_widget_new (contact, + EMPATHY_CONTACT_WIDGET_EDIT_NONE); + g_object_add_weak_pointer (G_OBJECT (priv->tooltip_widget), + (gpointer) &priv->tooltip_widget); + } else { + empathy_contact_widget_set_contact (priv->tooltip_widget, + contact); + } + + gtk_tooltip_set_custom (tooltip, priv->tooltip_widget); + + g_object_unref (contact); + + return TRUE; } static void -empathy_contact_list_view_init (EmpathyContactListView *view) +contact_list_view_drag_data_received (GtkWidget *widget, + GdkDragContext *context, + gint x, + gint y, + GtkSelectionData *selection, + guint info, + guint time) { EmpathyContactListViewPriv *priv; - GtkActionGroup *action_group; - GError *error = NULL; - - priv = GET_PRIV (view); - - /* Get saved group states. */ - empathy_contact_groups_get_all (); - - /* Set up UI Manager */ - priv->ui = gtk_ui_manager_new (); + EmpathyContactList *list; + EmpathyContactFactory *factory; + McAccount *account; + GtkTreeModel *model; + GtkTreePath *path; + GtkTreeViewDropPosition position; + EmpathyContact *contact = NULL; + const gchar *id; + gchar **strv; + gchar *new_group = NULL; + gchar *old_group = NULL; + gboolean is_row; - action_group = gtk_action_group_new ("Actions"); - gtk_action_group_set_translation_domain (action_group, GETTEXT_PACKAGE); - gtk_action_group_add_actions (action_group, entries, n_entries, view); - gtk_ui_manager_insert_action_group (priv->ui, action_group, 0); + priv = GET_PRIV (widget); - if (!gtk_ui_manager_add_ui_from_string (priv->ui, ui_info, -1, &error)) { - g_warning ("Could not build contact menus from string:'%s'", error->message); - g_error_free (error); + id = (const gchar*) selection->data; + DEBUG ("Received %s%s drag & drop contact from roster with id:'%s'", + context->action == GDK_ACTION_MOVE ? "move" : "", + context->action == GDK_ACTION_COPY ? "copy" : "", + id); + + strv = g_strsplit (id, "/", 2); + factory = empathy_contact_factory_new (); + account = mc_account_lookup (strv[0]); + if (account) { + contact = empathy_contact_factory_get_from_id (factory, + account, + strv[1]); + g_object_unref (account); } + g_object_unref (factory); + g_strfreev (strv); - g_object_unref (action_group); + if (!contact) { + DEBUG ("No contact found associated with drag & drop"); + return; + } - gtk_tree_view_set_row_separator_func (GTK_TREE_VIEW (view), - empathy_contact_list_store_row_separator_func, - NULL, NULL); + empathy_contact_run_until_ready (contact, + EMPATHY_CONTACT_READY_HANDLE, + NULL); - /* Connect to tree view signals rather than override. */ - g_signal_connect (view, - "button-press-event", - G_CALLBACK (contact_list_view_button_press_event_cb), - NULL); - g_signal_connect (view, - "row-activated", - G_CALLBACK (contact_list_view_row_activated_cb), - NULL); - g_signal_connect (view, - "row-expanded", - G_CALLBACK (contact_list_view_row_expand_or_collapse_cb), - GINT_TO_POINTER (TRUE)); - g_signal_connect (view, - "row-collapsed", - G_CALLBACK (contact_list_view_row_expand_or_collapse_cb), - GINT_TO_POINTER (FALSE)); -} + model = gtk_tree_view_get_model (GTK_TREE_VIEW (widget)); -static void -contact_list_view_finalize (GObject *object) -{ - EmpathyContactListViewPriv *priv; + /* Get source group information. */ + if (priv->drag_row) { + path = gtk_tree_row_reference_get_path (priv->drag_row); + if (path) { + old_group = empathy_contact_list_store_get_parent_group (model, path, NULL); + gtk_tree_path_free (path); + } + } - priv = GET_PRIV (object); + /* Get destination group information. */ + is_row = gtk_tree_view_get_dest_row_at_pos (GTK_TREE_VIEW (widget), + x, + y, + &path, + &position); - if (priv->ui) { - g_object_unref (priv->ui); + if (is_row) { + new_group = empathy_contact_list_store_get_parent_group (model, path, NULL); + gtk_tree_path_free (path); } - if (priv->store) { - g_object_unref (priv->store); + + DEBUG ("contact %s (%d) dragged from '%s' to '%s'", + empathy_contact_get_id (contact), + empathy_contact_get_handle (contact), + old_group, new_group); + + list = empathy_contact_list_store_get_list_iface (priv->store); + if (new_group) { + empathy_contact_list_add_to_group (list, contact, new_group); } - if (priv->filter) { - g_object_unref (priv->filter); + if (old_group && context->action == GDK_ACTION_MOVE) { + empathy_contact_list_remove_from_group (list, contact, old_group); } - g_free (priv->filter_text); - G_OBJECT_CLASS (empathy_contact_list_view_parent_class)->finalize (object); + g_free (old_group); + g_free (new_group); + + gtk_drag_finish (context, TRUE, FALSE, GDK_CURRENT_TIME); } -static void -contact_list_view_get_property (GObject *object, - guint param_id, - GValue *value, - GParamSpec *pspec) +static gboolean +contact_list_view_drag_motion_cb (DragMotionData *data) { - EmpathyContactListViewPriv *priv; + gtk_tree_view_expand_row (GTK_TREE_VIEW (data->view), + data->path, + FALSE); - priv = GET_PRIV (object); + data->timeout_id = 0; - switch (param_id) { - case PROP_FILTER: - g_value_set_string (value, priv->filter_text); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec); - break; - }; + return FALSE; } -static void -contact_list_view_set_property (GObject *object, - guint param_id, - const GValue *value, - GParamSpec *pspec) +static gboolean +contact_list_view_drag_motion (GtkWidget *widget, + GdkDragContext *context, + gint x, + gint y, + guint time) { - EmpathyContactListViewPriv *priv; + static DragMotionData *dm = NULL; + GtkTreePath *path; + gboolean is_row; + gboolean is_different = FALSE; + gboolean cleanup = TRUE; - priv = GET_PRIV (object); + is_row = gtk_tree_view_get_path_at_pos (GTK_TREE_VIEW (widget), + x, + y, + &path, + NULL, + NULL, + NULL); - switch (param_id) { - case PROP_FILTER: - empathy_contact_list_view_set_filter (EMPATHY_CONTACT_LIST_VIEW (object), - g_value_get_string (value)); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec); - break; - }; -} + cleanup &= (!dm); -EmpathyContactListView * -empathy_contact_list_view_new (EmpathyContactListStore *store) -{ - EmpathyContactListViewPriv *priv; - EmpathyContactListView *view; - - view = g_object_new (EMPATHY_TYPE_CONTACT_LIST_VIEW, NULL); - priv = GET_PRIV (view); + if (is_row) { + cleanup &= (dm && gtk_tree_path_compare (dm->path, path) != 0); + is_different = (!dm || (dm && gtk_tree_path_compare (dm->path, path) != 0)); + } else { + cleanup &= FALSE; + } - priv->store = g_object_ref (store); - contact_list_view_setup (view); + if (!is_different && !cleanup) { + return TRUE; + } - return view; -} + if (dm) { + gtk_tree_path_free (dm->path); + if (dm->timeout_id) { + g_source_remove (dm->timeout_id); + } -EmpathyContact * -empathy_contact_list_view_get_selected (EmpathyContactListView *view) -{ - EmpathyContactListViewPriv *priv; - GtkTreeSelection *selection; - GtkTreeIter iter; - GtkTreeModel *model; - EmpathyContact *contact; + g_free (dm); - g_return_val_if_fail (EMPATHY_IS_CONTACT_LIST_VIEW (view), NULL); + dm = NULL; + } - priv = GET_PRIV (view); + if (!gtk_tree_view_row_expanded (GTK_TREE_VIEW (widget), path)) { + dm = g_new0 (DragMotionData, 1); - selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (view)); - if (!gtk_tree_selection_get_selected (selection, &model, &iter)) { - return NULL; - } + dm->view = EMPATHY_CONTACT_LIST_VIEW (widget); + dm->path = gtk_tree_path_copy (path); - gtk_tree_model_get (model, &iter, COL_CONTACT, &contact, -1); + dm->timeout_id = g_timeout_add_seconds (1, + (GSourceFunc) contact_list_view_drag_motion_cb, + dm); + } - return contact; + return TRUE; } -gchar * -empathy_contact_list_view_get_selected_group (EmpathyContactListView *view) +static void +contact_list_view_drag_begin (GtkWidget *widget, + GdkDragContext *context) { EmpathyContactListViewPriv *priv; GtkTreeSelection *selection; - GtkTreeIter iter; GtkTreeModel *model; - gboolean is_group; - gchar *name; + GtkTreePath *path; + GtkTreeIter iter; - g_return_val_if_fail (EMPATHY_IS_CONTACT_LIST_VIEW (view), NULL); + priv = GET_PRIV (widget); - priv = GET_PRIV (view); + GTK_WIDGET_CLASS (empathy_contact_list_view_parent_class)->drag_begin (widget, + context); - selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (view)); + selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (widget)); if (!gtk_tree_selection_get_selected (selection, &model, &iter)) { - return NULL; - } - - gtk_tree_model_get (model, &iter, - COL_IS_GROUP, &is_group, - COL_NAME, &name, - -1); - - if (!is_group) { - g_free (name); - return NULL; + return; } - return name; + path = gtk_tree_model_get_path (model, &iter); + priv->drag_row = gtk_tree_row_reference_new (model, path); + gtk_tree_path_free (path); } -GtkWidget * -empathy_contact_list_view_get_group_menu (EmpathyContactListView *view) +static void +contact_list_view_drag_data_get (GtkWidget *widget, + GdkDragContext *context, + GtkSelectionData *selection, + guint info, + guint time) { EmpathyContactListViewPriv *priv; - GtkWidget *widget; - - g_return_val_if_fail (EMPATHY_IS_CONTACT_LIST_VIEW (view), NULL); - - priv = GET_PRIV (view); + GtkTreePath *src_path; + GtkTreeIter iter; + GtkTreeModel *model; + EmpathyContact *contact; + McAccount *account; + const gchar *contact_id; + const gchar *account_id; + gchar *str; - widget = gtk_ui_manager_get_widget (priv->ui, "/Group"); + priv = GET_PRIV (widget); - return widget; -} + model = gtk_tree_view_get_model (GTK_TREE_VIEW (widget)); + if (!priv->drag_row) { + return; + } -GtkWidget * -empathy_contact_list_view_get_contact_menu (EmpathyContactListView *view, - EmpathyContact *contact) -{ - EmpathyLogManager *log_manager; - gboolean can_show_log; - gboolean can_send_file; + src_path = gtk_tree_row_reference_get_path (priv->drag_row); + if (!src_path) { + return; + } - g_return_val_if_fail (EMPATHY_IS_CONTACT_LIST_VIEW (view), NULL); - g_return_val_if_fail (EMPATHY_IS_CONTACT (contact), NULL); - - log_manager = empathy_log_manager_new (); - can_show_log = empathy_log_manager_exists (log_manager, - empathy_contact_get_account (contact), - empathy_contact_get_id (contact), - FALSE); - can_send_file = FALSE; - g_object_unref (log_manager); - - return contact_list_view_get_contact_menu (view, - can_send_file, - can_show_log); -} + if (!gtk_tree_model_get_iter (model, &iter, src_path)) { + gtk_tree_path_free (src_path); + return; + } -void -empathy_contact_list_view_set_filter (EmpathyContactListView *view, - const gchar *filter) -{ - EmpathyContactListViewPriv *priv; + gtk_tree_path_free (src_path); - g_return_if_fail (EMPATHY_IS_CONTACT_LIST_VIEW (view)); + contact = empathy_contact_list_view_get_selected (EMPATHY_CONTACT_LIST_VIEW (widget)); + if (!contact) { + return; + } - priv = GET_PRIV (view); + account = empathy_contact_get_account (contact); + account_id = mc_account_get_unique_name (account); + contact_id = empathy_contact_get_id (contact); + g_object_unref (contact); + str = g_strconcat (account_id, "/", contact_id, NULL); - g_free (priv->filter_text); - if (filter) { - priv->filter_text = g_utf8_casefold (filter, -1); - } else { - priv->filter_text = NULL; + switch (info) { + case DND_DRAG_TYPE_CONTACT_ID: + gtk_selection_data_set (selection, drag_atoms_source[info], 8, + (guchar*)str, strlen (str) + 1); + break; } - empathy_debug (DEBUG_DOMAIN, "Refiltering with filter:'%s' (case folded)", filter); - gtk_tree_model_filter_refilter (GTK_TREE_MODEL_FILTER (priv->filter)); + g_free (str); } -void -empathy_contact_list_view_set_drag_received_func (EmpathyContactListView *view, - EmpathyContactListViewDragReceivedFunc func, - gpointer user_data) +static void +contact_list_view_drag_end (GtkWidget *widget, + GdkDragContext *context) { EmpathyContactListViewPriv *priv; - g_return_if_fail (EMPATHY_IS_CONTACT_LIST_VIEW (view)); + priv = GET_PRIV (widget); - priv = GET_PRIV (view); + GTK_WIDGET_CLASS (empathy_contact_list_view_parent_class)->drag_end (widget, + context); - if (func) { - priv->drag_received = func; - priv->drag_received_data = user_data; - } else { - priv->drag_received = NULL; - priv->drag_received_data = NULL; + if (priv->drag_row) { + gtk_tree_row_reference_free (priv->drag_row); + priv->drag_row = NULL; } } -static void -contact_list_view_setup (EmpathyContactListView *view) +static gboolean +contact_list_view_drag_drop (GtkWidget *widget, + GdkDragContext *drag_context, + gint x, + gint y, + guint time) { - EmpathyContactListViewPriv *priv; - GtkCellRenderer *cell; - GtkTreeViewColumn *col; - gint i; - - priv = GET_PRIV (view); - - /* Create filter */ - priv->filter = gtk_tree_model_filter_new (GTK_TREE_MODEL (priv->store), NULL); + return FALSE; +} - gtk_tree_model_filter_set_visible_func (GTK_TREE_MODEL_FILTER (priv->filter), - (GtkTreeModelFilterVisibleFunc) - contact_list_view_filter_func, - view, NULL); - gtk_tree_view_set_search_equal_func (GTK_TREE_VIEW (view), - empathy_contact_list_store_search_equal_func, - view, NULL); - g_signal_connect (priv->filter, "row-has-child-toggled", - G_CALLBACK (contact_list_view_row_has_child_toggled_cb), - view); - gtk_tree_view_set_model (GTK_TREE_VIEW (view), priv->filter); +typedef struct { + EmpathyContactListView *view; + guint button; + guint32 time; +} MenuPopupData; +static gboolean +contact_list_view_popup_menu_idle_cb (gpointer user_data) +{ + MenuPopupData *data = user_data; + GtkWidget *menu; - /* Setup view */ - g_object_set (view, - "headers-visible", FALSE, - "reorderable", TRUE, - "show-expanders", FALSE, - NULL); + menu = empathy_contact_list_view_get_contact_menu (data->view); + if (!menu) { + menu = empathy_contact_list_view_get_group_menu (data->view); + } - col = gtk_tree_view_column_new (); + if (menu) { + gtk_widget_show (menu); + gtk_menu_popup (GTK_MENU (menu), + NULL, NULL, NULL, NULL, + data->button, data->time); + } - /* State */ - cell = gtk_cell_renderer_pixbuf_new (); - gtk_tree_view_column_pack_start (col, cell, FALSE); - gtk_tree_view_column_set_cell_data_func ( - col, cell, - (GtkTreeCellDataFunc) contact_list_view_pixbuf_cell_data_func, - view, NULL); + g_slice_free (MenuPopupData, data); - g_object_set (cell, - "xpad", 5, - "ypad", 1, - "visible", FALSE, - NULL); + return FALSE; +} - /* Name */ - cell = empathy_cell_renderer_text_new (); - gtk_tree_view_column_pack_start (col, cell, TRUE); - gtk_tree_view_column_set_cell_data_func ( - col, cell, - (GtkTreeCellDataFunc) contact_list_view_text_cell_data_func, - view, NULL); +static gboolean +contact_list_view_button_press_event_cb (EmpathyContactListView *view, + GdkEventButton *event, + gpointer user_data) +{ + if (event->button == 3) { + MenuPopupData *data; + + data = g_slice_new (MenuPopupData); + data->view = view; + data->button = event->button; + data->time = event->time; + g_idle_add (contact_list_view_popup_menu_idle_cb, data); + } - gtk_tree_view_column_add_attribute (col, cell, - "name", COL_NAME); - gtk_tree_view_column_add_attribute (col, cell, - "status", COL_STATUS); - gtk_tree_view_column_add_attribute (col, cell, - "is_group", COL_IS_GROUP); + return FALSE; +} - /* Avatar */ - cell = gtk_cell_renderer_pixbuf_new (); - gtk_tree_view_column_pack_start (col, cell, FALSE); - gtk_tree_view_column_set_cell_data_func ( - col, cell, - (GtkTreeCellDataFunc) contact_list_view_avatar_cell_data_func, - view, NULL); +static gboolean +contact_list_view_key_press_event_cb (EmpathyContactListView *view, + GdkEventKey *event, + gpointer user_data) +{ + if (event->keyval == GDK_Menu) { + MenuPopupData *data; + + data = g_slice_new (MenuPopupData); + data->view = view; + data->button = 0; + data->time = event->time; + g_idle_add (contact_list_view_popup_menu_idle_cb, data); + } - g_object_set (cell, - "xpad", 0, - "ypad", 0, - "visible", FALSE, - "width", 32, - "height", 32, - NULL); + return FALSE; +} - /* Expander */ - cell = empathy_cell_renderer_expander_new (); - gtk_tree_view_column_pack_end (col, cell, FALSE); - gtk_tree_view_column_set_cell_data_func ( - col, cell, - (GtkTreeCellDataFunc) contact_list_view_expander_cell_data_func, - view, NULL); +static void +contact_list_view_row_activated_cb (EmpathyContactListView *view, + GtkTreePath *path, + GtkTreeViewColumn *col, + gpointer user_data) +{ + EmpathyContactListViewPriv *priv = GET_PRIV (view); + EmpathyContact *contact; + GtkTreeModel *model; + GtkTreeIter iter; - /* Actually add the column now we have added all cell renderers */ - gtk_tree_view_append_column (GTK_TREE_VIEW (view), col); + model = GTK_TREE_MODEL (priv->store); + gtk_tree_model_get_iter (model, &iter, path); + gtk_tree_model_get (model, &iter, + EMPATHY_CONTACT_LIST_STORE_COL_CONTACT, &contact, + -1); - /* Drag & Drop. */ - for (i = 0; i < G_N_ELEMENTS (drag_types_dest); ++i) { - drag_atoms_dest[i] = gdk_atom_intern (drag_types_dest[i].target, - FALSE); + if (!contact) { + return; } - for (i = 0; i < G_N_ELEMENTS (drag_types_source); ++i) { - drag_atoms_source[i] = gdk_atom_intern (drag_types_source[i].target, - FALSE); + /* There is no event for the contact, default action is starting a chat */ + if (priv->contact_features & EMPATHY_CONTACT_FEATURE_CHAT) { + empathy_dispatcher_chat_with_contact (contact); } - /* Note: We support the COPY action too, but need to make the - * MOVE action the default. - */ - gtk_drag_source_set (GTK_WIDGET (view), - GDK_BUTTON1_MASK, - drag_types_source, - G_N_ELEMENTS (drag_types_source), - GDK_ACTION_MOVE); - - gtk_drag_dest_set (GTK_WIDGET (view), - GTK_DEST_DEFAULT_ALL, - drag_types_dest, - G_N_ELEMENTS (drag_types_dest), - GDK_ACTION_MOVE | GDK_ACTION_LINK); + g_object_unref (contact); } static void -contact_list_view_row_has_child_toggled_cb (GtkTreeModel *model, - GtkTreePath *path, - GtkTreeIter *iter, - EmpathyContactListView *view) +contact_list_view_voip_activated_cb (EmpathyCellRendererActivatable *cell, + const gchar *path_string, + EmpathyContactListView *view) { - gboolean is_group = FALSE; - gchar *name = NULL; - - gtk_tree_model_get (model, iter, - COL_IS_GROUP, &is_group, - COL_NAME, &name, - -1); + EmpathyContactListViewPriv *priv = GET_PRIV (view); + GtkTreeModel *model; + GtkTreeIter iter; + EmpathyContact *contact; - if (!is_group || G_STR_EMPTY (name)) { - g_free (name); + if (!(priv->contact_features & EMPATHY_CONTACT_FEATURE_CALL)) { return; } - if (empathy_contact_group_get_expanded (name)) { - g_signal_handlers_block_by_func (view, - contact_list_view_row_expand_or_collapse_cb, - GINT_TO_POINTER (TRUE)); - gtk_tree_view_expand_row (GTK_TREE_VIEW (view), path, TRUE); - g_signal_handlers_unblock_by_func (view, - contact_list_view_row_expand_or_collapse_cb, - GINT_TO_POINTER (TRUE)); - } else { - g_signal_handlers_block_by_func (view, - contact_list_view_row_expand_or_collapse_cb, - GINT_TO_POINTER (FALSE)); - gtk_tree_view_collapse_row (GTK_TREE_VIEW (view), path); - g_signal_handlers_unblock_by_func (view, - contact_list_view_row_expand_or_collapse_cb, - GINT_TO_POINTER (FALSE)); + model = gtk_tree_view_get_model (GTK_TREE_VIEW (view)); + if (!gtk_tree_model_get_iter_from_string (model, &iter, path_string)) { + return; } - g_free (name); + gtk_tree_model_get (model, &iter, + EMPATHY_CONTACT_LIST_STORE_COL_CONTACT, &contact, + -1); + + if (contact) { + empathy_dispatcher_call_with_contact (contact); + g_object_unref (contact); + } } static void -contact_list_view_contact_received (EmpathyContactListView *view, - EmpathyContact *contact, - GdkDragAction action, - const gchar *old_group, - const gchar *new_group) +contact_list_view_cell_set_background (EmpathyContactListView *view, + GtkCellRenderer *cell, + gboolean is_group, + gboolean is_active) { - EmpathyContactListViewPriv *priv; - GList *groups, *l; - GList *new_groups_list = NULL; - - priv = GET_PRIV (view); - - groups = empathy_contact_get_groups (contact); - for (l = groups; l; l = l->next) { - gchar *str; - - str = l->data; + GdkColor color; + GtkStyle *style; - if (action == GDK_ACTION_MOVE && - old_group != NULL && - strcmp (str, old_group) == 0) { - continue; - } + style = gtk_widget_get_style (GTK_WIDGET (view)); - if (new_group && strcmp (str, new_group) == 0) { - /* Otherwise we set it twice */ - continue; - } + if (!is_group && is_active) { + color = style->bg[GTK_STATE_SELECTED]; - new_groups_list = g_list_prepend (new_groups_list, g_strdup (str)); - } + /* Here we take the current theme colour and add it to + * the colour for white and average the two. This + * gives a colour which is inline with the theme but + * slightly whiter. + */ + color.red = (color.red + (style->white).red) / 2; + color.green = (color.green + (style->white).green) / 2; + color.blue = (color.blue + (style->white).blue) / 2; - if (new_group) { - new_groups_list = g_list_prepend (new_groups_list, g_strdup (new_group)); + g_object_set (cell, + "cell-background-gdk", &color, + NULL); + } else { + g_object_set (cell, + "cell-background-gdk", NULL, + NULL); } - - empathy_contact_set_groups (contact, new_groups_list); } static void -contact_list_view_drag_data_received (GtkWidget *widget, - GdkDragContext *context, - gint x, - gint y, - GtkSelectionData *selection, - guint info, - guint time) +contact_list_view_pixbuf_cell_data_func (GtkTreeViewColumn *tree_column, + GtkCellRenderer *cell, + GtkTreeModel *model, + GtkTreeIter *iter, + EmpathyContactListView *view) { - EmpathyContactListViewPriv *priv; - EmpathyContactList *list; - GtkTreeModel *model; - GtkTreePath *path; - GtkTreeViewDropPosition position; - EmpathyContact *contact; - const gchar *id; - gchar *new_group = NULL; - gchar *old_group = NULL; - gboolean is_row; + gchar *icon_name; + gboolean is_group; + gboolean is_active; - priv = GET_PRIV (widget); + gtk_tree_model_get (model, iter, + EMPATHY_CONTACT_LIST_STORE_COL_IS_GROUP, &is_group, + EMPATHY_CONTACT_LIST_STORE_COL_IS_ACTIVE, &is_active, + EMPATHY_CONTACT_LIST_STORE_COL_ICON_STATUS, &icon_name, + -1); - id = (const gchar*) selection->data; - empathy_debug (DEBUG_DOMAIN, "Received %s%s drag & drop contact from roster with id:'%s'", - context->action == GDK_ACTION_MOVE ? "move" : "", - context->action == GDK_ACTION_COPY ? "copy" : "", - id); + g_object_set (cell, + "visible", !is_group, + "icon-name", icon_name, + NULL); - /* FIXME: This is ambigous, an id can come from multiple accounts */ - list = empathy_contact_list_store_get_list_iface (priv->store); - contact = empathy_contact_list_find (list, id); + g_free (icon_name); - if (!contact) { - empathy_debug (DEBUG_DOMAIN, "No contact found associated with drag & drop"); - return; - } + contact_list_view_cell_set_background (view, cell, is_group, is_active); +} - model = gtk_tree_view_get_model (GTK_TREE_VIEW (widget)); +static void +contact_list_view_voip_cell_data_func (GtkTreeViewColumn *tree_column, + GtkCellRenderer *cell, + GtkTreeModel *model, + GtkTreeIter *iter, + EmpathyContactListView *view) +{ + gboolean is_group; + gboolean is_active; + gboolean can_voip; - /* Get source group information. */ - if (priv->drag_row) { - path = gtk_tree_row_reference_get_path (priv->drag_row); - if (path) { - old_group = empathy_contact_list_store_get_parent_group (model, path, NULL); - gtk_tree_path_free (path); - } - } + gtk_tree_model_get (model, iter, + EMPATHY_CONTACT_LIST_STORE_COL_IS_GROUP, &is_group, + EMPATHY_CONTACT_LIST_STORE_COL_IS_ACTIVE, &is_active, + EMPATHY_CONTACT_LIST_STORE_COL_CAN_VOIP, &can_voip, + -1); - /* Get destination group information. */ - is_row = gtk_tree_view_get_dest_row_at_pos (GTK_TREE_VIEW (widget), - x, - y, - &path, - &position); + g_object_set (cell, + "visible", !is_group && can_voip, + "icon-name", EMPATHY_IMAGE_VOIP, + NULL); - if (is_row) { - new_group = empathy_contact_list_store_get_parent_group (model, path, NULL); - gtk_tree_path_free (path); - } + contact_list_view_cell_set_background (view, cell, is_group, is_active); +} - empathy_debug (DEBUG_DOMAIN, - "contact '%s' dragged from '%s' to '%s'", - empathy_contact_get_name (contact), - old_group, new_group); - - if (priv->drag_received) { - priv->drag_received (contact, - context->action, - old_group, - new_group, - priv->drag_received_data); - } else { - contact_list_view_contact_received (EMPATHY_CONTACT_LIST_VIEW (widget), - contact, - context->action, - old_group, - new_group); - } +static void +contact_list_view_avatar_cell_data_func (GtkTreeViewColumn *tree_column, + GtkCellRenderer *cell, + GtkTreeModel *model, + GtkTreeIter *iter, + EmpathyContactListView *view) +{ + GdkPixbuf *pixbuf; + gboolean show_avatar; + gboolean is_group; + gboolean is_active; - g_free (old_group); - g_free (new_group); + gtk_tree_model_get (model, iter, + EMPATHY_CONTACT_LIST_STORE_COL_PIXBUF_AVATAR, &pixbuf, + EMPATHY_CONTACT_LIST_STORE_COL_PIXBUF_AVATAR_VISIBLE, &show_avatar, + EMPATHY_CONTACT_LIST_STORE_COL_IS_GROUP, &is_group, + EMPATHY_CONTACT_LIST_STORE_COL_IS_ACTIVE, &is_active, + -1); - gtk_drag_finish (context, TRUE, FALSE, GDK_CURRENT_TIME); + g_object_set (cell, + "visible", !is_group && show_avatar, + "pixbuf", pixbuf, + NULL); + + if (pixbuf) { + g_object_unref (pixbuf); + } + + contact_list_view_cell_set_background (view, cell, is_group, is_active); } -static gboolean -contact_list_view_drag_motion (GtkWidget *widget, - GdkDragContext *context, - gint x, - gint y, - guint time) +static void +contact_list_view_text_cell_data_func (GtkTreeViewColumn *tree_column, + GtkCellRenderer *cell, + GtkTreeModel *model, + GtkTreeIter *iter, + EmpathyContactListView *view) { - static DragMotionData *dm = NULL; - GtkTreePath *path; - gboolean is_row; - gboolean is_different = FALSE; - gboolean cleanup = TRUE; + gboolean is_group; + gboolean is_active; + gboolean show_status; - is_row = gtk_tree_view_get_path_at_pos (GTK_TREE_VIEW (widget), - x, - y, - &path, - NULL, - NULL, - NULL); + gtk_tree_model_get (model, iter, + EMPATHY_CONTACT_LIST_STORE_COL_IS_GROUP, &is_group, + EMPATHY_CONTACT_LIST_STORE_COL_IS_ACTIVE, &is_active, + EMPATHY_CONTACT_LIST_STORE_COL_STATUS_VISIBLE, &show_status, + -1); - cleanup &= (!dm); + g_object_set (cell, + "show-status", show_status, + NULL); - if (is_row) { - cleanup &= (dm && gtk_tree_path_compare (dm->path, path) != 0); - is_different = (!dm || (dm && gtk_tree_path_compare (dm->path, path) != 0)); - } else { - cleanup &= FALSE; - } + contact_list_view_cell_set_background (view, cell, is_group, is_active); +} - if (!is_different && !cleanup) { - return TRUE; - } +static void +contact_list_view_expander_cell_data_func (GtkTreeViewColumn *column, + GtkCellRenderer *cell, + GtkTreeModel *model, + GtkTreeIter *iter, + EmpathyContactListView *view) +{ + gboolean is_group; + gboolean is_active; - if (dm) { - gtk_tree_path_free (dm->path); - if (dm->timeout_id) { - g_source_remove (dm->timeout_id); - } + gtk_tree_model_get (model, iter, + EMPATHY_CONTACT_LIST_STORE_COL_IS_GROUP, &is_group, + EMPATHY_CONTACT_LIST_STORE_COL_IS_ACTIVE, &is_active, + -1); - g_free (dm); + if (gtk_tree_model_iter_has_child (model, iter)) { + GtkTreePath *path; + gboolean row_expanded; - dm = NULL; + path = gtk_tree_model_get_path (model, iter); + row_expanded = gtk_tree_view_row_expanded (GTK_TREE_VIEW (column->tree_view), path); + gtk_tree_path_free (path); + + g_object_set (cell, + "visible", TRUE, + "expander-style", row_expanded ? GTK_EXPANDER_EXPANDED : GTK_EXPANDER_COLLAPSED, + NULL); + } else { + g_object_set (cell, "visible", FALSE, NULL); } - if (!gtk_tree_view_row_expanded (GTK_TREE_VIEW (widget), path)) { - dm = g_new0 (DragMotionData, 1); + contact_list_view_cell_set_background (view, cell, is_group, is_active); +} - dm->view = EMPATHY_CONTACT_LIST_VIEW (widget); - dm->path = gtk_tree_path_copy (path); +static void +contact_list_view_row_expand_or_collapse_cb (EmpathyContactListView *view, + GtkTreeIter *iter, + GtkTreePath *path, + gpointer user_data) +{ + EmpathyContactListViewPriv *priv = GET_PRIV (view); + GtkTreeModel *model; + gchar *name; + gboolean expanded; - dm->timeout_id = g_timeout_add ( - 1500, - (GSourceFunc) contact_list_view_drag_motion_cb, - dm); + if (!(priv->list_features & EMPATHY_CONTACT_LIST_FEATURE_GROUPS_SAVE)) { + return; } - return TRUE; -} + model = gtk_tree_view_get_model (GTK_TREE_VIEW (view)); -static gboolean -contact_list_view_drag_motion_cb (DragMotionData *data) -{ - gtk_tree_view_expand_row (GTK_TREE_VIEW (data->view), - data->path, - FALSE); + gtk_tree_model_get (model, iter, + EMPATHY_CONTACT_LIST_STORE_COL_NAME, &name, + -1); - data->timeout_id = 0; + expanded = GPOINTER_TO_INT (user_data); + empathy_contact_group_set_expanded (name, expanded); - return FALSE; + g_free (name); } static void -contact_list_view_drag_begin (GtkWidget *widget, - GdkDragContext *context) +contact_list_view_row_has_child_toggled_cb (GtkTreeModel *model, + GtkTreePath *path, + GtkTreeIter *iter, + EmpathyContactListView *view) { - EmpathyContactListViewPriv *priv; - GtkTreeSelection *selection; - GtkTreeModel *model; - GtkTreePath *path; - GtkTreeIter iter; - - priv = GET_PRIV (widget); + EmpathyContactListViewPriv *priv = GET_PRIV (view); + gboolean is_group = FALSE; + gchar *name = NULL; - GTK_WIDGET_CLASS (empathy_contact_list_view_parent_class)->drag_begin (widget, - context); + gtk_tree_model_get (model, iter, + EMPATHY_CONTACT_LIST_STORE_COL_IS_GROUP, &is_group, + EMPATHY_CONTACT_LIST_STORE_COL_NAME, &name, + -1); - selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (widget)); - if (!gtk_tree_selection_get_selected (selection, &model, &iter)) { + if (!is_group || G_STR_EMPTY (name)) { + g_free (name); return; } - path = gtk_tree_model_get_path (model, &iter); - priv->drag_row = gtk_tree_row_reference_new (model, path); - gtk_tree_path_free (path); + if (!(priv->list_features & EMPATHY_CONTACT_LIST_FEATURE_GROUPS_SAVE) || + empathy_contact_group_get_expanded (name)) { + g_signal_handlers_block_by_func (view, + contact_list_view_row_expand_or_collapse_cb, + GINT_TO_POINTER (TRUE)); + gtk_tree_view_expand_row (GTK_TREE_VIEW (view), path, TRUE); + g_signal_handlers_unblock_by_func (view, + contact_list_view_row_expand_or_collapse_cb, + GINT_TO_POINTER (TRUE)); + } else { + g_signal_handlers_block_by_func (view, + contact_list_view_row_expand_or_collapse_cb, + GINT_TO_POINTER (FALSE)); + gtk_tree_view_collapse_row (GTK_TREE_VIEW (view), path); + g_signal_handlers_unblock_by_func (view, + contact_list_view_row_expand_or_collapse_cb, + GINT_TO_POINTER (FALSE)); + } + + g_free (name); } static void -contact_list_view_drag_data_get (GtkWidget *widget, - GdkDragContext *context, - GtkSelectionData *selection, - guint info, - guint time) +contact_list_view_setup (EmpathyContactListView *view) { EmpathyContactListViewPriv *priv; - GtkTreePath *src_path; - GtkTreeIter iter; - GtkTreeModel *model; - EmpathyContact *contact; - const gchar *id; + GtkCellRenderer *cell; + GtkTreeViewColumn *col; + gint i; - priv = GET_PRIV (widget); + priv = GET_PRIV (view); - model = gtk_tree_view_get_model (GTK_TREE_VIEW (widget)); - if (!priv->drag_row) { - return; - } + gtk_tree_view_set_search_equal_func (GTK_TREE_VIEW (view), + empathy_contact_list_store_search_equal_func, + NULL, NULL); - src_path = gtk_tree_row_reference_get_path (priv->drag_row); - if (!src_path) { - return; - } + g_signal_connect (priv->store, "row-has-child-toggled", + G_CALLBACK (contact_list_view_row_has_child_toggled_cb), + view); + gtk_tree_view_set_model (GTK_TREE_VIEW (view), + GTK_TREE_MODEL (priv->store)); - if (!gtk_tree_model_get_iter (model, &iter, src_path)) { - gtk_tree_path_free (src_path); - return; - } + /* Setup view */ + g_object_set (view, + "headers-visible", FALSE, + "reorderable", TRUE, + "show-expanders", FALSE, + NULL); - gtk_tree_path_free (src_path); + col = gtk_tree_view_column_new (); - contact = empathy_contact_list_view_get_selected (EMPATHY_CONTACT_LIST_VIEW (widget)); - if (!contact) { - return; - } + /* State */ + cell = gtk_cell_renderer_pixbuf_new (); + gtk_tree_view_column_pack_start (col, cell, FALSE); + gtk_tree_view_column_set_cell_data_func ( + col, cell, + (GtkTreeCellDataFunc) contact_list_view_pixbuf_cell_data_func, + view, NULL); - id = empathy_contact_get_id (contact); - g_object_unref (contact); + g_object_set (cell, + "xpad", 5, + "ypad", 1, + "visible", FALSE, + NULL); - switch (info) { - case DND_DRAG_TYPE_CONTACT_ID: - gtk_selection_data_set (selection, drag_atoms_source[info], 8, - (guchar*)id, strlen (id) + 1); - break; + /* Name */ + cell = empathy_cell_renderer_text_new (); + gtk_tree_view_column_pack_start (col, cell, TRUE); + gtk_tree_view_column_set_cell_data_func ( + col, cell, + (GtkTreeCellDataFunc) contact_list_view_text_cell_data_func, + view, NULL); - default: - return; - } -} + gtk_tree_view_column_add_attribute (col, cell, + "name", EMPATHY_CONTACT_LIST_STORE_COL_NAME); + gtk_tree_view_column_add_attribute (col, cell, + "status", EMPATHY_CONTACT_LIST_STORE_COL_STATUS); + gtk_tree_view_column_add_attribute (col, cell, + "is_group", EMPATHY_CONTACT_LIST_STORE_COL_IS_GROUP); -static void -contact_list_view_drag_end (GtkWidget *widget, - GdkDragContext *context) -{ - EmpathyContactListViewPriv *priv; + /* Voip Capability Icon */ + cell = empathy_cell_renderer_activatable_new (); + gtk_tree_view_column_pack_start (col, cell, FALSE); + gtk_tree_view_column_set_cell_data_func ( + col, cell, + (GtkTreeCellDataFunc) contact_list_view_voip_cell_data_func, + view, NULL); - priv = GET_PRIV (widget); + g_object_set (cell, + "visible", FALSE, + NULL); - GTK_WIDGET_CLASS (empathy_contact_list_view_parent_class)->drag_end (widget, - context); + g_signal_connect (cell, "path-activated", + G_CALLBACK (contact_list_view_voip_activated_cb), + view); - if (priv->drag_row) { - gtk_tree_row_reference_free (priv->drag_row); - priv->drag_row = NULL; - } -} + /* Avatar */ + cell = gtk_cell_renderer_pixbuf_new (); + gtk_tree_view_column_pack_start (col, cell, FALSE); + gtk_tree_view_column_set_cell_data_func ( + col, cell, + (GtkTreeCellDataFunc) contact_list_view_avatar_cell_data_func, + view, NULL); -static gboolean -contact_list_view_drag_drop (GtkWidget *widget, - GdkDragContext *drag_context, - gint x, - gint y, - guint time) -{ - return FALSE; -} + g_object_set (cell, + "xpad", 0, + "ypad", 0, + "visible", FALSE, + "width", 32, + "height", 32, + NULL); -static void -contact_list_view_cell_set_background (EmpathyContactListView *view, - GtkCellRenderer *cell, - gboolean is_group, - gboolean is_active) -{ - GdkColor color; - GtkStyle *style; + /* Expander */ + cell = empathy_cell_renderer_expander_new (); + gtk_tree_view_column_pack_end (col, cell, FALSE); + gtk_tree_view_column_set_cell_data_func ( + col, cell, + (GtkTreeCellDataFunc) contact_list_view_expander_cell_data_func, + view, NULL); - style = gtk_widget_get_style (GTK_WIDGET (view)); + /* Actually add the column now we have added all cell renderers */ + gtk_tree_view_append_column (GTK_TREE_VIEW (view), col); - if (!is_group) { - if (is_active) { - color = style->bg[GTK_STATE_SELECTED]; - - /* Here we take the current theme colour and add it to - * the colour for white and average the two. This - * gives a colour which is inline with the theme but - * slightly whiter. - */ - color.red = (color.red + (style->white).red) / 2; - color.green = (color.green + (style->white).green) / 2; - color.blue = (color.blue + (style->white).blue) / 2; - - g_object_set (cell, - "cell-background-gdk", &color, - NULL); - } else { - g_object_set (cell, - "cell-background-gdk", NULL, - NULL); - } - } else { - g_object_set (cell, - "cell-background-gdk", NULL, - NULL); + /* Drag & Drop. */ + for (i = 0; i < G_N_ELEMENTS (drag_types_dest); ++i) { + drag_atoms_dest[i] = gdk_atom_intern (drag_types_dest[i].target, + FALSE); + } + + for (i = 0; i < G_N_ELEMENTS (drag_types_source); ++i) { + drag_atoms_source[i] = gdk_atom_intern (drag_types_source[i].target, + FALSE); } } static void -contact_list_view_pixbuf_cell_data_func (GtkTreeViewColumn *tree_column, - GtkCellRenderer *cell, - GtkTreeModel *model, - GtkTreeIter *iter, - EmpathyContactListView *view) +contact_list_view_set_list_features (EmpathyContactListView *view, + EmpathyContactListFeatureFlags features) { - gchar *icon_name; - gboolean is_group; - gboolean is_active; + EmpathyContactListViewPriv *priv = GET_PRIV (view); + gboolean has_tooltip; - gtk_tree_model_get (model, iter, - COL_IS_GROUP, &is_group, - COL_IS_ACTIVE, &is_active, - COL_ICON_STATUS, &icon_name, - -1); + g_return_if_fail (EMPATHY_IS_CONTACT_LIST_VIEW (view)); - g_object_set (cell, - "visible", !is_group, - "icon-name", icon_name, - NULL); + priv->list_features = features; - g_free (icon_name); + /* Update DnD source/dest */ + if (features & EMPATHY_CONTACT_LIST_FEATURE_CONTACT_DRAG) { + gtk_drag_source_set (GTK_WIDGET (view), + GDK_BUTTON1_MASK, + drag_types_source, + G_N_ELEMENTS (drag_types_source), + GDK_ACTION_MOVE | GDK_ACTION_COPY); + } else { + gtk_drag_source_unset (GTK_WIDGET (view)); - contact_list_view_cell_set_background (view, cell, is_group, is_active); + } + + if (features & EMPATHY_CONTACT_LIST_FEATURE_CONTACT_DROP) { + gtk_drag_dest_set (GTK_WIDGET (view), + GTK_DEST_DEFAULT_ALL, + drag_types_dest, + G_N_ELEMENTS (drag_types_dest), + GDK_ACTION_MOVE | GDK_ACTION_COPY); + } else { + /* FIXME: URI could still be droped depending on FT feature */ + gtk_drag_dest_unset (GTK_WIDGET (view)); + } + + /* Update has-tooltip */ + has_tooltip = (features & EMPATHY_CONTACT_LIST_FEATURE_CONTACT_TOOLTIP) != 0; + gtk_widget_set_has_tooltip (GTK_WIDGET (view), has_tooltip); } static void -contact_list_view_avatar_cell_data_func (GtkTreeViewColumn *tree_column, - GtkCellRenderer *cell, - GtkTreeModel *model, - GtkTreeIter *iter, - EmpathyContactListView *view) +contact_list_view_finalize (GObject *object) { - GdkPixbuf *pixbuf; - gboolean show_avatar; - gboolean is_group; - gboolean is_active; - - gtk_tree_model_get (model, iter, - COL_PIXBUF_AVATAR, &pixbuf, - COL_PIXBUF_AVATAR_VISIBLE, &show_avatar, - COL_IS_GROUP, &is_group, - COL_IS_ACTIVE, &is_active, - -1); + EmpathyContactListViewPriv *priv; - g_object_set (cell, - "visible", !is_group && show_avatar, - "pixbuf", pixbuf, - NULL); + priv = GET_PRIV (object); - if (pixbuf) { - g_object_unref (pixbuf); + if (priv->store) { + g_object_unref (priv->store); } - contact_list_view_cell_set_background (view, cell, is_group, is_active); + G_OBJECT_CLASS (empathy_contact_list_view_parent_class)->finalize (object); } static void -contact_list_view_text_cell_data_func (GtkTreeViewColumn *tree_column, - GtkCellRenderer *cell, - GtkTreeModel *model, - GtkTreeIter *iter, - EmpathyContactListView *view) +contact_list_view_get_property (GObject *object, + guint param_id, + GValue *value, + GParamSpec *pspec) { - gboolean is_group; - gboolean is_active; - gboolean show_status; + EmpathyContactListViewPriv *priv; - gtk_tree_model_get (model, iter, - COL_IS_GROUP, &is_group, - COL_IS_ACTIVE, &is_active, - COL_STATUS_VISIBLE, &show_status, - -1); + priv = GET_PRIV (object); + + switch (param_id) { + case PROP_STORE: + g_value_set_object (value, priv->store); + break; + case PROP_LIST_FEATURES: + g_value_set_flags (value, priv->list_features); + break; + case PROP_CONTACT_FEATURES: + g_value_set_flags (value, priv->contact_features); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec); + break; + }; +} - g_object_set (cell, - "show-status", show_status, - NULL); +static void +contact_list_view_set_property (GObject *object, + guint param_id, + const GValue *value, + GParamSpec *pspec) +{ + EmpathyContactListView *view = EMPATHY_CONTACT_LIST_VIEW (object); + EmpathyContactListViewPriv *priv = GET_PRIV (object); - contact_list_view_cell_set_background (view, cell, is_group, is_active); + switch (param_id) { + case PROP_STORE: + priv->store = g_value_dup_object (value); + contact_list_view_setup (view); + break; + case PROP_LIST_FEATURES: + contact_list_view_set_list_features (view, g_value_get_flags (value)); + break; + case PROP_CONTACT_FEATURES: + priv->contact_features = g_value_get_flags (value); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec); + break; + }; } static void -contact_list_view_expander_cell_data_func (GtkTreeViewColumn *column, - GtkCellRenderer *cell, - GtkTreeModel *model, - GtkTreeIter *iter, - EmpathyContactListView *view) +empathy_contact_list_view_class_init (EmpathyContactListViewClass *klass) { - gboolean is_group; - gboolean is_active; + GObjectClass *object_class = G_OBJECT_CLASS (klass); + GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); - gtk_tree_model_get (model, iter, - COL_IS_GROUP, &is_group, - COL_IS_ACTIVE, &is_active, - -1); + object_class->finalize = contact_list_view_finalize; + object_class->get_property = contact_list_view_get_property; + object_class->set_property = contact_list_view_set_property; - if (gtk_tree_model_iter_has_child (model, iter)) { - GtkTreePath *path; - gboolean row_expanded; + widget_class->drag_data_received = contact_list_view_drag_data_received; + widget_class->drag_drop = contact_list_view_drag_drop; + widget_class->drag_begin = contact_list_view_drag_begin; + widget_class->drag_data_get = contact_list_view_drag_data_get; + widget_class->drag_end = contact_list_view_drag_end; + /* FIXME: noticed but when you drag the row over the treeview + * fast, it seems to stop redrawing itself, if we don't + * connect this signal, all is fine. + */ + widget_class->drag_motion = contact_list_view_drag_motion; - path = gtk_tree_model_get_path (model, iter); - row_expanded = gtk_tree_view_row_expanded (GTK_TREE_VIEW (column->tree_view), path); - gtk_tree_path_free (path); + signals[DRAG_CONTACT_RECEIVED] = + g_signal_new ("drag-contact-received", + G_OBJECT_CLASS_TYPE (klass), + G_SIGNAL_RUN_LAST, + 0, + NULL, NULL, + _empathy_gtk_marshal_VOID__OBJECT_STRING_STRING, + G_TYPE_NONE, + 3, EMPATHY_TYPE_CONTACT, G_TYPE_STRING, G_TYPE_STRING); - g_object_set (cell, - "visible", TRUE, - "expander-style", row_expanded ? GTK_EXPANDER_EXPANDED : GTK_EXPANDER_COLLAPSED, - NULL); - } else { - g_object_set (cell, "visible", FALSE, NULL); - } + g_object_class_install_property (object_class, + PROP_STORE, + g_param_spec_object ("store", + "The store of the view", + "The store of the view", + EMPATHY_TYPE_CONTACT_LIST_STORE, + G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE)); + g_object_class_install_property (object_class, + PROP_LIST_FEATURES, + g_param_spec_flags ("list-features", + "Features of the view", + "Falgs for all enabled features", + EMPATHY_TYPE_CONTACT_LIST_FEATURE_FLAGS, + EMPATHY_CONTACT_LIST_FEATURE_NONE, + G_PARAM_READWRITE)); + g_object_class_install_property (object_class, + PROP_CONTACT_FEATURES, + g_param_spec_flags ("contact-features", + "Features of the contact menu", + "Falgs for all enabled features for the menu", + EMPATHY_TYPE_CONTACT_FEATURE_FLAGS, + EMPATHY_CONTACT_FEATURE_NONE, + G_PARAM_READWRITE)); - contact_list_view_cell_set_background (view, cell, is_group, is_active); + g_type_class_add_private (object_class, sizeof (EmpathyContactListViewPriv)); } -static GtkWidget * -contact_list_view_get_contact_menu (EmpathyContactListView *view, - gboolean can_send_file, - gboolean can_show_log) +static void +empathy_contact_list_view_init (EmpathyContactListView *view) { - EmpathyContactListViewPriv *priv; - GtkAction *action; - GtkWidget *widget; - - priv = GET_PRIV (view); + EmpathyContactListViewPriv *priv = G_TYPE_INSTANCE_GET_PRIVATE (view, + EMPATHY_TYPE_CONTACT_LIST_VIEW, EmpathyContactListViewPriv); - /* Sort out sensitive items */ - action = gtk_ui_manager_get_action (priv->ui, "/Contact/Log"); - gtk_action_set_sensitive (action, can_show_log); + view->priv = priv; + /* Get saved group states. */ + empathy_contact_groups_get_all (); - action = gtk_ui_manager_get_action (priv->ui, "/Contact/SendFile"); - gtk_action_set_visible (action, can_send_file); + gtk_tree_view_set_row_separator_func (GTK_TREE_VIEW (view), + empathy_contact_list_store_row_separator_func, + NULL, NULL); - widget = gtk_ui_manager_get_widget (priv->ui, "/Contact"); + /* Connect to tree view signals rather than override. */ + g_signal_connect (view, "button-press-event", + G_CALLBACK (contact_list_view_button_press_event_cb), + NULL); + g_signal_connect (view, "key-press-event", + G_CALLBACK (contact_list_view_key_press_event_cb), + NULL); + g_signal_connect (view, "row-activated", + G_CALLBACK (contact_list_view_row_activated_cb), + NULL); + g_signal_connect (view, "row-expanded", + G_CALLBACK (contact_list_view_row_expand_or_collapse_cb), + GINT_TO_POINTER (TRUE)); + g_signal_connect (view, "row-collapsed", + G_CALLBACK (contact_list_view_row_expand_or_collapse_cb), + GINT_TO_POINTER (FALSE)); + g_signal_connect (view, "query-tooltip", + G_CALLBACK (contact_list_view_query_tooltip_cb), + NULL); +} - return widget; +EmpathyContactListView * +empathy_contact_list_view_new (EmpathyContactListStore *store, + EmpathyContactListFeatureFlags list_features, + EmpathyContactFeatureFlags contact_features) +{ + g_return_val_if_fail (EMPATHY_IS_CONTACT_LIST_STORE (store), NULL); + + return g_object_new (EMPATHY_TYPE_CONTACT_LIST_VIEW, + "store", store, + "contact-features", contact_features, + "list-features", list_features, + NULL); } -static gboolean -contact_list_view_button_press_event_cb (EmpathyContactListView *view, - GdkEventButton *event, - gpointer user_data) +EmpathyContact * +empathy_contact_list_view_get_selected (EmpathyContactListView *view) { EmpathyContactListViewPriv *priv; - EmpathyContact *contact; - GtkTreePath *path; GtkTreeSelection *selection; - GtkTreeModel *model; GtkTreeIter iter; - gboolean row_exists; - GtkWidget *menu; + GtkTreeModel *model; + EmpathyContact *contact; - if (event->button != 3) { - return FALSE; - } + g_return_val_if_fail (EMPATHY_IS_CONTACT_LIST_VIEW (view), NULL); priv = GET_PRIV (view); selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (view)); - model = gtk_tree_view_get_model (GTK_TREE_VIEW (view)); - - gtk_widget_grab_focus (GTK_WIDGET (view)); - - row_exists = gtk_tree_view_get_path_at_pos (GTK_TREE_VIEW (view), - event->x, event->y, - &path, - NULL, NULL, NULL); - if (!row_exists) { - return FALSE; - } - - gtk_tree_selection_unselect_all (selection); - gtk_tree_selection_select_path (selection, path); - - gtk_tree_model_get_iter (model, &iter, path); - gtk_tree_path_free (path); - - gtk_tree_model_get (model, &iter, COL_CONTACT, &contact, -1); - - if (contact) { - menu = empathy_contact_list_view_get_contact_menu (view, contact); - g_object_unref (contact); - } else { - menu = empathy_contact_list_view_get_group_menu (view); - } - - if (!menu) { - return FALSE; + if (!gtk_tree_selection_get_selected (selection, &model, &iter)) { + return NULL; } - gtk_widget_show (menu); - - gtk_menu_popup (GTK_MENU (menu), - NULL, NULL, NULL, NULL, - event->button, event->time); + gtk_tree_model_get (model, &iter, + EMPATHY_CONTACT_LIST_STORE_COL_CONTACT, &contact, + -1); - return TRUE; + return contact; } -static void -contact_list_view_row_activated_cb (EmpathyContactListView *view, - GtkTreePath *path, - GtkTreeViewColumn *col, - gpointer user_data) +gchar * +empathy_contact_list_view_get_selected_group (EmpathyContactListView *view) { - EmpathyContact *contact; - GtkTreeModel *model; - GtkTreeIter iter; + EmpathyContactListViewPriv *priv; + GtkTreeSelection *selection; + GtkTreeIter iter; + GtkTreeModel *model; + gboolean is_group; + gchar *name; - model = gtk_tree_view_get_model (GTK_TREE_VIEW (view)); + g_return_val_if_fail (EMPATHY_IS_CONTACT_LIST_VIEW (view), NULL); - gtk_tree_model_get_iter (model, &iter, path); - gtk_tree_model_get (model, &iter, COL_CONTACT, &contact, -1); + priv = GET_PRIV (view); - if (contact) { - contact_list_view_action_activated (view, contact); - g_object_unref (contact); + selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (view)); + if (!gtk_tree_selection_get_selected (selection, &model, &iter)) { + return NULL; } -} - -static void -contact_list_view_row_expand_or_collapse_cb (EmpathyContactListView *view, - GtkTreeIter *iter, - GtkTreePath *path, - gpointer user_data) -{ - GtkTreeModel *model; - gchar *name; - gboolean expanded; - model = gtk_tree_view_get_model (GTK_TREE_VIEW (view)); - - gtk_tree_model_get (model, iter, - COL_NAME, &name, + gtk_tree_model_get (model, &iter, + EMPATHY_CONTACT_LIST_STORE_COL_IS_GROUP, &is_group, + EMPATHY_CONTACT_LIST_STORE_COL_NAME, &name, -1); - expanded = GPOINTER_TO_INT (user_data); - empathy_contact_group_set_expanded (name, expanded); + if (!is_group) { + g_free (name); + return NULL; + } - g_free (name); + return name; } -static gboolean -contact_list_view_filter_show_contact (EmpathyContact *contact, - const gchar *filter) +static gboolean +contact_list_view_remove_dialog_show (GtkWindow *parent, + const gchar *window_title, + const gchar *text) { - gchar *str; - gboolean visible; - - /* Check contact id */ - str = g_utf8_casefold (empathy_contact_get_id (contact), -1); - visible = G_STR_EMPTY (str) || strstr (str, filter); - g_free (str); - - if (visible) { - return TRUE; - } - - /* Check contact name */ - str = g_utf8_casefold (empathy_contact_get_name (contact), -1); - visible = G_STR_EMPTY (str) || strstr (str, filter); - g_free (str); + GtkWidget *dialog, *label, *image, *hbox; + gboolean res; - return visible; + dialog = gtk_dialog_new_with_buttons (window_title, parent, + GTK_DIALOG_MODAL, + GTK_STOCK_CANCEL, GTK_RESPONSE_NO, + GTK_STOCK_DELETE, GTK_RESPONSE_YES, + NULL); + gtk_dialog_set_has_separator (GTK_DIALOG(dialog), FALSE); + + label = gtk_label_new (text); + image = gtk_image_new_from_stock (GTK_STOCK_DIALOG_QUESTION, GTK_ICON_SIZE_DIALOG); + + hbox = gtk_hbox_new (FALSE, 5); + gtk_container_set_border_width (GTK_CONTAINER (hbox), 5); + gtk_box_pack_start_defaults (GTK_BOX (hbox), image); + gtk_box_pack_start_defaults (GTK_BOX (hbox), label); + gtk_box_pack_start_defaults (GTK_BOX(GTK_DIALOG(dialog)->vbox), hbox); + + gtk_widget_show (image); + gtk_widget_show (label); + gtk_widget_show (hbox); + gtk_widget_show (dialog); + + res = gtk_dialog_run (GTK_DIALOG (dialog)); + gtk_widget_destroy (dialog); + + return (res == GTK_RESPONSE_YES); } -static gboolean -contact_list_view_filter_show_group (EmpathyContactListView *view, - const gchar *group, - const gchar *filter) +static void +contact_list_view_group_remove_activate_cb (GtkMenuItem *menuitem, + EmpathyContactListView *view) { - EmpathyContactListViewPriv *priv; - EmpathyContactList *list; - GList *contacts, *l; - gchar *str; - gboolean show_group = FALSE; + EmpathyContactListViewPriv *priv = GET_PRIV (view); + gchar *group; - priv = GET_PRIV (view); - - str = g_utf8_casefold (group, -1); - if (!str) { - return FALSE; - } + group = empathy_contact_list_view_get_selected_group (view); + if (group) { + gchar *text; + GtkWindow *parent; - /* If the filter is the partially the group name, we show the - * whole group. - */ - if (strstr (str, filter)) { - g_free (str); - return TRUE; - } + text = g_strdup_printf (_("Do you really want to remove the group '%s'?"), group); + parent = empathy_get_toplevel_window (GTK_WIDGET (view)); + if (contact_list_view_remove_dialog_show (parent, _("Removing group"), text)) { + EmpathyContactList *list; - /* At this point, we need to check in advance if this - * group should be shown because a contact we want to - * show exists in it. - */ - list = empathy_contact_list_store_get_list_iface (priv->store); - contacts = empathy_contact_list_get_members (list); - for (l = contacts; l && !show_group; l = l->next) { - if (!empathy_contact_is_in_group (l->data, group)) { - g_object_unref (l->data); - continue; + list = empathy_contact_list_store_get_list_iface (priv->store); + empathy_contact_list_remove_group (list, group); } - if (contact_list_view_filter_show_contact (l->data, filter)) { - show_group = TRUE; - } - g_object_unref (l->data); + g_free (text); } - g_list_free (contacts); - g_free (str); - return show_group; + g_free (group); } -static gboolean -contact_list_view_filter_func (GtkTreeModel *model, - GtkTreeIter *iter, - EmpathyContactListView *view) +GtkWidget * +empathy_contact_list_view_get_group_menu (EmpathyContactListView *view) { - EmpathyContactListViewPriv *priv; - gboolean is_group; - gboolean is_separator; - gboolean visible = TRUE; + EmpathyContactListViewPriv *priv = GET_PRIV (view); + gchar *group; + GtkWidget *menu; + GtkWidget *item; + GtkWidget *image; - priv = GET_PRIV (view); + g_return_val_if_fail (EMPATHY_IS_CONTACT_LIST_VIEW (view), NULL); - if (G_STR_EMPTY (priv->filter_text)) { - return TRUE; + if (!(priv->list_features & (EMPATHY_CONTACT_LIST_FEATURE_GROUPS_RENAME | + EMPATHY_CONTACT_LIST_FEATURE_GROUPS_REMOVE))) { + return NULL; } - - /* Check to see if iter matches any group names */ - gtk_tree_model_get (model, iter, - COL_IS_GROUP, &is_group, - COL_IS_SEPARATOR, &is_separator, - -1); - - if (is_group) { - gchar *name; - gtk_tree_model_get (model, iter, COL_NAME, &name, -1); - visible &= contact_list_view_filter_show_group (view, - name, - priv->filter_text); - g_free (name); - } else if (is_separator) { - /* Do nothing here */ - } else { - EmpathyContact *contact; + group = empathy_contact_list_view_get_selected_group (view); + if (!group) { + return NULL; + } - /* Check contact id */ - gtk_tree_model_get (model, iter, COL_CONTACT, &contact, -1); - visible &= contact_list_view_filter_show_contact (contact, - priv->filter_text); - g_object_unref (contact); + menu = gtk_menu_new (); + + /* FIXME: Not implemented yet + if (priv->features & EMPATHY_CONTACT_LIST_FEATURE_GROUPS_RENAME) { + item = gtk_menu_item_new_with_mnemonic (_("Re_name")); + gtk_menu_shell_append (GTK_MENU_SHELL (menu), item); + gtk_widget_show (item); + g_signal_connect (item, "activate", + G_CALLBACK (contact_list_view_group_rename_activate_cb), + view); + }*/ + + if (priv->list_features & EMPATHY_CONTACT_LIST_FEATURE_GROUPS_REMOVE) { + item = gtk_image_menu_item_new_with_mnemonic (_("_Remove")); + image = gtk_image_new_from_icon_name (GTK_STOCK_REMOVE, + GTK_ICON_SIZE_MENU); + gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image); + gtk_menu_shell_append (GTK_MENU_SHELL (menu), item); + gtk_widget_show (item); + g_signal_connect (item, "activate", + G_CALLBACK (contact_list_view_group_remove_activate_cb), + view); } - return visible; + g_free (group); + + return menu; } static void -contact_list_view_action_cb (GtkAction *action, - EmpathyContactListView *view) +contact_list_view_remove_activate_cb (GtkMenuItem *menuitem, + EmpathyContactListView *view) { - EmpathyContactListViewPriv *priv; + EmpathyContactListViewPriv *priv = GET_PRIV (view); EmpathyContact *contact; - const gchar *name; - gchar *group; - GtkWindow *parent; + + contact = empathy_contact_list_view_get_selected (view); - priv = GET_PRIV (view); + if (contact) { + gchar *text; + GtkWindow *parent; + + parent = empathy_get_toplevel_window (GTK_WIDGET (view)); + text = g_strdup_printf (_("Do you really want to remove the contact '%s'?"), + empathy_contact_get_name (contact)); + if (contact_list_view_remove_dialog_show (parent, _("Removing contact"), text)) { + EmpathyContactList *list; + + list = empathy_contact_list_store_get_list_iface (priv->store); + empathy_contact_list_remove (list, contact, + _("Sorry, I don't want you in my contact list anymore.")); + } - name = gtk_action_get_name (action); - if (!name) { - return; + g_free (text); + g_object_unref (contact); } +} + +GtkWidget * +empathy_contact_list_view_get_contact_menu (EmpathyContactListView *view) +{ + EmpathyContactListViewPriv *priv = GET_PRIV (view); + EmpathyContact *contact; + GtkWidget *menu; + GtkWidget *item; + GtkWidget *image; - empathy_debug (DEBUG_DOMAIN, "Action:'%s' activated", name); + g_return_val_if_fail (EMPATHY_IS_CONTACT_LIST_VIEW (view), NULL); contact = empathy_contact_list_view_get_selected (view); - group = empathy_contact_list_view_get_selected_group (view); - parent = empathy_get_toplevel_window (GTK_WIDGET (view)); - - if (contact && strcmp (name, "Chat") == 0) { - contact_list_view_action_activated (view, contact); - } - else if (contact && strcmp (name, "Information") == 0) { - empathy_contact_information_dialog_show (contact, parent, FALSE); - } - else if (contact && strcmp (name, "Edit") == 0) { - empathy_contact_information_dialog_show (contact, parent, TRUE); + if (!contact) { + return NULL; } - else if (contact && strcmp (name, "Remove") == 0) { - /* FIXME: Ask for confirmation */ - EmpathyContactList *list; - list = empathy_contact_list_store_get_list_iface (priv->store); - empathy_contact_list_remove (list, contact, - _("Sorry, I don't want you in my contact list anymore.")); - } - else if (contact && strcmp (name, "Invite") == 0) { - } - else if (contact && strcmp (name, "SendFile") == 0) { - } - else if (contact && strcmp (name, "Log") == 0) { - empathy_log_window_show (empathy_contact_get_account (contact), - empathy_contact_get_id (contact), - FALSE, - parent); + menu = empathy_contact_menu_new (contact, priv->contact_features); + + if (!(priv->list_features & EMPATHY_CONTACT_LIST_FEATURE_CONTACT_REMOVE)) { + g_object_unref (contact); + return menu; } - else if (group && strcmp (name, "Rename") == 0) { + + if (menu) { + /* Separator */ + item = gtk_separator_menu_item_new (); + gtk_menu_shell_append (GTK_MENU_SHELL (menu), item); + gtk_widget_show (item); + } else { + menu = gtk_menu_new (); } - g_free (group); - if (contact) { - g_object_unref (contact); + /* Remove contact */ + if (priv->list_features & EMPATHY_CONTACT_LIST_FEATURE_CONTACT_REMOVE) { + item = gtk_image_menu_item_new_with_mnemonic (_("_Remove")); + image = gtk_image_new_from_icon_name (GTK_STOCK_REMOVE, + GTK_ICON_SIZE_MENU); + gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image); + gtk_menu_shell_append (GTK_MENU_SHELL (menu), item); + gtk_widget_show (item); + g_signal_connect (item, "activate", + G_CALLBACK (contact_list_view_remove_activate_cb), + view); } -} -static void -contact_list_view_action_activated (EmpathyContactListView *view, - EmpathyContact *contact) -{ - MissionControl *mc; - - mc = empathy_mission_control_new (); - mission_control_request_channel (mc, - empathy_contact_get_account (contact), - TP_IFACE_CHANNEL_TYPE_TEXT, - empathy_contact_get_handle (contact), - TP_HANDLE_TYPE_CONTACT, - NULL, NULL); - g_object_unref (mc); + g_object_unref (contact); + + return menu; }