2 Configure module for the Midnight Commander
4 Copyright (C) 1994-2016
5 Free Software Foundation, Inc.
7 This file is part of the Midnight Commander.
9 The Midnight Commander is free software: you can redistribute it
10 and/or modify it under the terms of the GNU General Public License as
11 published by the Free Software Foundation, either version 3 of the License,
12 or (at your option) any later version.
14 The Midnight Commander is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>.
25 #include "lib/global.h"
26 #include "lib/strutil.h"
27 #include "lib/mcconfig.h"
29 /*** global variables **************************************************/
31 /*** file scope macro definitions **************************************/
33 /*** file scope type declarations **************************************/
35 /*** file scope variables **********************************************/
37 /*** file scope functions **********************************************/
39 /*** public functions **************************************************/
42 mc_config_get_groups (const mc_config_t
* mc_config
, gsize
* len
)
46 if (mc_config
!= NULL
)
47 ret
= g_key_file_get_groups (mc_config
->handle
, len
);
51 ret
= g_try_malloc0 (sizeof (gchar
**));
59 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
62 mc_config_get_keys (const mc_config_t
* mc_config
, const gchar
* group
, gsize
* len
)
66 if (mc_config
!= NULL
&& group
!= NULL
)
67 ret
= g_key_file_get_keys (mc_config
->handle
, group
, len
, NULL
);
71 ret
= g_try_malloc0 (sizeof (gchar
**));
79 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
82 mc_config_get_string (mc_config_t
* mc_config
, const gchar
* group
,
83 const gchar
* param
, const gchar
* def
)
90 if (!mc_config
|| !group
|| !param
)
91 return g_strdup (def
);
93 if (!mc_config_has_param (mc_config
, group
, param
))
96 mc_config_set_string (mc_config
, group
, param
, def
);
97 return g_strdup (def
);
100 ret
= g_key_file_get_string (mc_config
->handle
, group
, param
, NULL
);
102 ret
= g_strdup (def
);
104 if (mc_global
.utf8_display
)
107 conv
= str_crt_conv_from ("UTF-8");
108 if (conv
== INVALID_CONV
)
111 buffer
= g_string_new ("");
112 conv_res
= str_convert (conv
, ret
, buffer
);
113 str_close_conv (conv
);
115 if (conv_res
== ESTR_FAILURE
)
117 g_string_free (buffer
, TRUE
);
123 return g_string_free (buffer
, FALSE
);
126 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
129 mc_config_get_string_raw (const mc_config_t
* mc_config
, const gchar
* group
,
130 const gchar
* param
, const gchar
* def
)
134 if (!mc_config
|| !group
|| !param
)
135 return g_strdup (def
);
137 if (!mc_config_has_param (mc_config
, group
, param
))
140 mc_config_set_string (mc_config
, group
, param
, def
);
141 return g_strdup (def
);
144 ret
= g_key_file_get_string (mc_config
->handle
, group
, param
, NULL
);
146 return ret
!= NULL
? ret
: g_strdup (def
);
149 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
152 mc_config_get_bool (mc_config_t
* mc_config
, const gchar
* group
, const gchar
* param
, gboolean def
)
154 if (!mc_config
|| !group
|| !param
)
157 if (!mc_config_has_param (mc_config
, group
, param
))
159 mc_config_set_bool (mc_config
, group
, param
, def
);
163 return g_key_file_get_boolean (mc_config
->handle
, group
, param
, NULL
);
166 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
169 mc_config_get_int (mc_config_t
* mc_config
, const gchar
* group
, const gchar
* param
, int def
)
171 if (!mc_config
|| !group
|| !param
)
174 if (!mc_config_has_param (mc_config
, group
, param
))
176 mc_config_set_int (mc_config
, group
, param
, def
);
180 return g_key_file_get_integer (mc_config
->handle
, group
, param
, NULL
);
183 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
184 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
187 mc_config_get_string_list (mc_config_t
* mc_config
, const gchar
* group
,
188 const gchar
* param
, gsize
* length
)
190 if (!mc_config
|| !group
|| !param
)
193 return g_key_file_get_string_list (mc_config
->handle
, group
, param
, length
, NULL
);
196 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
199 mc_config_get_bool_list (mc_config_t
* mc_config
, const gchar
* group
,
200 const gchar
* param
, gsize
* length
)
202 if (!mc_config
|| !group
|| !param
)
205 return g_key_file_get_boolean_list (mc_config
->handle
, group
, param
, length
, NULL
);
208 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
211 mc_config_get_int_list (mc_config_t
* mc_config
, const gchar
* group
,
212 const gchar
* param
, gsize
* length
)
214 if (!mc_config
|| !group
|| !param
)
217 return g_key_file_get_integer_list (mc_config
->handle
, group
, param
, length
, NULL
);
220 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */