]> git.street.me.uk Git - andy/viking.git/blobdiff - src/thumbnails.c
Add Refresh to consider reloading a Mapnik Rendering configuration.
[andy/viking.git] / src / thumbnails.c
index e845e13353d028e9c6872761bba5b76dcd70f3e0..40914049a571bbe76ac5d31f956d4f63d92a4d3a 100644 (file)
  *
  */
 
  *
  */
 
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
 #include <stdlib.h>
 #include <stdlib.h>
-#include <sys/stat.h>
+#ifdef HAVE_UNISTD_H
+#include <unistd.h>
+#endif
 #include <errno.h>
 #include <string.h>
 #include <errno.h>
 #include <string.h>
+#include <glib.h>
+#include <glib/gstdio.h>
 #include "viking.h"
 #include "thumbnails.h"
 #include "viking.h"
 #include "thumbnails.h"
-#include "thumbnails_pixbuf.h"
+#include "icons/icons.h"
 
 #ifdef __CYGWIN__
 #ifdef __CYGWIN_USE_BIG_TYPES__
 
 #ifdef __CYGWIN__
 #ifdef __CYGWIN_USE_BIG_TYPES__
 
 #undef MIN /* quit yer whining, gcc */
 #undef MAX
 
 #undef MIN /* quit yer whining, gcc */
 #undef MAX
-#include <sys/param.h> /* for realpath() */
 #ifndef MAX
 /* We need MAX macro and some system does not offer it */
 #define MAX(a,b) (((a)>(b))?(a):(b))
 #endif
 
 #ifndef MAX
 /* We need MAX macro and some system does not offer it */
 #define MAX(a,b) (((a)>(b))?(a):(b))
 #endif
 
+#define HOME_DIR g_get_home_dir()
+
 #ifdef WINDOWS
 #ifdef WINDOWS
-#define HOME_DIR "C:\\VIKING"
 #define THUMB_DIR "\\THUMBNAILS\\" /* viking maps default viking\maps */
 #define THUMB_SUB_DIR "normal\\"
 #define THUMB_DIR "\\THUMBNAILS\\" /* viking maps default viking\maps */
 #define THUMB_SUB_DIR "normal\\"
-#define mkdir(a,b) mkdir(a)
-#define realpath(X,Y) _fullpath(Y,X,MAX_PATH)
-
 #else
 #else
-#define HOME_DIR g_get_home_dir()
 #define THUMB_DIR "/.thumbnails/"
 #define THUMB_SUB_DIR "normal/"
 #endif
 
 #define PIXMAP_THUMB_SIZE  128
 
 #define THUMB_DIR "/.thumbnails/"
 #define THUMB_SUB_DIR "normal/"
 #endif
 
 #define PIXMAP_THUMB_SIZE  128
 
-#ifndef MAXPATHLEN
-#define MAXPATHLEN 1024
-#endif
-
 static char *md5_hash(const char *message);
 static char *md5_hash(const char *message);
-static char *pathdup(const char *path);
 static GdkPixbuf *save_thumbnail(const char *pathname, GdkPixbuf *full);
 static GdkPixbuf *child_create_thumbnail(const gchar *path);
 
 static GdkPixbuf *save_thumbnail(const char *pathname, GdkPixbuf *full);
 static GdkPixbuf *child_create_thumbnail(const gchar *path);
 
@@ -90,7 +89,7 @@ gboolean a_thumbnails_exists ( const gchar *filename )
 
 GdkPixbuf *a_thumbnails_get_default ()
 {
 
 GdkPixbuf *a_thumbnails_get_default ()
 {
-  return gdk_pixbuf_from_pixdata ( &tnnyl_pixbuf, FALSE, NULL );
+  return gdk_pixbuf_from_pixdata ( &thumbnails_pixbuf, FALSE, NULL );
 }
 
 /* filename must be absolute. you could have a function to make sure it exists and absolutize it */
 }
 
 /* filename must be absolute. you could have a function to make sure it exists and absolutize it */
@@ -115,7 +114,7 @@ GdkPixbuf *a_thumbnails_scale_pixbuf(GdkPixbuf *src, int max_w, int max_h)
 
        if (w <= max_w && h <= max_h)
        {
 
        if (w <= max_w && h <= max_h)
        {
-               gdk_pixbuf_ref(src);
+               g_object_ref ( G_OBJECT ( src ) );
                return src;
        }
        else
                return src;
        }
        else
