* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
-#include "main.h"
#include "filedata.h"
-#include "filefilter.h"
+#include <config.h>
+
#include "cache.h"
-#include "thumb-standard.h"
-#include "ui-fileops.h"
-#include "metadata.h"
-#include "trash.h"
+#include "debug.h"
+#include "filefilter.h"
#include "histogram.h"
+#include "intl.h"
+#include "main-defines.h"
+#include "main.h"
+#include "metadata.h"
+#include "options.h"
#include "secure-save.h"
+#include "thumb-standard.h"
+#include "trash.h"
+#include "ui-fileops.h"
#include "exif.h"
#include "misc.h"
#include <grp.h>
+#include <pwd.h>
#ifdef DEBUG_FILEDATA
gint global_file_data_count = 0;
#endif
-static GHashTable *file_data_pool = NULL;
-static GHashTable *file_data_planned_change_hash = NULL;
+static GHashTable *file_data_pool = nullptr;
+static GHashTable *file_data_planned_change_hash = nullptr;
static gint sidecar_file_priority(const gchar *extension);
static void file_data_check_sidecars(const GList *basename_list);
static SortType filelist_sort_method = SORT_NONE;
static gboolean filelist_sort_ascend = TRUE;
+static gboolean filelist_sort_case = TRUE;
/*
*-----------------------------------------------------------------------------
gchar *text_from_size(gint64 size)
{
- gchar *a, *b;
- gchar *s, *d;
- gint l, n, i;
+ gchar *a;
+ gchar *b;
+ gchar *s;
+ gchar *d;
+ gint l;
+ gint n;
+ gint i;
/* what I would like to use is printf("%'d", size)
* BUT: not supported on every libc :(
/* note: returned string is valid until next call to text_from_time() */
const gchar *text_from_time(time_t t)
{
- static gchar *ret = NULL;
+ static gchar *ret = nullptr;
gchar buf[128];
gint buflen;
struct tm *btime;
- GError *error = NULL;
+ GError *error = nullptr;
btime = localtime(&t);
if (buflen < 1) return "";
g_free(ret);
- ret = g_locale_to_utf8(buf, buflen, NULL, NULL, &error);
+ ret = g_locale_to_utf8(buf, buflen, nullptr, nullptr, &error);
if (error)
{
log_printf("Error converting locale strftime to UTF-8: %s\n", error->message);
fd->cdate = st->st_ctime;
fd->mode = st->st_mode;
if (fd->thumb_pixbuf) g_object_unref(fd->thumb_pixbuf);
- fd->thumb_pixbuf = NULL;
+ fd->thumb_pixbuf = nullptr;
file_data_increment_version(fd);
file_data_send_notification(fd, NOTIFY_REREAD);
return TRUE;
{
GList *sidecars;
GList *work;
- FileData *sfd = NULL;
+ FileData *sfd = nullptr;
/* parent is missing, we have to rebuild whole group */
ret = TRUE;
g_free(fd->collate_key_name);
g_free(fd->collate_key_name_nocase);
- if (options->file_sort.natural)
- {
- fd->collate_key_name = g_utf8_collate_key_for_filename(fd->name, -1);
- fd->collate_key_name_nocase = g_utf8_collate_key_for_filename(caseless_name, -1);
- }
- else
- {
- fd->collate_key_name = g_utf8_collate_key(valid_name, -1);
- fd->collate_key_name_nocase = g_utf8_collate_key(caseless_name, -1);
- }
+ fd->collate_key_name_natural = g_utf8_collate_key_for_filename(fd->name, -1);
+ fd->collate_key_name_nocase_natural = g_utf8_collate_key_for_filename(caseless_name, -1);
+ fd->collate_key_name = g_utf8_collate_key(valid_name, -1);
+ fd->collate_key_name_nocase = g_utf8_collate_key(caseless_name, -1);
g_free(valid_name);
g_free(caseless_name);
file_data_set_collate_keys(fd);
return;
}
- else if (strcmp(fd->name, ".") == 0)
+
+ if (strcmp(fd->name, ".") == 0)
{
g_free(fd->path);
fd->path = remove_level_from_path(path);
}
fd->extension = registered_extension_from_path(fd->path);
- if (fd->extension == NULL)
+ if (fd->extension == nullptr)
{
fd->extension = fd->name + strlen(fd->name);
}
}
else
{
- fd = NULL;
+ fd = nullptr;
}
}
}
if (fd)
{
- gboolean changed;
-
if (disable_sidecars) file_data_disable_grouping(fd, TRUE);
-
- changed = file_data_check_changed_single_file(fd, st);
+#ifdef DEBUG_FILEDATA
+ gboolean changed =
+#endif
+ file_data_check_changed_single_file(fd, st);
DEBUG_2("file_data_pool hit: '%s' %s", fd->path, changed ? "(changed)" : "");
if (tmp)
{
struct tm time_str;
- uint year, month, day, hour, min, sec;
+ uint year;
+ uint month;
+ uint day;
+ uint hour;
+ uint min;
+ uint sec;
sscanf(tmp, "%4u:%2u:%2u %2u:%2u:%2u", &year, &month, &day, &hour, &min, &sec);
time_str.tm_year = year - 1900;
if (tmp)
{
struct tm time_str;
- uint year, month, day, hour, min, sec;
+ uint year;
+ uint month;
+ uint day;
+ uint hour;
+ uint min;
+ uint sec;
sscanf(tmp, "%4u:%2u:%2u %2u:%2u:%2u", &year, &month, &day, &hour, &min, &sec);
time_str.tm_year = year - 1900;
}
}
-//void set_exif_time_data(GList *files)
-//{
- //DEBUG_1("%s set_exif_time_data: ...", get_exec_time());
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wunused-function"
+void set_exif_time_data_unused(GList *files)
+{
+ DEBUG_1("%s set_exif_time_data: ...", get_exec_time());
- //while (files)
- //{
- //FileData *file = files->data;
+ while (files)
+ {
+ auto *file = static_cast<FileData *>(files->data);
- //read_exif_time_data(file);
- //files = files->next;
- //}
-//}
+ read_exif_time_data(file);
+ files = files->next;
+ }
+}
-//void set_exif_time_digitized_data(GList *files)
-//{
- //DEBUG_1("%s set_exif_time_digitized_data: ...", get_exec_time());
+void set_exif_time_digitized_data_unused(GList *files)
+{
+ DEBUG_1("%s set_exif_time_digitized_data: ...", get_exec_time());
- //while (files)
- //{
- //FileData *file = files->data;
+ while (files)
+ {
+ auto *file = static_cast<FileData *>(files->data);
- //read_exif_time_digitized_data(file);
- //files = files->next;
- //}
-//}
+ read_exif_time_digitized_data(file);
+ files = files->next;
+ }
+}
-//void set_rating_data(GList *files)
-//{
- //gchar *rating_str;
- //DEBUG_1("%s set_rating_data: ...", get_exec_time());
+void set_rating_data_unused(GList *files)
+{
+ gchar *rating_str;
+ DEBUG_1("%s set_rating_data: ...", get_exec_time());
- //while (files)
- //{
- //FileData *file = files->data;
- //rating_str = metadata_read_string(file, RATING_KEY, METADATA_PLAIN);
- //if (rating_str )
- //{
- //file->rating = atoi(rating_str);
- //g_free(rating_str);
- //}
- //files = files->next;
- //}
-//}
+ while (files)
+ {
+ auto *file = static_cast<FileData *>(files->data);
+ rating_str = metadata_read_string(file, RATING_KEY, METADATA_PLAIN);
+ if (rating_str )
+ {
+ file->rating = atoi(rating_str);
+ g_free(rating_str);
+ }
+ files = files->next;
+ }
+}
+#pragma GCC diagnostic pop
FileData *file_data_new_no_grouping(const gchar *path_utf8)
{
FileData *file_data_ref(FileData *fd)
#endif
{
- if (fd == NULL) return NULL;
+ if (fd == nullptr) return nullptr;
if (fd->magick != FD_MAGICK)
#ifdef DEBUG_FILEDATA
log_printf("Error: fd magick mismatch @ %s:%d fd=%p", file, line, (void *)fd);
log_printf("%d", global_file_data_count);
log_printf("%d", g_list_length(list));
- while (list)
+ GList *work = list;
+ while (work)
{
- fd = static_cast<FileData *>(list->data);
+ fd = static_cast<FileData *>(work->data);
log_printf("%-4d %s", fd->ref, fd->path);
- list = list->next;
+ work = work->next;
}
g_list_free(list);
g_free(fd->group);
g_free(fd->sym_link);
g_free(fd->format_name);
- g_assert(fd->sidecar_files == NULL); /* sidecar files must be freed before calling this */
+ g_assert(fd->sidecar_files == nullptr); /* sidecar files must be freed before calling this */
- file_data_change_info_free(NULL, fd);
+ file_data_change_info_free(nullptr, fd);
g_free(fd);
}
DEBUG_2("file_data_consider_free: deleting '%s', parent '%s'",
fd->path, fd->parent ? parent->path : "-");
- work = parent->sidecar_files;
- while (work)
- {
- auto sfd = static_cast<FileData *>(work->data);
- file_data_free(sfd);
- work = work->next;
- }
-
- g_list_free(parent->sidecar_files);
- parent->sidecar_files = NULL;
+ g_list_free_full(parent->sidecar_files, reinterpret_cast<GDestroyNotify>(file_data_free));
+ parent->sidecar_files = nullptr;
file_data_free(parent);
}
void file_data_unref(FileData *fd)
#endif
{
- if (fd == NULL) return;
+ if (fd == nullptr) return;
if (fd->magick != FD_MAGICK)
#ifdef DEBUG_FILEDATA
log_printf("Error: fd magick mismatch @ %s:%d fd=%p", file, line, (void *)fd);
*/
void file_data_lock(FileData *fd)
{
- if (fd == NULL) return;
+ if (fd == nullptr) return;
if (fd->magick != FD_MAGICK) log_printf("Error: fd magick mismatch fd=%p", (void *)fd);
g_assert(fd->magick == FD_MAGICK);
*/
void file_data_unlock(FileData *fd)
{
- if (fd == NULL) return;
+ if (fd == nullptr) return;
if (fd->magick != FD_MAGICK) log_printf("Error: fd magick mismatch fd=%p", (void *)fd);
g_assert(fd->magick == FD_MAGICK);
gint i = 1;
GList *work;
- if (extension == NULL)
+ if (extension == nullptr)
return 0;
work = sidecar_ext_get_list();
/* all files in the list have ref count > 0 */
const GList *work;
- GList *s_work, *new_sidecars;
+ GList *s_work;
+ GList *new_sidecars;
FileData *parent_fd;
if (!basename_list) return;
DEBUG_2(" sidecar: %p %s", (void *)sfd, sfd->name);
}
- g_assert(fd->parent == NULL || fd->sidecar_files == NULL);
+ g_assert(fd->parent == nullptr || fd->sidecar_files == nullptr);
}
parent_fd = static_cast<FileData *>(basename_list->data);
{
auto fd = static_cast<FileData *>(work->data);
work = work->next;
- g_assert(fd->parent == NULL || fd->sidecar_files == NULL);
+ g_assert(fd->parent == nullptr || fd->sidecar_files == nullptr);
if (fd->parent)
{
FileData *old_parent = fd->parent;
- g_assert(old_parent->parent == NULL || old_parent->sidecar_files == NULL);
+ g_assert(old_parent->parent == nullptr || old_parent->sidecar_files == nullptr);
file_data_ref(old_parent);
file_data_disconnect_sidecar_file(old_parent, fd);
file_data_send_notification(old_parent, NOTIFY_REREAD);
while (fd->sidecar_files)
{
auto sfd = static_cast<FileData *>(fd->sidecar_files->data);
- g_assert(sfd->parent == NULL || sfd->sidecar_files == NULL);
+ g_assert(sfd->parent == nullptr || sfd->sidecar_files == nullptr);
file_data_ref(sfd);
file_data_disconnect_sidecar_file(fd, sfd);
file_data_send_notification(sfd, NOTIFY_REREAD);
}
file_data_send_notification(fd, NOTIFY_GROUPING);
- g_assert(fd->parent == NULL && fd->sidecar_files == NULL);
+ g_assert(fd->parent == nullptr && fd->sidecar_files == nullptr);
}
/* now we can form the new group */
work = basename_list->next;
- new_sidecars = NULL;
+ new_sidecars = nullptr;
while (work)
{
auto sfd = static_cast<FileData *>(work->data);
g_assert(sfd->magick == FD_MAGICK);
- g_assert(sfd->parent == NULL && sfd->sidecar_files == NULL);
+ g_assert(sfd->parent == nullptr && sfd->sidecar_files == nullptr);
sfd->parent = parent_fd;
new_sidecars = g_list_prepend(new_sidecars, sfd);
work = work->next;
}
- g_assert(parent_fd->sidecar_files == NULL);
+ g_assert(parent_fd->sidecar_files == nullptr);
parent_fd->sidecar_files = g_list_reverse(new_sidecars);
DEBUG_1("basename group changed for %s", parent_fd->path);
}
file_data_increment_version(sfd); /* increments both sfd and target */
target->sidecar_files = g_list_remove(target->sidecar_files, sfd);
- sfd->parent = NULL;
+ sfd->parent = nullptr;
g_free(sfd->extended_extension);
- sfd->extended_extension = NULL;
+ sfd->extended_extension = nullptr;
file_data_unref(target);
file_data_unref(sfd);
if (fa->format_class > fb->format_class) return 1;
/* fall back to name */
break;
+ case SORT_NUMBER:
+ ret = strcmp(fa->collate_key_name_natural, fb->collate_key_name_natural);
+ if (ret != 0) return ret;
+ /* fall back to name */
+ break;
default:
break;
}
- if (options->file_sort.case_sensitive)
+ if (filelist_sort_case)
ret = strcmp(fa->collate_key_name, fb->collate_key_name);
else
ret = strcmp(fa->collate_key_name_nocase, fb->collate_key_name_nocase);
return filelist_sort_compare_filedata(static_cast<FileData *>(a), static_cast<FileData *>(b));
}
-GList *filelist_sort_full(GList *list, SortType method, gboolean ascend, GCompareFunc cb)
+GList *filelist_sort_full(GList *list, SortType method, gboolean ascend, gboolean case_sensitive, GCompareFunc cb)
{
filelist_sort_method = method;
filelist_sort_ascend = ascend;
+ filelist_sort_case = case_sensitive;
return g_list_sort(list, cb);
}
-GList *filelist_insert_sort_full(GList *list, gpointer data, SortType method, gboolean ascend, GCompareFunc cb)
+GList *filelist_insert_sort_full(GList *list, gpointer data, SortType method, gboolean ascend, gboolean case_sensitive, GCompareFunc cb)
{
filelist_sort_method = method;
filelist_sort_ascend = ascend;
+ filelist_sort_case = case_sensitive;
return g_list_insert_sorted(list, data, cb);
}
-GList *filelist_sort(GList *list, SortType method, gboolean ascend)
+GList *filelist_sort(GList *list, SortType method, gboolean ascend, gboolean case_sensitive)
{
- return filelist_sort_full(list, method, ascend, reinterpret_cast<GCompareFunc>(filelist_sort_file_cb));
+ return filelist_sort_full(list, method, ascend, case_sensitive, reinterpret_cast<GCompareFunc>(filelist_sort_file_cb));
}
-//GList *filelist_insert_sort(GList *list, FileData *fd, SortType method, gboolean ascend)
-//{
- //return filelist_insert_sort_full(list, fd, method, ascend, (GCompareFunc) filelist_sort_file_cb);
-//}
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wunused-function"
+GList *filelist_insert_sort_unused(GList *list, FileData *fd, SortType method, gboolean ascend)
+{
+ return filelist_insert_sort_full(list, fd, method, ascend, ascend, (GCompareFunc) filelist_sort_file_cb);
+}
+#pragma GCC diagnostic pop
/*
*-----------------------------------------------------------------------------
*/
-static GHashTable *file_data_basename_hash_new(void)
+static GHashTable *file_data_basename_hash_new()
{
- return g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL);
+ return g_hash_table_new_full(g_str_hash, g_str_equal, g_free, nullptr);
}
static GList * file_data_basename_hash_insert(GHashTable *basename_hash, FileData *fd)
{
DEBUG_1("TG: parent fd doesn't fit");
g_free(parent_basename);
- list = NULL;
+ list = nullptr;
}
else
{
file_data_basename_hash_insert(static_cast<GHashTable *>(basename_hash), static_cast<FileData *>(fd));
}
-static void file_data_basename_hash_remove_list(gpointer UNUSED(key), gpointer value, gpointer UNUSED(data))
+static void file_data_basename_hash_remove_list(gpointer, gpointer value, gpointer)
{
filelist_free(static_cast<GList *>(value));
}
static void file_data_basename_hash_free(GHashTable *basename_hash)
{
- g_hash_table_foreach(basename_hash, file_data_basename_hash_remove_list, NULL);
+ g_hash_table_foreach(basename_hash, file_data_basename_hash_remove_list, nullptr);
g_hash_table_destroy(basename_hash);
}
static GList *filelist_filter_out_sidecars(GList *flist)
{
GList *work = flist;
- GList *flist_filtered = NULL;
+ GList *flist_filtered = nullptr;
while (work)
{
return flist_filtered;
}
-static void file_data_basename_hash_to_sidecars(gpointer UNUSED(key), gpointer value, gpointer UNUSED(data))
+static void file_data_basename_hash_to_sidecars(gpointer, gpointer value, gpointer)
{
auto basename_list = static_cast<GList *>(value);
file_data_check_sidecars(basename_list);
DIR *dp;
struct dirent *dir;
gchar *pathl;
- GList *dlist = NULL;
- GList *flist = NULL;
- GList *xmp_files = NULL;
+ GList *dlist = nullptr;
+ GList *flist = nullptr;
+ GList *xmp_files = nullptr;
gint (*stat_func)(const gchar *path, struct stat *buf);
- GHashTable *basename_hash = NULL;
+ GHashTable *basename_hash = nullptr;
g_assert(files || dirs);
- if (files) *files = NULL;
- if (dirs) *dirs = NULL;
+ if (files) *files = nullptr;
+ if (dirs) *dirs = nullptr;
pathl = path_from_utf8(dir_path);
if (!pathl) return FALSE;
dp = opendir(pathl);
- if (dp == NULL)
+ if (dp == nullptr)
{
g_free(pathl);
return FALSE;
else
stat_func = lstat;
- while ((dir = readdir(dp)) != NULL)
+ while ((dir = readdir(dp)) != nullptr)
{
struct stat ent_sbuf;
const gchar *name = dir->d_name;
{
/* we ignore the .thumbnails dir for cleanliness */
if (dirs &&
- !(name[0] == '.' && (name[1] == '\0' || (name[1] == '.' && name[2] == '\0'))) &&
+ (name[0] != '.' || (name[1] != '\0' && (name[1] != '.' || name[2] != '\0'))) &&
strcmp(name, GQ_CACHE_LOCAL_THUMB) != 0 &&
strcmp(name, GQ_CACHE_LOCAL_METADATA) != 0 &&
strcmp(name, THUMB_FOLDER_LOCAL) != 0)
if (files)
{
- g_hash_table_foreach(basename_hash, file_data_basename_hash_to_sidecars, NULL);
+ g_hash_table_foreach(basename_hash, file_data_basename_hash_to_sidecars, nullptr);
*files = filelist_filter_out_sidecars(flist);
}
dir = remove_level_from_path(path_utf8);
- filelist_read_real(dir, &files, NULL, TRUE);
+ filelist_read_real(dir, &files, nullptr, TRUE);
fd = static_cast<FileData *>(g_hash_table_lookup(file_data_pool, path_utf8));
if (!fd) fd = file_data_new(path_utf8, &st, TRUE);
GList *filelist_copy(GList *list)
{
- GList *new_list = NULL;
- GList *work;
+ GList *new_list = nullptr;
- work = list;
- while (work)
+ for (GList *work = list; work; work = work->next)
{
- FileData *fd;
-
- fd = static_cast<FileData *>(work->data);
- work = work->next;
+ auto fd = static_cast<FileData *>(work->data);
new_list = g_list_prepend(new_list, file_data_ref(fd));
}
GList *filelist_from_path_list(GList *list)
{
- GList *new_list = NULL;
+ GList *new_list = nullptr;
GList *work;
work = list;
GList *filelist_to_path_list(GList *list)
{
- GList *new_list = NULL;
+ GList *new_list = nullptr;
GList *work;
work = list;
{
auto fd = static_cast<FileData *>(work->data);
const gchar *name = fd->name;
+ GList *link = work;
+ work = work->next;
if ((!options->file_filter.show_hidden_files && is_hidden_file(name)) ||
(!is_dir_list && !filter_name_exists(name)) ||
(is_dir_list && name[0] == '.' && (strcmp(name, GQ_CACHE_LOCAL_THUMB) == 0 ||
strcmp(name, GQ_CACHE_LOCAL_METADATA) == 0)) )
{
- GList *link = work;
-
list = g_list_remove_link(list, link);
file_data_unref(fd);
g_list_free(link);
}
-
- work = work->next;
}
return list;
}
}
-static void filelist_recursive_append_full(GList **list, GList *dirs, SortType method, gboolean ascend)
+static void filelist_recursive_append_full(GList **list, GList *dirs, SortType method, gboolean ascend, gboolean case_sensitive)
{
GList *work;
if (filelist_read(fd, &f, &d))
{
f = filelist_filter(f, FALSE);
- f = filelist_sort_full(f, method, ascend, reinterpret_cast<GCompareFunc>(filelist_sort_file_cb));
+ f = filelist_sort_full(f, method, ascend, case_sensitive, reinterpret_cast<GCompareFunc>(filelist_sort_file_cb));
*list = g_list_concat(*list, f);
d = filelist_filter(d, TRUE);
d = filelist_sort_path(d);
- filelist_recursive_append_full(list, d, method, ascend);
+ filelist_recursive_append_full(list, d, method, ascend, case_sensitive);
filelist_free(d);
}
GList *list;
GList *d;
- if (!filelist_read(dir_fd, &list, &d)) return NULL;
+ if (!filelist_read(dir_fd, &list, &d)) return nullptr;
list = filelist_filter(list, FALSE);
list = filelist_sort_path(list);
return list;
}
-GList *filelist_recursive_full(FileData *dir_fd, SortType method, gboolean ascend)
+GList *filelist_recursive_full(FileData *dir_fd, SortType method, gboolean ascend, gboolean case_sensitive)
{
GList *list;
GList *d;
- if (!filelist_read(dir_fd, &list, &d)) return NULL;
+ if (!filelist_read(dir_fd, &list, &d)) return nullptr;
list = filelist_filter(list, FALSE);
- list = filelist_sort_full(list, method, ascend, reinterpret_cast<GCompareFunc>(filelist_sort_file_cb));
+ list = filelist_sort_full(list, method, ascend, case_sensitive, reinterpret_cast<GCompareFunc>(filelist_sort_file_cb));
d = filelist_filter(d, TRUE);
d = filelist_sort_path(d);
- filelist_recursive_append_full(&list, d, method, ascend);
+ filelist_recursive_append_full(&list, d, method, ascend, case_sensitive);
filelist_free(d);
return list;
g_free(fdci);
- if (fd) fd->change = NULL;
+ if (fd) fd->change = nullptr;
}
static gboolean file_data_can_write_directly(FileData *fd)
gchar *file_data_get_sidecar_path(FileData *fd, gboolean existing_only)
{
- gchar *sidecar_path = NULL;
+ gchar *sidecar_path = nullptr;
GList *work;
- if (!file_data_can_write_sidecar(fd)) return NULL;
+ if (!file_data_can_write_sidecar(fd)) return nullptr;
work = fd->parent ? fd->parent->sidecar_files : fd->sidecar_files;
gchar *extended_extension = g_strconcat(fd->parent ? fd->parent->extension : fd->extension, ".xmp", NULL);
gboolean file_data_filter_file_filter(FileData *fd, GRegex *filter)
{
- return g_regex_match(filter, fd->name, static_cast<GRegexMatchFlags>(0), NULL);
+ return g_regex_match(filter, fd->name, static_cast<GRegexMatchFlags>(0), nullptr);
}
GList *file_data_filter_file_filter_list(GList *list, GRegex *filter)
return list;
}
-static void file_data_notify_mark_func(gpointer UNUSED(key), gpointer value, gpointer UNUSED(user_data))
+static void file_data_notify_mark_func(gpointer, gpointer value, gpointer)
{
auto fd = static_cast<FileData *>(value);
file_data_increment_version(fd);
if (get_mark_func && file_data_pool)
{
/* this effectively changes all known files */
- g_hash_table_foreach(file_data_pool, file_data_notify_mark_func, NULL);
+ g_hash_table_foreach(file_data_pool, file_data_notify_mark_func, nullptr);
}
return TRUE;
if (data) *data = file_data_mark_func_data[n];
}
-//gint file_data_get_user_orientation(FileData *fd)
-//{
- //return fd->user_orientation;
-//}
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wunused-function"
+gint file_data_get_user_orientation_unused(FileData *fd)
+{
+ return fd->user_orientation;
+}
-//void file_data_set_user_orientation(FileData *fd, gint value)
-//{
- //if (fd->user_orientation == value) return;
+void file_data_set_user_orientation_unused(FileData *fd, gint value)
+{
+ if (fd->user_orientation == value) return;
- //fd->user_orientation = value;
- //file_data_increment_version(fd);
- //file_data_send_notification(fd, NOTIFY_ORIENTATION);
-//}
+ fd->user_orientation = value;
+ file_data_increment_version(fd);
+ file_data_send_notification(fd, NOTIFY_ORIENTATION);
+}
+#pragma GCC diagnostic pop
/*
if (g_hash_table_size(file_data_planned_change_hash) == 0)
{
g_hash_table_destroy(file_data_planned_change_hash);
- file_data_planned_change_hash = NULL;
+ file_data_planned_change_hash = nullptr;
DEBUG_1("planned change: empty");
}
}
g_free(fdci);
- fd->change = NULL;
+ fd->change = nullptr;
}
void file_data_set_regroup_when_finished(FileData *fd, gboolean enable)
work = work->next;
}
- file_data_add_ci(fd, type, NULL, NULL);
+ file_data_add_ci(fd, type, nullptr, nullptr);
work = fd->sidecar_files;
while (work)
{
auto sfd = static_cast<FileData *>(work->data);
- file_data_add_ci(sfd, type, NULL, NULL);
+ file_data_add_ci(sfd, type, nullptr, nullptr);
work = work->next;
}
gboolean file_data_add_ci_write_metadata(FileData *fd)
{
- return file_data_add_ci(fd, FILEDATA_CHANGE_WRITE_METADATA, NULL, NULL);
+ return file_data_add_ci(fd, FILEDATA_CHANGE_WRITE_METADATA, nullptr, nullptr);
}
void file_data_sc_free_ci(FileData *fd)
static void file_data_sc_update_ci(FileData *fd, const gchar *dest_path)
{
GList *work;
- gchar *dest_path_full = NULL;
+ gchar *dest_path_full = nullptr;
if (fd->parent) fd = fd->parent;
{
gint ret = CHANGE_OK;
gchar *dir;
- GList *work = NULL;
- FileData *fd1 = NULL;
+ GList *work = nullptr;
+ FileData *fd1 = nullptr;
if (!fd->change)
{
{
/* determine destination file */
gboolean have_dest = FALSE;
- gchar *dest_dir = NULL;
+ gchar *dest_dir = nullptr;
if (options->metadata.save_in_image_file)
{
/* If an existing metadata file exists, we will try writing to
* it's location regardless of the user's preference.
*/
- gchar *metadata_path = NULL;
+ gchar *metadata_path = nullptr;
#ifdef HAVE_EXIV2
/* but ignore XMP if we are not able to write it */
metadata_path = cache_find_location(CACHE_TYPE_XMP_METADATA, fd->path);
if (metadata_path && !access_file(metadata_path, W_OK))
{
g_free(metadata_path);
- metadata_path = NULL;
+ metadata_path = nullptr;
}
if (!metadata_path)
if (access_file(metadata_path, W_OK) || (!isname(metadata_path) && access_file(dest_dir, W_OK)))
{
file_data_update_ci_dest(fd, metadata_path);
- have_dest = TRUE;
}
else
{
{
fd1 = static_cast<FileData *>(work->data);
work = work->next;
- if (fd1 != NULL && fd != fd1 )
+ if (fd1 != nullptr && fd != fd1 )
{
if (!strcmp(fd->change->dest, fd1->change->dest))
{
{
if (isdir(fd->path) && !islink(fd->path))
return rmdir_utf8(fd->path);
- else
- if (options->file_ops.safe_delete_enable)
- return file_util_safe_unlink(fd->path);
- else
- return unlink_file(fd->path);
+
+ if (options->file_ops.safe_delete_enable)
+ return file_util_safe_unlink(fd->path);
+
+ return unlink_file(fd->path);
}
gboolean file_data_perform_ci(FileData *fd)
{
+ /** @FIXME When a directory that is a symbolic link is deleted,
+ * at this point fd->change is null because no FileDataChangeInfo
+ * has been set up. Therefore there is a seg. fault.
+ * This code simply aborts the delete.
+ */
+ if (!fd->change)
+ {
+ return FALSE;
+ }
+
FileDataChangeType type = fd->change->type;
switch (type)
GList *file_data_process_groups_in_selection(GList *list, gboolean ungroup, GList **ungrouped_list)
{
- GList *out = NULL;
+ GList *out = nullptr;
GList *work = list;
/* change partial groups to independent files */
implementation in view-file-list.cc */
-typedef struct _NotifyIdleData NotifyIdleData;
-
-struct _NotifyIdleData {
+struct NotifyIdleData {
FileData *fd;
NotifyType type;
};
-typedef struct _NotifyData NotifyData;
-
-struct _NotifyData {
+struct NotifyData {
FileDataNotifyFunc func;
gpointer data;
NotifyPriority priority;
};
-static GList *notify_func_list = NULL;
+static GList *notify_func_list = nullptr;
static gint file_data_notify_sort(gconstpointer a, gconstpointer b)
{
- auto nda = (NotifyData *)a;
- auto ndb = (NotifyData *)b;
+ auto nda = static_cast<const NotifyData *>(a);
+ auto ndb = static_cast<const NotifyData *>(b);
if (nda->priority < ndb->priority) return -1;
if (nda->priority > ndb->priority) return 1;
if (nd->func == func && nd->data == data)
{
notify_func_list = g_list_delete_link(notify_func_list, work);
- g_free(nd);
DEBUG_2("Notify func unregistered: %p", (void *)nd);
+ g_free(nd);
return TRUE;
}
work = work->next;
return FALSE;
}
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wunused-function"
+gboolean file_data_send_notification_idle_cb_unused(gpointer data)
+{
+ auto *nid = (NotifyIdleData *)data;
+ GList *work = notify_func_list;
-//gboolean file_data_send_notification_idle_cb(gpointer data)
-//{
- //NotifyIdleData *nid = (NotifyIdleData *)data;
- //GList *work = notify_func_list;
-
- //while (work)
- //{
- //NotifyData *nd = (NotifyData *)work->data;
+ while (work)
+ {
+ auto *nd = (NotifyData *)work->data;
- //nd->func(nid->fd, nid->type, nd->data);
- //work = work->next;
- //}
- //file_data_unref(nid->fd);
- //g_free(nid);
- //return FALSE;
-//}
+ nd->func(nid->fd, nid->type, nd->data);
+ work = work->next;
+ }
+ file_data_unref(nid->fd);
+ g_free(nid);
+ return FALSE;
+}
+#pragma GCC diagnostic pop
void file_data_send_notification(FileData *fd, NotifyType type)
{
*/
}
-static GHashTable *file_data_monitor_pool = NULL;
+static GHashTable *file_data_monitor_pool = nullptr;
static guint realtime_monitor_id = 0; /* event source id */
-static void realtime_monitor_check_cb(gpointer key, gpointer UNUSED(value), gpointer UNUSED(data))
+static void realtime_monitor_check_cb(gpointer key, gpointer, gpointer)
{
auto fd = static_cast<FileData *>(key);
DEBUG_1("monitor %s", fd->path);
}
-static gboolean realtime_monitor_cb(gpointer UNUSED(data))
+static gboolean realtime_monitor_cb(gpointer)
{
if (!options->update_on_time_change) return TRUE;
- g_hash_table_foreach(file_data_monitor_pool, realtime_monitor_check_cb, NULL);
+ g_hash_table_foreach(file_data_monitor_pool, realtime_monitor_check_cb, nullptr);
return TRUE;
}
if (!realtime_monitor_id)
{
- realtime_monitor_id = g_timeout_add(5000, realtime_monitor_cb, NULL);
+ realtime_monitor_id = g_timeout_add(5000, realtime_monitor_cb, nullptr);
}
return TRUE;
{
if (s_buf[0]=='#') continue;
file_path = strtok(s_buf, ",");
- marks_value = strtok(NULL, ",");
+ marks_value = strtok(nullptr, ",");
if (isfile(file_path))
{
FileData *fd = file_data_new_no_grouping(file_path);
{
SecureSaveInfo *ssi;
gchar *pathl;
- GString *marks = g_string_new("");
pathl = path_from_utf8(path);
ssi = secure_open(pathl);
secure_fprintf(ssi, "#Marks lists\n");
+ GString *marks = g_string_new("");
if (save)
{
g_hash_table_foreach(file_data_pool, marks_get_files, marks);
}
secure_fprintf(ssi, "%s", marks->str);
- g_string_free(marks, FALSE);
+ g_string_free(marks, TRUE);
secure_fprintf(ssi, "#end\n");
return (secure_close(ssi) == 0);
}
-static void marks_clear(gpointer key, gpointer value, gpointer UNUSED(userdata))
+static void marks_clear(gpointer key, gpointer value, gpointer)
{
auto file_name = static_cast<gchar *>(key);
gint mark_no;
void marks_clear_all()
{
- g_hash_table_foreach(file_data_pool, marks_clear, NULL);
+ g_hash_table_foreach(file_data_pool, marks_clear, nullptr);
}
void file_data_set_page_num(FileData *fd, gint page_num)