From 9be0890e445a1d8bc28ceeea3bea1703f14cd5eb Mon Sep 17 00:00:00 2001 From: Guillaume Desmottes Date: Fri, 17 Feb 2012 15:13:28 +0100 Subject: chat-window: invite contacts using DnD https://bugzilla.gnome.org/show_bug.cgi?id=655101 --- src/empathy-chat-window.c | 72 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) diff --git a/src/empathy-chat-window.c b/src/empathy-chat-window.c index c841a5c26..ccf22ff01 100644 --- a/src/empathy-chat-window.c +++ b/src/empathy-chat-window.c @@ -47,6 +47,7 @@ #include #include #include +#include #include #include @@ -129,12 +130,14 @@ static const guint tab_accel_keys[] = { typedef enum { DND_DRAG_TYPE_CONTACT_ID, + DND_DRAG_TYPE_INDIVIDUAL_ID, DND_DRAG_TYPE_URI_LIST, DND_DRAG_TYPE_TAB } DndDragType; static const GtkTargetEntry drag_types_dest[] = { { "text/contact-id", 0, DND_DRAG_TYPE_CONTACT_ID }, + { "text/x-individual-id", 0, DND_DRAG_TYPE_INDIVIDUAL_ID }, { "GTK_NOTEBOOK_TAB", GTK_TARGET_SAME_APP, DND_DRAG_TYPE_TAB }, { "text/uri-list", 0, DND_DRAG_TYPE_URI_LIST }, { "text/path-list", 0, DND_DRAG_TYPE_URI_LIST }, @@ -142,6 +145,7 @@ static const GtkTargetEntry drag_types_dest[] = { static const GtkTargetEntry drag_types_dest_contact[] = { { "text/contact-id", 0, DND_DRAG_TYPE_CONTACT_ID }, + { "text/x-individual-id", 0, DND_DRAG_TYPE_INDIVIDUAL_ID }, }; static const GtkTargetEntry drag_types_dest_file[] = { @@ -1980,6 +1984,70 @@ chat_window_drag_motion (GtkWidget *widget, return FALSE; } +static void +drag_data_received_individual_id (EmpathyChatWindow *self, + GtkWidget *widget, + GdkDragContext *context, + int x, + int y, + GtkSelectionData *selection, + guint info, + guint time_) +{ + const gchar *id; + EmpathyIndividualManager *manager; + FolksIndividual *individual; + EmpathyChatWindowPriv *priv = GET_PRIV (self); + EmpathyTpChat *chat; + TpContact *tp_contact; + TpConnection *conn; + EmpathyContact *contact; + + id = (const gchar *) gtk_selection_data_get_data (selection); + + DEBUG ("DND invididual %s", id); + + if (priv->current_chat == NULL) + goto out; + + chat = empathy_chat_get_tp_chat (priv->current_chat); + if (chat == NULL) + goto out; + + if (!empathy_tp_chat_can_add_contact (chat)) { + DEBUG ("Can't invite contact to %s", + tp_proxy_get_object_path (chat)); + goto out; + } + + manager = empathy_individual_manager_dup_singleton (); + + individual = empathy_individual_manager_lookup_member (manager, id); + if (individual == NULL) { + DEBUG ("Failed to find individual %s", id); + goto out; + } + + conn = tp_channel_borrow_connection ((TpChannel *) chat); + tp_contact = empathy_get_tp_contact_for_individual (individual, conn); + if (tp_contact == NULL) { + DEBUG ("Can't find a TpContact on connection %s for %s", + tp_proxy_get_object_path (conn), id); + goto out; + } + + DEBUG ("Inviting %s to join %s", tp_contact_get_identifier (tp_contact), + tp_channel_get_identifier ((TpChannel *) chat)); + + contact = empathy_contact_dup_from_tp_contact (tp_contact); + empathy_contact_list_add (EMPATHY_CONTACT_LIST (chat), contact, NULL); + g_object_unref (contact); + +out: + gtk_drag_finish (context, TRUE, FALSE, time_); + tp_clear_object (&manager); +} + static void chat_window_drag_data_received (GtkWidget *widget, GdkDragContext *context, @@ -2060,6 +2128,10 @@ chat_window_drag_data_received (GtkWidget *widget, */ gtk_drag_finish (context, TRUE, FALSE, time_); } + else if (info == DND_DRAG_TYPE_INDIVIDUAL_ID) { + drag_data_received_individual_id (window, widget, context, x, y, + selection, info, time_); + } else if (info == DND_DRAG_TYPE_URI_LIST) { EmpathyChatWindowPriv *priv; EmpathyContact *contact; -- cgit v1.2.3