aboutsummaryrefslogtreecommitdiffstats
path: root/composer
diff options
context:
space:
mode:
Diffstat (limited to 'composer')
-rw-r--r--composer/e-composer-private.c75
-rw-r--r--composer/e-composer-private.h3
-rw-r--r--composer/e-msg-composer.c15
3 files changed, 92 insertions, 1 deletions
diff --git a/composer/e-composer-private.c b/composer/e-composer-private.c
index 816ea10b16..cb926b93ee 100644
--- a/composer/e-composer-private.c
+++ b/composer/e-composer-private.c
@@ -414,7 +414,8 @@ e_composer_private_constructed (EMsgComposer *composer)
container = priv->gallery_scrolled_window;
- gallery_path = e_shell_settings_get_string (shell_settings, "composer-gallery-path");
+ gallery_path = e_shell_settings_get_string (
+ shell_settings, "composer-gallery-path");
widget = e_picture_gallery_new (gallery_path);
gtk_container_add (GTK_CONTAINER (container), widget);
priv->gallery_icon_view = g_object_ref (widget);
@@ -813,3 +814,75 @@ e_composer_paste_uris (EMsgComposer *composer,
return TRUE;
}
+
+gboolean
+e_composer_selection_is_image_uris (EMsgComposer *composer,
+ GtkSelectionData *selection)
+{
+ gboolean all_image_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 == NULL)
+ return FALSE;
+
+ for (ii = 0; uris[ii] != NULL; ii++) {
+ GFile *file;
+ GFileInfo *file_info;
+ GdkPixbufLoader *loader;
+ const gchar *attribute;
+ const gchar *content_type;
+ gchar *mime_type = NULL;
+
+ file = g_file_new_for_uri (uris[ii]);
+ attribute = G_FILE_ATTRIBUTE_STANDARD_FAST_CONTENT_TYPE;
+
+ /* XXX This blocks, but we're requesting the fast content
+ * type (which only inspects filenames), so hopefully
+ * it won't be noticeable. Also, this is best effort
+ * so we don't really care if it fails. */
+ file_info = g_file_query_info (
+ file, attribute, G_FILE_QUERY_INFO_NONE, NULL, NULL);
+
+ if (file_info == NULL) {
+ g_object_unref (file);
+ all_image_uris = FALSE;
+ break;
+ }
+
+ content_type = g_file_info_get_attribute_string (
+ file_info, attribute);
+ mime_type = g_content_type_get_mime_type (content_type);
+
+ g_object_unref (file_info);
+ g_object_unref (file);
+
+ if (mime_type == NULL) {
+ all_image_uris = FALSE;
+ break;
+ }
+
+ /* Easy way to determine if a MIME type is a supported
+ * image format: try creating a GdkPixbufLoader for it. */
+ loader = gdk_pixbuf_loader_new_with_mime_type (mime_type, NULL);
+
+ g_free (mime_type);
+
+ if (loader == NULL) {
+ all_image_uris = FALSE;
+ break;
+ }
+
+ gdk_pixbuf_loader_close (loader, NULL);
+ g_object_unref (loader);
+ }
+
+ g_strfreev (uris);
+
+ return all_image_uris;
+}
diff --git a/composer/e-composer-private.h b/composer/e-composer-private.h
index 20a39963ae..5cf503e735 100644
--- a/composer/e-composer-private.h
+++ b/composer/e-composer-private.h
@@ -169,6 +169,9 @@ gboolean e_composer_paste_text (EMsgComposer *composer,
GtkClipboard *clipboard);
gboolean e_composer_paste_uris (EMsgComposer *composer,
GtkClipboard *clipboard);
+gboolean e_composer_selection_is_image_uris
+ (EMsgComposer *composer,
+ GtkSelectionData *selection);
G_END_DECLS
diff --git a/composer/e-msg-composer.c b/composer/e-msg-composer.c
index 7439007ae4..d3df63aad0 100644
--- a/composer/e-msg-composer.c
+++ b/composer/e-msg-composer.c
@@ -1830,6 +1830,21 @@ msg_composer_drag_data_received_cb (GtkWidget *widget,
{
EAttachmentView *view;
+ /* HTML mode has a few special cases for drops... */
+ if (gtkhtml_editor_get_html_mode (GTKHTML_EDITOR (composer))) {
+
+ /* If we're receiving an image, we want the image to be
+ * inserted in the message body. Let GtkHtml handle it. */
+ if (gtk_selection_data_targets_include_image (selection, TRUE))
+ return;
+
+ /* If we're receiving URIs and -all- the URIs point to
+ * image files, we want the image(s) to be inserted in
+ * the message body. Let GtkHtml handle it. */
+ if (e_composer_selection_is_image_uris (composer, selection))
+ return;
+ }
+
view = e_msg_composer_get_attachment_view (composer);
/* Forward the data to the attachment view. Note that calling