2012-06-19 08:59:49 -07:00
|
|
|
#include "private.h"
|
|
|
|
#include "utils.h"
|
2012-10-09 10:20:27 -07:00
|
|
|
#include <unistd.h>
|
|
|
|
#include <pwd.h>
|
2012-06-19 08:59:49 -07:00
|
|
|
|
|
|
|
#include <Edje.h>
|
2015-02-14 03:08:50 -08:00
|
|
|
#include <Efreet.h>
|
2014-02-26 14:03:27 -08:00
|
|
|
#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 */
|
2015-08-10 21:15:16 -07:00
|
|
|
struct stat s2;
|
2014-02-26 14:03:27 -08:00
|
|
|
|
|
|
|
snprintf(path2, sizeof(path2) - 1, "%s/terminology/themes/%s",
|
|
|
|
efreet_config_home_get(), name);
|
|
|
|
|
2015-08-10 21:15:16 -07:00
|
|
|
if (stat(path2, &s2) == 0) return path2;
|
|
|
|
snprintf(path1, sizeof(path1) - 1, "%s/themes/%s",
|
|
|
|
elm_app_data_dir_get(), name);
|
|
|
|
return path1;
|
2014-02-26 14:03:27 -08:00
|
|
|
}
|
2012-06-19 08:59:49 -07:00
|
|
|
|
|
|
|
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;
|
2014-08-13 10:34:57 -07:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2019-05-22 14:03:03 -07:00
|
|
|
Eina_Bool
|
|
|
|
theme_apply_elm(Evas_Object *layout, const Config *config, const char *group)
|
|
|
|
{
|
|
|
|
const char *errmsg;
|
|
|
|
Evas_Object *edje;
|
|
|
|
|
|
|
|
EINA_SAFETY_ON_NULL_RETURN_VAL(layout, EINA_FALSE);
|
|
|
|
EINA_SAFETY_ON_NULL_RETURN_VAL(config, EINA_FALSE);
|
|
|
|
EINA_SAFETY_ON_NULL_RETURN_VAL(group, EINA_FALSE);
|
|
|
|
|
|
|
|
if (elm_layout_file_set(layout, config_theme_path_get(config), group))
|
|
|
|
return EINA_TRUE;
|
|
|
|
|
|
|
|
edje = elm_layout_edje_get(layout);
|
|
|
|
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 (elm_layout_file_set(layout, 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;
|
|
|
|
}
|
|
|
|
|
2014-08-13 10:34:57 -07:00
|
|
|
Eina_Bool
|
|
|
|
theme_apply_default(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_default_get(config), group))
|
|
|
|
return EINA_TRUE;
|
2012-06-19 08:59:49 -07:00
|
|
|
|
|
|
|
errmsg = edje_load_error_str(edje_object_load_error_get(edje));
|
2014-08-18 09:53:49 -07:00
|
|
|
ERR(_("Could not load default theme for group=%s: %s"), group, errmsg);
|
2012-06-19 08:59:49 -07:00
|
|
|
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);
|
2014-01-30 02:38:07 -08:00
|
|
|
if (!edje_object_file_set(edje, file, group)) return;
|
2012-06-19 08:59:49 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2016-10-05 13:00:22 -07:00
|
|
|
theme_reload_cb(void *_data EINA_UNUSED,
|
|
|
|
Evas_Object *obj,
|
|
|
|
const char *_emission EINA_UNUSED,
|
|
|
|
const char *_source EINA_UNUSED)
|
2012-06-19 08:59:49 -07:00
|
|
|
{
|
2013-10-11 22:31:03 -07:00
|
|
|
void (*func) (void *d);
|
|
|
|
void *func_data;
|
|
|
|
|
2012-06-19 08:59:49 -07:00
|
|
|
theme_reload(obj);
|
2013-10-11 22:31:03 -07:00
|
|
|
func = evas_object_data_get(obj, "theme_reload_func");
|
|
|
|
func_data = evas_object_data_get(obj, "theme_reload_func_data");
|
|
|
|
printf("%p %p\n", func, func_data);
|
|
|
|
if (func) func(func_data);
|
2012-06-19 08:59:49 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
theme_auto_reload_enable(Evas_Object *edje)
|
|
|
|
{
|
|
|
|
edje_object_signal_callback_add
|
|
|
|
(edje, "edje,change,file", "edje", theme_reload_cb, NULL);
|
|
|
|
}
|
2012-08-08 06:15:54 -07:00
|
|
|
|
2012-10-09 10:20:27 -07:00
|
|
|
Eina_Bool
|
|
|
|
homedir_get(char *buf, size_t size)
|
|
|
|
{
|
|
|
|
const char *home = getenv("HOME");
|
|
|
|
if (!home)
|
|
|
|
{
|
|
|
|
uid_t uid = getuid();
|
|
|
|
struct passwd *pw = getpwuid(uid);
|
|
|
|
if (pw) home = pw->pw_dir;
|
|
|
|
}
|
|
|
|
if (!home)
|
|
|
|
{
|
|
|
|
ERR("Could not get $HOME");
|
|
|
|
return EINA_FALSE;
|
|
|
|
}
|
|
|
|
return eina_strlcpy(buf, home, size) < size;
|
|
|
|
}
|
|
|
|
|
2019-09-08 10:28:52 -07:00
|
|
|
Eina_Bool
|
|
|
|
utils_need_scale_wizard(void)
|
|
|
|
{
|
|
|
|
static char path[PATH_MAX] = "";
|
|
|
|
struct stat st;
|
|
|
|
int res;
|
2019-09-08 12:18:53 -07:00
|
|
|
char *config_xdg = getenv("ELM_CONFIG_DIR_XDG");
|
2019-09-08 10:28:52 -07:00
|
|
|
|
|
|
|
|
|
|
|
snprintf(path, sizeof(path) -1, "%s/terminology/config/",
|
|
|
|
efreet_config_home_get());
|
|
|
|
res = stat(path, &st);
|
|
|
|
if (res == 0)
|
|
|
|
return EINA_FALSE;
|
|
|
|
|
2019-09-08 12:18:53 -07:00
|
|
|
if (config_xdg)
|
|
|
|
{
|
|
|
|
snprintf(path, sizeof(path) - 1,
|
2019-12-08 07:41:06 -08:00
|
|
|
"%s/elementary/config/standard/base.cfg", config_xdg);
|
2019-09-08 12:18:53 -07:00
|
|
|
}
|
2019-09-08 10:28:52 -07:00
|
|
|
else
|
2019-09-08 12:18:53 -07:00
|
|
|
{
|
2019-12-08 07:41:06 -08:00
|
|
|
const char *suffix = "/.elementary/config/standard/base.cfg";
|
2019-09-08 12:18:53 -07:00
|
|
|
char home[PATH_MAX - strlen(suffix)];
|
|
|
|
|
|
|
|
if (!homedir_get(home, sizeof(home)))
|
|
|
|
return EINA_TRUE;
|
|
|
|
snprintf(path, sizeof(path) - 1,
|
|
|
|
"%s%s", home, suffix);
|
|
|
|
}
|
|
|
|
res = stat(path, &st);
|
2019-09-08 10:28:52 -07:00
|
|
|
if (res == 0)
|
|
|
|
return EINA_FALSE;
|
|
|
|
|
|
|
|
return EINA_TRUE;
|
|
|
|
}
|