]> www.fi.muni.cz Git - evince.git/blobdiff - thumbnailer/evince-thumbnailer.c
[dualscreen] fix crash on ctrl+w and fix control window closing
[evince.git] / thumbnailer / evince-thumbnailer.c
index 9cc572f368ce242ab222783281ef010723301460..94d6b77ea334d3b676aa9ba4f2f840ea819d6ecd 100644 (file)
@@ -13,7 +13,7 @@
 
    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
-   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 */
 
 #include <config.h>
 #include <stdlib.h>
 #include <string.h>
 
+#ifdef G_OS_WIN32
+#include <io.h>
+#include <conio.h>
+#if !(_WIN32_WINNT >= 0x0500)
+#error "_WIN32_WINNT must be defined >= 0x0500"
+#endif
+#include <windows.h>
+#endif
+
 #define THUMBNAIL_SIZE 128
 
 static gint size = THUMBNAIL_SIZE;
@@ -43,13 +52,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 +116,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,11 +134,10 @@ 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),
-                                                      rc, FALSE);
+       pixbuf = ev_document_get_thumbnail (document, rc);
        g_object_unref (rc);
        g_object_unref (page);
        
@@ -88,7 +147,13 @@ evince_thumbnail_pngenc_get (EvDocument *document, const char *thumbnail, int si
                if (overlaid_icon_name) {
                        GdkPixbuf *overlaid_pixbuf;
 
-                       gchar *overlaid_icon_path = g_strdup_printf ("%s/%s", DATADIR, overlaid_icon_name);
+#ifdef G_OS_WIN32
+                       gchar *dir = g_win32_get_package_installation_directory_of_module (NULL);
+                       gchar *overlaid_icon_path = g_build_filename (dir, "share", "evince", overlaid_icon_name, NULL);
+                       g_free (dir);
+#else
+                       gchar *overlaid_icon_path = g_strdup_printf ("%s/%s", EVINCEDATADIR, overlaid_icon_name);
+#endif
                        overlaid_pixbuf = gdk_pixbuf_new_from_file (overlaid_icon_path, NULL);
                        g_free (overlaid_icon_path);
                        if (overlaid_pixbuf != NULL) {
@@ -153,7 +218,6 @@ main (int argc, char *argv[])
        GOptionContext *context;
        const char     *input;
        const char     *output;
-       char           *uri;
        GFile          *file;
        GError         *error = NULL;
 
@@ -197,23 +261,14 @@ 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 ();
                return -2;
        }
 
-       if (!EV_IS_DOCUMENT_THUMBNAILS (document)) {
-               g_object_unref (document);
-               ev_shutdown ();
-               return -2;
-       }
-
        if (EV_IS_ASYNC_RENDERER (document)) {
                struct AsyncData data;