2011-10-15 14:56:47 +04:00
|
|
|
/*
|
|
|
|
Configure module for the Midnight Commander
|
|
|
|
|
2024-01-01 09:46:17 +03:00
|
|
|
Copyright (C) 1994-2024
|
2014-02-12 10:33:10 +04:00
|
|
|
Free Software Foundation, Inc.
|
2011-10-15 14:56:47 +04:00
|
|
|
|
|
|
|
This file is part of the Midnight Commander.
|
2009-05-20 10:33:53 +04:00
|
|
|
|
2011-10-15 14:56:47 +04:00
|
|
|
The Midnight Commander is free software: you can redistribute it
|
|
|
|
and/or modify it under the terms of the GNU General Public License as
|
|
|
|
published by the Free Software Foundation, either version 3 of the License,
|
|
|
|
or (at your option) any later version.
|
2009-05-20 10:33:53 +04:00
|
|
|
|
2011-10-15 14:56:47 +04:00
|
|
|
The Midnight Commander is distributed in the hope that it will be useful,
|
2009-05-20 10:33:53 +04:00
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
2011-10-15 14:56:47 +04:00
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2009-05-20 10:33:53 +04:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
2010-01-20 18:11:52 +03:00
|
|
|
#include "lib/global.h"
|
2010-01-21 15:17:26 +03:00
|
|
|
#include "lib/strutil.h"
|
2019-07-28 10:28:26 +03:00
|
|
|
|
2010-01-21 16:06:15 +03:00
|
|
|
#include "lib/mcconfig.h"
|
2009-07-08 16:17:10 +04:00
|
|
|
|
2019-07-28 10:28:26 +03:00
|
|
|
/*** global variables ****************************************************************************/
|
|
|
|
|
|
|
|
/*** file scope macro definitions ****************************************************************/
|
2009-05-20 10:33:53 +04:00
|
|
|
|
2019-07-28 10:28:26 +03:00
|
|
|
/*** file scope type declarations ****************************************************************/
|
2009-05-20 10:33:53 +04:00
|
|
|
|
2019-07-28 10:28:26 +03:00
|
|
|
/*** file scope variables ************************************************************************/
|
2009-05-20 10:33:53 +04:00
|
|
|
|
2019-07-28 10:28:26 +03:00
|
|
|
/*** file scope functions ************************************************************************/
|
2009-05-20 10:33:53 +04:00
|
|
|
|
2019-07-28 10:28:26 +03:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
/*** file scope functions ************************************************************************/
|
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
2009-05-20 10:33:53 +04:00
|
|
|
|
2019-07-28 10:28:26 +03:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
/*** public functions ****************************************************************************/
|
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
2009-05-20 10:33:53 +04:00
|
|
|
|
|
|
|
gchar **
|
2024-06-01 21:12:14 +03:00
|
|
|
mc_config_get_groups (const mc_config_t *mc_config, gsize *len)
|
2009-05-20 10:33:53 +04:00
|
|
|
{
|
2014-05-04 12:05:30 +04:00
|
|
|
gchar **ret = NULL;
|
|
|
|
|
|
|
|
if (mc_config != NULL)
|
|
|
|
ret = g_key_file_get_groups (mc_config->handle, len);
|
2009-05-20 10:33:53 +04:00
|
|
|
|
2014-05-04 12:05:30 +04:00
|
|
|
if (ret == NULL)
|
2009-05-20 10:33:53 +04:00
|
|
|
{
|
2010-11-08 13:21:45 +03:00
|
|
|
ret = g_try_malloc0 (sizeof (gchar **));
|
|
|
|
if (len != NULL)
|
|
|
|
*len = 0;
|
2009-05-20 10:33:53 +04:00
|
|
|
}
|
2014-05-04 12:05:30 +04:00
|
|
|
|
2009-05-20 10:33:53 +04:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2019-07-28 10:28:26 +03:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
2009-05-20 10:33:53 +04:00
|
|
|
|
|
|
|
gchar **
|
2024-06-01 21:12:14 +03:00
|
|
|
mc_config_get_keys (const mc_config_t *mc_config, const gchar *group, gsize *len)
|
2009-05-20 10:33:53 +04:00
|
|
|
{
|
2014-05-04 11:38:25 +04:00
|
|
|
gchar **ret = NULL;
|
|
|
|
|
|
|
|
if (mc_config != NULL && group != NULL)
|
|
|
|
ret = g_key_file_get_keys (mc_config->handle, group, len, NULL);
|
2009-05-20 10:33:53 +04:00
|
|
|
|
2014-05-04 11:38:25 +04:00
|
|
|
if (ret == NULL)
|
2009-05-20 10:33:53 +04:00
|
|
|
{
|
2010-11-08 13:21:45 +03:00
|
|
|
ret = g_try_malloc0 (sizeof (gchar **));
|
|
|
|
if (len != NULL)
|
|
|
|
*len = 0;
|
2009-05-20 10:33:53 +04:00
|
|
|
}
|
2014-05-04 11:38:25 +04:00
|
|
|
|
2009-05-20 10:33:53 +04:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2019-07-28 10:28:26 +03:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
2009-05-20 10:33:53 +04:00
|
|
|
|
|
|
|
gchar *
|
2024-06-01 21:12:14 +03:00
|
|
|
mc_config_get_string (mc_config_t *mc_config, const gchar *group,
|
|
|
|
const gchar *param, const gchar *def)
|
2009-05-20 10:33:53 +04:00
|
|
|
{
|
2009-07-08 16:17:10 +04:00
|
|
|
GIConv conv;
|
|
|
|
GString *buffer;
|
2009-05-20 10:33:53 +04:00
|
|
|
gchar *ret;
|
2010-11-16 11:32:57 +03:00
|
|
|
estr_t conv_res;
|
2009-07-08 16:17:10 +04:00
|
|
|
|
2022-05-14 15:36:37 +03:00
|
|
|
ret = mc_config_get_string_raw (mc_config, group, param, def);
|
2009-05-20 10:33:53 +04:00
|
|
|
|
2011-02-10 18:02:54 +03:00
|
|
|
if (mc_global.utf8_display)
|
2009-07-08 16:17:10 +04:00
|
|
|
return ret;
|
|
|
|
|
2010-11-16 11:32:57 +03:00
|
|
|
conv = str_crt_conv_from ("UTF-8");
|
2009-07-08 16:17:10 +04:00
|
|
|
if (conv == INVALID_CONV)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
buffer = g_string_new ("");
|
2010-11-16 11:32:57 +03:00
|
|
|
conv_res = str_convert (conv, ret, buffer);
|
|
|
|
str_close_conv (conv);
|
2009-07-08 16:17:10 +04:00
|
|
|
|
2010-11-16 11:32:57 +03:00
|
|
|
if (conv_res == ESTR_FAILURE)
|
2009-07-08 16:17:10 +04:00
|
|
|
{
|
2010-11-08 13:21:45 +03:00
|
|
|
g_string_free (buffer, TRUE);
|
2009-07-08 16:17:10 +04:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2010-11-08 13:21:45 +03:00
|
|
|
g_free (ret);
|
2009-07-08 16:17:10 +04:00
|
|
|
|
2010-11-08 13:21:45 +03:00
|
|
|
return g_string_free (buffer, FALSE);
|
2009-05-20 10:33:53 +04:00
|
|
|
}
|
|
|
|
|
2019-07-28 10:28:26 +03:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
2009-05-20 10:33:53 +04:00
|
|
|
|
2009-09-14 17:43:03 +04:00
|
|
|
gchar *
|
2024-06-01 21:12:14 +03:00
|
|
|
mc_config_get_string_raw (mc_config_t *mc_config, const gchar *group,
|
|
|
|
const gchar *param, const gchar *def)
|
2009-09-14 17:43:03 +04:00
|
|
|
{
|
|
|
|
gchar *ret;
|
|
|
|
|
2019-07-28 10:28:26 +03:00
|
|
|
if (mc_config == NULL || group == NULL || param == NULL)
|
2010-11-16 11:32:57 +03:00
|
|
|
return g_strdup (def);
|
2009-09-14 17:43:03 +04:00
|
|
|
|
2010-11-08 13:21:45 +03:00
|
|
|
if (!mc_config_has_param (mc_config, group, param))
|
2009-09-14 17:43:03 +04:00
|
|
|
{
|
2013-01-13 17:47:11 +04:00
|
|
|
if (def != NULL)
|
|
|
|
mc_config_set_string (mc_config, group, param, def);
|
2010-11-16 11:32:57 +03:00
|
|
|
return g_strdup (def);
|
2009-09-14 17:43:03 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
ret = g_key_file_get_string (mc_config->handle, group, param, NULL);
|
|
|
|
|
2010-11-16 11:32:57 +03:00
|
|
|
return ret != NULL ? ret : g_strdup (def);
|
2009-09-14 17:43:03 +04:00
|
|
|
}
|
|
|
|
|
2019-07-28 10:28:26 +03:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
2009-09-14 17:43:03 +04:00
|
|
|
|
2009-05-20 10:33:53 +04:00
|
|
|
gboolean
|
2024-06-01 21:12:14 +03:00
|
|
|
mc_config_get_bool (mc_config_t *mc_config, const gchar *group, const gchar *param, gboolean def)
|
2009-05-20 10:33:53 +04:00
|
|
|
{
|
2019-07-28 10:28:26 +03:00
|
|
|
if (mc_config == NULL || group == NULL || param == NULL)
|
2010-11-08 13:21:45 +03:00
|
|
|
return def;
|
2009-05-20 10:33:53 +04:00
|
|
|
|
2010-11-08 13:21:45 +03:00
|
|
|
if (!mc_config_has_param (mc_config, group, param))
|
2009-05-20 10:33:53 +04:00
|
|
|
{
|
2010-11-08 13:21:45 +03:00
|
|
|
mc_config_set_bool (mc_config, group, param, def);
|
|
|
|
return def;
|
2009-05-20 10:33:53 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return g_key_file_get_boolean (mc_config->handle, group, param, NULL);
|
|
|
|
}
|
|
|
|
|
2019-07-28 10:28:26 +03:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
2009-05-20 10:33:53 +04:00
|
|
|
|
|
|
|
int
|
2024-06-01 21:12:14 +03:00
|
|
|
mc_config_get_int (mc_config_t *mc_config, const gchar *group, const gchar *param, int def)
|
2009-05-20 10:33:53 +04:00
|
|
|
{
|
2019-07-28 10:28:26 +03:00
|
|
|
if (mc_config == NULL || group == NULL || param == NULL)
|
2010-11-08 13:21:45 +03:00
|
|
|
return def;
|
2009-05-20 10:33:53 +04:00
|
|
|
|
2010-11-08 13:21:45 +03:00
|
|
|
if (!mc_config_has_param (mc_config, group, param))
|
2009-05-20 10:33:53 +04:00
|
|
|
{
|
2010-11-08 13:21:45 +03:00
|
|
|
mc_config_set_int (mc_config, group, param, def);
|
|
|
|
return def;
|
2009-05-20 10:33:53 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return g_key_file_get_integer (mc_config->handle, group, param, NULL);
|
|
|
|
}
|
|
|
|
|
2019-07-28 10:28:26 +03:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
2009-05-20 10:33:53 +04:00
|
|
|
|
|
|
|
gchar **
|
2024-06-01 21:12:14 +03:00
|
|
|
mc_config_get_string_list (mc_config_t *mc_config, const gchar *group,
|
|
|
|
const gchar *param, gsize *length)
|
2009-05-20 10:33:53 +04:00
|
|
|
{
|
2019-07-28 10:28:26 +03:00
|
|
|
if (mc_config == NULL || group == NULL || param == NULL)
|
2010-11-08 13:21:45 +03:00
|
|
|
return NULL;
|
2009-05-20 10:33:53 +04:00
|
|
|
|
2010-11-08 13:21:45 +03:00
|
|
|
return g_key_file_get_string_list (mc_config->handle, group, param, length, NULL);
|
2009-05-20 10:33:53 +04:00
|
|
|
}
|
|
|
|
|
2019-07-28 10:28:26 +03:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
2009-05-20 10:33:53 +04:00
|
|
|
|
|
|
|
gboolean *
|
2024-06-01 21:12:14 +03:00
|
|
|
mc_config_get_bool_list (mc_config_t *mc_config, const gchar *group,
|
|
|
|
const gchar *param, gsize *length)
|
2009-05-20 10:33:53 +04:00
|
|
|
{
|
2019-07-28 10:28:26 +03:00
|
|
|
if (mc_config == NULL || group == NULL || param == NULL)
|
2010-11-08 13:21:45 +03:00
|
|
|
return NULL;
|
2009-05-20 10:33:53 +04:00
|
|
|
|
2010-11-08 13:21:45 +03:00
|
|
|
return g_key_file_get_boolean_list (mc_config->handle, group, param, length, NULL);
|
2009-05-20 10:33:53 +04:00
|
|
|
}
|
|
|
|
|
2019-07-28 10:28:26 +03:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
2009-05-20 10:33:53 +04:00
|
|
|
|
|
|
|
int *
|
2024-06-01 21:12:14 +03:00
|
|
|
mc_config_get_int_list (mc_config_t *mc_config, const gchar *group,
|
|
|
|
const gchar *param, gsize *length)
|
2009-05-20 10:33:53 +04:00
|
|
|
{
|
2019-07-28 10:28:26 +03:00
|
|
|
if (mc_config == NULL || group == NULL || param == NULL)
|
2010-11-08 13:21:45 +03:00
|
|
|
return NULL;
|
2009-05-20 10:33:53 +04:00
|
|
|
|
2010-11-08 13:21:45 +03:00
|
|
|
return g_key_file_get_integer_list (mc_config->handle, group, param, length, NULL);
|
2009-05-20 10:33:53 +04:00
|
|
|
}
|
|
|
|
|
2019-07-28 10:28:26 +03:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|