2009-09-04 18:22:49 +04:00
|
|
|
/*
|
|
|
|
Skins engine.
|
|
|
|
Interface functions
|
|
|
|
|
2024-01-01 09:46:17 +03:00
|
|
|
Copyright (C) 2009-2024
|
2014-02-12 10:33:10 +04:00
|
|
|
Free Software Foundation, Inc.
|
2009-09-04 18:22:49 +04:00
|
|
|
|
|
|
|
Written by:
|
2010-12-29 12:58:10 +03:00
|
|
|
Slava Zanko <slavazanko@gmail.com>, 2009
|
|
|
|
Egmont Koblinger <egmont@gmail.com>, 2010
|
2009-09-04 18:22:49 +04:00
|
|
|
|
|
|
|
This file is part of the Midnight Commander.
|
|
|
|
|
2011-10-15 14:56:47 +04:00
|
|
|
The Midnight Commander is free software: you can redistribute it
|
2009-09-04 18:22:49 +04:00
|
|
|
and/or modify it under the terms of the GNU General Public License as
|
2011-10-15 14:56:47 +04:00
|
|
|
published by the Free Software Foundation, either version 3 of the License,
|
|
|
|
or (at your option) any later version.
|
2009-09-04 18:22:49 +04:00
|
|
|
|
2011-10-15 14:56:47 +04:00
|
|
|
The Midnight Commander is distributed in the hope that it will be useful,
|
|
|
|
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.
|
2009-09-04 18:22:49 +04:00
|
|
|
|
|
|
|
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-09-04 18:22:49 +04:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
#include "internal.h"
|
2014-07-15 16:53:06 +04:00
|
|
|
#include "lib/util.h"
|
2009-09-04 18:22:49 +04:00
|
|
|
|
2011-01-16 03:13:48 +03:00
|
|
|
#include "lib/tty/color.h" /* tty_use_256colors(); */
|
|
|
|
|
2009-09-04 18:22:49 +04:00
|
|
|
/*** global variables ****************************************************************************/
|
|
|
|
|
|
|
|
mc_skin_t mc_skin__default;
|
|
|
|
|
|
|
|
/*** file scope macro definitions ****************************************************************/
|
|
|
|
|
|
|
|
/*** file scope type declarations ****************************************************************/
|
|
|
|
|
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) *************************************************/
|
|
|
|
|
2009-09-04 18:22:49 +04:00
|
|
|
/*** file scope variables ************************************************************************/
|
|
|
|
|
|
|
|
static gboolean mc_skin_is_init = FALSE;
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
/*** file scope functions ************************************************************************/
|
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
static void
|
|
|
|
mc_skin_hash_destroy_value (gpointer data)
|
|
|
|
{
|
2023-09-10 12:57:40 +03:00
|
|
|
tty_color_pair_t *mc_skin_color = (tty_color_pair_t *) data;
|
|
|
|
|
|
|
|
g_free (mc_skin_color->fg);
|
|
|
|
g_free (mc_skin_color->bg);
|
2010-12-29 12:58:10 +03:00
|
|
|
g_free (mc_skin_color->attrs);
|
2009-09-04 18:22:49 +04:00
|
|
|
g_free (mc_skin_color);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
static char *
|
2009-09-14 17:43:03 +04:00
|
|
|
mc_skin_get_default_name (void)
|
2009-09-04 18:22:49 +04:00
|
|
|
{
|
|
|
|
char *tmp_str;
|
|
|
|
|
|
|
|
/* from command line */
|
2012-01-28 14:13:32 +04:00
|
|
|
if (mc_global.tty.skin != NULL)
|
|
|
|
return g_strdup (mc_global.tty.skin);
|
2009-09-04 18:22:49 +04:00
|
|
|
|
|
|
|
/* from envirovement variable */
|
|
|
|
tmp_str = getenv ("MC_SKIN");
|
|
|
|
if (tmp_str != NULL)
|
2009-09-14 17:43:03 +04:00
|
|
|
return g_strdup (tmp_str);
|
2009-09-04 18:22:49 +04:00
|
|
|
|
|
|
|
/* from config. Or 'default' if no present in config */
|
2016-04-26 09:30:42 +03:00
|
|
|
return mc_config_get_string (mc_global.main_config, CONFIG_APP_SECTION, "skin", "default");
|
2009-09-04 18:22:49 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
static void
|
2009-09-14 17:43:03 +04:00
|
|
|
mc_skin_reinit (void)
|
2009-09-04 18:22:49 +04:00
|
|
|
{
|
2009-09-14 17:43:03 +04:00
|
|
|
mc_skin_deinit ();
|
|
|
|
mc_skin__default.name = mc_skin_get_default_name ();
|
2009-09-04 18:22:49 +04:00
|
|
|
mc_skin__default.colors = g_hash_table_new_full (g_str_hash, g_str_equal,
|
2010-11-08 13:21:45 +03:00
|
|
|
g_free, mc_skin_hash_destroy_value);
|
2009-09-04 18:22:49 +04:00
|
|
|
}
|
|
|
|
|
2009-09-28 18:04:25 +04:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
static void
|
|
|
|
mc_skin_try_to_load_default (void)
|
|
|
|
{
|
|
|
|
mc_skin_reinit ();
|
|
|
|
g_free (mc_skin__default.name);
|
|
|
|
mc_skin__default.name = g_strdup ("default");
|
2010-11-08 13:21:45 +03:00
|
|
|
if (!mc_skin_ini_file_load (&mc_skin__default))
|
|
|
|
{
|
2009-09-28 18:04:25 +04:00
|
|
|
mc_skin_reinit ();
|
|
|
|
mc_skin_set_hardcoded_skin (&mc_skin__default);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-09-04 18:22:49 +04:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
/*** public functions ****************************************************************************/
|
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
2009-09-28 18:04:25 +04:00
|
|
|
gboolean
|
2024-06-01 21:12:14 +03:00
|
|
|
mc_skin_init (const gchar *skin_override, GError **mcerror)
|
2009-09-04 18:22:49 +04:00
|
|
|
{
|
2009-10-30 04:12:04 +03:00
|
|
|
gboolean is_good_init = TRUE;
|
2016-11-02 14:07:33 +03:00
|
|
|
GError *error = NULL;
|
2009-09-28 18:04:25 +04:00
|
|
|
|
2014-07-15 16:53:06 +04:00
|
|
|
mc_return_val_if_error (mcerror, FALSE);
|
|
|
|
|
2011-01-16 03:13:48 +03:00
|
|
|
mc_skin__default.have_256_colors = FALSE;
|
2016-11-02 14:07:33 +03:00
|
|
|
mc_skin__default.have_true_colors = FALSE;
|
2011-01-16 03:13:48 +03:00
|
|
|
|
2014-02-08 19:37:11 +04:00
|
|
|
mc_skin__default.name =
|
|
|
|
skin_override != NULL ? g_strdup (skin_override) : mc_skin_get_default_name ();
|
2009-09-28 18:04:25 +04:00
|
|
|
|
2009-09-04 18:22:49 +04:00
|
|
|
mc_skin__default.colors = g_hash_table_new_full (g_str_hash, g_str_equal,
|
2010-11-08 13:21:45 +03:00
|
|
|
g_free, mc_skin_hash_destroy_value);
|
|
|
|
if (!mc_skin_ini_file_load (&mc_skin__default))
|
|
|
|
{
|
2014-07-15 16:53:06 +04:00
|
|
|
mc_propagate_error (mcerror, 0,
|
|
|
|
_("Unable to load '%s' skin.\nDefault skin has been loaded"),
|
|
|
|
mc_skin__default.name);
|
2009-09-28 18:04:25 +04:00
|
|
|
mc_skin_try_to_load_default ();
|
|
|
|
is_good_init = FALSE;
|
2009-09-04 18:22:49 +04:00
|
|
|
}
|
2009-09-10 16:14:18 +04:00
|
|
|
mc_skin_colors_old_configure (&mc_skin__default);
|
2009-09-04 18:22:49 +04:00
|
|
|
|
2010-11-08 13:21:45 +03:00
|
|
|
if (!mc_skin_ini_file_parse (&mc_skin__default))
|
|
|
|
{
|
2014-07-15 16:53:06 +04:00
|
|
|
mc_propagate_error (mcerror, 0,
|
|
|
|
_("Unable to parse '%s' skin.\nDefault skin has been loaded"),
|
|
|
|
mc_skin__default.name);
|
2009-09-28 18:04:25 +04:00
|
|
|
|
|
|
|
mc_skin_try_to_load_default ();
|
2009-09-14 17:43:03 +04:00
|
|
|
mc_skin_colors_old_configure (&mc_skin__default);
|
|
|
|
(void) mc_skin_ini_file_parse (&mc_skin__default);
|
2009-09-28 18:04:25 +04:00
|
|
|
is_good_init = FALSE;
|
2009-09-04 18:22:49 +04:00
|
|
|
}
|
2019-02-21 13:35:12 +03:00
|
|
|
if (is_good_init && mc_skin__default.have_true_colors && !tty_use_truecolors (&error))
|
2016-11-02 14:07:33 +03:00
|
|
|
{
|
|
|
|
mc_propagate_error (mcerror, 0,
|
|
|
|
_
|
|
|
|
("Unable to use '%s' skin with true colors support:\n%s\nDefault skin has been loaded"),
|
|
|
|
mc_skin__default.name, error->message);
|
|
|
|
g_error_free (error);
|
|
|
|
mc_skin_try_to_load_default ();
|
|
|
|
mc_skin_colors_old_configure (&mc_skin__default);
|
|
|
|
(void) mc_skin_ini_file_parse (&mc_skin__default);
|
|
|
|
is_good_init = FALSE;
|
|
|
|
}
|
2021-02-07 15:08:13 +03:00
|
|
|
if (is_good_init && mc_skin__default.have_256_colors && !tty_use_256colors (&error))
|
2011-01-16 03:13:48 +03:00
|
|
|
{
|
2014-07-15 16:53:06 +04:00
|
|
|
mc_propagate_error (mcerror, 0,
|
|
|
|
_
|
|
|
|
("Unable to use '%s' skin with 256 colors support\non non-256 colors terminal.\nDefault skin has been loaded"),
|
|
|
|
mc_skin__default.name);
|
2011-01-16 03:13:48 +03:00
|
|
|
mc_skin_try_to_load_default ();
|
|
|
|
mc_skin_colors_old_configure (&mc_skin__default);
|
|
|
|
(void) mc_skin_ini_file_parse (&mc_skin__default);
|
|
|
|
is_good_init = FALSE;
|
|
|
|
}
|
2009-09-04 18:22:49 +04:00
|
|
|
mc_skin_is_init = TRUE;
|
2009-09-28 18:04:25 +04:00
|
|
|
return is_good_init;
|
2009-09-04 18:22:49 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
void
|
2009-09-14 17:43:03 +04:00
|
|
|
mc_skin_deinit (void)
|
2009-09-04 18:22:49 +04:00
|
|
|
{
|
2023-06-12 12:35:20 +03:00
|
|
|
tty_color_free_all ();
|
2014-02-08 19:37:11 +04:00
|
|
|
|
2014-08-05 11:18:30 +04:00
|
|
|
MC_PTR_FREE (mc_skin__default.name);
|
2009-09-04 18:22:49 +04:00
|
|
|
g_hash_table_destroy (mc_skin__default.colors);
|
|
|
|
mc_skin__default.colors = NULL;
|
|
|
|
|
2014-08-05 11:18:30 +04:00
|
|
|
MC_PTR_FREE (mc_skin__default.description);
|
2009-09-04 18:22:49 +04:00
|
|
|
|
2010-11-04 15:13:41 +03:00
|
|
|
mc_config_deinit (mc_skin__default.config);
|
|
|
|
mc_skin__default.config = NULL;
|
2009-09-04 18:22:49 +04:00
|
|
|
|
|
|
|
mc_skin_is_init = FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
2009-10-15 11:31:24 +04:00
|
|
|
|
|
|
|
gchar *
|
2024-06-01 21:12:14 +03:00
|
|
|
mc_skin_get (const gchar *group, const gchar *key, const gchar *default_value)
|
2009-10-15 11:31:24 +04:00
|
|
|
{
|
2011-09-07 13:06:03 +04:00
|
|
|
if (mc_global.tty.ugly_line_drawing)
|
2010-11-08 13:21:45 +03:00
|
|
|
return g_strdup (default_value);
|
2022-11-27 20:11:08 +03:00
|
|
|
|
2010-11-08 13:21:45 +03:00
|
|
|
return mc_config_get_string (mc_skin__default.config, group, key, default_value);
|
2009-10-15 11:31:24 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------- */
|