This source file includes following definitions.
- mc_skin_hash_destroy_value
- mc_skin_get_default_name
- mc_skin_reinit
- mc_skin_try_to_load_default
- mc_skin_init
- mc_skin_deinit
- mc_skin_get
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28 #include <config.h>
29 #include <stdlib.h>
30
31 #include "internal.h"
32 #include "lib/util.h"
33
34 #include "lib/tty/color.h"
35
36
37
38 mc_skin_t mc_skin__default;
39
40
41
42
43
44
45
46
47
48 static gboolean mc_skin_is_init = FALSE;
49
50
51
52
53
54 static void
55 mc_skin_hash_destroy_value (gpointer data)
56 {
57 tty_color_pair_t *mc_skin_color = (tty_color_pair_t *) data;
58
59 g_free (mc_skin_color->fg);
60 g_free (mc_skin_color->bg);
61 g_free (mc_skin_color->attrs);
62 g_free (mc_skin_color);
63 }
64
65
66
67 static char *
68 mc_skin_get_default_name (void)
69 {
70 char *tmp_str;
71
72
73 if (mc_global.tty.skin != NULL)
74 return g_strdup (mc_global.tty.skin);
75
76
77 tmp_str = getenv ("MC_SKIN");
78 if (tmp_str != NULL)
79 return g_strdup (tmp_str);
80
81
82 return mc_config_get_string (mc_global.main_config, CONFIG_APP_SECTION, "skin", "default");
83 }
84
85
86
87 static void
88 mc_skin_reinit (void)
89 {
90 mc_skin_deinit ();
91 mc_skin__default.name = mc_skin_get_default_name ();
92 mc_skin__default.colors = g_hash_table_new_full (g_str_hash, g_str_equal,
93 g_free, mc_skin_hash_destroy_value);
94 }
95
96
97
98 static void
99 mc_skin_try_to_load_default (void)
100 {
101 mc_skin_reinit ();
102 g_free (mc_skin__default.name);
103 mc_skin__default.name = g_strdup ("default");
104 if (!mc_skin_ini_file_load (&mc_skin__default))
105 {
106 mc_skin_reinit ();
107 mc_skin_set_hardcoded_skin (&mc_skin__default);
108 }
109 }
110
111
112
113
114
115 gboolean
116 mc_skin_init (const gchar *skin_override, GError **mcerror)
117 {
118 gboolean is_good_init = TRUE;
119 GError *error = NULL;
120
121 mc_return_val_if_error (mcerror, FALSE);
122
123 mc_skin__default.have_256_colors = FALSE;
124 mc_skin__default.have_true_colors = FALSE;
125
126 mc_skin__default.name =
127 skin_override != NULL ? g_strdup (skin_override) : mc_skin_get_default_name ();
128
129 mc_skin__default.colors = g_hash_table_new_full (g_str_hash, g_str_equal,
130 g_free, mc_skin_hash_destroy_value);
131 if (!mc_skin_ini_file_load (&mc_skin__default))
132 {
133 mc_propagate_error (mcerror, 0,
134 _("Unable to load '%s' skin.\nDefault skin has been loaded"),
135 mc_skin__default.name);
136 mc_skin_try_to_load_default ();
137 is_good_init = FALSE;
138 }
139 mc_skin_colors_old_configure (&mc_skin__default);
140
141 if (!mc_skin_ini_file_parse (&mc_skin__default))
142 {
143 mc_propagate_error (mcerror, 0,
144 _("Unable to parse '%s' skin.\nDefault skin has been loaded"),
145 mc_skin__default.name);
146
147 mc_skin_try_to_load_default ();
148 mc_skin_colors_old_configure (&mc_skin__default);
149 (void) mc_skin_ini_file_parse (&mc_skin__default);
150 is_good_init = FALSE;
151 }
152 if (is_good_init && mc_skin__default.have_true_colors && !tty_use_truecolors (&error))
153 {
154 mc_propagate_error (mcerror, 0,
155 _
156 ("Unable to use '%s' skin with true colors support:\n%s\nDefault skin has been loaded"),
157 mc_skin__default.name, error->message);
158 g_error_free (error);
159 mc_skin_try_to_load_default ();
160 mc_skin_colors_old_configure (&mc_skin__default);
161 (void) mc_skin_ini_file_parse (&mc_skin__default);
162 is_good_init = FALSE;
163 }
164 if (is_good_init && mc_skin__default.have_256_colors && !tty_use_256colors (&error))
165 {
166 mc_propagate_error (mcerror, 0,
167 _
168 ("Unable to use '%s' skin with 256 colors support\non non-256 colors terminal.\nDefault skin has been loaded"),
169 mc_skin__default.name);
170 mc_skin_try_to_load_default ();
171 mc_skin_colors_old_configure (&mc_skin__default);
172 (void) mc_skin_ini_file_parse (&mc_skin__default);
173 is_good_init = FALSE;
174 }
175 mc_skin_is_init = TRUE;
176 return is_good_init;
177 }
178
179
180
181 void
182 mc_skin_deinit (void)
183 {
184 tty_color_free_all ();
185
186 MC_PTR_FREE (mc_skin__default.name);
187 g_hash_table_destroy (mc_skin__default.colors);
188 mc_skin__default.colors = NULL;
189
190 MC_PTR_FREE (mc_skin__default.description);
191
192 mc_config_deinit (mc_skin__default.config);
193 mc_skin__default.config = NULL;
194
195 mc_skin_is_init = FALSE;
196 }
197
198
199
200 gchar *
201 mc_skin_get (const gchar *group, const gchar *key, const gchar *default_value)
202 {
203 if (mc_global.tty.ugly_line_drawing)
204 return g_strdup (default_value);
205
206 return mc_config_get_string (mc_skin__default.config, group, key, default_value);
207 }
208
209