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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
|
/*
* vim:ts=8:sw=3:sts=8:noexpandtab:cino=>5n-3f0^-2{2
*/
#include "e.h"
/* local subsystem functions */
typedef struct _E_Theme_Result E_Theme_Result;
struct _E_Theme_Result
{
char *file;
char *cache;
};
static Evas_Bool _e_theme_mappings_free_cb(Evas_Hash *hash, const char *key, void *data, void *fdata);
/* local subsystem globals */
static Evas_Hash *mappings = NULL;
static Evas_Hash *group_cache = NULL;
/* externally accessible functions */
int
e_theme_init(void)
{
Evas_List *l;
/* this is a fallback that is ALWAYS there - if all fails things will */
/* always fall back to the default theme. the rest after this are config */
/* values users can set */
e_theme_file_set("base", "default.edj");
for (l = e_config->themes; l; l = l->next)
{
E_Config_Theme *et;
char buf[256];
et = l->data;
snprintf(buf, sizeof(buf), "base/%s", et->category);
e_theme_file_set(buf, et->file);
}
/*
* this is used to sewt the theme for a CATEGORY of e17. "base" is always set
* to the default theme - because if a selected theme for lest say base/theme
* does not provide theme elements it can default back to the default theme.
*
* the idea is you can actually set a different theme for different parts of
* the desktop... :)
*
* other possible categories...
* e_theme_file_set("base/theme/borders", "default.edj");
* e_theme_file_set("base/theme/menus", "default.edj");
* e_theme_file_set("base/theme/error", "default.edj");
* e_theme_file_set("base/theme/gadman", "default.edj");
* e_theme_file_set("base/theme/dnd", "default.edj");
* e_theme_file_set("base/theme/modules", "default.edj");
* e_theme_file_set("base/theme/modules/pager", "default.edj");
* e_theme_file_set("base/theme/modules/ibar", "default.edj");
* e_theme_file_set("base/theme/modules/clock", "default.edj");
* e_theme_file_set("base/theme/modules/battery", "default.edj");
* e_theme_file_set("base/theme/modules/cpufreq", "default.edj");
* e_theme_file_set("base/theme/modules/temperature", "default.edj");
*/
return 1;
}
int
e_theme_shutdown(void)
{
if (mappings)
{
evas_hash_foreach(mappings, _e_theme_mappings_free_cb, NULL);
evas_hash_free(mappings);
mappings = NULL;
}
if (group_cache)
{
evas_hash_free(group_cache);
group_cache = NULL;
}
return 1;
}
int
e_theme_edje_object_set(Evas_Object *o, char *category, char *group)
{
E_Theme_Result *res;
char buf[256];
char *p;
/* find category -> edje mapping */
res = evas_hash_find(mappings, category);
if (res)
{
char *str;
/* if found check cached path */
str = res->cache;
if (!str)
{
/* no cached path */
str = res->file;
/* if its not an absolute path find it */
if (str[0] != '/')
str = e_path_find(path_themes, str);
/* save cached value */
if (str)
res->cache = strdup(str);
}
if (str)
{
void *tres;
int ok;
snprintf(buf, sizeof(buf), "%s/::/%s", str, group);
tres = evas_hash_find(group_cache, buf);
if (!tres)
{
ok = edje_object_file_set(o, str, group);
/* save in the group cache hash */
if (ok)
group_cache = evas_hash_add(group_cache, buf, res);
else
group_cache = evas_hash_add(group_cache, buf, (void *)1);
}
else if (tres == (void *)1)
ok = 0;
else
ok = 1;
if (ok)
{
if (tres)
edje_object_file_set(o, str, group);
return 1;
}
}
}
/* no mapping or set failed - fall back */
strncpy(buf, category, sizeof(buf) - 1);
buf[sizeof(buf) - 1] = 0;
/* shorten string up to and not including last / char */
p = strrchr(buf, '/');
if (p) *p = 0;
/* no / anymore - we are already as far back as we can go */
else return 0;
/* try this category */
return e_theme_edje_object_set(o, buf, group);
}
const char *
e_theme_edje_file_get(char *category, char *group)
{
E_Theme_Result *res;
char buf[4096];
char *p;
/* find category -> edje mapping */
res = evas_hash_find(mappings, category);
if (res)
{
char *str;
/* if found check cached path */
str = res->cache;
if (!str)
{
/* no cached path */
str = res->file;
/* if its not an absolute path find it */
if (str[0] != '/')
str = e_path_find(path_themes, str);
/* save cached value */
if (str)
res->cache = strdup(str);
}
if (str)
{
void *tres;
Evas_List *coll, *l;
int ok;
snprintf(buf, sizeof(buf), "%s/::/%s", str, group);
tres = evas_hash_find(group_cache, buf);
if (!tres)
{
/* if the group exists - return */
coll = edje_file_collection_list(str);
ok = 0;
for (l = coll; l; l = l->next)
{
if (!strcmp(l->data, group))
{
ok = 1;
break;
}
}
if (coll) edje_file_collection_list_free(coll);
/* save in the group cache hash */
if (ok)
group_cache = evas_hash_add(group_cache, buf, res);
else
group_cache = evas_hash_add(group_cache, buf, (void *)1);
}
else if (tres == (void *)1) /* special pointer "1" == not there */
ok = 0;
else
ok = 1;
if (ok) return str;
}
}
/* no mapping or set failed - fall back */
strncpy(buf, category, sizeof(buf) - 1);
buf[sizeof(buf) - 1] = 0;
/* shorten string up to and not including last / char */
p = strrchr(buf, '/');
if (p) *p = 0;
/* no / anymore - we are already as far back as we can go */
else return "";
/* try this category */
return e_theme_edje_file_get(buf, group);
}
void
e_theme_file_set(char *category, char *file)
{
E_Theme_Result *res;
if (group_cache)
{
evas_hash_free(group_cache);
group_cache = NULL;
}
res = evas_hash_find(mappings, category);
if (res)
{
mappings = evas_hash_del(mappings, category, res);
E_FREE(res->file);
E_FREE(res->cache);
free(res);
}
res = calloc(1, sizeof(E_Theme_Result));
res->file = strdup(file);
mappings = evas_hash_add(mappings, category, res);
}
void
e_theme_about(E_Zone *zone, const char *file)
{
static E_Popup *pop = NULL;
if (pop) return;
pop = e_popup_new(zone, zone->w / 2, zone->h / 2, 1, 1);
e_popup_show(pop);
}
/* local subsystem functions */
static Evas_Bool
_e_theme_mappings_free_cb(Evas_Hash *hash, const char *key, void *data, void *fdata)
{
E_Theme_Result *res;
res = data;
E_FREE(res->file);
E_FREE(res->cache);
free(res);
return 1;
}
|