Merge branch '2206_jump_line'
[midnight-commander.git] / lib / mcconfig / get.c
blob0a102d1b7374e189c301761416359d9f957656f4
1 /*
2 Configure module for the Midnight Commander
4 Copyright (C) 1994, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006,
5 2007, 2009, 2011
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/>.
24 #include <config.h>
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 **************************************************/
42 gchar **
43 mc_config_get_groups (const mc_config_t * mc_config, gsize * len)
45 gchar **ret;
47 if (!mc_config)
49 ret = g_try_malloc0 (sizeof (gchar **));
50 if (len != NULL)
51 *len = 0;
52 return ret;
54 ret = g_key_file_get_groups (mc_config->handle, len);
55 if (ret == NULL)
57 ret = g_try_malloc0 (sizeof (gchar **));
59 return ret;
62 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
64 gchar **
65 mc_config_get_keys (const mc_config_t * mc_config, const gchar * group, gsize * len)
67 gchar **ret;
69 if (!mc_config || !group)
71 ret = g_try_malloc0 (sizeof (gchar **));
72 if (len != NULL)
73 *len = 0;
74 return ret;
76 ret = g_key_file_get_keys (mc_config->handle, group, len, NULL);
77 if (ret == NULL)
79 ret = g_try_malloc0 (sizeof (gchar **));
81 return ret;
84 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
86 gchar *
87 mc_config_get_string (mc_config_t * mc_config, const gchar * group,
88 const gchar * param, const gchar * def)
90 GIConv conv;
91 GString *buffer;
92 gchar *ret;
93 estr_t conv_res;
95 if (!mc_config || !group || !param)
96 return g_strdup (def);
98 if (!mc_config_has_param (mc_config, group, param))
100 if (def != NULL)
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);
106 if (ret == NULL)
107 ret = g_strdup (def);
109 if (mc_global.utf8_display)
110 return ret;
112 conv = str_crt_conv_from ("UTF-8");
113 if (conv == INVALID_CONV)
114 return ret;
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);
123 return ret;
126 g_free (ret);
128 return g_string_free (buffer, FALSE);
131 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
133 gchar *
134 mc_config_get_string_raw (const mc_config_t * mc_config, const gchar * group,
135 const gchar * param, const gchar * def)
137 gchar *ret;
139 if (!mc_config || !group || !param)
140 return g_strdup (def);
142 if (!mc_config_has_param (mc_config, group, param))
144 if (def != NULL)
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 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
156 gboolean
157 mc_config_get_bool (mc_config_t * mc_config, const gchar * group, const gchar * param, gboolean def)
159 if (!mc_config || !group || !param)
160 return def;
162 if (!mc_config_has_param (mc_config, group, param))
164 mc_config_set_bool (mc_config, group, param, def);
165 return 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)
177 return def;
179 if (!mc_config_has_param (mc_config, group, param))
181 mc_config_set_int (mc_config, group, param, def);
182 return def;
185 return g_key_file_get_integer (mc_config->handle, group, param, NULL);
188 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
189 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
191 gchar **
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)
196 return NULL;
198 return g_key_file_get_string_list (mc_config->handle, group, param, length, NULL);
201 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
203 gboolean *
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)
208 return NULL;
210 return g_key_file_get_boolean_list (mc_config->handle, group, param, length, NULL);
213 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
215 int *
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)
220 return NULL;
222 return g_key_file_get_integer_list (mc_config->handle, group, param, length, NULL);
225 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */