From 4bfc84110e4635c42333a64e784ba921745878be Mon Sep 17 00:00:00 2001 From: Boris Faure Date: Wed, 26 Feb 2014 23:03:27 +0100 Subject: [PATCH] load themes from ~/.config/terminology/themes. Closes T1030 --- README | 4 ++ man/terminology.1 | 4 ++ src/bin/config.c | 12 ++--- src/bin/main.c | 16 +++---- src/bin/options_theme.c | 97 +++++++++++++++++++++++++++-------------- src/bin/utils.c | 22 ++++++++++ src/bin/utils.h | 1 + 7 files changed, 110 insertions(+), 46 deletions(-) diff --git a/README b/README index eb46145b..57c65218 100644 --- a/README +++ b/README @@ -122,6 +122,10 @@ or aa[true/false] should become something like: or aafalse +Themes: + +Themes can be stored in ~/.config/terminology/themes/ . + --- pn[FULL-PATH-OR-URL] diff --git a/man/terminology.1 b/man/terminology.1 index 064e0742..d54b3c34 100644 --- a/man/terminology.1 +++ b/man/terminology.1 @@ -275,6 +275,10 @@ Reset the background (no media) .B bPATH Set the background media to an absolute file PATH +.SH THEMES: +Themes can be stored in ~/.config/terminology/themes/ . + + .SH EXTENDED ESCAPES FOR TERMINOLOGY: . .TP diff --git a/src/bin/config.c b/src/bin/config.c index 949a09bc..ba6397b5 100644 --- a/src/bin/config.c +++ b/src/bin/config.c @@ -5,6 +5,7 @@ #include "config.h" #include "main.h" #include "col.h" +#include "utils.h" #define CONF_VER 2 @@ -23,10 +24,15 @@ void config_init(void) { Eet_Data_Descriptor_Class eddc; + char path[PATH_MAX] = {}; elm_need_efreet(); efreet_init(); + snprintf(path, sizeof(path) -1, "%s/terminology/themes", + _config_home_get()); + ecore_file_mkpath(path); + eet_eina_stream_data_descriptor_class_set (&eddc, sizeof(eddc), "Config", sizeof(Config)); edd_base = eet_data_descriptor_stream_new(&eddc); @@ -613,17 +619,13 @@ config_del(Config *config) const char * config_theme_path_get(const Config *config) { - static char path[PATH_MAX]; - EINA_SAFETY_ON_NULL_RETURN_VAL(config, NULL); EINA_SAFETY_ON_NULL_RETURN_VAL(config->theme, NULL); if (strchr(config->theme, '/')) return config->theme; - snprintf(path, sizeof(path), "%s/themes/%s", - elm_app_data_dir_get(), config->theme); - return path; + return theme_path_get(config->theme); } const char * diff --git a/src/bin/main.c b/src/bin/main.c index 3d6c94d0..9ccb4a0c 100644 --- a/src/bin/main.c +++ b/src/bin/main.c @@ -2753,20 +2753,20 @@ elm_main(int argc, char **argv) if (theme) { char path[PATH_MAX]; - char nom[PATH_MAX]; + char theme_name[PATH_MAX]; + const char *theme_path = (const char *)&path; if (eina_str_has_suffix(theme, ".edj")) - eina_strlcpy(nom, theme, sizeof(nom)); + eina_strlcpy(theme_name, theme, sizeof(theme_name)); else - snprintf(nom, sizeof(nom), "%s.edj", theme); + snprintf(theme_name, sizeof(theme_name), "%s.edj", theme); - if (strchr(nom, '/')) - eina_strlcpy(path, nom, sizeof(path)); + if (strchr(theme_name, '/')) + eina_strlcpy(path, theme_name, sizeof(path)); else - snprintf(path, sizeof(path), "%s/themes/%s", - elm_app_data_dir_get(), nom); + theme_path = theme_path_get(theme_name); - eina_stringshare_replace(&(config->theme), path); + eina_stringshare_replace(&(config->theme), theme_path); config->temporary = EINA_TRUE; } diff --git a/src/bin/options_theme.c b/src/bin/options_theme.c index fc2b6484..03585d77 100644 --- a/src/bin/options_theme.c +++ b/src/bin/options_theme.c @@ -42,14 +42,12 @@ _cb_op_theme_content_get(void *data, Evas_Object *obj, const char *part) if (!strcmp(part, "elm.swallow.icon")) { Evas_Object *o; - char buf[4096]; Config *config = termio_config_get(t->term); - + if (config) { - snprintf(buf, sizeof(buf), "%s/themes/%s", - elm_app_data_dir_get(), t->name); - o = options_theme_preview_add(obj, config, buf, + o = options_theme_preview_add(obj, config, + theme_path_get(t->name), 128 * elm_config_scale_get(), 64 * elm_config_scale_get()); return o; @@ -98,10 +96,13 @@ options_theme(Evas_Object *opbox, Evas_Object *term) { Evas_Object *o, *box, *fr; Elm_Gengrid_Item_Class *it_class; - Eina_List *files; + Eina_List *files, *userfiles, *l, *l_next; char buf[4096], *file; - Theme *t; + const char *config_dir = efreet_config_home_get(), + *data_dir = elm_app_data_dir_get(); Config *config = termio_config_get(term); + Eina_Bool to_skip = EINA_FALSE; + double scale = elm_config_scale_get(); options_theme_clear(); @@ -127,49 +128,79 @@ options_theme(Evas_Object *opbox, Evas_Object *term) op_themelist = o = elm_gengrid_add(opbox); evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); evas_object_size_hint_align_set(o, EVAS_HINT_FILL, EVAS_HINT_FILL); - elm_gengrid_item_size_set(o, - elm_config_scale_get() * 160, - elm_config_scale_get() * 180); + elm_gengrid_item_size_set(o, scale * 160, scale * 180); - snprintf(buf, sizeof(buf), "%s/themes", elm_app_data_dir_get()); + snprintf(buf, sizeof(buf), "%s/themes", data_dir); files = ecore_file_ls(buf); if (files) files = eina_list_sort(files, eina_list_count(files), _cb_op_theme_sort); + snprintf(buf, sizeof(buf), "%s/terminology/themes", config_dir); + userfiles = ecore_file_ls(buf); + if (userfiles) + userfiles = eina_list_sort(userfiles, eina_list_count(userfiles), + _cb_op_theme_sort); + + if (files && userfiles) + files = eina_list_sorted_merge(files, userfiles, _cb_op_theme_sort); + else if (userfiles) + files = userfiles; + if (seltimer) { ecore_timer_del(seltimer); seltimer = NULL; } - EINA_LIST_FREE(files, file) + + EINA_LIST_FOREACH_SAFE(files, l, l_next, file) { const char *ext = strchr(file, '.'); - - if ((config) && (file[0] != '.') && - ((ext) && (!strcasecmp(".edj", ext)))) + + if (!((config) && (file[0] != '.') && + ((ext) && (!strcasecmp(".edj", ext))))) { - t = calloc(1, sizeof(Theme)); - t->name = eina_stringshare_add(file); - t->term = term; - t->item = elm_gengrid_item_append(o, it_class, t, - _cb_op_theme_sel, t); - if (t->item) + free(file); + files = eina_list_remove_list(files, l); + } + } + + EINA_LIST_FOREACH_SAFE(files, l, l_next, file) + { + Theme *t; + if (to_skip == EINA_TRUE) + { + to_skip = EINA_FALSE; + goto end_loop; + } + + if (l_next && l_next->data && !strcmp(file, l_next->data)) + { + to_skip = EINA_TRUE; + } + + t = calloc(1, sizeof(Theme)); + t->name = eina_stringshare_add(file); + t->term = term; + t->item = elm_gengrid_item_append(o, it_class, t, + _cb_op_theme_sel, t); + if (t->item) + { + themes = eina_list_append(themes, t); + if ((config->theme) && + (!strcmp(config->theme, t->name))) { - themes = eina_list_append(themes, t); - if ((config->theme) && - (!strcmp(config->theme, t->name))) - { - if (seltimer) ecore_timer_del(seltimer); - seltimer = ecore_timer_add(0.2, _cb_sel_item, t); - } - } - else - { - eina_stringshare_del(t->name); - free(t); + if (seltimer) ecore_timer_del(seltimer); + seltimer = ecore_timer_add(0.2, _cb_sel_item, t); } } + else + { + eina_stringshare_del(t->name); + free(t); + } + end_loop: + files = eina_list_remove_list(files, l); free(file); } diff --git a/src/bin/utils.c b/src/bin/utils.c index 66f2f897..45bd6183 100644 --- a/src/bin/utils.c +++ b/src/bin/utils.c @@ -4,6 +4,28 @@ #include #include +#include + +const char * +theme_path_get(const char *name) +{ + static char path1[PATH_MAX] = ""; + static char path2[PATH_MAX] = ""; + + /* use the newer file */ + struct stat s1, s2; + + snprintf(path1, sizeof(path1) - 1, "%s/themes/%s", + elm_app_data_dir_get(), name); + snprintf(path2, sizeof(path2) - 1, "%s/terminology/themes/%s", + efreet_config_home_get(), name); + + if (stat(path1, &s1) < 0) return path2; + if (stat(path2, &s2) < 0) return path1; + + if (s1.st_mtime > s2.st_mtime) return path1; + return path2; +} Eina_Bool theme_apply(Evas_Object *edje, const Config *config, const char *group) diff --git a/src/bin/utils.h b/src/bin/utils.h index c79e6673..cbdcdd5e 100644 --- a/src/bin/utils.h +++ b/src/bin/utils.h @@ -7,6 +7,7 @@ Eina_Bool theme_apply(Evas_Object *edje, const Config *config, const char *group); void theme_reload(Evas_Object *edje); void theme_auto_reload_enable(Evas_Object *edje); +const char *theme_path_get(const char *name); Eina_Bool homedir_get(char *buf, size_t size);