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
))
101 mc_config_set_string (mc_config
, group
, param
, def
);
102 return g_strdup (def
);
105 ret
= g_key_file_get_string (mc_config
->handle
, group
, param
, NULL
);
107 ret
= g_strdup (def
);
109 if (mc_global
.utf8_display
)
112 conv
= str_crt_conv_from ("UTF-8");
113 if (conv
== INVALID_CONV
)
116 buffer
= g_string_new ("");
117 conv_res
= str_convert (conv
, ret
, buffer
);
118 str_close_conv (conv
);
120 if (conv_res
== ESTR_FAILURE
)
122 g_string_free (buffer
, TRUE
);
128 return g_string_free (buffer
, FALSE
);
131 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
134 mc_config_get_string_raw (const mc_config_t
* mc_config
, const gchar
* group
,
135 const gchar
* param
, const gchar
* def
)
139 if (!mc_config
|| !group
|| !param
)
140 return g_strdup (def
);
142 if (!mc_config_has_param (mc_config
, group
, param
))
145 mc_config_set_string (mc_config
, group
, param
, def
);
146 return g_strdup (def
);
149 ret
= g_key_file_get_string (mc_config
->handle
, group
, param
, NULL
);
151 return ret
!= NULL
? ret
: g_strdup (def
);
154 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
157 mc_config_get_bool (mc_config_t
* mc_config
, const gchar
* group
, const gchar
* param
, gboolean def
)
159 if (!mc_config
|| !group
|| !param
)
162 if (!mc_config_has_param (mc_config
, group
, param
))
164 mc_config_set_bool (mc_config
, group
, param
, def
);
168 return g_key_file_get_boolean (mc_config
->handle
, group
, param
, NULL
);
171 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
174 mc_config_get_int (mc_config_t
* mc_config
, const gchar
* group
, const gchar
* param
, int def
)
176 if (!mc_config
|| !group
|| !param
)
179 if (!mc_config_has_param (mc_config
, group
, param
))
181 mc_config_set_int (mc_config
, group
, param
, def
);
185 return g_key_file_get_integer (mc_config
->handle
, group
, param
, NULL
);
188 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
189 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
192 mc_config_get_string_list (mc_config_t
* mc_config
, const gchar
* group
,
193 const gchar
* param
, gsize
* length
)
195 if (!mc_config
|| !group
|| !param
)
198 return g_key_file_get_string_list (mc_config
->handle
, group
, param
, length
, NULL
);
201 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
204 mc_config_get_bool_list (mc_config_t
* mc_config
, const gchar
* group
,
205 const gchar
* param
, gsize
* length
)
207 if (!mc_config
|| !group
|| !param
)
210 return g_key_file_get_boolean_list (mc_config
->handle
, group
, param
, length
, NULL
);
213 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
216 mc_config_get_int_list (mc_config_t
* mc_config
, const gchar
* group
,
217 const gchar
* param
, gsize
* length
)
219 if (!mc_config
|| !group
|| !param
)
222 return g_key_file_get_integer_list (mc_config
->handle
, group
, param
, length
, NULL
);
225 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */