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 ****************************************************************************/
|
2009-05-20 10:33:53 +04:00
|
|
|
|
2019-07-28 10:28:26 +03:00
|
|
|
/*** 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
|
|
|
|
Update template for .c files.
Add section for forward declarations of local functions. This section is
located before file scope variables because functions can be used in
strucutres (see find.c for example):
/*** forward declarations (file scope functions) *************************************************/
/* button callbacks */
static int start_stop (WButton * button, int action);
static int find_do_view_file (WButton * button, int action);
static int find_do_edit_file (WButton * button, int action);
/*** file scope variables ************************************************************************/
static struct
{
...
bcback_fn callback;
} fbuts[] =
{
...
{ B_STOP, NORMAL_BUTTON, N_("S&uspend"), 0, 0, NULL, start_stop },
...
{ B_VIEW, NORMAL_BUTTON, N_("&View - F3"), 0, 0, NULL, find_do_view_file },
{ B_VIEW, NORMAL_BUTTON, N_("&Edit - F4"), 0, 0, NULL, find_do_edit_file }
};
Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
2023-02-24 09:27:11 +03:00
|
|
|
/*** forward declarations (file scope functions) *************************************************/
|
|
|
|
|
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
|
|
|
|
2009-10-12 15:56:46 +04:00
|
|
|
static gchar *
|
2024-06-01 21:12:14 +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
|
|
|
}
|
|
|
|
|
2019-07-28 10:28:26 +03:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
/*** public functions ****************************************************************************/
|
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
2009-10-12 15:56:46 +04:00
|
|
|
|
|
|
|
void
|
2024-06-01 21:12:14 +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
|
|
|
{
|
2019-07-28 10:28:26 +03:00
|
|
|
if (mc_config != NULL && group != NULL && param != NULL && value != NULL)
|
|
|
|
g_key_file_set_string (mc_config->handle, group, param, value);
|
2009-10-12 15:56:46 +04:00
|
|
|
}
|
|
|
|
|
2019-07-28 10:28:26 +03:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
2009-10-12 15:56:46 +04:00
|
|
|
|
2011-12-05 13:45:03 +04:00
|
|
|
void
|
2024-06-01 21:12:14 +03:00
|
|
|
mc_config_set_string_raw_value (mc_config_t *mc_config, const gchar *group,
|
|
|
|
const gchar *param, const gchar *value)
|
2011-12-05 13:45:03 +04:00
|
|
|
{
|
2019-07-28 10:28:26 +03:00
|
|
|
if (mc_config != NULL && group != NULL && param != NULL && value != NULL)
|
|
|
|
g_key_file_set_value (mc_config->handle, group, param, value);
|
2011-12-05 13:45:03 +04:00
|
|
|
}
|
|
|
|
|
2019-07-28 10:28:26 +03:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
2011-12-05 13:45:03 +04:00
|
|
|
|
2009-10-12 15:56:46 +04:00
|
|
|
void
|
2024-06-01 21:12:14 +03:00
|
|
|
mc_config_set_string (mc_config_t *mc_config, const gchar *group,
|
|
|
|
const gchar *param, const gchar *value)
|
2009-10-12 15:56:46 +04:00
|
|
|
{
|
2019-07-28 10:28:26 +03:00
|
|
|
if (mc_config != NULL && group != NULL && param != NULL && value != NULL)
|
|
|
|
{
|
|
|
|
gchar *buffer;
|
2009-10-12 15:56:46 +04:00
|
|
|
|
2019-07-28 10:28:26 +03:00
|
|
|
buffer = mc_config_normalize_before_save (value);
|
|
|
|
g_key_file_set_string (mc_config->handle, group, param, buffer);
|
|
|
|
g_free (buffer);
|
|
|
|
}
|
2009-05-20 10:33:53 +04:00
|
|
|
}
|
|
|
|
|
2019-07-28 10:28:26 +03:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
2009-05-20 10:33:53 +04:00
|
|
|
|
|
|
|
void
|
2024-06-01 21:12:14 +03:00
|
|
|
mc_config_set_bool (mc_config_t *mc_config, const gchar *group, const gchar *param, gboolean value)
|
2009-05-20 10:33:53 +04:00
|
|
|
{
|
2019-07-28 10:28:26 +03:00
|
|
|
if (mc_config != NULL && group != NULL && param != NULL)
|
|
|
|
g_key_file_set_boolean (mc_config->handle, group, param, value);
|
2009-05-20 10:33:53 +04:00
|
|
|
}
|
|
|
|
|
2019-07-28 10:28:26 +03:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
2009-05-20 10:33:53 +04:00
|
|
|
|
|
|
|
void
|
2024-06-01 21:12:14 +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
|
|
|
{
|
2019-07-28 10:28:26 +03:00
|
|
|
if (mc_config != NULL && group != NULL && param != NULL)
|
|
|
|
g_key_file_set_integer (mc_config->handle, group, param, value);
|
2009-05-20 10:33:53 +04:00
|
|
|
}
|
|
|
|
|
2019-07-28 10:28:26 +03:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
2009-05-20 10:33:53 +04:00
|
|
|
|
|
|
|
void
|
2024-06-01 21:12:14 +03:00
|
|
|
mc_config_set_string_list (mc_config_t *mc_config, const gchar *group,
|
|
|
|
const gchar *param, const gchar *const value[], 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 && value != NULL && length != 0)
|
|
|
|
g_key_file_set_string_list (mc_config->handle, group, param, value, length);
|
2009-05-20 10:33:53 +04:00
|
|
|
}
|
|
|
|
|
2019-07-28 10:28:26 +03:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
2009-05-20 10:33:53 +04:00
|
|
|
|
|
|
|
void
|
2024-06-01 21:12:14 +03:00
|
|
|
mc_config_set_bool_list (mc_config_t *mc_config, const gchar *group,
|
|
|
|
const gchar *param, gboolean value[], 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 && value != NULL && length != 0)
|
|
|
|
g_key_file_set_boolean_list (mc_config->handle, group, param, value, length);
|
2009-05-20 10:33:53 +04:00
|
|
|
}
|
|
|
|
|
2019-07-28 10:28:26 +03:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
2009-05-20 10:33:53 +04:00
|
|
|
|
|
|
|
void
|
2024-06-01 21:12:14 +03:00
|
|
|
mc_config_set_int_list (mc_config_t *mc_config, const gchar *group,
|
|
|
|
const gchar *param, int value[], 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 && value != NULL && length != 0)
|
|
|
|
g_key_file_set_integer_list (mc_config->handle, group, param, value, length);
|
2009-05-20 10:33:53 +04:00
|
|
|
}
|
|
|
|
|
2019-07-28 10:28:26 +03:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|