This source file includes following definitions.
- mc_skin_get_list_from_dir
- string_array_comparator
- mc_skin_ini_file_load_search_in_dir
- mc_skin_list
- mc_skin_ini_file_load
- mc_skin_ini_file_parse
- mc_skin_set_hardcoded_skin
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 #include <config.h>
28
29 #include <string.h>
30
31 #include "lib/global.h"
32
33 #include "internal.h"
34 #include "lib/fileloc.h"
35 #include "lib/util.h"
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51 static void
52 mc_skin_get_list_from_dir (const gchar *base_dir, GPtrArray *list)
53 {
54 gchar *name;
55 GDir *dir;
56
57 name = g_build_filename (base_dir, MC_SKINS_DIR, (char *) NULL);
58 dir = g_dir_open (name, 0, NULL);
59 g_free (name);
60
61 if (dir != NULL)
62 {
63 const gchar *cname;
64
65 while ((cname = g_dir_read_name (dir)) != NULL)
66 {
67 gchar *sname;
68 size_t slen;
69 unsigned int i;
70
71 slen = strlen (cname);
72 sname = g_strndup (cname, slen);
73
74 if (slen > 4 && strcmp (sname + slen - 4, ".ini") == 0)
75 sname[slen - 4] = '\0';
76
77 for (i = 0; i < list->len; i++)
78 if (strcmp (sname, g_ptr_array_index (list, i)) == 0)
79 break;
80
81 if (i < list->len)
82 g_free (sname);
83 else
84 g_ptr_array_add (list, sname);
85 }
86
87 g_dir_close (dir);
88 }
89 }
90
91
92
93 static int
94 string_array_comparator (gconstpointer a, gconstpointer b)
95 {
96 return strcmp (*(char *const *) a, *(char *const *) b);
97 }
98
99
100
101 static gboolean
102 mc_skin_ini_file_load_search_in_dir (mc_skin_t *mc_skin, const gchar *base_dir)
103 {
104 char *file_name, *file_name2;
105
106 file_name = g_build_filename (base_dir, MC_SKINS_DIR, mc_skin->name, (char *) NULL);
107 if (exist_file (file_name))
108 {
109 mc_skin->config = mc_config_init (file_name, TRUE);
110 g_free (file_name);
111 return (mc_skin->config != NULL);
112 }
113 g_free (file_name);
114
115 file_name2 = g_strdup_printf ("%s.ini", mc_skin->name);
116 file_name = g_build_filename (base_dir, MC_SKINS_DIR, file_name2, (char *) NULL);
117 g_free (file_name2);
118
119 if (exist_file (file_name))
120 {
121 mc_skin->config = mc_config_init (file_name, TRUE);
122 g_free (file_name);
123 return (mc_skin->config != NULL);
124 }
125 g_free (file_name);
126 return FALSE;
127 }
128
129
130
131
132
133 GPtrArray *
134 mc_skin_list (void)
135 {
136 GPtrArray *list;
137
138 list = g_ptr_array_new_with_free_func (g_free);
139 mc_skin_get_list_from_dir (mc_config_get_data_path (), list);
140 mc_skin_get_list_from_dir (mc_global.sysconfig_dir, list);
141 mc_skin_get_list_from_dir (mc_global.share_data_dir, list);
142 g_ptr_array_sort (list, (GCompareFunc) string_array_comparator);
143
144 return list;
145 }
146
147
148
149 gboolean
150 mc_skin_ini_file_load (mc_skin_t *mc_skin)
151 {
152 char *file_name;
153
154 file_name = g_path_get_basename (mc_skin->name);
155 if (file_name == NULL)
156 return FALSE;
157
158 if (strcmp (file_name, mc_skin->name) != 0)
159 {
160 g_free (file_name);
161 if (!g_path_is_absolute (mc_skin->name))
162 return FALSE;
163 mc_skin->config = mc_config_init (mc_skin->name, TRUE);
164 return (mc_skin->config != NULL);
165 }
166 g_free (file_name);
167
168
169 if (mc_skin_ini_file_load_search_in_dir (mc_skin, mc_config_get_data_path ()))
170 return TRUE;
171
172
173 if (mc_skin_ini_file_load_search_in_dir (mc_skin, mc_global.sysconfig_dir))
174 return TRUE;
175
176
177 return mc_skin_ini_file_load_search_in_dir (mc_skin, mc_global.share_data_dir);
178 }
179
180
181
182 gboolean
183 mc_skin_ini_file_parse (mc_skin_t *mc_skin)
184 {
185 mc_skin->description =
186 mc_config_get_string (mc_skin->config, "skin", "description", "- no description -");
187 if (!mc_skin_color_parse_ini_file (mc_skin))
188 return FALSE;
189
190 mc_skin_lines_parse_ini_file (mc_skin);
191 mc_skin->have_256_colors = mc_config_get_bool (mc_skin->config, "skin", "256colors", FALSE);
192 mc_skin->have_true_colors = mc_config_get_bool (mc_skin->config, "skin", "truecolors", FALSE);
193
194 return TRUE;
195 }
196
197
198
199 void
200 mc_skin_set_hardcoded_skin (mc_skin_t *mc_skin)
201 {
202 mc_skin->config = mc_config_init (NULL, TRUE);
203
204 mc_config_set_string (mc_skin->config, "skin", "description", "hardcoded skin");
205
206 mc_skin_hardcoded_ugly_lines (mc_skin);
207 mc_skin_hardcoded_blackwhite_colors (mc_skin);
208 }
209
210