aboutsummaryrefslogtreecommitdiffstats
path: root/composer/e-composer-private.c
diff options
context:
space:
mode:
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;
+}