summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJaehwan Kim <jae.hwan.kim@samsung.com>2015-06-25 14:04:23 +0900
committerJaehwan Kim <jae.hwan.kim@samsung.com>2015-06-25 14:10:24 +0900
commit6d94fb95096084d89913775269b855303e0ced69 (patch)
tree68d0c05ea8796b3eb4af498e8efedd6a67b66263
parent47b380a1d979b4d0c0ce5718272c80bb492aeb01 (diff)
config: read flush.cfg when elm_config_all_flush is called.
When elm_config_all_flush is called, another processes should get the config of current process instead of saved base.cfg. so current process save the config to flush.cfg and another processes read it when it is changed. @fix
-rw-r--r--src/lib/elm_config.c146
1 files changed, 123 insertions, 23 deletions
diff --git a/src/lib/elm_config.c b/src/lib/elm_config.c
index 676137f1a..b44729692 100644
--- a/src/lib/elm_config.c
+++ b/src/lib/elm_config.c
@@ -116,7 +116,6 @@ static void _config_free(Elm_Config *cfg);
116static void _config_apply(void); 116static void _config_apply(void);
117static void _config_sub_apply(void); 117static void _config_sub_apply(void);
118static void _config_update(void); 118static void _config_update(void);
119static void _config_get(void);
120static void _env_get(void); 119static void _env_get(void);
121static void _color_overlays_cancel(void); 120static void _color_overlays_cancel(void);
122 121
@@ -1468,13 +1467,53 @@ _config_load(void)
1468} 1467}
1469 1468
1470static void 1469static void
1471_config_get(void) 1470_config_flush_load(void)
1471{
1472 Elm_Config *cfg = NULL;
1473 Eet_File *ef;
1474 char buf[PATH_MAX];
1475
1476 _elm_config_user_dir_snprintf(buf, sizeof(buf), "config/flush.cfg");
1477
1478 ef = eet_open(buf, EET_FILE_MODE_READ);
1479 if (ef)
1480 {
1481 cfg = eet_data_read(ef, _config_edd, "config");
1482 eet_close(ef);
1483 }
1484
1485 if (cfg)
1486 {
1487 size_t len;
1488
1489 len = _elm_config_user_dir_snprintf(buf, sizeof(buf), "themes/");
1490 if (len + 1 < sizeof(buf))
1491 ecore_file_mkpath(buf);
1492
1493 _elm_config = cfg;
1494
1495 if ((_elm_config->config_version >> ELM_CONFIG_VERSION_EPOCH_OFFSET) < ELM_CONFIG_EPOCH)
1496 {
1497 WRN("User's elementary config seems outdated and unusable. Fallback to load system config.");
1498 _config_free(_elm_config);
1499 _elm_config = NULL;
1500 }
1501 else
1502 {
1503 if (_elm_config->config_version < ELM_CONFIG_VERSION)
1504 _config_update();
1505 }
1506 }
1507}
1508
1509static void
1510_config_flush_get(void)
1472{ 1511{
1473 _elm_config_font_overlays_cancel(); 1512 _elm_config_font_overlays_cancel();
1474 _color_overlays_cancel(); 1513 _color_overlays_cancel();
1475 _config_free(_elm_config); 1514 _config_free(_elm_config);
1476 _elm_config = NULL; 1515 _elm_config = NULL;
1477 _config_load(); 1516 _config_flush_load();
1478 _env_get(); 1517 _env_get();
1479 _config_apply(); 1518 _config_apply();
1480 _config_sub_apply(); 1519 _config_sub_apply();
@@ -3062,16 +3101,83 @@ elm_config_window_auto_focus_animate_set(Eina_Bool enable)
3062EAPI void 3101EAPI void
3063elm_config_all_flush(void) 3102elm_config_all_flush(void)
3064{ 3103{
3065 FILE *f; 3104 char buf[4096], buf2[4096];
3066 char buf[PATH_MAX]; 3105 int ok = 0, ret;
3106 const char *err;
3107 Eet_File *ef;
3108 size_t len;
3109
3110 len = _elm_config_user_dir_snprintf(buf, sizeof(buf), "themes/");
3111 if (len + 1 >= sizeof(buf))
3112 return;
3113
3114 ok = ecore_file_mkpath(buf);
3115 if (!ok)
3116 {
3117 ERR("Problem accessing Elementary's user configuration directory: %s",
3118 buf);
3119 return;
3120 }
3121
3122 len = _elm_config_user_dir_snprintf(buf, sizeof(buf), "config");
3123 if (len + 1 >= sizeof(buf))
3124 return;
3125
3126 ok = ecore_file_mkpath(buf);
3127 if (!ok)
3128 {
3129 ERR("Problem accessing Elementary's user configuration directory: %s",
3130 buf);
3131 return;
3132 }
3133
3134 if (!_elm_config_profile_save())
3135 return;
3136
3137 buf[len] = '/';
3138 len++;
3139
3140 if (len + sizeof("flush.cfg") >= sizeof(buf) - len)
3141 return;
3142
3143 memcpy(buf + len, "flush.cfg", sizeof("flush.cfg"));
3144 len += sizeof("flush.cfg") - 1;
3145
3146 if (len + sizeof(".tmp") >= sizeof(buf))
3147 return;
3148
3149 memcpy(buf2, buf, len);
3150 memcpy(buf2 + len, ".tmp", sizeof(".tmp"));
3151
3152 ef = eet_open(buf2, EET_FILE_MODE_WRITE);
3153 if (!ef)
3154 return;
3067 3155
3068 _elm_config_user_dir_snprintf(buf, sizeof(buf), "config/flush"); 3156 ok = eet_data_write(ef, _config_edd, "config", _elm_config, 1);
3069 f = fopen(buf, "w+"); 3157 if (!ok)
3070 if (f) 3158 goto err;
3159
3160 err = _elm_config_eet_close_error_get(ef, buf2);
3161 if (err)
3071 { 3162 {
3072 fprintf(f, "flush"); 3163 ERR("%s", err);
3073 fclose(f); 3164 free((void *)err);
3165 goto err;
3074 } 3166 }
3167
3168 ret = ecore_file_mv(buf2, buf);
3169 if (!ret)
3170 {
3171 ERR("Error saving Elementary's configuration file");
3172 goto err;
3173 }
3174
3175 ecore_file_unlink(buf2);
3176 return;
3177
3178err:
3179 ecore_file_unlink(buf2);
3180 return;
3075} 3181}
3076 3182
3077static void 3183static void
@@ -3134,7 +3240,10 @@ _elm_config_sub_shutdown(void)
3134static Eina_Bool 3240static Eina_Bool
3135_config_change_delay_cb(void *data EINA_UNUSED) 3241_config_change_delay_cb(void *data EINA_UNUSED)
3136{ 3242{
3137 _config_get(); 3243 char buf[PATH_MAX];
3244
3245 _elm_config_user_dir_snprintf(buf, sizeof(buf), "config/flush.cfg");
3246 if (ecore_file_exists(buf)) _config_flush_get();
3138 _config_change_delay_timer = NULL; 3247 _config_change_delay_timer = NULL;
3139 3248
3140 return ECORE_CALLBACK_CANCEL; 3249 return ECORE_CALLBACK_CANCEL;
@@ -3229,7 +3338,7 @@ _elm_config_sub_init(void)
3229 int ok = 0; 3338 int ok = 0;
3230 3339
3231 len = _elm_config_user_dir_snprintf(buf, sizeof(buf), "config/"); 3340 len = _elm_config_user_dir_snprintf(buf, sizeof(buf), "config/");
3232 if (len + 6 >= sizeof(buf)) // the space to add "flush" 3341 if (len + 10 >= sizeof(buf)) // the space to add "flush.cfg"
3233 goto end; 3342 goto end;
3234 3343
3235 ok = ecore_file_mkpath(buf); 3344 ok = ecore_file_mkpath(buf);
@@ -3240,18 +3349,9 @@ _elm_config_sub_init(void)
3240 goto end; 3349 goto end;
3241 } 3350 }
3242 3351
3243 strcat(buf, "flush"); 3352 strcat(buf, "flush.cfg");
3244 if (!ecore_file_exists(buf)) 3353 if (!ecore_file_exists(buf)) elm_config_all_flush();
3245 {
3246 FILE *f = fopen(buf, "w+");
3247 3354
3248 if (f)
3249 {
3250 fprintf(f, "flush");
3251 fclose(f);
3252 goto end;
3253 }
3254 }
3255 _eio_monitor = eio_monitor_add(buf); 3355 _eio_monitor = eio_monitor_add(buf);
3256 ecore_event_handler_add(EIO_MONITOR_FILE_MODIFIED, _elm_config_file_monitor_cb, NULL); 3356 ecore_event_handler_add(EIO_MONITOR_FILE_MODIFIED, _elm_config_file_monitor_cb, NULL);
3257 3357