2011-10-15 14:56:47 +04:00
|
|
|
/*
|
|
|
|
Configure module for the Midnight Commander
|
|
|
|
|
2014-01-05 12:37:43 +04:00
|
|
|
Copyright (C) 1994-2014
|
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"
|
2010-01-21 16:06:15 +03:00
|
|
|
#include "lib/mcconfig.h"
|
2009-07-08 16:17:10 +04:00
|
|
|
|
2009-05-20 10:33:53 +04:00
|
|
|
/*** global variables **************************************************/
|
|
|
|
|
|
|
|
/*** file scope macro definitions **************************************/
|
|
|
|
|
|
|
|
/*** file scope type declarations **************************************/
|
|
|
|
|
|
|
|
/*** file scope variables **********************************************/
|
|
|
|
|
|
|
|
/*** file scope functions **********************************************/
|
2009-10-12 15:56:46 +04:00
|
|
|
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
|
2009-05-20 10:33:53 +04:00
|
|
|
|
2009-10-12 15:56:46 +04:00
|
|
|
static gchar *
|
2010-11-08 13:21:45 +03:00
|
|
|
mc_config_normalize_before_save (const gchar * value)
|
2009-05-20 10:33:53 +04:00
|
|
|
{
|
2009-07-08 16:17:10 +04:00
|
|
|
GIConv conv;
|
|
|
|
GString *buffer;
|
2011-12-06 11:19:11 +04:00
|
|
|
gboolean ok;
|
2009-07-08 16:17:10 +04:00
|
|
|
|
2011-02-10 18:02:54 +03:00
|
|
|
if (mc_global.utf8_display)
|
2010-11-16 11:32:57 +03:00
|
|
|
return g_strdup (value);
|
2009-07-08 16:17:10 +04:00
|
|
|
|
2010-11-16 11:32:57 +03:00
|
|
|
conv = str_crt_conv_to ("UTF-8");
|
|
|
|
if (conv == INVALID_CONV)
|
|
|
|
return g_strdup (value);
|
2009-07-08 16:17:10 +04:00
|
|
|
|
2010-11-16 11:32:57 +03:00
|
|
|
buffer = g_string_new ("");
|
2009-07-08 16:17:10 +04:00
|
|
|
|
2011-12-06 11:19:11 +04:00
|
|
|
ok = (str_convert (conv, value, buffer) != ESTR_FAILURE);
|
|
|
|
str_close_conv (conv);
|
|
|
|
|
|
|
|
if (!ok)
|
2010-11-16 11:32:57 +03:00
|
|
|
{
|
|
|
|
g_string_free (buffer, TRUE);
|
|
|
|
return g_strdup (value);
|
2009-07-08 16:17:10 +04:00
|
|
|
}
|
|
|
|
|
2010-11-08 13:21:45 +03:00
|
|
|
return g_string_free (buffer, FALSE);
|
2009-10-12 15:56:46 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
|
|
|
|
/*** public functions **************************************************/
|
|
|
|
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
|
|
|
|
|
|
|
|
void
|
2010-11-16 13:52:23 +03:00
|
|
|
mc_config_set_string_raw (mc_config_t * mc_config, const gchar * group,
|
|
|
|
const gchar * param, const gchar * value)
|
2009-10-12 15:56:46 +04:00
|
|
|
{
|
|
|
|
if (!mc_config || !group || !param || !value)
|
2010-11-08 13:21:45 +03:00
|
|
|
return;
|
2009-10-12 15:56:46 +04:00
|
|
|
|
2011-05-31 15:11:01 +04:00
|
|
|
g_key_file_set_string (mc_config->handle, group, param, value);
|
2009-10-12 15:56:46 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
|
|
|
|
|
2011-12-05 13:45:03 +04:00
|
|
|
void
|
|
|
|
mc_config_set_string_raw_value (mc_config_t * mc_config, const gchar * group,
|
|
|
|
const gchar * param, const gchar * value)
|
|
|
|
{
|
|
|
|
if (!mc_config || !group || !param || !value)
|
|
|
|
return;
|
|
|
|
|
|
|
|
g_key_file_set_value (mc_config->handle, group, param, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
|
|
|
|
|
2009-10-12 15:56:46 +04:00
|
|
|
void
|
2011-06-06 15:54:02 +04:00
|
|
|
mc_config_set_string (const mc_config_t * mc_config, const gchar * group,
|
2010-11-08 13:21:45 +03:00
|
|
|
const gchar * param, const gchar * value)
|
2009-10-12 15:56:46 +04:00
|
|
|
{
|
|
|
|
gchar *buffer;
|
|
|
|
|
|
|
|
if (!mc_config || !group || !param || !value)
|
2010-11-08 13:21:45 +03:00
|
|
|
return;
|
2009-10-12 15:56:46 +04:00
|
|
|
|
2010-11-08 13:21:45 +03:00
|
|
|
buffer = mc_config_normalize_before_save (value);
|
2009-10-12 15:56:46 +04:00
|
|
|
|
|
|
|
g_key_file_set_string (mc_config->handle, group, param, buffer);
|
|
|
|
|
2010-11-08 13:21:45 +03:00
|
|
|
g_free (buffer);
|
2009-05-20 10:33:53 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
|
|
|
|
|
|
|
|
void
|
|
|
|
mc_config_set_bool (mc_config_t * mc_config, const gchar * group,
|
2010-11-08 13:21:45 +03:00
|
|
|
const gchar * param, gboolean value)
|
2009-05-20 10:33:53 +04:00
|
|
|
{
|
2010-11-08 13:21:45 +03:00
|
|
|
if (!mc_config || !group || !param)
|
|
|
|
return;
|
2009-05-20 10:33:53 +04:00
|
|
|
|
|
|
|
g_key_file_set_boolean (mc_config->handle, group, param, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
|
|
|
|
|
|
|
|
void
|
2010-11-08 13:21:45 +03:00
|
|
|
mc_config_set_int (mc_config_t * mc_config, const gchar * group, const gchar * param, int value)
|
2009-05-20 10:33:53 +04:00
|
|
|
{
|
2010-11-08 13:21:45 +03:00
|
|
|
if (!mc_config || !group || !param)
|
|
|
|
return;
|
2009-05-20 10:33:53 +04:00
|
|
|
|
|
|
|
g_key_file_set_integer (mc_config->handle, group, param, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
|
|
|
|
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
|
|
|
|
|
|
|
|
void
|
|
|
|
mc_config_set_string_list (mc_config_t * mc_config, const gchar * group,
|
2010-11-08 13:21:45 +03:00
|
|
|
const gchar * param, const gchar * const value[], gsize length)
|
2009-05-20 10:33:53 +04:00
|
|
|
{
|
|
|
|
if (!mc_config || !group || !param || !value || length == 0)
|
2010-11-08 13:21:45 +03:00
|
|
|
return;
|
2009-05-20 10:33:53 +04:00
|
|
|
|
2010-11-08 13:21:45 +03:00
|
|
|
g_key_file_set_string_list (mc_config->handle, group, param, value, length);
|
2009-05-20 10:33:53 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
mc_config_set_bool_list (mc_config_t * mc_config, const gchar * group,
|
2010-11-08 13:21:45 +03:00
|
|
|
const gchar * param, gboolean value[], gsize length)
|
2009-05-20 10:33:53 +04:00
|
|
|
{
|
|
|
|
if (!mc_config || !group || !param || !value || length == 0)
|
2010-11-08 13:21:45 +03:00
|
|
|
return;
|
2009-05-20 10:33:53 +04:00
|
|
|
|
2010-11-08 13:21:45 +03:00
|
|
|
g_key_file_set_boolean_list (mc_config->handle, group, param, value, length);
|
2009-05-20 10:33:53 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
|
|
|
|
|
|
|
|
void
|
|
|
|
mc_config_set_int_list (mc_config_t * mc_config, const gchar * group,
|
2010-11-08 13:21:45 +03:00
|
|
|
const gchar * param, int value[], gsize length)
|
2009-05-20 10:33:53 +04:00
|
|
|
{
|
|
|
|
if (!mc_config || !group || !param || !value || length == 0)
|
2010-11-08 13:21:45 +03:00
|
|
|
return;
|
2009-05-20 10:33:53 +04:00
|
|
|
|
2010-11-08 13:21:45 +03:00
|
|
|
g_key_file_set_integer_list (mc_config->handle, group, param, value, length);
|
2009-05-20 10:33:53 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
|