Ansel 0.0
A darktable fork - bloat + design vision
Loading...
Searching...
No Matches
bauhaus_conf.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
24#include "gui/bauhaus_conf.h"
25
26#include "common/conf.h"
27#include "common/utility.h"
28#include "system/mem_alloc.h"
29
30#include <glib/gi18n.h>
31#include <stdio.h>
32
33static void _combobox_conf_value_changed(GtkWidget *widget, gpointer user_data)
34{
35 const char *value = (const char *)dt_bauhaus_combobox_get_data(widget);
36 if(value) dt_conf_set_string((const char *)user_data, value);
37}
38
40{
42 {
43 fprintf(stderr, "[dt_bauhaus_combobox_from_conf] `%s` is not declared as an <enum> config entry\n", confkey);
44 return NULL;
45 }
46
47 GtkWidget *combo = dt_bauhaus_combobox_new(bh, self);
49
52
53 gchar *current = dt_conf_get_string(confkey);
54 const char *values = dt_confgen_get(confkey, DT_VALUES);
55 GList *options = dt_util_str_to_glist("][", values);
56
57 int pos = 0, active = 0;
59 {
60 char *item = (char *)opt->data;
61 // strip the leading '[' of the first entry and the trailing ']' of the last one
62 if(item[0] == '[') item++;
63 else if(item[strlen(item) - 1] == ']') item[strlen(item) - 1] = '\0';
64
67
68 if(!g_strcmp0(current, item)) active = pos;
69 pos++;
70 }
72 dt_free(current);
73
74 // Select the entry matching the current config value before connecting the signal,
75 // so the initial sync doesn't bounce back through dt_conf_set_string().
76 dt_bauhaus_combobox_set(combo, active);
77
78 g_signal_connect(G_OBJECT(combo), "value-changed", G_CALLBACK(_combobox_conf_value_changed), (gpointer)confkey);
79
80 return combo;
81}
82// clang-format off
83// modelines: These editor modelines have been set for all relevant files by tools/update_modelines.py
84// vim: shiftwidth=2 expandtab tabstop=2 cindent
85// kate: tab-indents: off; indent-width 2; replace-tabs on; indent-mode cstyle; remove-trailing-spaces modified;
86// clang-format on
#define TRUE
Definition ashift_lsd.c:162
void dt_bauhaus_combobox_add_full(GtkWidget *widget, const char *text, dt_bauhaus_combobox_alignment_t align, gpointer data, void(free_func)(void *data), gboolean sensitive)
Definition bauhaus.c:1841
gpointer dt_bauhaus_combobox_get_data(GtkWidget *widget)
Definition bauhaus.c:1982
void dt_bauhaus_combobox_set(GtkWidget *widget, const int pos)
Definition bauhaus.c:2085
void dt_bauhaus_widget_set_label(GtkWidget *widget, const char *label)
Definition bauhaus.c:1504
GtkWidget * dt_bauhaus_combobox_new(dt_bauhaus_t *bh, dt_gui_module_t *self)
Definition bauhaus.c:1693
@ DT_BAUHAUS_COMBOBOX_ALIGN_RIGHT
Definition bauhaus.h:127
GtkWidget * dt_bauhaus_combobox_from_conf(dt_bauhaus_t *bh, dt_gui_module_t *self, const char *confkey)
static void _combobox_conf_value_changed(GtkWidget *widget, gpointer user_data)
struct _GtkWidget GtkWidget
GtkWidget, opaque, spelled exactly as GTK spells it.
Definition colorspaces.h:98
const char * dt_confgen_get_tooltip(const char *name)
gchar * dt_conf_get_string(const char *name)
gboolean dt_confgen_value_exists(const char *name, dt_confgen_value_kind_t kind)
void dt_conf_set_string(const char *name, const char *val)
const char * dt_confgen_get(const char *name, dt_confgen_value_kind_t kind)
dt_confgen_type_t dt_confgen_type(const char *name)
const char * dt_confgen_get_label(const char *name)
@ DT_VALUES
Definition conf.h:100
@ DT_ENUM
Definition conf.h:66
const char * tooltip
Definition image.h:284
static void dt_free_gpointer(gpointer ptr)
Definition mem_alloc.h:104
#define dt_free(ptr)
Definition mem_alloc.h:97
static const dt_aligned_pixel_simd_t value
Definition simd.h:144
The dt_gui_module_t type is the intersection between a dt_lib_module_t and a dt_iop_module_t structur...
GList * dt_util_str_to_glist(const gchar *separator, const gchar *text)
Definition utility.c:832