diff options
author | Shaun McCance <Shaun McCance> | 2009-09-15 10:15:06 +0800 |
---|---|---|
committer | Shaun McCance <shaunm@gnome.org> | 2009-11-25 02:05:31 +0800 |
commit | 2e2fdd45ae2d7fac58c9cc40b48c84ffc6b3f48e (patch) | |
tree | acd72f1059e152155f1ae3b30f8aa610c3233cfb /src | |
parent | 783fe36cb4d096a9ed17078e8ddc36b3542b638b (diff) | |
download | gsoc2013-empathy-2e2fdd45ae2d7fac58c9cc40b48c84ffc6b3f48e.tar gsoc2013-empathy-2e2fdd45ae2d7fac58c9cc40b48c84ffc6b3f48e.tar.gz gsoc2013-empathy-2e2fdd45ae2d7fac58c9cc40b48c84ffc6b3f48e.tar.bz2 gsoc2013-empathy-2e2fdd45ae2d7fac58c9cc40b48c84ffc6b3f48e.tar.lz gsoc2013-empathy-2e2fdd45ae2d7fac58c9cc40b48c84ffc6b3f48e.tar.xz gsoc2013-empathy-2e2fdd45ae2d7fac58c9cc40b48c84ffc6b3f48e.tar.zst gsoc2013-empathy-2e2fdd45ae2d7fac58c9cc40b48c84ffc6b3f48e.zip |
Implementing drag and drop file sending on chat windows
Diffstat (limited to 'src')
-rw-r--r-- | src/empathy-chat-window.c | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/src/empathy-chat-window.c b/src/empathy-chat-window.c index 278c8f044..15ab92ce6 100644 --- a/src/empathy-chat-window.c +++ b/src/empathy-chat-window.c @@ -106,6 +106,7 @@ static const guint tab_accel_keys[] = { typedef enum { DND_DRAG_TYPE_CONTACT_ID, + DND_DRAG_TYPE_URI_LIST, DND_DRAG_TYPE_TAB } DndDragType; @@ -114,6 +115,10 @@ static const GtkTargetEntry drag_types_dest[] = { { "GTK_NOTEBOOK_TAB", GTK_TARGET_SAME_APP, DND_DRAG_TYPE_TAB }, }; +static const GtkTargetEntry drag_types_uri_dest[] = { + { "text/uri-list", 0, DND_DRAG_TYPE_URI_LIST }, +}; + static void chat_window_update (EmpathyChatWindow *window); G_DEFINE_TYPE (EmpathyChatWindow, empathy_chat_window, G_TYPE_OBJECT); @@ -1403,6 +1408,40 @@ chat_window_drag_data_received (GtkWidget *widget, */ gtk_drag_finish (context, TRUE, FALSE, time_); } + else if (info == DND_DRAG_TYPE_URI_LIST) { + EmpathyChatWindowPriv *priv; + EmpathyContact *contact; + const gchar *data; + GFile *file; + gchar *nl; + gchar *uri; + + /* Only handle a single file for new. It would be wicked cool to be + able to do multiple files, offering to zip them or whatever like + nautilus-sendto does. Note that text/uri-list is defined to have + each line terminated by \r\n, but we can be tolerant of applications + that only use \n or don't terminate single-line entries. + */ + data = (const gchar*) gtk_selection_data_get_data (selection); + nl = strstr (data, "\r\n"); + if (!nl) { + nl = strchr (data, '\n'); + } + if (nl) { + uri = g_strndup (data, nl - data); + file = g_file_new_for_uri (uri); + g_free (uri); + } + else { + file = g_file_new_for_uri (data); + } + + priv = GET_PRIV (window); + contact = empathy_chat_get_remote_contact (priv->current_chat); + empathy_send_file (contact, file); + + g_object_unref (file); + } else if (info == DND_DRAG_TYPE_TAB) { EmpathyChat **chat; EmpathyChatWindow *old_window = NULL; @@ -1617,6 +1656,11 @@ empathy_chat_window_init (EmpathyChatWindow *window) drag_types_dest, G_N_ELEMENTS (drag_types_dest), GDK_ACTION_MOVE); + gtk_drag_dest_set (GTK_WIDGET (priv->notebook), + GTK_DEST_DEFAULT_ALL, + drag_types_uri_dest, + G_N_ELEMENTS (drag_types_uri_dest), + GDK_ACTION_COPY); g_signal_connect (priv->notebook, "drag-data-received", |