aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--e-util/e-util.c81
-rw-r--r--e-util/e-util.h5
-rw-r--r--widgets/misc/e-image-chooser.c47
3 files changed, 36 insertions, 97 deletions
diff --git a/e-util/e-util.c b/e-util/e-util.c
index 800974577c..330419c4d4 100644
--- a/e-util/e-util.c
+++ b/e-util/e-util.c
@@ -1418,87 +1418,6 @@ e_util_guess_mime_type (const gchar *filename, gboolean localfile)
return mime_type;
}
-/**
- * e_util_read_file:
- * @filename: File name to read.
- * @filename_is_uri: Whether the file name is URI, if not, then it's a local path.
- * @buffer: Read content or the file. Should not be NULL. Returned value should be freed with g_free.
- * @read: Number of actually read bytes. Should not be NULL.
- * @error: Here will be returned an error from reading operations. Can be NULL. Not every time is set when returned FALSE.
- *
- * Reads synchronously content of the file, to which is pointed either by path or by URI.
- * Mount point should be already mounted when calling this function.
- *
- * Returns: Whether was reading successful or not.
- **/
-gboolean
-e_util_read_file (const gchar *filename, gboolean filename_is_uri, gchar **buffer, gsize *read, GError **error)
-{
- GFile *file;
- GFileInfo *info;
- GError *err = NULL;
- gboolean res = FALSE;
-
- g_return_val_if_fail (filename != NULL, FALSE);
- g_return_val_if_fail (buffer != NULL, FALSE);
- g_return_val_if_fail (read != NULL, FALSE);
-
- *buffer = NULL;
- *read = 0;
-
- if (filename_is_uri)
- file = g_file_new_for_uri (filename);
- else
- file = g_file_new_for_path (filename);
-
- g_return_val_if_fail (file != NULL, FALSE);
-
- info = g_file_query_info (file, G_FILE_ATTRIBUTE_STANDARD_SIZE, G_FILE_QUERY_INFO_NONE, NULL, &err);
-
- if (!err && info) {
- guint64 sz;
- gchar *buff;
-
- sz = g_file_info_get_attribute_uint64 (info, G_FILE_ATTRIBUTE_STANDARD_SIZE);
- buff = g_malloc (sizeof (gchar) * sz);
-
- if (buff) {
- GInputStream *stream;
-
- stream = G_INPUT_STREAM (g_file_read (file, NULL, &err));
-
- if (!err && stream) {
- res = g_input_stream_read_all (stream, buff, sz, read, NULL, &err);
-
- if (err)
- res = FALSE;
-
- if (res)
- *buffer = buff;
- else
- g_free (buff);
- }
-
- if (stream)
- g_object_unref (stream);
- }
- }
-
- if (info)
- g_object_unref (info);
-
- g_object_unref (file);
-
- if (err) {
- if (error)
- *error = err;
- else
- g_error_free (err);
- }
-
- return res;
-}
-
GSList *
e_util_get_category_filter_options (void)
{
diff --git a/e-util/e-util.h b/e-util/e-util.h
index 7c4be25bd4..276d20f310 100644
--- a/e-util/e-util.h
+++ b/e-util/e-util.h
@@ -143,11 +143,6 @@ gboolean e_file_lock_exists (void);
gchar * e_util_guess_mime_type (const gchar *filename,
gboolean localfile);
-gboolean e_util_read_file (const gchar *filename,
- gboolean filename_is_uri,
- gchar **buffer,
- gsize *read,
- GError **error);
GSList * e_util_get_category_filter_options
(void);
diff --git a/widgets/misc/e-image-chooser.c b/widgets/misc/e-image-chooser.c
index 5ef4e7cd3e..4ea76099aa 100644
--- a/widgets/misc/e-image-chooser.c
+++ b/widgets/misc/e-image-chooser.c
@@ -241,6 +241,32 @@ image_drag_drop_cb (GtkWidget *widget,
}
static void
+image_chooser_file_loaded_cb (GFile *file,
+ GAsyncResult *result,
+ EImageChooser *chooser)
+{
+ gchar *contents;
+ gsize length;
+ GError *error = NULL;
+
+ g_file_load_contents_finish (
+ file, result, &contents, &length, NULL, &error);
+
+ if (error != NULL) {
+ g_warning ("%s", error->message);
+ g_error_free (error);
+ goto exit;
+ }
+
+ set_image_from_data (chooser, contents, length);
+
+ g_free (contents);
+
+exit:
+ g_object_unref (chooser);
+}
+
+static void
image_drag_data_received_cb (GtkWidget *widget,
GdkDragContext *context,
gint x,
@@ -250,29 +276,28 @@ image_drag_data_received_cb (GtkWidget *widget,
guint time,
EImageChooser *chooser)
{
+ GFile *file;
gboolean handled = FALSE;
gchar **uris;
- gchar *buf = NULL;
- gsize read = 0;
- GError *error = NULL;
uris = gtk_selection_data_get_uris (selection_data);
if (uris == NULL)
goto exit;
- if (e_util_read_file (uris[0], TRUE, &buf, &read, &error) && read > 0 && buf)
- handled = set_image_from_data (chooser, buf, read);
+ file = g_file_new_for_uri (uris[0]);
- if (!handled)
- g_free (buf);
+ /* XXX Not cancellable. */
+ g_file_load_contents_async (
+ file, NULL, (GAsyncReadyCallback)
+ image_chooser_file_loaded_cb,
+ g_object_ref (chooser));
+ g_object_unref (file);
g_strfreev (uris);
- if (error) {
- g_warning ("%s", error->message);
- g_error_free (error);
- }
+ /* Assume success. We won't know til later. */
+ handled = TRUE;
exit:
gtk_drag_finish (context, handled, FALSE, time);