#include <Elementary.h>
#include "elm_priv.h"
#include <pwd.h>
-#include <fcntl.h>
-
#include "efl_config_global.eo.h"
Eina_Bool _config_profile_lock = EINA_FALSE;
static Ecore_Timer *_config_change_delay_timer = NULL;
static Ecore_Timer *_config_profile_change_delay_timer = NULL;
-static Ecore_Event_Handler *_monitor_file_modified_handler = NULL;
+static Ecore_Event_Handler *_monitor_file_created_handler = NULL;
+static Ecore_Event_Handler *_monitor_directory_created_handler = NULL;
static Eio_Monitor *_eio_config_monitor = NULL;
static Eio_Monitor *_eio_profile_monitor = NULL;
static void _config_update(void);
static void _env_get(void);
static void _color_overlays_cancel(void);
-static Eina_Bool _file_touch(const char *file);
#define ELM_CONFIG_VAL(edd, type, member, dtype) \
EET_DATA_DESCRIPTOR_ADD_BASIC(edd, type, #member, member, dtype)
}
static Elm_Config *
-_config_user_load(Eina_Bool on_flush)
+_config_user_load(void)
{
Elm_Config *cfg = NULL;
Eet_File *ef;
char buf[PATH_MAX];
- if (on_flush)
- _elm_config_user_dir_snprintf(buf, sizeof(buf), "config/%s/.base.flush.cfg",
- _elm_profile);
+ _elm_config_user_dir_snprintf(buf, sizeof(buf), "config/%s",
+ _elm_profile);
+ ecore_file_mkpath(buf);
+ if (_eio_config_monitor) eio_monitor_del(_eio_config_monitor);
+ _eio_config_monitor = eio_monitor_add(buf);
- if ((on_flush && !ecore_file_exists(buf)) || !on_flush)
- _elm_config_user_dir_snprintf(buf, sizeof(buf), "config/%s/base.cfg",
- _elm_profile);
+ _elm_config_user_dir_snprintf(buf, sizeof(buf), "config/%s/base.cfg",
+ _elm_profile);
ef = eet_open(buf, EET_FILE_MODE_READ);
if (ef)
}
static void
-_config_load(Eina_Bool on_flush)
+_config_load(void)
{
if (_efl_config_obj)
{
efl_del_intercept_set(_efl_config_obj, _efl_config_obj_del);
if (!_use_build_config)
{
- _elm_config = _config_user_load(on_flush);
+ _elm_config = _config_user_load();
if (_elm_config)
{
if ((_elm_config->config_version >> ELM_CONFIG_VERSION_EPOCH_OFFSET) < ELM_CONFIG_EPOCH)
}
static void
-_elm_config_reload_do(Eina_Bool on_flush)
+_elm_config_reload_do(void)
{
Elm_Config *prev_config;
prev_config = _elm_config;
_elm_config = NULL;
- _config_load(on_flush);
+ _config_load();
if ((prev_config) && (_elm_config))
{
#define KEEP_VAL(xxx) \
_elm_config_font_overlays_cancel();
_color_overlays_cancel();
- _elm_config_reload_do(EINA_TRUE);
+ _elm_config_reload_do();
/* restore prev value which is not part of the EET file */
_elm_config->is_mirrored = is_mirrored;
return NULL;
}
-static char *
-_elm_config_profile_name_get()
-{
- char buf[PATH_MAX], *p;
- Eet_File *ef = NULL;
- int len = 0;
- char *rst = NULL;
-
- _elm_config_user_dir_snprintf(buf, sizeof(buf), "config/profile.cfg");
-
- ef = eet_open(buf, EET_FILE_MODE_READ);
- if (ef)
- {
- p = eet_read(ef, "config", &len);
- if (p)
- {
- rst = calloc(1, len+1);
- memcpy(rst, p, len);
- rst[len] = '\0';
- free(p);
- }
- eet_close(ef);
- }
-
- if (rst)
- return rst;
- else
- return strdup("default");
-}
-
static Eina_Bool
_elm_config_profile_save(const char *profile)
{
const char *err, *s;
Eet_File *ef;
size_t len;
- char *_file_profile = NULL;
if ((s = getenv("ELM_PROFILE_NOSAVE")) && atoi(s))
return EINA_TRUE;
- _file_profile = _elm_config_profile_name_get();
-
- if (!_file_profile || strcmp(_elm_profile, _file_profile))
- {
- len = _elm_config_user_dir_snprintf(buf, sizeof(buf), "config/profile.cfg");
- if (len + 1 >= sizeof(buf))
- return EINA_FALSE;
-
- len = _elm_config_user_dir_snprintf(buf2, sizeof(buf2),
- "config/profile.cfg.tmp");
- if (len + 1 >= sizeof(buf2))
- return EINA_FALSE;
+ len = _elm_config_user_dir_snprintf(buf, sizeof(buf), "config/profile.cfg");
+ if (len + 1 >= sizeof(buf))
+ return EINA_FALSE;
- ef = eet_open(buf2, EET_FILE_MODE_WRITE);
- if (!ef)
- return EINA_FALSE;
+ len = _elm_config_user_dir_snprintf(buf2, sizeof(buf2),
+ "config/profile.cfg.tmp");
+ if (len + 1 >= sizeof(buf2))
+ return EINA_FALSE;
- ok = eet_write(ef, "config", _elm_profile, strlen(_elm_profile), 0);
- if (!ok)
- goto err;
+ ef = eet_open(buf2, EET_FILE_MODE_WRITE);
+ if (!ef)
+ return EINA_FALSE;
- err = _elm_config_eet_close_error_get(ef, buf2);
- if (err)
- {
- ERR("%s", err);
- free((void *)err);
- goto err;
- }
+ ok = eet_write(ef, "config", _elm_profile, strlen(_elm_profile), 0);
+ if (!ok)
+ goto err;
- ret = ecore_file_cp(buf2, buf);
- if (!ret)
- {
- ERR("Error saving Elementary's configuration profile file");
- goto err;
- }
+ err = _elm_config_eet_close_error_get(ef, buf2);
+ if (err)
+ {
+ ERR("%s", err);
+ free((void *)err);
+ goto err;
+ }
- ecore_file_unlink(buf2);
+ ret = ecore_file_cp(buf2, buf);
+ if (!ret)
+ {
+ ERR("Error saving Elementary's configuration profile file");
+ goto err;
}
- free(_file_profile);
+
+ ecore_file_unlink(buf2);
derived = _elm_config_derived_load(profile ? profile : _elm_profile);
if (derived)
eina_stringshare_replace(&_elm_config->engine, s);
else if ((!strcasecmp(s, "ews")))
eina_stringshare_replace(&_elm_config->engine, ELM_EWS);
- else if ((!strcasecmp(s, "wayland_shm")) ||
+ else if ((!strcasecmp(s, "wayland_shm")) ||
(!strcasecmp(s, "wayland-shm")))
eina_stringshare_replace(&_elm_config->engine, ELM_WAYLAND_SHM);
- else if ((!strcasecmp(s, "wayland_egl")) ||
+ else if ((!strcasecmp(s, "wayland_egl")) ||
(!strcasecmp(s, "wayland-egl")))
eina_stringshare_replace(&_elm_config->engine, ELM_WAYLAND_EGL);
else if ((!strcasecmp(s, "drm")))
EAPI void
elm_config_reload(void)
{
- _elm_config_reload(EINA_FALSE);
+ _elm_config_reload();
}
EAPI const char *
EAPI void
elm_config_all_flush(void)
{
- char buf[PATH_MAX], buf2[PATH_MAX];
+ char buf[PATH_MAX];
int ok = 0;
size_t len;
- Eet_File *ef = NULL;
len = _elm_config_user_dir_snprintf(buf, sizeof(buf), "themes/");
if (len + 1 >= sizeof(buf))
return;
}
- _elm_config_user_dir_snprintf(buf, sizeof(buf),
- "config/%s/.base.flush.cfg.tmp", _elm_profile);
-
- _elm_config_user_dir_snprintf(buf2, sizeof(buf2),
- "config/%s/.base.flush.cfg", _elm_profile);
-
- ef = eet_open(buf, EET_FILE_MODE_WRITE);
- if (ef)
- {
- ok = eet_data_write(ef, _config_edd, "config", _elm_config, 1);
- if (!ok)
- {
- eet_close(ef);
- ERR("Failed to save config");
- return;
- }
- eet_close(ef);
- ecore_file_cp(buf, buf2);
- }
- ecore_file_unlink(buf);
-
elm_config_save();
return;
}
_desc_init();
_elm_config_profile_derived_init();
_profile_fetch_from_conf();
- _config_load(EINA_FALSE);
+ _config_load();
if (_elm_config) _env_get();
ELM_SAFE_FREE(_elm_accel_preference, eina_stringshare_del);
ELM_SAFE_FREE(_elm_gl_preference, eina_stringshare_del);
ELM_SAFE_FREE(_eio_profile_monitor, eio_monitor_del);
ELM_SAFE_FREE(_config_change_delay_timer, ecore_timer_del);
ELM_SAFE_FREE(_config_profile_change_delay_timer, ecore_timer_del);
- ELM_SAFE_FREE(_monitor_file_modified_handler, ecore_event_handler_del);
+ ELM_SAFE_FREE(_monitor_file_created_handler, ecore_event_handler_del);
+ ELM_SAFE_FREE(_monitor_directory_created_handler, ecore_event_handler_del);
}
static Eina_Bool
_config_profile_change_delay_cb(void *data EINA_UNUSED)
{
char *pprof = NULL;
- char buf[PATH_MAX];
if (_elm_profile) pprof = strdup(_elm_profile);
_profile_fetch_from_conf();
-
- _elm_config_user_dir_snprintf(buf, sizeof(buf), "config/%s/base.cfg", _elm_profile);
- if(!ecore_file_exists(buf)) _file_touch(buf);
-
- _elm_config_user_dir_snprintf(buf, sizeof(buf), "config/%s/.base.flush.cfg", _elm_profile);
- if(!ecore_file_exists(buf)) _file_touch(buf);
-
- ELM_SAFE_FREE(_eio_config_monitor, eio_monitor_del);
- _eio_config_monitor = eio_monitor_add(buf);
-
if ((!pprof) || (!(!strcmp(pprof, _elm_profile))))
{
_config_flush_get();
static Eina_Bool
_config_change_delay_cb(void *data EINA_UNUSED)
{
- _elm_config_reload(EINA_TRUE);
+ _elm_config_reload();
_config_change_delay_timer = NULL;
return ECORE_CALLBACK_CANCEL;
if (ev->monitor == _eio_config_monitor)
{
- if (!strcmp(file, ".base.flush.cfg"))
+ if (type == EIO_MONITOR_FILE_CREATED)
{
- if (_config_change_delay_timer)
- ecore_timer_del(_config_change_delay_timer);
- _config_change_delay_timer = ecore_timer_add(0.1, _config_change_delay_cb, NULL);
+ if (!strcmp(file, "base.cfg"))
+ {
+ if (_config_change_delay_timer)
+ ecore_timer_del(_config_change_delay_timer);
+ _config_change_delay_timer = ecore_timer_add(0.1, _config_change_delay_cb, NULL);
+ }
}
}
-
if (ev->monitor == _eio_profile_monitor)
{
- if (!strcmp(file, "profile.cfg"))
+ if (type == EIO_MONITOR_FILE_CREATED)
+ {
+ if ((!_config_profile_lock) && (!strcmp(file, "profile.cfg")))
+ {
+ if (_config_profile_change_delay_timer)
+ ecore_timer_del(_config_profile_change_delay_timer);
+ _config_profile_change_delay_timer = ecore_timer_add(0.1, _config_profile_change_delay_cb, NULL);
+ }
+ }
+ else if (type == EIO_MONITOR_DIRECTORY_CREATED)
{
- if (_config_profile_change_delay_timer)
- ecore_timer_del(_config_profile_change_delay_timer);
- _config_profile_change_delay_timer = ecore_timer_add(0.1, _config_profile_change_delay_cb, NULL);
+ if (!_eio_config_monitor)
+ {
+ char buf[PATH_MAX];
+
+ _eio_config_monitor = eio_monitor_add(ev->filename);
+ snprintf(buf, sizeof(buf), "%s/base.cfg", ev->filename);
+ if (ecore_file_exists(buf))
+ {
+ if (_config_change_delay_timer)
+ ecore_timer_del(_config_change_delay_timer);
+ _config_change_delay_timer = ecore_timer_add(0.1, _config_change_delay_cb, NULL);
+ }
+ }
}
}
buf);
goto end;
}
-
- _elm_config_profile_save(NULL);
-
- _elm_config_user_dir_snprintf(buf, sizeof(buf), "config/profile.cfg");
- if(!ecore_file_exists(buf)) _file_touch(buf);
_eio_profile_monitor = eio_monitor_add(buf);
-
- _elm_config_user_dir_snprintf(buf, sizeof(buf), "config/%s/base.cfg", _elm_profile);
- if(!ecore_file_exists(buf)) _file_touch(buf);
-
- _elm_config_user_dir_snprintf(buf, sizeof(buf), "config/%s/.base.flush.cfg", _elm_profile);
- if(!ecore_file_exists(buf)) _file_touch(buf);
- _eio_config_monitor = eio_monitor_add(buf);
-
- _monitor_file_modified_handler = ecore_event_handler_add
- (EIO_MONITOR_FILE_MODIFIED, _elm_config_file_monitor_cb, NULL);
+ _monitor_file_created_handler = ecore_event_handler_add
+ (EIO_MONITOR_FILE_CREATED, _elm_config_file_monitor_cb, NULL);
+ _monitor_directory_created_handler = ecore_event_handler_add
+ (EIO_MONITOR_DIRECTORY_CREATED, _elm_config_file_monitor_cb, NULL);
end:
_config_sub_apply();
}
void
-_elm_config_reload(Eina_Bool on_flush)
+_elm_config_reload(void)
{
Eina_Bool is_mirrored;
Eina_Bool translate;
is_mirrored = _elm_config->is_mirrored;
translate = _elm_config->translate;
- _elm_config_reload_do(on_flush);
-
+ _elm_config_reload_do();
+
/* restore prev value which is not part of the EET file */
_elm_config->is_mirrored = is_mirrored;
_elm_config->translate = translate;
Eina_Bool translate;
is_mirrored = _elm_config->is_mirrored;
translate = _elm_config->translate;
- char buf[PATH_MAX];
if (!profile) return;
_elm_profile = strdup(profile);
- _elm_config_user_dir_snprintf(buf, sizeof(buf), "config/%s/base.cfg", _elm_profile);
- if(!ecore_file_exists(buf)) _file_touch(buf);
-
- _elm_config_user_dir_snprintf(buf, sizeof(buf), "config/%s/.base.flush.cfg", _elm_profile);
- if(!ecore_file_exists(buf)) _file_touch(buf);
-
_color_overlays_cancel();
- _elm_config_reload_do(EINA_FALSE);
+ _elm_config_reload_do();
/* restore prev value which is not part of the EET file */
_elm_config->is_mirrored = is_mirrored;
_efl_config_global_profile_derived_del(Eo *obj EINA_UNUSED, void *_pd EINA_UNUSED, const char *profile)
{
elm_config_profile_derived_del(profile);
-
-}
-static Eina_Bool
-_file_touch(const char *file)
-{
- if (!file) return EINA_FALSE;
-
- const char *dir = ecore_file_dir_get(file);
- if(!dir) return EINA_FALSE;
- if(!ecore_file_mkpath(dir)) return EINA_FALSE;
-
- Eo *f = efl_add_ref(EFL_IO_FILE_CLASS, NULL,
- efl_file_set(efl_added, file, NULL),
- efl_io_file_flags_set(efl_added, O_CREAT|O_RDWR),
- efl_io_file_mode_set(efl_added, 0644));
- if (!f) return EINA_FALSE;
- efl_unref(f);
-
- return EINA_TRUE;
}
#include "efl_config_global.eo.c"