Include a Other Software section in Help file
[geeqie.git] / src / cache.c
index 53798c1..fee9db9 100644 (file)
@@ -1,13 +1,22 @@
 /*
- * Geeqie
- * (C) 2004 John Ellis
- * Copyright (C) 2008 The Geeqie Team
+ * 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 "main.h"
 
 #include "md5-util.h"
 #include "secure_save.h"
+#include "thumb_standard.h"
 #include "ui_fileops.h"
 
 #include <utime.h>
 #include <errno.h>
 
 
-/*
+/**
+ * @file
  *-------------------------------------------------------------------
  * Cache data file format:
  *-------------------------------------------------------------------
  *
- * SIMcache
- * #comment
- * Dimensions=[<width> x <height>]
- * Date=[<value in time_t format, or -1 if no embedded date>]
- * Checksum=[<value>]
- * MD5sum=[<32 character ascii text digest>]
+ * SIMcache \n
+ * #comment \n
+ * Dimensions=[<width> x <height>] \n
+ * Date=[<value in time_t format, or -1 if no embedded date>] \n
+ * MD5sum=[<32 character ascii text digest>] \n
  * SimilarityGrid[32 x 32]=<3072 bytes of data (1024 pixels in RGB format, 1 pixel is 24bits)>
  *
- *
- * The first line (9 bytes) indicates it is a SIMcache format file. (new line char must exist)
- * Comment lines starting with a # are ignored up to a new line.
- * All data lines should end with a new line char.
- * Format is very strict, data must begin with the char immediately following '='.
- * Currently SimilarityGrid is always assumed to be 32 x 32 RGB.
+ * The first line (9 bytes) indicates it is a SIMcache format file. (new line char must exist) \n
+ * Comment lines starting with a # are ignored up to a new line. \n
+ * All data lines should end with a new line char. \n
+ * Format is very strict, data must begin with the char immediately following '='. \n
+ * Currently SimilarityGrid is always assumed to be 32 x 32 RGB. \n
  */
 
 
@@ -74,7 +83,7 @@ void cache_sim_data_free(CacheData *cd)
  *-------------------------------------------------------------------
  */
 
-static gint cache_sim_write_dimensions(SecureSaveInfo *ssi, CacheData *cd)
+static gboolean cache_sim_write_dimensions(SecureSaveInfo *ssi, CacheData *cd)
 {
        if (!cd || !cd->dimensions) return FALSE;
 
@@ -83,7 +92,7 @@ static gint cache_sim_write_dimensions(SecureSaveInfo *ssi, CacheData *cd)
        return TRUE;
 }
 
-static gint cache_sim_write_date(SecureSaveInfo *ssi, CacheData *cd)
+static gboolean cache_sim_write_date(SecureSaveInfo *ssi, CacheData *cd)
 {
        if (!cd || !cd->have_date) return FALSE;
 
@@ -92,16 +101,7 @@ static gint cache_sim_write_date(SecureSaveInfo *ssi, CacheData *cd)
        return TRUE;
 }
 
-static gint cache_sim_write_checksum(SecureSaveInfo *ssi, CacheData *cd)
-{
-       if (!cd || !cd->have_checksum) return FALSE;
-
-       secure_fprintf(ssi, "Checksum=[%ld]\n", cd->checksum);
-
-       return TRUE;
-}
-
-static gint cache_sim_write_md5sum(SecureSaveInfo *ssi, CacheData *cd)
+static gboolean cache_sim_write_md5sum(SecureSaveInfo *ssi, CacheData *cd)
 {
        gchar *text;
 
@@ -114,7 +114,7 @@ static gint cache_sim_write_md5sum(SecureSaveInfo *ssi, CacheData *cd)
        return TRUE;
 }
 
