2005-01-17 [colin] 0.9.13cvs36.2
authorColin Leroy <colin@colino.net>
Mon, 17 Jan 2005 16:52:39 +0000 (16:52 +0000)
committerColin Leroy <colin@colino.net>
Mon, 17 Jan 2005 16:52:39 +0000 (16:52 +0000)
* src/compose.c
Fix DnD inserting twice. While at it,
add DnD support for text/plain in the
body, and add support in the headers.

ChangeLog-gtk2.claws
PATCHSETS
configure.ac
src/compose.c

index c9267f29416371c2c45a5085de144e24998e32ce..856147e683a41f93ed3877ee4d1588bedc5345a1 100644 (file)
@@ -1,3 +1,10 @@
+2005-01-17 [colin]     0.9.13cvs36.2
+
+       * src/compose.c
+               Fix DnD inserting twice. While at it,
+               add DnD support for text/plain in the
+               body, and add support in the headers.
+
 2005-01-16 [colin]     0.9.13cvs36.1
 
        * ChangeLog
index 9f044ed0863fb9843a113874a6e64c5a05afa370..30e5e8a317114b561267d025981116610ebdfdf6 100644 (file)
--- a/PATCHSETS
+++ b/PATCHSETS
 ( cvs diff -u -r 1.12.2.4 -r 1.12.2.5 src/html.c; cvs diff -u -r 1.16.2.12 -r 1.16.2.13 src/msgcache.c; ) > 0.9.13cvs33.1.patchset
 ( cvs diff -u -r 1.30.2.7 -r 1.30.2.8 src/prefs_toolbar.c; ) > 0.9.13cvs33.2.patchset
 ( cvs diff -u -r 1.396.2.19 -r 1.396.2.20 ChangeLog; cvs diff -u -r 1.391.2.19 -r 1.391.2.20 ChangeLog.jp; cvs diff -u -r 1.2504.2.42 -r 1.2504.2.43 ChangeLog.claws; ) > 0.9.13cvs36.1.patchset
+( cvs diff -u -r 1.382.2.85 -r 1.382.2.86 src/compose.c; ) > 0.9.13cvs36.2.patchset
index 62544efdbce945a4b3b70f21750789def7f46f66..28b7e6e5e9e8621fec914e0f2efb01e33043beab 100644 (file)
@@ -13,7 +13,7 @@ INTERFACE_AGE=0
 BINARY_AGE=0
 EXTRA_VERSION=36
 EXTRA_RELEASE=
-EXTRA_GTK2_VERSION=.1
+EXTRA_GTK2_VERSION=.2
 
 if test \( $EXTRA_VERSION -eq 0 \) -o \( "x$EXTRA_RELEASE" != "x" \); then
     VERSION=${MAJOR_VERSION}.${MINOR_VERSION}.${MICRO_VERSION}${EXTRA_RELEASE}${EXTRA_GTK2_VERSION}
index 3bfee2f2fee62814abbb9cad2fcdacdbdbae82bf..47c5ea8e08c8cd78d2dfa824b4c83312eada7c4d 100644 (file)
@@ -452,7 +452,19 @@ static void compose_insert_drag_received_cb (GtkWidget             *widget,
                                             guint               info,
                                             guint               time,
                                             gpointer            user_data);
+static void compose_header_drag_received_cb (GtkWidget         *widget,
+                                            GdkDragContext     *drag_context,
+                                            gint                x,
+                                            gint                y,
+                                            GtkSelectionData   *data,
+                                            guint               info,
+                                            guint               time,
+                                            gpointer            user_data);
 
+static gboolean compose_drag_drop          (GtkWidget *widget,
+                                            GdkDragContext *drag_context,
+                                            gint x, gint y,
+                                            guint time, gpointer user_data);
 #if 0
 static void to_activated               (GtkWidget      *widget,
                                         Compose        *compose);
@@ -666,7 +678,9 @@ static GtkItemFactoryEntry compose_entries[] =
 
 static GtkTargetEntry compose_mime_types[] =
 {
-       {"text/uri-list", 0, 0}
+       {"text/uri-list", 0, 0},
+       {"text/plain", 0, 0},
+       {"STRING", 0, 0}
 };
 
 static gboolean compose_put_existing_to_front(MsgInfo *info)
@@ -4445,6 +4459,18 @@ static void compose_create_header_entry(Compose *compose)
                         G_CALLBACK(compose_grab_focus_before_cb), compose);
        g_signal_connect_after(G_OBJECT(entry), "grab_focus",
                         G_CALLBACK(compose_grab_focus_cb), compose);
+                        
+       /* email dnd */
+       gtk_drag_dest_set(entry, GTK_DEST_DEFAULT_ALL, compose_mime_types, 
+                         sizeof(compose_mime_types)/sizeof(compose_mime_types[0]),
+                         GDK_ACTION_COPY | GDK_ACTION_MOVE);
+       g_signal_connect(G_OBJECT(entry), "drag_data_received",
+                        G_CALLBACK(compose_header_drag_received_cb),
+                        entry);
+       g_signal_connect(G_OBJECT(entry), "drag-drop",
+                        G_CALLBACK(compose_drag_drop),
+                        compose);
+       
        address_completion_register_entry(GTK_ENTRY(entry));
 
         headerentry->compose = compose;
@@ -4662,11 +4688,15 @@ GtkWidget *compose_create_attach(Compose *compose)
 
        /* drag and drop */
        gtk_drag_dest_set(attach_clist,
-                         GTK_DEST_DEFAULT_ALL, compose_mime_types, 1,
+                         GTK_DEST_DEFAULT_ALL, compose_mime_types, 
+                         sizeof(compose_mime_types)/sizeof(compose_mime_types[0]),
                          GDK_ACTION_COPY | GDK_ACTION_MOVE);
        g_signal_connect(G_OBJECT(attach_clist), "drag_data_received",
                         G_CALLBACK(compose_attach_drag_received_cb),
                         compose);
