From: discomfitor Date: Mon, 12 Sep 2011 01:05:07 +0000 (+0000) Subject: all this for elm_theme_data_get X-Git-Tag: REL_F_I9500_20111128_2~22 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=8b3c3462bac4520151425435329b38417cb2b84b;p=framework%2Fuifw%2Felementary.git all this for elm_theme_data_get git-svn-id: https://svn.enlightenment.org/svn/e/trunk/elementary@63331 7cbeb6ba-43b4-40fd-8cce-4c39aea84d33 --- diff --git a/src/lib/elm_priv.h b/src/lib/elm_priv.h index c1da756..6c70a69 100644 --- a/src/lib/elm_priv.h +++ b/src/lib/elm_priv.h @@ -39,6 +39,7 @@ struct _Elm_Theme Eina_List *themes; Eina_List *extension; Eina_Hash *cache; + Eina_Hash *cache_data; Elm_Theme *ref_theme; Eina_List *referrers; const char *theme; diff --git a/src/lib/elm_theme.c b/src/lib/elm_theme.c index b8ccfed..3382b67 100644 --- a/src/lib/elm_theme.c +++ b/src/lib/elm_theme.c @@ -4,7 +4,7 @@ static Elm_Theme theme_default = { - NULL, NULL, NULL, NULL, NULL, NULL, NULL, 1 + NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 1 }; static Eina_List *themes = NULL; @@ -24,6 +24,11 @@ _elm_theme_clear(Elm_Theme *th) eina_hash_free(th->cache); th->cache = NULL; } + if (th->cache_data) + { + eina_hash_free(th->cache_data); + th->cache_data = NULL; + } if (th->theme) { eina_stringshare_del(th->theme); @@ -111,6 +116,79 @@ _elm_theme_group_file_find(Elm_Theme *th, const char *group) return NULL; } +static const char * +_elm_theme_find_data_try(Elm_Theme *th, const char *f, const char *key) +{ + char *data; + const char *t; + + data = edje_file_data_get(f, key); + t = eina_stringshare_add(data); + free(data); + if (t) + { + eina_hash_add(th->cache, key, t); + return t; + } + return NULL; +} + +static const char * +_elm_theme_theme_data_try(Elm_Theme *th, const char *home, const char *f, const char *key) +{ + char buf[PATH_MAX]; + const char *data = NULL; + + if ((f[0] == '/') || ((f[0] == '.') && (f[1] == '/')) || + ((f[0] == '.') && (f[1] == '.') && (f[2] == '/')) || + ((isalpha(f[0])) && (f[1] == ':'))) + return _elm_theme_find_data_try(th, f, key); + else if (((f[0] == '~') && (f[1] == '/'))) + { + snprintf(buf, sizeof(buf), "%s/%s", home, f + 2); + return _elm_theme_find_try(th, buf, key); + } + snprintf(buf, sizeof(buf), "%s/.elementary/themes/%s.edj", home, f); + data = _elm_theme_find_data_try(th, buf, key); + if (data) return data; + snprintf(buf, sizeof(buf), "%s/themes/%s.edj", _elm_data_dir, f); + data = _elm_theme_find_data_try(th, buf, key); + return data; +} + +static const char * +_elm_theme_data_find(Elm_Theme *th, const char *key) +{ + const Eina_List *l; + const char *f; + static const char *home = NULL; + const char *data = eina_hash_find(th->cache_data, key); + + if (data) return data; + if (!home) + { + home = getenv("HOME"); + if (!home) home = ""; + } + EINA_LIST_FOREACH(th->overlay, l, f) + { + data = _elm_theme_theme_data_try(th, home, f, key); + if (data) return data; + } + EINA_LIST_FOREACH(th->themes, l, f) + { + data = _elm_theme_theme_data_try(th, home, f, key); + if (data) return data; + } + EINA_LIST_FOREACH(th->extension, l, f) + { + data = _elm_theme_theme_data_try(th, home, f, key); + if (data) return data; + } + if (th->ref_theme) return _elm_theme_data_find(th->ref_theme, key); + return NULL; +} + Eina_Bool _elm_theme_object_set(Evas_Object *parent, Evas_Object *o, const char *clas, const char *group, const char *style) { @@ -224,6 +302,8 @@ _elm_theme_parse(Elm_Theme *th, const char *theme) } if (th->cache) eina_hash_free(th->cache); th->cache = eina_hash_string_superfast_new(EINA_FREE_CB(eina_stringshare_del)); + if (th->cache_data) eina_hash_free(th->cache_data); + th->cache_data = eina_hash_string_superfast_new(EINA_FREE_CB(eina_stringshare_del)); EINA_LIST_FREE(th->themes, p) eina_stringshare_del(p); @@ -433,6 +513,8 @@ elm_theme_flush(Elm_Theme *th) if (!th) th = &(theme_default); if (th->cache) eina_hash_free(th->cache); th->cache = eina_hash_string_superfast_new(EINA_FREE_CB(eina_stringshare_del)); + if (th->cache_data) eina_hash_free(th->cache_data); + th->cache_data = eina_hash_string_superfast_new(EINA_FREE_CB(eina_stringshare_del)); _elm_win_rescale(th, EINA_TRUE); if (th->referrers) { @@ -556,3 +638,10 @@ elm_object_theme_get(const Evas_Object *obj) EINA_SAFETY_ON_NULL_RETURN_VAL(obj, NULL); return elm_widget_theme_get(obj); } + +EAPI const char * +elm_theme_data_get(Elm_Theme *th, const char *key) +{ + if (!th) th = &(theme_default); + return _elm_theme_data_find(th, key); +}