Ticket #2598: u7z: Improve handling of missing p7zip binaries.
[midnight-commander.git] / lib / mcconfig / get.c
blob6a5e11afcbce6d7a40fc3758597c38ad18e00386
1 /* Configure module for the Midnight Commander
2 Copyright (C) 1994, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006,
3 2007, 2009 Free Software Foundation, Inc.
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 #include <config.h>
22 #include "lib/global.h"
23 #include "lib/strutil.h"
24 #include "lib/mcconfig.h"
26 /*** global variables **************************************************/
28 /*** file scope macro definitions **************************************/
30 /*** file scope type declarations **************************************/
32 /*** file scope variables **********************************************/
34 /*** file scope functions **********************************************/
36 /*** public functions **************************************************/
38 gchar **
39 mc_config_get_groups (const mc_config_t * mc_config, gsize * len)
41 gchar **ret;
43 if (!mc_config)
45 ret = g_try_malloc0 (sizeof (gchar **));
46 if (len != NULL)
47 *len = 0;
48 return ret;
50 ret = g_key_file_get_groups (mc_config->handle, len);
51 if (ret == NULL)
53 ret = g_try_malloc0 (sizeof (gchar **));
55 return ret;
58 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
60 gchar **
61 mc_config_get_keys (const mc_config_t * mc_config, const gchar * group, gsize * len)
63 gchar **ret;
65 if (!mc_config || !group)
67 ret = g_try_malloc0 (sizeof (gchar **));
68 if (len != NULL)
69 *len = 0;
70 return ret;
72 ret = g_key_file_get_keys (mc_config->handle, group, len, NULL);
73 if (ret == NULL)
75 ret = g_try_malloc0 (sizeof (gchar **));
77 return ret;
80 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
82 gchar *
83 mc_config_get_string (mc_config_t * mc_config, const gchar * group,
84 const gchar * param, const gchar * def)
86 GIConv conv;
87 GString *buffer;
88 gchar *ret;
89 estr_t conv_res;
91 if (!mc_config || !group || !param)
92 return g_strdup (def);
94 if (!mc_config_has_param (mc_config, group, param))
96 mc_config_set_string (mc_config, group, param, def ? def : "");
97 return g_strdup (def);
100 ret = g_key_file_get_string (mc_config->handle, group, param, NULL);
101 if (ret == NULL)
102 ret = g_strdup (def);
104 if (mc_global.utf8_display)
105 return ret;
107 conv = str_crt_conv_from ("UTF-8");
108 if (conv == INVALID_CONV)
109 return ret;
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);
118 return ret;
121 g_free (ret);
123 return g_string_free (buffer, FALSE);
126 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
128 gchar *
129 mc_config_get_string_raw (const mc_config_t * mc_config, const gchar * group,
130 const gchar * param, const gchar * def)
132 gchar *ret;
134 if (!mc_config || !group || !param)
135 return g_strdup (def);
137 if (!mc_config_has_param (mc_config, group, param))
139 mc_config_set_string (mc_config, group, param, def ? def : "");
140 return g_strdup (def);
143 ret = g_key_file_get_string (mc_config->handle, group, param, NULL);
145 return ret != NULL ? ret : g_strdup (def);
148 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
150 gboolean
151 mc_config_get_bool (mc_config_t * mc_config, const gchar * group, const gchar * param, gboolean def)
153 if (!mc_config || !group || !param)
154 return def;
156 if (!mc_config_has_param (mc_config, group, param))
158 mc_config_set_bool (mc_config, group, param, def);
159 return def;
162 return g_key_file_get_boolean (mc_config->handle, group, param, NULL);
165 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
168 mc_config_get_int (mc_config_t * mc_config, const gchar * group, const gchar * param, int def)
170 if (!mc_config || !group || !param)
171 return def;
173 if (!mc_config_has_param (mc_config, group, param))
175 mc_config_set_int (mc_config, group, param, def);
176 return def;
179 return g_key_file_get_integer (mc_config->handle, group, param, NULL);
182 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
183 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
185 gchar **
186 mc_config_get_string_list (mc_config_t * mc_config, const gchar * group,
187 const gchar * param, gsize * length)
189 if (!mc_config || !group || !param)
190 return NULL;
192 return g_key_file_get_string_list (mc_config->handle, group, param, length, NULL);
195 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
197 gboolean *
198 mc_config_get_bool_list (mc_config_t * mc_config, const gchar * group,
199 const gchar * param, gsize * length)
201 if (!mc_config || !group || !param)
202 return NULL;
204 return g_key_file_get_boolean_list (mc_config->handle, group, param, length, NULL);
207 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
209 int *
210 mc_config_get_int_list (mc_config_t * mc_config, const gchar * group,
211 const gchar * param, gsize * length)
213 if (!mc_config || !group || !param)
214 return NULL;
216 return g_key_file_get_integer_list (mc_config->handle, group, param, length, NULL);
219 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */