本文整理汇总了C++中DT_DEBUG_SQLITE3_PREPARE_V2函数的典型用法代码示例。如果您正苦于以下问题:C++ DT_DEBUG_SQLITE3_PREPARE_V2函数的具体用法?C++ DT_DEBUG_SQLITE3_PREPARE_V2怎么用?C++ DT_DEBUG_SQLITE3_PREPARE_V2使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了DT_DEBUG_SQLITE3_PREPARE_V2函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: dt_image_duplicate
int32_t dt_image_duplicate(const int32_t imgid)
{
sqlite3_stmt *stmt;
DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db),
"insert into images "
"(id, group_id, film_id, width, height, filename, maker, model, lens, exposure, "
"aperture, iso, focal_length, focus_distance, datetime_taken, flags, "
"output_width, output_height, crop, raw_parameters, raw_denoise_threshold, "
"raw_auto_bright_threshold, raw_black, raw_maximum, "
"caption, description, license, sha1sum, orientation, histogram, lightmap, "
"longitude, latitude, color_matrix, colorspace) "
"select null, group_id, film_id, width, height, filename, maker, model, lens, "
"exposure, aperture, iso, focal_length, focus_distance, datetime_taken, "
"flags, width, height, crop, raw_parameters, raw_denoise_threshold, "
"raw_auto_bright_threshold, raw_black, raw_maximum, "
"caption, description, license, sha1sum, orientation, histogram, lightmap, "
"longitude, latitude, color_matrix, colorspace "
"from images where id = ?1", -1, &stmt, NULL);
DT_DEBUG_SQLITE3_BIND_INT(stmt, 1, imgid);
sqlite3_step(stmt);
sqlite3_finalize(stmt);
DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db),
"select a.id from images as a join images as b where "
"a.film_id = b.film_id and a.filename = b.filename and "
"b.id = ?1 order by a.id desc", -1, &stmt, NULL);
DT_DEBUG_SQLITE3_BIND_INT(stmt, 1, imgid);
int32_t newid = -1;
if(sqlite3_step(stmt) == SQLITE_ROW)
newid = sqlite3_column_int(stmt, 0);
sqlite3_finalize(stmt);
if(newid != -1)
{
DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db),
"insert into color_labels (imgid, color) select ?1, color from "
"color_labels where imgid = ?2", -1, &stmt, NULL);
DT_DEBUG_SQLITE3_BIND_INT(stmt, 1, newid);
DT_DEBUG_SQLITE3_BIND_INT(stmt, 2, imgid);
sqlite3_step(stmt);
sqlite3_finalize(stmt);
DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db),
"insert into meta_data (id, key, value) select ?1, key, value "
"from meta_data where id = ?2", -1, &stmt, NULL);
DT_DEBUG_SQLITE3_BIND_INT(stmt, 1, newid);
DT_DEBUG_SQLITE3_BIND_INT(stmt, 2, imgid);
sqlite3_step(stmt);
sqlite3_finalize(stmt);
DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db),
"insert into tagged_images (imgid, tagid) select ?1, tagid from "
"tagged_images where imgid = ?2", -1, &stmt, NULL);
DT_DEBUG_SQLITE3_BIND_INT(stmt, 1, newid);
DT_DEBUG_SQLITE3_BIND_INT(stmt, 2, imgid);
sqlite3_step(stmt);
sqlite3_finalize(stmt);
DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db),
"update tagxtag set count = count + 1 where "
"(id1 in (select tagid from tagged_images where imgid = ?1)) or "
"(id2 in (select tagid from tagged_images where imgid = ?1))",
-1, &stmt, NULL);
DT_DEBUG_SQLITE3_BIND_INT(stmt, 1, newid);
sqlite3_step(stmt);
sqlite3_finalize(stmt);
if(darktable.gui && darktable.gui->grouping)
{
const dt_image_t *img = dt_image_cache_read_get(darktable.image_cache, newid);
darktable.gui->expanded_group_id = img->group_id;
dt_image_cache_read_release(darktable.image_cache, img);
dt_collection_update_query(darktable.collection);
}
}
return newid;
}
示例2: _upgrade_schema_step
//.........这里部分代码省略.........
NULL, NULL, NULL) != SQLITE_OK)
{
fprintf(stderr, "[init] can't create detach_tag trigger\n");
fprintf(stderr, "[init] %s\n", sqlite3_errmsg(db->handle));
sqlite3_exec(db->handle, "ROLLBACK TRANSACTION", NULL, NULL, NULL);
return version;
}
sqlite3_exec(db->handle, "COMMIT", NULL, NULL, NULL);
new_version = 4;
}
else if(version == 4)
{
sqlite3_exec(db->handle, "BEGIN TRANSACTION", NULL, NULL, NULL);
if (sqlite3_exec(db->handle,
"ALTER TABLE presets RENAME TO tmp_presets", NULL, NULL, NULL) != SQLITE_OK)
{
fprintf(stderr, "[init] can't rename table presets\n");
fprintf(stderr, "[init] %s\n", sqlite3_errmsg(db->handle));
sqlite3_exec(db->handle, "ROLLBACK TRANSACTION", NULL, NULL, NULL);
return version;
}
if (sqlite3_exec(db->handle,
"CREATE TABLE presets (name VARCHAR, description VARCHAR, operation VARCHAR, op_params BLOB,"
"enabled INTEGER, blendop_params BLOB, model VARCHAR, maker VARCHAR, lens VARCHAR,"
"iso_min REAL, iso_max REAL, exposure_min REAL, exposure_max REAL, aperture_min REAL,"
"aperture_max REAL, focal_length_min REAL, focal_length_max REAL, writeprotect INTEGER,"
"autoapply INTEGER, filter INTEGER, def INTEGER, format INTEGER, op_version INTEGER,"
"blendop_version INTEGER, multi_priority INTEGER, multi_name VARCHAR(256))",
NULL, NULL, NULL) != SQLITE_OK)
{
fprintf(stderr, "[init] can't create new presets table\n");
fprintf(stderr, "[init] %s\n", sqlite3_errmsg(db->handle));
sqlite3_exec(db->handle, "ROLLBACK TRANSACTION", NULL, NULL, NULL);
return version;
}
if (sqlite3_exec(db->handle,
"INSERT INTO presets (name, description, operation, op_params, enabled, blendop_params, model, maker, lens,"
" iso_min, iso_max, exposure_min, exposure_max, aperture_min, aperture_max,"
" focal_length_min, focal_length_max, writeprotect, autoapply, filter, def, format,"
" op_version, blendop_version, multi_priority, multi_name)"
" SELECT name, description, operation, op_params, enabled, blendop_params, model, maker, lens,"
" iso_min, iso_max, exposure_min, exposure_max, aperture_min, aperture_max,"
" focal_length_min, focal_length_max, writeprotect, autoapply, filter, def, isldr,"
" op_version, blendop_version, multi_priority, multi_name"
" FROM tmp_presets",
NULL, NULL, NULL) != SQLITE_OK)
{
fprintf(stderr, "[init] can't populate presets table from tmp_presets\n");
fprintf(stderr, "[init] %s\n", sqlite3_errmsg(db->handle));
sqlite3_exec(db->handle, "ROLLBACK TRANSACTION", NULL, NULL, NULL);
return version;
}
if (sqlite3_exec(db->handle,
"DROP TABLE tmp_presets", NULL, NULL, NULL) != SQLITE_OK)
{
fprintf(stderr, "[init] can't delete table tmp_presets\n");
fprintf(stderr, "[init] %s\n", sqlite3_errmsg(db->handle));
sqlite3_exec(db->handle, "ROLLBACK TRANSACTION", NULL, NULL, NULL);
return version;
}
sqlite3_exec(db->handle, "COMMIT", NULL, NULL, NULL);
new_version = 5;
}
else if(version == 5)
{
sqlite3_exec(db->handle, "BEGIN TRANSACTION", NULL, NULL, NULL);
if(sqlite3_exec(db->handle,
"CREATE INDEX images_filename_index ON images (filename)", NULL, NULL, NULL) != SQLITE_OK)
{
fprintf(stderr, "[init] can't create index on image filename\n");
fprintf(stderr, "[init] %s\n", sqlite3_errmsg(db->handle));
sqlite3_exec(db->handle, "ROLLBACK TRANSACTION", NULL, NULL, NULL);
return version;
}
sqlite3_exec(db->handle, "COMMIT", NULL, NULL, NULL);
new_version = 6;
}// maybe in the future, see commented out code elsewhere
// else if(version == XXX)
// {
// sqlite3_exec(db->handle, "ALTER TABLE film_rolls ADD COLUMN external_drive VARCHAR(1024)", NULL, NULL, NULL);
// }
else
new_version = version; // should be the fallback so that calling code sees that we are in an infinite loop
// write the new version to db
DT_DEBUG_SQLITE3_PREPARE_V2(db->handle, "INSERT OR REPLACE INTO db_info (key, value) VALUES ('version', ?1)", -1, &stmt, NULL);
DT_DEBUG_SQLITE3_BIND_INT(stmt, 1, new_version);
sqlite3_step(stmt);
sqlite3_finalize(stmt);
return new_version;
}
示例3: dt_film_import
int dt_film_import(const char *dirname)
{
int rc;
sqlite3_stmt *stmt;
/* initialize a film object*/
dt_film_t *film = (dt_film_t *)malloc(sizeof(dt_film_t));
dt_film_init(film);
film->id = -1;
/* lookup if film exists and reuse id */
DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db),
"select id from film_rolls where folder = ?1", -1, &stmt, NULL);
DT_DEBUG_SQLITE3_BIND_TEXT(stmt, 1, dirname, strlen(dirname),
SQLITE_STATIC);
if(sqlite3_step(stmt) == SQLITE_ROW)
film->id = sqlite3_column_int(stmt, 0);
sqlite3_finalize(stmt);
/* if we didn't find a id, lets instansiate a new filmroll */
if(film->id <= 0)
{
char datetime[20];
dt_gettime(datetime);
/* insert a new film roll into database */
DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db),
"insert into film_rolls (id, datetime_accessed, folder) values "
"(null, ?1, ?2)", -1, &stmt, NULL);
DT_DEBUG_SQLITE3_BIND_TEXT(stmt, 1, datetime, strlen(datetime),
SQLITE_STATIC);
DT_DEBUG_SQLITE3_BIND_TEXT(stmt, 2, dirname, strlen(dirname),
SQLITE_STATIC);
rc = sqlite3_step(stmt);
if(rc != SQLITE_DONE)
fprintf(stderr, "[film_import] failed to insert film roll! %s\n",
sqlite3_errmsg(dt_database_get(darktable.db)));
sqlite3_finalize(stmt);
/* requery for filmroll and fetch new id */
DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db),
"select id from film_rolls where folder=?1", -1, &stmt, NULL);
DT_DEBUG_SQLITE3_BIND_TEXT(stmt, 1, dirname, strlen(dirname),
SQLITE_STATIC);
if(sqlite3_step(stmt) == SQLITE_ROW)
film->id = sqlite3_column_int(stmt, 0);
sqlite3_finalize(stmt);
}
/* bail out if we got troubles */
if(film->id <= 0)
{
// if the film is empty => remove it again.
if(dt_film_is_empty(film->id))
{
dt_film_remove(film->id);
}
dt_film_cleanup(film);
free(film);
return 0;
}
/* at last put import film job on queue */
dt_job_t j;
film->last_loaded = 0;
g_strlcpy(film->dirname, dirname, sizeof(film->dirname));
film->dir = g_dir_open(film->dirname, 0, NULL);
dt_film_import1_init(&j, film);
dt_control_add_job(darktable.control, &j);
return film->id;
}
示例4: dt_styles_update
void
dt_styles_update (const char *name, const char *newname, const char *newdescription, GList *filter)
{
sqlite3_stmt *stmt;
int id=0;
gchar *desc = NULL;
id = dt_styles_get_id_by_name(name);
if(id == 0) return;
desc = dt_styles_get_description (name);
if ((g_strcmp0(name, newname)) || (g_strcmp0(desc, newdescription)))
{
DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db), "update styles set name=?1, description=?2 where rowid=?3", -1, &stmt, NULL);
DT_DEBUG_SQLITE3_BIND_TEXT(stmt, 1, newname, strlen (newname), SQLITE_STATIC);
DT_DEBUG_SQLITE3_BIND_TEXT(stmt, 2, newdescription, strlen (newdescription), SQLITE_STATIC);
DT_DEBUG_SQLITE3_BIND_INT(stmt, 3, id);
sqlite3_step(stmt);
sqlite3_finalize(stmt);
}
if (filter)
{
GList *list=filter;
char tmp[64];
char include[2048] = {0};
g_strlcat(include,"num not in (", 2048);
do
{
if(list!=g_list_first(list))
g_strlcat(include, ",", 2048);
sprintf(tmp, "%ld", (long int)list->data);
g_strlcat(include, tmp, 2048);
}
while ((list=g_list_next(list)));
g_strlcat(include,")", 2048);
char query[4096]= {0};
sprintf(query,"delete from style_items where styleid=?1 and %s", include);
DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db), query, -1, &stmt, NULL);
DT_DEBUG_SQLITE3_BIND_INT(stmt, 1, id);
sqlite3_step(stmt);
sqlite3_finalize(stmt);
}
/* backup style to disk */
char stylesdir[1024];
dt_loc_get_user_config_dir(stylesdir, 1024);
g_strlcat(stylesdir,"/styles",1024);
g_mkdir_with_parents(stylesdir,00755);
dt_styles_save_to_file(newname,stylesdir,TRUE);
/* delete old accelerator and create a new one */
//TODO: sould better use dt_accel_rename_global() to keep the old accel_key untouched, but it seems to be buggy
if (g_strcmp0(name, newname))
{
char tmp_accel[1024];
snprintf(tmp_accel, 1024, "styles/Apply %s", name);
dt_accel_deregister_global(tmp_accel);
gchar* tmp_name = g_strdup(newname); // freed by _destro_style_shortcut_callback
snprintf(tmp_accel, 1024, "styles/Apply %s", newname);
dt_accel_register_global( tmp_accel, 0, 0);
GClosure *closure;
closure = g_cclosure_new(
G_CALLBACK(_apply_style_shortcut_callback),
tmp_name, _destroy_style_shortcut_callback);
dt_accel_connect_global(tmp_accel, closure);
}
g_free(desc);
}
示例5: dt_styles_apply_to_image
void
dt_styles_apply_to_image(const char *name,gboolean duplicate, int32_t imgid)
{
int id=0;
sqlite3_stmt *stmt;
if ((id=dt_styles_get_id_by_name(name)) != 0)
{
/* check if we should make a duplicate before applying style */
if (duplicate)
imgid = dt_image_duplicate (imgid);
/* if merge onto history stack, lets find history offest in destination image */
int32_t offs = 0;
#if 1
{
/* apply on top of history stack */
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) offs = sqlite3_column_int (stmt, 0);
}
#else
{
/* replace history stack */
DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db), "delete from history where imgid = ?1", -1, &stmt, NULL);
DT_DEBUG_SQLITE3_BIND_INT(stmt, 1, imgid);
sqlite3_step (stmt);
}
#endif
sqlite3_finalize (stmt);
/* copy history items from styles onto image */
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) select ?1, num+?2,module,operation,op_params,enabled,blendop_params,blendop_version,multi_priority,multi_name from style_items where styleid=?3", -1, &stmt, NULL);
DT_DEBUG_SQLITE3_BIND_INT(stmt, 1, imgid);
DT_DEBUG_SQLITE3_BIND_INT(stmt, 2, offs);
DT_DEBUG_SQLITE3_BIND_INT(stmt, 3, id);
sqlite3_step (stmt);
sqlite3_finalize (stmt);
/* add tag */
guint tagid=0;
gchar ntag[512]= {0};
g_snprintf(ntag,512,"darktable|style|%s",name);
if (dt_tag_new(ntag,&tagid))
dt_tag_attach(tagid,imgid);
/* if current image in develop reload history */
if (dt_dev_is_current_image(darktable.develop, imgid))
{
dt_dev_reload_history_items (darktable.develop);
dt_dev_modulegroups_set(darktable.develop, dt_dev_modulegroups_get(darktable.develop));
}
/* update xmp file */
dt_image_synch_xmp(imgid);
/* remove old obsolete thumbnails */
dt_mipmap_cache_remove(darktable.mipmap_cache, imgid);
/* redraw center view to update visible mipmaps */
dt_control_queue_redraw_center();
}
}
示例6: init
void init(dt_view_t *self)
{
self->data = malloc(sizeof(dt_map_t));
memset(self->data,0,sizeof(dt_map_t));
dt_map_t *lib = (dt_map_t *)self->data;
OsmGpsMapSource_t map_source = OSM_GPS_MAP_SOURCE_OPENSTREETMAP;
const gchar *old_map_source = dt_conf_get_string("plugins/map/map_source");
if(old_map_source && old_map_source[0] != '\0')
{
// find the number of the stored map_source
for(int i=0; i<=OSM_GPS_MAP_SOURCE_LAST; i++)
{
const gchar *new_map_source = osm_gps_map_source_get_friendly_name(i);
if(!g_strcmp0(old_map_source, new_map_source))
{
if(osm_gps_map_source_is_valid(i))
map_source = i;
break;
}
}
}
else // open street map should be a nice default ...
dt_conf_set_string("plugins/map/map_source", osm_gps_map_source_get_friendly_name(OSM_GPS_MAP_SOURCE_OPENSTREETMAP));
lib->map = g_object_new (OSM_TYPE_GPS_MAP,
"map-source", map_source,
"proxy-uri",g_getenv("http_proxy"),
NULL);
GtkWidget *parent = gtk_widget_get_parent(dt_ui_center(darktable.gui->ui));
gtk_box_pack_start(GTK_BOX(parent), GTK_WIDGET(lib->map) ,TRUE, TRUE, 0);
lib->osd = g_object_new (OSM_TYPE_GPS_MAP_OSD,
"show-scale",TRUE, "show-coordinates",TRUE, "show-dpad",TRUE, "show-zoom",TRUE, NULL);
if(dt_conf_get_bool("plugins/map/show_map_osd"))
{
osm_gps_map_layer_add(OSM_GPS_MAP(lib->map), lib->osd);
}
/* build the query string */
int max_images_drawn = dt_conf_get_int("plugins/map/max_images_drawn");
if(max_images_drawn == 0)
max_images_drawn = 100;
char *geo_query = g_strdup_printf("select * from (select id from images where \
longitude >= ?1 and longitude <= ?2 and latitude <= ?3 and latitude >= ?4 \
and longitude not NULL and latitude not NULL order by abs(latitude - ?5), abs(longitude - ?6) \
limit 0, %d) order by id", max_images_drawn);
/* prepare the main query statement */
DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db), geo_query, -1, &lib->statements.main_query, NULL);
g_free(geo_query);
/* allow drag&drop of images from filmstrip */
gtk_drag_dest_set(GTK_WIDGET(lib->map), GTK_DEST_DEFAULT_ALL, target_list_internal, n_targets_internal, GDK_ACTION_COPY);
g_signal_connect(GTK_WIDGET(lib->map), "drag-data-received", G_CALLBACK(drag_and_drop_received), self);
g_signal_connect(GTK_WIDGET(lib->map), "changed", G_CALLBACK(_view_map_changed_callback), self);
g_signal_connect(G_OBJECT(lib->map), "button-press-event", G_CALLBACK(_view_map_button_press_callback), self);
g_signal_connect (G_OBJECT(lib->map), "motion-notify-event", G_CALLBACK(_view_map_motion_notify_callback), self);
/* allow drag&drop of images from the map, too */
g_signal_connect(GTK_WIDGET(lib->map), "drag-data-get", G_CALLBACK(_view_map_dnd_get_callback), self);
g_signal_connect(GTK_WIDGET(lib->map), "drag-failed", G_CALLBACK(_view_map_dnd_failed_callback), self);
}
示例7: dt_control_indexer_job_run
int32_t dt_control_indexer_job_run(dt_job_t *job)
{
// if no indexing was requested, bail out:
if(!dt_conf_get_bool("run_similarity_indexer")) return 0;
/*
* First pass run thru ALL images and collect the ones who needs to update
* \TODO in the future lets have a indexer table with ids filed with images
* thats need some kind of reindexing.. all mark dirty functions adds image
* to this table--
*/
// temp memory for uncompressed images:
uint8_t *scratchmem = dt_mipmap_cache_alloc_scratchmem(darktable.mipmap_cache);
GList *images=NULL;
sqlite3_stmt *stmt;
DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db), "select images.id,film_rolls.folder||'/'||images.filename,images.histogram,images.lightmap from images,film_rolls where film_rolls.id = images.film_id", -1, &stmt, NULL);
while(sqlite3_step(stmt) == SQLITE_ROW)
{
_control_indexer_img_t *idximg=g_malloc(sizeof( _control_indexer_img_t));
memset(idximg,0,sizeof(_control_indexer_img_t));
idximg->id = sqlite3_column_int(stmt,0);
/* first check if image file exists on disk */
const char *filename = (const char *)sqlite3_column_text(stmt, 1);
if (filename && !g_file_test(filename, G_FILE_TEST_IS_REGULAR))
idximg->flags |= _INDEXER_IMAGE_FILE_REMOVED;
/* check if histogram should be updated */
if (sqlite3_column_bytes(stmt, 2) != sizeof(dt_similarity_histogram_t))
idximg->flags |= _INDEXER_UPDATE_HISTOGRAM;
/* check if lightmap should be updated */
if (sqlite3_column_bytes(stmt, 3) != sizeof(dt_similarity_lightmap_t))
idximg->flags |= _INDEXER_UPDATE_LIGHTMAP;
/* if image is flagged add to collection */
if (idximg->flags != 0)
images = g_list_append(images, idximg);
else
g_free(idximg);
}
sqlite3_finalize(stmt);
/*
* Second pass, run thru collected images thats
* need reindexing...
*/
GList *imgitem = g_list_first(images);
if(imgitem)
{
char message[512]= {0};
double fraction=0;
int total = g_list_length(images);
guint *jid = NULL;
/* background job plate only if more then one image is reindexed */
if (total > 1)
{
snprintf(message, 512, ngettext ("re-indexing %d image", "re-indexing %d images", total), total );
jid = (guint *)dt_control_backgroundjobs_create(darktable.control, 0, message);
}
do
{
// bail out if we're shutting down:
if(!dt_control_running()) break;
// if indexer was switched off during runtime, respect that as soon as we can:
if(!dt_conf_get_bool("run_similarity_indexer")) break;
/* get the _control_indexer_img_t pointer */
_control_indexer_img_t *idximg = imgitem->data;
/*
* Check if image has been delete from disk
*/
if ((idximg->flags&_INDEXER_IMAGE_FILE_REMOVED))
{
/* file does not exist on disk lets delete image reference from database */
//char query[512]={0};
// \TODO dont delete move to an temp table and let user to revalidate
/*sprintf(query,"delete from history where imgid=%d",idximg->id);
DT_DEBUG_SQLITE3_EXEC(darktable.db, query, NULL, NULL, NULL);
sprintf(query,"delete from tagged_images where imgid=%d",idximg->id);
DT_DEBUG_SQLITE3_EXEC(darktable.db, query, NULL, NULL, NULL);
sprintf(query,"delete from images where id=%d",idximg->id);
DT_DEBUG_SQLITE3_EXEC(darktable.db, query, NULL, NULL, NULL);*/
/* no need to additional work */
continue;
}
/*
//.........这里部分代码省略.........
示例8: edit_preset
static void
edit_preset (const char *name_in, dt_lib_module_info_t *minfo)
{
gchar *name = NULL;
if(name_in == NULL)
{
name = get_active_preset_name(minfo);
if(name == NULL) return;
}
else name = g_strdup(name_in);
GtkWidget *dialog;
/* Create the widgets */
char title[1024];
GtkWidget *window = dt_ui_main_window(darktable.gui->ui);
snprintf(title, 1024, _("edit `%s'"), name);
dialog = gtk_dialog_new_with_buttons (title,
GTK_WINDOW(window),
GTK_DIALOG_DESTROY_WITH_PARENT,
GTK_STOCK_OK, GTK_RESPONSE_ACCEPT,
GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT,
NULL);
GtkContainer *content_area = GTK_CONTAINER(gtk_dialog_get_content_area (GTK_DIALOG (dialog)));
GtkWidget *alignment = gtk_alignment_new(0.5, 0.5, 1.0, 1.0);
gtk_alignment_set_padding(GTK_ALIGNMENT(alignment), 5, 5, 5, 5);
gtk_container_add (content_area, alignment);
GtkBox *box = GTK_BOX(gtk_vbox_new(FALSE, 5));
gtk_container_add (GTK_CONTAINER(alignment), GTK_WIDGET(box));
dt_lib_presets_edit_dialog_t *g = (dt_lib_presets_edit_dialog_t *)g_malloc0(sizeof(dt_lib_presets_edit_dialog_t));
g->old_id = -1;
g_strlcpy(g->plugin_name, minfo->plugin_name, 128);
g->version = minfo->version;
g->params_size = minfo->params_size;
g->params = minfo->params;
g->name = GTK_ENTRY(gtk_entry_new());
g->module = minfo->module;
g->original_name = name;
gtk_entry_set_text(g->name, name);
gtk_box_pack_start(box, GTK_WIDGET(g->name), FALSE, FALSE, 0);
g_object_set(G_OBJECT(g->name), "tooltip-text", _("name of the preset"), (char *)NULL);
g->description = GTK_ENTRY(gtk_entry_new());
gtk_box_pack_start(box, GTK_WIDGET(g->description), FALSE, FALSE, 0);
g_object_set(G_OBJECT(g->description), "tooltip-text", _("description or further information"), (char *)NULL);
sqlite3_stmt *stmt;
DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db), "select rowid, description from presets where name = ?1 and operation = ?2 and op_version = ?3", -1, &stmt, NULL);
DT_DEBUG_SQLITE3_BIND_TEXT(stmt, 1, name, strlen(name), SQLITE_TRANSIENT);
DT_DEBUG_SQLITE3_BIND_TEXT(stmt, 2, minfo->plugin_name, strlen(minfo->plugin_name), SQLITE_TRANSIENT);
DT_DEBUG_SQLITE3_BIND_INT(stmt, 3, minfo->version);
if(sqlite3_step(stmt) == SQLITE_ROW)
{
g->old_id = sqlite3_column_int(stmt, 0);
gtk_entry_set_text(g->description, (const char *)sqlite3_column_text(stmt, 1));
}
sqlite3_finalize(stmt);
g_signal_connect (dialog, "response", G_CALLBACK (edit_preset_response), g);
gtk_widget_show_all (dialog);
}
示例9: dt_lib_presets_popup_menu_show
static void
dt_lib_presets_popup_menu_show(dt_lib_module_info_t *minfo)
{
GtkMenu *menu = darktable.gui->presets_popup_menu;
if(menu)
gtk_widget_destroy(GTK_WIDGET(menu));
darktable.gui->presets_popup_menu = GTK_MENU(gtk_menu_new());
menu = darktable.gui->presets_popup_menu;
GtkWidget *mi;
int active_preset = -1, cnt = 0, writeprotect = 0;
sqlite3_stmt *stmt;
// order: get shipped defaults first
DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db), "select name, op_params, writeprotect, description from presets where operation=?1 and op_version=?2 order by writeprotect desc, rowid", -1, &stmt, NULL);
DT_DEBUG_SQLITE3_BIND_TEXT(stmt, 1, minfo->plugin_name, strlen(minfo->plugin_name), SQLITE_TRANSIENT);
DT_DEBUG_SQLITE3_BIND_INT(stmt, 2, minfo->version);
// collect all presets for op from db
int found = 0;
while(sqlite3_step(stmt) == SQLITE_ROW)
{
void *op_params = (void *)sqlite3_column_blob(stmt, 1);
int32_t op_params_size = sqlite3_column_bytes(stmt, 1);
const char *name = (char *)sqlite3_column_text(stmt, 0);
if (darktable.gui->last_preset
&& strcmp(darktable.gui->last_preset, name)==0)
found = 1;
// selected in bold:
// printf("comparing %d bytes to %d\n", op_params_size, minfo->params_size);
// for(int k=0;k<op_params_size && !memcmp(minfo->params, op_params, k);k++) printf("compare [%c %c] %d: %d\n",
// ((const char*)(minfo->params))[k],
// ((const char*)(op_params))[k],
// k, memcmp(minfo->params, op_params, k));
if(op_params_size == minfo->params_size && !memcmp(minfo->params, op_params, op_params_size))
{
active_preset = cnt;
writeprotect = sqlite3_column_int(stmt, 2);
char *markup;
mi = gtk_menu_item_new_with_label("");
markup = g_markup_printf_escaped ("<span weight=\"bold\">%s</span>", name);
gtk_label_set_markup (GTK_LABEL (gtk_bin_get_child(GTK_BIN(mi))), markup);
g_free (markup);
}
else
{
mi = gtk_menu_item_new_with_label((const char *)name);
}
g_signal_connect(G_OBJECT(mi), "activate", G_CALLBACK(pick_callback), minfo);
g_object_set(G_OBJECT(mi), "tooltip-text", sqlite3_column_text(stmt, 3), (char *)NULL);
gtk_menu_shell_append(GTK_MENU_SHELL(menu), mi);
cnt ++;
}
sqlite3_finalize(stmt);
if(cnt > 0)
gtk_menu_shell_append(GTK_MENU_SHELL(menu), gtk_separator_menu_item_new());
// FIXME: this doesn't seem to work.
if(active_preset >= 0)
{
if(!writeprotect)
{
mi = gtk_menu_item_new_with_label(_("edit this preset.."));
g_signal_connect(G_OBJECT(mi), "activate", G_CALLBACK(menuitem_edit_preset), minfo);
gtk_menu_shell_append(GTK_MENU_SHELL(menu), mi);
mi = gtk_menu_item_new_with_label(_("delete this preset"));
g_signal_connect(G_OBJECT(mi), "activate", G_CALLBACK(menuitem_delete_preset), minfo);
gtk_menu_shell_append(GTK_MENU_SHELL(menu), mi);
}
}
else
{
mi = gtk_menu_item_new_with_label(_("store new preset.."));
g_signal_connect(G_OBJECT(mi), "activate", G_CALLBACK(menuitem_new_preset), minfo);
gtk_menu_shell_append(GTK_MENU_SHELL(menu), mi);
if (darktable.gui->last_preset && found)
{
char label[60];
strcpy (label, _("update preset"));
strcat (label, " <span weight=\"bold\">%s</span>");
char *markup = g_markup_printf_escaped (label, darktable.gui->last_preset);
mi = gtk_menu_item_new_with_label("");
gtk_label_set_markup (GTK_LABEL (gtk_bin_get_child(GTK_BIN(mi))), markup);
g_signal_connect(G_OBJECT(mi), "activate", G_CALLBACK(menuitem_update_preset), minfo);
gtk_menu_shell_append(GTK_MENU_SHELL(menu), mi);
g_free (markup);
}
}
}
示例10: dt_image_cache_allocate
void dt_image_cache_allocate(void *data, dt_cache_entry_t *entry)
{
entry->cost = sizeof(dt_image_t);
dt_image_t *img = (dt_image_t *)g_malloc(sizeof(dt_image_t));
dt_image_init(img);
entry->data = img;
// load stuff from db and store in cache:
char *str;
sqlite3_stmt *stmt;
DT_DEBUG_SQLITE3_PREPARE_V2(
dt_database_get(darktable.db),
"SELECT id, group_id, film_id, width, height, filename, maker, model, lens, exposure, "
"aperture, iso, focal_length, datetime_taken, flags, crop, orientation, focus_distance, "
"raw_parameters, longitude, latitude, color_matrix, colorspace, version, raw_black, raw_maximum FROM "
"images WHERE id = ?1",
-1, &stmt, NULL);
DT_DEBUG_SQLITE3_BIND_INT(stmt, 1, entry->key);
if(sqlite3_step(stmt) == SQLITE_ROW)
{
img->id = sqlite3_column_int(stmt, 0);
img->group_id = sqlite3_column_int(stmt, 1);
img->film_id = sqlite3_column_int(stmt, 2);
img->width = sqlite3_column_int(stmt, 3);
img->height = sqlite3_column_int(stmt, 4);
img->crop_x = img->crop_y = img->crop_width = img->crop_height = 0;
img->filename[0] = img->exif_maker[0] = img->exif_model[0] = img->exif_lens[0]
= img->exif_datetime_taken[0] = '\0';
str = (char *)sqlite3_column_text(stmt, 5);
if(str) g_strlcpy(img->filename, str, sizeof(img->filename));
str = (char *)sqlite3_column_text(stmt, 6);
if(str) g_strlcpy(img->exif_maker, str, sizeof(img->exif_maker));
str = (char *)sqlite3_column_text(stmt, 7);
if(str) g_strlcpy(img->exif_model, str, sizeof(img->exif_model));
str = (char *)sqlite3_column_text(stmt, 8);
if(str) g_strlcpy(img->exif_lens, str, sizeof(img->exif_lens));
img->exif_exposure = sqlite3_column_double(stmt, 9);
img->exif_aperture = sqlite3_column_double(stmt, 10);
img->exif_iso = sqlite3_column_double(stmt, 11);
img->exif_focal_length = sqlite3_column_double(stmt, 12);
str = (char *)sqlite3_column_text(stmt, 13);
if(str) g_strlcpy(img->exif_datetime_taken, str, sizeof(img->exif_datetime_taken));
img->flags = sqlite3_column_int(stmt, 14);
img->exif_crop = sqlite3_column_double(stmt, 15);
img->orientation = sqlite3_column_int(stmt, 16);
img->exif_focus_distance = sqlite3_column_double(stmt, 17);
if(img->exif_focus_distance >= 0 && img->orientation >= 0) img->exif_inited = 1;
uint32_t tmp = sqlite3_column_int(stmt, 18);
memcpy(&img->legacy_flip, &tmp, sizeof(dt_image_raw_parameters_t));
if(sqlite3_column_type(stmt, 19) == SQLITE_FLOAT)
img->longitude = sqlite3_column_double(stmt, 19);
else
img->longitude = NAN;
if(sqlite3_column_type(stmt, 20) == SQLITE_FLOAT)
img->latitude = sqlite3_column_double(stmt, 20);
else
img->latitude = NAN;
const void *color_matrix = sqlite3_column_blob(stmt, 21);
if(color_matrix)
memcpy(img->d65_color_matrix, color_matrix, sizeof(img->d65_color_matrix));
else
img->d65_color_matrix[0] = NAN;
g_free(img->profile);
img->profile = NULL;
img->profile_size = 0;
img->colorspace = sqlite3_column_int(stmt, 22);
img->version = sqlite3_column_int(stmt, 23);
img->raw_black_level = sqlite3_column_int(stmt, 24);
for(uint8_t i = 0; i < 4; i++) img->raw_black_level_separate[i] = 0;
img->raw_white_point = sqlite3_column_int(stmt, 25);
// buffer size?
if(img->flags & DT_IMAGE_LDR)
img->bpp = 4 * sizeof(float);
else if(img->flags & DT_IMAGE_HDR)
{
if(img->flags & DT_IMAGE_RAW)
img->bpp = sizeof(float);
else
img->bpp = 4 * sizeof(float);
}
else // raw
img->bpp = sizeof(uint16_t);
}
else
{
img->id = -1;
fprintf(stderr, "[image_cache_allocate] failed to open image %d from database: %s\n", entry->key,
sqlite3_errmsg(dt_database_get(darktable.db)));
}
sqlite3_finalize(stmt);
img->cache_entry = entry; // init backref
// could downgrade lock write->read on entry->lock if we were using concurrencykit..
}
示例11: edit_preset_response
static void
edit_preset_response(GtkDialog *dialog, gint response_id, dt_lib_presets_edit_dialog_t *g)
{
gint dlg_ret;
gint is_new = 0;
if(response_id == GTK_RESPONSE_ACCEPT)
{
sqlite3_stmt *stmt;
// now delete preset, so we can re-insert the new values:
DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db), "delete from presets where name=?1 and operation=?2 and op_version=?3", -1, &stmt, NULL);
DT_DEBUG_SQLITE3_BIND_TEXT(stmt, 1, g->original_name, -1, SQLITE_TRANSIENT);
DT_DEBUG_SQLITE3_BIND_TEXT(stmt, 2, g->plugin_name, -1, SQLITE_TRANSIENT);
DT_DEBUG_SQLITE3_BIND_INT(stmt, 3, g->version);
sqlite3_step(stmt);
sqlite3_finalize(stmt);
if ( ((g->old_id >= 0) && (strcmp(g->original_name, gtk_entry_get_text(g->name)) != 0)) || (g->old_id < 0) )
{
// editing existing preset with different name or store new preset -> check for a preset with the same name:
DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db), "select name from presets where name = ?1 and operation=?2 and op_version=?3", -1, &stmt, NULL);
DT_DEBUG_SQLITE3_BIND_TEXT(stmt, 1, gtk_entry_get_text(g->name), strlen(gtk_entry_get_text(g->name)), SQLITE_TRANSIENT);
DT_DEBUG_SQLITE3_BIND_TEXT(stmt, 2, g->plugin_name, strlen(g->plugin_name), SQLITE_TRANSIENT);
DT_DEBUG_SQLITE3_BIND_INT(stmt, 3, g->version);
if(sqlite3_step(stmt) == SQLITE_ROW)
{
sqlite3_finalize(stmt);
GtkWidget *window = dt_ui_main_window(darktable.gui->ui);
GtkWidget *dlg_overwrite = gtk_message_dialog_new (GTK_WINDOW(window),
GTK_DIALOG_DESTROY_WITH_PARENT,
GTK_MESSAGE_WARNING,
GTK_BUTTONS_YES_NO,
_("preset `%s' already exists.\ndo you want to overwrite?"),
gtk_entry_get_text(g->name)
);
gtk_window_set_title(GTK_WINDOW (dlg_overwrite), _("overwrite preset?"));
dlg_ret = gtk_dialog_run (GTK_DIALOG (dlg_overwrite));
gtk_widget_destroy (dlg_overwrite);
// if result is BUTTON_NO exit without destroy dialog, to permit other name
if (dlg_ret == GTK_RESPONSE_NO) return;
}
else
{
is_new = 1;
sqlite3_finalize(stmt);
}
}
if (is_new == 0)
{
// delete preset, so we can re-insert the new values:
DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db), "delete from presets where name=?1 and operation=?2 and op_version=?3", -1, &stmt, NULL);
DT_DEBUG_SQLITE3_BIND_TEXT(stmt, 1, gtk_entry_get_text(g->name), strlen(gtk_entry_get_text(g->name)), SQLITE_TRANSIENT);
DT_DEBUG_SQLITE3_BIND_TEXT(stmt, 2, g->plugin_name, strlen(g->plugin_name), SQLITE_TRANSIENT);
DT_DEBUG_SQLITE3_BIND_INT(stmt, 3, g->version);
sqlite3_step(stmt);
sqlite3_finalize(stmt);
}
// commit all the user input fields
char path[1024];
snprintf(path,1024,"preset/%s",g->original_name);
dt_accel_rename_preset_lib(g->module,path,gtk_entry_get_text(g->name));
DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db), "insert into presets (name, description, operation, op_version, op_params, blendop_params, blendop_version, enabled, model, maker, lens, "
"iso_min, iso_max, exposure_min, exposure_max, aperture_min, aperture_max, focal_length_min, focal_length_max, writeprotect, "
"autoapply, filter, def, isldr) values (?1, ?2, ?3, ?4, ?5, null, 0, 1, '%', '%', '%', 0, 51200, 0, 100000000, 0, 100000000, 0, 1000, 0, 0, 0, 0, 0)", -1, &stmt, NULL);
DT_DEBUG_SQLITE3_BIND_TEXT(stmt, 1, gtk_entry_get_text(g->name), strlen(gtk_entry_get_text(g->name)), SQLITE_TRANSIENT);
DT_DEBUG_SQLITE3_BIND_TEXT(stmt, 2, gtk_entry_get_text(g->description), strlen(gtk_entry_get_text(g->description)), SQLITE_TRANSIENT);
DT_DEBUG_SQLITE3_BIND_TEXT(stmt, 3, g->plugin_name, strlen(g->plugin_name), SQLITE_TRANSIENT);
DT_DEBUG_SQLITE3_BIND_INT(stmt, 4, g->version);
DT_DEBUG_SQLITE3_BIND_BLOB(stmt, 5, g->params, g->params_size, SQLITE_TRANSIENT);
sqlite3_step(stmt);
sqlite3_finalize(stmt);
dt_gui_store_last_preset (gtk_entry_get_text(g->name));
}
gtk_widget_destroy(GTK_WIDGET(dialog));
g_free(g->original_name);
free(g);
}
示例12: dt_image_copy
int32_t dt_image_copy(const int32_t imgid, const int32_t filmid)
{
int32_t newid = -1;
sqlite3_stmt *stmt;
gchar srcpath[DT_MAX_PATH_LEN] = {0};
gchar *newdir = NULL;
DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db),
"select folder from film_rolls where id = ?1", -1, &stmt, NULL);
DT_DEBUG_SQLITE3_BIND_INT(stmt, 1, filmid);
if(sqlite3_step(stmt) == SQLITE_ROW)
newdir = g_strdup((gchar *) sqlite3_column_text(stmt, 0));
sqlite3_finalize(stmt);
if(newdir)
{
dt_image_full_path(imgid, srcpath, DT_MAX_PATH_LEN);
gchar *imgbname = g_path_get_basename(srcpath);
gchar *destpath = g_build_filename(newdir, imgbname, NULL);
GFile *src = g_file_new_for_path(srcpath);
GFile *dest = g_file_new_for_path(destpath);
g_free(imgbname);
imgbname = NULL;
g_free(newdir);
newdir = NULL;
g_free(destpath);
destpath = NULL;
// copy image to new folder
// if image file already exists, continue
GError *gerror = NULL;
g_file_copy(src, dest, G_FILE_COPY_NONE, NULL, NULL, NULL, &gerror);
if((gerror == NULL) || (gerror != NULL && gerror->code == G_IO_ERROR_EXISTS))
{
// update database
DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db),
"insert into images "
"(id, group_id, film_id, width, height, filename, maker, model, lens, exposure, "
"aperture, iso, focal_length, focus_distance, datetime_taken, flags, "
"output_width, output_height, crop, raw_parameters, raw_denoise_threshold, "
"raw_auto_bright_threshold, raw_black, raw_maximum, "
"caption, description, license, sha1sum, orientation, histogram, lightmap, "
"longitude, latitude, color_matrix, colorspace) "
"select null, group_id, ?1 as film_id, width, height, filename, maker, model, lens, "
"exposure, aperture, iso, focal_length, focus_distance, datetime_taken, "
"flags, width, height, crop, raw_parameters, raw_denoise_threshold, "
"raw_auto_bright_threshold, raw_black, raw_maximum, "
"caption, description, license, sha1sum, orientation, histogram, lightmap, "
"longitude, latitude, color_matrix, colorspace "
"from images where id = ?2", -1, &stmt, NULL);
DT_DEBUG_SQLITE3_BIND_INT(stmt, 1, filmid);
DT_DEBUG_SQLITE3_BIND_INT(stmt, 2, imgid);
sqlite3_step(stmt);
sqlite3_finalize(stmt);
DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db),
"select a.id from images as a join images as b where "
"a.film_id = ?1 and a.filename = b.filename and "
"b.id = ?2 order by a.id desc", -1, &stmt, NULL);
DT_DEBUG_SQLITE3_BIND_INT(stmt, 1, filmid);
DT_DEBUG_SQLITE3_BIND_INT(stmt, 2, imgid);
if(sqlite3_step(stmt) == SQLITE_ROW)
newid = sqlite3_column_int(stmt, 0);
sqlite3_finalize(stmt);
if(newid != -1)
{
DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db),
"insert into color_labels (imgid, color) select ?1, color from "
"color_labels where imgid = ?2", -1, &stmt, NULL);
DT_DEBUG_SQLITE3_BIND_INT(stmt, 1, newid);
DT_DEBUG_SQLITE3_BIND_INT(stmt, 2, imgid);
sqlite3_step(stmt);
sqlite3_finalize(stmt);
DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db),
"insert into meta_data (id, key, value) select ?1, key, value "
"from meta_data where id = ?2", -1, &stmt, NULL);
DT_DEBUG_SQLITE3_BIND_INT(stmt, 1, newid);
DT_DEBUG_SQLITE3_BIND_INT(stmt, 2, imgid);
sqlite3_step(stmt);
sqlite3_finalize(stmt);
DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db),
"insert into tagged_images (imgid, tagid) select ?1, tagid from "
"tagged_images where imgid = ?2", -1, &stmt, NULL);
DT_DEBUG_SQLITE3_BIND_INT(stmt, 1, newid);
DT_DEBUG_SQLITE3_BIND_INT(stmt, 2, imgid);
sqlite3_step(stmt);
sqlite3_finalize(stmt);
DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db),
"update tagxtag set count = count + 1 where "
"(id1 in (select tagid from tagged_images where imgid = ?1)) or "
"(id2 in (select tagid from tagged_images where imgid = ?1))",
-1, &stmt, NULL);
DT_DEBUG_SQLITE3_BIND_INT(stmt, 1, newid);
sqlite3_step(stmt);
sqlite3_finalize(stmt);
// write xmp file
dt_image_write_sidecar_file(newid);
//.........这里部分代码省略.........
示例13: dt_image_move
int32_t dt_image_move(const int32_t imgid, const int32_t filmid)
{
//TODO: several places where string truncation could occur unnoticed
int32_t result = -1;
gchar oldimg[DT_MAX_PATH_LEN] = {0};
gchar newimg[DT_MAX_PATH_LEN] = {0};
dt_image_full_path(imgid, oldimg, DT_MAX_PATH_LEN);
gchar *newdir = NULL;
sqlite3_stmt *film_stmt;
DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db),
"select folder from film_rolls where id = ?1", -1, &film_stmt, NULL);
DT_DEBUG_SQLITE3_BIND_INT(film_stmt, 1, filmid);
if(sqlite3_step(film_stmt) == SQLITE_ROW)
newdir = g_strdup((gchar *) sqlite3_column_text(film_stmt, 0));
sqlite3_finalize(film_stmt);
if(newdir)
{
gchar *imgbname = g_path_get_basename(oldimg);
g_snprintf(newimg, DT_MAX_PATH_LEN, "%s%c%s", newdir, G_DIR_SEPARATOR, imgbname);
g_free(imgbname);
g_free(newdir);
// statement for getting ids of the image to be moved and it's duplicates
sqlite3_stmt *duplicates_stmt;
DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db),
"select id from images where filename in (select filename from images "
"where id = ?1) and film_id in (select film_id from images where id = ?1)",
-1, &duplicates_stmt, NULL);
// move image
// TODO: Use gio's' g_file_move instead of g_rename?
if (!g_file_test(newimg, G_FILE_TEST_EXISTS)
&& (g_rename(oldimg, newimg) == 0))
{
// first move xmp files of image and duplicates
GList *dup_list = NULL;
DT_DEBUG_SQLITE3_BIND_INT(duplicates_stmt, 1, imgid);
while (sqlite3_step(duplicates_stmt) == SQLITE_ROW)
{
int32_t id = sqlite3_column_int(duplicates_stmt, 0);
dup_list = g_list_append(dup_list, GINT_TO_POINTER(id));
gchar oldxmp[512], newxmp[512];
g_strlcpy(oldxmp, oldimg, 512);
g_strlcpy(newxmp, newimg, 512);
dt_image_path_append_version(id, oldxmp, 512);
dt_image_path_append_version(id, newxmp, 512);
g_strlcat(oldxmp, ".xmp", 512);
g_strlcat(newxmp, ".xmp", 512);
if (g_file_test(oldxmp, G_FILE_TEST_EXISTS))
(void)g_rename(oldxmp, newxmp);
}
sqlite3_reset(duplicates_stmt);
sqlite3_clear_bindings(duplicates_stmt);
// then update database and cache
// if update was performed in above loop, dt_image_path_append_version()
// would return wrong version!
while (dup_list)
{
long int id = GPOINTER_TO_INT(dup_list->data);
const dt_image_t *cimg = dt_image_cache_read_get(darktable.image_cache, id);
dt_image_t *img = dt_image_cache_write_get(darktable.image_cache, cimg);
img->film_id = filmid;
// write through to db, but not to xmp
dt_image_cache_write_release(darktable.image_cache, img, DT_IMAGE_CACHE_RELAXED);
dt_image_cache_read_release(darktable.image_cache, img);
dup_list = g_list_delete_link(dup_list, dup_list);
}
g_list_free(dup_list);
result = 0;
}
}
return result;
}
示例14: dt_image_import
uint32_t dt_image_import(const int32_t film_id, const char *filename, gboolean override_ignore_jpegs)
{
if(!g_file_test(filename, G_FILE_TEST_IS_REGULAR))
return 0;
const char *cc = filename + strlen(filename);
for(; *cc!='.'&&cc>filename; cc--);
if(!strcmp(cc, ".dt")) return 0;
if(!strcmp(cc, ".dttags")) return 0;
if(!strcmp(cc, ".xmp")) return 0;
char *ext = g_ascii_strdown(cc+1, -1);
if(override_ignore_jpegs == FALSE && (!strcmp(ext, "jpg") ||
!strcmp(ext, "jpeg")) && dt_conf_get_bool("ui_last/import_ignore_jpegs"))
return 0;
int supported = 0;
char **extensions = g_strsplit(dt_supported_extensions, ",", 100);
for(char **i=extensions; *i!=NULL; i++)
if(!strcmp(ext, *i))
{
supported = 1;
break;
}
g_strfreev(extensions);
if(!supported)
{
g_free(ext);
return 0;
}
int rc;
uint32_t id = 0;
// select from images; if found => return
gchar *imgfname;
imgfname = g_path_get_basename((const gchar*)filename);
sqlite3_stmt *stmt;
DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db),
"select id from images where film_id = ?1 and filename = ?2",
-1, &stmt, NULL);
DT_DEBUG_SQLITE3_BIND_INT(stmt, 1, film_id);
DT_DEBUG_SQLITE3_BIND_TEXT(stmt, 2, imgfname, strlen(imgfname), SQLITE_STATIC);
if(sqlite3_step(stmt) == SQLITE_ROW)
{
id = sqlite3_column_int(stmt, 0);
g_free(imgfname);
sqlite3_finalize(stmt);
g_free(ext);
const dt_image_t *cimg = dt_image_cache_read_get(darktable.image_cache, id);
dt_image_t *img = dt_image_cache_write_get(darktable.image_cache, cimg);
img->flags &= ~DT_IMAGE_REMOVE;
dt_image_cache_write_release(darktable.image_cache, img, DT_IMAGE_CACHE_RELAXED);
dt_image_cache_read_release(darktable.image_cache, img);
return id;
}
sqlite3_finalize(stmt);
// also need to set the no-legacy bit, to make sure we get the right presets (new ones)
uint32_t flags = dt_conf_get_int("ui_last/import_initial_rating");
if(flags > 5)
{
flags = 1;
dt_conf_set_int("ui_last/import_initial_rating", 1);
}
flags |= DT_IMAGE_NO_LEGACY_PRESETS;
// insert dummy image entry in database
DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db),
"insert into images (id, film_id, filename, caption, description, "
"license, sha1sum, flags) values (null, ?1, ?2, '', '', '', '', ?3)",
-1, &stmt, NULL);
DT_DEBUG_SQLITE3_BIND_INT(stmt, 1, film_id);
DT_DEBUG_SQLITE3_BIND_TEXT(stmt, 2, imgfname, strlen(imgfname),
SQLITE_TRANSIENT);
DT_DEBUG_SQLITE3_BIND_INT(stmt, 3, flags);
rc = sqlite3_step(stmt);
if (rc != SQLITE_DONE) fprintf(stderr, "sqlite3 error %d\n", rc);
sqlite3_finalize(stmt);
DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db),
"select id from images where film_id = ?1 and filename = ?2",
-1, &stmt, NULL);
DT_DEBUG_SQLITE3_BIND_INT(stmt, 1, film_id);
DT_DEBUG_SQLITE3_BIND_TEXT(stmt, 2, imgfname, strlen(imgfname),
SQLITE_STATIC);
if(sqlite3_step(stmt) == SQLITE_ROW) id = sqlite3_column_int(stmt, 0);
sqlite3_finalize(stmt);
// Try to find out if this should be grouped already.
gchar *basename = g_strdup(imgfname);
gchar *cc2 = basename + strlen(basename);
for(; *cc2!='.'&&cc2>basename; cc2--);
*cc2='\0';
gchar *sql_pattern = g_strconcat(basename, ".%", NULL);
DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db), "select group_id from images where film_id = ?1 and filename like ?2 and id != ?3", -1, &stmt, NULL);
DT_DEBUG_SQLITE3_BIND_INT(stmt, 1, film_id);
DT_DEBUG_SQLITE3_BIND_TEXT(stmt, 2, sql_pattern, -1, SQLITE_TRANSIENT);
DT_DEBUG_SQLITE3_BIND_INT(stmt, 3, id);
int group_id;
if(sqlite3_step(stmt) == SQLITE_ROW) group_id = sqlite3_column_int(stmt, 0);
else group_id = id;
sqlite3_finalize(stmt);
DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db), "update images set group_id = ?1 where id = ?2", -1, &stmt, NULL);
DT_DEBUG_SQLITE3_BIND_INT(stmt, 1, group_id);
DT_DEBUG_SQLITE3_BIND_INT(stmt, 2, id);
//.........这里部分代码省略.........
示例15: dt_collection_update_query
void
dt_collection_update_query(const dt_collection_t *collection)
{
char query[1024], confname[200];
gchar *complete_query = NULL;
const int _n_r = dt_conf_get_int("plugins/lighttable/collect/num_rules");
const int num_rules = CLAMP(_n_r, 1, 10);
char *conj[] = {"and", "or", "and not"};
complete_query = dt_util_dstrcat(complete_query, "(");
for(int i=0; i<num_rules; i++)
{
snprintf(confname, 200, "plugins/lighttable/collect/item%1d", i);
const int property = dt_conf_get_int(confname);
snprintf(confname, 200, "plugins/lighttable/collect/string%1d", i);
gchar *text = dt_conf_get_string(confname);
if(!text) break;
snprintf(confname, 200, "plugins/lighttable/collect/mode%1d", i);
const int mode = dt_conf_get_int(confname);
gchar *escaped_text = dt_util_str_replace(text, "'", "''");
get_query_string(property, escaped_text, query);
if(i > 0)
complete_query = dt_util_dstrcat(complete_query, " %s %s", conj[mode], query);
else
complete_query = dt_util_dstrcat(complete_query, "%s", query);
g_free(escaped_text);
g_free(text);
}
complete_query = dt_util_dstrcat(complete_query, ")");
// printf("complete query: `%s'\n", complete_query);
/* set the extended where and the use of it in the query */
dt_collection_set_extended_where (collection, complete_query);
dt_collection_set_query_flags (collection, (dt_collection_get_query_flags (collection) | COLLECTION_QUERY_USE_WHERE_EXT));
/* remove film id from default filter */
dt_collection_set_filter_flags (collection, (dt_collection_get_filter_flags (collection) & ~COLLECTION_FILTER_FILM_ID));
/* update query and at last the visual */
dt_collection_update (collection);
/* free string */
g_free(complete_query);
// remove from selected images where not in this query.
sqlite3_stmt *stmt = NULL;
const gchar *cquery = dt_collection_get_query(collection);
complete_query = NULL;
if(cquery && cquery[0] != '\0')
{
complete_query = dt_util_dstrcat(complete_query, "delete from selected_images where imgid not in (%s)", cquery);
DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db), complete_query, -1, &stmt, NULL);
DT_DEBUG_SQLITE3_BIND_INT(stmt, 1, 0);
DT_DEBUG_SQLITE3_BIND_INT(stmt, 2, -1);
sqlite3_step(stmt);
sqlite3_finalize(stmt);
/* free allocated strings */
g_free(complete_query);
}
/* raise signal of collection change, only if this is an original */
if (!collection->clone)
dt_control_signal_raise(darktable.signals, DT_SIGNAL_COLLECTION_CHANGED);
}