2009-09-04 18:22:49 +04:00
|
|
|
/*
|
|
|
|
Skins engine.
|
|
|
|
Interface functions
|
|
|
|
|
2010-12-29 12:58:10 +03:00
|
|
|
Copyright (C) 2009, 2010 The 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.
|
|
|
|
|
|
|
|
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 2 of the
|
|
|
|
License, or (at your option) any later version.
|
|
|
|
|
|
|
|
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.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
|
|
|
MA 02110-1301, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
#include "internal.h"
|
|
|
|
|
2010-01-21 16:06:15 +03:00
|
|
|
#include "src/args.h"
|
|
|
|
|
2009-09-04 18:22:49 +04:00
|
|
|
/*** global variables ****************************************************************************/
|
|
|
|
|
|
|
|
mc_skin_t mc_skin__default;
|
|
|
|
|
|
|
|
/*** file scope macro definitions ****************************************************************/
|
|
|
|
|
|
|
|
/*** file scope type declarations ****************************************************************/
|
|
|
|
|
|
|
|
/*** file scope variables ************************************************************************/
|
|
|
|
|
|
|
|
static gboolean mc_skin_is_init = FALSE;
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
/*** file scope functions ************************************************************************/
|
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
static void
|
|
|
|
mc_skin_hash_destroy_value (gpointer data)
|
|
|
|
{
|
|
|
|
mc_skin_color_t *mc_skin_color = (mc_skin_color_t *) data;
|
|
|
|
g_free (mc_skin_color->fgcolor);
|
|
|
|
g_free (mc_skin_color->bgcolor);
|
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 */
|
|
|
|
if (mc_args__skin != NULL)
|
2009-09-14 17:43:03 +04:00
|
|
|
return g_strdup (mc_args__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 */
|
2009-09-14 17:43:03 +04:00
|
|
|
return mc_config_get_string (mc_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
|
|
|
|
mc_skin_init (GError ** error)
|
2009-09-04 18:22:49 +04:00
|
|
|
{
|
2009-10-30 04:12:04 +03:00
|
|
|
gboolean is_good_init = TRUE;
|
2009-09-28 18:04:25 +04:00
|
|
|
|
2009-09-14 17:43:03 +04:00
|
|
|
mc_skin__default.name = 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);
|
2009-09-04 18:22:49 +04:00
|
|
|
|
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
|
|
|
*error = g_error_new (MC_ERROR, 0,
|
|
|
|
_("Unable to load '%s' skin.\nDefault skin has been loaded"),
|
|
|
|
mc_skin__default.name);
|
|
|
|
|
|
|
|
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))
|
|
|
|
{
|
2009-09-28 18:04:25 +04:00
|
|
|
if (*error == NULL)
|
|
|
|
*error = g_error_new (MC_ERROR, 0,
|
|
|
|
_("Unable to parse '%s' skin.\nDefault skin has been loaded"),
|
|
|
|
mc_skin__default.name);
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
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
|
|
|
{
|
2009-09-14 17:43:03 +04:00
|
|
|
g_free (mc_skin__default.name);
|
2009-09-04 18:22:49 +04:00
|
|
|
mc_skin__default.name = NULL;
|
|
|
|
g_hash_table_destroy (mc_skin__default.colors);
|
|
|
|
mc_skin__default.colors = NULL;
|
|
|
|
|
2009-09-14 17:43:03 +04:00
|
|
|
g_free (mc_skin__default.description);
|
2009-09-04 18:22:49 +04:00
|
|
|
mc_skin__default.description = NULL;
|
|
|
|
|
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 *
|
2010-11-08 13:21:45 +03:00
|
|
|
mc_skin_get (const gchar * group, const gchar * key, const gchar * default_value)
|
2009-10-15 11:31:24 +04:00
|
|
|
{
|
2010-11-08 13:21:45 +03:00
|
|
|
if (mc_args__ugly_line_drawing)
|
|
|
|
{
|
|
|
|
return g_strdup (default_value);
|
2009-10-15 11:31:24 +04: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
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------- */
|