Ansel 0.0
A darktable fork - bloat + design vision
Loading...
Searching...
No Matches
collection_gui.c
Go to the documentation of this file.
1/*
2 * This file is part of darktable,
3 * Copyright (C) 2016 johannes hanika.
4 * Copyright (C) 2016, 2020 Tobias Ellinghaus.
5 * Copyright (C) 2020 Pascal Obry.
6 * Copyright (C) 2021 Sakari Kapanen.
7 * Copyright (C) 2022 Martin Baƙinka.
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
23
25
26#include "common/collection.h"
27#include "system/macros.h"
28#include "system/mem_alloc.h" // dt_free(), previously arriving through metadata/metadata.h -> gui/gtk.h
29#include "common/conf.h"
30
31#include <stdio.h>
32#include <string.h>
33
34/* Store the n most recent collections in config for re-use in menu */
36{
37 // No GUI-presence test needed: with no GUI this handler is never registered.
38 // Serialize current request
39 char confname[200] = { 0 };
40 char buf[4096];
41 dt_collection_serialize(buf, sizeof(buf));
42
43 int n = -1;
44 gboolean found_duplicate = FALSE;
45
46 // Check if current request already exist in history
47 int num_items = dt_conf_get_int("plugins/lighttable/recentcollect/num_items");
48 for(int k = 0; k < num_items; k++)
49 {
50 snprintf(confname, sizeof(confname), "plugins/lighttable/recentcollect/line%1d", k);
51 const char *line = dt_conf_get_string_const(confname);
52 if(IS_NULL_PTR(line)) continue;
53 if(!strcmp(line, buf))
54 {
55 n = k;
57 break;
58 }
59 }
60
61 // Shift all history items one step behind. When the history is already full,
62 // the last item has no destination slot and must be dropped before moving
63 // the remaining entries down.
64 const int max_items = CLAMP(dt_conf_get_int("plugins/lighttable/recentcollect/max_items"), 1,
67 for(int k = num_items - 1; k > -1; k--)
68 {
69 if(k == n) continue; // this is the duplicate of current collection we found, skip it
70
71 // Get old records
72 snprintf(confname, sizeof(confname), "plugins/lighttable/recentcollect/line%1d", k);
73 gchar *line1 = dt_conf_get_string(confname);
74 snprintf(confname, sizeof(confname), "plugins/lighttable/recentcollect/pos%1d", k);
75 uint32_t pos1 = dt_conf_get_int(confname);
76
77 // Write new records shifted by 1 slot
78 if(IS_NULL_PTR(line1) || line1[0] == '\0')
79 {
81 continue;
82 }
83
85 {
86 snprintf(confname, sizeof(confname), "plugins/lighttable/recentcollect/line%1d", shifted_index);
87 dt_conf_set_string(confname, line1);
88 snprintf(confname, sizeof(confname), "plugins/lighttable/recentcollect/pos%1d", shifted_index);
89 dt_conf_set_int(confname, pos1);
90 }
91 shifted_index -= 1;
93 }
94
95 // Prepend current collection on top of history
96 dt_conf_set_string("plugins/lighttable/recentcollect/line0", buf);
97
98 // Increment items if we didn't find a duplicate
99 num_items += found_duplicate ? 0 : 1;
100 dt_conf_set_int("plugins/lighttable/recentcollect/num_items", CLAMP(num_items, 1, max_items));
101}
102
107
108// clang-format off
109// modelines: These editor modelines have been set for all relevant files by tools/update_modelines.py
110// vim: shiftwidth=2 expandtab tabstop=2 cindent
111// kate: tab-indents: off; indent-width 2; replace-tabs on; indent-mode cstyle; remove-trailing-spaces modified;
112// clang-format on
#define TRUE
Definition ashift_lsd.c:162
#define FALSE
Definition ashift_lsd.c:158
void dt_collection_set_recents_handler(dt_collection_recents_handler_t handler)
Definition collection.c:785
int dt_collection_serialize(char *buf, int bufsize)
Definition collection.c:674
#define NUM_LAST_COLLECTIONS
Definition collection.h:54
static void _update_recentcollections()
void dt_collection_gui_register_handlers(void)
gchar * dt_conf_get_string(const char *name)
void dt_conf_set_int(const char *name, int val)
int dt_conf_get_int(const char *name)
void dt_conf_set_string(const char *name, const char *val)
const char * dt_conf_get_string_const(const char *name)
float *const restrict const size_t k
#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
#define dt_free(ptr)
Definition mem_alloc.h:97
#define MIN(a, b)
Definition thinplate.c:32