1 /* Configure module for the Midnight Commander
2 Copyright (C) 1994, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006,
3 2007, 2009 Free Software Foundation, Inc.
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
25 #include "../src/strutil.h"
27 /*** global variables **************************************************/
29 extern int utf8_display
;
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
)
48 buffer
= g_string_new(value
);
52 conv
= str_crt_conv_to ("UTF-8");
53 if (conv
== INVALID_CONV
)
54 return g_strdup(value
);
56 buffer
= g_string_new ("");
58 if (str_convert (conv
, value
, buffer
) == ESTR_FAILURE
)
60 g_string_free(buffer
, TRUE
);
61 buffer
= g_string_new(value
);
64 str_close_conv (conv
);
67 return g_string_free(buffer
, FALSE
);
70 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
71 /*** public functions **************************************************/
72 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
75 mc_config_direct_set_string (mc_config_t
* mc_config
, const gchar
* group
,
76 const gchar
* param
, const gchar
* value
)
80 if (!mc_config
|| !group
|| !param
|| !value
)
83 buffer
= mc_config_normalize_before_save(value
);
85 g_key_file_set_value (mc_config
->handle
, group
, param
, buffer
);
90 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
93 mc_config_set_string (mc_config_t
* mc_config
, const gchar
* group
,
94 const gchar
* param
, const gchar
* value
)
98 if (!mc_config
|| !group
|| !param
|| !value
)
101 buffer
= mc_config_normalize_before_save(value
);
103 g_key_file_set_string (mc_config
->handle
, group
, param
, buffer
);
108 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
111 mc_config_set_bool (mc_config_t
* mc_config
, const gchar
* group
,
112 const gchar
* param
, gboolean value
)
114 if (!mc_config
|| !group
|| !param
)
117 g_key_file_set_boolean (mc_config
->handle
, group
, param
, value
);
120 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
123 mc_config_set_int (mc_config_t
* mc_config
, const gchar
* group
,
124 const gchar
* param
, int value
)
126 if (!mc_config
|| !group
|| !param
)
129 g_key_file_set_integer (mc_config
->handle
, group
, param
, value
);
132 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
133 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
136 mc_config_set_string_list (mc_config_t
* mc_config
, const gchar
* group
,
137 const gchar
* param
, const gchar
* const value
[],
140 if (!mc_config
|| !group
|| !param
|| !value
|| length
== 0)
143 g_key_file_set_string_list (mc_config
->handle
, group
, param
, value
,
147 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
151 mc_config_set_bool_list (mc_config_t
* mc_config
, const gchar
* group
,
152 const gchar
* param
, gboolean value
[], gsize length
)
154 if (!mc_config
|| !group
|| !param
|| !value
|| length
== 0)
157 g_key_file_set_boolean_list (mc_config
->handle
, group
, param
, value
,
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
,
174 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */