5 Copyright (C) 2009, 2010 The Free Software Foundation, Inc.
8 Slava Zanko <slavazanko@gmail.com>, 2009
9 Egmont Koblinger <egmont@gmail.com>, 2010
11 This file is part of the Midnight Commander.
13 The Midnight Commander is free software; you can redistribute it
14 and/or modify it under the terms of the GNU General Public License as
15 published by the Free Software Foundation; either version 2 of the
16 License, or (at your option) any later version.
18 The Midnight Commander is distributed in the hope that it will be
19 useful, but WITHOUT ANY WARRANTY; without even the implied warranty
20 of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 General Public License for more details.
23 You should have received a copy of the GNU General Public License
24 along with this program; if not, write to the Free Software
25 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
34 #include "lib/tty/color.h" /* tty_use_256colors(); */
38 /*** global variables ****************************************************************************/
40 mc_skin_t mc_skin__default
;
42 /*** file scope macro definitions ****************************************************************/
44 /*** file scope type declarations ****************************************************************/
46 /*** file scope variables ************************************************************************/
48 static gboolean mc_skin_is_init
= FALSE
;
50 /* --------------------------------------------------------------------------------------------- */
51 /*** file scope functions ************************************************************************/
52 /* --------------------------------------------------------------------------------------------- */
55 mc_skin_hash_destroy_value (gpointer data
)
57 mc_skin_color_t
*mc_skin_color
= (mc_skin_color_t
*) data
;
58 g_free (mc_skin_color
->fgcolor
);
59 g_free (mc_skin_color
->bgcolor
);
60 g_free (mc_skin_color
->attrs
);
61 g_free (mc_skin_color
);
64 /* --------------------------------------------------------------------------------------------- */
67 mc_skin_get_default_name (void)
71 /* from command line */
72 if (mc_args__skin
!= NULL
)
73 return g_strdup (mc_args__skin
);
75 /* from envirovement variable */
76 tmp_str
= getenv ("MC_SKIN");
78 return g_strdup (tmp_str
);
80 /* from config. Or 'default' if no present in config */
81 return mc_config_get_string (mc_main_config
, CONFIG_APP_SECTION
, "skin", "default");
84 /* --------------------------------------------------------------------------------------------- */
90 mc_skin__default
.name
= mc_skin_get_default_name ();
91 mc_skin__default
.colors
= g_hash_table_new_full (g_str_hash
, g_str_equal
,
92 g_free
, mc_skin_hash_destroy_value
);
95 /* --------------------------------------------------------------------------------------------- */
98 mc_skin_try_to_load_default (void)
101 g_free (mc_skin__default
.name
);
102 mc_skin__default
.name
= g_strdup ("default");
103 if (!mc_skin_ini_file_load (&mc_skin__default
))
106 mc_skin_set_hardcoded_skin (&mc_skin__default
);
111 /* --------------------------------------------------------------------------------------------- */
112 /*** public functions ****************************************************************************/
113 /* --------------------------------------------------------------------------------------------- */
116 mc_skin_init (GError
** error
)
118 gboolean is_good_init
= TRUE
;
120 mc_skin__default
.have_256_colors
= FALSE
;
122 mc_skin__default
.name
= mc_skin_get_default_name ();
124 mc_skin__default
.colors
= g_hash_table_new_full (g_str_hash
, g_str_equal
,
125 g_free
, mc_skin_hash_destroy_value
);
126 if (!mc_skin_ini_file_load (&mc_skin__default
))
128 *error
= g_error_new (MC_ERROR
, 0,
129 _("Unable to load '%s' skin.\nDefault skin has been loaded"),
130 mc_skin__default
.name
);
132 mc_skin_try_to_load_default ();
133 is_good_init
= FALSE
;
135 mc_skin_colors_old_configure (&mc_skin__default
);
137 if (!mc_skin_ini_file_parse (&mc_skin__default
))
140 *error
= g_error_new (MC_ERROR
, 0,
141 _("Unable to parse '%s' skin.\nDefault skin has been loaded"),
142 mc_skin__default
.name
);
144 mc_skin_try_to_load_default ();
145 mc_skin_colors_old_configure (&mc_skin__default
);
146 (void) mc_skin_ini_file_parse (&mc_skin__default
);
147 is_good_init
= FALSE
;
149 if ( is_good_init
&& !tty_use_256colors () && mc_skin__default
.have_256_colors
)
152 *error
= g_error_new (MC_ERROR
, 0,
154 ("Unable to use '%s' skin with 256 colors support\non non-256 colors terminal.\nDefault skin has been loaded"),
155 mc_skin__default
.name
);
157 mc_skin_try_to_load_default ();
158 mc_skin_colors_old_configure (&mc_skin__default
);
159 (void) mc_skin_ini_file_parse (&mc_skin__default
);
160 is_good_init
= FALSE
;
162 mc_skin_is_init
= TRUE
;
166 /* --------------------------------------------------------------------------------------------- */
169 mc_skin_deinit (void)
171 g_free (mc_skin__default
.name
);
172 mc_skin__default
.name
= NULL
;
173 g_hash_table_destroy (mc_skin__default
.colors
);
174 mc_skin__default
.colors
= NULL
;
176 g_free (mc_skin__default
.description
);
177 mc_skin__default
.description
= NULL
;
179 mc_config_deinit (mc_skin__default
.config
);
180 mc_skin__default
.config
= NULL
;
182 mc_skin_is_init
= FALSE
;
185 /* --------------------------------------------------------------------------------------------- */
188 mc_skin_get (const gchar
* group
, const gchar
* key
, const gchar
* default_value
)
190 if (mc_args__ugly_line_drawing
)
192 return g_strdup (default_value
);
194 return mc_config_get_string (mc_skin__default
.config
, group
, key
, default_value
);
197 /* --------------------------------------------------------------------------------------------- */