elm theme - add some api's to expose info so e can use elm's theme stuff

This commit is contained in:
Carsten Haitzler 2013-10-31 23:22:18 +09:00
parent ef8f697748
commit 9503c1f95b
2 changed files with 194 additions and 0 deletions

View File

@ -767,3 +767,122 @@ elm_theme_data_get(Elm_Theme *th, const char *key)
if (!th) th = &(theme_default);
return _elm_theme_data_find(th, key);
}
EAPI const char *
elm_theme_group_path_find(Elm_Theme *th, const char *group)
{
EINA_SAFETY_ON_NULL_RETURN_VAL(group, NULL);
if (!th) th = &(theme_default);
return _elm_theme_group_file_find(th, group);
}
static Eina_List *
_file_find_append(Eina_List *list, const char *home, const char *f)
{
char buf[PATH_MAX];
if ((f[0] == '/') || ((f[0] == '.') && (f[1] == '/')) ||
((f[0] == '.') && (f[1] == '.') && (f[2] == '/')) ||
((isalpha(f[0])) && (f[1] == ':')))
{
list = eina_list_append(list, eina_stringshare_add(f));
}
else if (((f[0] == '~') && (f[1] == '/')))
{
snprintf(buf, sizeof(buf), "%s/%s", home, f + 2);
list = eina_list_append(list, eina_stringshare_add(buf));
}
else
{
snprintf(buf, sizeof(buf), "%s/"ELEMENTARY_BASE_DIR"/themes/%s.edj", home, f);
list = eina_list_append(list, eina_stringshare_add(buf));
snprintf(buf, sizeof(buf), "%s/themes/%s.edj", _elm_data_dir, f);
list = eina_list_append(list, eina_stringshare_add(buf));
}
return list;
}
EAPI Eina_List *
elm_theme_group_base_list(Elm_Theme *th, const char *base)
{
Eina_List *list = NULL, *files = NULL, *coll, *l;
int len;
Eina_Stringshare *c, *c2, *f;
static const char *home = NULL;
EINA_SAFETY_ON_NULL_RETURN_VAL(base, NULL);
if (!th) th = &(theme_default);
// XXX: look results up in a hash for speed
len = strlen(base);
if (!home) // get homedir once only
{
home = getenv("HOME");
if (!home) home = "";
}
// go through overlay, themes and extensions in that order and build list
EINA_LIST_FOREACH(th->overlay, l, f)
files = _file_find_append(files, home, f);
EINA_LIST_FOREACH(th->themes, l, f)
files = _file_find_append(files, home, f);
EINA_LIST_FOREACH(th->extension, l, f)
files = _file_find_append(files, home, f);
// go through all possible theme files and find collections that match
EINA_LIST_FREE(files, f)
{
coll = edje_file_collection_list(f);
EINA_LIST_FREE(coll, c)
{
if (!strncmp(c, base, len)) // if base == start of collection str
{
EINA_LIST_FOREACH(list, l, c2) // check if already in list
{
if (!strcmp(c, c2)) break;
}
if (!l) // if not already in list append shared str to list
{
c2 = eina_stringshare_add(c);
list = eina_list_append(list, c2);
}
}
eina_stringshare_del(c);
}
}
// sort the list nicely at the end
list = eina_list_sort(list, 0, EINA_COMPARE_CB(strcmp));
// XXX: store results in hash for fast lookup...
return list;
}
EAPI const char *
elm_theme_system_dir_get(void)
{
static char *path = NULL;
char buf[PATH_MAX];
if (path) return path;
if (!path)
{
snprintf(buf, sizeof(buf), "%s/themes", _elm_data_dir);
path = strdup(buf);
}
return path;
}
EAPI const char *
elm_theme_user_dir_get(void)
{
static char *path = NULL;
char buf[PATH_MAX];
if (path) return path;
if (!path)
{
char *home = getenv("HOME");
if (!home) home = "";
snprintf(buf, sizeof(buf), "%s/"ELEMENTARY_BASE_DIR"/themes", home);
path = strdup(buf);
}
return path;
}

View File

@ -431,6 +431,81 @@ EAPI Elm_Theme *elm_object_theme_get(const Evas_Object *obj);
*/
EAPI const char *elm_theme_data_get(Elm_Theme *th, const char *key);
/**
* Get the file path for an edje file for the group and theme given
*
* @param th The theme, or NULL for default theme
* @param group The group in the edje file to look for
* @return The full path to the file as a string
*
* This function looks up the given edje @p group in the set of theme edje
* files configured for the theme @p th (which if NULL indicates the default
* theme). If not found in any, NULL wil be returned. If found, the string
* returned is internal and should not be freed, but will only be valid
* until the theme is re-configured, or cache flushed, so if the string needs
* to be kept, duplicate it and store that. The string will be a stringshare
* string that is returned by functions like eina_stringshare_add() so it can
* be just references via stringshare functions if desired.
*
* If group is NULL, then nothing can be looked up, so it is a non-sensical
* request.
*
* @ingroup Theme
*/
EAPI const char *elm_theme_group_path_find(Elm_Theme *th, const char *group);
/**
* Get a list of groups that match the initial base string given within all themes
*
* @param th The theme, or NULL for default theme
* @param base The base string group collection to look for
* @return A list of collection names (sorted) or NULL if none found
*
* This function will walk all theme files configured in the theme @p th (or
* NULL if its the default) and find all groups that BEGIN with the string
* @p begin and have that string as at LEAST their start, and then add the
* fulll group name that matches to the list and return that full group
* group string.
*
* The list returned must be freed by the caller, with each string being a
* stringshared string to be freed with eina_stringshare_del(). Not doing so
* may result in a leak.
*
* @ingroup Theme
*/
EAPI Eina_List *elm_theme_group_base_list(Elm_Theme *th, const char *base);
/**
* Get the file path where elementary system theme files are found
*
* @return A string that holds the path where system themes are
*
* This returns the location in the filesystem where the system themes are
* to be found that elementary looks for. This is useful for something
* that wishes toiterate over the files in this folder and display them, for
* example a theme selector.
*
* @ingroup Theme
*/
EAPI const char *elm_theme_system_dir_get(void);
/**
* Get the file path where elementary user theme files are found
*
* @return A string that holds the path where user themes are
*
* This returns the location in the filesystem where the user themes are
* to be found that elementary looks for. This is useful for something
* that wishes toiterate over the files in this folder and display them, for
* example a theme selector.
*
* User themes are always looked for before system themes. The user theme
* directory is normally expected to be writable by the user.
*
* @ingroup Theme
*/
EAPI const char *elm_theme_user_dir_get(void);
/**
* @}
*/