utils/theme: unify code, error messages and allow fallback.

Introduced two nice helpers to aid common Edje handling:
 * apply theme, using fallback if main is not found;
 * reload theme if file changed.



SVN revision: 72490
devs/lucas/wip
Gustavo Sverzut Barbieri 11 years ago
parent c71424367d
commit 2cd2514538
  1. 3
      src/bin/Makefile.am
  2. 17
      src/bin/config.c
  3. 1
      src/bin/config.h
  4. 25
      src/bin/main.c
  5. 15
      src/bin/media.c
  6. 19
      src/bin/options_font.c
  7. 18
      src/bin/termio.c
  8. 52
      src/bin/utils.c
  9. 13
      src/bin/utils.h

@ -22,4 +22,5 @@ options_video.c options_video.h \
termio.c termio.h \
termpty.c termpty.h \
utf8.c utf8.h \
win.c win.h
win.c win.h \
utils.c utils.h

@ -1,3 +1,5 @@
#include "private.h"
#include <Elementary.h>
#include "config.h"
@ -173,3 +175,18 @@ config_theme_path_get(const Config *config)
elm_app_data_dir_get(), config->theme);
return path;
}
const char *
config_theme_path_default_get(const Config *config __UNUSED__)
{
static char path[PATH_MAX] = "";
EINA_SAFETY_ON_NULL_RETURN_VAL(config, NULL);
EINA_SAFETY_ON_NULL_RETURN_VAL(config->theme, NULL);
if (path[0]) return path;
snprintf(path, sizeof(path), "%s/themes/default.edj",
elm_app_data_dir_get());
return path;
}

@ -31,5 +31,6 @@ Config *config_load(const char *key);
void config_del(Config *config);
const char *config_theme_path_get(const Config *config);
const char *config_theme_path_default_get(const Config *config);
#endif

@ -8,6 +8,7 @@
#include "config.h"
#include "options.h"
#include "media.h"
#include "utils.h"
int _log_domain = -1;
@ -48,18 +49,6 @@ _cb_size_hint(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj, void
}
}
static void
_reload_theme(void *data __UNUSED__, Evas_Object *obj,
const char *emission __UNUSED__, const char *source __UNUSED__)
{
const char *file;
const char *group;
edje_object_file_get(obj, &file, &group);
edje_object_file_set(obj, file, group);
fprintf(stderr, "RELOADING THEME main.c\n");
}
static void
_cb_options(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event __UNUSED__)
{
@ -273,9 +262,13 @@ elm_main(int argc, char **argv)
bg = o = edje_object_add(evas_object_evas_get(win));
evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
evas_object_size_hint_fill_set(o, EVAS_HINT_FILL, EVAS_HINT_FILL);
edje_object_file_set(o, config_theme_path_get(config),
"terminology/background");
edje_object_signal_callback_add(o, "edje,change,file", "edje", _reload_theme, NULL);
if (!theme_apply(o, config, "terminology/background"))
{
CRITICAL("Couldn't find terminology theme! Forgot 'make install'?");
retval = EXIT_FAILURE;
goto end;
}
theme_auto_reload_enable(o);
elm_win_resize_object_add(win, o);
evas_object_show(o);
@ -292,7 +285,7 @@ elm_main(int argc, char **argv)
main_trans_update(config);
main_media_update(config);
evas_object_smart_callback_add(win, "focus,in", _cb_focus_in, term);
evas_object_smart_callback_add(win, "focus,out", _cb_focus_out, term);
_cb_size_hint(win, evas_object_evas_get(win), term, NULL);

@ -4,6 +4,7 @@
#include <Emotion.h>
#include "media.h"
#include "config.h"
#include "utils.h"
typedef struct _Media Media;
@ -73,18 +74,6 @@ _is_fmt(const char *f, const char **extn)
}
//////////////////////// img
static void
_reload_theme(void *data __UNUSED__, Evas_Object *obj,
const char *emission __UNUSED__, const char *source __UNUSED__)
{
const char *file;
const char *group;
edje_object_file_get(obj, &file, &group);
edje_object_file_set(obj, file, group);
fprintf(stderr, "RELOADING THEME media.c\n");
}
static void
_cb_img_preloaded(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event __UNUSED__)
{
@ -286,8 +275,8 @@ _type_edje_init(Evas_Object *obj)
{
edje_object_signal_callback_add(o, "preload,done", "",
_cb_edje_preloaded, obj);
edje_object_signal_callback_add(o, "edje,change,file", "edje", _reload_theme, NULL);
edje_object_preload(o, EINA_FALSE);
theme_auto_reload_enable(o);
return;
}
}

@ -5,6 +5,7 @@
#include "termio.h"
#include "options.h"
#include "options_font.h"
#include "utils.h"
static Evas_Object *op_fontslider, *op_fontlist, *op_fsml, *op_fbig;
@ -21,18 +22,6 @@ struct _Font
static Eina_List *fonts = NULL;
static Eina_Hash *fonthash = NULL;
static void
_reload_theme(void *data __UNUSED__, Evas_Object *obj,
const char *emission __UNUSED__, const char *source __UNUSED__)
{
const char *file;
const char *group;
edje_object_file_get(obj, &file, &group);
edje_object_file_set(obj, file, group);
fprintf(stderr, "RELOADING THEME\n");
}
static void
_update_sizing(Evas_Object *term)
{
@ -140,10 +129,8 @@ _cb_op_font_content_get(void *data, Evas_Object *obj, const char *part)
Config *config = termio_config_get(f->term);
o = edje_object_add(evas_object_evas_get(obj));
edje_object_file_set(o, config_theme_path_get(config),
"terminology/fontpreview");
edje_object_signal_callback_add(o, "edje,change,file", "edje",
_reload_theme, NULL);
theme_apply(o, config, "terminology/fontpreview");
theme_auto_reload_enable(o);
evas_object_size_hint_min_set(o,
96 * elm_config_scale_get(),
40 * elm_config_scale_get());

@ -8,6 +8,7 @@
#include "col.h"
#include "keyin.h"
#include "config.h"
#include "utils.h"
typedef struct _Termio Termio;
@ -54,18 +55,6 @@ static Evas_Smart_Class _parent_sc = EVAS_SMART_CLASS_INIT_NULL;
static void _smart_calculate(Evas_Object *obj);
static void
_reload_theme(void *data __UNUSED__, Evas_Object *obj,
const char *emission __UNUSED__, const char *source __UNUSED__)
{
const char *file;
const char *group;
edje_object_file_get(obj, &file, &group);
edje_object_file_set(obj, file, group);
fprintf(stderr, "RELOADING THEME termio\n");
}
static void
_smart_apply(Evas_Object *obj)
{
@ -800,9 +789,8 @@ _termio_config_set(Evas_Object *obj, Config *config)
sd->font.chw = w;
sd->font.chh = h;
edje_object_file_set(sd->cur.obj,
config_theme_path_get(config), "terminology/cursor");
edje_object_signal_callback_add(sd->cur.obj, "edje,change,file", "edje", _reload_theme, NULL);
theme_apply(sd->cur.obj, config, "terminology/cursor");
theme_auto_reload_enable(sd->cur.obj);
evas_object_resize(sd->cur.obj, sd->font.chw, sd->font.chh);
evas_object_show(sd->cur.obj);
}

@ -0,0 +1,52 @@
#include "private.h"
#include "utils.h"
#include <Edje.h>
Eina_Bool
theme_apply(Evas_Object *edje, const Config *config, const char *group)
{
const char *errmsg;
EINA_SAFETY_ON_NULL_RETURN_VAL(edje, EINA_FALSE);
EINA_SAFETY_ON_NULL_RETURN_VAL(config, EINA_FALSE);
EINA_SAFETY_ON_NULL_RETURN_VAL(group, EINA_FALSE);
if (edje_object_file_set(edje, config_theme_path_get(config), group))
return EINA_TRUE;
errmsg = edje_load_error_str(edje_object_load_error_get(edje));
INF("Cannot find theme: file=%s group=%s error='%s', trying default...",
config_theme_path_get(config), group, errmsg);
if (edje_object_file_set(edje, config_theme_path_default_get(config), group))
return EINA_TRUE;
errmsg = edje_load_error_str(edje_object_load_error_get(edje));
ERR("Could not load any theme for group=%s: %s", group, errmsg);
return EINA_FALSE;
}
void
theme_reload(Evas_Object *edje)
{
const char *file;
const char *group;
edje_object_file_get(edje, &file, &group);
INF("file=%s, group=%s", file, group);
edje_object_file_set(edje, file, group);
}
static void
theme_reload_cb(void *data __UNUSED__, Evas_Object *obj, const char *emission __UNUSED__, const char *source __UNUSED__)
{
theme_reload(obj);
}
void
theme_auto_reload_enable(Evas_Object *edje)
{
edje_object_signal_callback_add
(edje, "edje,change,file", "edje", theme_reload_cb, NULL);
}

@ -0,0 +1,13 @@
#ifndef _UTILS_H__
#define _UTILS_H__
#include <Evas.h>
#include "config.h"
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);
#endif
Loading…
Cancel
Save