diff --git a/src/db/db.c b/src/db/db.c index 700eb33c..63b2c2f7 100644 --- a/src/db/db.c +++ b/src/db/db.c @@ -78,14 +78,13 @@ compare_labels(const void *a, const void *b, void *arg) return db->image[ia[0]].labels - db->image[ib[0]].labels; } -static inline void -read_createdate(const dt_db_t *db, uint32_t imgid, char createdate[20]) +void +dt_db_read_createdate(const dt_db_t *db, uint32_t imgid, char createdate[20]) { char fn[1024], f[1024]; dt_db_image_path(db, imgid, fn, sizeof(fn)); - size_t off; fs_realpath(fn, f); - off = strnlen(f, sizeof(f)); + size_t off = strnlen(f, sizeof(f)); if(off > 4) f[off - 4] = 0; else f[off] = 0; @@ -102,8 +101,8 @@ compare_createdate(const void *a, const void *b, void *arg) dt_db_t *db = arg; const uint32_t *ia = a, *ib = b; char cda[20] = {0}, cdb[20] = {0}; - read_createdate(db, ia[0], cda); - read_createdate(db, ib[0], cdb); + dt_db_read_createdate(db, ia[0], cda); + dt_db_read_createdate(db, ib[0], cdb); return strcmp(cda, cdb); } @@ -149,7 +148,7 @@ dt_db_update_collection(dt_db_t *db) if(!(db->image[k].labels & db->collection_filter_val)) continue; break; case s_prop_createdate: - read_createdate(db, k, createdate); + dt_db_read_createdate(db, k, createdate); char val[10]; snprintf(val, sizeof(val), "%" PRItkn, dt_token_str(db->collection_filter_val)); if(!strstr(createdate, val)) continue; break; diff --git a/src/db/db.h b/src/db/db.h index d9c2e748..ad221d11 100644 --- a/src/db/db.h +++ b/src/db/db.h @@ -192,3 +192,5 @@ void dt_db_current_set(dt_db_t *db, uint32_t colid); // internal storage anyways. this is all done at once by calling dt_gui_switch_collection, // which by separation of concerns also cares about the thumbnail creation (the db doesn't). void dt_db_duplicate_selected_images(dt_db_t *db); +// convenience function to read create date of an image +void dt_db_read_createdate(const dt_db_t *db, uint32_t imgid, char createdate[20]); diff --git a/src/gui/render_lighttable.c b/src/gui/render_lighttable.c index 1d66d15a..e3df0463 100644 --- a/src/gui/render_lighttable.c +++ b/src/gui/render_lighttable.c @@ -632,6 +632,49 @@ void render_lighttable_right_panel() vkdt.db.collection_filter_val = typed_filter_val; update_collection = 1; } + static int cached_hash = 0; + static int day_cnt = 0; + static dt_token_t day[31]; // okay if you have more than a month you should split it some other way first + if(sort_prop == s_prop_createdate) + { + int hash = nk_murmur_hash(vkdt.db.dirname, (int)nk_strlen(vkdt.db.dirname), 0); + if(hash != cached_hash) + { + dt_tooltip("create list of quick buttons for every day in current collection"); + if(nk_button_label(ctx, "by day")) + { + day_cnt = 0; + for(int i=0;i= NK_LEN(day)) break; + char createdate[20]; + dt_db_read_createdate(&vkdt.db, vkdt.db.collection[i], createdate); + if(!day_cnt || strncmp(createdate+4, dt_token_str(day[day_cnt-1]), 6)) + { + day[day_cnt] = 0; + strncpy(dt_token_str(day[day_cnt]), createdate+4, 6); + day_cnt++; + } + } + cached_hash = hash; + } + } + else + { + nk_label(ctx, "", 0); + nk_layout_row_dynamic(ctx, row_height, 7); + for(int i=0;i