Deduplicate cr3 image loader
[geeqie.git] / src / rcfile.h
1 /*
2  * Copyright (C) 2004 John Ellis
3  * Copyright (C) 2008 - 2016 The Geeqie Team
4  *
5  * Author: John Ellis
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License along
18  * with this program; if not, write to the Free Software Foundation, Inc.,
19  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20  */
21
22 #ifndef RCFILE_H
23 #define RCFILE_H
24
25 #include <gdk/gdk.h>
26 #include <glib.h>
27
28 struct ConfOptions;
29 struct GQParserData;
30 struct LayoutWindow;
31
32 void write_indent(GString *str, gint indent);
33 void write_char_option(GString *str, gint indent, const gchar *label, const gchar *text);
34 gboolean read_dummy_option(const gchar *option, const gchar *label, const gchar *message);
35 gboolean read_char_option(const gchar *option, const gchar *label, const gchar *value, gchar **text);
36 void write_color_option(GString *str, gint indent, const gchar *label, GdkRGBA *color);
37 gboolean read_color_option(const gchar *option, const gchar *label, const gchar *value, GdkRGBA *color);
38 void write_int_option(GString *str, gint indent, const gchar *label, gint n);
39 gboolean read_int_option(const gchar *option, const gchar *label, const gchar *value, gint *n);
40 gboolean read_ushort_option(const gchar *option, const gchar *label, const gchar *value, guint16 *n);
41 void write_uint_option(GString *str, gint indent, const gchar *label, guint n);
42 gboolean read_uint_option(const gchar *option, const gchar *label, const gchar *value, guint *n);
43 gboolean read_uint_option_clamp(const gchar *option, const gchar *label, const gchar *value, guint *n, guint min, guint max);
44 gboolean read_int_option_clamp(const gchar *option, const gchar *label, const gchar *value, gint *n, gint min, gint max);
45 void write_int_unit_option(GString *str, gint indent, const gchar *label, gint n, gint subunits);
46 gboolean read_int_unit_option(const gchar *option, const gchar *label, const gchar *value, gint *n, gint subunits);
47 void write_bool_option(GString *str, gint indent, const gchar *label, gint n);
48 gboolean read_bool_option(const gchar *option, const gchar *label, const gchar *value, gint *n);
49
50 #define WRITE_BOOL(_source_, _name_) write_bool_option(outstr, indent, #_name_, (_source_)._name_)
51 #define WRITE_INT(_source_, _name_) write_int_option(outstr, indent, #_name_, (_source_)._name_)
52 #define WRITE_UINT(_source_, _name_) write_uint_option(outstr, indent, #_name_, (_source_)._name_)
53 #define WRITE_INT_UNIT(_source_, _name_, _unit_) write_int_unit_option(outstr, indent, #_name_, (_source_)._name_, _unit_)
54 #define WRITE_CHAR(_source_, _name_) write_char_option(outstr, indent, #_name_, (_source_)._name_)
55 #define WRITE_COLOR(_source_, _name_) write_color_option(outstr, indent, #_name_, &(_source_)._name_)
56
57 #define WRITE_NL() write_indent(outstr, indent)
58 #define WRITE_SEPARATOR() g_string_append(outstr, "\n")
59 #define WRITE_STRING(...) g_string_append_printf(outstr, __VA_ARGS__)
60
61 #define READ_BOOL(_target_, _name_) read_bool_option(option, #_name_, value, &(_target_)._name_)
62 #define READ_INT(_target_, _name_) read_int_option(option, #_name_, value, &(_target_)._name_)
63 #define READ_UINT(_target_, _name_) read_uint_option(option, #_name_, value, &(_target_)._name_)
64 #define READ_UINT_ENUM(_target_, _name_) read_uint_option(option, #_name_, value, (guint*)&(_target_)._name_)
65 #define READ_USHORT(_target_, _name_) read_ushort_option(option, #_name_, value, &(_target_)._name_)
66 #define READ_INT_CLAMP(_target_, _name_, _min_, _max_) read_int_option_clamp(option, #_name_, value, &(_target_)._name_, _min_, _max_)
67 #define READ_UINT_CLAMP(_target_, _name_, _min_, _max_) read_uint_option_clamp(option, #_name_, value, &(_target_)._name_, _min_, _max_)
68 #define READ_UINT_ENUM_CLAMP(_target_, _name_, _min_, _max_) read_uint_option_clamp(option, #_name_, value, (guint*)&(_target_)._name_, _min_, _max_)
69 #define READ_INT_UNIT(_target_, _name_, _unit_) read_int_unit_option(option, #_name_, value, &(_target_)._name_, _unit_)
70 #define READ_CHAR(_target_, _name_) read_char_option(option, #_name_, value, &(_target_)._name_)
71 #define READ_COLOR(_target_, _name_) read_color_option(option, #_name_, value, &(_target_)._name_)
72
73 #define READ_BOOL_FULL(_name_, _target_) read_bool_option(option, _name_, value, &(_target_))
74 #define READ_INT_FULL(_name_, _target_) read_int_option(option, _name_, value, &(_target_))
75 #define READ_UINT_FULL(_name_, _target_) read_uint_option(option, _name_, value, &(_target_))
76 #define READ_INT_CLAMP_FULL(_name_, _target_, _min_, _max_) read_int_option_clamp(option, _name_, value, &(_target_), _min_, _max_)
77 #define READ_INT_UNIT_FULL(_name_, _target_, _unit_) read_int_unit_option(option, _name_, value, &(_target_), _unit_)
78 #define READ_CHAR_FULL(_name_, _target_) read_char_option(option, _name_, value, &(_target_))
79 #define READ_COLOR_FULL(_name_, _target_) read_color_option(option, _name_, value, &(_target_))
80
81 #define READ_DUMMY(_target_, _name_, _msg_) read_dummy_option(option, #_name_, _msg_)
82
83 using GQParserStartFunc = void (*)(GQParserData *, GMarkupParseContext *, const gchar *, const gchar **, const gchar **, gpointer, GError **);
84 using GQParserEndFunc = void (*)(GQParserData *, GMarkupParseContext *, const gchar *, gpointer, GError **);
85
86 void options_parse_func_push(GQParserData *parser_data, GQParserStartFunc start_func, GQParserEndFunc end_func, gpointer data);
87 void options_parse_func_pop(GQParserData *parser_data);
88 void options_parse_func_set_data(GQParserData *parser_data, gpointer data);
89
90
91 gboolean save_config_to_file(const gchar *utf8_path, ConfOptions *options, LayoutWindow *lw);
92 gboolean save_default_layout_options_to_file(const gchar *utf8_path, ConfOptions *options, LayoutWindow *lw);
93
94 gboolean load_config_from_buf(const gchar *buf, gsize size, gboolean startup);
95 gboolean load_config_from_file(const gchar *utf8_path, gboolean startup);
96
97 #endif
98 /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */