GList *dt_history_get_items(int32_t imgid, gboolean enabled) { GList *result = NULL; sqlite3_stmt *stmt; DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db), "SELECT num, operation, enabled, multi_name FROM main.history WHERE imgid=?1 AND " "num IN (SELECT MAX(num) FROM main.history hst2 WHERE hst2.imgid=?1 AND " "hst2.operation=main.history.operation GROUP BY multi_priority) ORDER BY num DESC", -1, &stmt, NULL); DT_DEBUG_SQLITE3_BIND_INT(stmt, 1, imgid); while(sqlite3_step(stmt) == SQLITE_ROW) { char name[512] = { 0 }; const int is_active = sqlite3_column_int(stmt, 2); if(enabled == FALSE || is_active) { dt_history_item_t *item = g_malloc(sizeof(dt_history_item_t)); item->num = sqlite3_column_int(stmt, 0); char *mname = NULL; mname = g_strdup((gchar *)sqlite3_column_text(stmt, 3)); if(enabled) { if(strcmp(mname, "0") == 0) g_snprintf(name, sizeof(name), "%s", dt_iop_get_localized_name((char *)sqlite3_column_text(stmt, 1))); else g_snprintf(name, sizeof(name), "%s %s", dt_iop_get_localized_name((char *)sqlite3_column_text(stmt, 1)), (char *)sqlite3_column_text(stmt, 3)); } else { if(strcmp(mname, "0") == 0) g_snprintf(name, sizeof(name), "%s (%s)", dt_iop_get_localized_name((char *)sqlite3_column_text(stmt, 1)), (is_active != 0) ? _("on") : _("off")); g_snprintf(name, sizeof(name), "%s %s (%s)", dt_iop_get_localized_name((char *)sqlite3_column_text(stmt, 1)), (char *)sqlite3_column_text(stmt, 3), (is_active != 0) ? _("on") : _("off")); } item->name = g_strdup(name); item->op = g_strdup((gchar *)sqlite3_column_text(stmt, 1)); result = g_list_append(result, item); g_free(mname); } } sqlite3_finalize(stmt); return result; }
static void dt_add_hist (int imgid, char *operation, dt_iop_params_t *params, int params_size, char *imported, size_t imported_len, int version, int *import_count) { int32_t num = 0; dt_develop_blend_params_t blend_params; memset(&blend_params, 0, sizeof(dt_develop_blend_params_t)); // get current num if any sqlite3_stmt *stmt; DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db), "select count(num) from history where imgid = ?1", -1, &stmt, NULL); DT_DEBUG_SQLITE3_BIND_INT(stmt, 1, imgid); if(sqlite3_step(stmt) == SQLITE_ROW) { num = sqlite3_column_int(stmt, 0); } sqlite3_finalize(stmt); // add new history info DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db), "insert into history (imgid, num, module, operation, op_params, enabled, blendop_params, blendop_version) values (?1, ?2, ?3, ?4, ?5, 1, ?6, ?7)", -1, &stmt, NULL); DT_DEBUG_SQLITE3_BIND_INT(stmt, 1, imgid); DT_DEBUG_SQLITE3_BIND_INT(stmt, 2, num); DT_DEBUG_SQLITE3_BIND_INT(stmt, 3, version); DT_DEBUG_SQLITE3_BIND_TEXT(stmt, 4, operation, -1, SQLITE_TRANSIENT); DT_DEBUG_SQLITE3_BIND_BLOB(stmt, 5, params, params_size, SQLITE_TRANSIENT); DT_DEBUG_SQLITE3_BIND_BLOB(stmt, 6, &blend_params, sizeof(dt_develop_blend_params_t), SQLITE_TRANSIENT); DT_DEBUG_SQLITE3_BIND_INT(stmt, 7, LRDT_BLEND_VERSION); sqlite3_step (stmt); sqlite3_finalize (stmt); if (imported[0]) g_strlcat(imported, ", ", imported_len); g_strlcat(imported, dt_iop_get_localized_name(operation), imported_len); (*import_count)++; }
char * dt_history_get_items_as_string(int32_t imgid) { GList *items = NULL; const char *onoff[2] = {_("off"), _("on")}; unsigned int count = 0; sqlite3_stmt *stmt; DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db), "select operation, enabled, multi_name from history where imgid=?1 order by num desc", -1, &stmt, NULL); DT_DEBUG_SQLITE3_BIND_INT(stmt, 1, imgid); // collect all the entries in the history from the db while (sqlite3_step(stmt) == SQLITE_ROW) { char *name = NULL, *multi_name = NULL; const char *mn = (char*)sqlite3_column_text(stmt, 2); if(mn && *mn && g_strcmp0(mn, " ") != 0 && g_strcmp0(mn, "0") != 0) multi_name = g_strconcat(" ", sqlite3_column_text(stmt, 2), NULL); name = g_strconcat(dt_iop_get_localized_name((char*)sqlite3_column_text(stmt, 0)), multi_name?multi_name:"", " (", (sqlite3_column_int(stmt, 1)==0)?onoff[0]:onoff[1], ")", NULL); items = g_list_append(items, name); g_free(multi_name); count++; } return dt_util_glist_to_str("\n", items, count); }
char *dt_history_get_items_as_string(int32_t imgid) { GList *items = NULL; const char *onoff[2] = { _("off"), _("on") }; sqlite3_stmt *stmt; DT_DEBUG_SQLITE3_PREPARE_V2( dt_database_get(darktable.db), "SELECT operation, enabled, multi_name FROM main.history WHERE imgid=?1 ORDER BY num DESC", -1, &stmt, NULL); DT_DEBUG_SQLITE3_BIND_INT(stmt, 1, imgid); // collect all the entries in the history from the db while(sqlite3_step(stmt) == SQLITE_ROW) { char *name = NULL, *multi_name = NULL; const char *mn = (char *)sqlite3_column_text(stmt, 2); if(mn && *mn && g_strcmp0(mn, " ") != 0 && g_strcmp0(mn, "0") != 0) multi_name = g_strconcat(" ", sqlite3_column_text(stmt, 2), NULL); name = g_strconcat(dt_iop_get_localized_name((char *)sqlite3_column_text(stmt, 0)), multi_name ? multi_name : "", " (", (sqlite3_column_int(stmt, 1) == 0) ? onoff[0] : onoff[1], ")", NULL); items = g_list_append(items, name); g_free(multi_name); } sqlite3_finalize(stmt); char *result = dt_util_glist_to_str("\n", items); g_list_free_full(items, g_free); return result; }
GList * dt_history_get_items(int32_t imgid, gboolean enabled) { GList *result=NULL; sqlite3_stmt *stmt; DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db), "select num, operation, enabled, multi_name from history where imgid=?1 and num in (select MAX(num) from history hst2 where hst2.imgid=?1 and hst2.operation=history.operation group by multi_priority) order by num desc", -1, &stmt, NULL); DT_DEBUG_SQLITE3_BIND_INT(stmt, 1, imgid); while (sqlite3_step(stmt) == SQLITE_ROW) { char name[512]= {0}; const int is_active = sqlite3_column_int(stmt, 2); if (enabled == FALSE || is_active) { dt_history_item_t *item=g_malloc (sizeof (dt_history_item_t)); item->num = sqlite3_column_int (stmt, 0); char *mname = NULL; mname = g_strdup((gchar *)sqlite3_column_text(stmt, 3)); if (enabled) { if (strcmp(mname,"0") == 0) g_snprintf(name,512,"%s",dt_iop_get_localized_name((char*)sqlite3_column_text(stmt, 1))); else g_snprintf(name,512,"%s %s",dt_iop_get_localized_name((char*)sqlite3_column_text(stmt, 1)),(char*)sqlite3_column_text(stmt, 3)); } else { if (strcmp(mname,"0") == 0) g_snprintf(name,512,"%s (%s)",dt_iop_get_localized_name((char*)sqlite3_column_text(stmt, 1)), (is_active!=0)?_("on"):_("off")); g_snprintf(name,512,"%s %s (%s)",dt_iop_get_localized_name((char*)sqlite3_column_text(stmt, 1)), (char*)sqlite3_column_text(stmt, 3), (is_active!=0)?_("on"):_("off")); } item->name = g_strdup (name); item->op = g_strdup((gchar *)sqlite3_column_text(stmt, 1)); result = g_list_append (result,item); g_free(mname); } } return result; }
GList * dt_styles_get_item_list (const char *name, gboolean params) { GList *result=NULL; sqlite3_stmt *stmt; int id=0; if ((id=dt_styles_get_id_by_name(name)) != 0) { if (params) DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db), "select num, operation, enabled, op_params, blendop_params from style_items where styleid=?1 order by num desc", -1, &stmt, NULL); else DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db), "select num, operation, enabled from style_items where styleid=?1 order by num desc", -1, &stmt, NULL); DT_DEBUG_SQLITE3_BIND_INT(stmt, 1, id); while (sqlite3_step(stmt) == SQLITE_ROW) { char name[512]= {0}; dt_style_item_t *item=g_malloc (sizeof (dt_style_item_t)); item->num = sqlite3_column_int (stmt, 0); if (params) { // when we get the parameters we do not want to get the operation localized as this // is used to compare against the internal module name. g_snprintf(name,512,"%s",sqlite3_column_text (stmt, 1)); const unsigned char *op_blob = sqlite3_column_blob(stmt, 3); const int32_t op_len = sqlite3_column_bytes(stmt, 3); const unsigned char *bop_blob = sqlite3_column_blob(stmt, 4); const int32_t bop_len = sqlite3_column_bytes(stmt, 4); item->params = malloc(op_len); memcpy(item->params, op_blob, op_len); item->blendop_params = malloc(bop_len); memcpy(item->blendop_params, bop_blob, bop_len); } else { g_snprintf(name,512,"%s (%s)",dt_iop_get_localized_name((gchar *)sqlite3_column_text (stmt, 1)),(sqlite3_column_int (stmt, 2)!=0)?_("on"):_("off")); item->params = NULL; item->blendop_params = NULL; } item->name = g_strdup (name); result = g_list_append (result,item); } sqlite3_finalize(stmt); } return result; }
GList * dt_history_get_items(int32_t imgid) { GList *result=NULL; sqlite3_stmt *stmt; DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db), "select num, operation, enabled from history where imgid=?1 order by num desc", -1, &stmt, NULL); DT_DEBUG_SQLITE3_BIND_INT(stmt, 1, imgid); while (sqlite3_step(stmt) == SQLITE_ROW) { char name[512]= {0}; dt_history_item_t *item=g_malloc (sizeof (dt_history_item_t)); item->num = sqlite3_column_int (stmt, 0); g_snprintf(name,512,"%s (%s)",dt_iop_get_localized_name((char*)sqlite3_column_text(stmt, 1)), (sqlite3_column_int(stmt, 2)!=0)?_("on"):_("off")); item->name = g_strdup (name); item->op = g_strdup((gchar *)sqlite3_column_text(stmt, 1)); result = g_list_append (result,item); } return result; }
char * dt_history_get_items_as_string(int32_t imgid) { GList *items = NULL; const char *onoff[2] = {_("off"), _("on")}; unsigned int count = 0; sqlite3_stmt *stmt; DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db), "select operation, enabled from history where imgid=?1 order by num desc", -1, &stmt, NULL); DT_DEBUG_SQLITE3_BIND_INT(stmt, 1, imgid); // collect all the entries in the history from the db while (sqlite3_step(stmt) == SQLITE_ROW) { char name[512]= {0}; g_snprintf(name,512,"%s (%s)", dt_iop_get_localized_name((char*)sqlite3_column_text(stmt, 0)), (sqlite3_column_int(stmt, 1)==0)?onoff[0]:onoff[1]); items = g_list_append(items, g_strdup(name)); count++; } return dt_util_glist_to_str("\n", items, count); }
static void dt_add_hist(int imgid, char *operation, dt_iop_params_t *params, int params_size, char *imported, size_t imported_len, int version, int *import_count) { int32_t num = 0; dt_develop_blend_params_t blend_params = { 0 }; // get current num if any sqlite3_stmt *stmt; DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db), "SELECT count(num) FROM history WHERE imgid = ?1", -1, &stmt, NULL); DT_DEBUG_SQLITE3_BIND_INT(stmt, 1, imgid); if(sqlite3_step(stmt) == SQLITE_ROW) { num = sqlite3_column_int(stmt, 0); } sqlite3_finalize(stmt); // add new history info DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db), "INSERT INTO history (imgid, num, module, operation, op_params, enabled, " "blendop_params, blendop_version, multi_priority, multi_name) " "VALUES (?1, ?2, ?3, ?4, ?5, 1, ?6, ?7, 0, ' ')", -1, &stmt, NULL); DT_DEBUG_SQLITE3_BIND_INT(stmt, 1, imgid); DT_DEBUG_SQLITE3_BIND_INT(stmt, 2, num); DT_DEBUG_SQLITE3_BIND_INT(stmt, 3, version); DT_DEBUG_SQLITE3_BIND_TEXT(stmt, 4, operation, -1, SQLITE_TRANSIENT); DT_DEBUG_SQLITE3_BIND_BLOB(stmt, 5, params, params_size, SQLITE_TRANSIENT); DT_DEBUG_SQLITE3_BIND_BLOB(stmt, 6, &blend_params, sizeof(dt_develop_blend_params_t), SQLITE_TRANSIENT); DT_DEBUG_SQLITE3_BIND_INT(stmt, 7, LRDT_BLEND_VERSION); sqlite3_step(stmt); sqlite3_finalize(stmt); if(imported[0]) g_strlcat(imported, ", ", imported_len); g_strlcat(imported, dt_iop_get_localized_name(operation), imported_len); (*import_count)++; }
GList * dt_styles_get_item_list (const char *name) { GList *result=NULL; sqlite3_stmt *stmt; int id=0; if ((id=dt_styles_get_id_by_name(name)) != 0) { DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db), "select num, operation, enabled from style_items where styleid=?1 order by num desc", -1, &stmt, NULL); DT_DEBUG_SQLITE3_BIND_INT(stmt, 1, id); while (sqlite3_step(stmt) == SQLITE_ROW) { char name[512]= {0}; dt_style_item_t *item=g_malloc (sizeof (dt_style_item_t)); item->num = sqlite3_column_int (stmt, 0); g_snprintf(name,512,"%s (%s)",dt_iop_get_localized_name((gchar *)sqlite3_column_text (stmt, 1)),(sqlite3_column_int (stmt, 2)!=0)?_("on"):_("off")); item->name = g_strdup (name); result = g_list_append (result,item); } sqlite3_finalize(stmt); } return result; }
GList * dt_styles_get_item_list (const char *name, gboolean params, int imgid) { GList *result=NULL; sqlite3_stmt *stmt; int id=0; if ((id=dt_styles_get_id_by_name(name)) != 0) { if (params) DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db), "select num, operation, enabled, op_params, blendop_params, multi_name from style_items where styleid=?1 order by num desc", -1, &stmt, NULL); else if (imgid != -1) { // get all items from the style // UNION // get all items from history, not in the style : select only the last operation, that is max(num) DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db), "select num, operation, enabled, (select max(num) from history where imgid=?2 and operation=style_items.operation group by multi_priority),multi_name from style_items where styleid=?1 UNION select -1,history.operation,history.enabled,history.num,multi_name from history where imgid=?2 and history.enabled=1 and (history.operation not in (select operation from style_items where styleid=?1) or (history.op_params not in (select op_params from style_items where styleid=?1 and operation=history.operation)) or (history.blendop_params not in (select blendop_params from style_items where styleid=?1 and operation=history.operation))) group by operation having max(num) order by num desc", -1, &stmt, NULL); DT_DEBUG_SQLITE3_BIND_INT(stmt, 2, imgid); } else DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db), "select num, operation, enabled, 0, multi_name from style_items where styleid=?1 order by num desc", -1, &stmt, NULL); DT_DEBUG_SQLITE3_BIND_INT(stmt, 1, id); while (sqlite3_step(stmt) == SQLITE_ROW) { char name[512]= {0}; dt_style_item_t *item=g_malloc (sizeof (dt_style_item_t)); if (sqlite3_column_type(stmt,0)==SQLITE_NULL) item->num = -1; else item->num = sqlite3_column_int (stmt, 0); item->selimg_num = -1; item->enabled = sqlite3_column_int(stmt, 2); if (params) { // when we get the parameters we do not want to get the operation localized as this // is used to compare against the internal module name. const char *multi_name = (const char *)sqlite3_column_text (stmt, 5); if (!multi_name || (strlen(multi_name)==0)) g_snprintf(name,512,"%s",sqlite3_column_text (stmt, 1)); else g_snprintf(name,512,"%s %s",sqlite3_column_text (stmt, 1), multi_name); const unsigned char *op_blob = sqlite3_column_blob(stmt, 3); const int32_t op_len = sqlite3_column_bytes(stmt, 3); const unsigned char *bop_blob = sqlite3_column_blob(stmt, 4); const int32_t bop_len = sqlite3_column_bytes(stmt, 4); item->params = malloc(op_len); memcpy(item->params, op_blob, op_len); item->blendop_params = malloc(bop_len); memcpy(item->blendop_params, bop_blob, bop_len); } else { const char *multi_name = (const char *)sqlite3_column_text (stmt, 4); gboolean has_multi_name = FALSE; if (multi_name && strlen(multi_name)>0 && strcmp(multi_name,"0")!=0) has_multi_name = TRUE; if (has_multi_name) g_snprintf(name,512,"%s %s (%s)",dt_iop_get_localized_name((gchar *)sqlite3_column_text (stmt, 1)),multi_name,(sqlite3_column_int (stmt, 2)!=0)?_("on"):_("off")); else g_snprintf(name,512,"%s (%s)",dt_iop_get_localized_name((gchar *)sqlite3_column_text (stmt, 1)),(sqlite3_column_int (stmt, 2)!=0)?_("on"):_("off")); item->params = NULL; item->blendop_params = NULL; if (imgid != -1 && sqlite3_column_type(stmt,3)!=SQLITE_NULL) item->selimg_num = sqlite3_column_int (stmt, 3); } item->name = g_strdup (name); result = g_list_append (result,item); } sqlite3_finalize(stmt); } return result; }
GList *dt_styles_get_item_list(const char *name, gboolean params, int imgid) { GList *result = NULL; sqlite3_stmt *stmt; int id = 0; if((id = dt_styles_get_id_by_name(name)) != 0) { if(params) DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db), "SELECT num, module, operation, enabled, op_params, blendop_params, " "multi_name FROM data.style_items WHERE styleid=?1 ORDER BY num DESC", -1, &stmt, NULL); else if(imgid != -1) { // get all items from the style // UNION // get all items from history, not in the style : select only the last operation, that is max(num) DT_DEBUG_SQLITE3_PREPARE_V2( dt_database_get(darktable.db), "SELECT num, module, operation, enabled, (SELECT MAX(num) FROM main.history WHERE imgid=?2 AND " "operation=data.style_items.operation GROUP BY multi_priority),multi_name FROM data.style_items WHERE " "styleid=?1 UNION SELECT -1,main.history.module,main.history.operation,main.history.enabled, " "main.history.num,multi_name FROM main.history WHERE imgid=?2 AND main.history.enabled=1 AND " "(main.history.operation NOT IN (SELECT operation FROM data.style_items WHERE styleid=?1) OR " "(main.history.op_params NOT IN (SELECT op_params FROM data.style_items WHERE styleid=?1 AND " "operation=main.history.operation)) OR (main.history.blendop_params NOT IN (SELECT blendop_params FROM " "data.style_items WHERE styleid=?1 AND operation=main.history.operation))) GROUP BY operation HAVING " "MAX(num) ORDER BY num DESC", -1, &stmt, NULL); DT_DEBUG_SQLITE3_BIND_INT(stmt, 2, imgid); } else DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db), "SELECT num, module, operation, enabled, 0, " "multi_name FROM data.style_items WHERE " "styleid=?1 ORDER BY num DESC", -1, &stmt, NULL); DT_DEBUG_SQLITE3_BIND_INT(stmt, 1, id); while(sqlite3_step(stmt) == SQLITE_ROW) { // name of current item of style char iname[512] = { 0 }; dt_style_item_t *item = calloc(1, sizeof(dt_style_item_t)); if(sqlite3_column_type(stmt, 0) == SQLITE_NULL) item->num = -1; else item->num = sqlite3_column_int(stmt, 0); item->selimg_num = -1; item->module_version = sqlite3_column_int(stmt, 1); item->enabled = sqlite3_column_int(stmt, 3); if(params) { // when we get the parameters we do not want to get the operation localized as this // is used to compare against the internal module name. const char *multi_name = (const char *)sqlite3_column_text(stmt, 6); if(!(multi_name && *multi_name)) g_snprintf(iname, sizeof(iname), "%s", sqlite3_column_text(stmt, 2)); else g_snprintf(iname, sizeof(iname), "%s %s", sqlite3_column_text(stmt, 2), multi_name); const unsigned char *op_blob = sqlite3_column_blob(stmt, 4); const int32_t op_len = sqlite3_column_bytes(stmt, 4); const unsigned char *bop_blob = sqlite3_column_blob(stmt, 5); const int32_t bop_len = sqlite3_column_bytes(stmt, 5); item->params = malloc(op_len); memcpy(item->params, op_blob, op_len); item->blendop_params = malloc(bop_len); memcpy(item->blendop_params, bop_blob, bop_len); } else { const char *multi_name = (const char *)sqlite3_column_text(stmt, 5); gboolean has_multi_name = FALSE; if(multi_name && *multi_name && strcmp(multi_name, "0") != 0) has_multi_name = TRUE; if(has_multi_name) g_snprintf(iname, sizeof(iname), "%s %s (%s)", dt_iop_get_localized_name((gchar *)sqlite3_column_text(stmt, 2)), multi_name, (sqlite3_column_int(stmt, 3) != 0) ? _("on") : _("off")); else g_snprintf(iname, sizeof(iname), "%s (%s)", dt_iop_get_localized_name((gchar *)sqlite3_column_text(stmt, 2)), (sqlite3_column_int(stmt, 3) != 0) ? _("on") : _("off")); item->params = NULL; item->blendop_params = NULL; if(imgid != -1 && sqlite3_column_type(stmt, 4) != SQLITE_NULL) item->selimg_num = sqlite3_column_int(stmt, 4); } item->name = g_strdup(iname); result = g_list_append(result, item); } sqlite3_finalize(stmt); } return result; }