Skip to content

Commit

Permalink
lighttable: quick buttons for per-day filter
Browse files Browse the repository at this point in the history
  • Loading branch information
hanatos committed Sep 2, 2024
1 parent 8cfa8b3 commit b104227
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 7 deletions.
13 changes: 6 additions & 7 deletions src/db/db.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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);
}

Expand Down Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions src/db/db.h
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
43 changes: 43 additions & 0 deletions src/gui/render_lighttable.c
Original file line number Diff line number Diff line change
Expand Up @@ -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<vkdt.db.collection_cnt;i++)
{
if(day_cnt >= 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<day_cnt;i++)
{
dt_tooltip(dt_token_str(day[i])); // careful htis only works because we copy a max of 6<8 chars (so there'll always be 0 in the end)
if(nk_button_text(ctx, dt_token_str(day[i])+4, 2))
{
typed_filter_val = day[i];
vkdt.db.collection_filter_val = typed_filter_val;
update_collection = 1;
}
}
}
}
}
else if(filter_prop == s_prop_rating)
{
Expand Down

0 comments on commit b104227

Please sign in to comment.