load themes from ~/.config/terminology/themes. Closes T1030

This commit is contained in:
Boris Faure 2014-02-26 23:03:27 +01:00
parent f757868436
commit 4bfc84110e
7 changed files with 110 additions and 46 deletions

4
README
View File

@ -122,6 +122,10 @@ or aa[true/false] should become something like:
or or
aafalse aafalse
Themes:
Themes can be stored in ~/.config/terminology/themes/ .
--- ---
pn[FULL-PATH-OR-URL] pn[FULL-PATH-OR-URL]

View File

@ -275,6 +275,10 @@ Reset the background (no media)
.B bPATH .B bPATH
Set the background media to an absolute file PATH Set the background media to an absolute file PATH
.SH THEMES:
Themes can be stored in ~/.config/terminology/themes/ .
.SH EXTENDED ESCAPES FOR TERMINOLOGY: .SH EXTENDED ESCAPES FOR TERMINOLOGY:
. .
.TP .TP

View File

@ -5,6 +5,7 @@
#include "config.h" #include "config.h"
#include "main.h" #include "main.h"
#include "col.h" #include "col.h"
#include "utils.h"
#define CONF_VER 2 #define CONF_VER 2
@ -23,10 +24,15 @@ void
config_init(void) config_init(void)
{ {
Eet_Data_Descriptor_Class eddc; Eet_Data_Descriptor_Class eddc;
char path[PATH_MAX] = {};
elm_need_efreet(); elm_need_efreet();
efreet_init(); efreet_init();
snprintf(path, sizeof(path) -1, "%s/terminology/themes",
_config_home_get());
ecore_file_mkpath(path);
eet_eina_stream_data_descriptor_class_set eet_eina_stream_data_descriptor_class_set
(&eddc, sizeof(eddc), "Config", sizeof(Config)); (&eddc, sizeof(eddc), "Config", sizeof(Config));
edd_base = eet_data_descriptor_stream_new(&eddc); edd_base = eet_data_descriptor_stream_new(&eddc);
@ -613,17 +619,13 @@ config_del(Config *config)
const char * const char *
config_theme_path_get(const Config *config) 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, NULL);
EINA_SAFETY_ON_NULL_RETURN_VAL(config->theme, NULL); EINA_SAFETY_ON_NULL_RETURN_VAL(config->theme, NULL);
if (strchr(config->theme, '/')) if (strchr(config->theme, '/'))
return config->theme; return config->theme;
snprintf(path, sizeof(path), "%s/themes/%s", return theme_path_get(config->theme);
elm_app_data_dir_get(), config->theme);
return path;
} }
const char * const char *

View File

@ -2753,20 +2753,20 @@ elm_main(int argc, char **argv)
if (theme) if (theme)
{ {
char path[PATH_MAX]; 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")) if (eina_str_has_suffix(theme, ".edj"))
eina_strlcpy(nom, theme, sizeof(nom)); eina_strlcpy(theme_name, theme, sizeof(theme_name));
else else
snprintf(nom, sizeof(nom), "%s.edj", theme); snprintf(theme_name, sizeof(theme_name), "%s.edj", theme);
if (strchr(nom, '/')) if (strchr(theme_name, '/'))
eina_strlcpy(path, nom, sizeof(path)); eina_strlcpy(path, theme_name, sizeof(path));
else else
snprintf(path, sizeof(path), "%s/themes/%s", theme_path = theme_path_get(theme_name);
elm_app_data_dir_get(), nom);
eina_stringshare_replace(&(config->theme), path); eina_stringshare_replace(&(config->theme), theme_path);
config->temporary = EINA_TRUE; config->temporary = EINA_TRUE;
} }

View File

@ -42,14 +42,12 @@ _cb_op_theme_content_get(void *data, Evas_Object *obj, const char *part)
if (!strcmp(part, "elm.swallow.icon")) if (!strcmp(part, "elm.swallow.icon"))
{ {
Evas_Object *o; Evas_Object *o;
char buf[4096];
Config *config = termio_config_get(t->term); Config *config = termio_config_get(t->term);
if (config) if (config)
{ {
snprintf(buf, sizeof(buf), "%s/themes/%s", o = options_theme_preview_add(obj, config,
elm_app_data_dir_get(), t->name); theme_path_get(t->name),
o = options_theme_preview_add(obj, config, buf,
128 * elm_config_scale_get(), 128 * elm_config_scale_get(),
64 * elm_config_scale_get()); 64 * elm_config_scale_get());
return o; return o;
@ -98,10 +96,13 @@ options_theme(Evas_Object *opbox, Evas_Object *term)
{ {
Evas_Object *o, *box, *fr; Evas_Object *o, *box, *fr;
Elm_Gengrid_Item_Class *it_class; Elm_Gengrid_Item_Class *it_class;
Eina_List *files; Eina_List *files, *userfiles, *l, *l_next;
char buf[4096], *file; 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); Config *config = termio_config_get(term);
Eina_Bool to_skip = EINA_FALSE;
double scale = elm_config_scale_get();
options_theme_clear(); options_theme_clear();
@ -127,49 +128,79 @@ options_theme(Evas_Object *opbox, Evas_Object *term)
op_themelist = o = elm_gengrid_add(opbox); op_themelist = o = elm_gengrid_add(opbox);
evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); 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); evas_object_size_hint_align_set(o, EVAS_HINT_FILL, EVAS_HINT_FILL);
elm_gengrid_item_size_set(o, elm_gengrid_item_size_set(o, scale * 160, scale * 180);
elm_config_scale_get() * 160,
elm_config_scale_get() * 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); files = ecore_file_ls(buf);
if (files) if (files)
files = eina_list_sort(files, eina_list_count(files), files = eina_list_sort(files, eina_list_count(files),
_cb_op_theme_sort); _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) if (seltimer)
{ {
ecore_timer_del(seltimer); ecore_timer_del(seltimer);
seltimer = NULL; seltimer = NULL;
} }
EINA_LIST_FREE(files, file)
EINA_LIST_FOREACH_SAFE(files, l, l_next, file)
{ {
const char *ext = strchr(file, '.'); const char *ext = strchr(file, '.');
if ((config) && (file[0] != '.') && if (!((config) && (file[0] != '.') &&
((ext) && (!strcasecmp(".edj", ext)))) ((ext) && (!strcasecmp(".edj", ext)))))
{ {
t = calloc(1, sizeof(Theme)); free(file);
t->name = eina_stringshare_add(file); files = eina_list_remove_list(files, l);
t->term = term; }
t->item = elm_gengrid_item_append(o, it_class, t, }
_cb_op_theme_sel, t);
if (t->item) 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 (seltimer) ecore_timer_del(seltimer);
if ((config->theme) && seltimer = ecore_timer_add(0.2, _cb_sel_item, t);
(!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);
} }
} }
else
{
eina_stringshare_del(t->name);
free(t);
}
end_loop:
files = eina_list_remove_list(files, l);
free(file); free(file);
} }

View File

@ -4,6 +4,28 @@
#include <pwd.h> #include <pwd.h>
#include <Edje.h> #include <Edje.h>
#include <Elementary.h>
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 Eina_Bool
theme_apply(Evas_Object *edje, const Config *config, const char *group) theme_apply(Evas_Object *edje, const Config *config, const char *group)

View File

@ -7,6 +7,7 @@
Eina_Bool theme_apply(Evas_Object *edje, const Config *config, const char *group); Eina_Bool theme_apply(Evas_Object *edje, const Config *config, const char *group);
void theme_reload(Evas_Object *edje); void theme_reload(Evas_Object *edje);
void theme_auto_reload_enable(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); Eina_Bool homedir_get(char *buf, size_t size);