3 /* local subsystem functions */
4 typedef struct _E_Theme_Result E_Theme_Result;
13 static Eina_Bool _e_theme_mappings_free_cb(const Eina_Hash *hash, const void *key, void *data, void *fdata);
14 static Eina_Bool _e_theme_mappings_quickfind_free_cb(const Eina_Hash *hash, const void *key, void *data, void *fdata);
15 static void _e_theme_category_register(const char *category);
16 static Eina_List *_e_theme_collection_item_register(Eina_List *list, const char *name);
17 static Eina_List *_e_theme_collection_items_find(const char *base, const char *collname);
20 /* local subsystem globals */
21 static Eina_Hash *mappings = NULL;
22 static Eina_Hash *group_cache = NULL;
24 static Eina_List *categories = NULL;
25 static Eina_List *transitions = NULL;
26 static Eina_List *borders = NULL;
27 static Eina_List *shelfs = NULL;
28 static Eina_List *comps = NULL;
29 static E_Fm2_Mime_Handler *theme_hdl = NULL;
31 /* externally accessible functions */
39 /* Register mime handler */
40 theme_hdl = e_fm2_mime_handler_new(_("Set As Theme"), "preferences-desktop-theme",
41 e_theme_handler_set, NULL,
42 e_theme_handler_test, NULL);
43 if (theme_hdl) e_fm2_mime_handler_glob_add(theme_hdl, "*.edj");
45 /* this is a fallback that is ALWAYS there - if all fails things will */
46 /* always fall back to the default theme. the rest after this are config */
47 /* values users can set */
48 e_theme_file_set("base", "default.edj");
50 EINA_LIST_FOREACH(e_config->themes, l, et)
54 snprintf(buf, sizeof(buf), "base/%s", et->category);
55 e_theme_file_set(buf, et->file);
58 /* Find transitions */
59 transitions = _e_theme_collection_items_find("base/theme/transitions", "e/transitions");
60 borders = _e_theme_collection_items_find("base/theme/borders", "e/widgets/border");
61 shelfs = _e_theme_collection_items_find("base/theme/shelf", "e/shelf");
62 comps = _e_theme_collection_items_find("base/theme/borders", "e/comp");
63 if (!mappings) mappings = eina_hash_string_superfast_new(NULL);
64 group_cache = eina_hash_string_superfast_new(NULL);
70 e_theme_shutdown(void)
76 e_fm2_mime_handler_glob_del(theme_hdl, "*.edj");
77 e_fm2_mime_handler_free(theme_hdl);
81 eina_hash_foreach(mappings, _e_theme_mappings_free_cb, NULL);
82 eina_hash_free(mappings);
87 eina_hash_free(group_cache);
90 EINA_LIST_FREE(categories, str)
91 eina_stringshare_del(str);
92 EINA_LIST_FREE(transitions, str)
93 eina_stringshare_del(str);
94 EINA_LIST_FREE(borders, str)
95 eina_stringshare_del(str);
96 EINA_LIST_FREE(shelfs, str)
97 eina_stringshare_del(str);
98 EINA_LIST_FREE(comps, str)
99 eina_stringshare_del(str);
104 e_theme_edje_object_set(Evas_Object *o, const char *category, const char *group)
110 /* find category -> edje mapping */
111 _e_theme_category_register(category);
112 res = eina_hash_find(mappings, category);
117 /* if found check cached path */
123 /* if its not an absolute path find it */
125 str = e_path_find(path_themes, str);
126 /* save cached value */
127 if (str) res->cache = str;
134 snprintf(buf, sizeof(buf), "%s/::/%s", str, group);
135 tres = eina_hash_find(group_cache, buf);
138 ok = edje_object_file_set(o, str, group);
139 /* save in the group cache hash */
141 eina_hash_add(group_cache, buf, res);
143 eina_hash_add(group_cache, buf, (void *)1);
145 else if (tres == (void *)1)
152 edje_object_file_set(o, str, group);
157 /* no mapping or set failed - fall back */
158 eina_strlcpy(buf, category, sizeof(buf));
159 /* shorten string up to and not including last / char */
160 p = strrchr(buf, '/');
162 /* no / anymore - we are already as far back as we can go */
164 /* try this category */
165 return e_theme_edje_object_set(o, buf, group);
169 _e_theme_edje_file_get(const char *category, const char *group, Eina_Bool fallback_icon)
176 /* find category -> edje mapping */
177 _e_theme_category_register(category);
178 res = eina_hash_find(mappings, category);
180 if (e_config->icon_theme &&
182 (!strcmp(category, "base")) &&
183 (!strncmp(group, "e/icons", 7)))
190 /* if found check cached path */
196 /* if its not an absolute path find it */
198 str = e_path_find(path_themes, str);
199 /* save cached value */
200 if (str) res->cache = str;
208 snprintf(buf, sizeof(buf), "%s/::/%s", str, group);
209 tres = eina_hash_find(group_cache, buf);
212 /* if the group exists - return */
217 res->quickfind = eina_hash_string_superfast_new(NULL);
218 /* create a quick find hash of all group entries */
219 coll = edje_file_collection_list(str);
221 EINA_LIST_FOREACH(coll, l, col)
223 q = eina_stringshare_add(col);
224 eina_hash_direct_add(res->quickfind, q, q);
226 if (coll) edje_file_collection_list_free(coll);
228 /* save in the group cache hash */
229 if (eina_hash_find(res->quickfind, group))
231 eina_hash_add(group_cache, buf, res);
236 eina_hash_add(group_cache, buf, (void *)1);
240 else if (tres == (void *)1) /* special pointer "1" == not there */
247 /* no mapping or set failed - fall back */
248 eina_strlcpy(buf, category, sizeof(buf));
249 /* shorten string up to and not including last / char */
250 p = strrchr(buf, '/');
252 /* no / anymore - we are already as far back as we can go */
254 /* try this category */
255 return e_theme_edje_file_get(buf, group);
259 e_theme_edje_file_get(const char *category, const char *group)
261 return _e_theme_edje_file_get(category, group, EINA_FALSE);
265 e_theme_edje_icon_fallback_file_get(const char *group)
267 return _e_theme_edje_file_get("base", group, EINA_TRUE);
271 * this is used to set the theme for a CATEGORY of E17. "base" is always set
272 * to the default theme - because if a selected theme wants "base/theme", but
273 * does not provide theme elements, it can fall back to the default theme.
275 * the idea is you can actually set a different theme for different parts of
278 * other possible categories...
279 * e_theme_file_set("base/theme/about", "default.edj");
280 * e_theme_file_set("base/theme/borders", "default.edj");
281 * e_theme_file_set("base/theme/background", "default.edj");
282 * e_theme_file_set("base/theme/configure", "default.edj");
283 * e_theme_file_set("base/theme/dialog", "default.edj");
284 * e_theme_file_set("base/theme/menus", "default.edj");
285 * e_theme_file_set("base/theme/error", "default.edj");
286 * e_theme_file_set("base/theme/gadman", "default.edj");
287 * e_theme_file_set("base/theme/dnd", "default.edj");
288 * e_theme_file_set("base/theme/icons", "default.edj");
289 * e_theme_file_set("base/theme/pointer", "default.edj");
290 * e_theme_file_set("base/theme/transitions", "default.edj");
291 * e_theme_file_set("base/theme/widgets", "default.edj");
292 * e_theme_file_set("base/theme/winlist", "default.edj");
293 * e_theme_file_set("base/theme/modules", "default.edj");
294 * e_theme_file_set("base/theme/modules/pager", "default.edj");
295 * e_theme_file_set("base/theme/modules/ibar", "default.edj");
296 * e_theme_file_set("base/theme/modules/ibox", "default.edj");
297 * e_theme_file_set("base/theme/modules/clock", "default.edj");
298 * e_theme_file_set("base/theme/modules/battery", "default.edj");
299 * e_theme_file_set("base/theme/modules/cpufreq", "default.edj");
300 * e_theme_file_set("base/theme/modules/start", "default.edj");
301 * e_theme_file_set("base/theme/modules/temperature", "default.edj");
305 e_theme_file_set(const char *category, const char *file)
311 eina_hash_free(group_cache);
314 _e_theme_category_register(category);
315 res = eina_hash_find(mappings, category);
318 eina_hash_del(mappings, category, res);
321 e_filereg_deregister(res->file);
322 eina_stringshare_del(res->file);
324 if (res->cache) eina_stringshare_del(res->cache);
327 res = E_NEW(E_Theme_Result, 1);
328 res->file = eina_stringshare_add(file);
329 e_filereg_register(res->file);
331 mappings = eina_hash_string_superfast_new(NULL);
332 eina_hash_add(mappings, category, res);
336 e_theme_config_set(const char *category, const char *file)
341 /* Don't accept unused categories */
343 if (!e_theme_category_find(category)) return 0;
346 /* search for the category */
347 EINA_LIST_FOREACH(e_config->themes, next, ect)
349 if (!strcmp(ect->category, category))
351 if (ect->file) eina_stringshare_del(ect->file);
352 ect->file = eina_stringshare_add(file);
357 /* the text class doesnt exist */
358 ect = E_NEW(E_Config_Theme, 1);
359 ect->category = eina_stringshare_add(category);
360 ect->file = eina_stringshare_add(file);
362 e_config->themes = eina_list_append(e_config->themes, ect);
367 * returns a pointer to the data, return null if nothing if found.
369 EAPI E_Config_Theme *
370 e_theme_config_get(const char *category)
372 E_Config_Theme *ect = NULL;
375 /* search for the category */
376 EINA_LIST_FOREACH(e_config->themes, next, ect)
378 if (!strcmp(ect->category, category))
385 e_theme_config_remove(const char *category)
390 /* search for the category */
391 EINA_LIST_FOREACH(e_config->themes, next, ect)
393 if (!strcmp(ect->category, category))
395 e_config->themes = eina_list_remove_list(e_config->themes, next);
396 if (ect->category) eina_stringshare_del(ect->category);
397 if (ect->file) eina_stringshare_del(ect->file);
406 e_theme_config_list(void)
408 return e_config->themes;
412 e_theme_category_find(const char *category)
414 if (eina_list_search_sorted(categories, EINA_COMPARE_CB(strcmp), category))
420 e_theme_category_list(void)
426 e_theme_transition_find(const char *transition)
428 if (eina_list_search_sorted(transitions, EINA_COMPARE_CB(strcmp), transition))
434 e_theme_transition_list(void)
440 e_theme_border_find(const char *border)
442 if (eina_list_search_sorted(borders, EINA_COMPARE_CB(strcmp), border))
448 e_theme_border_list(void)
454 e_theme_shelf_find(const char *shelf)
456 if (eina_list_search_sorted(shelfs, EINA_COMPARE_CB(strcmp), shelf))
462 e_theme_shelf_list(void)
468 e_theme_comp_find(const char *comp)
470 if (eina_list_search_sorted(comps, EINA_COMPARE_CB(strcmp), comp))
476 e_theme_comp_list(void)
482 e_theme_handler_set(Evas_Object *obj __UNUSED__, const char *path, void *data __UNUSED__)
490 /* if not in system dir or user dir, copy to user dir */
491 e_prefix_data_concat_static(buf, "data/themes");
492 if (!strncmp(buf, path, strlen(buf)))
496 e_user_dir_concat_static(buf, "themes");
497 if (!strncmp(buf, path, strlen(buf)))
505 file = ecore_file_file_get(path);
506 name = ecore_file_strip_ext(file);
508 e_user_dir_snprintf(buf, sizeof(buf), "themes/%s-%f.edj", name, ecore_time_unix_get());
511 if (!ecore_file_exists(buf))
513 ecore_file_cp(path, buf);
514 e_theme_config_set("theme", buf);
517 e_theme_config_set("theme", path);
520 e_theme_config_set("theme", path);
522 e_config_save_queue();
523 a = e_action_find("restart");
524 if ((a) && (a->func.go)) a->func.go(NULL, NULL);
528 e_theme_handler_test(Evas_Object *obj __UNUSED__, const char *path, void *data __UNUSED__)
531 if (!edje_file_group_exists(path, "e/widgets/border/default/border"))
536 /* local subsystem functions */
538 _e_theme_mappings_free_cb(const Eina_Hash *hash __UNUSED__, const void *key __UNUSED__, void *data, void *fdata __UNUSED__)
543 if (res->file) eina_stringshare_del(res->file);
544 if (res->cache) eina_stringshare_del(res->cache);
547 eina_hash_foreach(res->quickfind, _e_theme_mappings_quickfind_free_cb, NULL);
548 eina_hash_free(res->quickfind);
555 _e_theme_mappings_quickfind_free_cb(const Eina_Hash *hash __UNUSED__, const void *key, void *data __UNUSED__, void *fdata __UNUSED__)
557 eina_stringshare_del(key);
562 _e_theme_category_register(const char *category)
568 categories = eina_list_append(categories, eina_stringshare_add(category));
570 l = eina_list_search_sorted_near_list(categories, EINA_COMPARE_CB(strcmp),
576 categories = eina_list_append_relative_list(categories, eina_stringshare_add(category), l);
578 categories = eina_list_prepend_relative_list(categories, eina_stringshare_add(category), l);
582 _e_theme_collection_item_register(Eina_List *list, const char *name)
587 EINA_LIST_FOREACH(list, l, item)
589 if (!strcmp(name, item)) return list;
591 list = eina_list_append(list, eina_stringshare_add(name));
596 _e_theme_collection_items_find(const char *base, const char *collname)
598 Eina_List *list = NULL;
600 char *category, *p, *p2;
603 collname_len = strlen(collname);
604 category = alloca(strlen(base) + 1);
605 strcpy(category, base);
608 res = eina_hash_find(mappings, category);
613 /* if found check cached path */
619 /* if its not an absolute path find it */
620 if (str[0] != '/') str = e_path_find(path_themes, str);
621 /* save cached value */
622 if (str) res->cache = str;
628 coll = edje_file_collection_list(str);
633 EINA_LIST_FOREACH(coll, l, c)
635 if (!strncmp(c, collname, collname_len))
640 p = trans + collname_len + 1;
645 list = _e_theme_collection_item_register(list, p);
650 edje_file_collection_list_free(coll);
654 p = strrchr(category, '/');
659 list = eina_list_sort(list, 0, EINA_COMPARE_CB(strcmp));