Implementing sorting by file creation
authorKlaus Ethgen <Klaus@Ethgen.de>
Fri, 4 Mar 2016 10:21:09 +0000 (11:21 +0100)
committerKlaus Ethgen <Klaus@Ethgen.de>
Fri, 4 Mar 2016 10:21:09 +0000 (11:21 +0100)
src/filedata.c
src/menu.c
src/typedefs.h

index c4e0525..cf24f7a 100644 (file)
@@ -165,6 +165,7 @@ static gboolean file_data_check_changed_single_file(FileData *fd, struct stat *s
                {
                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;
@@ -394,6 +395,7 @@ static FileData *file_data_new(const gchar *path_utf8, struct stat *st, gboolean
 
        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;
@@ -997,6 +999,11 @@ gint filelist_sort_compare_filedata(FileData *fa, FileData *fb)
                        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;
index 7d493a8..bea2dc2 100644 (file)
@@ -135,6 +135,9 @@ gchar *sort_type_get_text(SortType method)
                case SORT_TIME:
                        return _("Sort by date");
                        break;
+               case SORT_CTIME:
+                       return _("Sort by file creation date");
+                       break;
                case SORT_EXIFTIME:
                        return _("Sort by Exif-date");
                        break;
@@ -191,6 +194,7 @@ GtkWidget *submenu_add_sort(GtkWidget *menu, GCallback func, gpointer data,
        submenu_add_sort_item(submenu, func, SORT_NUMBER, show_current, type);
 #endif
        submenu_add_sort_item(submenu, func, SORT_TIME, show_current, type);
+       submenu_add_sort_item(submenu, func, SORT_CTIME, show_current, type);
        submenu_add_sort_item(submenu, func, SORT_EXIFTIME, show_current, type);
        submenu_add_sort_item(submenu, func, SORT_SIZE, show_current, type);
        if (include_path) submenu_add_sort_item(submenu, func, SORT_PATH, show_current, type);
index d5a65c8..b903460 100644 (file)
@@ -49,6 +49,7 @@ typedef enum {
        SORT_NAME,
        SORT_SIZE,
        SORT_TIME,
+       SORT_CTIME,
        SORT_PATH,
        SORT_NUMBER,
        SORT_EXIFTIME
@@ -511,6 +512,7 @@ struct _FileData {
        gchar *collate_key_name_nocase;
        gint64 size;
        time_t date;
+       time_t cdate;
        mode_t mode; /* this is needed at least for notification in view_dir because it is preserved after the file/directory is deleted */
        gint sidecar_priority;