* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
-#include "main.h"
#include "thumb-standard.h"
+#include <sys/stat.h>
+
+#include <cstdlib>
+#include <cstring>
+#include <ctime>
+
+#include <glib-object.h>
+
+#include <config.h>
+
#include "cache.h"
+#include "color-man.h"
+#include "debug.h"
+#include "exif.h"
+#include "filedata.h"
#include "image-load.h"
#include "md5-util.h"
+#include "metadata.h"
+#include "options.h"
#include "pixbuf-util.h"
+#include "typedefs.h"
#include "ui-fileops.h"
-#include "filedata.h"
-#include "exif.h"
-#include "metadata.h"
-#include "color-man.h"
+struct ExifData;
/**
* @file
- *
+ *
* This thumbnail caching implementation attempts to conform
* to the Thumbnail Managing Standard proposed on freedesktop.org
* The standard is documented here: \n
*/
-#define THUMB_SIZE_NORMAL 128
-#define THUMB_SIZE_LARGE 256
+enum {
+ THUMB_SIZE_NORMAL = 128,
+ THUMB_SIZE_LARGE = 256
+};
#define THUMB_MARKER_URI "tEXt::Thumb::URI"
#define THUMB_MARKER_MTIME "tEXt::Thumb::MTime"
#define THUMB_MARKER_HEIGHT "tEXt::Thumb::Image::Height"
#define THUMB_MARKER_APP "tEXt::Software"
-#define THUMB_PERMS_FOLDER 0700
-#define THUMB_PERMS_THUMB 0600
-
-
-
/*
*-----------------------------------------------------------------------------
* thumbnail loader
}
void thumb_loader_std_set_callbacks(ThumbLoaderStd *tl,
- ThumbLoaderStdFunc func_done,
- ThumbLoaderStdFunc func_error,
- ThumbLoaderStdFunc func_progress,
+ ThumbLoaderStd::Func func_done,
+ ThumbLoaderStd::Func func_error,
+ ThumbLoaderStd::Func func_progress,
gpointer data)
{
if (!tl) return;
static void thumb_loader_std_reset(ThumbLoaderStd *tl)
{
image_loader_free(tl->il);
- tl->il = NULL;
+ tl->il = nullptr;
file_data_unref(tl->fd);
- tl->fd = NULL;
+ tl->fd = nullptr;
g_free(tl->thumb_path);
- tl->thumb_path = NULL;
+ tl->thumb_path = nullptr;
g_free(tl->thumb_uri);
- tl->thumb_uri = NULL;
- tl->local_uri = NULL;
+ tl->thumb_uri = nullptr;
+ tl->local_uri = nullptr;
tl->thumb_path_local = FALSE;
static gchar *thumb_std_cache_path(const gchar *path, const gchar *uri, gboolean local,
const gchar *cache_subfolder)
{
- gchar *result = NULL;
+ gchar *result = nullptr;
gchar *md5_text;
- guchar digest[16];
gchar *name;
- if (!path || !uri || !cache_subfolder) return NULL;
+ if (!path || !uri || !cache_subfolder) return nullptr;
- md5_get_digest((guchar *)uri, strlen(uri), digest);
- md5_text = md5_digest_to_text(digest);
+ md5_text = md5_get_string(reinterpret_cast<const guchar *>(uri), strlen(uri));
- if (!md5_text) return NULL;
+ if (!md5_text) return nullptr;
name = g_strconcat(md5_text, THUMB_NAME_EXTENSION, NULL);
static gchar *thumb_loader_std_cache_path(ThumbLoaderStd *tl, gboolean local, GdkPixbuf *pixbuf, gboolean fail)
{
const gchar *folder;
- gint w, h;
+ gint w;
+ gint h;
- if (!tl->fd || !tl->thumb_uri) return NULL;
+ if (!tl->fd || !tl->thumb_uri) return nullptr;
if (pixbuf)
{
gchar *fail_path;
gboolean result = FALSE;
- fail_path = thumb_loader_std_cache_path(tl, FALSE, NULL, TRUE);
+ fail_path = thumb_loader_std_cache_path(tl, FALSE, nullptr, TRUE);
if (isfile(fail_path))
{
GdkPixbuf *pixbuf;
if (tl->cache_retry)
{
- pixbuf = NULL;
+ pixbuf = nullptr;
}
else
{
gchar *pathl;
pathl = path_from_utf8(fail_path);
- pixbuf = gdk_pixbuf_new_from_file(pathl, NULL);
+ pixbuf = gdk_pixbuf_new_from_file(pathl, nullptr);
g_free(pathl);
}
const gchar *mtime_str;
mtime_str = gdk_pixbuf_get_option(pixbuf, THUMB_MARKER_MTIME);
- if (mtime_str && strtol(mtime_str, NULL, 10) == tl->source_mtime)
+ if (mtime_str && strtol(mtime_str, nullptr, 10) == tl->source_mtime)
{
result = TRUE;
DEBUG_1("thumb fail valid: %s", tl->fd->path);
const gchar *uri;
const gchar *mtime_str;
time_t mtime;
- gint w, h;
+ gint w;
+ gint h;
if (!pixbuf) return FALSE;
if (!mtime_str || !uri || !valid_uri) return FALSE;
if (strcmp(uri, valid_uri) != 0) return FALSE;
- mtime = strtol(mtime_str, NULL, 10);
+ mtime = strtol(mtime_str, nullptr, 10);
if (tl->source_mtime != mtime) return FALSE;
return TRUE;
}
else
{
- recursive_mkdir_if_not_exists(base_path, THUMB_PERMS_FOLDER);
+ recursive_mkdir_if_not_exists(base_path, S_IRWXU);
}
g_free(base_path);
mark_uri = (tl->cache_local) ? tl->local_uri :tl->thumb_uri;
mark_app = g_strdup_printf("%s %s", GQ_APPNAME, VERSION);
- mark_mtime = g_strdup_printf("%llu", (unsigned long long)tl->source_mtime);
+ mark_mtime = g_strdup_printf("%llu", static_cast<unsigned long long>(tl->source_mtime));
pathl = path_from_utf8(tmp_path);
- success = gdk_pixbuf_save(pixbuf, pathl, "png", NULL,
+ success = gdk_pixbuf_save(pixbuf, pathl, "png", nullptr,
THUMB_MARKER_URI, mark_uri,
THUMB_MARKER_MTIME, mark_mtime,
THUMB_MARKER_APP, mark_app,
NULL);
if (success)
{
- chmod(pathl, (tl->cache_local) ? tl->source_mode : THUMB_PERMS_THUMB);
+ chmod(pathl, (tl->cache_local) ? tl->source_mode : S_IRUSR & S_IWUSR);
success = rename_file(tmp_path, tl->thumb_path);
}
void thumb_loader_std_calibrate_pixbuf(FileData *fd, GdkPixbuf *pixbuf) {
- ColorMan *cm = NULL;
- ExifData *exif = NULL;
+ ColorMan *cm = nullptr;
+ ExifData *exif = nullptr;
gint color_profile_from_image = COLOR_PROFILE_NONE;
ColorManProfileType input_type = COLOR_PROFILE_MEM;
ColorManProfileType screen_type;
- const gchar *input_file = NULL;
- guchar *profile = NULL;
+ const gchar *input_file = nullptr;
+ guchar *profile = nullptr;
guint profile_len;
- gint sw, sh;
+ gint sw;
+ gint sh;
if (!options->thumbnails.use_color_management)
{
if (profile)
{
- cm = color_man_new_embedded(NULL, pixbuf,
+ cm = color_man_new_embedded(nullptr, pixbuf,
profile, profile_len,
- screen_type, NULL, NULL, 0);
+ screen_type, nullptr, nullptr, 0);
g_free(profile);
}
else
{
- cm = color_man_new(NULL, pixbuf,
+ cm = color_man_new(nullptr, pixbuf,
input_type, input_file,
- screen_type, NULL, NULL, 0);
+ screen_type, nullptr, nullptr, 0);
}
if(cm) {
static GdkPixbuf *thumb_loader_std_finish(ThumbLoaderStd *tl, GdkPixbuf *pixbuf, gboolean shrunk)
{
- GdkPixbuf *pixbuf_thumb = NULL;
+ GdkPixbuf *pixbuf_thumb = nullptr;
GdkPixbuf *result;
- GdkPixbuf *rotated = NULL;
- gint sw, sh;
+ GdkPixbuf *rotated = nullptr;
+ gint sw;
+ gint sh;
if (!tl->cache_hit && options->image.exif_rotate_enable)
{
if (!tl->cache_hit)
{
- gint cache_w, cache_h;
+ gint cache_w;
+ gint cache_h;
if (tl->requested_width > THUMB_SIZE_NORMAL || tl->requested_height > THUMB_SIZE_NORMAL)
{
if (sw > cache_w || sh > cache_h || shrunk)
{
- gint thumb_w, thumb_h;
+ gint thumb_w;
+ gint thumb_h;
struct stat st;
if (pixbuf_scale_aspect(cache_w, cache_h, sw, sh,
&thumb_w, &thumb_h))
{
pixbuf_thumb = gdk_pixbuf_scale_simple(pixbuf, thumb_w, thumb_h,
- (GdkInterpType)options->thumbnails.quality);
+ static_cast<GdkInterpType>(options->thumbnails.quality));
}
else
{
* so specifically save as a local thumbnail.
*/
g_free(tl->thumb_path);
- tl->thumb_path = NULL;
+ tl->thumb_path = nullptr;
tl->cache_hit = FALSE;
}
else
{
- gint thumb_w, thumb_h;
+ gint thumb_w;
+ gint thumb_h;
if (pixbuf_thumb)
{
&thumb_w, &thumb_h))
{
result = gdk_pixbuf_scale_simple(pixbuf, thumb_w, thumb_h,
- (GdkInterpType)options->thumbnails.quality);
+ static_cast<GdkInterpType>(options->thumbnails.quality));
}
else
{
static gboolean thumb_loader_std_next_source(ThumbLoaderStd *tl, gboolean remove_broken)
{
image_loader_free(tl->il);
- tl->il = NULL;
+ tl->il = nullptr;
if (tl->thumb_path)
{
}
g_free(tl->thumb_path);
- tl->thumb_path = NULL;
+ tl->thumb_path = nullptr;
if (!tl->thumb_path_local)
{
- tl->thumb_path = thumb_loader_std_cache_path(tl, TRUE, NULL, FALSE);
+ tl->thumb_path = thumb_loader_std_cache_path(tl, TRUE, nullptr, FALSE);
if (isfile(tl->thumb_path))
{
FileData *fd = file_data_new_no_grouping(tl->thumb_path);
}
g_free(tl->thumb_path);
- tl->thumb_path = NULL;
+ tl->thumb_path = nullptr;
}
if (thumb_loader_std_setup(tl, tl->fd)) return TRUE;
}
- thumb_loader_std_save(tl, NULL);
+ thumb_loader_std_save(tl, nullptr);
return FALSE;
}
return;
}
- tl->cache_hit = (tl->thumb_path != NULL);
+ tl->cache_hit = (tl->thumb_path != nullptr);
if (tl->fd)
{
auto tl = static_cast<ThumbLoaderStd *>(data);
/* if at least some of the image is available, go to done */
- if (image_loader_get_pixbuf(tl->il) != NULL)
+ if (image_loader_get_pixbuf(tl->il) != nullptr)
{
thumb_loader_std_done_cb(il, data);
return;
if (tl->func_error) tl->func_error(tl, tl->data);
}
-static void thumb_loader_std_progress_cb(ImageLoader *UNUSED(il), gdouble percent, gpointer data)
+static void thumb_loader_std_progress_cb(ImageLoader *, gdouble percent, gpointer data)
{
auto tl = static_cast<ThumbLoaderStd *>(data);
- tl->progress = (gdouble)percent;
+ tl->progress = percent;
if (tl->func_progress) tl->func_progress(tl, tl->data);
}
}
image_loader_free(tl->il);
- tl->il = NULL;
+ tl->il = nullptr;
return FALSE;
}
gboolean thumb_loader_std_start(ThumbLoaderStd *tl, FileData *fd)
{
- static gchar *thumb_cache = NULL;
+ static gchar *thumb_cache = nullptr;
struct stat st;
if (!tl || !fd) return FALSE;
gchar *pathl;
pathl = path_from_utf8(fd->path);
- tl->thumb_uri = g_filename_to_uri(pathl, NULL, NULL);
+ tl->thumb_uri = g_filename_to_uri(pathl, nullptr, nullptr);
tl->local_uri = filename_from_path(tl->thumb_uri);
g_free(pathl);
}
{
gint found;
- tl->thumb_path = thumb_loader_std_cache_path(tl, FALSE, NULL, FALSE);
+ tl->thumb_path = thumb_loader_std_cache_path(tl, FALSE, nullptr, FALSE);
tl->thumb_path_local = FALSE;
found = isfile(tl->thumb_path);
if (!thumb_loader_std_setup(tl, tl->fd))
{
- thumb_loader_std_save(tl, NULL);
+ thumb_loader_std_save(tl, nullptr);
thumb_loader_std_set_fallback(tl);
return FALSE;
}
}
else
{
- pixbuf = pixbuf_fallback(NULL, tl->requested_width, tl->requested_height);
+ pixbuf = pixbuf_fallback(nullptr, tl->requested_width, tl->requested_height);
}
return pixbuf;
}
-typedef struct _ThumbValidate ThumbValidate;
-struct _ThumbValidate
+struct ThumbValidate
{
ThumbLoaderStd *tl;
gchar *path;
thumb_loader_std_thumb_file_validate_free(tv);
}
-static void thumb_loader_std_thumb_file_validate_done_cb(ThumbLoaderStd *UNUSED(tl), gpointer data)
+static void thumb_loader_std_thumb_file_validate_done_cb(ThumbLoaderStd *, gpointer data)
{
auto tv = static_cast<ThumbValidate *>(data);
GdkPixbuf *pixbuf;
struct stat st;
gchar *target;
- target = g_filename_from_uri(uri, NULL, NULL);
+ target = g_filename_from_uri(uri, nullptr, nullptr);
if (stat(target, &st) == 0 &&
- st.st_mtime == strtol(mtime_str, NULL, 10))
+ st.st_mtime == strtol(mtime_str, nullptr, 10))
{
valid = TRUE;
}
{
time_t now;
- now = time(NULL);
- if (st.st_atime >= now - (time_t)tv->days * 24 * 60 * 60)
+ now = time(nullptr);
+ if (st.st_atime >= now - static_cast<time_t>(tv->days) * 24 * 60 * 60)
{
valid = TRUE;
}
thumb_loader_std_thumb_file_validate_finish(tv, valid);
}
-static void thumb_loader_std_thumb_file_validate_error_cb(ThumbLoaderStd *UNUSED(tl), gpointer data)
+static void thumb_loader_std_thumb_file_validate_error_cb(ThumbLoaderStd *, gpointer data)
{
auto tv = static_cast<ThumbValidate *>(data);
thumb_loader_std_set_callbacks(tv->tl,
thumb_loader_std_thumb_file_validate_done_cb,
thumb_loader_std_thumb_file_validate_error_cb,
- NULL,
+ nullptr,
tv);
thumb_loader_std_reset(tv->tl);
gchar *sourcel;
sourcel = path_from_utf8(source);
- uri = g_filename_to_uri(sourcel, NULL, NULL);
+ uri = g_filename_to_uri(sourcel, nullptr, nullptr);
g_free(sourcel);
/* all this to remove a thumbnail? */
g_free(uri);
}
-typedef struct _TMaintMove TMaintMove;
-struct _TMaintMove
+struct TMaintMove
{
gchar *source;
gchar *dest;
gint pass;
};
-static GList *thumb_std_maint_move_list = NULL;
-static GList *thumb_std_maint_move_tail = NULL;
+static GList *thumb_std_maint_move_list = nullptr;
+static GList *thumb_std_maint_move_tail = nullptr;
static void thumb_std_maint_move_step(TMaintMove *tm);
static gboolean thumb_std_maint_move_idle(gpointer data);
-static void thumb_std_maint_move_validate_cb(const gchar *UNUSED(path), gboolean UNUSED(valid), gpointer data)
+static void thumb_std_maint_move_validate_cb(const gchar *, gboolean, gpointer data)
{
auto tm = static_cast<TMaintMove *>(data);
GdkPixbuf *pixbuf;
tm->tl->cache_local = FALSE;
file_data_unref(tm->tl->fd);
tm->tl->fd = file_data_new_group(tm->dest);
- tm->tl->source_mtime = strtol(mtime_str, NULL, 10);
+ tm->tl->source_mtime = strtol(mtime_str, nullptr, 10);
pathl = path_from_utf8(tm->tl->fd->path);
g_free(tm->tl->thumb_uri);
- tm->tl->thumb_uri = g_filename_to_uri(pathl, NULL, NULL);
+ tm->tl->thumb_uri = g_filename_to_uri(pathl, nullptr, nullptr);
tm->tl->local_uri = filename_from_path(tm->tl->thumb_uri);
g_free(pathl);
g_free(tm->tl->thumb_path);
- tm->tl->thumb_path = NULL;
+ tm->tl->thumb_path = nullptr;
tm->tl->thumb_path_local = FALSE;
DEBUG_1("thumb move attempting save:");
if (thumb_std_maint_move_list)
{
- g_idle_add_full(G_PRIORITY_LOW, thumb_std_maint_move_idle, NULL, NULL);
+ g_idle_add_full(G_PRIORITY_LOW, thumb_std_maint_move_idle, nullptr, nullptr);
}
return;
thumb_std_maint_move_validate_cb, tm);
}
-static gboolean thumb_std_maint_move_idle(gpointer UNUSED(data))
+static gboolean thumb_std_maint_move_idle(gpointer)
{
TMaintMove *tm;
gchar *pathl;
tm = static_cast<TMaintMove *>(thumb_std_maint_move_list->data);
thumb_std_maint_move_list = g_list_remove(thumb_std_maint_move_list, tm);
- if (!thumb_std_maint_move_list) thumb_std_maint_move_tail = NULL;
+ if (!thumb_std_maint_move_list) thumb_std_maint_move_tail = nullptr;
pathl = path_from_utf8(tm->source);
- tm->source_uri = g_filename_to_uri(pathl, NULL, NULL);
+ tm->source_uri = g_filename_to_uri(pathl, nullptr, nullptr);
g_free(pathl);
tm->pass = 0;
if (!thumb_std_maint_move_list)
{
- g_idle_add_full(G_PRIORITY_LOW, thumb_std_maint_move_idle, NULL, NULL);
+ g_idle_add_full(G_PRIORITY_LOW, thumb_std_maint_move_idle, nullptr, nullptr);
}
if (thumb_std_maint_move_tail)