]> git.0d.be Git - empathy.git/commitdiff
Utilitiy function to send files from a URI list, for dnd implementations
authorShaun McCance <Shaun McCance>
Mon, 5 Oct 2009 19:22:32 +0000 (14:22 -0500)
committerShaun McCance <shaunm@gnome.org>
Tue, 24 Nov 2009 21:14:51 +0000 (15:14 -0600)
libempathy-gtk/empathy-chat.c
libempathy-gtk/empathy-contact-list-view.c
libempathy-gtk/empathy-ui-utils.c
libempathy-gtk/empathy-ui-utils.h
src/empathy-chat-window.c

index c83649a047df6f76721adcfee91d0ad493d1fa26..52806e07c57a2cf6cdfedcaf8a593570fb4ff026 100644 (file)
@@ -2007,6 +2007,11 @@ chat_create_ui (EmpathyChat *chat)
 
        /* Add message view. */
        chat->view = empathy_theme_manager_create_view (empathy_theme_manager_get ());
+       /* If this is a GtkTextView, it's set as a drag destination for text/plain
+          and other types, even though it's non-editable and doesn't accept any
+          drags.  This steals drag motion for anything inside the scrollbars,
+          making drag destinations on chat windows far less useful.
+        */
        gtk_drag_dest_unset (GTK_WIDGET (chat->view));
        g_signal_connect (chat->view, "focus_in_event",
                          G_CALLBACK (chat_text_view_focus_in_event_cb),
index 24793b457ac903326d4522ba1d9e908db3e38a31..3e1464654c9696333fc1fd8689b8815d145946d2 100644 (file)
@@ -332,9 +332,6 @@ contact_list_view_file_drag_received (GtkWidget         *view,
 {
        GtkTreeIter     iter;
        const gchar    *sel_data;
-       const gchar    *nl;
-       gchar          *uri;
-       GFile          *file;
        EmpathyContact *contact;
 
        sel_data = (const gchar *) gtk_selection_data_get_data (selection);
@@ -347,22 +344,9 @@ contact_list_view_file_drag_received (GtkWidget         *view,
                return FALSE;
        }
 
-       nl = strstr (sel_data, "\r\n");
-       if (!nl) {
-               nl = strchr (sel_data, '\n');
-       }
-       if (nl) {
-               uri = g_strndup (sel_data, nl - sel_data);
-               file = g_file_new_for_uri (uri);
-               g_free (uri);
-       }
-       else {
-               file = g_file_new_for_uri (sel_data);
-       }
-
-       empathy_send_file (contact, file);
+       empathy_send_file_from_uri_list (contact, sel_data);
 
-       g_object_unref (file);
+       g_object_unref (contact);
 
        return TRUE;
 }
index 411a7664031f264ac560fb2727aa729b68b2f270..9f4182ce1c79c513d8cb7fd6046f6b3386a10007 100644 (file)
@@ -1473,6 +1473,36 @@ empathy_send_file (EmpathyContact *contact, GFile *file)
        g_object_unref (factory);
 }
 
+void
+empathy_send_file_from_uri_list (EmpathyContact *contact, const gchar *uri_list)
+{
+       const gchar *nl;
+       GFile *file;
+
+       /* Only handle a single file for now.  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.
+       */
+       nl = strstr (uri_list, "\r\n");
+       if (!nl) {
+               nl = strchr (uri_list, '\n');
+       }
+       if (nl) {
+               gchar *uri = g_strndup (uri_list, nl - uri_list);
+               file = g_file_new_for_uri (uri);
+               g_free (uri);
+       }
+       else {
+               file = g_file_new_for_uri (uri_list);
+       }
+
+       empathy_send_file (contact, file);
+
+       g_object_unref (file);
+}
+
 static void
 file_manager_send_file_response_cb (GtkDialog      *widget,
                                    gint            response_id,
index 0f453ddbce3e39c0e28ad6d84c33c467ae36189a..e0c0904b02904469153ea727670d7db8583e7479 100644 (file)
@@ -112,6 +112,8 @@ GtkWidget * empathy_link_button_new                     (const gchar      *url,
 
 void        empathy_send_file                           (EmpathyContact   *contact,
                                                         GFile            *file);
+void        empathy_send_file_from_uri_list             (EmpathyContact   *contact,
+                                                        const gchar      *uri_list);
 void        empathy_send_file_with_file_chooser         (EmpathyContact   *contact);
 void        empathy_receive_file_with_file_chooser      (EmpathyFTHandler *handler);
 
index a58d4f65c9905ada1a15a14a288bd8c1180b69b6..2c6acf75e1aaf6c0a493b7cbe1e7176e3b99c343 100644 (file)
@@ -1438,9 +1438,6 @@ chat_window_drag_data_received (GtkWidget        *widget,
                EmpathyChatWindowPriv *priv;
                EmpathyContact *contact;
                const gchar *data;
-               const gchar *nl;
-               gchar *uri;
-               GFile *file;
 
                priv = GET_PRIV (window);
                contact = empathy_chat_get_remote_contact (priv->current_chat);
@@ -1450,29 +1447,9 @@ chat_window_drag_data_received (GtkWidget        *widget,
                        return;
                }
 
-               /* 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);
-               }
-
-               empathy_send_file (contact, file);
+               data = (const gchar *) gtk_selection_data_get_data (selection);
+               empathy_send_file_from_uri_list (contact, data);
 
-               g_object_unref (file);
                gtk_drag_finish (context, TRUE, FALSE, time);
        }
        else if (info == DND_DRAG_TYPE_TAB) {