/*
- * Geeqie
- * (C) 2006 John Ellis
- * Copyright (C) 2008 - 2012 The Geeqie Team
+ * Copyright (C) 2006 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 "filedata.h"
/* what I would like to use is printf("%'d", size)
* BUT: not supported on every libc :(
*/
- if (size > G_MAXUINT)
+ if (size > G_MAXINT)
{
/* the %lld conversion is not valid in all libcs, so use a simple work-around */
a = g_strdup_printf("%d%09d", (guint)(size / 1000000000), (guint)(size % 1000000000));
{
fd->size = st->st_size;
fd->date = st->st_mtime;
+ fd->cdate = st->st_ctime;
fd->mode = st->st_mode;
if (fd->thumb_pixbuf) g_object_unref(fd->thumb_pixbuf);
fd->thumb_pixbuf = NULL;
g_free(fd->collate_key_name);
g_free(fd->collate_key_name_nocase);
+#if GTK_CHECK_VERSION(2, 8, 0)
+ 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);
+ }
+#else
fd->collate_key_name = g_utf8_collate_key(valid_name, -1);
fd->collate_key_name_nocase = g_utf8_collate_key(caseless_name, -1);
+#endif
g_free(valid_name);
g_free(caseless_name);
if (fd)
{
DEBUG_1("planned change: using %s -> %s", path_utf8, fd->path);
- file_data_ref(fd);
- file_data_apply_ci(fd);
+ if (!isfile(fd->path))
+ {
+ file_data_ref(fd);
+ file_data_apply_ci(fd);
+ }
+ else
+ {
+ fd = NULL;
+ }
}
}
fd->size = st->st_size;
fd->date = st->st_mtime;
+ fd->cdate = st->st_ctime;
fd->mode = st->st_mode;
fd->ref = 1;
fd->magick = FD_MAGICK;
+ fd->exifdate = 0;
if (disable_sidecars) fd->disable_grouping = TRUE;
return fd;
}
-void init_exif_time_data(GList *files)
-{
- FileData *file;
- DEBUG_1("%s init_exif_time_data: ...", get_exec_time());
- while (files)
- {
- file = files->data;
-
- if (file)
- file->exifdate = 0;
-
- files = files->next;
- }
-}
-
void read_exif_time_data(FileData *file)
{
if (file->exifdate > 0)
g_free(fd->original_path);
g_free(fd->collate_key_name);
g_free(fd->collate_key_name_nocase);
+ g_free(fd->extended_extension);
if (fd->thumb_pixbuf) g_object_unref(fd->thumb_pixbuf);
histmap_free(fd->histmap);
target->sidecar_files = g_list_remove(target->sidecar_files, sfd);
sfd->parent = NULL;
+ g_free(sfd->extended_extension);
+ sfd->extended_extension = NULL;
file_data_unref(target);
file_data_unref(sfd);
if (fa->date > fb->date) return 1;
/* fall back to name */
break;
+ case SORT_CTIME:
+ if (fa->cdate < fb->cdate) return -1;
+ if (fa->cdate > fb->cdate) return 1;
+ /* fall back to name */
+ break;
case SORT_EXIFTIME:
if (fa->exifdate < fb->exifdate) return -1;
if (fa->exifdate > fb->exifdate) return 1;
list = g_hash_table_lookup(basename_hash, basename);
+ if (!list)
+ {
+ DEBUG_1("TG: basename_hash not found for %s",fd->path);
+ const gchar *parent_extension = registered_extension_from_path(basename);
+
+ if (parent_extension)
+ {
+ DEBUG_1("TG: parent extension %s",parent_extension);
+ gchar *parent_basename = g_strndup(basename, parent_extension - basename);
+ DEBUG_1("TG: parent basename %s",parent_basename);
+ FileData *parent_fd = g_hash_table_lookup(file_data_pool, basename);
+ if (parent_fd)
+ {
+ DEBUG_1("TG: parent fd found");
+ list = g_hash_table_lookup(basename_hash, parent_basename);
+ if (!g_list_find(list, parent_fd))
+ {
+ DEBUG_1("TG: parent fd doesn't fit");
+ g_free(parent_basename);
+ list = NULL;
+ }
+ else
+ {
+ g_free(basename);
+ basename = parent_basename;
+ fd->extended_extension = g_strconcat(parent_extension, fd->extension, NULL);
+ }
+ }
+ }
+ }
+
if (!g_list_find(list, fd))
{
list = g_list_insert_sorted(list, file_data_ref(fd), file_data_sort_by_ext);
return list;
}
+static void file_data_basename_hash_insert_cb(gpointer fd, gpointer basename_hash)
+{
+ file_data_basename_hash_insert((GHashTable *)basename_hash, (FileData *)fd);
+}
+
static void file_data_basename_hash_remove_list(gpointer key, gpointer value, gpointer data)
{
filelist_free((GList *)value);
gchar *pathl;
GList *dlist = NULL;
GList *flist = NULL;
+ GList *xmp_files = NULL;
gint (*stat_func)(const gchar *path, struct stat *buf);
GHashTable *basename_hash = NULL;
flist = g_list_prepend(flist, fd);
if (fd->sidecar_priority && !fd->disable_grouping)
{
- file_data_basename_hash_insert(basename_hash, fd);
+ if (strcmp(fd->extension, ".xmp") != 0)
+ file_data_basename_hash_insert(basename_hash, fd);
+ else
+ xmp_files = g_list_append(xmp_files, fd);
}
}
}
g_free(pathl);
+ if (xmp_files)
+ {
+ g_list_foreach(xmp_files,file_data_basename_hash_insert_cb,basename_hash);
+ g_list_free(xmp_files);
+ }
+
if (dirs) *dirs = dlist;
if (files)
}
if (basename_hash) file_data_basename_hash_free(basename_hash);
- // Call a separate function to initialize the exif datestamps for the found files..
- if (files) init_exif_time_data(*files);
-
return TRUE;
}
if (!file_data_can_write_sidecar(fd)) return NULL;
work = fd->parent ? fd->parent->sidecar_files : fd->sidecar_files;
+ gchar *extended_extension = g_strconcat(fd->parent ? fd->parent->extension : fd->extension, ".xmp", NULL);
while (work)
{
FileData *sfd = work->data;
work = work->next;
- if (g_ascii_strcasecmp(sfd->extension, ".xmp") == 0)
+ if (g_ascii_strcasecmp(sfd->extension, ".xmp") == 0 || g_ascii_strcasecmp(sfd->extension, extended_extension) == 0)
{
sidecar_path = g_strdup(sfd->path);
break;
}
}
+ g_free(extended_extension);
if (!existing_only && !sidecar_path)
{
- gchar *base = g_strndup(fd->path, fd->extension - fd->path);
- sidecar_path = g_strconcat(base, ".xmp", NULL);
- g_free(base);
+ if (options->metadata.sidecar_extended_name)
+ sidecar_path = g_strconcat(fd->path, ".xmp", NULL);
+ else
+ {
+ gchar *base = g_strndup(fd->path, fd->extension - fd->path);
+ sidecar_path = g_strconcat(base, ".xmp", NULL);
+ g_free(base);
+ }
}
return sidecar_path;
file_data_mark_func_data[n] = data;
file_data_destroy_mark_func[n] = notify;
- if (get_mark_func)
+ 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);
static void file_data_update_ci_dest_preserve_ext(FileData *fd, const gchar *dest_path)
{
- const gchar *extension = extension_from_path(fd->change->source);
+ const gchar *extension = registered_extension_from_path(fd->change->source);
gchar *base = remove_extension_from_path(dest_path);
gchar *old_path = fd->change->dest;
- fd->change->dest = g_strconcat(base, extension, NULL);
+ fd->change->dest = g_strconcat(base, fd->extended_extension ? fd->extended_extension : extension, NULL);
file_data_update_planned_change_hash(fd, old_path, fd->change->dest);
g_free(old_path);
* it should detect all possible problems with the planned operation
*/
-gint file_data_verify_ci(FileData *fd)
+gint file_data_verify_ci(FileData *fd, GList *list)
{
gint ret = CHANGE_OK;
gchar *dir;
+ GList *work = NULL;
+ FileData *fd1 = NULL;
if (!fd->change)
{
if (!same)
{
- const gchar *dest_ext = extension_from_path(fd->change->dest);
+ const gchar *dest_ext = registered_extension_from_path(fd->change->dest);
if (!dest_ext) dest_ext = "";
-
- if (g_ascii_strcasecmp(fd->extension, dest_ext) != 0)
+ if (!options->file_filter.disable_file_extension_checks)
{
- ret |= CHANGE_WARN_CHANGED_EXT;
- DEBUG_1("Change checked: source and destination have different extensions: %s -> %s", fd->path, fd->change->dest);
+ if (g_ascii_strcasecmp(fd->extension, dest_ext) != 0)
+ {
+ ret |= CHANGE_WARN_CHANGED_EXT;
+ DEBUG_1("Change checked: source and destination have different extensions: %s -> %s", fd->path, fd->change->dest);
+ }
}
}
else
g_free(dest_dir);
}
+ /* During a rename operation, check if another planned destination file has
+ * the same filename
+ */
+ if(fd->change->type == FILEDATA_CHANGE_RENAME ||
+ fd->change->type == FILEDATA_CHANGE_COPY ||
+ fd->change->type == FILEDATA_CHANGE_MOVE)
+ {
+ work = list;
+ while (work)
+ {
+ fd1 = work->data;
+ work = work->next;
+ if (fd1 != NULL && fd != fd1 )
+ {
+ if (!strcmp(fd->change->dest, fd1->change->dest))
+ {
+ ret |= CHANGE_DUPLICATE_DEST;
+ }
+ }
+ }
+ }
+
fd->change->error = ret;
if (ret == 0) DEBUG_1("Change checked: OK: %s", fd->path);
}
-gint file_data_sc_verify_ci(FileData *fd)
+gint file_data_sc_verify_ci(FileData *fd, GList *list)
{
GList *work;
gint ret;
- ret = file_data_verify_ci(fd);
+ ret = file_data_verify_ci(fd, list);
work = fd->sidecar_files;
while (work)
{
FileData *sfd = work->data;
- ret |= file_data_verify_ci(sfd);
+ ret |= file_data_verify_ci(sfd, list);
work = work->next;
}
g_string_append(result, _("there are unsaved metadata changes for the file"));
}
+ if (error & CHANGE_DUPLICATE_DEST)
+ {
+ if (result->len > 0) g_string_append(result, ", ");
+ g_string_append(result, _("another destination file has the same filename"));
+ }
+
return g_string_free(result, FALSE);
}
fd = work->data;
work = work->next;
- error = with_sidecars ? file_data_sc_verify_ci(fd) : file_data_verify_ci(fd);
+ error = with_sidecars ? file_data_sc_verify_ci(fd, list) : file_data_verify_ci(fd, list);
all_errors |= error;
common_errors &= error;
void file_data_send_notification(FileData *fd, NotifyType type)
{
+ GList *work = notify_func_list;
+
+ while (work)
+ {
+ NotifyData *nd = (NotifyData *)work->data;
+
+ nd->func(fd, type, nd->data);
+ work = work->next;
+ }
+ /*
NotifyIdleData *nid = g_new0(NotifyIdleData, 1);
nid->fd = file_data_ref(fd);
nid->type = type;
g_idle_add_full(G_PRIORITY_HIGH, file_data_send_notification_idle_cb, nid, NULL);
+ */
}
static GHashTable *file_data_monitor_pool = NULL;