Skip to content

Commit 51820a5

Browse files
Merge pull request #19531 from kazuoteramoto/feat/roll_name_n_levels
Allow the use of multiple levels in $(ROLL.NAME[n]) variable
1 parent 8df9feb commit 51820a5

File tree

5 files changed

+18
-5
lines changed

5 files changed

+18
-5
lines changed

RELEASE_NOTES.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,10 @@ changes (where available).
201201
- Fixed out of memory issue which could kill Darktable on small
202202
systems when processing large images.
203203

204+
- Allow the variable `$(ROLL.NAME)` to have optional levels, `$(ROLL.NAME[n])`,
205+
where 1 <= n <= 5, the levels follow the same rules as film roll, the default
206+
value `n=1`, this keep the previous behavior of `$(ROLL.NAME)`.
207+
204208
## Lua
205209

206210
### API Version

src/common/image.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -269,10 +269,9 @@ int dt_image_monochrome_flags(const dt_image_t *img)
269269
| DT_IMAGE_MONOCHROME_BAYER));
270270
}
271271

272-
const char *dt_image_film_roll_name(const char *path)
272+
const char *dt_image_film_roll_name_levels(const char *path, const int levels)
273273
{
274274
const char *folder = path + strlen(path);
275-
const int numparts = CLAMPS(dt_conf_get_int("show_folder_levels"), 1, 5);
276275
int count = 0;
277276
while(folder > path)
278277
{
@@ -284,7 +283,7 @@ const char *dt_image_film_roll_name(const char *path)
284283
if(*folder == G_DIR_SEPARATOR)
285284
#endif
286285

287-
if(++count >= numparts)
286+
if(++count >= levels)
288287
{
289288
++folder;
290289
break;
@@ -294,6 +293,13 @@ const char *dt_image_film_roll_name(const char *path)
294293
return folder;
295294
}
296295

296+
const char *dt_image_film_roll_name(const char *path)
297+
{
298+
const int levels = CLAMPS(dt_conf_get_int("show_folder_levels"), 1, 5);
299+
300+
return dt_image_film_roll_name_levels(path, levels);
301+
}
302+
297303
void dt_image_film_roll_directory(const dt_image_t *img,
298304
char *pathname,
299305
const size_t pathname_len)

src/common/image.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,8 @@ void dt_image_full_path(const dt_imgid_t imgid,
409409
void dt_image_film_roll_directory(const dt_image_t *img,
410410
char *pathname,
411411
const size_t pathname_len);
412+
/** returns the portion of the path used for the film roll name, at given levels */
413+
const char *dt_image_film_roll_name_levels(const char *path, const int levels);
412414
/** returns the portion of the path used for the film roll name. */
413415
const char *dt_image_film_roll_name(const char *path);
414416
/** returns the film roll name, i.e. without the path. */

src/common/variables.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -647,7 +647,8 @@ static char *_get_base_value(dt_variables_params_t *params, char **variable)
647647
if(params->filename)
648648
{
649649
gchar *dirname = g_path_get_dirname(params->filename);
650-
result = g_path_get_basename(dirname);
650+
uint8_t levels = _get_var_parameter(variable, 1);
651+
result = g_strdup(dt_image_film_roll_name_levels(dirname, CLAMPS(levels, 1, 5)));
651652
g_free(dirname);
652653
}
653654
}

src/gui/gtkentry.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ typedef enum
3434

3535

3636
static dt_gtkentry_completion_spec _default_path_compl_list[]
37-
= { { "ROLL.NAME", N_("$(ROLL.NAME) - roll of the input image") },
37+
= { { "ROLL.NAME[]", N_("$(ROLL.NAME[n]) - roll of the input image, n: levels used") },
3838
{ "FILE.FOLDER", N_("$(FILE.FOLDER) - folder containing the input image") },
3939
{ "FILE.NAME", N_("$(FILE.NAME) - basename of the input image") },
4040
{ "FILE.EXTENSION", N_("$(FILE.EXTENSION) - extension of the input image") },

0 commit comments

Comments
 (0)