Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 49 additions & 4 deletions src/common/collection.c
Original file line number Diff line number Diff line change
Expand Up @@ -2349,16 +2349,60 @@ void dt_collection_sort_serialize(char *buf, int bufsize)
}
}

char *dt_collection_checksum(const gboolean filtering)
{
const char *plugin_name = filtering
? "plugins/lighttable/filtering"
: "plugins/lighttable/collect";
char confname[200];

snprintf(confname, sizeof(confname), "%s/num_rules", plugin_name);
const int num_rules = dt_conf_get_int(confname);

GChecksum *checksum = g_checksum_new(G_CHECKSUM_MD5);
g_checksum_update(checksum, (const guchar *)&num_rules, sizeof(int));

for(int k = 0; k < num_rules; k++)
{
snprintf(confname, sizeof(confname), "%s/mode%1d", plugin_name, k);
const int mode = dt_conf_get_int(confname);
g_checksum_update(checksum, (const guchar *)&mode, sizeof(int));

snprintf(confname, sizeof(confname), "%s/item%1d", plugin_name, k);
const int item = dt_conf_get_int(confname);
g_checksum_update(checksum, (const guchar *)&item, sizeof(int));

if(filtering)
{
snprintf(confname, sizeof(confname), "%s/off%1d", plugin_name, k);
const int off = dt_conf_get_int(confname);
g_checksum_update(checksum, (const guchar *)&off, sizeof(int));

snprintf(confname, sizeof(confname), "%s/top%1d", plugin_name, k);
const int top = dt_conf_get_int(confname);
g_checksum_update(checksum, (const guchar *)&top, sizeof(int));
}

snprintf(confname, sizeof(confname), "%s/string%1d", plugin_name, k);
const char *str = dt_conf_get_string_const(confname);
g_checksum_update(checksum, (const guchar *)str, strlen(str));
}

char *chk = g_strdup(g_checksum_get_string(checksum));
g_checksum_free(checksum);
return chk;
}

int dt_collection_serialize(char *buf, int bufsize,
const gboolean filtering)
{
const char *plugin_name = filtering
? "plugins/lighttable/filtering" : "plugins/lighttable/collect";
? "plugins/lighttable/filtering"
: "plugins/lighttable/collect";
char confname[200];
int c;
snprintf(confname, sizeof(confname), "%s/num_rules", plugin_name);
const int num_rules = dt_conf_get_int(confname);
c = snprintf(buf, bufsize, "%d:", num_rules);
int c = snprintf(buf, bufsize, "%d:", num_rules);
buf += c;
bufsize -= c;
for(int k = 0; k < num_rules; k++)
Expand Down Expand Up @@ -2401,7 +2445,8 @@ int dt_collection_serialize(char *buf, int bufsize,
void dt_collection_deserialize(const char *buf, const gboolean filtering)
{
const char *plugin_name = filtering
? "plugins/lighttable/filtering" : "plugins/lighttable/collect";
? "plugins/lighttable/filtering"
: "plugins/lighttable/collect";
char confname[200];
int num_rules = 0;
sscanf(buf, "%d", &num_rules);
Expand Down
6 changes: 4 additions & 2 deletions src/common/collection.h
Original file line number Diff line number Diff line change
Expand Up @@ -246,8 +246,10 @@ void dt_collection_hint_message(const dt_collection_t *collection);
int dt_collection_image_offset(dt_imgid_t imgid);

/* serialize and deserialize into a string. */
void dt_collection_deserialize(const char *buf, gboolean filtering);
int dt_collection_serialize(char *buf, int bufsize, gboolean filtering);
void dt_collection_deserialize(const char *buf, const gboolean filtering);
int dt_collection_serialize(char *buf, int bufsize, const gboolean filtering);
/* get a checksum for the current collection */
char * dt_collection_checksum(const gboolean filtering);

/* splits an input string into a number part and an optional operator part */
void dt_collection_split_operator_number(const gchar *input,
Expand Down
30 changes: 25 additions & 5 deletions src/control/jobs/control_jobs.c
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,8 @@ static int32_t _generic_dt_control_fileop_images_job_run
int32_t (*fileop_callback)(const int32_t,
const int32_t),
const char *desc,
const char *desc_pl)
const char *desc_pl,
const gboolean is_copy)
{
dt_control_image_enumerator_t *params = dt_control_job_get_params(job);
GList *t = params->index;
Expand All @@ -213,27 +214,44 @@ static int32_t _generic_dt_control_fileop_images_job_run
return -1;
}

int32_t col_count = dt_collection_get_collected_count();
char *old_chk = dt_collection_checksum(FALSE);

gboolean completeSuccess = TRUE;
double prev_time = 0;
while(t && !_job_cancelled(job))
{
completeSuccess &= (fileop_callback(GPOINTER_TO_INT(t->data), film_id) != -1);
const gboolean success = fileop_callback(GPOINTER_TO_INT(t->data), film_id) != -1;
completeSuccess &= success;
t = g_list_next(t);
fraction += 1.0 / total;
_update_progress(job, fraction, &prev_time);
if(success) col_count--;
}

if(completeSuccess)
char *new_chk = dt_collection_checksum(FALSE);
const gboolean col_changed = g_strcmp0(old_chk, new_chk) != 0;
g_free(old_chk);
g_free(new_chk);

// If there is no more image in the current collection or we did a
// copy and we did not change to a new collection then jump to the
// new location.
if(completeSuccess
&& !col_changed
&& (col_count == 0 || is_copy))
{
char collect[1024];
snprintf(collect, sizeof(collect), "1:0:0:%s$", new_film.dirname);
dt_collection_deserialize(collect, FALSE);
}
dt_film_remove_empty();

DT_CONTROL_SIGNAL_RAISE(DT_SIGNAL_FILMROLLS_CHANGED);
dt_collection_update_query(darktable.collection,
DT_COLLECTION_CHANGE_RELOAD, DT_COLLECTION_PROP_UNDEF,
g_list_copy(params->index));

dt_control_queue_redraw_center();
return 0;
}
Expand Down Expand Up @@ -1454,14 +1472,16 @@ static int32_t _control_move_images_job_run(dt_job_t *job)
{
return _generic_dt_control_fileop_images_job_run(job, &dt_image_move,
_("moving %d image"),
_("moving %d images"));
_("moving %d images"),
FALSE);
}

static int32_t _control_copy_images_job_run(dt_job_t *job)
{
return _generic_dt_control_fileop_images_job_run(job, &dt_image_copy,
_("copying %d image"),
_("copying %d images"));
_("copying %d images"),
TRUE);
}

static int32_t _control_local_copy_images_job_run(dt_job_t *job)
Expand Down
Loading