[evince] [thumbnailer] Add support for remote files
- From: Carlos Garcia Campos <carlosgc src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [evince] [thumbnailer] Add support for remote files
- Date: Tue, 22 Dec 2009 17:05:27 +0000 (UTC)
commit fd7c1a68733c5718b9cb0fdcbed09be1889c1140
Author: Carlos Garcia Campos <carlosgc gnome org>
Date: Tue Dec 22 18:04:30 2009 +0100
[thumbnailer] Add support for remote files
Fixes bgo#605218.
thumbnailer/evince-thumbnailer.c | 63 +++++++++++++++++++++++++++++++++-----
1 files changed, 55 insertions(+), 8 deletions(-)
---
diff --git a/thumbnailer/evince-thumbnailer.c b/thumbnailer/evince-thumbnailer.c
index 31486bf..6ec0f6c 100644
--- a/thumbnailer/evince-thumbnailer.c
+++ b/thumbnailer/evince-thumbnailer.c
@@ -53,13 +53,63 @@ struct AsyncData {
gboolean success;
};
+static void
+delete_temp_file (GFile *file)
+{
+ ev_tmp_file_unlink (file);
+ g_object_unref (file);
+}
+
static EvDocument *
-evince_thumbnailer_get_document (const gchar *uri)
+evince_thumbnailer_get_document (GFile *file)
{
EvDocument *document = NULL;
+ gchar *uri;
+ GFile *tmp_file = NULL;
GError *error = NULL;
- document = ev_document_factory_get_document (uri, &error);
+ if (!g_file_is_native (file)) {
+ gchar *base_name, *template;
+
+ base_name = g_file_get_basename (file);
+ template = g_strdup_printf ("document.XXXXXX-%s", base_name);
+ g_free (base_name);
+
+ tmp_file = ev_mkstemp_file (template, &error);
+ g_free (template);
+ if (!tmp_file) {
+ g_printerr ("Error loading remote document: %s\n", error->message);
+ g_error_free (error);
+
+ return NULL;
+ }
+
+ g_file_copy (file, tmp_file, G_FILE_COPY_OVERWRITE,
+ NULL, NULL, NULL, &error);
+ if (error) {
+ g_printerr ("Error loading remote document: %s\n", error->message);
+ g_error_free (error);
+ g_object_unref (tmp_file);
+
+ return NULL;
+ }
+ uri = g_file_get_uri (tmp_file);
+ } else {
+ uri = g_file_get_uri (file);
+ }
+
+ document = ev_document_factory_get_document (uri, &error);
+ if (tmp_file) {
+ if (document) {
+ g_object_weak_ref (G_OBJECT (document),
+ (GWeakNotify)delete_temp_file,
+ tmp_file);
+ } else {
+ ev_tmp_file_unlink (tmp_file);
+ g_object_unref (tmp_file);
+ }
+ }
+ g_free (uri);
if (error) {
if (error->domain == EV_DOCUMENT_ERROR &&
error->code == EV_DOCUMENT_ERROR_ENCRYPTED) {
@@ -67,10 +117,11 @@ evince_thumbnailer_get_document (const gchar *uri)
g_error_free (error);
return NULL;
}
+ g_printerr ("Error loading document: %s\n", error->message);
g_error_free (error);
return NULL;
}
-
+
return document;
}
@@ -169,7 +220,6 @@ main (int argc, char *argv[])
GOptionContext *context;
const char *input;
const char *output;
- char *uri;
GFile *file;
GError *error = NULL;
@@ -213,11 +263,8 @@ main (int argc, char *argv[])
return -1;
file = g_file_new_for_commandline_arg (input);
- uri = g_file_get_uri (file);
- document = evince_thumbnailer_get_document (uri);
-
+ document = evince_thumbnailer_get_document (file);
g_object_unref (file);
- g_free (uri);
if (!document) {
ev_shutdown ();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]