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/style multi name #13391

Closed
wants to merge 5 commits into from
Closed
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
24 changes: 20 additions & 4 deletions src/common/database.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
// whenever _create_*_schema() gets changed you HAVE to bump this version and add an update path to
// _upgrade_*_schema_step()!
#define CURRENT_DATABASE_VERSION_LIBRARY 38
#define CURRENT_DATABASE_VERSION_DATA 9
#define CURRENT_DATABASE_VERSION_DATA 10

// #define USE_NESTED_TRANSACTIONS
#define MAX_NESTED_TRANSACTIONS 0
Expand Down Expand Up @@ -2375,6 +2375,20 @@ static int _upgrade_data_schema_step(dt_database_t *db, int version)
// clang-format on
new_version = 9;
}
else if(version == 9)
{
TRY_EXEC("ALTER TABLE data.style_items ADD COLUMN multi_name_hand_edited INTEGER default 0",
"[init] can't add multi_name_hand_edited column\n");
TRY_EXEC("UPDATE data.style_items SET multi_name_hand_edited = 1 WHERE multi_name != ''",
"[init] can't set multi_name_hand_edited column\n");

TRY_EXEC("ALTER TABLE data.presets ADD COLUMN multi_name_hand_edited INTEGER default 0",
"[init] can't add multi_name_hand_edited column\n");
TRY_EXEC("UPDATE data.presets SET multi_name_hand_edited = 1 WHERE multi_name != ''",
"[init] can't set multi_name_hand_edited column\n");

new_version = 10;
}
else
new_version = version; // should be the fallback so that calling code sees that we are in an infinite loop

Expand Down Expand Up @@ -2557,9 +2571,11 @@ static void _create_data_schema(dt_database_t *db)
////////////////////////////// style_items
sqlite3_exec(
db->handle,
"CREATE TABLE data.style_items (styleid INTEGER, num INTEGER, module INTEGER, "
"operation VARCHAR(256), op_params BLOB, enabled INTEGER, "
"blendop_params BLOB, blendop_version INTEGER, multi_priority INTEGER, multi_name VARCHAR(256))",
"CREATE TABLE data.style_items (styleid INTEGER, num INTEGER, module INTEGER,"
" operation VARCHAR(256), op_params BLOB, enabled INTEGER,"
" blendop_params BLOB, blendop_version INTEGER,"
" multi_priority INTEGER, multi_name VARCHAR(256),"
" multi_name_hand_edited INTEGER)",
NULL, NULL, NULL);
sqlite3_exec(
db->handle,
Expand Down
76 changes: 49 additions & 27 deletions src/common/history.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ static void _remove_preset_flag(const int imgid)
dt_image_cache_write_release(darktable.image_cache, image, DT_IMAGE_CACHE_SAFE);
}

void dt_history_delete_on_image_ext(int32_t imgid, gboolean undo)
void dt_history_delete_on_image_ext(const int32_t imgid, const gboolean undo)
{
dt_undo_lt_history_t *hist = undo?dt_history_snapshot_item_init():NULL;

Expand Down Expand Up @@ -283,13 +283,24 @@ static void _fill_used_forms(GList *forms_list, int formid, int *used, int nb)
}

