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 /*** file scope macro definitions **************************************/
30 /*** file scope type declarations **************************************/
32 /*** file scope variables **********************************************/
34 /*** file scope functions **********************************************/
35 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
38 mc_config_normalize_before_save (const gchar
* value
)
43 if (mc_global
.utf8_display
)
44 return g_strdup (value
);
46 conv
= str_crt_conv_to ("UTF-8");
47 if (conv
== INVALID_CONV
)
48 return g_strdup (value
);
50 buffer
= g_string_new ("");
52 if (str_convert (conv
, value
, buffer
) == ESTR_FAILURE
)
54 g_string_free (buffer
, TRUE
);
55 return g_strdup (value
);
58 str_close_conv (conv
);
59 return g_string_free (buffer
, FALSE
);
62 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
63 /*** public functions **************************************************/
64 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
67 mc_config_set_string_raw (mc_config_t
* mc_config
, const gchar
* group
,
68 const gchar
* param
, const gchar
* value
)
70 if (!mc_config
|| !group
|| !param
|| !value
)
73 g_key_file_set_string (mc_config
->handle
, group
, param
, value
);
76 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
79 mc_config_set_string (const mc_config_t
* mc_config
, const gchar
* group
,
80 const gchar
* param
, const gchar
* value
)
84 if (!mc_config
|| !group
|| !param
|| !value
)
87 buffer
= mc_config_normalize_before_save (value
);
89 g_key_file_set_string (mc_config
->handle
, group
, param
, buffer
);
94 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
97 mc_config_set_bool (mc_config_t
* mc_config
, const gchar
* group
,
98 const gchar
* param
, gboolean value
)
100 if (!mc_config
|| !group
|| !param
)
103 g_key_file_set_boolean (mc_config
->handle
, group
, param
, value
);
106 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
109 mc_config_set_int (mc_config_t
* mc_config
, const gchar
* group
, const gchar
* param
, int value
)
111 if (!mc_config
|| !group
|| !param
)
114 g_key_file_set_integer (mc_config
->handle
, group
, param
, value
);
117 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
118 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
121 mc_config_set_string_list (mc_config_t
* mc_config
, const gchar
* group
,
122 const gchar
* param
, const gchar
* const value
[], gsize length
)
124 if (!mc_config
|| !group
|| !param
|| !value
|| length
== 0)
127 g_key_file_set_string_list (mc_config
->handle
, group
, param
, value
, length
);
130 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
134 mc_config_set_bool_list (mc_config_t
* mc_config
, const gchar
* group
,
135 const gchar
* param
, gboolean value
[], gsize length
)
137 if (!mc_config
|| !group
|| !param
|| !value
|| length
== 0)
140 g_key_file_set_boolean_list (mc_config
->handle
, group
, param
, value
, length
);
143 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
146 mc_config_set_int_list (mc_config_t
* mc_config
, const gchar
* group
,
147 const gchar
* param
, int value
[], gsize length
)
149 if (!mc_config
|| !group
|| !param
|| !value
|| length
== 0)
152 g_key_file_set_integer_list (mc_config
->handle
, group
, param
, value
, length
);
155 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */