Fix #314: Remote commands for thumbnail maintenance
[geeqie.git] / src / cache-loader.c
index f77a0aa..323b39d 100644 (file)
@@ -1,20 +1,31 @@
 /*
- * GQview
- * (C) 2005 John Ellis
+ * Copyright (C) 2004 John Ellis
+ * Copyright (C) 2008 - 2016 The Geeqie Team
  *
  * Author: John Ellis
  *
- * This software is released under the GNU General Public License (GNU GPL).
- * Please read the included file COPYING for more information.
- * This software comes with no warranty of any kind, use at your own risk!
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * 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.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 
-#include "gqview.h"
+#include "main.h"
 #include "cache-loader.h"
 #include "cache.h"
 
-#include "filelist.h"
+#include "filedata.h"
 #include "exif.h"
+#include "metadata.h"
 #include "md5-util.h"
 #include "ui_fileops.h"
 
@@ -47,8 +58,9 @@ static gboolean cache_loader_process(CacheLoader *cl)
                if (!cl->il && !cl->error)
                        {
                        cl->il = image_loader_new(cl->fd);
-                       image_loader_set_error_func(cl->il, cache_loader_error_cb, cl);
-                       if (image_loader_start(cl->il, cache_loader_done_cb, cl))
+                       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;
                                }
@@ -123,29 +135,24 @@ static gboolean cache_loader_process(CacheLoader *cl)
                 !cl->cd->have_date)
                {
                time_t date = -1;
-               ExifData *exif;
+               gchar *text;
 
-               exif = exif_read(cl->fd, FALSE);
-               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;
@@ -157,14 +164,14 @@ 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->fd->path, FALSE, &mode);
-                       if (cache_ensure_dir_exists(base, mode))
+                       if (recursive_mkdir_if_not_exists(base, mode))
                                {
                                g_free(cl->cd->path);
                                cl->cd->path = cache_get_location(CACHE_TYPE_SIM, cl->fd->path, TRUE, NULL);
@@ -176,7 +183,7 @@ static gboolean cache_loader_process(CacheLoader *cl)
                        g_free(base);
                        }
 
-               cl->idle_id = -1;
+               cl->idle_id = 0;
 
                if (cl->done_func)
                        {
@@ -234,10 +241,10 @@ 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);
@@ -246,4 +253,4 @@ void cache_loader_free(CacheLoader *cl)
        file_data_unref(cl->fd);
        g_free(cl);
 }
-
+/* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */