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.
22 #include "lib/global.h"
23 #include "lib/strutil.h"
24 #include "lib/mcconfig.h"
26 /*** global variables **************************************************/
28 extern int utf8_display
;
30 /*** file scope macro definitions **************************************/
32 /*** file scope type declarations **************************************/
34 /*** file scope variables **********************************************/
36 /*** file scope functions **********************************************/
37 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
40 mc_config_normalize_before_save(const gchar
* value
)
47 buffer
= g_string_new(value
);
51 conv
= str_crt_conv_to ("UTF-8");
52 if (conv
== INVALID_CONV
)
53 return g_strdup(value
);
55 buffer
= g_string_new ("");
57 if (str_convert (conv
, value
, buffer
) == ESTR_FAILURE
)
59 g_string_free(buffer
, TRUE
);
60 buffer
= g_string_new(value
);
63 str_close_conv (conv
);
66 return g_string_free(buffer
, FALSE
);
69 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
70 /*** public functions **************************************************/
71 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
74 mc_config_direct_set_string (mc_config_t
* mc_config
, const gchar
* group
,
75 const gchar
* param
, const gchar
* value
)
79 if (!mc_config
|| !group
|| !param
|| !value
)
82 buffer
= mc_config_normalize_before_save(value
);
84 g_key_file_set_value (mc_config
->handle
, group
, param
, buffer
);
89 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
92 mc_config_set_string (mc_config_t
* mc_config
, const gchar
* group
,
93 const gchar
* param
, const gchar
* value
)
97 if (!mc_config
|| !group
|| !param
|| !value
)
100 buffer
= mc_config_normalize_before_save(value
);
102 g_key_file_set_string (mc_config
->handle
, group
, param
, buffer
);
107 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
110 mc_config_set_bool (mc_config_t
* mc_config
, const gchar
* group
,
111 const gchar
* param
, gboolean value
)
113 if (!mc_config
|| !group
|| !param
)
116 g_key_file_set_boolean (mc_config
->handle
, group
, param
, value
);
119 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
122 mc_config_set_int (mc_config_t
* mc_config
, const gchar
* group
,
123 const gchar
* param
, int value
)
125 if (!mc_config
|| !group
|| !param
)
128 g_key_file_set_integer (mc_config
->handle
, group
, param
, value
);
131 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
132 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
135 mc_config_set_string_list (mc_config_t
* mc_config
, const gchar
* group
,
136 const gchar
* param
, const gchar
* const value
[],
139 if (!mc_config
|| !group
|| !param
|| !value
|| length
== 0)
142 g_key_file_set_string_list (mc_config
->handle
, group
, param
, value
,
146 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
150 mc_config_set_bool_list (mc_config_t
* mc_config
, const gchar
* group
,
151 const gchar
* param
, gboolean value
[], gsize length
)
153 if (!mc_config
|| !group
|| !param
|| !value
|| length
== 0)
156 g_key_file_set_boolean_list (mc_config
->handle
, group
, param
, value
,
160 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
163 mc_config_set_int_list (mc_config_t
* mc_config
, const gchar
* group
,
164 const gchar
* param
, int value
[], gsize length
)
166 if (!mc_config
|| !group
|| !param
|| !value
|| length
== 0)
169 g_key_file_set_integer_list (mc_config
->handle
, group
, param
, value
,
173 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */