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 <slavazanko@gmail.com>
This commit is contained in:
Slava Zanko 2009-09-28 17:04:25 +03:00
parent 4ea55c0b93
commit 197d5efa28
5 changed files with 64 additions and 14 deletions

View File

@ -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

View File

@ -149,4 +149,7 @@ void refresh_screen (void *);
#include <assert.h>
#endif
#define MC_ERROR mc_main_error_quark ()
GQuark mc_main_error_quark (void);
#endif

View File

@ -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);

View File

@ -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;
}
/* --------------------------------------------------------------------------------------------- */

View File

@ -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 *);