2 Configure module for the Midnight Commander
4 Copyright (C) 1994-2016
5 Free Software Foundation, Inc.
7 This file is part of the Midnight Commander.
9 The Midnight Commander is free software: you can redistribute it
10 and/or modify it under the terms of the GNU General Public License as
11 published by the Free Software Foundation, either version 3 of the License,
12 or (at your option) any later version.
14 The Midnight Commander 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.
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>.
25 #include "lib/global.h"
26 #include "lib/strutil.h"
27 #include "lib/mcconfig.h"
29 /*** global variables **************************************************/
31 /*** file scope macro definitions **************************************/
33 /*** file scope type declarations **************************************/
35 /*** file scope variables **********************************************/
37 /*** file scope functions **********************************************/
38 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
41 mc_config_normalize_before_save (const gchar
* value
)
47 if (mc_global
.utf8_display
)
48 return g_strdup (value
);
50 conv
= str_crt_conv_to ("UTF-8");
51 if (conv
== INVALID_CONV
)
52 return g_strdup (value
);
54 buffer
= g_string_new ("");
56 ok
= (str_convert (conv
, value
, buffer
) != ESTR_FAILURE
);
57 str_close_conv (conv
);
61 g_string_free (buffer
, TRUE
);
62 return g_strdup (value
);
65 return g_string_free (buffer
, FALSE
);
68 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
69 /*** public functions **************************************************/
70 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
73 mc_config_set_string_raw (mc_config_t
* mc_config
, const gchar
* group
,
74 const gchar
* param
, const gchar
* value
)
76 if (!mc_config
|| !group
|| !param
|| !value
)
79 g_key_file_set_string (mc_config
->handle
, group
, param
, value
);
82 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
85 mc_config_set_string_raw_value (mc_config_t
* mc_config
, const gchar
* group
,
86 const gchar
* param
, const gchar
* value
)
88 if (!mc_config
|| !group
|| !param
|| !value
)
91 g_key_file_set_value (mc_config
->handle
, group
, param
, value
);
94 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
97 mc_config_set_string (const mc_config_t
* mc_config
, const gchar
* group
,
98 const gchar
* param
, const gchar
* value
)
102 if (!mc_config
|| !group
|| !param
|| !value
)
105 buffer
= mc_config_normalize_before_save (value
);
107 g_key_file_set_string (mc_config
->handle
, group
, param
, buffer
);
112 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
115 mc_config_set_bool (mc_config_t
* mc_config
, const gchar
* group
,
116 const gchar
* param
, gboolean value
)
118 if (!mc_config
|| !group
|| !param
)
121 g_key_file_set_boolean (mc_config
->handle
, group
, param
, value
);
124 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
127 mc_config_set_int (mc_config_t
* mc_config
, const gchar
* group
, const gchar
* param
, int value
)
129 if (!mc_config
|| !group
|| !param
)
132 g_key_file_set_integer (mc_config
->handle
, group
, param
, value
);
135 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
136 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
139 mc_config_set_string_list (mc_config_t
* mc_config
, const gchar
* group
,
140 const gchar
* param
, const gchar
* const value
[], gsize length
)
142 if (!mc_config
|| !group
|| !param
|| !value
|| length
== 0)
145 g_key_file_set_string_list (mc_config
->handle
, group
, param
, value
, length
);
148 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
152 mc_config_set_bool_list (mc_config_t
* mc_config
, const gchar
* group
,
153 const gchar
* param
, gboolean value
[], gsize length
)
155 if (!mc_config
|| !group
|| !param
|| !value
|| length
== 0)
158 g_key_file_set_boolean_list (mc_config
->handle
, group
, param
, value
, length
);
161 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
164 mc_config_set_int_list (mc_config_t
* mc_config
, const gchar
* group
,
165 const gchar
* param
, int value
[], gsize length
)
167 if (!mc_config
|| !group
|| !param
|| !value
|| length
== 0)
170 g_key_file_set_integer_list (mc_config
->handle
, group
, param
, value
, length
);
173 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */