* e_theme: Cleanup and use sorted list for faster looking.

SVN revision: 39551
This commit is contained in:
Cedric BAIL 2009-03-18 16:49:20 +00:00
parent 15b8d85967
commit 1ef42062db
1 changed files with 55 additions and 73 deletions

View File

@ -35,6 +35,7 @@ static E_Fm2_Mime_Handler *theme_hdl = NULL;
EAPI int EAPI int
e_theme_init(void) e_theme_init(void)
{ {
E_Config_Theme *et;
Eina_List *l = NULL; Eina_List *l = NULL;
/* Register mime handler */ /* Register mime handler */
@ -47,13 +48,11 @@ e_theme_init(void)
/* always fall back to the default theme. the rest after this are config */ /* always fall back to the default theme. the rest after this are config */
/* values users can set */ /* values users can set */
e_theme_file_set("base", "default.edj"); e_theme_file_set("base", "default.edj");
for (l = e_config->themes; l; l = l->next) EINA_LIST_FOREACH(e_config->themes, l, et)
{ {
E_Config_Theme *et;
char buf[256]; char buf[256];
et = l->data;
snprintf(buf, sizeof(buf), "base/%s", et->category); snprintf(buf, sizeof(buf), "base/%s", et->category);
e_theme_file_set(buf, et->file); e_theme_file_set(buf, et->file);
} }
@ -72,6 +71,8 @@ e_theme_init(void)
EAPI int EAPI int
e_theme_shutdown(void) e_theme_shutdown(void)
{ {
const char *str;
if (theme_hdl) if (theme_hdl)
{ {
e_fm2_mime_handler_glob_del(theme_hdl, "*.edj"); e_fm2_mime_handler_glob_del(theme_hdl, "*.edj");
@ -88,26 +89,14 @@ e_theme_shutdown(void)
eina_hash_free(group_cache); eina_hash_free(group_cache);
group_cache = NULL; group_cache = NULL;
} }
while (categories) EINA_LIST_FREE(categories, str)
{ eina_stringshare_del(str);
eina_stringshare_del(categories->data); EINA_LIST_FREE(transitions, str)
categories = eina_list_remove_list(categories, categories); eina_stringshare_del(str);
} EINA_LIST_FREE(borders, str)
while (transitions) eina_stringshare_del(str);
{ EINA_LIST_FREE(shelfs, str)
eina_stringshare_del(transitions->data); eina_stringshare_del(str);
transitions = eina_list_remove_list(transitions, transitions);
}
while (borders)
{
eina_stringshare_del(borders->data);
borders = eina_list_remove_list(borders, borders);
}
while (shelfs)
{
eina_stringshare_del(shelfs->data);
shelfs = eina_list_remove_list(shelfs, shelfs);
}
return 1; return 1;
} }
@ -216,12 +205,14 @@ e_theme_edje_file_get(const char *category, const char *group)
/* if the group exists - return */ /* if the group exists - return */
if (!res->quickfind) if (!res->quickfind)
{ {
const char *col;
res->quickfind = eina_hash_string_superfast_new(NULL); res->quickfind = eina_hash_string_superfast_new(NULL);
/* great a quick find hash of all group entires */ /* great a quick find hash of all group entires */
coll = edje_file_collection_list(str); coll = edje_file_collection_list(str);
for (l = coll; l; l = l->next) EINA_LIST_FOREACH(coll, l, col)
{ {
q = eina_stringshare_add(l->data); q = eina_stringshare_add(col);
eina_hash_direct_add(res->quickfind, q, q); eina_hash_direct_add(res->quickfind, q, q);
} }
if (coll) edje_file_collection_list_free(coll); if (coll) edje_file_collection_list_free(coll);
@ -333,9 +324,8 @@ e_theme_config_set(const char *category, const char *file)
#endif #endif
/* search for the category */ /* search for the category */
for (next = e_config->themes; next; next = next->next) EINA_LIST_FOREACH(e_config->themes, next, ect)
{ {
ect = eina_list_data_get(next);
if (!strcmp(ect->category, category)) if (!strcmp(ect->category, category))
{ {
if (ect->file) eina_stringshare_del(ect->file); if (ect->file) eina_stringshare_del(ect->file);
@ -363,9 +353,8 @@ e_theme_config_get(const char *category)
Eina_List *next; Eina_List *next;
/* search for the category */ /* search for the category */
for (next = e_config->themes; next; next = next->next) EINA_LIST_FOREACH(e_config->themes, next, ect)
{ {
ect = eina_list_data_get(next);
if (!strcmp(ect->category, category)) if (!strcmp(ect->category, category))
return ect; return ect;
} }
@ -377,11 +366,10 @@ e_theme_config_remove(const char *category)
{ {
E_Config_Theme *ect; E_Config_Theme *ect;
Eina_List *next; Eina_List *next;
/* search for the category */ /* search for the category */
for (next = e_config->themes; next; next = next->next) EINA_LIST_FOREACH(e_config->themes, next, ect)
{ {
ect = eina_list_data_get(next);
if (!strcmp(ect->category, category)) if (!strcmp(ect->category, category))
{ {
e_config->themes = eina_list_remove_list(e_config->themes, next); e_config->themes = eina_list_remove_list(e_config->themes, next);
@ -403,13 +391,8 @@ e_theme_config_list(void)
EAPI int EAPI int
e_theme_category_find(const char *category) e_theme_category_find(const char *category)
{ {
Eina_List *l; if (eina_list_search_sorted(categories, EINA_COMPARE_CB(strcmp), category))
return 1;
for (l = categories; l; l = l->next)
{
if (!strcmp(category, l->data))
return 1;
}
return 0; return 0;
} }
@ -422,13 +405,8 @@ e_theme_category_list(void)
EAPI int EAPI int
e_theme_transition_find(const char *transition) e_theme_transition_find(const char *transition)
{ {
Eina_List *l; if (eina_list_search_sorted(transitions, EINA_COMPARE_CB(strcmp), transition))
return 1;
for (l = transitions; l; l = l->next)
{
if (!strcmp(transition, l->data))
return 1;
}
return 0; return 0;
} }
@ -441,13 +419,8 @@ e_theme_transition_list(void)
EAPI int EAPI int
e_theme_border_find(const char *border) e_theme_border_find(const char *border)
{ {
Eina_List *l; if (eina_list_search_sorted(borders, EINA_COMPARE_CB(strcmp), border))
return 1;
for (l = borders; l; l = l->next)
{
if (!strcmp(border, l->data))
return 1;
}
return 0; return 0;
} }
@ -460,13 +433,8 @@ e_theme_border_list(void)
EAPI int EAPI int
e_theme_shelf_find(const char *shelf) e_theme_shelf_find(const char *shelf)
{ {
Eina_List *l; if (eina_list_search_sorted(shelfs, EINA_COMPARE_CB(strcmp), shelf))
return 1;
for (l = shelfs; l; l = l->next)
{
if (!strcmp(shelf, l->data))
return 1;
}
return 0; return 0;
} }
@ -525,24 +493,34 @@ _e_theme_mappings_quickfind_free_cb(const Eina_Hash *hash, const void *key, void
static void static void
_e_theme_category_register(const char *category) _e_theme_category_register(const char *category)
{ {
const char *c;
Eina_List *l; Eina_List *l;
int ret;
for (l = categories; l; l = l->next) if (!categories)
{ categories = eina_list_append(categories, eina_stringshare_add(category));
if (!strcmp(category, l->data)) return;
}
categories = eina_list_append(categories, eina_stringshare_add(category)); l = eina_list_search_sorted_near_list(categories, EINA_COMPARE_CB(strcmp), category);
c = eina_list_data_get(l);
ret = strcmp(c, category);
if (!ret) return;
if (ret < 0)
categories = eina_list_append_relative_list(categories, eina_stringshare_add(category), l);
else
categories = eina_list_prepend_relative_list(categories, eina_stringshare_add(category), l);
} }
static Eina_List * static Eina_List *
_e_theme_collection_item_register(Eina_List *list, const char *name) _e_theme_collection_item_register(Eina_List *list, const char *name)
{ {
const char *item;
Eina_List *l; Eina_List *l;
for (l = list; l; l = l->next) EINA_LIST_FOREACH(list, l, item)
{ {
if (!strcmp(name, l->data)) return list; if (!strcmp(name, item)) return list;
} }
list = eina_list_append(list, eina_stringshare_add(name)); list = eina_list_append(list, eina_stringshare_add(name));
return list; return list;
@ -584,13 +562,15 @@ _e_theme_collection_items_find(const char *base, const char *collname)
coll = edje_file_collection_list(str); coll = edje_file_collection_list(str);
if (coll) if (coll)
{ {
for (l = coll; l; l = l->next) const char *c;
EINA_LIST_FOREACH(coll, l, c)
{ {
if (!strncmp(l->data, collname, collname_len)) if (!strncmp(c, collname, collname_len))
{ {
char *trans; char *trans;
trans = strdup(l->data); trans = strdup(c);
p = trans + collname_len + 1; p = trans + collname_len + 1;
if (*p) if (*p)
{ {
@ -609,5 +589,7 @@ _e_theme_collection_items_find(const char *base, const char *collname)
if (p) *p = 0; if (p) *p = 0;
} }
while (p); while (p);
list = eina_list_sort(list, 0, EINA_COMPARE_CB(strcmp));
return list; return list;
} }