aboutsummaryrefslogtreecommitdiffstats
path: root/composer/e-composer-private.c
diff options
context:
space:
mode:
authorMatthew Barnes <mbarnes@redhat.com>2011-02-03 11:48:43 +0800
committerMatthew Barnes <mbarnes@redhat.com>2011-02-03 11:48:43 +0800
commit93a51af22567bdddf3978716791f0be2e1dd2656 (patch)
tree80984c2c3a564bca5ba1ab95497dd80b3fd81f9c /composer/e-composer-private.c
parentc49e3012a029bb78dc759a9fc8dfc1103a36d976 (diff)
downloadgsoc2013-evolution-93a51af22567bdddf3978716791f0be2e1dd2656.tar
gsoc2013-evolution-93a51af22567bdddf3978716791f0be2e1dd2656.tar.gz
gsoc2013-evolution-93a51af22567bdddf3978716791f0be2e1dd2656.tar.bz2
gsoc2013-evolution-93a51af22567bdddf3978716791f0be2e1dd2656.tar.lz
gsoc2013-evolution-93a51af22567bdddf3978716791f0be2e1dd2656.tar.xz
gsoc2013-evolution-93a51af22567bdddf3978716791f0be2e1dd2656.tar.zst
gsoc2013-evolution-93a51af22567bdddf3978716791f0be2e1dd2656.zip
Fix image dropping in composer while in HTML mode.
Dragging image data or an image URI to the message body while in HTML mode should insert the image inline, not attach it. Without this the Picture Gallery feature is pointless.
Diffstat (limited to 'composer/e-composer-private.c')
-rw-r--r--composer/e-composer-private.c75
1 files changed, 74 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;
+}