-static gint cache_sim_write_similarity(SecureSaveInfo *ssi, CacheData *cd)
+static gboolean cache_sim_write_similarity(SecureSaveInfo *ssi, CacheData *cd)
 {
        guint x, y;
        guint8 buf[3 * 32];
@@ -129,7 +129,7 @@ static gint cache_sim_write_similarity(SecureSaveInfo *ssi, CacheData *cd)
                guint8 *avg_g = &cd->sim->avg_g[s];
                guint8 *avg_b = &cd->sim->avg_b[s];
                guint n = 0;
-                       
+
                for (x = 0; x < 32; x++)
                        {
                        buf[n++] = avg_r[x];
@@ -145,7 +145,7 @@ static gint cache_sim_write_similarity(SecureSaveInfo *ssi, CacheData *cd)
        return TRUE;
 }
 
-gint cache_sim_data_save(CacheData *cd)
+gboolean cache_sim_data_save(CacheData *cd)
 {
        SecureSaveInfo *ssi;
        gchar *pathl;
@@ -165,7 +165,6 @@ gint cache_sim_data_save(CacheData *cd)
        secure_fprintf(ssi, "SIMcache\n#%s %s\n", PACKAGE, VERSION);
        cache_sim_write_dimensions(ssi, cd);
        cache_sim_write_date(ssi, cd);
-       cache_sim_write_checksum(ssi, cd);
        cache_sim_write_md5sum(ssi, cd);
        cache_sim_write_similarity(ssi, cd);
 
@@ -185,7 +184,7 @@ gint cache_sim_data_save(CacheData *cd)
  *-------------------------------------------------------------------
  */
 
-static gint cache_sim_read_skipline(FILE *f, gint s)
+static gboolean cache_sim_read_skipline(FILE *f, gint s)
 {
        if (!f) return FALSE;
 
@@ -202,7 +201,7 @@ static gint cache_sim_read_skipline(FILE *f, gint s)
        return FALSE;
 }
 
-static gint cache_sim_read_comment(FILE *f, gchar *buf, gint s, CacheData *cd)
+static gboolean cache_sim_read_comment(FILE *f, gchar *buf, gint s, CacheData *cd)
 {
        if (!f || !buf || !cd) return FALSE;
 
@@ -211,7 +210,7 @@ static gint cache_sim_read_comment(FILE *f, gchar *buf, gint s, CacheData *cd)
        return cache_sim_read_skipline(f, s - 1);
 }
 
-static gint cache_sim_read_dimensions(FILE *f, gchar *buf, gint s, CacheData *cd)
+static gboolean cache_sim_read_dimensions(FILE *f, gchar *buf, gint s, CacheData *cd)
 {
        if (!f || !buf || !cd) return FALSE;
 
@@ -254,7 +253,7 @@ static gint cache_sim_read_dimensions(FILE *f, gchar *buf, gint s, CacheData *cd
        return FALSE;
 }
 
-static gint cache_sim_read_date(FILE *f, gchar *buf, gint s, CacheData *cd)
+static gboolean cache_sim_read_date(FILE *f, gchar *buf, gint s, CacheData *cd)
 {
        if (!f || !buf || !cd) return FALSE;
 
@@ -294,47 +293,7 @@ static gint cache_sim_read_date(FILE *f, gchar *buf, gint s, CacheData *cd)
        return FALSE;
 }
 
-static gint cache_sim_read_checksum(FILE *f, gchar *buf, gint s, CacheData *cd)
-{
-       if (!f || !buf || !cd) return FALSE;
-
-       if (s < 8 || strncmp("Checksum", buf, 8) != 0) return FALSE;
-
-       if (fseek(f, - s, SEEK_CUR) == 0)
-               {
-               gchar b;
-               gchar buf[1024];
-               gsize p = 0;
-
-               b = 'X';
-               while (b != '[')
-                       {
-                       if (fread(&b, sizeof(b), 1, f) != 1) return FALSE;
-                       }
-               while (b != ']' && p < sizeof(buf) - 1)
-                       {
-                       if (fread(&b, sizeof(b), 1, f) != 1) return FALSE;
-                       buf[p] = b;
-                       p++;
-                       }
-
-               while (b != '\n')
-                       {
-                       if (fread(&b, sizeof(b), 1, f) != 1) break;
-                       }
-
-               buf[p] = '\0';
-               cd->checksum = strtol(buf, NULL, 10);
-
-               cd->have_checksum = TRUE;
-
-               return TRUE;
-               }
-
-       return FALSE;
-}
-
-static gint cache_sim_read_md5sum(FILE *f, gchar *buf, gint s, CacheData *cd)
+static gboolean cache_sim_read_md5sum(FILE *f, gchar *buf, gint s, CacheData *cd)
 {
        if (!f || !buf || !cd) return FALSE;
 
@@ -371,7 +330,7 @@ static gint cache_sim_read_md5sum(FILE *f, gchar *buf, gint s, CacheData *cd)
        return FALSE;
 }
 
-static gint cache_sim_read_similarity(FILE *f, gchar *buf, gint s, CacheData *cd)
+static gboolean cache_sim_read_similarity(FILE *f, gchar *buf, gint s, CacheData *cd)
 {
        if (!f || !buf || !cd) return FALSE;
 
@@ -477,7 +436,6 @@ CacheData *cache_sim_data_load(const gchar *path)
                        if (!cache_sim_read_comment(f, buf, s, cd) &&
                            !cache_sim_read_dimensions(f, buf, s, cd) &&
                            !cache_sim_read_date(f, buf, s, cd) &&
-                           !cache_sim_read_checksum(f, buf, s, cd) &&
                            !cache_sim_read_md5sum(f, buf, s, cd) &&
                            !cache_sim_read_similarity(f, buf, s, cd))
                                {
@@ -501,7 +459,6 @@ CacheData *cache_sim_data_load(const gchar *path)
 
        if (!cd->dimensions &&
            !cd->have_date &&
-           !cd->have_checksum &&
            !cd->have_md5sum &&
            !cd->similarity)
                {
@@ -535,14 +492,6 @@ void cache_sim_data_set_date(CacheData *cd, time_t date)
        cd->have_date = TRUE;
 }
 
-void cache_sim_data_set_checksum(CacheData *cd, glong checksum)
-{
-       if (!cd) return;
-
-       cd->checksum = checksum;
-       cd->have_checksum = TRUE;
-}
-
 void cache_sim_data_set_md5sum(CacheData *cd, guchar digest[16])
 {
        gint i;
@@ -570,7 +519,7 @@ void cache_sim_data_set_similarity(CacheData *cd, ImageSimilarityData *sd)
        cd->similarity = TRUE;
 }
 
-gint cache_sim_data_filled(ImageSimilarityData *sd)
+gboolean cache_sim_data_filled(ImageSimilarityData *sd)
 {
        if (!sd) return FALSE;
        return sd->filled;
@@ -658,7 +607,7 @@ static gchar *cache_build_path_local(const gchar *source, const gchar *cache_loc
        path = g_build_filename(base, cache_local, name, NULL);
        g_free(name);
        g_free(base);
-       
+
        return path;
 }
 
@@ -678,7 +627,7 @@ gchar *cache_find_location(CacheType type, const gchar *source)
        const gchar *cache_rc;
        const gchar *cache_local;
        const gchar *cache_ext;
-       gint prefer_local;
+       gboolean prefer_local;
 
        if (!source) return NULL;
 
@@ -726,13 +675,13 @@ gchar *cache_find_location(CacheType type, const gchar *source)
        return path;
 }
 
-gint cache_time_valid(const gchar *cache, const gchar *path)
+gboolean cache_time_valid(const gchar *cache, const gchar *path)
 {
        struct stat cache_st;
        struct stat path_st;
        gchar *cachel;
        gchar *pathl;
-       gint ret = FALSE;
+       gboolean ret = FALSE;
 
        if (!cache || !path) return FALSE;
 
@@ -774,7 +723,8 @@ const gchar *get_thumbnails_cache_dir(void)
 
        if (USE_XDG)
                {
-               thumbnails_cache_dir = g_build_filename(xdg_cache_home_get(), GQ_APPNAME_LC, GQ_CACHE_THUMB, NULL);
+               thumbnails_cache_dir = g_build_filename(xdg_cache_home_get(),
+                                                               GQ_APPNAME_LC, GQ_CACHE_THUMB, NULL);
                }
        else
                {
@@ -784,6 +734,18 @@ const gchar *get_thumbnails_cache_dir(void)
        return thumbnails_cache_dir;
 }
 
+const gchar *get_thumbnails_standard_cache_dir(void)
+{
+       static gchar *thumbnails_standard_cache_dir = NULL;
+
+       if (thumbnails_standard_cache_dir) return thumbnails_standard_cache_dir;
+
+       thumbnails_standard_cache_dir = g_build_filename(xdg_cache_home_get(),
+                                                                               THUMB_FOLDER_GLOBAL, NULL);
+
+       return thumbnails_standard_cache_dir;
+}
+
 const gchar *get_metadata_cache_dir(void)
 {
        static gchar *metadata_cache_dir = NULL;