// dev_src is used only to copy masks, if no mask will be copied it can be null
int dt_history_merge_module_into_history(dt_develop_t *dev_dest, dt_develop_t *dev_src, dt_iop_module_t *mod_src, GList **_modules_used, const int append)
int dt_history_merge_module_into_history(dt_develop_t *dev_dest,
dt_develop_t *dev_src,
dt_iop_module_t *mod_src,
GList **_modules_used,
const int append)
{
int module_added = 1;
GList *modules_used = *_modules_used;
dt_iop_module_t *module = NULL;
dt_iop_module_t *mod_replace = NULL;

char modsrc_multi_name[128] = { 0 };

// use multi-name for match copied instance only for hand-edited names
// for the multi-priority = 0 (first instance).

g_strlcpy(modsrc_multi_name, dt_iop_get_instance_name(mod_src), sizeof(modsrc_multi_name));

// one-instance modules always replace the existing one
if(mod_src->flags() & IOP_FLAGS_ONE_INSTANCE)
{
Expand Down Expand Up @@ -319,7 +330,7 @@ int dt_history_merge_module_into_history(dt_develop_t *dev_dest, dt_develop_t *d
dt_iop_module_t *mod_dest = (dt_iop_module_t *)modules_dest->data;

if(strcmp(mod_src->op, mod_dest->op) == 0
&& strcmp(mod_src->multi_name, mod_dest->multi_name) == 0)
&& strcmp(modsrc_multi_name, mod_dest->multi_name) == 0)
{
// but only if it hasn't been used already
if(_search_list_iop_by_module(modules_used, mod_dest) == NULL)
Expand Down Expand Up @@ -376,7 +387,7 @@ int dt_history_merge_module_into_history(dt_develop_t *dev_dest, dt_develop_t *d
}

module->enabled = mod_src->enabled;
g_strlcpy(module->multi_name, mod_src->multi_name, sizeof(module->multi_name));
g_strlcpy(module->multi_name, modsrc_multi_name, sizeof(module->multi_name));

memcpy(module->params, mod_src->params, module->params_size);
if(module->flags() & IOP_FLAGS_SUPPORTS_BLENDING)
Expand Down Expand Up @@ -489,7 +500,10 @@ int dt_history_merge_module_into_history(dt_develop_t *dev_dest, dt_develop_t *d
return module_added;
}

static int _history_copy_and_paste_on_image_merge(int32_t imgid, int32_t dest_imgid, GList *ops, const gboolean copy_full)
static int _history_copy_and_paste_on_image_merge(const int32_t imgid,
const int32_t dest_imgid,
GList *ops,
const gboolean copy_full)
{
GList *modules_used = NULL;

Expand Down Expand Up @@ -593,7 +607,10 @@ static int _history_copy_and_paste_on_image_merge(int32_t imgid, int32_t dest_im
return 0;
}

static int _history_copy_and_paste_on_image_overwrite(const int32_t imgid, const int32_t dest_imgid, GList *ops, const gboolean copy_full)
static int _history_copy_and_paste_on_image_overwrite(const int32_t imgid,
const int32_t dest_imgid,
GList *ops,
const gboolean copy_full)
{
int ret_val = 0;
sqlite3_stmt *stmt;
Expand Down Expand Up @@ -649,10 +666,10 @@ static int _history_copy_and_paste_on_image_overwrite(const int32_t imgid, const
// clang-format off
gchar *query = g_strdup_printf
("INSERT INTO main.history "
" (imgid,num,module,operation,op_params,enabled,blendop_params, "
" blendop_version,multi_priority,multi_name,multi_name_hand_edited)"
" SELECT ?1,num,module,operation,op_params,enabled,blendop_params, "
" blendop_version,multi_priority,multi_name,multi_name_hand_edited "
" (imgid, num, module, operation, op_params, enabled, blendop_params,"
" blendop_version, multi_priority, multi_name, multi_name_hand_edited)"
" SELECT ?1, num, module, operation, op_params, enabled, blendop_params,"
" blendop_version, multi_priority, multi_name, multi_name_hand_edited"
" FROM main.history"
" WHERE imgid=?2"
" AND operation NOT IN (%s)"
Expand All @@ -674,7 +691,8 @@ static int _history_copy_and_paste_on_image_overwrite(const int32_t imgid, const
" SELECT ?1, num, formid, form, name, version, points, points_count, source "
" FROM main.masks_history"
" WHERE imgid = ?2"
" AND num NOT IN (SELECT num FROM history WHERE imgid=?2 AND OPERATION IN (%s))", skip_modules);
" AND num NOT IN (SELECT num FROM history WHERE imgid=?2 AND OPERATION IN (%s))",
skip_modules);
// clang-format on

DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db), query, -1, &stmt, NULL);
Expand Down Expand Up @@ -757,9 +775,12 @@ static int _history_copy_and_paste_on_image_overwrite(const int32_t imgid, const
return ret_val;
}

gboolean dt_history_copy_and_paste_on_image(const int32_t imgid, const int32_t dest_imgid,
const gboolean merge, GList *ops,
const gboolean copy_iop_order, const gboolean copy_full)
gboolean dt_history_copy_and_paste_on_image(const int32_t imgid,
const int32_t dest_imgid,
const gboolean merge,
GList *ops,
const gboolean copy_iop_order,
const gboolean copy_full)
{
if(imgid == dest_imgid) return 1;

Expand Down Expand Up @@ -844,12 +865,12 @@ gboolean dt_history_copy_and_paste_on_image(const int32_t imgid, const int32_t d
return ret_val;
}

char *dt_history_item_as_string(const char *name, gboolean enabled)
char *dt_history_item_as_string(const char *name, const gboolean enabled)
{
return g_strconcat(enabled ? "●" : "○", " ", name, NULL);
}

GList *dt_history_get_items(const int32_t imgid, gboolean enabled)
GList *dt_history_get_items(const int32_t imgid, const gboolean enabled)
{
GList *result = NULL;
sqlite3_stmt *stmt;
Expand Down Expand Up @@ -1098,8 +1119,9 @@ void dt_history_compress_on_image(const int32_t imgid)
// create a mask manager entry in history as first entry
// clang-format off
DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db),
"INSERT INTO main.history (imgid, num, operation, op_params, module, enabled, "
" blendop_params, blendop_version, multi_priority, multi_name) "
"INSERT INTO main.history"
" (imgid, num, operation, op_params, module, enabled,"
" blendop_params, blendop_version, multi_priority, multi_name)"
" VALUES(?1, 0, ?2, NULL, 1, 0, NULL, 0, 0, '')",
-1, &stmt, NULL);
// clang-format on
Expand Down Expand Up @@ -1282,7 +1304,9 @@ gboolean dt_history_check_module_exists(int32_t imgid, const char *operation, gb
return result;
}

gboolean dt_history_check_module_exists_list(GList *hist, const char *operation, gboolean enabled)
gboolean dt_history_check_module_exists_list(GList *hist,
const char *operation,
const gboolean enabled)
{
for(GList *h = hist; h; h = g_list_next(h))
{
Expand Down Expand Up @@ -1672,7 +1696,7 @@ dt_history_hash_t dt_history_hash_get_status(const int32_t imgid)
return status;
}

gboolean dt_history_copy(int imgid)
gboolean dt_history_copy(const int imgid)
{
// note that this routine does not copy anything, it just setup the copy_paste proxy
// with the needed information that will be used while pasting.
Expand All @@ -1694,7 +1718,7 @@ gboolean dt_history_copy(int imgid)
return TRUE;
}

gboolean dt_history_copy_parts(int imgid)
gboolean dt_history_copy_parts(const int imgid)
{
if(dt_history_copy(imgid))
{
Expand All @@ -1711,15 +1735,14 @@ gboolean dt_history_copy_parts(int imgid)
return FALSE;
}

gboolean dt_history_paste_on_list(const GList *list, gboolean undo)
gboolean dt_history_paste_on_list(const GList *list, const gboolean undo)
{
if(darktable.view_manager->copy_paste.copied_imageid <= 0) 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");
gboolean merge = FALSE;
if(mode == 0) merge = TRUE;
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))
Expand Down Expand Up @@ -1754,8 +1777,7 @@ gboolean dt_history_paste_parts_on_list(const GList *list, gboolean undo)
return FALSE;

const int mode = dt_conf_get_int("plugins/lighttable/copy_history/pastemode");
gboolean merge = FALSE;
if(mode == 0) merge = TRUE;
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.
Expand Down Expand Up @@ -1800,7 +1822,7 @@ gboolean dt_history_paste_parts_on_list(const GList *list, gboolean undo)
return TRUE;
}

gboolean dt_history_delete_on_list(const GList *list, gboolean undo)
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;
Expand Down
14 changes: 11 additions & 3 deletions src/common/history.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,19 @@ typedef struct dt_history_copy_item_t
void dt_history_item_free(gpointer data);

/** adds to dev_dest module mod_src */
int dt_history_merge_module_into_history(struct dt_develop_t *dev_dest, struct dt_develop_t *dev_src, struct dt_iop_module_t *mod_src, GList **_modules_used, const int append);
int dt_history_merge_module_into_history(struct dt_develop_t *dev_dest,
struct dt_develop_t *dev_src,
struct dt_iop_module_t *mod_src,
GList **_modules_used,
const int append);

/** copy history from imgid and pasts on dest_imgid, merge or overwrite... */
int dt_history_copy_and_paste_on_image(int32_t imgid, int32_t dest_imgid, gboolean merge, GList *ops, gboolean copy_iop_order, const gboolean copy_full);
int dt_history_copy_and_paste_on_image(const int32_t imgid,
const int32_t dest_imgid,
const gboolean merge,
GList *ops,
const gboolean copy_iop_order,
const gboolean copy_full);

/** delete all history for the given image */
void dt_history_delete_on_image(int32_t imgid);
Expand Down Expand Up @@ -151,4 +160,3 @@ void dt_history_hash_read(const int32_t imgid, dt_history_hash_values_t *hash);
// vim: shiftwidth=2 expandtab tabstop=2 cindent
// kate: tab-indents: off; indent-width 2; replace-tabs on; indent-mode cstyle; remove-trailing-spaces modified;
// clang-format on

Loading