Ansel 0.0
A darktable fork - bloat + design vision
Loading...
Searching...
No Matches
film_repository.c
Go to the documentation of this file.
1/*
2 This file is part of darktable,
3 Copyright (C) 2009-2011 johannes hanika.
4 Copyright (C) 2010-2011 Henrik Andersson.
5 Copyright (C) 2011-2016 Tobias Ellinghaus.
6 Copyright (C) 2012, 2019-2022 Pascal Obry.
7 Copyright (C) 2025-2026 Aurélien PIERRE.
8
9 darktable is free software: you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation, either version 3 of the License, or
12 (at your option) any later version.
13
14 darktable is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with darktable. If not, see <http://www.gnu.org/licenses/>.
21*/
22
24#include "database/database.h"
25#include "database/sql_debug.h"
26#include "system/macros.h"
27#include "system/mem_alloc.h"
28
29int32_t dt_film_repository_find_by_folder(const char *folder)
30{
31 if(IS_NULL_PTR(folder)) return -1;
32
33 int32_t filmroll_id = -1;
37 "SELECT id FROM main.film_rolls WHERE folder LIKE ?1",
38#else
39 "SELECT id FROM main.film_rolls WHERE folder = ?1",
40#endif
41 -1, &stmt, NULL);
45 return filmroll_id;
46}
47
48char *dt_film_repository_get_folder(const int32_t id)
49{
50 char *folder = NULL;
52 // clang-format off
54 "SELECT id, folder"
55 " FROM main.film_rolls"
56 " WHERE id = ?1", -1, &stmt, NULL);
57 // clang-format on
60 folder = g_strdup((const char *)sqlite3_column_text(stmt, 1));
62 return folder;
63}
64
65gboolean dt_film_repository_insert(const char *folder)
66{
67 if(IS_NULL_PTR(folder)) return FALSE;
68
70 // clang-format off
72 "INSERT INTO main.film_rolls (id, access_timestamp, folder)"
73 " VALUES (NULL, strftime('%s', 'now'), ?1)",
74 -1, &stmt, NULL);
75 // clang-format on
77 const gboolean ok = (sqlite3_step(stmt) == SQLITE_DONE);
79 return ok;
80}
81
82gboolean dt_film_repository_touch_access(const int32_t id)
83{
85 // clang-format off
87 "UPDATE main.film_rolls"
88 " SET access_timestamp = strftime('%s', 'now')"
89 " WHERE id = ?1", -1, &stmt,
90 NULL);
91 // clang-format on
93 const gboolean ok = (sqlite3_step(stmt) == SQLITE_DONE);
95 return ok;
96}
97
98gboolean dt_film_repository_set_folder(const int32_t id, const char *folder)
99{
100 if(IS_NULL_PTR(folder)) return FALSE;
101
104 "UPDATE main.film_rolls SET folder=?1 WHERE id=?2", -1, &stmt, NULL);
107 const gboolean ok = (sqlite3_step(stmt) == SQLITE_DONE);
109 return ok;
110}
111
112gboolean dt_film_repository_delete(const int32_t id)
113{
115 // due to foreign keys, all images with references to the film roll are deleted,
116 // and likewise all entries with references to those images
118 "DELETE FROM main.film_rolls WHERE id = ?1", -1,
119 &stmt, NULL);
121 const gboolean ok = (sqlite3_step(stmt) == SQLITE_DONE);
123 return ok;
124}
125
126gboolean dt_film_repository_has_images(const int32_t id)
127{
128 gboolean has = FALSE;
131 "SELECT id FROM main.images WHERE film_id = ?1", -1,
132 &stmt, NULL);
136 return has;
137}
138
140{
141 GList *result = NULL;
144 "SELECT id FROM main.images WHERE film_id = ?1",
145 -1, &stmt, NULL);
147 while(sqlite3_step(stmt) == SQLITE_ROW)
148 {
149 const int id = sqlite3_column_int(stmt, 0);
150 result = g_list_prepend(result, GINT_TO_POINTER(id));
151 }
153 return g_list_reverse(result); // list was built in reverse order, so un-reverse it
154}
155
157{
158 if(IS_NULL_PTR(cb)) return;
159
162 "SELECT id, folder FROM main.film_rolls",
163 -1, &stmt, NULL);
164 while(sqlite3_step(stmt) == SQLITE_ROW)
165 cb(user_data, sqlite3_column_int(stmt, 0), (const char *)sqlite3_column_text(stmt, 1));
167}
168
170{
171 if(IS_NULL_PTR(cb)) return;
172
175 "SELECT id,folder"
176 " FROM main.film_rolls AS B"
177 " WHERE (SELECT COUNT(*)"
178 " FROM main.images AS A"
179 " WHERE A.film_id=B.id) = 0",
180 -1, &stmt, NULL);
181 while(sqlite3_step(stmt) == SQLITE_ROW)
182 cb(user_data, sqlite3_column_int(stmt, 0), (const char *)sqlite3_column_text(stmt, 1));
184}
185
187 void *user_data)
188{
189 if(IS_NULL_PTR(path) || IS_NULL_PTR(cb)) return;
190
192 gchar *like = g_strdup_printf("%s%%", path);
194 "SELECT id, folder FROM main.film_rolls WHERE folder LIKE ?1", -1, &stmt, NULL);
196 g_free(like);
197
198 while(sqlite3_step(stmt) == SQLITE_ROW)
199 cb(user_data, sqlite3_column_int(stmt, 0), (const char *)sqlite3_column_text(stmt, 1));
201}
202
204{
207 "DELETE FROM memory.film_folder",
208 -1, &stmt, NULL);
211}
212
213void dt_film_repository_folder_status_set(const int32_t id, const gboolean present)
214{
216 // clang-format off
218 "INSERT INTO memory.film_folder (id, status) "
219 "VALUES (?1, ?2)",
220 -1, &stmt, NULL);
221 // clang-format on
226}
227
228// clang-format off
229// modelines: These editor modelines have been set for all relevant files by tools/update_modelines.py
230// vim: shiftwidth=2 expandtab tabstop=2 cindent
231// kate: tab-indents: off; indent-width 2; replace-tabs on; indent-mode cstyle; remove-trailing-spaces modified;
232// clang-format on
#define TRUE
Definition ashift_lsd.c:162
#define FALSE
Definition ashift_lsd.c:158
sqlite3 * dt_database_get_sqlite3_global(void)
Definition database.c:3753
char * dt_film_repository_get_folder(const int32_t id)
gboolean dt_film_repository_insert(const char *folder)
void dt_film_repository_foreach_empty(dt_film_repository_row_cb cb, void *user_data)
gboolean dt_film_repository_has_images(const int32_t id)
void dt_film_repository_foreach_under(const char *path, dt_film_repository_row_cb cb, void *user_data)
int32_t dt_film_repository_find_by_folder(const char *folder)
gboolean dt_film_repository_touch_access(const int32_t id)
void dt_film_repository_foreach(dt_film_repository_row_cb cb, void *user_data)
gboolean dt_film_repository_set_folder(const int32_t id, const char *folder)
gboolean dt_film_repository_delete(const int32_t id)
void dt_film_repository_folder_status_set(const int32_t id, const gboolean present)
GList * dt_film_repository_get_image_ids(const int32_t filmid)
void dt_film_repository_folder_status_clear(void)
void(* dt_film_repository_row_cb)(void *user_data, const int32_t id, const char *folder)
#define IS_NULL_PTR(p)
C is way too permissive with !=, == and if(var) checks, which can mean too many things depending on w...
Definition macros.h:65
Checked wrappers around the sqlite3_* calls: trace the statement, assert the return code,...
#define DT_DEBUG_SQLITE3_PREPARE_V2(a, b, c, d, e)
Definition sql_debug.h:137
#define DT_DEBUG_SQLITE3_BIND_TEXT(a, b, c, d, e)
Definition sql_debug.h:148
#define DT_DEBUG_SQLITE3_BIND_INT(a, b, c)
Definition sql_debug.h:145