Skip to content

Commit ef89847

Browse files
authored
Merge pull request #19898 from darktable-org/po/better-collection-jump
Fix jumping to new collection.
2 parents 92ba736 + 444a00e commit ef89847

File tree

3 files changed

+78
-11
lines changed

3 files changed

+78
-11
lines changed

src/common/collection.c

Lines changed: 49 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2349,16 +2349,60 @@ void dt_collection_sort_serialize(char *buf, int bufsize)
23492349
}
23502350
}
23512351

2352+
char *dt_collection_checksum(const gboolean filtering)
2353+
{
2354+
const char *plugin_name = filtering
2355+
? "plugins/lighttable/filtering"
2356+
: "plugins/lighttable/collect";
2357+
char confname[200];
2358+
2359+
snprintf(confname, sizeof(confname), "%s/num_rules", plugin_name);
2360+
const int num_rules = dt_conf_get_int(confname);
2361+
2362+
GChecksum *checksum = g_checksum_new(G_CHECKSUM_MD5);
2363+
g_checksum_update(checksum, (const guchar *)&num_rules, sizeof(int));
2364+
2365+
for(int k = 0; k < num_rules; k++)
2366+
{
2367+
snprintf(confname, sizeof(confname), "%s/mode%1d", plugin_name, k);
2368+
const int mode = dt_conf_get_int(confname);
2369+
g_checksum_update(checksum, (const guchar *)&mode, sizeof(int));
2370+
2371+
snprintf(confname, sizeof(confname), "%s/item%1d", plugin_name, k);
2372+
const int item = dt_conf_get_int(confname);
2373+
g_checksum_update(checksum, (const guchar *)&item, sizeof(int));
2374+
2375+
if(filtering)
2376+
{
2377+
snprintf(confname, sizeof(confname), "%s/off%1d", plugin_name, k);
2378+
const int off = dt_conf_get_int(confname);
2379+
g_checksum_update(checksum, (const guchar *)&off, sizeof(int));
2380+
2381+
snprintf(confname, sizeof(confname), "%s/top%1d", plugin_name, k);
2382+
const int top = dt_conf_get_int(confname);
2383+
g_checksum_update(checksum, (const guchar *)&top, sizeof(int));
2384+
}
2385+
2386+
snprintf(confname, sizeof(confname), "%s/string%1d", plugin_name, k);
2387+
const char *str = dt_conf_get_string_const(confname);
2388+
g_checksum_update(checksum, (const guchar *)str, strlen(str));
2389+
}
2390+
2391+
char *chk = g_strdup(g_checksum_get_string(checksum));
2392+
g_checksum_free(checksum);
2393+
return chk;
2394+
}
2395+
23522396
int dt_collection_serialize(char *buf, int bufsize,
23532397
const gboolean filtering)
23542398
{
23552399
const char *plugin_name = filtering
2356-
? "plugins/lighttable/filtering" : "plugins/lighttable/collect";
2400+
? "plugins/lighttable/filtering"
2401+
: "plugins/lighttable/collect";
23572402
char confname[200];
2358-
int c;
23592403
snprintf(confname, sizeof(confname), "%s/num_rules", plugin_name);
23602404
const int num_rules = dt_conf_get_int(confname);
2361-
c = snprintf(buf, bufsize, "%d:", num_rules);
2405+
int c = snprintf(buf, bufsize, "%d:", num_rules);
23622406
buf += c;
23632407
bufsize -= c;
23642408
for(int k = 0; k < num_rules; k++)
@@ -2401,7 +2445,8 @@ int dt_collection_serialize(char *buf, int bufsize,
24012445
void dt_collection_deserialize(const char *buf, const gboolean filtering)
24022446
{
24032447
const char *plugin_name = filtering
2404-
? "plugins/lighttable/filtering" : "plugins/lighttable/collect";
2448+
? "plugins/lighttable/filtering"
2449+
: "plugins/lighttable/collect";
24052450
char confname[200];
24062451
int num_rules = 0;
24072452
sscanf(buf, "%d", &num_rules);

src/common/collection.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -246,8 +246,10 @@ void dt_collection_hint_message(const dt_collection_t *collection);
246246
int dt_collection_image_offset(dt_imgid_t imgid);
247247

248248
/* serialize and deserialize into a string. */
249-
void dt_collection_deserialize(const char *buf, gboolean filtering);
250-
int dt_collection_serialize(char *buf, int bufsize, gboolean filtering);
249+
void dt_collection_deserialize(const char *buf, const gboolean filtering);
250+
int dt_collection_serialize(char *buf, int bufsize, const gboolean filtering);
251+
/* get a checksum for the current collection */
252+
char * dt_collection_checksum(const gboolean filtering);
251253

252254
/* splits an input string into a number part and an optional operator part */
253255
void dt_collection_split_operator_number(const gchar *input,

src/control/jobs/control_jobs.c

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,8 @@ static int32_t _generic_dt_control_fileop_images_job_run
193193
int32_t (*fileop_callback)(const int32_t,
194194
const int32_t),
195195
const char *desc,
196-
const char *desc_pl)
196+
const char *desc_pl,
197+
const gboolean is_copy)
197198
{
198199
dt_control_image_enumerator_t *params = dt_control_job_get_params(job);
199200
GList *t = params->index;
@@ -215,27 +216,44 @@ static int32_t _generic_dt_control_fileop_images_job_run
215216
return -1;
216217
}
217218

219+
int32_t col_count = dt_collection_get_collected_count();
220+
char *old_chk = dt_collection_checksum(FALSE);
221+
218222
gboolean completeSuccess = TRUE;
219223
double prev_time = 0;
220224
while(t && !_job_cancelled(job))
221225
{
222-
completeSuccess &= (fileop_callback(GPOINTER_TO_INT(t->data), film_id) != -1);
226+
const gboolean success = fileop_callback(GPOINTER_TO_INT(t->data), film_id) != -1;
227+
completeSuccess &= success;
223228
t = g_list_next(t);
224229
fraction += 1.0 / total;
225230
_update_progress(job, fraction, &prev_time);
231+
if(success) col_count--;
226232
}
227233

228-
if(completeSuccess)
234+
char *new_chk = dt_collection_checksum(FALSE);
235+
const gboolean col_changed = g_strcmp0(old_chk, new_chk) != 0;
236+
g_free(old_chk);
237+
g_free(new_chk);
238+
239+
// If there is no more image in the current collection or we did a
240+
// copy and we did not change to a new collection then jump to the
241+
// new location.
242+
if(completeSuccess
243+
&& !col_changed
244+
&& (col_count == 0 || is_copy))
229245
{
230246
char collect[1024];
231247
snprintf(collect, sizeof(collect), "1:0:0:%s$", new_film.dirname);
232248
dt_collection_deserialize(collect, FALSE);
233249
}
234250
dt_film_remove_empty();
251+
235252
DT_CONTROL_SIGNAL_RAISE(DT_SIGNAL_FILMROLLS_CHANGED);
236253
dt_collection_update_query(darktable.collection,
237254
DT_COLLECTION_CHANGE_RELOAD, DT_COLLECTION_PROP_UNDEF,
238255
g_list_copy(params->index));
256+
239257
dt_control_queue_redraw_center();
240258
return 0;
241259
}
@@ -1456,14 +1474,16 @@ static int32_t _control_move_images_job_run(dt_job_t *job)
14561474
{
14571475
return _generic_dt_control_fileop_images_job_run(job, &dt_image_move,
14581476
_("moving %d image"),
1459-
_("moving %d images"));
1477+
_("moving %d images"),
1478+
FALSE);
14601479
}
14611480

14621481
static int32_t _control_copy_images_job_run(dt_job_t *job)
14631482
{
14641483
return _generic_dt_control_fileop_images_job_run(job, &dt_image_copy,
14651484
_("copying %d image"),
1466-
_("copying %d images"));
1485+
_("copying %d images"),
1486+
TRUE);
14671487
}
14681488

14691489
static int32_t _control_local_copy_images_job_run(dt_job_t *job)

0 commit comments

Comments
 (0)