2009-09-04 18:22:49 +04:00
|
|
|
/*
|
|
|
|
Skins engine.
|
2009-09-10 16:14:18 +04:00
|
|
|
Reading and parse ini-files
|
2009-09-04 18:22:49 +04:00
|
|
|
|
|
|
|
Copyright (C) 2009 The Free Software Foundation, Inc.
|
|
|
|
|
|
|
|
Written by:
|
|
|
|
Slava Zanko <slavazanko@gmail.com>, 2009.
|
|
|
|
|
|
|
|
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 <string.h>
|
|
|
|
|
|
|
|
#include "internal.h"
|
2010-01-21 16:06:15 +03:00
|
|
|
#include "lib/fileloc.h"
|
2010-11-11 16:58:29 +03:00
|
|
|
#include "lib/util.h" /* exist_file() */
|
2010-01-21 16:06:15 +03:00
|
|
|
|
|
|
|
#include "src/main.h"
|
|
|
|
|
2009-09-04 18:22:49 +04:00
|
|
|
/*** global variables ****************************************************************************/
|
|
|
|
|
|
|
|
/*** file scope macro definitions ****************************************************************/
|
|
|
|
|
|
|
|
/*** file scope type declarations ****************************************************************/
|
|
|
|
|
|
|
|
/*** file scope variables ************************************************************************/
|
|
|
|
|
|
|
|
/*** file scope functions ************************************************************************/
|
2010-11-08 21:50:15 +03:00
|
|
|
|
2009-09-04 18:22:49 +04:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
static gboolean
|
2009-09-14 17:43:03 +04:00
|
|
|
mc_skin_ini_file_load_search_in_dir (mc_skin_t * mc_skin, const gchar * base_dir)
|
2009-09-04 18:22:49 +04:00
|
|
|
{
|
|
|
|
char *file_name, *file_name2;
|
|
|
|
|
2009-10-05 18:32:46 +04:00
|
|
|
file_name = g_build_filename (base_dir, MC_SKINS_SUBDIR, mc_skin->name, NULL);
|
2010-11-08 13:21:45 +03:00
|
|
|
if (exist_file (file_name))
|
|
|
|
{
|
2009-09-14 17:43:03 +04:00
|
|
|
mc_skin->config = mc_config_init (file_name);
|
|
|
|
g_free (file_name);
|
|
|
|
return (mc_skin->config != NULL);
|
2009-09-04 18:22:49 +04:00
|
|
|
}
|
2009-09-14 17:43:03 +04:00
|
|
|
g_free (file_name);
|
2009-09-04 18:22:49 +04:00
|
|
|
|
2009-09-14 17:43:03 +04:00
|
|
|
file_name2 = g_strdup_printf ("%s.ini", mc_skin->name);
|
2009-10-05 18:32:46 +04:00
|
|
|
file_name = g_build_filename (base_dir, MC_SKINS_SUBDIR, file_name2, NULL);
|
2009-09-14 17:43:03 +04:00
|
|
|
g_free (file_name2);
|
|
|
|
|
2010-11-08 13:21:45 +03:00
|
|
|
if (exist_file (file_name))
|
|
|
|
{
|
2009-09-14 17:43:03 +04:00
|
|
|
mc_skin->config = mc_config_init (file_name);
|
|
|
|
g_free (file_name);
|
|
|
|
return (mc_skin->config != NULL);
|
2009-09-04 18:22:49 +04:00
|
|
|
}
|
2009-09-14 17:43:03 +04:00
|
|
|
g_free (file_name);
|
2009-09-04 18:22:49 +04:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
/*** public functions ****************************************************************************/
|
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
gboolean
|
2009-09-14 17:43:03 +04:00
|
|
|
mc_skin_ini_file_load (mc_skin_t * mc_skin)
|
2009-09-04 18:22:49 +04:00
|
|
|
{
|
2010-12-29 18:12:59 +03:00
|
|
|
char *file_name;
|
2009-09-04 18:22:49 +04:00
|
|
|
|
2009-09-14 17:43:03 +04:00
|
|
|
file_name = g_path_get_basename (mc_skin->name);
|
2010-06-21 21:32:51 +04:00
|
|
|
if (file_name == NULL)
|
|
|
|
return FALSE;
|
2009-09-14 17:43:03 +04:00
|
|
|
|
2010-11-08 13:21:45 +03:00
|
|
|
if (strcmp (file_name, mc_skin->name) != 0)
|
|
|
|
{
|
2009-09-14 17:43:03 +04:00
|
|
|
g_free (file_name);
|
|
|
|
if (!g_path_is_absolute (mc_skin->name))
|
|
|
|
return FALSE;
|
|
|
|
mc_skin->config = mc_config_init (mc_skin->name);
|
|
|
|
return (mc_skin->config != NULL);
|
2009-09-04 18:22:49 +04:00
|
|
|
}
|
2009-09-14 17:43:03 +04:00
|
|
|
g_free (file_name);
|
2009-09-04 18:22:49 +04:00
|
|
|
|
2010-12-30 22:10:20 +03:00
|
|
|
/* ${XDG_DATA_HOME}/mc/skins/ */
|
2010-12-29 18:12:59 +03:00
|
|
|
if (mc_skin_ini_file_load_search_in_dir (mc_skin, mc_config_get_data_path ()))
|
2010-11-08 21:58:19 +03:00
|
|
|
return TRUE;
|
2009-09-04 18:22:49 +04:00
|
|
|
|
|
|
|
/* /etc/mc/skins/ */
|
2010-12-30 13:35:33 +03:00
|
|
|
if (mc_skin_ini_file_load_search_in_dir (mc_skin, mc_sysconfig_dir))
|
2009-09-14 17:43:03 +04:00
|
|
|
return TRUE;
|
2009-09-04 18:22:49 +04:00
|
|
|
|
|
|
|
/* /usr/share/mc/skins/ */
|
2010-12-30 13:35:33 +03:00
|
|
|
return mc_skin_ini_file_load_search_in_dir (mc_skin, mc_share_data_dir);
|
2009-09-04 18:22:49 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
gboolean
|
2009-09-14 17:43:03 +04:00
|
|
|
mc_skin_ini_file_parse (mc_skin_t * mc_skin)
|
2009-09-04 18:22:49 +04:00
|
|
|
{
|
2009-09-14 17:43:03 +04:00
|
|
|
mc_skin->description =
|
|
|
|
mc_config_get_string (mc_skin->config, "skin", "description", "- no description -");
|
|
|
|
if (!mc_skin_color_parse_ini_file (mc_skin))
|
|
|
|
return FALSE;
|
2009-09-04 18:22:49 +04:00
|
|
|
|
2009-09-14 17:43:03 +04:00
|
|
|
mc_skin_lines_parse_ini_file (mc_skin);
|
2009-09-09 18:56:52 +04:00
|
|
|
|
2009-09-04 18:22:49 +04:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
void
|
2009-09-14 17:43:03 +04:00
|
|
|
mc_skin_set_hardcoded_skin (mc_skin_t * mc_skin)
|
2009-09-04 18:22:49 +04:00
|
|
|
{
|
2009-09-14 17:43:03 +04:00
|
|
|
mc_skin->config = mc_config_init (NULL);
|
2009-09-04 18:22:49 +04:00
|
|
|
|
2009-09-14 17:43:03 +04:00
|
|
|
mc_config_set_string (mc_skin->config, "skin", "description", "hardcoded skin");
|
2009-09-04 18:22:49 +04:00
|
|
|
|
2009-09-14 17:43:03 +04:00
|
|
|
mc_skin_hardcoded_ugly_lines (mc_skin);
|
|
|
|
mc_skin_hardcoded_blackwhite_colors (mc_skin);
|
2009-09-04 18:22:49 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------- */
|