+       g_signal_connect(G_OBJECT(attach_clist), "drag-drop",
+                        G_CALLBACK(compose_drag_drop),
+                        compose);
 
        compose->attach_scrwin = attach_scrwin;
        compose->attach_clist  = attach_clist;
@@ -4940,11 +4970,15 @@ static Compose *compose_create(PrefsAccount *account, ComposeMode mode)
                         G_CALLBACK(text_inserted), compose);
 
        /* drag and drop */
-       gtk_drag_dest_set(text, GTK_DEST_DEFAULT_ALL, compose_mime_types, 1,
+       gtk_drag_dest_set(text, GTK_DEST_DEFAULT_ALL, compose_mime_types, 
+                         sizeof(compose_mime_types)/sizeof(compose_mime_types[0]),
                          GDK_ACTION_COPY | GDK_ACTION_MOVE);
        g_signal_connect(G_OBJECT(text), "drag_data_received",
                         G_CALLBACK(compose_insert_drag_received_cb),
                         compose);
+       g_signal_connect(G_OBJECT(text), "drag-drop",
+                        G_CALLBACK(compose_drag_drop),
+                        compose);
        gtk_widget_show_all(vbox);
 
        /* pane between attach clist and text */
@@ -7132,15 +7166,27 @@ static void compose_attach_drag_received_cb (GtkWidget          *widget,
 {
        Compose *compose = (Compose *)user_data;
        GList *list, *tmp;
+       
+       if (gdk_atom_name(data->type) && !strcmp(gdk_atom_name(data->type), "text/uri-list")) {
+               list = uri_list_extract_filenames((const gchar *)data->data);
+               for (tmp = list; tmp != NULL; tmp = tmp->next)
+                       compose_attach_append
+                               (compose, (const gchar *)tmp->data,
+                                (const gchar *)tmp->data, NULL);
+               if (list) compose_changed_cb(NULL, compose);
+               list_free_strings(list);
+               g_list_free(list);
+       }
+}
 
-       list = uri_list_extract_filenames((const gchar *)data->data);
-       for (tmp = list; tmp != NULL; tmp = tmp->next)
-               compose_attach_append
-                       (compose, (const gchar *)tmp->data,
-                        (const gchar *)tmp->data, NULL);
-       if (list) compose_changed_cb(NULL, compose);
-       list_free_strings(list);
-       g_list_free(list);
+static gboolean compose_drag_drop(GtkWidget *widget,
+                                 GdkDragContext *drag_context,
+                                 gint x, gint y,
+                                 guint time, gpointer user_data)
+{
+       /* not handling this signal makes compose_insert_drag_received_cb
+        * called twice */
+       return TRUE;                                     
 }
 
 static void compose_insert_drag_received_cb (GtkWidget         *widget,
@@ -7155,11 +7201,56 @@ static void compose_insert_drag_received_cb (GtkWidget          *widget,
        Compose *compose = (Compose *)user_data;
        GList *list, *tmp;
 
-       list = uri_list_extract_filenames((const gchar *)data->data);
-       for (tmp = list; tmp != NULL; tmp = tmp->next)
-               compose_insert_file(compose, (const gchar *)tmp->data);
-       list_free_strings(list);
-       g_list_free(list);
+       /* strangely, testing data->type == gdk_atom_intern("text/uri-list", TRUE)
+        * does not work */
+       if (gdk_atom_name(data->type) && !strcmp(gdk_atom_name(data->type), "text/uri-list")) {
+               list = uri_list_extract_filenames((const gchar *)data->data);
+               for (tmp = list; tmp != NULL; tmp = tmp->next) {
+                               compose_insert_file(compose, (const gchar *)tmp->data);
+               }
+               list_free_strings(list);
+               g_list_free(list);
+               gtk_drag_finish(drag_context, TRUE, FALSE, time);
+               return;
+       } else {
+               gchar *tmpfile = get_tmp_file();
+               str_write_to_file((const gchar *)data->data, tmpfile);
+               compose_insert_file(compose, tmpfile);
+               unlink(tmpfile);
+               g_free(tmpfile);
+               gtk_drag_finish(drag_context, TRUE, FALSE, time);
+               return;
+       }
+       gtk_drag_finish(drag_context, TRUE, FALSE, time);
+}
+
+static void compose_header_drag_received_cb (GtkWidget         *widget,
+                                            GdkDragContext     *drag_context,
+                                            gint                x,
+                                            gint                y,
+                                            GtkSelectionData   *data,
+                                            guint               info,
+                                            guint               time,
+                                            gpointer            user_data)
+{
+       GtkEditable *entry = (GtkEditable *)user_data;
+       gchar *email = (gchar *)data->data;
+
+       /* strangely, testing data->type == gdk_atom_intern("text/plain", TRUE)
+        * does not work */
+
+       if (!strncmp(email, "mailto:", strlen("mailto:"))) {
+               gchar decoded[strlen(email)];
+               int start = 0;
+
+               email += strlen("mailto:");
+               decode_uri(decoded, email); /* will fit */
+               gtk_editable_delete_text(entry, 0, -1);
+               gtk_editable_insert_text(entry, decoded, strlen(decoded), &start);
+               gtk_drag_finish(drag_context, TRUE, FALSE, time);
+               return;
+       }
+       gtk_drag_finish(drag_context, TRUE, FALSE, time);
 }
 
 #if 0 /* NEW COMPOSE GUI */