Merge branch 'master' into ke-lua
authorKlaus Ethgen <Klaus@Ethgen.de>
Tue, 2 Oct 2012 21:19:13 +0000 (22:19 +0100)
committerKlaus Ethgen <Klaus@Ethgen.de>
Tue, 2 Oct 2012 21:23:24 +0000 (22:23 +0100)
* master: (185 commits)
  better fix for big-endian architectures
  Minor indentation fixes.
  Cleanup checker shader code.
  Fix exif orientation in clutter rendering mode.
  Silent 2 warnings using explicit type casting.
  Polish translation was updated, thanks to Grzegorz Gibas.
  Update pt_BR translation.
  Add *~, *.rej, *.orig files to git ignore list.
  Fix for support >=automake-1.11.4
  Trim trailing white spaces on empty lines.
  Trim trailing white spaces.
  Add missing vim modeline.
  Fix indentation and few trailing white spaces.
  Clear few more warnings, unused variables mostly.
  Drop unused variable.
  Remove commented out code.
  Remove commented out code.
  Remove commented out code.
  Remove commented out code.
  Remove commented out code.
  ...

1  2 
configure.in
src/Makefile.am
src/filedata.c
src/image-overlay.c
src/main.c

diff --combined configure.in
@@@ -2,7 -2,7 +2,7 @@@ dnl Process this file with autoconf to 
   -*-
  
  dnl This file is a part of Geeqie project (http://geeqie.sourceforge.net/).
- dnl Copyright (C) 2008 - 2010 The Geeqie Team
+ dnl Copyright (C) 2008 - 2012 The Geeqie Team
  dnl
  dnl This program is free software; you can redistribute it and/or modify
  dnl it under the terms of the GNU General Public License as published by
@@@ -15,7 -15,7 +15,7 @@@ dnl MERCHANTABILITY or FITNESS FOR A PA
  dnl GNU General Public License for more details.
  
  AC_PREREQ(2.57)
- AC_INIT(geeqie, 1.0, geeqie-devel@lists.sourceforge.net)
+ AC_INIT(geeqie, 1.1, geeqie-devel@lists.sourceforge.net)
  
  # Check for rightly dirs
  AC_CONFIG_SRCDIR([src/main.c])
@@@ -128,6 -128,7 +128,7 @@@ AC_PROG_C
  AC_PROG_CXX
  AC_STDC_HEADERS
  AC_ARG_PROGRAM
+ AC_SYS_LARGEFILE
  IT_PROG_INTLTOOL([0.35.0])
  
  
@@@ -188,8 -189,23 +189,23 @@@ els
    prefix=$prefix
  fi
  
- AM_PATH_GLIB_2_0(2.4.0,,AC_MSG_ERROR(GLIB >= 2.4.0 not installed.))
- AM_PATH_GTK_2_0(2.4.0,,AC_MSG_ERROR(GTK+ >= 2.4.0 not installed.))
+ AM_PATH_GLIB_2_0(2.24.0,,AC_MSG_ERROR(GLIB >= 2.24.0 not installed.))
+ AC_ARG_ENABLE([gtk3], AC_HELP_STRING([--disable-gtk3], [use gtk2 instead of gtk3]),[gtk3="${enableval}"], [gtk3=m4_ifdef([AM_PATH_GTK_3_0], [auto], [no])])
+ if test x$gtk3 == xyes; then
+     AC_MSG_WARN("Gtk3 enabled")
+     m4_ifdef([AM_PATH_GTK_3_0], [AM_PATH_GTK_3_0(3.0.0,,AC_MSG_ERROR(GTK+ >= 3.0.0 not installed.))])
+ else
+     if test x$gtk3 != xno; then
+        AC_MSG_WARN("Gtk3 is preferred...")
+        m4_ifdef([AM_PATH_GTK_3_0], [AM_PATH_GTK_3_0(3.0.0,,[gtk3=no])])
+     fi
+ fi
+ if test x$gtk3 == xno; then
+     m4_ifdef([AM_PATH_GTK_2_0], [AM_PATH_GTK_2_0(2.20.0,,AC_MSG_ERROR(GTK+ >= 2.20.0 not installed.))])
+     true
+ fi
  
  threads="auto"
  AC_ARG_ENABLE([threads],
@@@ -274,14 -290,22 +290,22 @@@ AC_ARG_ENABLE([lcms]
      [liblcms=$enableval], [liblcms=auto])
  
  if test "x${liblcms}" != "xno"; then
-   PKG_CHECK_MODULES(LCMS, [lcms >= 1.14],
+   PKG_CHECK_MODULES(LCMS, [lcms2 >= 2.0],
      [
        HAVE_LCMS=yes
        AC_DEFINE(HAVE_LCMS, 1, [define to enable use of color profiles with lcms])
+       AC_DEFINE(HAVE_LCMS2, 1, [lcms2 is used])
      ],
      [
-       HAVE_LCMS=no
-       AC_MSG_WARN([$LCMS_PKG_ERRORS])
+     PKG_CHECK_MODULES(LCMS, [lcms >= 1.14],
+       [
+         HAVE_LCMS=yes
+         AC_DEFINE(HAVE_LCMS, 1, [define to enable use of color profiles with lcms])
+       ],
+       [
+         HAVE_LCMS=no
+         AC_MSG_WARN([$LCMS_PKG_ERRORS])
+       ])
      ])
  else
    HAVE_LCMS=disabled
@@@ -380,15 -404,50 +404,50 @@@ AC_SUBST(CPPFLAGS
  AC_SUBST(LDFLAGS)
  
  
+ #  clutter support - experimental
+ # ----------------------------------------------------------------------
+ AC_ARG_ENABLE([clutter],
+   AC_HELP_STRING([--enable-clutter], [enable clutter support - experimental]),
+     [libclutter=$enableval], [libclutter=auto])
+ if test "x${libclutter}" = "xyes" -o "x${libgps}" = "xyes"; then
+   PKG_CHECK_MODULES(CLUTTER, [clutter-1.0 >= 1.0],
+     [
+       PKG_CHECK_MODULES(CLUTTER_GTK, [clutter-gtk-1.0 >= 1.0],
+         [
+           HAVE_CLUTTER=yes
+           AC_DEFINE(HAVE_CLUTTER, 1, [define to enable use of clutter library])
+         ],
+         [
+           HAVE_CLUTTER=no
+           AC_MSG_WARN([$CLUTTER_GTK_PKG_ERRORS])
+         ])
+         
+     ],
+     [
+       HAVE_CLUTTER=no
+       AC_MSG_WARN([$CLUTTER_PKG_ERRORS])
+     ])
+ else
+   HAVE_CLUTTER=disabled
+ fi
+ AC_SUBST(CLUTTER_CFLAGS)
+ AC_SUBST(CLUTTER_LIBS)
+ AC_SUBST(CLUTTER_GTK_CFLAGS)
+ AC_SUBST(CLUTTER_GTK_LIBS)
  #  Libchamplain support - used for GPS map facility - experimental
  # ----------------------------------------------------------------------
  
  AC_ARG_ENABLE([gps],
    AC_HELP_STRING([--enable-gps], [enable GPS map support - experimental]),
-     [libgps=$enableval], [libgps=auto])
+     [libgps=$enableval], [libgps=yes])
  
- if test "x${libgps}" = "xyes"; then
-   PKG_CHECK_MODULES(LIBCHAMPLAIN, [champlain-0.4 >= 0.4],
+ if test "x${libgps}" = "xyes" -a "x${HAVE_CLUTTER}" = "xyes" ; then
+   PKG_CHECK_MODULES(LIBCHAMPLAIN, [champlain-0.12 >= 0.12],
      [
        HAVE_LIBCHAMPLAIN=yes
        AC_DEFINE(HAVE_LIBCHAMPLAIN, 1, [define to enable use of GPS maps])
@@@ -401,8 -460,8 +460,8 @@@ els
    HAVE_LIBCHAMPLAIN=disabled
  fi
  
- if test "x${libgps}" = "xyes"; then
-   PKG_CHECK_MODULES(LIBCHAMPLAIN_GTK, [champlain-gtk-0.4 >= 0.4],
+ if test "x${libgps}" = "xyes" -a "x${HAVE_LIBCHAMPLAIN}" = "xyes" ; then
+   PKG_CHECK_MODULES(LIBCHAMPLAIN_GTK, [champlain-gtk-0.12 >= 0.12],
      [
        HAVE_LIBCHAMPLAIN_GTK=yes
        AC_DEFINE(HAVE_LIBCHAMPLAIN_GTK, 1, [define to enable use of GPS maps])
@@@ -419,33 -478,6 +478,33 @@@ AM_CONDITIONAL(HAVE_LIBCHAMPLAIN_GTK, [
  AC_SUBST(LIBCHAMPLAIN_GTK_CFLAGS)
  AC_SUBST(LIBCHAMPLAIN_GTK_LIBS)
  
 +#  Lua support
 +# ----------------------------------------------------------------------
 +
 +AC_ARG_ENABLE([lua],
 +  AC_HELP_STRING([--disable-lua], [disable lua support]),
 +    [liblua=$enableval], [liblua=auto])
 +
 +if test "x${liblua}" != "xno"; then
 +  PKG_CHECK_MODULES(LUA, lua5.1 >= 5.1,
 +    [
 +      HAVE_LUA=yes
 +      AC_DEFINE(HAVE_LUA, 1, [define to enable lua support])
 +    ],
 +    [
 +      HAVE_LUA=no
 +      AC_MSG_WARN([$LUA_PKG_ERRORS])
 +    ])
 +else
 +  HAVE_LUA=disabled
 +fi
 +
 +AM_CONDITIONAL(HAVE_LUA, [test "x$HAVE_LUA" = xyes])
 +AC_SUBST(LUA_CFLAGS)
 +AC_SUBST(LUA_LIBS)
 +
 +# ----------------------------------------------------------------------
 +
  AH_TOP([
  /** \file
   * \short autogenerated definition by autoheader.
  
  /*
   *  This file is a part of Geeqie project (http://geeqie.sourceforge.net/).
-  *  Copyright (C) 2008 - 2010 The Geeqie Team
+  *  Copyright (C) 2008 - 2012 The Geeqie Team
   *
   *  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
@@@ -519,7 -551,7 +578,7 @@@ Flags
    Gtk:           $GTK_CFLAGS
    Glib:          $GLIB_CFLAGS
    Thread:        $GTHREAD_LIBS
-   Others:      $JPEG_LIBS $TIFF_LIBS $LCMS_LIBS $EXIV2_LIBS $LIBCHAMPLAIN_LIBS $LIBCHAMPLAIN_GTK_LIBS $LUA_LIBS
 -  Others:      $JPEG_LIBS $TIFF_LIBS $LCMS_LIBS $EXIV2_LIBS $CLUTTER_LIBS $CLUTTER_GTK_LIBS $LIBCHAMPLAIN_LIBS $LIBCHAMPLAIN_GTK_LIBS
++  Others:      $JPEG_LIBS $TIFF_LIBS $LCMS_LIBS $EXIV2_LIBS $CLUTTER_LIBS $CLUTTER_GTK_LIBS $LIBCHAMPLAIN_LIBS $LIBCHAMPLAIN_GTK_LIBS $LUA_LIBS
  
  Localization:
    NLS support:   $USE_NLS
@@@ -535,9 -567,9 +594,10 @@@ Support
    LCMS:          $HAVE_LCMS
    Exiv2:       $HAVE_EXIV2
    Lirc:          $HAVE_LIRC
+   Clutter:       $HAVE_CLUTTER
    Libchamplain:               $HAVE_LIBCHAMPLAIN
    Libchamplain-gtk:   $HAVE_LIBCHAMPLAIN_GTK
 +  Lua:                 $HAVE_LUA
  
  Documentation:
    Doxygen:       $DOXYGEN
diff --combined src/Makefile.am
@@@ -7,7 -7,8 +7,9 @@@ AM_CFLAGS =                              
        $(EXIV2_CFLAGS)                 \
        $(LIBCHAMPLAIN_CFLAGS)          \
        $(LIBCHAMPLAIN_GTK_CFLAGS)      \
 +      $(LUA_CFLAGS)                   \
+       $(CLUTTER_CFLAGS)               \
+       $(CLUTTER_GTK_CFLAGS)   \
        -I$(top_srcdir)                 \
        -I$(top_builddir)
  
@@@ -18,7 -19,8 +20,9 @@@ AM_CXXFLAGS =                         
        $(EXIV2_CFLAGS)                 \
        $(LIBCHAMPLAIN_CFLAGS)          \
        $(LIBCHAMPLAIN_GTK_CFLAGS)      \
 +      $(LUA_CFLAGS)                   \
+       $(CLUTTER_CFLAGS)               \
+       $(CLUTTER_GTK_CFLAGS)   \
        -I$(top_srcdir)                 \
        -I$(top_builddir)
  
@@@ -211,6 -213,8 +215,8 @@@ geeqie_SOURCES = 
        pixbuf-renderer.h       \
        renderer-tiles.c        \
        renderer-tiles.h        \
+       renderer-clutter.c      \
+       renderer-clutter.h      \
        pixbuf_util.c   \
        pixbuf_util.h   \
        preferences.c   \
        view_file_icon.c        \
        view_file_icon.h        \
        window.c        \
 -      window.h
 +      window.h        \
 +      lua.c
  
- geeqie_LDADD = $(GTK_LIBS) $(GLIB_LIBS) $(INTLLIBS) $(JPEG_LIBS) $(TIFF_LIBS) $(LCMS_LIBS) $(EXIV2_LIBS) $(LIBCHAMPLAIN_LIBS) $(LIBCHAMPLAIN_GTK_LIBS) $(LUA_LIBS)
 -geeqie_LDADD = $(GTK_LIBS) $(GLIB_LIBS) $(INTLLIBS) $(JPEG_LIBS) $(TIFF_LIBS) $(LCMS_LIBS) $(EXIV2_LIBS) $(LIBCHAMPLAIN_LIBS) $(LIBCHAMPLAIN_GTK_LIBS) $(CLUTTER_LIBS) $(CLUTTER_GTK_LIBS)
++geeqie_LDADD = $(GTK_LIBS) $(GLIB_LIBS) $(INTLLIBS) $(JPEG_LIBS) $(TIFF_LIBS) $(LCMS_LIBS) $(EXIV2_LIBS) $(LIBCHAMPLAIN_LIBS) $(LIBCHAMPLAIN_GTK_LIBS) $(LUA_LIBS) $(CLUTTER_LIBS) $(CLUTTER_GTK_LIBS)
  
  EXTRA_DIST = \
        $(extra_SLIK)
diff --combined src/filedata.c
@@@ -1,7 -1,7 +1,7 @@@
  /*
   * Geeqie
   * (C) 2006 John Ellis
-  * Copyright (C) 2008 - 2010 The Geeqie Team
+  * Copyright (C) 2008 - 2012 The Geeqie Team
   *
   * Author: John Ellis
   *
@@@ -22,6 -22,8 +22,8 @@@
  #include "trash.h"
  #include "histogram.h"
  
+ #include "exif.h"
  #include <errno.h>
  
  static GHashTable *file_data_pool = NULL;
@@@ -29,9 -31,11 +31,11 @@@ static GHashTable *file_data_planned_ch
  
  static gint sidecar_file_priority(const gchar *extension);
  static void file_data_check_sidecars(const GList *basename_list);
- static FileData *file_data_disconnect_sidecar_file(FileData *target, FileData *sfd);
+ static void file_data_disconnect_sidecar_file(FileData *target, FileData *sfd);
  
  
+ static SortType filelist_sort_method = SORT_NONE;
+ static gboolean filelist_sort_ascend = TRUE;
  
  /*
   *-----------------------------------------------------------------------------
@@@ -135,7 -139,7 +139,7 @@@ const gchar *text_from_time(time_t t
  
  /*
   *-----------------------------------------------------------------------------
-  * changed files detection and notification 
+  * changed files detection and notification
   *-----------------------------------------------------------------------------
   */
  
@@@ -143,7 -147,7 +147,7 @@@ void file_data_increment_version(FileDa
  {
        fd->version++;
        fd->valid_marks = 0;
-       if (fd->parent) 
+       if (fd->parent)
                {
                fd->parent->version++;
                fd->parent->valid_marks = 0;
@@@ -171,7 -175,7 +175,7 @@@ static gboolean file_data_check_changed
  {
        gboolean ret = FALSE;
        GList *work;
-       
        ret = file_data_check_changed_single_file(fd, st);
  
        work = fd->sidecar_files;
                        {
                        fd->size = 0;
                        fd->date = 0;
+                       file_data_ref(sfd);
                        file_data_disconnect_sidecar_file(fd, sfd);
                        ret = TRUE;
+                       file_data_increment_version(sfd);
+                       file_data_send_notification(sfd, NOTIFY_REREAD);
+                       file_data_unref(sfd);
                        continue;
                        }
  
@@@ -200,7 -208,7 +208,7 @@@ gboolean file_data_check_changed_files(
  {
        gboolean ret = FALSE;
        struct stat st;
-       
        if (fd->parent) fd = fd->parent;
  
        if (!stat_utf8(fd->path, &st))
                ret = TRUE;
                fd->size = 0;
                fd->date = 0;
-               
                /* file_data_disconnect_sidecar_file might delete the file,
                   we have to keep the reference to prevent this */
                sidecars = filelist_copy(fd->sidecar_files);
+               file_data_ref(fd);
                work = sidecars;
                while (work)
                        {
                        sfd = work->data;
                        work = work->next;
-               
                        file_data_disconnect_sidecar_file(fd, sfd);
                        }
                file_data_check_sidecars(sidecars); /* this will group the sidecars back together */
                /* now we can release the sidecars */
                filelist_free(sidecars);
+               file_data_increment_version(fd);
                file_data_send_notification(fd, NOTIFY_REREAD);
+               file_data_unref(fd);
                }
        else
                {
  
  /*
   *-----------------------------------------------------------------------------
-  * file name, extension, sorting, ... 
+  * file name, extension, sorting, ...
   *-----------------------------------------------------------------------------
   */
  
  static void file_data_set_collate_keys(FileData *fd)
  {
        gchar *caseless_name;
+       gchar *valid_name;
  
-       caseless_name = g_utf8_casefold(fd->name, -1);
+       valid_name = g_filename_display_name(fd->name);
+       caseless_name = g_utf8_casefold(valid_name, -1);
  
        g_free(fd->collate_key_name);
        g_free(fd->collate_key_name_nocase);
  
- #if 0 && GLIB_CHECK_VERSION(2, 8, 0)
-       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(fd->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);
- #endif
+       g_free(valid_name);
        g_free(caseless_name);
  }
  
@@@ -319,7 -329,7 +329,7 @@@ static void file_data_set_path(FileDat
                {
                fd->extension = fd->name + strlen(fd->name);
                }
-               
        fd->sidecar_priority = sidecar_file_priority(fd->extension);
        file_data_set_collate_keys(fd);
  }
@@@ -336,7 -346,7 +346,7 @@@ static FileData *file_data_new(const gc
  
        DEBUG_2("file_data_new: '%s' %d", path_utf8, disable_sidecars);
  
-       if (S_ISDIR(st->st_mode)) disable_sidecars = TRUE; 
+       if (S_ISDIR(st->st_mode)) disable_sidecars = TRUE;
  
        if (!file_data_pool)
                file_data_pool = g_hash_table_new(g_str_hash, g_str_equal);
                {
                file_data_ref(fd);
                }
-               
        if (!fd && file_data_planned_change_hash)
                {
                fd = g_hash_table_lookup(file_data_planned_change_hash, path_utf8);
                        file_data_apply_ci(fd);
                        }
                }
-               
        if (fd)
                {
                gboolean changed;
-               
                if (disable_sidecars) file_data_disable_grouping(fd, TRUE);
-               
-               
                changed = file_data_check_changed_single_file(fd, st);
  
                DEBUG_2("file_data_pool hit: '%s' %s", fd->path, changed ? "(changed)" : "");
-               
                return fd;
                }
  
        fd = g_new0(FileData, 1);
-       
        fd->size = st->st_size;
        fd->date = st->st_mtime;
        fd->mode = st->st_mode;
        fd->ref = 1;
-       fd->magick = 0x12345678;
-       
+       fd->magick = FD_MAGICK;
        if (disable_sidecars) fd->disable_grouping = TRUE;
  
        file_data_set_path(fd, path_utf8); /* set path, name, collate_key_*, original_path */
@@@ -396,6 -406,69 +406,69 @@@ static FileData *file_data_new_local(co
        return ret;
  }
  
+ 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)
+               {
+               DEBUG_1("%s set_exif_time_data: Already exists for %s", get_exec_time(), file->path);
+               return;
+               }
+       file->exif = exif_read_fd(file);
+       if (file->exif)
+               {
+               gchar *tmp = exif_get_data_as_text(file->exif, "Exif.Photo.DateTimeOriginal");
+               DEBUG_2("%s set_exif_time_data: reading %p %s", get_exec_time(), file, file->path);
+               if (tmp)
+                       {
+                       struct tm time_str;
+                       uint year, month, day, hour, min, sec;
+                       sscanf(tmp, "%4d:%2d:%2d %2d:%2d:%2d", &year, &month, &day, &hour, &min, &sec);
+                       time_str.tm_year  = year - 1900;
+                       time_str.tm_mon   = month - 1;
+                       time_str.tm_mday  = day;
+                       time_str.tm_hour  = hour;
+                       time_str.tm_min   = min;
+                       time_str.tm_sec   = sec;
+                       time_str.tm_isdst = 0;
+                       file->exifdate = mktime(&time_str);
+                       g_free(tmp);
+                       }
+               }
+ }
+ void set_exif_time_data(GList *files)
+ {
+       DEBUG_1("%s set_exif_time_data: ...", get_exec_time());
+       while (files)
+               {
+               FileData *file = files->data;
+               read_exif_time_data(file);
+               files = files->next;
+               }
+ }
  FileData *file_data_new_no_grouping(const gchar *path_utf8)
  {
        struct stat st;
@@@ -421,7 -494,7 +494,7 @@@ FileData *file_data_new_dir(const gcha
        else
                /* dir or non-existing yet */
                g_assert(S_ISDIR(st.st_mode));
-               
        return file_data_new(path_utf8, &st, TRUE);
  }
  
@@@ -438,24 -511,26 +511,26 @@@ FileData *file_data_ref(FileData *fd
  #endif
  {
        if (fd == NULL) return NULL;
+       if (fd->magick != FD_MAGICK)
  #ifdef DEBUG_FILEDATA
-       if (fd->magick != 0x12345678)
-               DEBUG_0("fd magick mismatch at %s:%d", file, line);
+               DEBUG_0("fd magick mismatch @ %s:%d  fd=%p", file, line, fd);
+ #else
+               DEBUG_0("fd magick mismatch fd=%p", fd);
  #endif
-       g_assert(fd->magick == 0x12345678);
+       g_assert(fd->magick == FD_MAGICK);
        fd->ref++;
  
  #ifdef DEBUG_FILEDATA
-       DEBUG_2("file_data_ref (%d): '%s' @ %s:%d", fd->ref, fd->path, file, line);
+       DEBUG_2("file_data_ref fd=%p (%d): '%s' @ %s:%d", fd, fd->ref, fd->path, file, line);
  #else
-       DEBUG_2("file_data_ref (%d): '%s'", fd->ref, fd->path);
+       DEBUG_2("file_data_ref fd=%p (%d): '%s'", fd, fd->ref, fd->path);
  #endif
        return fd;
  }
  
  static void file_data_free(FileData *fd)
  {
-       g_assert(fd->magick == 0x12345678);
+       g_assert(fd->magick == FD_MAGICK);
        g_assert(fd->ref == 0);
  
        metadata_cache_free(fd);
        g_free(fd->collate_key_name_nocase);
        if (fd->thumb_pixbuf) g_object_unref(fd->thumb_pixbuf);
        histmap_free(fd->histmap);
-       
        g_assert(fd->sidecar_files == NULL); /* sidecar files must be freed before calling this */
  
        file_data_change_info_free(NULL, fd);
@@@ -481,23 -556,25 +556,25 @@@ void file_data_unref(FileData *fd
  #endif
  {
        if (fd == NULL) return;
+       if (fd->magick != FD_MAGICK)
  #ifdef DEBUG_FILEDATA
-       if (fd->magick != 0x12345678)
-               DEBUG_0("fd magick mismatch @ %s:%d", file, line);
+               DEBUG_0("fd magick mismatch @ %s:%d  fd=%p", file, line, fd);
+ #else
+               DEBUG_0("fd magick mismatch fd=%p", fd);
  #endif
-       g_assert(fd->magick == 0x12345678);
-       
+       g_assert(fd->magick == FD_MAGICK);
        fd->ref--;
  #ifdef DEBUG_FILEDATA
-       DEBUG_2("file_data_unref (%d): '%s' @ %s:%d", fd->ref, fd->path, file, line);
+       DEBUG_2("file_data_unref fd=%p (%d): '%s' @ %s:%d", fd, fd->ref, fd->path, file, line);
  #else
-       DEBUG_2("file_data_unref (%d): '%s'", fd->ref, fd->path);
+       DEBUG_2("file_data_unref fd=%p (%d): '%s'", fd, fd->ref, fd->path);
  #endif
        if (fd->ref == 0)
                {
                GList *work;
                FileData *parent = fd->parent ? fd->parent : fd;
-               
                if (parent->ref > 0) return;
  
                work = parent->sidecar_files;
@@@ -539,10 -616,10 +616,10 @@@ static gint file_data_sort_by_ext(gcons
  {
        const FileData *fda = a;
        const FileData *fdb = b;
-       
        if (fda->sidecar_priority < fdb->sidecar_priority) return -1;
        if (fda->sidecar_priority > fdb->sidecar_priority) return 1;
-       
        return strcmp(fdb->extension, fda->extension);
  }
  
@@@ -559,7 -636,7 +636,7 @@@ static gint sidecar_file_priority(cons
  
        while (work) {
                gchar *ext = work->data;
-               
                work = work->next;
                if (g_ascii_strcasecmp(extension, ext) == 0) return i;
                i++;
        return 0;
  }
  
- static FileData *file_data_add_sidecar_file(FileData *target, FileData *sfd)
+ static void file_data_check_sidecars(const GList *basename_list)
  {
-       sfd->parent = target;
-       if (!g_list_find(target->sidecar_files, sfd))
-               target->sidecar_files = g_list_insert_sorted(target->sidecar_files, sfd, file_data_sort_by_ext);
-       file_data_increment_version(sfd); /* increments both sfd and target */
-       return target;
- }
+       /* basename_list contains the new group - first is the parent, then sorted sidecars */
+       /* all files in the list have ref count > 0 */
  
+       const GList *work;
+       GList *s_work, *new_sidecars;
+       FileData *parent_fd;
  
- static FileData *file_data_merge_sidecar_files(FileData *target, FileData *source)
- {
-       GList *work;
-       
-       file_data_add_sidecar_file(target, source);
+       if (!basename_list) return;
  
-       work = source->sidecar_files;
+       DEBUG_2("basename start");
+       work = basename_list;
        while (work)
                {
-               FileData *sfd = work->data;
-               file_data_add_sidecar_file(target, sfd);
+               FileData *fd = work->data;
                work = work->next;
-               }
-       g_list_free(source->sidecar_files);
-       source->sidecar_files = NULL;
+               g_assert(fd->magick == FD_MAGICK);
+               DEBUG_2("basename: %p %s", fd, fd->name);
+               if (fd->parent)
+                       {
+                       g_assert(fd->parent->magick == FD_MAGICK);
+                       DEBUG_2("                  parent: %p", fd->parent);
+                       }
+               s_work = fd->sidecar_files;
+               while (s_work)
+                       {
+                       FileData *sfd = s_work->data;
+                       s_work = s_work->next;
+                       g_assert(sfd->magick == FD_MAGICK);
+                       DEBUG_2("                  sidecar: %p %s", sfd, sfd->name);
+                       }
  
-       return target;
- }
+               g_assert(fd->parent == NULL || fd->sidecar_files == NULL);
              }
  
- static void file_data_check_sidecars(const GList *basename_list)
- {
-       GList *work;
-       FileData *parent_fd;
-       if (!basename_list) return;
-       /* process the group list - the first one is the parent file, others are sidecars */
        parent_fd = basename_list->data;
+       /* check if the second and next entries of basename_list are already connected
+          as sidecars of the first entry (parent_fd) */
        work = basename_list->next;
-       while (work)
+       s_work = parent_fd->sidecar_files;
+       while (work && s_work)
                {
-               FileData *sfd = work->data;
+               if (work->data != s_work->data) break;
                work = work->next;
+               s_work = s_work->next;
+               }
  
-               file_data_merge_sidecar_files(parent_fd, sfd);
+       if (!work && !s_work)
+               {
+               DEBUG_2("basename no change");
+               return; /* no change in grouping */
                }
-               
-       /* there may be some sidecars that are already deleted - disconnect them */
-       work = parent_fd->sidecar_files;
+       /* we have to regroup it */
+       /* first, disconnect everything and send notification*/
+       work = basename_list;
        while (work)
                {
-               FileData *sfd = work->data;
+               FileData *fd = work->data;
                work = work->next;
-               
-               if (!g_list_find((GList *)basename_list, sfd)) 
+               g_assert(fd->parent == NULL || fd->sidecar_files == NULL);
+               if (fd->parent)
                        {
-                       printf("removing unknown %s: %s \n", parent_fd->path, sfd->path);
-                       file_data_disconnect_sidecar_file(parent_fd, sfd);
+                       FileData *old_parent = fd->parent;
+                       g_assert(old_parent->parent == NULL || old_parent->sidecar_files == NULL);
+                       file_data_ref(old_parent);
+                       file_data_disconnect_sidecar_file(old_parent, fd);
+                       file_data_send_notification(old_parent, NOTIFY_REREAD);
+                       file_data_unref(old_parent);
+                       }
+               while (fd->sidecar_files)
+                       {
+                       FileData *sfd = fd->sidecar_files->data;
+                       g_assert(sfd->parent == NULL || sfd->sidecar_files == NULL);
+                       file_data_ref(sfd);
+                       file_data_disconnect_sidecar_file(fd, sfd);
                        file_data_send_notification(sfd, NOTIFY_REREAD);
-                       file_data_send_notification(parent_fd, NOTIFY_REREAD);
+                       file_data_unref(sfd);
                        }
+               file_data_send_notification(fd, NOTIFY_GROUPING);
+               g_assert(fd->parent == NULL && fd->sidecar_files == NULL);
+               }
+       /* now we can form the new group */
+       work = basename_list->next;
+       new_sidecars = NULL;
+       while (work)
+               {
+               FileData *sfd = work->data;
+               g_assert(sfd->magick == FD_MAGICK);
+               g_assert(sfd->parent == NULL && sfd->sidecar_files == NULL);
+               sfd->parent = parent_fd;
+               new_sidecars = g_list_prepend(new_sidecars, sfd);
+               work = work->next;
                }
+       g_assert(parent_fd->sidecar_files == NULL);
+       parent_fd->sidecar_files = g_list_reverse(new_sidecars);
+       DEBUG_1("basename group changed for %s", parent_fd->path);
  }
  
- static FileData *file_data_disconnect_sidecar_file(FileData *target, FileData *sfd)
+ static void file_data_disconnect_sidecar_file(FileData *target, FileData *sfd)
  {
-       sfd->parent = target;
+       g_assert(target->magick == FD_MAGICK);
+       g_assert(sfd->magick == FD_MAGICK);
        g_assert(g_list_find(target->sidecar_files, sfd));
-       
+       file_data_ref(target);
+       file_data_ref(sfd);
+       g_assert(sfd->parent == target);
        file_data_increment_version(sfd); /* increments both sfd and target */
  
        target->sidecar_files = g_list_remove(target->sidecar_files, sfd);
        sfd->parent = NULL;
  
-       if (sfd->ref == 0)
-               {
-               file_data_free(sfd);
-               return NULL;
-               }
-       return sfd;
+       file_data_unref(target);
+       file_data_unref(sfd);
  }
  
  /* disables / enables grouping for particular file, sends UPDATE notification */
  void file_data_disable_grouping(FileData *fd, gboolean disable)
  {
        if (!fd->disable_grouping == !disable) return;
-       
        fd->disable_grouping = !!disable;
-       
        if (disable)
                {
                if (fd->parent)
  void file_data_disable_grouping_list(GList *fd_list, gboolean disable)
  {
        GList *work;
-       
        work = fd_list;
        while (work)
                {
                FileData *fd = work->data;
-               
                file_data_disable_grouping(fd, disable);
                work = work->next;
                }
   *-----------------------------------------------------------------------------
   */
  
- static SortType filelist_sort_method = SORT_NONE;
- static gboolean filelist_sort_ascend = TRUE;
  
  gint filelist_sort_compare_filedata(FileData *fa, FileData *fb)
  {
                        if (fa->date > fb->date) return 1;
                        /* fall back to name */
                        break;
+               case SORT_EXIFTIME:
+                       if (fa->exifdate < fb->exifdate) return -1;
+                       if (fa->exifdate > fb->exifdate) return 1;
+                       /* fall back to name */
+                       break;
  #ifdef HAVE_STRVERSCMP
                case SORT_NUMBER:
                        ret = strverscmp(fa->name, fb->name);
                ret = strcmp(fa->collate_key_name_nocase, fb->collate_key_name_nocase);
  
        if (ret != 0) return ret;
-       
-       /* do not return 0 unless the files are really the same 
-          file_data_pool ensures that original_path is unique 
+       /* do not return 0 unless the files are really the same
+          file_data_pool ensures that original_path is unique
        */
        return strcmp(fa->original_path, fb->original_path);
  }
@@@ -793,6 -920,10 +920,10 @@@ GList *filelist_insert_sort_full(GList 
  
  GList *filelist_sort(GList *list, SortType method, gboolean ascend)
  {
+       if (method == SORT_EXIFTIME)
+               {
+               set_exif_time_data(list);
+               }
        return filelist_sort_full(list, method, ascend, (GCompareFunc) filelist_sort_file_cb);
  }
  
@@@ -819,44 -950,19 +950,19 @@@ static GList * file_data_basename_hash_
        gchar *basename = g_strndup(fd->path, fd->extension - fd->path);
  
        list = g_hash_table_lookup(basename_hash, basename);
-       
        if (!g_list_find(list, fd))
                {
                list = g_list_insert_sorted(list, file_data_ref(fd), file_data_sort_by_ext);
                g_hash_table_insert(basename_hash, basename, list);
                }
-       else 
+       else
                {
                g_free(basename);
                }
        return list;
  }
  
- #if 0
- static void file_data_basename_hash_remove(GHashTable *basename_hash, FileData *fd)
- {
-       GList *list;
-       gchar *basename = g_strndup(fd->path, fd->extension - fd->path);
-       
-       list = g_hash_table_lookup(basename_hash, basename);
-       
-       if (!g_list_find(list, fd)) return;
-       
-       list = g_list_remove(list, fd);
-       file_data_unref(fd);
-       
-       if (list)
-               {
-               g_hash_table_insert(basename_hash, basename, list);
-               }
-       else 
-               {
-               g_hash_table_remove(basename_hash, basename);
-               g_free(basename);
-               }
- }
- #endif
  static void file_data_basename_hash_remove_list(gpointer key, gpointer value, gpointer data)
  {
        filelist_free((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, NULL);
        g_hash_table_destroy(basename_hash);
  }
  
@@@ -882,7 -988,7 +988,7 @@@ static GList *filelist_filter_out_sidec
        while (work)
                {
                FileData *fd = work->data;
-       
                work = work->next;
                if (fd->parent) /* remove fd's that are children */
                        file_data_unref(fd);
@@@ -976,7 -1082,7 +1082,7 @@@ static gboolean filelist_read_real(cons
                                        {
                                        FileData *fd = file_data_new_local(filepath, &ent_sbuf, FALSE);
                                        flist = g_list_prepend(flist, fd);
-                                       if (fd->sidecar_priority && !fd->disable_grouping) 
+                                       if (fd->sidecar_priority && !fd->disable_grouping)
                                                {
                                                file_data_basename_hash_insert(basename_hash, fd);
                                                }
                }
  
        closedir(dp);
-       
        g_free(pathl);
  
        if (dirs) *dirs = dlist;
-       if (files) 
+       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, NULL);
  
                *files = filelist_filter_out_sidecars(flist);
                }
        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;
  }
  
@@@ -1034,15 -1144,15 +1144,15 @@@ FileData *file_data_new_group(const gch
  
        if (S_ISDIR(st.st_mode))
                return file_data_new(path_utf8, &st, TRUE);
-       
        dir = remove_level_from_path(path_utf8);
-       
        filelist_read_real(dir, &files, NULL, TRUE);
-       
        fd = g_hash_table_lookup(file_data_pool, path_utf8);
        g_assert(fd);
        file_data_ref(fd);
-       
        filelist_free(files);
        g_free(dir);
        return fd;
@@@ -1139,12 -1249,12 +1249,12 @@@ GList *filelist_filter(GList *list, gbo
                                                       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;
                }
  
@@@ -1246,9 -1356,9 +1356,9 @@@ gchar *file_data_get_sidecar_path(FileD
  {
        gchar *sidecar_path = NULL;
        GList *work;
-       
        if (!file_data_can_write_sidecar(fd)) return NULL;
-       
        work = fd->parent ? fd->parent->sidecar_files : fd->sidecar_files;
        while (work)
                {
                        break;
                        }
                }
-       
        if (!existing_only && !sidecar_path)
                {
                gchar *base = g_strndup(fd->path, fd->extension - fd->path);
@@@ -1283,17 -1393,17 +1393,17 @@@ static GDestroyNotify file_data_destroy
  gboolean file_data_get_mark(FileData *fd, gint n)
  {
        gboolean valid = (fd->valid_marks & (1 << n));
-       
-       if (file_data_get_mark_func[n] && !valid) 
+       if (file_data_get_mark_func[n] && !valid)
                {
                guint old = fd->marks;
                gboolean value = (file_data_get_mark_func[n])(fd, n, file_data_mark_func_data[n]);
-               
-               if (!value != !(fd->marks & (1 << n))) 
+               if (!value != !(fd->marks & (1 << n)))
                        {
                        fd->marks = fd->marks ^ (1 << n);
                        }
-               
                fd->valid_marks |= (1 << n);
                if (old && !fd->marks) /* keep files with non-zero marks in memory */
                        {
@@@ -1319,16 -1429,16 +1429,16 @@@ void file_data_set_mark(FileData *fd, g
  {
        guint old;
        if (!value == !file_data_get_mark(fd, n)) return;
-       
-       if (file_data_set_mark_func[n]) 
+       if (file_data_set_mark_func[n])
                {
                (file_data_set_mark_func[n])(fd, n, value, file_data_mark_func_data[n]);
                }
-       
        old = fd->marks;
  
        fd->marks = fd->marks ^ (1 << n);
-       
        if (old && !fd->marks) /* keep files with non-zero marks in memory */
                {
                file_data_unref(fd);
                {
                file_data_ref(fd);
                }
-       
        file_data_increment_version(fd);
        file_data_send_notification(fd, NOTIFY_MARKS);
  }
@@@ -1381,9 -1491,9 +1491,9 @@@ static void file_data_notify_mark_func(
  gboolean file_data_register_mark_func(gint n, FileDataGetMarkFunc get_mark_func, FileDataSetMarkFunc set_mark_func, gpointer data, GDestroyNotify notify)
  {
        if (n < 0 || n >= FILEDATA_MARKS_SIZE) return FALSE;
-       
        if (file_data_destroy_mark_func[n]) (file_data_destroy_mark_func[n])(file_data_mark_func_data[n]);
-               
        file_data_get_mark_func[n] = get_mark_func;
          file_data_set_mark_func[n] = set_mark_func;
          file_data_mark_func_data[n] = data;
@@@ -1489,7 -1599,7 +1599,7 @@@ gboolean file_data_add_ci(FileData *fd
                fdci->dest = g_strdup(dest);
  
        fd->change = fdci;
-       
        return TRUE;
  }
  
@@@ -1521,7 -1631,7 +1631,7 @@@ void file_data_free_ci(FileData *fd
        if (!fdci) return;
  
        file_data_planned_change_remove(fd);
-       
        if (fdci->regroup_when_finished) file_data_disable_grouping(fd, FALSE);
  
        g_free(fdci->source);
@@@ -1544,40 -1654,40 +1654,40 @@@ static gboolean file_data_sc_add_ci(Fil
        GList *work;
  
        if (fd->parent) fd = fd->parent;
-       
        if (fd->change) return FALSE;
-       
        work = fd->sidecar_files;
        while (work)
                {
                FileData *sfd = work->data;
-               
                if (sfd->change) return FALSE;
                work = work->next;
                }
  
        file_data_add_ci(fd, type, NULL, NULL);
-       
        work = fd->sidecar_files;
        while (work)
                {
                FileData *sfd = work->data;
-               
                file_data_add_ci(sfd, type, NULL, NULL);
                work = work->next;
                }
-               
        return TRUE;
  }
  
  static gboolean file_data_sc_check_ci(FileData *fd, FileDataChangeType type)
  {
        GList *work;
-       
        if (fd->parent) fd = fd->parent;
-       
        if (!fd->change || fd->change->type != type) return FALSE;
-       
        work = fd->sidecar_files;
        while (work)
                {
@@@ -1634,14 -1744,14 +1744,14 @@@ void file_data_sc_free_ci(FileData *fd
        GList *work;
  
        if (fd->parent) fd = fd->parent;
-       
        file_data_free_ci(fd);
-       
        work = fd->sidecar_files;
        while (work)
                {
                FileData *sfd = work->data;
-       
                file_data_free_ci(sfd);
                work = work->next;
                }
@@@ -1656,7 -1766,7 +1766,7 @@@ gboolean file_data_sc_add_ci_delete_lis
        while (work)
                {
                FileData *fd = work->data;
-       
                if (!file_data_sc_add_ci_delete(fd)) ret = FALSE;
                work = work->next;
                }
  static void file_data_sc_revert_ci_list(GList *fd_list)
  {
        GList *work;
-       
        work = fd_list;
        while (work)
                {
                FileData *fd = work->data;
-               
                file_data_sc_free_ci(fd);
                work = work->prev;
                }
  static gboolean file_data_sc_add_ci_list_call_func(GList *fd_list, const gchar *dest, gboolean (*func)(FileData *, const gchar *))
  {
        GList *work;
-       
        work = fd_list;
        while (work)
                {
                FileData *fd = work->data;
-               
                if (!func(fd, dest))
                        {
                        file_data_sc_revert_ci_list(work->prev);
                        }
                work = work->next;
                }
-       
        return TRUE;
  }
  
@@@ -1727,7 -1837,7 +1837,7 @@@ gboolean file_data_add_ci_write_metadat
        while (work)
                {
                FileData *fd = work->data;
-       
                if (!file_data_add_ci_write_metadata(fd)) ret = FALSE;
                work = work->next;
                }
  void file_data_free_ci_list(GList *fd_list)
  {
        GList *work;
-       
        work = fd_list;
        while (work)
                {
                FileData *fd = work->data;
-               
                file_data_free_ci(fd);
                work = work->next;
                }
  void file_data_sc_free_ci_list(GList *fd_list)
  {
        GList *work;
-       
        work = fd_list;
        while (work)
                {
                FileData *fd = work->data;
-               
                file_data_sc_free_ci(fd);
                work = work->next;
                }
  static void file_data_update_planned_change_hash(FileData *fd, const gchar *old_path, gchar *new_path)
  {
        FileDataChangeType type = fd->change->type;
-       
        if (type == FILEDATA_CHANGE_MOVE || type == FILEDATA_CHANGE_RENAME)
                {
                FileData *ofd;
-               
                if (!file_data_planned_change_hash)
                        file_data_planned_change_hash = g_hash_table_new(g_str_hash, g_str_equal);
-               
                if (old_path && g_hash_table_lookup(file_data_planned_change_hash, old_path) == fd)
                        {
                        DEBUG_1("planned change: removing %s -> %s", old_path, fd->path);
                                g_hash_table_remove(file_data_planned_change_hash, new_path);
                                file_data_unref(ofd);
                                }
-                       
                        DEBUG_1("planned change: inserting %s -> %s", new_path, fd->path);
                        file_data_ref(fd);
                        g_hash_table_insert(file_data_planned_change_hash, new_path, fd);
@@@ -1817,10 -1927,10 +1927,10 @@@ static void file_data_update_ci_dest_pr
        const gchar *extension = 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);
        file_data_update_planned_change_hash(fd, old_path, fd->change->dest);
-       
        g_free(old_path);
        g_free(base);
  }
@@@ -1829,9 -1939,9 +1939,9 @@@ static void file_data_sc_update_ci(File
  {
        GList *work;
        gchar *dest_path_full = NULL;
-       
        if (fd->parent) fd = fd->parent;
-       
        if (!dest_path)
                {
                dest_path = fd->path;
        else if (!strchr(dest_path, G_DIR_SEPARATOR)) /* we got only filename, not a full path */
                {
                gchar *dir = remove_level_from_path(fd->path);
-               
                dest_path_full = g_build_filename(dir, dest_path, NULL);
                g_free(dir);
                dest_path = dest_path_full;
                dest_path_full = g_build_filename(dest_path, fd->name, NULL);
                dest_path = dest_path_full;
                }
-               
        file_data_update_ci_dest(fd, dest_path);
-       
        work = fd->sidecar_files;
        while (work)
                {
                FileData *sfd = work->data;
-               
                file_data_update_ci_dest_preserve_ext(sfd, dest_path);
                work = work->next;
                }
-       
        g_free(dest_path_full);
  }
  
@@@ -1875,7 -1985,7 +1985,7 @@@ gboolean file_data_sc_update_ci_copy(Fi
  {
        return file_data_sc_check_update_ci(fd, dest_path, FILEDATA_CHANGE_COPY);
  }
-       
  gboolean file_data_sc_update_ci_move(FileData *fd, const gchar *dest_path)
  {
        return file_data_sc_check_update_ci(fd, dest_path, FILEDATA_CHANGE_MOVE);
@@@ -1897,16 -2007,16 +2007,16 @@@ static gboolean file_data_sc_update_ci_
  {
        GList *work;
        gboolean ret = TRUE;
-       
        work = fd_list;
        while (work)
                {
                FileData *fd = work->data;
-               
                if (!func(fd, dest)) ret = FALSE;
                work = work->next;
                }
-       
        return ret;
  }
  
@@@ -1935,7 -2045,7 +2045,7 @@@ gint file_data_verify_ci(FileData *fd
  {
        gint ret = CHANGE_OK;
        gchar *dir;
-       
        if (!fd->change)
                {
                DEBUG_1("Change checked: no change info: %s", fd->path);
                DEBUG_1("Change checked: file does not exist: %s", fd->path);
                return ret;
                }
-               
        dir = remove_level_from_path(fd->path);
-       
        if (fd->change->type != FILEDATA_CHANGE_DELETE &&
            fd->change->type != FILEDATA_CHANGE_MOVE && /* the unsaved metadata should survive move and rename operations */
            fd->change->type != FILEDATA_CHANGE_RENAME &&
                ret |= CHANGE_WARN_UNSAVED_META;
                DEBUG_1("Change checked: unsaved metadata: %s", fd->path);
                }
-       
        if (fd->change->type != FILEDATA_CHANGE_DELETE &&
            fd->change->type != FILEDATA_CHANGE_WRITE_METADATA &&
            !access_file(fd->path, R_OK))
                /* determine destination file */
                gboolean have_dest = FALSE;
                gchar *dest_dir = NULL;
-               
                if (options->metadata.save_in_image_file)
                        {
-                       if (file_data_can_write_directly(fd)) 
+                       if (file_data_can_write_directly(fd))
                                {
                                /* we can write the file directly */
                                if (access_file(fd->path, W_OK))
                                                }
                                        }
                                }
-                       else if (file_data_can_write_sidecar(fd)) 
+                       else if (file_data_can_write_sidecar(fd))
                                {
                                /* we can write sidecar */
                                gchar *sidecar = file_data_get_sidecar_path(fd, FALSE);
                                g_free(sidecar);
                                }
                        }
-               
                if (!have_dest)
                        {
                        /* write private metadata file under ~/.geeqie */
                        metadata_path = cache_find_location(CACHE_TYPE_XMP_METADATA, fd->path);
  #endif
                        if (!metadata_path) metadata_path = cache_find_location(CACHE_TYPE_METADATA, fd->path);
-                       
                        if (metadata_path && !access_file(metadata_path, W_OK))
                                {
                                g_free(metadata_path);
                                if (recursive_mkdir_if_not_exists(dest_dir, mode))
                                        {
                                        gchar *filename = g_strconcat(fd->name, options->metadata.save_legacy_format ? GQ_CACHE_EXT_METADATA : GQ_CACHE_EXT_XMP_METADATA, NULL);
-                       
                                        metadata_path = g_build_filename(dest_dir, filename, NULL);
                                        g_free(filename);
                                        }
                        }
                g_free(dest_dir);
                }
-               
        if (fd->change->dest && fd->change->type != FILEDATA_CHANGE_WRITE_METADATA)
                {
                gboolean same;
                gchar *dest_dir;
-                       
                same = (strcmp(fd->path, fd->change->dest) == 0);
  
                if (!same)
                        }
                else if (!access_file(dest_dir, W_OK))
                        {
-                       ret |= CHANGE_NO_WRITE_PERM_DEST_DIR;
+                       ret |= CHANGE_WARN_NO_WRITE_PERM_DEST_DIR;
                        DEBUG_1("Change checked: destination dir is readonly: %s -> %s", fd->path, fd->change->dest);
                        }
                else if (!same)
  
                g_free(dest_dir);
                }
-               
        fd->change->error = ret;
        if (ret == 0) DEBUG_1("Change checked: OK: %s", fd->path);
  
@@@ -2193,7 -2303,7 +2303,7 @@@ gchar *file_data_get_error_string(gint 
                g_string_append(result, _("destination can't be overwritten"));
                }
  
-       if (error & CHANGE_NO_WRITE_PERM_DEST_DIR)
+       if (error & CHANGE_WARN_NO_WRITE_PERM_DEST_DIR)
                {
                if (result->len > 0) g_string_append(result, ", ");
                g_string_append(result, _("destination directory is not writable"));
                if (result->len > 0) g_string_append(result, ", ");
                g_string_append(result, _("destination already exists and will be overwritten"));
                }
-               
        if (error & CHANGE_WARN_SAME)
                {
                if (result->len > 0) g_string_append(result, ", ");
@@@ -2258,9 -2368,9 +2368,9 @@@ gint file_data_verify_ci_list(GList *li
        gint num;
        gint *errors;
        gint i;
-       
        if (!list) return 0;
-       
        num = g_list_length(list);
        errors = g_new(int, num);
        work = list;
  
                fd = work->data;
                work = work->next;
-                       
                error = with_sidecars ? file_data_sc_verify_ci(fd) : file_data_verify_ci(fd);
                all_errors |= error;
                common_errors &= error;
-               
                errors[i] = error;
-               
                i++;
                }
-       
        if (desc && all_errors)
                {
                GList *work;
                GString *result = g_string_new("");
-               
                if (common_errors)
                        {
                        gchar *str = file_data_get_error_string(common_errors);
                        g_string_append(result, "\n");
                        g_free(str);
                        }
-               
                work = list;
                i = 0;
                while (work)
  
                        fd = work->data;
                        work = work->next;
-                       
                        error = errors[i] & ~common_errors;
-                       
                        if (error)
                                {
                                gchar *str = file_data_get_error_string(error);
@@@ -2383,20 -2493,20 +2493,20 @@@ gboolean file_data_sc_perform_ci(FileDa
        GList *work;
        gboolean ret = TRUE;
        FileDataChangeType type = fd->change->type;
-       
        if (!file_data_sc_check_ci(fd, type)) return FALSE;
  
        work = fd->sidecar_files;
        while (work)
                {
                FileData *sfd = work->data;
-               
                if (!file_data_perform_ci(sfd)) ret = FALSE;
                work = work->next;
                }
-       
        if (!file_data_perform_ci(fd)) ret = FALSE;
-       
        return ret;
  }
  
@@@ -2413,7 -2523,7 +2523,7 @@@ gboolean file_data_apply_ci(FileData *f
                {
                DEBUG_1("planned change: applying %s -> %s", fd->change->dest, fd->path);
                file_data_planned_change_remove(fd);
-               
                if (g_hash_table_lookup(file_data_pool, fd->change->dest))
                        {
                        /* this change overwrites another file which is already known to other modules
                }
        file_data_increment_version(fd);
        file_data_send_notification(fd, NOTIFY_CHANGE);
-       
        return TRUE;
  }
  
@@@ -2438,20 -2548,20 +2548,20 @@@ gboolean file_data_sc_apply_ci(FileDat
  {
        GList *work;
        FileDataChangeType type = fd->change->type;
-       
        if (!file_data_sc_check_ci(fd, type)) return FALSE;
  
        work = fd->sidecar_files;
        while (work)
                {
                FileData *sfd = work->data;
-               
                file_data_apply_ci(sfd);
                work = work->next;
                }
-       
        file_data_apply_ci(fd);
-       
        return TRUE;
  }
  
@@@ -2460,7 -2570,7 +2570,7 @@@ static gboolean file_data_list_contains
        GList *work;
        if (fd->parent) fd = fd->parent;
        if (!g_list_find(list, fd)) return FALSE;
-       
        work = fd->sidecar_files;
        while (work)
                {
        return TRUE;
  }
  
- #if 0
- static gboolean file_data_list_dump(GList *list)
- {
-       GList *work, *work2;
-       work = list;
-       while (work)
-               {
-               FileData *fd = work->data;
-               printf("%s\n", fd->name);
-               work2 = fd->sidecar_files;
-               while (work2)
-                       {
-                       FileData *fd = work2->data;
-                       printf("       %s\n", fd->name);
-                       work2 = work2->next;
-                       }
-               work = work->next;
-               }
-       return TRUE;
- }
- #endif
  GList *file_data_process_groups_in_selection(GList *list, gboolean ungroup, GList **ungrouped_list)
  {
        GList *out = NULL;
                        {
                        FileData *fd = work->data;
                        work = work->next;
-               
-                       if (!file_data_list_contains_whole_group(list, fd)) 
+                       if (!file_data_list_contains_whole_group(list, fd))
                                {
                                file_data_disable_grouping(fd, TRUE);
-                               if (ungrouped_list) 
+                               if (ungrouped_list)
                                        {
                                        *ungrouped_list = g_list_prepend(*ungrouped_list, file_data_ref(fd));
                                        }
                                }
                        }
                }
-       
-       /* remove sidecars from the list, 
+       /* remove sidecars from the list,
           they can be still acessed via main_fd->sidecar_files */
        work = list;
        while (work)
                {
                FileData *fd = work->data;
                work = work->next;
-               
                if (!fd->parent ||
                    (!ungroup && !file_data_list_contains_whole_group(list, fd)))
                        {
                        out = g_list_prepend(out, file_data_ref(fd));
                        }
                }
-               
        filelist_free(list);
        out = g_list_reverse(out);
  
     implementation in view_file_list.c */
  
  
 -typedef struct _NotifyIdleData NotifyIdleData;
 -
 -struct _NotifyIdleData {
 -      FileData *fd;
 -      NotifyType type;
 -};
  
  
  typedef struct _NotifyData NotifyData;
@@@ -2577,11 -2670,11 +2664,11 @@@ gboolean file_data_register_notify_func
  {
        NotifyData *nd;
        GList *work = notify_func_list;
-       
        while (work)
                {
                NotifyData *nd = (NotifyData *)work->data;
-       
                if (nd->func == func && nd->data == data)
                        {
                        g_warning("Notify func already registered");
                        }
                work = work->next;
                }
-       
        nd = g_new(NotifyData, 1);
        nd->func = func;
        nd->data = data;
  
        notify_func_list = g_list_insert_sorted(notify_func_list, nd, file_data_notify_sort);
        DEBUG_2("Notify func registered: %p", nd);
-       
        return TRUE;
  }
  
  gboolean file_data_unregister_notify_func(FileDataNotifyFunc func, gpointer data)
  {
        GList *work = notify_func_list;
-       
        while (work)
                {
                NotifyData *nd = (NotifyData *)work->data;
-       
                if (nd->func == func && nd->data == data)
                        {
                        notify_func_list = g_list_delete_link(notify_func_list, work);
  }
  
  
 -gboolean file_data_send_notification_idle_cb(gpointer data)
 +void file_data_send_notification(FileData *fd, NotifyType type)
  {
 -      NotifyIdleData *nid = (NotifyIdleData *)data;
        GList *work = notify_func_list;
  
        while (work)
                {
                NotifyData *nd = (NotifyData *)work->data;
-               
 -              nd->func(nid->fd, nid->type, nd->data);
 +              nd->func(fd, type, nd->data);
                work = work->next;
                }
 -      file_data_unref(nid->fd);
 -      g_free(nid);
 -      return FALSE;
 -}
 -
 -void file_data_send_notification(FileData *fd, NotifyType type)
 -{
 -      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;
@@@ -2645,7 -2750,7 +2732,7 @@@ static void realtime_monitor_check_cb(g
        FileData *fd = key;
  
        file_data_check_changed_files(fd);
-       
        DEBUG_1("monitor %s", fd->path);
  }
  
@@@ -2659,24 -2764,24 +2746,24 @@@ static gboolean realtime_monitor_cb(gpo
  gboolean file_data_register_real_time_monitor(FileData *fd)
  {
        gint count;
-       
        file_data_ref(fd);
-       
        if (!file_data_monitor_pool)
                file_data_monitor_pool = g_hash_table_new(g_direct_hash, g_direct_equal);
-       
        count = GPOINTER_TO_INT(g_hash_table_lookup(file_data_monitor_pool, fd));
  
        DEBUG_1("Register realtime %d %s", count, fd->path);
-       
        count++;
        g_hash_table_insert(file_data_monitor_pool, fd, GINT_TO_POINTER(count));
-       
        if (!realtime_monitor_id)
                {
                realtime_monitor_id = g_timeout_add(5000, realtime_monitor_cb, NULL);
                }
-       
        return TRUE;
  }
  
@@@ -2685,29 -2790,29 +2772,29 @@@ gboolean file_data_unregister_real_time
        gint count;
  
        g_assert(file_data_monitor_pool);
-       
        count = GPOINTER_TO_INT(g_hash_table_lookup(file_data_monitor_pool, fd));
-       
        DEBUG_1("Unregister realtime %d %s", count, fd->path);
-       
        g_assert(count > 0);
-       
        count--;
-       
        if (count == 0)
                g_hash_table_remove(file_data_monitor_pool, fd);
        else
                g_hash_table_insert(file_data_monitor_pool, fd, GINT_TO_POINTER(count));
  
        file_data_unref(fd);
-       
        if (g_hash_table_size(file_data_monitor_pool) == 0)
                {
                g_source_remove(realtime_monitor_id);
                realtime_monitor_id = 0;
                return FALSE;
                }
-       
        return TRUE;
  }
  /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */
diff --combined src/image-overlay.c
@@@ -1,7 -1,7 +1,7 @@@
  /*
   * Geeqie
   * (C) 2006 John Ellis
-  * Copyright (C) 2008 - 2010 The Geeqie Team
+  * Copyright (C) 2008 - 2012 The Geeqie Team
   *
   * Author: John Ellis
   *
@@@ -25,7 -25,6 +25,7 @@@
  #include "pixbuf_util.h"
  #include "ui_fileops.h"
  #include "image-load.h"
 +#include "glua.h"
  
  /*
   *----------------------------------------------------------------------------
@@@ -45,7 -44,7 +45,7 @@@ struct _OverlayStateData 
        OsdShowFlags show;
  
        gint ovl_info;
-       
        gint x;
        gint y;
  
@@@ -227,13 -226,13 +227,13 @@@ static gchar *keywords_to_string(FileDa
                        {
                        gchar *kw = work->data;
                        work = work->next;
-                       
                        if (!kw) continue;
                        if (!kwstr)
                                kwstr = g_string_new("");
                        else
                                g_string_append(kwstr, ", ");
-                       
                        g_string_append(kwstr, kw);
                        }
                string_list_free(keywords);
@@@ -306,7 -305,7 +306,7 @@@ static gchar *image_osd_mkinfo(const gc
  
                if (extrapos)
                        extra = g_strndup(extrapos, end - extrapos);
-                                       
                name = g_strndup(start+1, (trunc ? trunc : end)-start-1);
                pos = start - new->str;
                data = NULL;
                        {
                        data = metadata_read_string(imd->image_fd, COMMENT_KEY, METADATA_PLAIN);
                        }
 +#ifdef HAVE_LUA
 +              else if (strncmp(name, "lua/", 4) == 0)
 +                      {
 +                      gchar *tmp;
 +                      tmp = strchr(name+4, '/');
 +                      if (!tmp)
 +                              break;
 +                      *tmp = '\0';
 +                      data = lua_callvalue(imd->image_fd, name+4, tmp+1);
 +                      }
 +#endif
                else
                        {
                        data = g_strdup(g_hash_table_lookup(vars, name));
                        if (!data)
                                data = metadata_read_string(imd->image_fd, name, METADATA_FORMATTED);
                        }
-       
                if (data && *data && limit > 0 && strlen(data) > limit + 3)
                        {
                        gchar *new_data = g_strdup_printf("%-*.*s...", limit, limit, data);
                        g_free(data);
                        data = new_data;
                        }
-       
                if (data)
                        {
                        /* Since we use pango markup to display, we need to escape here */
                                gchar *right = extra;
                                gchar *p;
                                guint len = strlen(extra);
-                               
                                /* Search for left and right parts and unescape characters */
                                for (p = extra; *p; p++, len--)
                                        if (p[0] == '\\')
@@@ -489,9 -477,8 +489,8 @@@ static GdkPixbuf *image_osd_info_render
        PangoLayout *layout;
        const gchar *name;
        gchar *text;
-       GdkPixbuf *imgpixbuf = NULL;
        gboolean with_hist;
-       const HistMap *histmap;
+       const HistMap *histmap = NULL;
        ImageWindow *imd = osd->imd;
        FileData *fd = image_get_fd(imd);
  
                                t = 1;
                                n = 1;
                                }
-       
                        if (n < 1) n = 1;
                        if (t < 1) t = 1;
-       
                        osd_template_insert(vars, "collection", NULL, OSDT_NONE);
                        }
-               
                osd_template_insert(vars, "number", g_strdup_printf("%d", n), OSDT_NO_DUP);
                osd_template_insert(vars, "total", g_strdup_printf("%d", t), OSDT_NO_DUP);
                osd_template_insert(vars, "name", (gchar *) name, OSDT_NONE);
                osd_template_insert(vars, "date", imd->image_fd ? ((gchar *) text_from_time(imd->image_fd->date)) : "", OSDT_NONE);
                osd_template_insert(vars, "size", imd->image_fd ? (text_from_size_abrev(imd->image_fd->size)) : g_strdup(""), OSDT_FREE);
                osd_template_insert(vars, "zoom", image_zoom_get_as_text(imd), OSDT_FREE);
-       
                if (!imd->unknown)
                        {
                        gint w, h;
                                {
                                w = gdk_pixbuf_get_width(load_pixbuf);
                                h = gdk_pixbuf_get_height(load_pixbuf);
-                               imgpixbuf = load_pixbuf;
                                }
                        else
                                {
                                image_get_image_size(imd, &w, &h);
-                               imgpixbuf = (PIXBUF_RENDERER(imd->pr))->pixbuf;
                                }
-               
-                       
                        osd_template_insert(vars, "width", g_strdup_printf("%d", w), OSDT_NO_DUP);
                        osd_template_insert(vars, "height", g_strdup_printf("%d", h), OSDT_NO_DUP);
                        osd_template_insert(vars, "res", g_strdup_printf("%d × %d", w, h), OSDT_FREE);
        if (with_hist)
                {
                histmap = histmap_get(imd->image_fd);
-               if (!histmap) 
+               if (!histmap)
                        {
                        histmap_start_idle(imd->image_fd);
                        with_hist = FALSE;
                        }
                }
-       
-       
        {
                gint active_marks = 0;
                gint mark;
@@@ -777,13 -762,6 +774,6 @@@ static void image_overlay_set(ImageWind
        pixbuf_renderer_overlay_set((PixbufRenderer *)imd->pr, id, pixbuf, x, y);
  }
  
- #if 0 /* unused for now */
- static gint image_overlay_get(ImageWindow *imd, gint id, GdkPixbuf **pixbuf, gint *x, gint *y)
- {
-       return pixbuf_renderer_overlay_get((PixbufRenderer *)imd->pr, id, pixbuf, x, y);
- }
- #endif
  static void image_overlay_remove(ImageWindow *imd, gint id)
  {
        pixbuf_renderer_overlay_remove((PixbufRenderer *)imd->pr, id);
@@@ -878,7 -856,7 +868,7 @@@ static gboolean image_osd_update_cb(gpo
  
        if (osd->show & OSD_SHOW_INFO)
                {
-               /* redraw when the image was changed, 
+               /* redraw when the image was changed,
                   with histogram we have to redraw also when loading is finished */
                if (osd->changed_states & IMAGE_STATE_IMAGE ||
                    (osd->changed_states & IMAGE_STATE_LOADING && osd->show & OSD_SHOW_HISTOGRAM) ||
                {
                if (osd->changed_states & IMAGE_STATE_IMAGE)
                        image_osd_icons_reset_time(osd);
-       
                if (osd->changed_states & IMAGE_STATE_COLOR_ADJ)
                        {
                        osd->icon_time[IMAGE_OSD_COLOR] = IMAGE_OSD_DEFAULT_DURATION + 1;
@@@ -1049,15 -1027,6 +1039,6 @@@ static void image_osd_free(OverlayState
        g_free(osd);
  }
  
- #if 0
- static void image_osd_remove(ImageWindow *imd)
- {
-       OverlayStateData *osd = image_get_osd_data(imd);
-       if (osd) image_osd_free(osd);
- }
- #endif
  static void image_osd_destroy_cb(GtkWidget *widget, gpointer data)
  {
        OverlayStateData *osd = data;
@@@ -1077,7 -1046,7 +1058,7 @@@ static void image_osd_enable(ImageWindo
                osd->show = OSD_SHOW_NOTHING;
                osd->x = options->image_overlay.x;
                osd->y = options->image_overlay.y;
-               
                osd->histogram = histogram_new();
  
                osd->destroy_id = g_signal_connect(G_OBJECT(imd->pr), "destroy",
@@@ -1122,13 -1091,13 +1103,13 @@@ void image_osd_copy_status(ImageWindow 
  {
        Histogram *h_src, *h_dest;
        image_osd_set(dest, image_osd_get(src));
-       
        h_src = image_osd_get_histogram(src);
        h_dest = image_osd_get_histogram(dest);
-       
        h_dest->histogram_mode = h_src->histogram_mode;
        h_dest->histogram_channel = h_src->histogram_channel;
-       
  }
  
  /* duration:
diff --combined src/main.c
@@@ -1,7 -1,7 +1,7 @@@
  /*
   * Geeqie
   * (C) 2006 John Ellis
-  * Copyright (C) 2008 - 2010 The Geeqie Team
+  * Copyright (C) 2008 - 2012 The Geeqie Team
   *
   * Author: John Ellis
   *
@@@ -19,6 -19,7 +19,7 @@@
  #ifdef G_OS_UNIX
  #include <pwd.h>
  #endif
+ #include <locale.h>
  
  #include "main.h"
  
  #include "exif.h"
  #include "histogram.h"
  #include "pixbuf_util.h"
 +#include "glua.h"
  
- #ifdef HAVE_LIBCHAMPLAIN
- #ifdef HAVE_LIBCHAMPLAIN_GTK
+ #ifdef HAVE_CLUTTER
  #include <clutter-gtk/clutter-gtk.h>
  #endif
- #endif
  
  
  gboolean thumb_format_changed = FALSE;
@@@ -143,7 -141,7 +142,7 @@@ static void parse_command_line_add_dir(
        path_parsed = g_strdup(dir);
        parse_out_relatives(path_parsed);
        dir_fd = file_data_new_dir(path_parsed);
-       
  
        if (filelist_read(dir_fd, &files, NULL))
                {
@@@ -213,9 -211,9 +212,9 @@@ static void parse_command_line(gint arg
        GList *remote_errors = NULL;
        gboolean remote_do = FALSE;
        gchar *first_dir = NULL;
-       
        command_line = g_new0(CommandLine, 1);
-       
        command_line->argc = argc;
        command_line->argv = argv;
  
                if (remote_errors)
                        {
                        GList *work = remote_errors;
-                       
                        printf_term(_("Invalid or ignored remote options: "));
                        while (work)
                                {
                                gchar *opt = work->data;
-                                               
                                printf_term("%s%s", (work == remote_errors) ? "" : ", ", opt);
                                work = work->next;
                                }
@@@ -544,7 -542,7 +543,7 @@@ static gboolean gq_accel_map_save(cons
                log_printf(_("error saving file: %s\n"), path);
                return FALSE;
                }
-       
        gstring = g_string_new("; ");
        if (g_get_prgname())
                g_string_append(gstring, g_get_prgname());
@@@ -700,7 -698,7 +699,7 @@@ void exit_program(void
        exit_program_final();
  }
  
- /* This code is supposed to handle situation when a file mmaped by image_loader 
+ /* This code is supposed to handle situation when a file mmaped by image_loader
   * or by exif loader is truncated by some other process.
   * This is probably not completely correct according to posix, because
   * mmap is not in the list of calls that can be used safely in signal handler,
@@@ -743,12 -741,12 +742,12 @@@ gint main(gint argc, gchar *argv[]
        gdk_threads_enter();
  
  #endif
-       
        /* init execution time counter (debug only) */
        init_exec_time();
  
        /* setup locale, i18n */
-       gtk_set_locale();
+       setlocale(LC_ALL, "");
  
  #ifdef ENABLE_NLS
        bindtextdomain(PACKAGE, GQ_LOCALEDIR);
  
        exif_init();
  
 +#ifdef HAVE_LUA
 +      lua_init();
 +#endif
 +
        /* setup random seed for random slideshow */
        srand(time(NULL));
  
        file_data_register_notify_func(histogram_notify_cb, NULL, NOTIFY_PRIORITY_HIGH);
        file_data_register_notify_func(collect_manager_notify_cb, NULL, NOTIFY_PRIORITY_LOW);
        file_data_register_notify_func(metadata_notify_cb, NULL, NOTIFY_PRIORITY_LOW);
-       
  
        gtkrc_load();
  
        parse_command_line_for_debug_option(argc, argv);
-       DEBUG_1("%s main: gtk_init", get_exec_time());   
- #ifdef HAVE_LIBCHAMPLAIN
- #ifdef HAVE_LIBCHAMPLAIN_GTK
+       DEBUG_1("%s main: gtk_init", get_exec_time());
+ #ifdef HAVE_CLUTTER
        if (gtk_clutter_init(&argc, &argv) != CLUTTER_INIT_SUCCESS)
                {
                log_printf("Can't initialize clutter-gtk.\n");
                exit(1);
                }
- #else
-       gtk_init(&argc, &argv);
- #endif
  #else
        gtk_init(&argc, &argv);
  #endif
                log_printf("!!! %s may quit unexpectedly with a relocation error.\n", GQ_APPNAME);
                }
  
-       DEBUG_1("%s main: pixbuf_inline_register_stock_icons", get_exec_time());         
+       DEBUG_1("%s main: pixbuf_inline_register_stock_icons", get_exec_time());
        pixbuf_inline_register_stock_icons();
  
-       DEBUG_1("%s main: parse_command_line", get_exec_time());         
+       DEBUG_1("%s main: setting default options before commandline handling", get_exec_time());
+       options = init_options(NULL);
+       setup_default_options(options);
+       DEBUG_1("%s main: parse_command_line", get_exec_time());
        parse_command_line(argc, argv);
  
-       DEBUG_1("%s main: mkdir_if_not_exists", get_exec_time());        
+       DEBUG_1("%s main: mkdir_if_not_exists", get_exec_time());
        /* these functions don't depend on config file */
        mkdir_if_not_exists(get_rc_dir());
        mkdir_if_not_exists(get_collections_dir());
  
        /* restore session from the config file */
  
-       options = init_options(NULL);
-       setup_default_options(options);
  
-       DEBUG_1("%s main: load_options", get_exec_time());       
+       DEBUG_1("%s main: load_options", get_exec_time());
        if (!load_options(options))
                {
                /* load_options calls these functions after it parses global options, we have to call it here if it fails */
                filter_add_defaults();
-               filter_rebuild(); 
+               filter_rebuild();
                }
  
        /* handle missing config file and commandline additions*/
-       if (!layout_window_list) 
+       if (!layout_window_list)
                {
                /* broken or no config file */
                layout_new_from_config(NULL, NULL, TRUE);
        buf = g_build_filename(get_rc_dir(), ".command", NULL);
        remote_connection = remote_server_init(buf, cd);
        g_free(buf);
-       
-       DEBUG_1("%s main: gtk_main", get_exec_time());   
+       DEBUG_1("%s main: gtk_main", get_exec_time());
        gtk_main();
  #ifdef HAVE_GTHREAD
        gdk_threads_leave();