[evolution/wip/webkit-composer: 370/372] Add support for Drag&Drop of base64 encoded images



commit 22a497906ff0b2612362cfab147c0ccc9c8d5a84
Author: Tomas Popela <tpopela redhat com>
Date:   Thu Feb 6 10:30:08 2014 +0100

    Add support for Drag&Drop of base64 encoded images
    
    These images can be found in the attachments below the received message.

 composer/e-composer-private.c |   31 ++++++++++++++++++++++++++++++-
 composer/e-composer-private.h |    3 +++
 composer/e-msg-composer.c     |   20 +++++++++++++++++++-
 3 files changed, 52 insertions(+), 2 deletions(-)
---
diff --git a/composer/e-composer-private.c b/composer/e-composer-private.c
index 172321c..a9246b3 100644
--- a/composer/e-composer-private.c
+++ b/composer/e-composer-private.c
@@ -633,6 +633,35 @@ e_composer_paste_uris (EMsgComposer *composer,
 }
 
 gboolean
+e_composer_selection_is_base64_uris (EMsgComposer *composer,
+                                     GtkSelectionData *selection)
+{
+       gboolean all_base64_uris = TRUE;
+       gchar **uris;
+       guint ii;
+
+       g_return_val_if_fail (E_IS_MSG_COMPOSER (composer), FALSE);
+       g_return_val_if_fail (selection != NULL, FALSE);
+
+       uris = gtk_selection_data_get_uris (selection);
+
+       if (!uris)
+               return FALSE;
+
+       for (ii = 0; uris[ii] != NULL; ii++) {
+               if (!((g_str_has_prefix (uris[ii], "data:") || strstr (uris[ii], ";data:"))
+                   && strstr (uris[ii], ";base64,"))) {
+                       all_base64_uris = FALSE;
+                       break;
+               }
+       }
+
+       g_strfreev (uris);
+
+       return all_base64_uris;
+}
+
+gboolean
 e_composer_selection_is_image_uris (EMsgComposer *composer,
                                     GtkSelectionData *selection)
 {
@@ -645,7 +674,7 @@ e_composer_selection_is_image_uris (EMsgComposer *composer,
 
        uris = gtk_selection_data_get_uris (selection);
 
-       if (uris == NULL)
+       if (!uris)
                return FALSE;
 
        for (ii = 0; uris[ii] != NULL; ii++) {
diff --git a/composer/e-composer-private.h b/composer/e-composer-private.h
index 5cd405f..9216133 100644
--- a/composer/e-composer-private.h
+++ b/composer/e-composer-private.h
@@ -116,6 +116,9 @@ gboolean    e_composer_paste_text           (EMsgComposer *composer,
                                                 GtkClipboard *clipboard);
 gboolean       e_composer_paste_uris           (EMsgComposer *composer,
                                                 GtkClipboard *clipboard);
+gboolean       e_composer_selection_is_base64_uris
+                                               (EMsgComposer *composer,
+                                                GtkSelectionData *selection);
 gboolean       e_composer_selection_is_image_uris
                                                (EMsgComposer *composer,
                                                 GtkSelectionData *selection);
diff --git a/composer/e-msg-composer.c b/composer/e-msg-composer.c
index 93d766f..f261179 100644
--- a/composer/e-msg-composer.c
+++ b/composer/e-msg-composer.c
@@ -1836,7 +1836,25 @@ msg_composer_drag_data_received_cb (GtkWidget *widget,
                        } while (list_len);
                }
 
-               /* FIXME CID images */
+               if (e_composer_selection_is_base64_uris (composer, selection)) {
+                       const guchar *data;
+                       gint length;
+                       gint list_len, len;
+                       gchar *uri;
+
+                       data = gtk_selection_data_get_data (selection);
+                       length = gtk_selection_data_get_length (selection);
+
+                       if (!data || length < 0)
+                               return;
+
+                       list_len = length;
+                       do {
+                               uri = next_uri ((guchar **) &data, &len, &list_len);
+
+                               e_editor_selection_insert_image (editor_selection, uri);
+                       } while (list_len);
+               }
        } else {
                view = e_msg_composer_get_attachment_view (composer);
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]