gchar *
empathy_contact_list_view_get_selected_group (EmpathyContactListView *view)
{
	EmpathyContactListViewPriv *priv;
	GtkTreeSelection          *selection;
	GtkTreeIter                iter;
	GtkTreeModel              *model;
	gboolean                   is_group;
	gchar                     *name;

	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));
	if (!gtk_tree_selection_get_selected (selection, &model, &iter)) {
		return NULL;
	}

	gtk_tree_model_get (model, &iter,
			    EMPATHY_CONTACT_LIST_STORE_COL_IS_GROUP, &is_group,
			    EMPATHY_CONTACT_LIST_STORE_COL_NAME, &name,
			    -1);

	if (!is_group) {
		g_free (name);
		return NULL;
	}

	return name;
}
GtkWidget *
empathy_contact_list_view_get_contact_menu (EmpathyContactListView *view)
{
	EmpathyContactListViewPriv *priv = GET_PRIV (view);
	EmpathyContact             *contact;
	GtkWidget                  *menu;
	GtkWidget                  *item;
	GtkWidget                  *image;

	g_return_val_if_fail (EMPATHY_IS_CONTACT_LIST_VIEW (view), NULL);

	contact = empathy_contact_list_view_get_selected (view);
	if (!contact) {
		return NULL;
	}

	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;
	}

	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 ();
	}

	/* 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);
	}

	g_object_unref (contact);

	return menu;
}
GtkWidget *
empathy_contact_list_view_get_group_menu (EmpathyContactListView *view)
{
	EmpathyContactListViewPriv *priv = GET_PRIV (view);
	gchar                      *group;
	GtkWidget                  *menu;
	GtkWidget                  *item;
	GtkWidget                  *image;

	g_return_val_if_fail (EMPATHY_IS_CONTACT_LIST_VIEW (view), NULL);

	if (!(priv->list_features & (EMPATHY_CONTACT_LIST_FEATURE_GROUPS_RENAME |
				     EMPATHY_CONTACT_LIST_FEATURE_GROUPS_REMOVE))) {
		return NULL;
	}

	group = empathy_contact_list_view_get_selected_group (view);
	if (!group) {
		return NULL;
	}

	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);
	}

	g_free (group);

	return menu;
}
static void
contact_list_view_set_list_features (EmpathyContactListView         *view,
				     EmpathyContactListFeatureFlags  features)
{
	EmpathyContactListViewPriv *priv = GET_PRIV (view);
	gboolean                    has_tooltip;

	g_return_if_fail (EMPATHY_IS_CONTACT_LIST_VIEW (view));

	priv->list_features = features;

	/* 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));

	}

	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);
}
EmpathyContact *
empathy_contact_list_view_get_selected (EmpathyContactListView *view)
{
	EmpathyContactListViewPriv *priv;
	GtkTreeSelection          *selection;
	GtkTreeIter                iter;
	GtkTreeModel              *model;
	EmpathyContact             *contact;

	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));
	if (!gtk_tree_selection_get_selected (selection, &model, &iter)) {
		return NULL;
	}

	gtk_tree_model_get (model, &iter,
			    EMPATHY_CONTACT_LIST_STORE_COL_CONTACT, &contact,
			    -1);

	return contact;
}
EmpathyContactListFlags
empathy_contact_list_view_get_flags (EmpathyContactListView *view)
{
	EmpathyContactListViewPriv *priv;
	GtkTreeSelection          *selection;
	GtkTreeIter                iter;
	GtkTreeModel              *model;
	EmpathyContactListFlags    flags;

	g_return_val_if_fail (EMPATHY_IS_CONTACT_LIST_VIEW (view), 0);

	priv = GET_PRIV (view);

	selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (view));
	if (!gtk_tree_selection_get_selected (selection, &model, &iter)) {
		return 0;
	}

	gtk_tree_model_get (model, &iter,
			    EMPATHY_CONTACT_LIST_STORE_COL_FLAGS, &flags,
			    -1);

	return flags;
}