@@ -135,14 +134,20 @@ GdkPixbuf *a_thumbnails_scale_pixbuf(GdkPixbuf *src, int max_w, int max_h)
 
 static GdkPixbuf *child_create_thumbnail(const gchar *path)
 {
 
 static GdkPixbuf *child_create_thumbnail(const gchar *path)
 {
-       GdkPixbuf *image;
+       GdkPixbuf *image, *tmpbuf;
 
        image = gdk_pixbuf_new_from_file(path, NULL);
 
        image = gdk_pixbuf_new_from_file(path, NULL);
+       if (!image)
+         return NULL;
+
+       tmpbuf = gdk_pixbuf_apply_embedded_orientation(image);
+       g_object_unref(G_OBJECT(image));
+       image = tmpbuf;
 
        if (image)
         {
                GdkPixbuf *thumb = save_thumbnail(path, image);
 
        if (image)
         {
                GdkPixbuf *thumb = save_thumbnail(path, image);
-               gdk_pixbuf_unref ( image );
+               g_object_unref ( G_OBJECT ( image ) );
                return thumb;
        }
 
                return thumb;
        }
 
@@ -154,6 +159,7 @@ static GdkPixbuf *save_thumbnail(const char *pathname, GdkPixbuf *full)
        struct stat info;
        gchar *path;
        int original_width, original_height;
        struct stat info;
        gchar *path;
        int original_width, original_height;
+       const gchar* orientation;
        GString *to;
        char *md5, *swidth, *sheight, *ssize, *smtime, *uri;
        mode_t old_mask;
        GString *to;
        char *md5, *swidth, *sheight, *ssize, *smtime, *uri;
        mode_t old_mask;
@@ -165,6 +171,8 @@ static GdkPixbuf *save_thumbnail(const char *pathname, GdkPixbuf *full)
 
        thumb = a_thumbnails_scale_pixbuf(full, PIXMAP_THUMB_SIZE, PIXMAP_THUMB_SIZE);
 
 
        thumb = a_thumbnails_scale_pixbuf(full, PIXMAP_THUMB_SIZE, PIXMAP_THUMB_SIZE);
 
+       orientation = gdk_pixbuf_get_option (full, "orientation");
+
        original_width = gdk_pixbuf_get_width(full);
        original_height = gdk_pixbuf_get_height(full);
 
        original_width = gdk_pixbuf_get_width(full);
        original_height = gdk_pixbuf_get_height(full);
 
@@ -174,19 +182,15 @@ static GdkPixbuf *save_thumbnail(const char *pathname, GdkPixbuf *full)
        ssize = g_strdup_printf(ST_SIZE_FMT, info.st_size);
        smtime = g_strdup_printf("%ld", (long) info.st_mtime);
 
        ssize = g_strdup_printf(ST_SIZE_FMT, info.st_size);
        smtime = g_strdup_printf("%ld", (long) info.st_mtime);
 
-       path = pathdup(pathname);
+       path = file_realpath_dup(pathname);
        uri = g_strconcat("file://", path, NULL);
        md5 = md5_hash(uri);
        g_free(path);
                
        to = g_string_new(HOME_DIR);
        uri = g_strconcat("file://", path, NULL);
        md5 = md5_hash(uri);
        g_free(path);
                
        to = g_string_new(HOME_DIR);
-#ifndef WINDOWS
-       mkdir(to->str, 0700);
-#endif
        g_string_append(to, THUMB_DIR);
        g_string_append(to, THUMB_DIR);
-       mkdir(to->str, 0700);
        g_string_append(to, THUMB_SUB_DIR);
        g_string_append(to, THUMB_SUB_DIR);
-       mkdir(to->str, 0700);
+       g_mkdir_with_parents(to->str, 0700);
        g_string_append(to, md5);
        name_len = to->len + 4; /* Truncate to this length when renaming */
 #ifdef WINDOWS
        g_string_append(to, md5);
        name_len = to->len + 4; /* Truncate to this length when renaming */
 #ifdef WINDOWS
@@ -205,6 +209,7 @@ static GdkPixbuf *save_thumbnail(const char *pathname, GdkPixbuf *full)
                        "tEXt::Thumb::MTime", smtime,
                        "tEXt::Thumb::URI", uri,
                        "tEXt::Software", PROJECT,
                        "tEXt::Thumb::MTime", smtime,
                        "tEXt::Thumb::URI", uri,
                        "tEXt::Software", PROJECT,
+                       "tEXt::Software::Orientation", orientation ? orientation : "0",
                        NULL);
        umask(old_mask);
 
                        NULL);
        umask(old_mask);
 
@@ -245,7 +250,7 @@ GdkPixbuf *a_thumbnails_get(const gchar *pathname)
        const char *ssize, *smtime;
        struct stat info;
 
        const char *ssize, *smtime;
        struct stat info;
 
-       path = pathdup(pathname);
+       path = file_realpath_dup(pathname);
        uri = g_strconcat("file://", path, NULL);
        md5 = md5_hash(uri);
        g_free(uri);
        uri = g_strconcat("file://", path, NULL);
        md5 = md5_hash(uri);
        g_free(uri);
@@ -276,7 +281,7 @@ GdkPixbuf *a_thumbnails_get(const gchar *pathname)
        goto out;
 err:
        if (thumb)
        goto out;
 err:
        if (thumb)
-               gdk_pixbuf_unref(thumb);
+               g_object_unref ( G_OBJECT ( thumb ) );
        thumb = NULL;
 out:
        g_free(path);
        thumb = NULL;
 out:
        g_free(path);
@@ -284,20 +289,6 @@ out:
        return thumb;
 }
 
        return thumb;
 }
 
-/* pathdup() stuff */
-
-static char *pathdup(const char *path)
-{
-       char real[MAXPATHLEN];
-
-       g_return_val_if_fail(path != NULL, NULL);
-
-       if (realpath(path, real))
-               return g_strdup(real);
-
-       return g_strdup(path);
-}
-
 /*
  * This code implements the MD5 message-digest algorithm.
  * The algorithm is due to Ron Rivest. The original code was
 /*
  * This code implements the MD5 message-digest algorithm.
  * The algorithm is due to Ron Rivest. The original code was
@@ -546,6 +537,6 @@ static char *md5_hash(const char *message)
        MD5Context ctx;
 
        MD5Init(&ctx);
        MD5Context ctx;
 
        MD5Init(&ctx);
-       MD5Update(&ctx, message, strlen(message));
+       MD5Update(&ctx, (md5byte *) message, strlen(message));
        return MD5Final(&ctx);
 }
        return MD5Final(&ctx);
 }