Remove commented out code.
[geeqie.git] / src / cache-loader.c
index 1fb2fcb..239cbed 100644 (file)
@@ -1,6 +1,7 @@
 /*
- * GQview
+ * Geeqie
  * (C) 2005 John Ellis
+ * Copyright (C) 2008 - 2012 The Geeqie Team
  *
  * Author: John Ellis
  *
  * This software comes with no warranty of any kind, use at your own risk!
  */
 
-#include "gqview.h"
+#include "main.h"
 #include "cache-loader.h"
+#include "cache.h"
 
+#include "filedata.h"
 #include "exif.h"
+#include "metadata.h"
 #include "md5-util.h"
 #include "ui_fileops.h"
 
@@ -44,9 +48,10 @@ static gboolean cache_loader_process(CacheLoader *cl)
 
                if (!cl->il && !cl->error)
                        {
-                       cl->il = image_loader_new(cl->path);
-                       image_loader_set_error_func(cl->il, cache_loader_error_cb, cl);
-                       if (image_loader_start(cl->il, cache_loader_done_cb, cl))
+                       cl->il = image_loader_new(cl->fd);
+                       g_signal_connect(G_OBJECT(cl->il), "error", (GCallback)cache_loader_error_cb, cl);
+                       g_signal_connect(G_OBJECT(cl->il), "done", (GCallback)cache_loader_done_cb, cl);
+                       if (image_loader_start(cl->il))
                                {
                                return FALSE;
                                }
@@ -90,7 +95,7 @@ static gboolean cache_loader_process(CacheLoader *cl)
                 !cl->cd->dimensions)
                {
                if (!cl->error &&
-                   image_load_dimensions(cl->path, &cl->cd->width, &cl->cd->height))
+                   image_load_dimensions(cl->fd, &cl->cd->width, &cl->cd->height))
                        {
                        cl->cd->dimensions = TRUE;
                        cl->done_mask |= CACHE_LOADER_DIMENSIONS;
@@ -105,7 +110,7 @@ static gboolean cache_loader_process(CacheLoader *cl)
        else if (cl->todo_mask & CACHE_LOADER_MD5SUM &&
                 !cl->cd->have_md5sum)
                {
-               if (md5_get_digest_from_file_utf8(cl->path, cl->cd->md5sum))
+               if (md5_get_digest_from_file_utf8(cl->fd->path, cl->cd->md5sum))
                        {
                        cl->cd->have_md5sum = TRUE;
                        cl->done_mask |= CACHE_LOADER_MD5SUM;
@@ -121,29 +126,24 @@ static gboolean cache_loader_process(CacheLoader *cl)
                 !cl->cd->have_date)
                {
                time_t date = -1;
-               ExifData *exif;
+               gchar *text;
 
-               exif = exif_read(cl->path);
-               if (exif)
+               text =  metadata_read_string(cl->fd, "formatted.DateTime", METADATA_FORMATTED);
+               if (text)
                        {
-                       gchar *text;
+                       struct tm t;
 
-                       text = exif_get_data_as_text(exif, "fDateTime");
-                       if (text)
-                               {
-                               struct tm t = { 0 };
+                       memset(&t, 0, sizeof(t));
 
-                               if (sscanf(text, "%d:%d:%d %d:%d:%d", &t.tm_year, &t.tm_mon, &t.tm_mday,
-                                          &t.tm_hour, &t.tm_min, &t.tm_sec) == 6)
-                                       {
-                                       t.tm_year -= 1900;
-                                       t.tm_mon -= 1;
-                                       t.tm_isdst = -1;
-                                       date = mktime(&t);
-                                       }
-                               g_free(text);
+                       if (sscanf(text, "%d:%d:%d %d:%d:%d", &t.tm_year, &t.tm_mon, &t.tm_mday,
+                                  &t.tm_hour, &t.tm_min, &t.tm_sec) == 6)
+                               {
+                               t.tm_year -= 1900;
+                               t.tm_mon -= 1;
+                               t.tm_isdst = -1;
+                               date = mktime(&t);
                                }
-                       exif_free(exif);
+                       g_free(text);
                        }
 
                cl->cd->date = date;
@@ -155,26 +155,26 @@ static gboolean cache_loader_process(CacheLoader *cl)
        else
                {
                /* done, save then call done function */
-               if (enable_thumb_caching &&
+               if (options->thumbnails.enable_caching &&
                    cl->done_mask != CACHE_LOADER_NONE)
                        {
                        gchar *base;
                        mode_t mode = 0755;
 
-                       base = cache_get_location(CACHE_TYPE_SIM, cl->path, FALSE, &mode);
-                       if (cache_ensure_dir_exists(base, mode))
+                       base = cache_get_location(CACHE_TYPE_SIM, cl->fd->path, FALSE, &mode);
+                       if (recursive_mkdir_if_not_exists(base, mode))
                                {
                                g_free(cl->cd->path);
-                               cl->cd->path = cache_get_location(CACHE_TYPE_SIM, cl->path, TRUE, NULL);
+                               cl->cd->path = cache_get_location(CACHE_TYPE_SIM, cl->fd->path, TRUE, NULL);
                                if (cache_sim_data_save(cl->cd))
                                        {
-                                       filetime_set(cl->cd->path, filetime(cl->path));
+                                       filetime_set(cl->cd->path, filetime(cl->fd->path));
                                        }
                                }
                        g_free(base);
                        }
 
-               cl->idle_id = -1;
+               cl->idle_id = 0;
 
                if (cl->done_func)
                        {
@@ -194,22 +194,22 @@ static gboolean cache_loader_idle_cb(gpointer data)
        return cache_loader_process(cl);
 }
 
-CacheLoader *cache_loader_new(const gchar *path, CacheDataType load_mask,
+CacheLoader *cache_loader_new(FileData *fd, CacheDataType load_mask,
                              CacheLoaderDoneFunc done_func, gpointer done_data)
 {
        CacheLoader *cl;
        gchar *found;
 
-       if (!path || !isfile(path)) return NULL;
+       if (!fd || !isfile(fd->path)) return NULL;
 
        cl = g_new0(CacheLoader, 1);
-       cl->path = g_strdup(path);
+       cl->fd = file_data_ref(fd);
 
        cl->done_func = done_func;
        cl->done_data = done_data;
 
-       found = cache_find_location(CACHE_TYPE_SIM, path);
-       if (found && filetime(found) == filetime(path))
+       found = cache_find_location(CACHE_TYPE_SIM, cl->fd->path);
+       if (found && filetime(found) == filetime(cl->fd->path))
                {
                cl->cd = cache_sim_data_load(found);
                }
@@ -232,16 +232,16 @@ void cache_loader_free(CacheLoader *cl)
 {
        if (!cl) return;
 
-       if (cl->idle_id != -1)
+       if (cl->idle_id)
                {
                g_source_remove(cl->idle_id);
-               cl->idle_id = -1;
+               cl->idle_id = 0;
                }
 
        image_loader_free(cl->il);
        cache_sim_data_free(cl->cd);
 
-       g_free(cl->path);
+       file_data_unref(cl->fd);
        g_free(cl);
 }
-
+/* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */