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

devs/cedric/ssh
Boris Faure 9 years ago
parent f757868436
commit 4bfc84110e
  1. 4
      README
  2. 4
      man/terminology.1
  3. 12
      src/bin/config.c
  4. 16
      src/bin/main.c
  5. 97
      src/bin/options_theme.c
  6. 22
      src/bin/utils.c
  7. 1
      src/bin/utils.h

@ -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]

@ -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

@ -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 *

@ -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;
}

@ -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)
{
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
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)))
{
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);
}

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

@ -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);

Loading…
Cancel
Save