2 Configure module for the Midnight Commander
4 Copyright (C) 1994, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006,
6 The Free Software Foundation, Inc.
8 This file is part of the Midnight Commander.
10 The Midnight Commander is free software: you can redistribute it
11 and/or modify it under the terms of the GNU General Public License as
12 published by the Free Software Foundation, either version 3 of the License,
13 or (at your option) any later version.
15 The Midnight Commander is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program. If not, see <http://www.gnu.org/licenses/>.
26 #include "lib/global.h"
27 #include "lib/strutil.h"
28 #include "lib/mcconfig.h"
30 /*** global variables **************************************************/
32 /*** file scope macro definitions **************************************/
34 /*** file scope type declarations **************************************/
36 /*** file scope variables **********************************************/
38 /*** file scope functions **********************************************/
40 /*** public functions **************************************************/
43 mc_config_get_groups (const mc_config_t
* mc_config
, gsize
* len
)
49 ret
= g_try_malloc0 (sizeof (gchar
**));
54 ret
= g_key_file_get_groups (mc_config
->handle
, len
);
57 ret
= g_try_malloc0 (sizeof (gchar
**));
62 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
65 mc_config_get_keys (const mc_config_t
* mc_config
, const gchar
* group
, gsize
* len
)
69 if (!mc_config
|| !group
)
71 ret
= g_try_malloc0 (sizeof (gchar
**));
76 ret
= g_key_file_get_keys (mc_config
->handle
, group
, len
, NULL
);
79 ret
= g_try_malloc0 (sizeof (gchar
**));
84 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
87 mc_config_get_string (mc_config_t
* mc_config
, const gchar
* group
,
88 const gchar
* param
, const gchar
* def
)
95 if (!mc_config
|| !group
|| !param
)
96 return g_strdup (def
);
98 if (!mc_config_has_param (mc_config
, group
, param
))
100 mc_config_set_string (mc_config
, group
, param
, def
? def
: "");
101 return g_strdup (def
);
104 ret
= g_key_file_get_string (mc_config
->handle
, group
, param
, NULL
);
106 ret
= g_strdup (def
);
108 if (mc_global
.utf8_display
)
111 conv
= str_crt_conv_from ("UTF-8");
112 if (conv
== INVALID_CONV
)
115 buffer
= g_string_new ("");
116 conv_res
= str_convert (conv
, ret
, buffer
);
117 str_close_conv (conv
);
119 if (conv_res
== ESTR_FAILURE
)
121 g_string_free (buffer
, TRUE
);
127 return g_string_free (buffer
, FALSE
);
130 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
133 mc_config_get_string_raw (const mc_config_t
* mc_config
, const gchar
* group
,
134 const gchar
* param
, const gchar
* def
)
138 if (!mc_config
|| !group
|| !param
)
139 return g_strdup (def
);
141 if (!mc_config_has_param (mc_config
, group
, param
))
144 mc_config_set_string (mc_config
, group
, param
, def
);
145 return g_strdup (def
);
148 ret
= g_key_file_get_string (mc_config
->handle
, group
, param
, NULL
);
150 return ret
!= NULL
? ret
: g_strdup (def
);
153 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
156 mc_config_get_bool (mc_config_t
* mc_config
, const gchar
* group
, const gchar
* param
, gboolean def
)
158 if (!mc_config
|| !group
|| !param
)
161 if (!mc_config_has_param (mc_config
, group
, param
))
163 mc_config_set_bool (mc_config
, group
, param
, def
);
167 return g_key_file_get_boolean (mc_config
->handle
, group
, param
, NULL
);
170 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
173 mc_config_get_int (mc_config_t
* mc_config
, const gchar
* group
, const gchar
* param
, int def
)
175 if (!mc_config
|| !group
|| !param
)
178 if (!mc_config_has_param (mc_config
, group
, param
))
180 mc_config_set_int (mc_config
, group
, param
, def
);
184 return g_key_file_get_integer (mc_config
->handle
, group
, param
, NULL
);
187 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
188 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
191 mc_config_get_string_list (mc_config_t
* mc_config
, const gchar
* group
,
192 const gchar
* param
, gsize
* length
)
194 if (!mc_config
|| !group
|| !param
)
197 return g_key_file_get_string_list (mc_config
->handle
, group
, param
, length
, NULL
);
200 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
203 mc_config_get_bool_list (mc_config_t
* mc_config
, const gchar
* group
,
204 const gchar
* param
, gsize
* length
)
206 if (!mc_config
|| !group
|| !param
)
209 return g_key_file_get_boolean_list (mc_config
->handle
, group
, param
, length
, NULL
);
212 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
215 mc_config_get_int_list (mc_config_t
* mc_config
, const gchar
* group
,
216 const gchar
* param
, gsize
* length
)
218 if (!mc_config
|| !group
|| !param
)
221 return g_key_file_get_integer_list (mc_config
->handle
, group
, param
, length
, NULL
);
224 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */