Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

po/progress meters for history actions (compress/copy/discard) #17302

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
add progress meter/cancellation to history discard/compress/paste
  • Loading branch information
ralfbrown authored and TurboGit committed Aug 9, 2024
commit e202223fbc8fe2c65a882406932f3748f957eaae
247 changes: 71 additions & 176 deletions src/common/history.c
Original file line number Diff line number Diff line change
Expand Up @@ -1367,86 +1367,75 @@ void dt_history_truncate_on_image(const dt_imgid_t imgid,
DT_SIGNAL_DEVELOP_MIPMAP_UPDATED, imgid);
}

int dt_history_compress_on_list(const GList *imgs)
gboolean dt_history_compress(const dt_imgid_t imgid)
{
int uncompressed=0;

// Get the list of selected images
for(const GList *l = imgs; l; l = g_list_next(l))
dt_lock_image(imgid);
const int test = dt_history_end_attop(imgid);
if(test == 1) // we do a compression and we know for sure history_end is at the top!
{
const dt_imgid_t imgid = GPOINTER_TO_INT(l->data);
dt_lock_image(imgid);
const int test = dt_history_end_attop(imgid);
if(test == 1) // we do a compression and we know for sure history_end is at the top!
{
dt_history_compress_on_image(imgid);
dt_history_compress_on_image(imgid);

// now the modules are in right order but need renumbering to remove leaks
int max=0; // the maximum num in main_history for an image
int size=0; // the number of items in main_history for an image
int done=0; // used for renumbering index
// now the modules are in right order but need renumbering to remove leaks
int max=0; // the maximum num in main_history for an image
int size=0; // the number of items in main_history for an image
int done=0; // used for renumbering index

sqlite3_stmt *stmt2;
sqlite3_stmt *stmt2;

// get highest num in history
DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db),
"SELECT MAX(num) FROM main.history WHERE imgid=?1", -1, &stmt2, NULL);
DT_DEBUG_SQLITE3_BIND_INT(stmt2, 1, imgid);
if(sqlite3_step(stmt2) == SQLITE_ROW)
max = sqlite3_column_int(stmt2, 0);
sqlite3_finalize(stmt2);
// get highest num in history
DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db),
"SELECT MAX(num) FROM main.history WHERE imgid=?1", -1, &stmt2, NULL);
DT_DEBUG_SQLITE3_BIND_INT(stmt2, 1, imgid);
if(sqlite3_step(stmt2) == SQLITE_ROW)
max = sqlite3_column_int(stmt2, 0);
sqlite3_finalize(stmt2);

// get number of items in main.history
DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db),
"SELECT COUNT(*) FROM main.history WHERE imgid = ?1", -1, &stmt2, NULL);
DT_DEBUG_SQLITE3_BIND_INT(stmt2, 1, imgid);
if(sqlite3_step(stmt2) == SQLITE_ROW)
size = sqlite3_column_int(stmt2, 0);
sqlite3_finalize(stmt2);
// get number of items in main.history
DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db),
"SELECT COUNT(*) FROM main.history WHERE imgid = ?1", -1, &stmt2, NULL);
DT_DEBUG_SQLITE3_BIND_INT(stmt2, 1, imgid);
if(sqlite3_step(stmt2) == SQLITE_ROW)
size = sqlite3_column_int(stmt2, 0);
sqlite3_finalize(stmt2);

if((size>0) && (max>0))
if((size>0) && (max>0))
{
for(int index=0;index<(max+1);index++)
{
for(int index=0;index<(max+1);index++)
sqlite3_stmt *stmt3;
DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db),
"SELECT num FROM main.history WHERE imgid=?1 AND num=?2", -1, &stmt3, NULL);
DT_DEBUG_SQLITE3_BIND_INT(stmt3, 1, imgid);
DT_DEBUG_SQLITE3_BIND_INT(stmt3, 2, index);
if(sqlite3_step(stmt3) == SQLITE_ROW)
{
sqlite3_stmt *stmt3;
DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db),
"SELECT num FROM main.history WHERE imgid=?1 AND num=?2", -1, &stmt3, NULL);
DT_DEBUG_SQLITE3_BIND_INT(stmt3, 1, imgid);
DT_DEBUG_SQLITE3_BIND_INT(stmt3, 2, index);
if(sqlite3_step(stmt3) == SQLITE_ROW)
{
sqlite3_stmt *stmt4;
// step by step set the correct num
DT_DEBUG_SQLITE3_PREPARE_V2
(dt_database_get(darktable.db),
"UPDATE main.history"
" SET num = ?3"
" WHERE imgid = ?1 AND num = ?2",
-1, &stmt4, NULL);
DT_DEBUG_SQLITE3_BIND_INT(stmt4, 1, imgid);
DT_DEBUG_SQLITE3_BIND_INT(stmt4, 2, index);
DT_DEBUG_SQLITE3_BIND_INT(stmt4, 3, done);
sqlite3_step(stmt4);
sqlite3_finalize(stmt4);

done++;
}
sqlite3_finalize(stmt3);
sqlite3_stmt *stmt4;
// step by step set the correct num
DT_DEBUG_SQLITE3_PREPARE_V2
(dt_database_get(darktable.db),
"UPDATE main.history"
" SET num = ?3"
" WHERE imgid = ?1 AND num = ?2",
-1, &stmt4, NULL);
DT_DEBUG_SQLITE3_BIND_INT(stmt4, 1, imgid);
DT_DEBUG_SQLITE3_BIND_INT(stmt4, 2, index);
DT_DEBUG_SQLITE3_BIND_INT(stmt4, 3, done);
sqlite3_step(stmt4);
sqlite3_finalize(stmt4);

done++;
}
sqlite3_finalize(stmt3);
}
// update history end
dt_image_set_history_end(imgid, done);

dt_image_synch_xmp(imgid);
}
if(test == 0) // no compression as history_end is right in the middle of history
uncompressed++;
// update history end
dt_image_set_history_end(imgid, done);

dt_unlock_image(imgid);
dt_history_hash_write_from_history(imgid, DT_HISTORY_HASH_CURRENT);
dt_image_write_sidecar_file(imgid);
}

return uncompressed;
dt_unlock_image(imgid);
dt_history_hash_write_from_history(imgid, DT_HISTORY_HASH_CURRENT);
return (test == 1);
}

gboolean dt_history_check_module_exists(const dt_imgid_t imgid,
Expand Down Expand Up @@ -1889,113 +1878,20 @@ gboolean dt_history_copy_parts(const dt_imgid_t imgid)
return FALSE;
}

gboolean dt_history_paste_on_list(const GList *list,
const gboolean undo)
gboolean dt_history_paste(const dt_imgid_t imgid, const gboolean merge)
{
if(!dt_is_valid_imgid(darktable.view_manager->copy_paste.copied_imageid))
return FALSE;

if(!list) // do we have any images to receive the pasted history?
return FALSE;

const int mode = dt_conf_get_int("plugins/lighttable/copy_history/pastemode");
const gboolean merge = (mode == 0) ? TRUE : FALSE;

if(undo)
dt_undo_start_group(darktable.undo, DT_UNDO_LT_HISTORY);

for(GList *l = (GList *)list; l; l = g_list_next(l))
{
const int dest = GPOINTER_TO_INT(l->data);
dt_history_copy_and_paste_on_image(darktable.view_manager->copy_paste.copied_imageid,
dest, merge,
darktable.view_manager->copy_paste.selops,
darktable.view_manager->copy_paste.copy_iop_order,
darktable.view_manager->copy_paste.full_copy);
}

if(undo)
dt_undo_end_group(darktable.undo);

// In darkroom and if there is a copy of the iop-order we need to rebuild the pipe
// to take into account the possible new order of modules.
if(dt_view_get_current() == DT_VIEW_DARKROOM)
{
dt_dev_pixelpipe_rebuild(darktable.develop);
}

dt_history_copy_and_paste_on_image(darktable.view_manager->copy_paste.copied_imageid,
imgid, merge,
darktable.view_manager->copy_paste.selops,
darktable.view_manager->copy_paste.copy_iop_order,
darktable.view_manager->copy_paste.full_copy);
return TRUE;
}

gboolean dt_history_paste_parts_on_list(const GList *list,
const gboolean undo)
gboolean dt_history_delete(const dt_imgid_t imgid, const gboolean undo)
{
if(!dt_is_valid_imgid(darktable.view_manager->copy_paste.copied_imageid))
return FALSE;

if(!list) // do we have any images to receive the pasted history?
return FALSE;

const int mode = dt_conf_get_int("plugins/lighttable/copy_history/pastemode");
const gboolean merge = (mode == 0) ? TRUE : FALSE;

// at the time the dialog is started, some signals are sent and this in turn call
// back dt_view_get_images_to_act_on() which free list and create a new one.

GList *l_copy = g_list_copy((GList *)list);

// we launch the dialog
const int res = dt_gui_hist_dialog_new
(&(darktable.view_manager->copy_paste),
darktable.view_manager->copy_paste.copied_imageid, FALSE);

if(res != GTK_RESPONSE_OK)
{
g_list_free(l_copy);
return FALSE;
}

if(undo)
dt_undo_start_group(darktable.undo, DT_UNDO_LT_HISTORY);

for(const GList *l = l_copy; l; l = g_list_next(l))
{
const int dest = GPOINTER_TO_INT(l->data);
dt_history_copy_and_paste_on_image(darktable.view_manager->copy_paste.copied_imageid,
dest, merge,
darktable.view_manager->copy_paste.selops,
darktable.view_manager->copy_paste.copy_iop_order,
darktable.view_manager->copy_paste.full_copy);
}

if(undo)
dt_undo_end_group(darktable.undo);

g_list_free(l_copy);

// In darkroom and if there is a copy of the iop-order we need to
// rebuild the pipe to take into account the possible new order of
// modules.
if(dt_view_get_current() == DT_VIEW_DARKROOM)
{
dt_dev_pixelpipe_rebuild(darktable.develop);
}

return TRUE;
}

gboolean dt_history_delete_on_list(const GList *list,
const gboolean undo)
{
if(!list) // do we have any images on which to operate?
return FALSE;

dt_gui_cursor_set_busy();
if(undo) dt_undo_start_group(darktable.undo, DT_UNDO_LT_HISTORY);

for(GList *l = (GList *)list; l; l = g_list_next(l))
{
const dt_imgid_t imgid = GPOINTER_TO_INT(l->data);
dt_undo_lt_history_t *hist = dt_history_snapshot_item_init();

hist->imgid = imgid;
Expand All @@ -2008,18 +1904,17 @@ gboolean dt_history_delete_on_list(const GList *list,
dt_undo_record(darktable.undo, NULL, DT_UNDO_LT_HISTORY,
(dt_undo_data_t)hist, dt_history_snapshot_undo_pop,
dt_history_snapshot_undo_lt_history_data_free);

/* update the aspect ratio if the current sorting is based on
aspect ratio, otherwise the aspect ratio will be recalculated
when the mimpap will be recreated */
if(darktable.collection->params.sorts[DT_COLLECTION_SORT_ASPECT_RATIO])
dt_image_set_aspect_ratio(imgid, FALSE);
}
else
{
dt_history_delete_on_image_ext(imgid, FALSE, TRUE);
}

DT_DEBUG_CONTROL_SIGNAL_RAISE(darktable.signals, DT_SIGNAL_TAG_CHANGED);

if(undo) dt_undo_end_group(darktable.undo);
dt_gui_cursor_clear_busy();
/* update the aspect ratio if the current sorting is based on
aspect ratio, otherwise the aspect ratio will be recalculated
when the mimpap will be recreated */
if(darktable.collection->params.sorts[DT_COLLECTION_SORT_ASPECT_RATIO])
dt_image_set_aspect_ratio(imgid, FALSE);
return TRUE;
}

Expand Down
7 changes: 5 additions & 2 deletions src/common/history.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ void dt_history_delete_on_image_ext(const dt_imgid_t imgid,
/** copy history from imgid and pasts on selected images, merge or overwrite... */
gboolean dt_history_copy(const dt_imgid_t imgid);
gboolean dt_history_copy_parts(const dt_imgid_t imgid);
gboolean dt_history_paste(const dt_imgid_t imgid, gboolean merge); // requires prior setup of copied history
gboolean dt_history_paste_on_list(const GList *list,
gboolean undo);
gboolean dt_history_paste_parts_on_list(const GList *list,
Expand All @@ -114,12 +115,14 @@ gboolean dt_history_load_and_apply(const dt_imgid_t imgid,
const gboolean history_only);

/** delete historystack of selected images */
gboolean dt_history_delete(const dt_imgid_t imgid,
const gboolean undo);
gboolean dt_history_delete_on_list(const GList *list,
const gboolean undo);

/** compress history stack */
int dt_history_compress_on_list(const GList *imgs);
void dt_history_compress_on_image(const dt_imgid_t imgid);
gboolean dt_history_compress(const dt_imgid_t imgid); // syncs to sidecar, says whether compress was successful
void dt_history_compress_on_image(const dt_imgid_t imgid); // database only

/** truncate history stack */
void dt_history_truncate_on_image(const dt_imgid_t imgid,
Expand Down
Loading