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
committerRodrigo Moya <rodrigo@gnome-db.org>2011-06-30 00:41:31 +0800
commitf099f679dcdd568cb5b7c8838f5f114ed19bce07 (patch)
treed54fa9561ef243e4ba8ce57d1e6a885406af02c6 /composer/e-composer-private.c
parentd92cfbebd8d52cfeeb3133ab30f0e1c56ce41ed5 (diff)
downloadgsoc2013-evolution-f099f679dcdd568cb5b7c8838f5f114ed19bce07.tar.gz
gsoc2013-evolution-f099f679dcdd568cb5b7c8838f5f114ed19bce07.tar.zst
gsoc2013-evolution-f099f679dcdd568cb5b7c8838f5f114ed19bce07.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;
+}