X-Git-Url: https://www.fi.muni.cz/~kas/git//home/kas/public_html/git/?a=blobdiff_plain;f=thumbnailer%2Fevince-thumbnailer.c;h=6ec0f6c4fb28b3589ab4ee82b39c06a02c174482;hb=7ffaa3a0083d1f59a721f9f22f23d29d3cfc52aa;hp=3598fdf6aa9e82aac099d864ca5e4fcea02fe51e;hpb=f575f06bfcb2e335f6b2089b3dba570e1da77198;p=evince.git diff --git a/thumbnailer/evince-thumbnailer.c b/thumbnailer/evince-thumbnailer.c index 3598fdf6..6ec0f6c4 100644 --- a/thumbnailer/evince-thumbnailer.c +++ b/thumbnailer/evince-thumbnailer.c @@ -25,6 +25,16 @@ #include #include +#ifdef G_OS_WIN32 +#ifdef DATADIR +#undef DATADIR +#endif +#include +#include +#define _WIN32_WINNT 0x0500 +#include +#endif + #define THUMBNAIL_SIZE 128 static gint size = THUMBNAIL_SIZE; @@ -43,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) { @@ -57,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; } @@ -74,7 +135,7 @@ evince_thumbnail_pngenc_get (EvDocument *document, const char *thumbnail, int si page = ev_document_get_page (document, 0); - ev_document_get_page_size (document, page, &width, &height); + ev_document_get_page_size (document, 0, &width, &height); rc = ev_render_context_new (page, 0, size / width); pixbuf = ev_document_thumbnails_get_thumbnail (EV_DOCUMENT_THUMBNAILS (document), @@ -159,7 +220,6 @@ main (int argc, char *argv[]) GOptionContext *context; const char *input; const char *output; - char *uri; GFile *file; GError *error = NULL; @@ -203,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 ();