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
))
143 mc_config_set_string (mc_config
, group
, param
, def
? def
: "");
144 return g_strdup (def
);
147 ret
= g_key_file_get_string (mc_config
->handle
, group
, param
, NULL
);
149 return ret
!= NULL
? ret
: g_strdup (def
);
152 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
155 mc_config_get_bool (mc_config_t
* mc_config
, const gchar
* group
, const gchar
* param
, gboolean def
)
157 if (!mc_config
|| !group
|| !param
)
160 if (!mc_config_has_param (mc_config
, group
, param
))
162 mc_config_set_bool (mc_config
, group
, param
, def
);
166 return g_key_file_get_boolean (mc_config
->handle
, group
, param
, NULL
);
169 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
172 mc_config_get_int (mc_config_t
* mc_config
, const gchar
* group
, const gchar
* param
, int def
)
174 if (!mc_config
|| !group
|| !param
)
177 if (!mc_config_has_param (mc_config
, group
, param
))
179 mc_config_set_int (mc_config
, group
, param
, def
);
183 return g_key_file_get_integer (mc_config
->handle
, group
, param
, NULL
);
186 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
187 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
190 mc_config_get_string_list (mc_config_t
* mc_config
, const gchar
* group
,
191 const gchar
* param
, gsize
* length
)
193 if (!mc_config
|| !group
|| !param
)
196 return g_key_file_get_string_list (mc_config
->handle
, group
, param
, length
, NULL
);
199 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
202 mc_config_get_bool_list (mc_config_t
* mc_config
, const gchar
* group
,
203 const gchar
* param
, gsize
* length
)
205 if (!mc_config
|| !group
|| !param
)
208 return g_key_file_get_boolean_list (mc_config
->handle
, group
, param
, length
, NULL
);
211 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
214 mc_config_get_int_list (mc_config_t
* mc_config
, const gchar
* group
,
215 const gchar
* param
, gsize
* length
)
217 if (!mc_config
|| !group
|| !param
)
220 return g_key_file_get_integer_list (mc_config
->handle
, group
, param
, length
, NULL
);
223 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */