From 197d5efa28318409b2f69a6f25021b86a5e4a0f0 Mon Sep 17 00:00:00 2001 From: Slava Zanko Date: Mon, 28 Sep 2009 17:04:25 +0300 Subject: [PATCH] Ticket #380: About colors schemes (reopened ticket) Original message: If invalid skin name is set via command line (or config file, or environment variable), then mc starts silently like -b -a mode. Two proposals, if required skin cannot be found: *. Show error message "Cannot find skin" *. Load the default.ini skin instead of set -a -c mode. Fix issue: Mc now more verbose if skin not found: {{{ _("Unable to load '%s' skin.\nDefault skin has been loaded") }}} or if skin not parse: {{{ _("Unable to parse '%s' skin.\nDefault skin has been loaded") }}} Translators: please, update your translates. Also, mc will try to load 'default' skin before switch to 'b&w' scheme. This commit adds ability to usage GError - glib error handling. Signed-off-by: Slava Zanko --- src/Makefile.am | 3 ++- src/global.h | 3 +++ src/main.c | 19 +++++++++++++++++- src/skin/common.c | 51 +++++++++++++++++++++++++++++++++++++---------- src/skin/skin.h | 2 +- 5 files changed, 64 insertions(+), 14 deletions(-) diff --git a/src/Makefile.am b/src/Makefile.am index 47074b3d2..e1f3e7211 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -15,7 +15,8 @@ AM_CPPFLAGS = -DDATADIR=\""$(pkgdatadir)/"\" -DLOCALEDIR=\""$(localedir)"\" \ else AM_CPPFLAGS = -DDATADIR=\""$(pkgdatadir)/"\" \ -DLOCALEDIR=\""$(localedir)"\" \ - -DSYSCONFDIR=\""$(sysconfdir)/@PACKAGE@/"\" + -DSYSCONFDIR=\""$(sysconfdir)/@PACKAGE@/"\" \ + -DPACKAGE=\""@PACKAGE@\" endif noinst_PROGRAMS = man2hlp diff --git a/src/global.h b/src/global.h index d8bfc9a67..fcf07c3db 100644 --- a/src/global.h +++ b/src/global.h @@ -149,4 +149,7 @@ void refresh_screen (void *); #include #endif +#define MC_ERROR mc_main_error_quark () +GQuark mc_main_error_quark (void); + #endif diff --git a/src/main.c b/src/main.c index 9805e403a..2ebd1345c 100644 --- a/src/main.c +++ b/src/main.c @@ -294,6 +294,14 @@ char *mc_home_alt = NULL; char cmd_buf[512]; +/* Define this function for glib-style error handling */ +GQuark +mc_main_error_quark (void) +{ + return g_quark_from_static_string (PACKAGE); +} + + /* Save current stat of directories to avoid reloading the panels */ /* when no modifications have taken place */ void @@ -1903,6 +1911,8 @@ main (int argc, char *argv[]) { struct stat s; char *mc_dir; + GError *error = NULL; + gboolean isInitialized; /* We had LC_CTYPE before, LC_ALL includs LC_TYPE as well */ setlocale (LC_ALL, ""); @@ -1961,11 +1971,18 @@ main (int argc, char *argv[]) tty_init_colors (mc_args__disable_colors, mc_args__force_colors); - mc_skin_init(); + isInitialized = mc_skin_init(&error); + mc_filehighlight = mc_fhl_new (TRUE); dlg_set_default_colors (); + if ( ! isInitialized ) { + message (D_ERROR, _("Warning"), error->message); + g_error_free(error); + error = NULL; + } + /* create home directory */ /* do it after the screen library initialization to show the error message */ mc_dir = concat_dir_and_file (home_dir, MC_BASE); diff --git a/src/skin/common.c b/src/skin/common.c index 9545a36b4..2de791e14 100644 --- a/src/skin/common.c +++ b/src/skin/common.c @@ -98,31 +98,60 @@ mc_skin_reinit (void) mc_skin_hash_destroy_value); } -/* --------------------------------------------------------------------------------------------- */ -/*** public functions ****************************************************************************/ /* --------------------------------------------------------------------------------------------- */ -void -mc_skin_init (void) +static void +mc_skin_try_to_load_default (void) { - mc_skin__default.name = mc_skin_get_default_name (); - mc_skin__default.colors = g_hash_table_new_full (g_str_hash, g_str_equal, - mc_skin_hash_destroy_key, - mc_skin_hash_destroy_value); - + mc_skin_reinit (); + g_free (mc_skin__default.name); + mc_skin__default.name = g_strdup ("default"); if (!mc_skin_ini_file_load (&mc_skin__default)) { mc_skin_reinit (); mc_skin_set_hardcoded_skin (&mc_skin__default); } + +} + +/* --------------------------------------------------------------------------------------------- */ +/*** public functions ****************************************************************************/ +/* --------------------------------------------------------------------------------------------- */ + +gboolean +mc_skin_init (GError ** error) +{ + + mc_skin__default.name = mc_skin_get_default_name (); + + mc_skin__default.colors = g_hash_table_new_full (g_str_hash, g_str_equal, + mc_skin_hash_destroy_key, + mc_skin_hash_destroy_value); + + gboolean is_good_init = TRUE; + + if (!mc_skin_ini_file_load (&mc_skin__default)) { + *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; + } mc_skin_colors_old_configure (&mc_skin__default); if (!mc_skin_ini_file_parse (&mc_skin__default)) { - mc_skin_reinit (); - mc_skin_set_hardcoded_skin (&mc_skin__default); + 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 (); mc_skin_colors_old_configure (&mc_skin__default); (void) mc_skin_ini_file_parse (&mc_skin__default); + is_good_init = FALSE; } mc_skin_is_init = TRUE; + return is_good_init; } /* --------------------------------------------------------------------------------------------- */ diff --git a/src/skin/skin.h b/src/skin/skin.h index 11412096c..f152bc6ca 100644 --- a/src/skin/skin.h +++ b/src/skin/skin.h @@ -85,7 +85,7 @@ extern mc_skin_t mc_skin__default; /*** declarations of public functions ************************************************************/ -void mc_skin_init (void); +gboolean mc_skin_init (GError **); void mc_skin_deinit (void); int mc_skin_color_get (const gchar *, const gchar *);