elementary/dayselector - New widget Elc_dayselector
[framework/uifw/elementary.git] / src / lib / elm_config.c
1 #ifdef HAVE_CONFIG_H
2 # include "elementary_config.h"
3 #endif
4
5 #ifdef HAVE_EVIL
6 # include <Evil.h>
7 #endif
8
9 #include <Elementary.h>
10 #include "elm_priv.h"
11
12 EAPI int ELM_EVENT_CONFIG_ALL_CHANGED = 0;
13
14 Elm_Config *_elm_config = NULL;
15 char *_elm_profile = NULL;
16 static Eet_Data_Descriptor *_config_edd = NULL;
17 static Eet_Data_Descriptor *_config_font_overlay_edd = NULL;
18 const char *_elm_preferred_engine = NULL;
19
20 static Ecore_Poller *_elm_cache_flush_poller = NULL;
21
22 const char *_elm_engines[] = {
23    "software_x11",
24    "fb",
25    "directfb",
26    "software_16_x11",
27    "software_8_x11",
28    "xrender_x11",
29    "opengl_x11",
30    "software_gdi",
31    "software_16_wince_gdi",
32    "sdl",
33    "software_16_sdl",
34    "opengl_sdl",
35    "buffer",
36    "ews",
37    "opengl_cocoa",
38    "psl1ght",
39    "wayland_shm",
40    "wayland_egl",
41    NULL
42 };
43
44 /* whenever you want to add a new text class support into Elementary,
45    declare it both here and in the (default) theme */
46 static const Elm_Text_Class _elm_text_classes[] = {
47    {"button", "Button Labels"},
48    {"label", "Text Labels"},
49    {"entry", "Text Entries"},
50    {"title_bar", "Title Bar"},
51    {"list_item", "List Items"},
52    {"grid_item", "Grid Items"},
53    {"toolbar_item", "Toolbar Items"},
54    {"menu_item", "Menu Items"},
55    {NULL, NULL}
56 };
57
58 static void        _desc_init(void);
59 static void        _desc_shutdown(void);
60 static void        _profile_fetch_from_conf(void);
61 static void        _config_free(void);
62 static void        _config_apply(void);
63 static Elm_Config *_config_user_load(void);
64 static Elm_Config *_config_system_load(void);
65 static void        _config_load(void);
66 static void        _config_update(void);
67 static void        _env_get(void);
68 static size_t      _elm_data_dir_snprintf(char       *dst,
69                                           size_t      size,
70                                           const char *fmt, ...)
71                                           EINA_PRINTF(3, 4);
72 static size_t _elm_user_dir_snprintf(char       *dst,
73                                      size_t      size,
74                                      const char *fmt, ...)
75                                      EINA_PRINTF(3, 4);
76
77 #define ELM_CONFIG_VAL(edd, type, member, dtype) \
78   EET_DATA_DESCRIPTOR_ADD_BASIC(edd, type, #member, member, dtype)
79 #define ELM_CONFIG_LIST(edd, type, member, eddtype) \
80   EET_DATA_DESCRIPTOR_ADD_LIST(edd, type, #member, member, eddtype)
81
82 #ifdef HAVE_ELEMENTARY_X
83 static Ecore_Event_Handler *_prop_change_handler = NULL;
84 static Ecore_Timer *_prop_all_update_timer = NULL;
85 static Ecore_Timer *_prop_change_delay_timer = NULL;
86 static Ecore_X_Window _root_1st = 0;
87 #define ATOM_COUNT 2
88 static Ecore_X_Atom _atom[ATOM_COUNT];
89 static Ecore_X_Atom _atom_config = 0;
90 static const char *_atom_names[ATOM_COUNT] =
91 {
92    "ELM_PROFILE",
93    "ELM_CONFIG"
94 };
95 #define ATOM_E_PROFILE                              0
96 #define ATOM_E_CONFIG                               1
97
98 static Eina_Bool _prop_all_update_cb(void *data __UNUSED__);
99 static Eina_Bool _prop_config_get(void);
100 static void      _prop_config_set(void);
101 static Eina_Bool _prop_change(void *data  __UNUSED__,
102                               int ev_type __UNUSED__,
103                               void       *ev);
104
105 static Eina_Bool
106 _prop_all_update_cb(void *data __UNUSED__)
107 {
108    _prop_config_set();
109    ecore_x_window_prop_string_set(_root_1st, _atom[ATOM_E_PROFILE],
110                                   _elm_profile);
111    _prop_all_update_timer = NULL;
112    return EINA_FALSE;
113 }
114
115 static Eina_Bool
116 _prop_config_get(void)
117 {
118    int size = 0;
119    Ecore_X_Atom atom;
120    char buf[512];
121    unsigned char *data = NULL;
122    Elm_Config *config_data;
123
124    snprintf(buf, sizeof(buf), "ELM_CONFIG_%s", _elm_profile);
125    atom = ecore_x_atom_get(buf);
126    _atom_config = atom;
127    if (!ecore_x_window_prop_property_get(_root_1st,
128                                          atom, _atom[ATOM_E_CONFIG],
129                                          8, &data, &size))
130      {
131         if (!ecore_x_window_prop_property_get(_root_1st,
132                                               _atom[ATOM_E_CONFIG],
133                                               _atom[ATOM_E_CONFIG],
134                                               8, &data, &size))
135           return EINA_FALSE;
136         else
137           _atom_config = _atom[ATOM_E_CONFIG];
138      }
139    else
140      _atom_config = atom;
141    if (size < 1)
142      {
143         free(data);
144         return EINA_FALSE;
145      }
146    config_data = eet_data_descriptor_decode(_config_edd, data, size);
147    free(data);
148    if (!config_data) return EINA_FALSE;
149
150    /* What do we do on version mismatch when someone changes the
151     * config in the rootwindow? */
152    /* Most obvious case, new version and we are still linked to
153     * whatever was there before, we just ignore until user restarts us */
154    if (config_data->config_version > ELM_CONFIG_VERSION)
155      return EINA_TRUE;
156    /* What in the case the version is older? Do we even support those
157     * cases or we only check for equality above? */
158
159    _config_free();
160    _elm_config = config_data;
161    _config_apply();
162    _elm_config_font_overlay_apply();
163    _elm_rescale();
164    _elm_recache();
165    ecore_event_add(ELM_EVENT_CONFIG_ALL_CHANGED, NULL, NULL, NULL);
166    return EINA_TRUE;
167 }
168
169 static void
170 _prop_config_set(void)
171 {
172    unsigned char *config_data = NULL;
173    int size = 0;
174
175    config_data = eet_data_descriptor_encode(_config_edd, _elm_config, &size);
176    if (config_data)
177      {
178         Ecore_X_Atom atom;
179         char buf[512];
180
181         snprintf(buf, sizeof(buf), "ELM_CONFIG_%s", _elm_profile);
182         atom = ecore_x_atom_get(buf);
183         _atom_config = atom;
184
185         ecore_x_window_prop_property_set(_root_1st, _atom_config,
186                                          _atom[ATOM_E_CONFIG], 8,
187                                          config_data, size);
188         free(config_data);
189      }
190 }
191
192 static Eina_Bool
193 _prop_change_delay_cb(void *data __UNUSED__)
194 {
195    char *s;
196
197    s = ecore_x_window_prop_string_get(_root_1st, _atom[ATOM_E_PROFILE]);
198    if (s)
199      {
200         if (_elm_profile) free(_elm_profile);
201         _elm_profile = s;
202      }
203    _prop_config_get();
204    _prop_change_delay_timer = NULL;
205    return EINA_FALSE;
206 }
207
208 static Eina_Bool
209 _prop_change(void *data  __UNUSED__,
210              int ev_type __UNUSED__,
211              void       *ev)
212 {
213    Ecore_X_Event_Window_Property *event = ev;
214
215    if (event->win == _root_1st)
216      {
217         if (event->atom == _atom[ATOM_E_PROFILE])
218           {
219              if (_prop_change_delay_timer) ecore_timer_del(_prop_change_delay_timer);
220              _prop_change_delay_timer = ecore_timer_add(0.1, _prop_change_delay_cb, NULL);
221           }
222         else if (((_atom_config > 0) && (event->atom == _atom_config)) ||
223                  (event->atom == _atom[ATOM_E_CONFIG]))
224           {
225              if (_prop_change_delay_timer) ecore_timer_del(_prop_change_delay_timer);
226              _prop_change_delay_timer = ecore_timer_add(0.1, _prop_change_delay_cb, NULL);
227           }
228      }
229    return ECORE_CALLBACK_PASS_ON;
230 }
231
232 #endif
233
234 static void
235 _desc_init(void)
236 {
237    Eet_Data_Descriptor_Class eddc;
238
239    EET_EINA_FILE_DATA_DESCRIPTOR_CLASS_SET(&eddc, Elm_Config);
240    eddc.func.str_direct_alloc = NULL;
241    eddc.func.str_direct_free = NULL;
242
243    _config_edd = eet_data_descriptor_file_new(&eddc);
244    if (!_config_edd)
245      {
246         printf("EEEK! eet_data_descriptor_file_new() failed\n");
247         return;
248      }
249
250    memset(&eddc, 0, sizeof(eddc)); /* just in case... */
251    EET_EINA_STREAM_DATA_DESCRIPTOR_CLASS_SET(&eddc, Elm_Font_Overlay);
252    eddc.func.str_direct_alloc = NULL;
253    eddc.func.str_direct_free = NULL;
254
255    _config_font_overlay_edd = eet_data_descriptor_stream_new(&eddc);
256    if (!_config_font_overlay_edd)
257      {
258         printf("EEEK! eet_data_descriptor_stream_new() failed\n");
259         eet_data_descriptor_free(_config_edd);
260         return;
261      }
262 #define T_INT    EET_T_INT
263 #define T_DOUBLE EET_T_DOUBLE
264 #define T_STRING EET_T_STRING
265 #define T_UCHAR  EET_T_UCHAR
266
267 #define T        Elm_Font_Overlay
268 #define D        _config_font_overlay_edd
269    ELM_CONFIG_VAL(D, T, text_class, EET_T_STRING);
270    ELM_CONFIG_VAL(D, T, font, EET_T_STRING);
271    ELM_CONFIG_VAL(D, T, size, EET_T_INT);
272 #undef T
273 #undef D
274
275 #define T Elm_Config
276 #define D _config_edd
277    ELM_CONFIG_VAL(D, T, config_version, T_INT);
278    ELM_CONFIG_VAL(D, T, engine, T_STRING);
279    ELM_CONFIG_VAL(D, T, vsync, T_UCHAR);
280    ELM_CONFIG_VAL(D, T, thumbscroll_enable, T_UCHAR);
281    ELM_CONFIG_VAL(D, T, thumbscroll_threshold, T_INT);
282    ELM_CONFIG_VAL(D, T, thumbscroll_momentum_threshold, T_DOUBLE);
283    ELM_CONFIG_VAL(D, T, thumbscroll_friction, T_DOUBLE);
284    ELM_CONFIG_VAL(D, T, thumbscroll_bounce_friction, T_DOUBLE);
285    ELM_CONFIG_VAL(D, T, thumbscroll_border_friction, T_DOUBLE);
286    ELM_CONFIG_VAL(D, T, thumbscroll_sensitivity_friction, T_DOUBLE);
287    ELM_CONFIG_VAL(D, T, page_scroll_friction, T_DOUBLE);
288    ELM_CONFIG_VAL(D, T, bring_in_scroll_friction, T_DOUBLE);
289    ELM_CONFIG_VAL(D, T, zoom_friction, T_DOUBLE);
290    ELM_CONFIG_VAL(D, T, thumbscroll_bounce_enable, T_UCHAR);
291    ELM_CONFIG_VAL(D, T, scroll_smooth_amount, T_DOUBLE);
292    ELM_CONFIG_VAL(D, T, scroll_smooth_history_weight, T_DOUBLE);
293    ELM_CONFIG_VAL(D, T, scroll_smooth_future_time, T_DOUBLE);
294    ELM_CONFIG_VAL(D, T, scroll_smooth_time_window, T_DOUBLE);
295    ELM_CONFIG_VAL(D, T, scale, T_DOUBLE);
296    ELM_CONFIG_VAL(D, T, bgpixmap, T_INT);
297    ELM_CONFIG_VAL(D, T, compositing, T_INT);
298    /* EET_DATA_DESCRIPTOR_ADD_LIST(D, T, "font_dirs", font_dirs, sub_edd); */
299    ELM_CONFIG_LIST(D, T, font_overlays, _config_font_overlay_edd);
300    ELM_CONFIG_VAL(D, T, font_hinting, T_INT);
301    ELM_CONFIG_VAL(D, T, cache_flush_poll_interval, T_INT);
302    ELM_CONFIG_VAL(D, T, cache_flush_enable, T_UCHAR);
303    ELM_CONFIG_VAL(D, T, image_cache, T_INT);
304    ELM_CONFIG_VAL(D, T, font_cache, T_INT);
305    ELM_CONFIG_VAL(D, T, edje_cache, T_INT);
306    ELM_CONFIG_VAL(D, T, edje_collection_cache, T_INT);
307    ELM_CONFIG_VAL(D, T, finger_size, T_INT);
308    ELM_CONFIG_VAL(D, T, fps, T_DOUBLE);
309    ELM_CONFIG_VAL(D, T, theme, T_STRING);
310    ELM_CONFIG_VAL(D, T, modules, T_STRING);
311    ELM_CONFIG_VAL(D, T, tooltip_delay, T_DOUBLE);
312    ELM_CONFIG_VAL(D, T, cursor_engine_only, T_UCHAR);
313    ELM_CONFIG_VAL(D, T, focus_highlight_enable, T_UCHAR);
314    ELM_CONFIG_VAL(D, T, focus_highlight_animate, T_UCHAR);
315    ELM_CONFIG_VAL(D, T, toolbar_shrink_mode, T_INT);
316    ELM_CONFIG_VAL(D, T, fileselector_expand_enable, T_UCHAR);
317    ELM_CONFIG_VAL(D, T, inwin_dialogs_enable, T_UCHAR);
318    ELM_CONFIG_VAL(D, T, icon_size, T_INT);
319    ELM_CONFIG_VAL(D, T, longpress_timeout, T_DOUBLE);
320    ELM_CONFIG_VAL(D, T, effect_enable, T_UCHAR);
321    ELM_CONFIG_VAL(D, T, desktop_entry, T_UCHAR);
322    ELM_CONFIG_VAL(D, T, password_show_last, T_UCHAR);
323    ELM_CONFIG_VAL(D, T, password_show_last_timeout, T_DOUBLE);
324    ELM_CONFIG_VAL(D, T, glayer_zoom_finger_enable, T_UCHAR);
325    ELM_CONFIG_VAL(D, T, glayer_zoom_finger_factor, T_DOUBLE);
326    ELM_CONFIG_VAL(D, T, glayer_zoom_wheel_factor, T_DOUBLE);
327    ELM_CONFIG_VAL(D, T, glayer_zoom_distance_tolerance, T_DOUBLE);
328    ELM_CONFIG_VAL(D, T, glayer_rotate_finger_enable, T_UCHAR);
329    ELM_CONFIG_VAL(D, T, glayer_rotate_angular_tolerance, T_DOUBLE);
330    ELM_CONFIG_VAL(D, T, glayer_line_min_length, T_DOUBLE);
331    ELM_CONFIG_VAL(D, T, glayer_line_distance_tolerance, T_DOUBLE);
332    ELM_CONFIG_VAL(D, T, glayer_line_angular_tolerance, T_DOUBLE);
333    ELM_CONFIG_VAL(D, T, glayer_flick_time_limit_ms, T_INT);
334    ELM_CONFIG_VAL(D, T, glayer_long_tap_start_timeout, T_DOUBLE);
335    ELM_CONFIG_VAL(D, T, access_mode, T_INT);
336    ELM_CONFIG_VAL(D, T, glayer_continues_enable, T_UCHAR);
337    ELM_CONFIG_VAL(D, T, week_start, T_INT);
338    ELM_CONFIG_VAL(D, T, weekend_start, T_INT);
339    ELM_CONFIG_VAL(D, T, weekend_len, T_INT);
340 #undef T
341 #undef D
342 #undef T_INT
343 #undef T_DOUBLE
344 #undef T_STRING
345 #undef T_UCHAR
346 }
347
348 static void
349 _desc_shutdown(void)
350 {
351    if (_config_edd)
352      {
353         eet_data_descriptor_free(_config_edd);
354         _config_edd = NULL;
355      }
356
357    if (_config_font_overlay_edd)
358      {
359         eet_data_descriptor_free(_config_font_overlay_edd);
360         _config_font_overlay_edd = NULL;
361      }
362 }
363
364 static int
365 _sort_files_cb(const void *f1,
366                const void *f2)
367 {
368    return strcmp(f1, f2);
369 }
370
371 const char *
372 _elm_config_current_profile_get(void)
373 {
374    return _elm_profile;
375 }
376
377 static size_t
378 _elm_data_dir_snprintf(char       *dst,
379                        size_t      size,
380                        const char *fmt,
381                        ...)
382 {
383    size_t data_dir_len, off;
384    va_list ap;
385
386    data_dir_len = eina_strlcpy(dst, _elm_data_dir, size);
387
388    off = data_dir_len + 1;
389    if (off >= size)
390      goto end;
391
392    va_start(ap, fmt);
393    dst[data_dir_len] = '/';
394
395    off = off + vsnprintf(dst + off, size - off, fmt, ap);
396    va_end(ap);
397
398 end:
399    return off;
400 }
401
402 static size_t
403 _elm_user_dir_snprintf(char       *dst,
404                        size_t      size,
405                        const char *fmt,
406                        ...)
407 {
408    const char *home;
409    size_t user_dir_len, off;
410    va_list ap;
411
412 #ifdef _WIN32
413    home = evil_homedir_get();
414 #else
415    home = getenv("HOME");
416 #endif
417    if (!home)
418      home = "/";
419
420    user_dir_len = eina_str_join_len(dst, size, '/', home, strlen(home),
421                                     ELEMENTARY_BASE_DIR, sizeof(ELEMENTARY_BASE_DIR) - 1);
422
423    off = user_dir_len + 1;
424    if (off >= size)
425      goto end;
426
427    va_start(ap, fmt);
428    dst[user_dir_len] = '/';
429
430    off = off + vsnprintf(dst + off, size - off, fmt, ap);
431    va_end(ap);
432
433 end:
434    return off;
435 }
436
437 const char *
438 _elm_config_profile_dir_get(const char *prof,
439                             Eina_Bool   is_user)
440 {
441    char buf[PATH_MAX];
442
443    if (!is_user)
444      goto not_user;
445
446    _elm_user_dir_snprintf(buf, sizeof(buf), "config/%s", prof);
447
448    if (ecore_file_is_dir(buf))
449      return strdup(buf);
450
451    return NULL;
452
453 not_user:
454    snprintf(buf, sizeof(buf), "%s/config/%s", _elm_data_dir, prof);
455
456    if (ecore_file_is_dir(buf))
457      return strdup(buf);
458
459    return NULL;
460 }
461
462 Eina_List *
463 _elm_config_font_overlays_list(void)
464 {
465    return _elm_config->font_overlays;
466 }
467
468 void
469 _elm_config_font_overlay_set(const char    *text_class,
470                              const char    *font,
471                              Evas_Font_Size size)
472 {
473    Elm_Font_Overlay *efd;
474    Eina_List *l;
475
476    EINA_LIST_FOREACH(_elm_config->font_overlays, l, efd)
477      {
478         if (strcmp(efd->text_class, text_class))
479           continue;
480
481         if (efd->font) eina_stringshare_del(efd->font);
482         efd->font = eina_stringshare_add(font);
483         efd->size = size;
484         _elm_config->font_overlays =
485           eina_list_promote_list(_elm_config->font_overlays, l);
486         return;
487      }
488
489    /* the text class doesn't exist */
490    efd = calloc(1, sizeof(Elm_Font_Overlay));
491    efd->text_class = eina_stringshare_add(text_class);
492    efd->font = eina_stringshare_add(font);
493    efd->size = size;
494
495    _elm_config->font_overlays = eina_list_prepend(_elm_config->font_overlays,
496                                                   efd);
497 }
498
499 void
500 _elm_config_font_overlay_remove(const char *text_class)
501 {
502    Elm_Font_Overlay *efd;
503    Eina_List *l;
504
505    EINA_LIST_FOREACH(_elm_config->font_overlays, l, efd)
506      {
507         if (strcmp(efd->text_class, text_class))
508           continue;
509
510         _elm_config->font_overlays =
511           eina_list_remove_list(_elm_config->font_overlays, l);
512         if (efd->text_class) eina_stringshare_del(efd->text_class);
513         if (efd->font) eina_stringshare_del(efd->font);
514         free(efd);
515
516         return;
517      }
518 }
519
520 void
521 _elm_config_font_overlay_apply(void)
522 {
523    Elm_Font_Overlay *efd;
524    Eina_List *l;
525    int i;
526
527    for (i = 0; _elm_text_classes[i].desc; i++)
528      edje_text_class_del(_elm_text_classes[i].name);
529
530    EINA_LIST_FOREACH(_elm_config->font_overlays, l, efd)
531      edje_text_class_set(efd->text_class, efd->font, efd->size);
532 }
533
534 Eina_List *
535 _elm_config_text_classes_get(void)
536 {
537    Eina_List *ret = NULL;
538    int i;
539
540    for (i = 0; _elm_text_classes[i].desc; i++)
541      {
542         Elm_Text_Class *tc;
543         tc = malloc(sizeof(*tc));
544         if (!tc) continue;
545
546         *tc = _elm_text_classes[i];
547
548         ret = eina_list_append(ret, tc);
549      }
550
551    return ret;
552 }
553
554 void
555 _elm_config_text_classes_free(Eina_List *l)
556 {
557    Elm_Text_Class *tc;
558
559    EINA_LIST_FREE(l, tc)
560      free(tc);
561 }
562
563 Eina_List *
564 _elm_config_profiles_list(void)
565 {
566    const Eina_File_Direct_Info *info;
567    Eina_List *flist = NULL;
568    Eina_Iterator *file_it;
569    char buf[PATH_MAX];
570    const char *dir;
571    size_t len;
572
573    len = _elm_user_dir_snprintf(buf, sizeof(buf), "config");
574
575    file_it = eina_file_direct_ls(buf);
576    if (!file_it)
577      goto sys;
578
579    buf[len] = '/';
580    len++;
581
582    len = sizeof(buf) - len;
583
584    EINA_ITERATOR_FOREACH(file_it, info)
585      {
586         if (info->name_length >= len)
587           continue;
588
589         if (info->type == EINA_FILE_DIR)
590           {
591              flist =
592                eina_list_sorted_insert(flist, _sort_files_cb,
593                                        eina_stringshare_add(info->path +
594                                                             info->name_start));
595           }
596      }
597
598    eina_iterator_free(file_it);
599
600 sys:
601    len = eina_str_join_len(buf, sizeof(buf), '/', _elm_data_dir,
602                            strlen(_elm_data_dir), "config",
603                            sizeof("config") - 1);
604
605    file_it = eina_file_direct_ls(buf);
606    if (!file_it)
607      goto list_free;
608
609    buf[len] = '/';
610    len++;
611
612    len = sizeof(buf) - len;
613    EINA_ITERATOR_FOREACH(file_it, info)
614      {
615         if (info->name_length >= len)
616           continue;
617
618         switch (info->type)
619           {
620            case EINA_FILE_DIR:
621            {
622               const Eina_List *l;
623               const char *tmp;
624
625               EINA_LIST_FOREACH(flist, l, tmp)
626                 if (!strcmp(info->path + info->name_start, tmp))
627                   break;
628
629               if (!l)
630                 flist =
631                   eina_list_sorted_insert(flist, _sort_files_cb,
632                                           eina_stringshare_add(info->path +
633                                                                info->name_start));
634            }
635            break;
636
637            default:
638              continue;
639           }
640      }
641    eina_iterator_free(file_it);
642    return flist;
643
644 list_free:
645    EINA_LIST_FREE(flist, dir)
646      eina_stringshare_del(dir);
647
648    return NULL;
649 }
650
651 static void
652 _profile_fetch_from_conf(void)
653 {
654    char buf[PATH_MAX], *p, *s;
655    Eet_File *ef = NULL;
656    int len = 0;
657
658    _elm_profile = strdup("default");
659
660    // if env var - use profile without question
661    s = getenv("ELM_PROFILE");
662    if (s)
663      {
664         free(_elm_profile);
665         _elm_profile = strdup(s);
666         return;
667      }
668
669    // user profile
670    _elm_user_dir_snprintf(buf, sizeof(buf), "config/profile.cfg");
671    ef = eet_open(buf, EET_FILE_MODE_READ);
672    if (ef)
673      {
674         p = eet_read(ef, "config", &len);
675         if (p)
676           {
677              free(_elm_profile);
678              _elm_profile = malloc(len + 1);
679              memcpy(_elm_profile, p, len);
680              _elm_profile[len] = 0;
681              free(p);
682           }
683         eet_close(ef);
684         if (!p) ef = NULL;
685      }
686    if (ef) return;
687
688    // system profile
689    _elm_data_dir_snprintf(buf, sizeof(buf), "config/profile.cfg");
690    ef = eet_open(buf, EET_FILE_MODE_READ);
691    if (ef)
692      {
693         p = eet_read(ef, "config", &len);
694         if (p)
695           {
696              free(_elm_profile);
697              _elm_profile = malloc(len + 1);
698              memcpy(_elm_profile, p, len);
699              _elm_profile[len] = 0;
700              free(p);
701           }
702         eet_close(ef);
703      }
704 }
705
706 static void
707 _config_free(void)
708 {
709    Elm_Font_Overlay *fo;
710    const char *fontdir;
711
712    if (!_elm_config) return;
713    EINA_LIST_FREE(_elm_config->font_dirs, fontdir)
714      {
715         eina_stringshare_del(fontdir);
716      }
717    if (_elm_config->engine) eina_stringshare_del(_elm_config->engine);
718    EINA_LIST_FREE(_elm_config->font_overlays, fo)
719      {
720         if (fo->text_class) eina_stringshare_del(fo->text_class);
721         if (fo->font) eina_stringshare_del(fo->font);
722         free(fo);
723      }
724    if (_elm_config->theme) eina_stringshare_del(_elm_config->theme);
725    if (_elm_config->modules) eina_stringshare_del(_elm_config->modules);
726    free(_elm_config);
727    _elm_config = NULL;
728 }
729
730 static void
731 _config_apply(void)
732 {
733    _elm_theme_parse(NULL, _elm_config->theme);
734    ecore_animator_frametime_set(1.0 / _elm_config->fps);
735 }
736
737 static void
738 _config_sub_apply(void)
739 {
740    edje_frametime_set(1.0 / _elm_config->fps);
741    edje_scale_set(_elm_config->scale);
742    edje_password_show_last_set(_elm_config->password_show_last);
743    edje_password_show_last_timeout_set(_elm_config->password_show_last_timeout);
744    if (_elm_config->modules) _elm_module_parse(_elm_config->modules);
745 }
746
747 static Eina_Bool
748 _elm_cache_flush_cb(void *data __UNUSED__)
749 {
750    elm_cache_all_flush();
751    return ECORE_CALLBACK_RENEW;
752 }
753
754 /* kind of abusing this call right now -- shared between all of those
755  * properties -- but they are not meant to be called that periodically
756  * anyway */
757 void
758 _elm_recache(void)
759 {
760    Eina_List *l;
761    Evas_Object *win;
762
763    elm_cache_all_flush();
764
765    EINA_LIST_FOREACH(_elm_win_list, l, win)
766      {
767         Evas *e = evas_object_evas_get(win);
768         evas_image_cache_set(e, _elm_config->image_cache * 1024);
769         evas_font_cache_set(e, _elm_config->font_cache * 1024);
770      }
771    edje_file_cache_set(_elm_config->edje_cache);
772    edje_collection_cache_set(_elm_config->edje_collection_cache);
773
774    if (_elm_cache_flush_poller)
775      {
776         ecore_poller_del(_elm_cache_flush_poller);
777         _elm_cache_flush_poller = NULL;
778      }
779    if (_elm_config->cache_flush_enable)
780      {
781         if (_elm_config->cache_flush_poll_interval > 0)
782           {
783              _elm_cache_flush_poller =
784                 ecore_poller_add(ECORE_POLLER_CORE,
785                                  _elm_config->cache_flush_poll_interval,
786                                  _elm_cache_flush_cb, NULL);
787           }
788      }
789 }
790
791 static Elm_Config *
792 _config_user_load(void)
793 {
794    Elm_Config *cfg = NULL;
795    Eet_File *ef;
796    char buf[PATH_MAX];
797
798    _elm_user_dir_snprintf(buf, sizeof(buf), "config/%s/base.cfg",
799                           _elm_profile);
800
801    ef = eet_open(buf, EET_FILE_MODE_READ);
802    if (ef)
803      {
804         cfg = eet_data_read(ef, _config_edd, "config");
805         eet_close(ef);
806      }
807    return cfg;
808 }
809
810 static Elm_Config *
811 _config_system_load(void)
812 {
813    Elm_Config *cfg = NULL;
814    Eet_File *ef;
815    char buf[PATH_MAX];
816
817    _elm_data_dir_snprintf(buf, sizeof(buf), "config/%s/base.cfg",
818                           _elm_profile);
819
820    ef = eet_open(buf, EET_FILE_MODE_READ);
821    if (ef)
822      {
823         cfg = eet_data_read(ef, _config_edd, "config");
824         eet_close(ef);
825      }
826    return cfg;
827 }
828
829 static void
830 _config_load(void)
831 {
832    _elm_config = _config_user_load();
833    if (_elm_config)
834      {
835         if (_elm_config->config_version < ELM_CONFIG_VERSION)
836           _config_update();
837         return;
838      }
839
840    /* no user config, fallback for system. No need to check version for
841     * this one, if it's not the right one, someone screwed up at the time
842     * of installing it */
843    _elm_config = _config_system_load();
844    if (_elm_config) return;
845    /* FIXME: config load could have failed because of a non-existent
846     * profile. Fallback to default before moving on */
847
848    // config load fail - defaults
849    // why are these here? well if they are, it means you can make a gui
850    // config recovery app i guess...
851    _elm_config = ELM_NEW(Elm_Config);
852    _elm_config->config_version = ELM_CONFIG_VERSION;
853    _elm_config->engine = eina_stringshare_add("software_x11");
854    _elm_config->vsync = 0;
855    _elm_config->thumbscroll_enable = EINA_TRUE;
856    _elm_config->thumbscroll_threshold = 24;
857    _elm_config->thumbscroll_momentum_threshold = 100.0;
858    _elm_config->thumbscroll_friction = 1.0;
859    _elm_config->thumbscroll_bounce_friction = 0.5;
860    _elm_config->thumbscroll_bounce_enable = EINA_TRUE;
861    _elm_config->page_scroll_friction = 0.5;
862    _elm_config->bring_in_scroll_friction = 0.5;
863    _elm_config->zoom_friction = 0.5;
864    _elm_config->thumbscroll_border_friction = 0.5;
865    _elm_config->thumbscroll_sensitivity_friction = 0.25; // magic number! just trial and error shows this makes it behave "nicer" and not run off at high speed all the time
866    _elm_config->scroll_smooth_amount = 1.0;
867    _elm_config->scroll_smooth_history_weight = 0.3;
868    _elm_config->scroll_smooth_future_time = 0.0;
869    _elm_config->scroll_smooth_time_window = 0.2;
870    _elm_config->scale = 1.0;
871    _elm_config->bgpixmap = 0;
872    _elm_config->compositing = 1;
873    _elm_config->font_hinting = 2;
874    _elm_config->cache_flush_poll_interval = 512;
875    _elm_config->cache_flush_enable = EINA_TRUE;
876    _elm_config->font_dirs = NULL;
877    _elm_config->image_cache = 4096;
878    _elm_config->font_cache = 512;
879    _elm_config->edje_cache = 32;
880    _elm_config->edje_collection_cache = 64;
881    _elm_config->finger_size = 40;
882    _elm_config->fps = 60.0;
883    _elm_config->theme = eina_stringshare_add("default");
884    _elm_config->modules = NULL;
885    _elm_config->tooltip_delay = 1.0;
886    _elm_config->cursor_engine_only = EINA_TRUE;
887    _elm_config->focus_highlight_enable = EINA_FALSE;
888    _elm_config->focus_highlight_animate = EINA_TRUE;
889    _elm_config->toolbar_shrink_mode = 2;
890    _elm_config->fileselector_expand_enable = EINA_FALSE;
891    _elm_config->inwin_dialogs_enable = EINA_FALSE;
892    _elm_config->icon_size = 32;
893    _elm_config->longpress_timeout = 1.0;
894    _elm_config->effect_enable = EINA_TRUE;
895    _elm_config->desktop_entry = EINA_FALSE;
896    _elm_config->is_mirrored = EINA_FALSE; /* Read sys value in env_get() */
897    _elm_config->password_show_last = EINA_FALSE;
898    _elm_config->password_show_last_timeout = 2.0;
899    _elm_config->glayer_zoom_finger_enable = EINA_TRUE;
900    _elm_config->glayer_zoom_finger_factor = 1.0;
901    _elm_config->glayer_zoom_wheel_factor = 0.05;
902    _elm_config->glayer_zoom_distance_tolerance = 1.0; /* 1 times elm_finger_size_get() */
903    _elm_config->glayer_rotate_finger_enable = EINA_TRUE;
904    _elm_config->glayer_rotate_angular_tolerance = 2.0; /* 2 DEG */
905    _elm_config->glayer_line_min_length = 1.0;         /* 1 times elm_finger_size_get() */
906    _elm_config->glayer_line_distance_tolerance = 3.0; /* 3 times elm_finger_size_get() */
907    _elm_config->glayer_line_angular_tolerance = 20.0; /* 20 DEG */
908    _elm_config->glayer_flick_time_limit_ms = 120;              /* ms to finish flick */
909    _elm_config->glayer_long_tap_start_timeout = 1.2;   /* 1.2 second to start long-tap */
910    _elm_config->glayer_continues_enable = EINA_TRUE;      /* Continue gestures default */
911    _elm_config->week_start = 0;
912    _elm_config->weekend_start = 6;
913    _elm_config->weekend_len = 2;
914 }
915
916 static const char *
917 _elm_config_eet_close_error_get(Eet_File *ef,
918                                 char     *file)
919 {
920    Eet_Error err;
921    const char *erstr = NULL;
922
923    err = eet_close(ef);
924    switch (err)
925      {
926       case EET_ERROR_WRITE_ERROR:
927         erstr = "An error occurred while saving Elementary's "
928                 "settings to disk. The error could not be "
929                 "deterimined. The file where the error occurred was: "
930                 "%s. This file has been deleted to avoid corrupt data.";
931         break;
932
933       case EET_ERROR_WRITE_ERROR_FILE_TOO_BIG:
934         erstr = "Elementary's settings files are too big "
935                 "for the file system they are being saved to. "
936                 "This error is very strange as the files should "
937                 "be extremely small. Please check the settings "
938                 "for your home directory. "
939                 "The file where the error occurred was: %s ."
940                 "This file has been deleted to avoid corrupt data.";
941         break;
942
943       case EET_ERROR_WRITE_ERROR_IO_ERROR:
944         erstr = "An output error occurred when writing the settings "
945                 "files for Elementary. Your disk is having troubles "
946                 "and possibly needs replacement. "
947                 "The file where the error occurred was: %s ."
948                 "This file has been deleted to avoid corrupt data.";
949         break;
950
951       case EET_ERROR_WRITE_ERROR_OUT_OF_SPACE:
952         erstr = "Elementary cannot write its settings file "
953                 "because it ran out of space to write the file. "
954                 "You have either run out of disk space or have "
955                 "gone over your quota limit. "
956                 "The file where the error occurred was: %s ."
957                 "This file has been deleted to avoid corrupt data.";
958         break;
959
960       case EET_ERROR_WRITE_ERROR_FILE_CLOSED:
961         erstr = "Elementary unexpectedly had the settings file "
962                 "it was writing closed on it. This is very unusual. "
963                 "The file where the error occurred was: %s "
964                 "This file has been deleted to avoid corrupt data.";
965         break;
966
967       default:
968         break;
969      }
970    if (erstr)
971      {
972         /* delete any partially-written file */
973          ecore_file_unlink(file);
974          return strdup(erstr);
975      }
976
977    return NULL;
978 }
979
980 static Eina_Bool
981 _elm_config_profile_save(void)
982 {
983    char buf[4096], buf2[4096];
984    int ok = 0, ret;
985    const char *err;
986    Eet_File *ef;
987    size_t len;
988
989    len = _elm_user_dir_snprintf(buf, sizeof(buf), "config/profile.cfg");
990    if (len + 1 >= sizeof(buf))
991      return EINA_FALSE;
992
993    len = _elm_user_dir_snprintf(buf2, sizeof(buf2), "config/profile.cfg.tmp");
994    if (len + 1 >= sizeof(buf2))
995      return EINA_FALSE;
996
997    ef = eet_open(buf2, EET_FILE_MODE_WRITE);
998    if (!ef)
999      return EINA_FALSE;
1000
1001    ok = eet_write(ef, "config", _elm_profile, strlen(_elm_profile), 0);
1002    if (!ok)
1003      goto err;
1004
1005    err = _elm_config_eet_close_error_get(ef, buf2);
1006    if (err)
1007      {
1008         ERR("%s", err);
1009         free((void *)err);
1010         goto err;
1011      }
1012
1013    ret = ecore_file_mv(buf2, buf);
1014    if (!ret)
1015      {
1016         ERR("Error saving Elementary's configuration file");
1017         goto err;
1018      }
1019
1020    ecore_file_unlink(buf2);
1021    return EINA_TRUE;
1022
1023 err:
1024    ecore_file_unlink(buf2);
1025    return EINA_FALSE;
1026 }
1027
1028 Eina_Bool
1029 _elm_config_save(void)
1030 {
1031    char buf[4096], buf2[4096];
1032    int ok = 0, ret;
1033    const char *err;
1034    Eet_File *ef;
1035    size_t len;
1036
1037    len = _elm_user_dir_snprintf(buf, sizeof(buf), "config/%s", _elm_profile);
1038    if (len + 1 >= sizeof(buf))
1039      return EINA_FALSE;
1040
1041    ok = ecore_file_mkpath(buf);
1042    if (!ok)
1043      {
1044         ERR("Problem accessing Elementary's user configuration directory: %s",
1045             buf);
1046         return EINA_FALSE;
1047      }
1048
1049    if (!_elm_config_profile_save())
1050      return EINA_FALSE;
1051
1052    buf[len] = '/';
1053    len++;
1054
1055    if (len + sizeof("base.cfg") >= sizeof(buf) - len)
1056      return EINA_FALSE;
1057
1058    memcpy(buf + len, "base.cfg", sizeof("base.cfg"));
1059    len += sizeof("base.cfg") - 1;
1060
1061    if (len + sizeof(".tmp") >= sizeof(buf))
1062      return EINA_FALSE;
1063
1064    memcpy(buf2, buf, len);
1065    memcpy(buf2 + len, ".tmp", sizeof(".tmp"));
1066
1067    ef = eet_open(buf2, EET_FILE_MODE_WRITE);
1068    if (!ef)
1069      return EINA_FALSE;
1070
1071    ok = eet_data_write(ef, _config_edd, "config", _elm_config, 1);
1072    if (!ok)
1073      goto err;
1074
1075    err = _elm_config_eet_close_error_get(ef, buf2);
1076    if (err)
1077      {
1078         ERR("%s", err);
1079         free((void *)err);
1080         goto err;
1081      }
1082
1083    ret = ecore_file_mv(buf2, buf);
1084    if (!ret)
1085      {
1086         ERR("Error saving Elementary's configuration file");
1087         goto err;
1088      }
1089
1090    ecore_file_unlink(buf2);
1091    return EINA_TRUE;
1092
1093 err:
1094    ecore_file_unlink(buf2);
1095    return EINA_FALSE;
1096 }
1097
1098 static void
1099 _config_update(void)
1100 {
1101    Elm_Config *tcfg;
1102
1103    tcfg = _config_system_load();
1104    if (!tcfg)
1105      {
1106         /* weird profile or something? We should probably fill
1107          * with hardcoded defaults, or get from default previx */
1108           return;
1109      }
1110 #define IFCFG(v)   if ((_elm_config->config_version & 0xffff) < (v)) {
1111 #define IFCFGELSE } else {
1112 #define IFCFGEND  }
1113 #define COPYVAL(x) do {_elm_config->x = tcfg->x; } while(0)
1114 #define COPYPTR(x) do {_elm_config->x = tcfg->x; tcfg->x = NULL; } while(0)
1115 #define COPYSTR(x) COPYPTR(x)
1116
1117      /* we also need to update for property changes in the root window
1118       * if needed, but that will be dependent on new properties added
1119       * with each version */
1120
1121      IFCFG(0x0003);
1122      COPYVAL(longpress_timeout);
1123      IFCFGEND;
1124
1125 #undef COPYSTR
1126 #undef COPYPTR
1127 #undef COPYVAL
1128 #undef IFCFGEND
1129 #undef IFCFGELSE
1130 #undef IFCFG
1131
1132      /* after updating user config, we must save */
1133 }
1134
1135 static void
1136 _env_get(void)
1137 {
1138    char *s;
1139    double friction;
1140
1141    s = getenv("ELM_ENGINE");
1142    if (s)
1143      {
1144         if ((!strcasecmp(s, "x11")) ||
1145             (!strcasecmp(s, "x")) ||
1146             (!strcasecmp(s, "software-x11")) ||
1147             (!strcasecmp(s, "software_x11")))
1148           eina_stringshare_replace(&_elm_config->engine, ELM_SOFTWARE_X11);
1149         else if ((!strcasecmp(s, "opengl")) ||
1150                  (!strcasecmp(s, "gl")) ||
1151                  (!strcasecmp(s, "opengl-x11")) ||
1152                  (!strcasecmp(s, "opengl_x11")))
1153           eina_stringshare_replace(&_elm_config->engine, ELM_OPENGL_X11);
1154         else if ((!strcasecmp(s, "x11-8")) ||
1155                  (!strcasecmp(s, "x8")) ||
1156                  (!strcasecmp(s, "software-8-x11")) ||
1157                  (!strcasecmp(s, "software_8_x11")))
1158           eina_stringshare_replace(&_elm_config->engine, ELM_SOFTWARE_8_X11);
1159         else if ((!strcasecmp(s, "x11-16")) ||
1160                  (!strcasecmp(s, "x16")) ||
1161                  (!strcasecmp(s, "software-16-x11")) ||
1162                  (!strcasecmp(s, "software_16_x11")))
1163           eina_stringshare_replace(&_elm_config->engine, ELM_SOFTWARE_16_X11);
1164 /*
1165         else if ((!strcasecmp(s, "xrender")) ||
1166                  (!strcasecmp(s, "xr")) ||
1167                  (!strcasecmp(s, "xrender-x11")) ||
1168                  (!strcasecmp(s, "xrender_x11")))
1169           eina_stringshare_replace(&_elm_config->engine, ELM_XRENDER_X11);
1170  */
1171         else if ((!strcasecmp(s, "fb")) ||
1172                  (!strcasecmp(s, "software-fb")) ||
1173                  (!strcasecmp(s, "software_fb")))
1174           eina_stringshare_replace(&_elm_config->engine, ELM_SOFTWARE_FB);
1175         else if ((!strcasecmp(s, "directfb")) ||
1176                  (!strcasecmp(s, "dfb")))
1177           eina_stringshare_replace(&_elm_config->engine, ELM_SOFTWARE_DIRECTFB);
1178         else if ((!strcasecmp(s, "psl1ght")))
1179           eina_stringshare_replace(&_elm_config->engine, ELM_SOFTWARE_PSL1GHT);
1180         else if ((!strcasecmp(s, "sdl")) ||
1181                  (!strcasecmp(s, "software-sdl")) ||
1182                  (!strcasecmp(s, "software_sdl")))
1183           eina_stringshare_replace(&_elm_config->engine, ELM_SOFTWARE_SDL);
1184         else if ((!strcasecmp(s, "sdl-16")) ||
1185                  (!strcasecmp(s, "software-16-sdl")) ||
1186                  (!strcasecmp(s, "software_16_sdl")))
1187           eina_stringshare_replace(&_elm_config->engine, ELM_SOFTWARE_16_SDL);
1188         else if ((!strcasecmp(s, "opengl-sdl")) ||
1189                  (!strcasecmp(s, "opengl_sdl")) ||
1190                  (!strcasecmp(s, "gl-sdl")) ||
1191                  (!strcasecmp(s, "gl_sdl")))
1192           eina_stringshare_replace(&_elm_config->engine, ELM_OPENGL_SDL);
1193         else if ((!strcasecmp(s, "opengl-cocoa")) ||
1194                  (!strcasecmp(s, "opengl_cocoa")) ||
1195                  (!strcasecmp(s, "gl-cocoa")) ||
1196                  (!strcasecmp(s, "gl_cocoa")))
1197           eina_stringshare_replace(&_elm_config->engine, ELM_OPENGL_COCOA);
1198         else if ((!strcasecmp(s, "gdi")) ||
1199                  (!strcasecmp(s, "software-gdi")) ||
1200                  (!strcasecmp(s, "software_gdi")))
1201           eina_stringshare_replace(&_elm_config->engine, ELM_SOFTWARE_WIN32);
1202         else if ((!strcasecmp(s, "wince-gdi")) ||
1203                  (!strcasecmp(s, "software-16-wince-gdi")) ||
1204                  (!strcasecmp(s, "software_16_wince_gdi")))
1205           eina_stringshare_replace(&_elm_config->engine, ELM_SOFTWARE_16_WINCE);
1206         else if (!strcasecmp(s, "buffer"))
1207           eina_stringshare_replace(&_elm_config->engine, ELM_BUFFER);
1208         else if ((!strncmp(s, "shot:", 5)))
1209           eina_stringshare_replace(&_elm_config->engine, s);
1210         else if ((!strcasecmp(s, "ews")))
1211           eina_stringshare_replace(&_elm_config->engine, ELM_EWS);
1212         else if ((!strcasecmp(s, "wayland_shm")))
1213           eina_stringshare_replace(&_elm_config->engine, ELM_WAYLAND_SHM);
1214         else if ((!strcasecmp(s, "wayland_egl")))
1215           eina_stringshare_replace(&_elm_config->engine, ELM_WAYLAND_EGL);
1216         else
1217           ERR("Unknown engine '%s'.", s);
1218      }
1219
1220    s = getenv("ELM_VSYNC");
1221    if (s) _elm_config->vsync = !!atoi(s);
1222
1223    s = getenv("ELM_THUMBSCROLL_ENABLE");
1224    if (s) _elm_config->thumbscroll_enable = !!atoi(s);
1225    s = getenv("ELM_THUMBSCROLL_THRESHOLD");
1226    if (s) _elm_config->thumbscroll_threshold = atoi(s);
1227    // FIXME: floatformat locale issues here 1.0 vs 1,0 - should just be 1.0
1228    s = getenv("ELM_THUMBSCROLL_MOMENTUM_THRESHOLD");
1229    if (s) _elm_config->thumbscroll_momentum_threshold = atof(s);
1230    s = getenv("ELM_THUMBSCROLL_FRICTION");
1231    if (s) _elm_config->thumbscroll_friction = atof(s);
1232    s = getenv("ELM_THUMBSCROLL_BOUNCE_ENABLE");
1233    if (s) _elm_config->thumbscroll_bounce_enable = !!atoi(s);
1234    s = getenv("ELM_THUMBSCROLL_BOUNCE_FRICTION");
1235    if (s) _elm_config->thumbscroll_bounce_friction = atof(s);
1236    s = getenv("ELM_PAGE_SCROLL_FRICTION");
1237    if (s) _elm_config->page_scroll_friction = atof(s);
1238    s = getenv("ELM_BRING_IN_SCROLL_FRICTION");
1239    if (s) _elm_config->bring_in_scroll_friction = atof(s);
1240    s = getenv("ELM_ZOOM_FRICTION");
1241    if (s) _elm_config->zoom_friction = atof(s);
1242    s = getenv("ELM_THUMBSCROLL_BORDER_FRICTION");
1243    if (s)
1244      {
1245         friction = atof(s);
1246         if (friction < 0.0)
1247           friction = 0.0;
1248
1249         if (friction > 1.0)
1250           friction = 1.0;
1251
1252         _elm_config->thumbscroll_border_friction = friction;
1253      }
1254    s = getenv("ELM_THUMBSCROLL_SENSITIVITY_FRICTION");
1255    if (s)
1256      {
1257         friction = atof(s);
1258         if (friction < 0.1)
1259           friction = 0.1;
1260
1261         if (friction > 1.0)
1262           friction = 1.0;
1263
1264         _elm_config->thumbscroll_sensitivity_friction = friction;
1265      }
1266    s = getenv("ELM_SCROLL_SMOOTH_AMOUNT");
1267    if (s) _elm_config->scroll_smooth_amount = atof(s);
1268    s = getenv("ELM_SCROLL_SMOOTH_HISTORY_WEIGHT");
1269    if (s) _elm_config->scroll_smooth_history_weight = atof(s);
1270    s = getenv("ELM_SCROLL_SMOOTH_FUTURE_TIME");
1271    if (s) _elm_config->scroll_smooth_future_time = atof(s);
1272    s = getenv("ELM_SCROLL_SMOOTH_TIME_WINDOW");
1273    if (s) _elm_config->scroll_smooth_time_window = atof(s);
1274    s = getenv("ELM_THEME");
1275    if (s) eina_stringshare_replace(&_elm_config->theme, s);
1276
1277    s = getenv("ELM_FONT_HINTING");
1278    if (s)
1279      {
1280         if      (!strcasecmp(s, "none")) _elm_config->font_hinting = 0;
1281         else if (!strcasecmp(s, "auto"))
1282           _elm_config->font_hinting = 1;
1283         else if (!strcasecmp(s, "bytecode"))
1284           _elm_config->font_hinting = 2;
1285      }
1286
1287    s = getenv("ELM_FONT_PATH");
1288    if (s)
1289      {
1290         const char *p, *pp;
1291         char *buf2;
1292
1293         EINA_LIST_FREE(_elm_config->font_dirs, p)
1294           {
1295              eina_stringshare_del(p);
1296           }
1297
1298         buf2 = alloca(strlen(s) + 1);
1299         p = s;
1300         pp = p;
1301         for (;; )
1302           {
1303              if ((*p == ':') || (*p == 0))
1304                {
1305                   int len;
1306
1307                   len = p - pp;
1308                   strncpy(buf2, pp, len);
1309                   buf2[len] = 0;
1310                   _elm_config->font_dirs =
1311                     eina_list_append(_elm_config->font_dirs,
1312                                      eina_stringshare_add(buf2));
1313                   if (*p == 0) break;
1314                   p++;
1315                   pp = p;
1316                }
1317              else
1318                {
1319                   if (*p == 0) break;
1320                   p++;
1321                }
1322           }
1323      }
1324
1325    s = getenv("ELM_IMAGE_CACHE");
1326    if (s) _elm_config->image_cache = atoi(s);
1327
1328    s = getenv("ELM_FONT_CACHE");
1329    if (s) _elm_config->font_cache = atoi(s);
1330
1331    s = getenv("ELM_SCALE");
1332    if (s) _elm_config->scale = atof(s);
1333
1334    s = getenv("ELM_FINGER_SIZE");
1335    if (s) _elm_config->finger_size = atoi(s);
1336
1337    s = getenv("ELM_PASSWORD_SHOW_LAST");
1338    if (s) _elm_config->password_show_last = !!atoi(s);
1339
1340    s = getenv("ELM_PASSWORD_SHOW_LAST_TIMEOUT");
1341    if (s)
1342      {
1343         double pw_show_last_timeout = atof(s);
1344         if (pw_show_last_timeout >= 0.0)
1345           _elm_config->password_show_last_timeout = pw_show_last_timeout;
1346      }
1347
1348    s = getenv("ELM_FPS");
1349    if (s) _elm_config->fps = atof(s);
1350    if (_elm_config->fps < 1.0) _elm_config->fps = 1.0;
1351
1352    s = getenv("ELM_MODULES");
1353    if (s) eina_stringshare_replace(&_elm_config->modules, s);
1354
1355    /* Get RTL orientation from system */
1356    setlocale(LC_ALL, "");
1357    bindtextdomain(PACKAGE, LOCALE_DIR);
1358    _elm_config->is_mirrored = !strcmp(E_("default:LTR"), "default:RTL");
1359
1360    s = getenv("ELM_TOOLTIP_DELAY");
1361    if (s)
1362      {
1363         double delay = atof(s);
1364         if (delay >= 0.0)
1365           _elm_config->tooltip_delay = delay;
1366      }
1367
1368    s = getenv("ELM_CURSOR_ENGINE_ONLY");
1369    if (s) _elm_config->cursor_engine_only = !!atoi(s);
1370
1371    s = getenv("ELM_FOCUS_HIGHLIGHT_ENABLE");
1372    if (s) _elm_config->focus_highlight_enable = !!atoi(s);
1373
1374    s = getenv("ELM_FOCUS_HIGHLIGHT_ANIMATE");
1375    if (s) _elm_config->focus_highlight_animate = !!atoi(s);
1376
1377    s = getenv("ELM_TOOLBAR_SHRINK_MODE");
1378    if (s) _elm_config->toolbar_shrink_mode = atoi(s);
1379
1380    s = getenv("ELM_FILESELECTOR_EXPAND_ENABLE");
1381    if (s) _elm_config->fileselector_expand_enable = !!atoi(s);
1382
1383    s = getenv("ELM_INWIN_DIALOGS_ENABLE");
1384    if (s) _elm_config->inwin_dialogs_enable = !!atoi(s);
1385
1386    s = getenv("ELM_ICON_SIZE");
1387    if (s) _elm_config->icon_size = atoi(s);
1388
1389    s = getenv("ELM_LONGPRESS_TIMEOUT");
1390    if (s) _elm_config->longpress_timeout = atof(s);
1391    if (_elm_config->longpress_timeout < 0.0)
1392      _elm_config->longpress_timeout = 0.0;
1393
1394    s = getenv("ELM_EFFECT_ENABLE");
1395    if (s) _elm_config->effect_enable = !!atoi(s);
1396
1397    s = getenv("ELM_DESKTOP_ENTRY");
1398    if (s) _elm_config->desktop_entry = !!atoi(s);
1399    s = getenv("ELM_ACCESS_MODE");
1400    if (s) _elm_config->access_mode = ELM_ACCESS_MODE_ON;
1401 }
1402
1403 EAPI Eina_Bool
1404 elm_config_mirrored_get(void)
1405 {
1406    return _elm_config->is_mirrored;
1407 }
1408
1409 EAPI void
1410 elm_config_mirrored_set(Eina_Bool mirrored)
1411 {
1412    _elm_config->is_mirrored = mirrored;
1413    _elm_rescale();
1414 }
1415
1416 EAPI Eina_Bool
1417 elm_config_cursor_engine_only_get(void)
1418 {
1419    return _elm_config->cursor_engine_only;
1420 }
1421
1422 EAPI void
1423 elm_config_cursor_engine_only_set(Eina_Bool engine_only)
1424 {
1425    engine_only = !!engine_only;
1426    _elm_config->cursor_engine_only = engine_only;
1427 }
1428
1429 EINA_DEPRECATED EAPI double
1430 elm_tooltip_delay_get(void)
1431 {
1432    return elm_config_tooltip_delay_get();
1433 }
1434
1435 EINA_DEPRECATED EAPI Eina_Bool
1436 elm_tooltip_delay_set(double delay)
1437 {
1438    elm_config_tooltip_delay_set(delay);
1439    return EINA_TRUE;
1440 }
1441
1442 EAPI double
1443 elm_config_tooltip_delay_get(void)
1444 {
1445    return _elm_config->tooltip_delay;
1446 }
1447
1448 EAPI void
1449 elm_config_tooltip_delay_set(double delay)
1450 {
1451    if (delay < 0.0) return;
1452    _elm_config->tooltip_delay = delay;
1453 }
1454
1455 EAPI double
1456 elm_config_scale_get(void)
1457 {
1458    return _elm_config->scale;
1459 }
1460
1461 EAPI void
1462 elm_config_scale_set(double scale)
1463 {
1464    if (_elm_config->scale == scale) return;
1465    _elm_config->scale = scale;
1466    _elm_rescale();
1467 }
1468
1469 EAPI Eina_Bool
1470 elm_config_password_show_last_get(void)
1471 {
1472    return _elm_config->password_show_last;
1473 }
1474
1475 EAPI void
1476 elm_config_password_show_last_set(Eina_Bool password_show_last)
1477 {
1478    if (_elm_config->password_show_last == password_show_last) return;
1479    _elm_config->password_show_last = password_show_last;
1480    edje_password_show_last_set(_elm_config->password_show_last);
1481 }
1482
1483 EAPI double
1484 elm_config_password_show_last_timeout_get(void)
1485 {
1486    return _elm_config->password_show_last_timeout;
1487 }
1488
1489 EAPI void
1490 elm_config_password_show_last_timeout_set(double password_show_last_timeout)
1491 {
1492    if (_elm_config->password_show_last_timeout == password_show_last_timeout) return;
1493    _elm_config->password_show_last_timeout = password_show_last_timeout;
1494    edje_password_show_last_timeout_set(_elm_config->password_show_last_timeout);
1495 }
1496
1497 EAPI Eina_Bool
1498 elm_config_save(void)
1499 {
1500    return _elm_config_save();
1501 }
1502
1503 EAPI void
1504 elm_config_reload(void)
1505 {
1506    _elm_config_reload();
1507 }
1508
1509 EAPI const char *
1510 elm_config_profile_get(void)
1511 {
1512    return _elm_config_current_profile_get();
1513 }
1514
1515 EAPI const char *
1516 elm_config_profile_dir_get(const char *profile,
1517                     Eina_Bool   is_user)
1518 {
1519    return _elm_config_profile_dir_get(profile, is_user);
1520 }
1521
1522 EAPI void
1523 elm_config_profile_dir_free(const char *p_dir)
1524 {
1525    free((void *)p_dir);
1526 }
1527
1528 EAPI Eina_List *
1529 elm_config_profile_list_get(void)
1530 {
1531    return _elm_config_profiles_list();
1532 }
1533
1534 EAPI void
1535 elm_config_profile_list_free(Eina_List *l)
1536 {
1537    const char *dir;
1538
1539    EINA_LIST_FREE(l, dir)
1540      eina_stringshare_del(dir);
1541 }
1542
1543 EAPI void
1544 elm_config_profile_set(const char *profile)
1545 {
1546    EINA_SAFETY_ON_NULL_RETURN(profile);
1547    _elm_config_profile_set(profile);
1548 }
1549
1550 EAPI const char *
1551 elm_config_engine_get(void)
1552 {
1553    return _elm_config->engine;
1554 }
1555
1556 EAPI void
1557 elm_config_engine_set(const char *engine)
1558 {
1559    EINA_SAFETY_ON_NULL_RETURN(engine);
1560
1561    _elm_config_engine_set(engine);
1562 }
1563
1564 EAPI Eina_List *
1565 elm_config_text_classes_list_get(void)
1566 {
1567    return _elm_config_text_classes_get();
1568 }
1569
1570 EAPI void
1571 elm_config_text_classes_list_free(Eina_List *list)
1572 {
1573    _elm_config_text_classes_free(list);
1574 }
1575
1576 EAPI const Eina_List *
1577 elm_config_font_overlay_list_get(void)
1578 {
1579    return _elm_config_font_overlays_list();
1580 }
1581
1582 EAPI void
1583 elm_config_font_overlay_set(const char    *text_class,
1584                      const char    *font,
1585                      Evas_Font_Size size)
1586 {
1587    EINA_SAFETY_ON_NULL_RETURN(text_class);
1588    _elm_config_font_overlay_set(text_class, font, size);
1589 }
1590
1591 EAPI void
1592 elm_config_font_overlay_unset(const char *text_class)
1593 {
1594    EINA_SAFETY_ON_NULL_RETURN(text_class);
1595    _elm_config_font_overlay_remove(text_class);
1596 }
1597
1598 EAPI void
1599 elm_config_font_overlay_apply(void)
1600 {
1601    _elm_config_font_overlay_apply();
1602 }
1603
1604 EAPI Evas_Coord
1605 elm_config_finger_size_get(void)
1606 {
1607    return _elm_config->finger_size;
1608 }
1609
1610 EAPI void
1611 elm_config_finger_size_set(Evas_Coord size)
1612 {
1613    if (_elm_config->finger_size == size) return;
1614    _elm_config->finger_size = size;
1615    _elm_rescale();
1616 }
1617
1618 EAPI int
1619 elm_config_cache_flush_interval_get(void)
1620 {
1621    return _elm_config->cache_flush_poll_interval;
1622 }
1623
1624 EAPI void
1625 elm_config_cache_flush_interval_set(int size)
1626 {
1627    if (_elm_config->cache_flush_poll_interval == size) return;
1628    _elm_config->cache_flush_poll_interval = size;
1629
1630    _elm_recache();
1631 }
1632
1633 EAPI Eina_Bool
1634 elm_config_cache_flush_enabled_get(void)
1635 {
1636    return _elm_config->cache_flush_enable;
1637 }
1638
1639 EAPI void
1640 elm_config_cache_flush_enabled_set(Eina_Bool enabled)
1641 {
1642    enabled = !!enabled;
1643    if (_elm_config->cache_flush_enable == enabled) return;
1644    _elm_config->cache_flush_enable = enabled;
1645
1646    _elm_recache();
1647 }
1648
1649 EINA_DEPRECATED EAPI int
1650 elm_font_cache_get(void)
1651 {
1652    return elm_config_cache_font_cache_size_get();
1653 }
1654
1655 EAPI int
1656 elm_config_cache_font_cache_size_get(void)
1657 {
1658    return _elm_config->font_cache;
1659 }
1660
1661 EINA_DEPRECATED EAPI void
1662 elm_font_cache_set(int size)
1663 {
1664    elm_config_cache_font_cache_size_set(size);
1665 }
1666
1667 EAPI void 
1668 elm_config_cache_font_cache_size_set(int size)
1669 {
1670    if (_elm_config->font_cache == size) return;
1671    _elm_config->font_cache = size;
1672
1673    _elm_recache();
1674 }
1675
1676 EINA_DEPRECATED EAPI int
1677 elm_image_cache_get(void)
1678 {
1679    return elm_config_cache_image_cache_size_get();
1680 }
1681
1682 EAPI int
1683 elm_config_cache_image_cache_size_get(void)
1684 {
1685    return _elm_config->image_cache;
1686 }
1687
1688 EINA_DEPRECATED EAPI void
1689 elm_image_cache_set(int size)
1690 {
1691    elm_config_cache_image_cache_size_set(size);
1692 }
1693
1694 EAPI void
1695 elm_config_cache_image_cache_size_set(int size)
1696 {
1697    if (_elm_config->image_cache == size) return;
1698    _elm_config->image_cache = size;
1699
1700    _elm_recache();
1701 }
1702
1703 EINA_DEPRECATED EAPI int
1704 elm_edje_file_cache_get(void)
1705 {
1706    return elm_config_cache_edje_file_cache_size_get();
1707 }
1708
1709 EAPI int
1710 elm_config_cache_edje_file_cache_size_get()
1711 {
1712    return _elm_config->edje_cache;
1713 }
1714
1715 EINA_DEPRECATED EAPI void
1716 elm_edje_file_cache_set(int size)
1717 {
1718    elm_config_cache_edje_file_cache_size_set(size);
1719 }
1720
1721 EAPI void
1722 elm_config_cache_edje_file_cache_size_set(int size)
1723 {
1724    if (_elm_config->edje_cache == size) return;
1725    _elm_config->edje_cache = size;
1726
1727    _elm_recache();
1728 }
1729
1730 EINA_DEPRECATED EAPI int
1731 elm_edje_collection_cache_get(void)
1732 {
1733    return elm_config_cache_edje_collection_cache_size_get();
1734 }
1735
1736 EAPI int
1737 elm_config_cache_edje_collection_cache_size_get(void)
1738 {
1739    return _elm_config->edje_collection_cache;
1740 }
1741
1742 EINA_DEPRECATED EAPI void
1743 elm_edje_collection_cache_set(int size)
1744 {
1745    elm_config_cache_edje_collection_cache_size_set(size);
1746 }
1747
1748 EAPI void
1749 elm_config_cache_edje_collection_cache_size_set(int size)
1750 {
1751    if (_elm_config->edje_collection_cache == size) return;
1752    _elm_config->edje_collection_cache = size;
1753
1754    _elm_recache();
1755 }
1756
1757 EAPI Eina_Bool
1758 elm_config_focus_highlight_enabled_get(void)
1759 {
1760    return _elm_config->focus_highlight_enable;
1761 }
1762
1763 EAPI void
1764 elm_config_focus_highlight_enabled_set(Eina_Bool enable)
1765 {
1766    _elm_config->focus_highlight_enable = !!enable;
1767 }
1768
1769 EAPI Eina_Bool
1770 elm_config_focus_highlight_animate_get(void)
1771 {
1772    return _elm_config->focus_highlight_animate;
1773 }
1774
1775 EAPI void
1776 elm_config_focus_highlight_animate_set(Eina_Bool animate)
1777 {
1778    _elm_config->focus_highlight_animate = !!animate;
1779 }
1780
1781 EAPI Eina_Bool
1782 elm_config_scroll_bounce_enabled_get(void)
1783 {
1784    return _elm_config->thumbscroll_bounce_enable;
1785 }
1786
1787 EAPI void
1788 elm_config_scroll_bounce_enabled_set(Eina_Bool enabled)
1789 {
1790    _elm_config->thumbscroll_bounce_enable = enabled;
1791 }
1792
1793 EAPI double
1794 elm_config_scroll_bounce_friction_get(void)
1795 {
1796    return _elm_config->thumbscroll_bounce_friction;
1797 }
1798
1799 EAPI void
1800 elm_config_scroll_bounce_friction_set(double friction)
1801 {
1802    _elm_config->thumbscroll_bounce_friction = friction;
1803 }
1804
1805 EAPI double
1806 elm_config_scroll_page_scroll_friction_get(void)
1807 {
1808    return _elm_config->page_scroll_friction;
1809 }
1810
1811 EAPI void
1812 elm_config_scroll_page_scroll_friction_set(double friction)
1813 {
1814    _elm_config->page_scroll_friction = friction;
1815 }
1816
1817 EAPI double
1818 elm_config_scroll_bring_in_scroll_friction_get(void)
1819 {
1820    return _elm_config->bring_in_scroll_friction;
1821 }
1822
1823 EAPI void
1824 elm_config_scroll_bring_in_scroll_friction_set(double friction)
1825 {
1826    _elm_config->bring_in_scroll_friction = friction;
1827 }
1828
1829 EAPI double
1830 elm_config_scroll_zoom_friction_get(void)
1831 {
1832    return _elm_config->zoom_friction;
1833 }
1834
1835 EAPI void
1836 elm_config_scroll_zoom_friction_set(double friction)
1837 {
1838    _elm_config->zoom_friction = friction;
1839 }
1840
1841 EAPI Eina_Bool
1842 elm_config_scroll_thumbscroll_enabled_get(void)
1843 {
1844    return _elm_config->thumbscroll_enable;
1845 }
1846
1847 EAPI void
1848 elm_config_scroll_thumbscroll_enabled_set(Eina_Bool enabled)
1849 {
1850    _elm_config->thumbscroll_enable = enabled;
1851 }
1852
1853 EAPI unsigned int
1854 elm_config_scroll_thumbscroll_threshold_get(void)
1855 {
1856    return _elm_config->thumbscroll_threshold;
1857 }
1858
1859 EAPI void
1860 elm_config_scroll_thumbscroll_threshold_set(unsigned int threshold)
1861 {
1862    _elm_config->thumbscroll_threshold = threshold;
1863 }
1864
1865 EAPI double
1866 elm_config_scroll_thumbscroll_momentum_threshold_get(void)
1867 {
1868    return _elm_config->thumbscroll_momentum_threshold;
1869 }
1870
1871 EAPI void
1872 elm_config_scroll_thumbscroll_momentum_threshold_set(double threshold)
1873 {
1874    _elm_config->thumbscroll_momentum_threshold = threshold;
1875 }
1876
1877 EAPI double
1878 elm_config_scroll_thumbscroll_friction_get(void)
1879 {
1880    return _elm_config->thumbscroll_friction;
1881 }
1882
1883 EAPI void
1884 elm_config_scroll_thumbscroll_friction_set(double friction)
1885 {
1886    _elm_config->thumbscroll_friction = friction;
1887 }
1888
1889 EAPI double
1890 elm_config_scroll_thumbscroll_border_friction_get(void)
1891 {
1892    return _elm_config->thumbscroll_border_friction;
1893 }
1894
1895 EAPI void
1896 elm_config_scroll_thumbscroll_border_friction_set(double friction)
1897 {
1898    if (friction < 0.0) friction = 0.0;
1899    if (friction > 1.0) friction = 1.0;
1900    _elm_config->thumbscroll_friction = friction;
1901 }
1902
1903 EAPI double
1904 elm_config_scroll_thumbscroll_sensitivity_friction_get(void)
1905 {
1906    return _elm_config->thumbscroll_sensitivity_friction;
1907 }
1908
1909 EAPI void
1910 elm_config_scroll_thumbscroll_sensitivity_friction_set(double friction)
1911 {
1912    if (friction < 0.1) friction = 0.1;
1913    if (friction > 1.0) friction = 1.0;
1914    _elm_config->thumbscroll_friction = friction;
1915 }
1916
1917 EAPI void
1918 elm_config_longpress_timeout_set(double longpress_timeout)
1919 {
1920    _elm_config->longpress_timeout = longpress_timeout;
1921 }
1922
1923 EAPI double
1924 elm_config_longpress_timeout_get(void)
1925 {
1926    return _elm_config->longpress_timeout;
1927 }
1928
1929 EAPI void
1930 elm_config_all_flush(void)
1931 {
1932 #ifdef HAVE_ELEMENTARY_X
1933    if (_prop_all_update_timer) ecore_timer_del(_prop_all_update_timer);
1934    _prop_all_update_timer = ecore_timer_add(0.1, _prop_all_update_cb, NULL);
1935 #endif
1936 }
1937
1938 static void
1939 _translation_init()
1940 {
1941 #ifdef ENABLE_NLS
1942    const char *cur_dom = textdomain(NULL);
1943    const char *trans_comment = gettext("");
1944    const char *msg_locale = setlocale(LC_MESSAGES, NULL);
1945
1946    /* Same concept as what glib does:
1947     * We shouldn't translate if there are no translations for the
1948     * application in the current locale + domain. (Unless locale is
1949     * en_/C where translating only parts of the interface make some
1950     * sense).
1951     */
1952    _elm_config->translate = !(strcmp (cur_dom, "messages") &&
1953          !*trans_comment && strncmp (msg_locale, "en_", 3) &&
1954          strcmp (msg_locale, "C"));
1955 #endif
1956 }
1957
1958 void
1959 _elm_config_init(void)
1960 {
1961    if (!ELM_EVENT_CONFIG_ALL_CHANGED)
1962       ELM_EVENT_CONFIG_ALL_CHANGED = ecore_event_type_new();
1963    _desc_init();
1964    _profile_fetch_from_conf();
1965    _config_load();
1966    if (_elm_preferred_engine) eina_stringshare_del(_elm_preferred_engine);
1967    if (_elm_config->engine)
1968      _elm_preferred_engine = eina_stringshare_add(_elm_config->engine);
1969    else
1970      _elm_preferred_engine = NULL;
1971    _translation_init();
1972    _env_get();
1973    _config_apply();
1974    _elm_config_font_overlay_apply();
1975    _elm_recache();
1976 }
1977
1978 void
1979 _elm_config_sub_shutdown(void)
1980 {
1981 #define ENGINE_COMPARE(name) (!strcmp(_elm_config->engine, name))
1982    if (ENGINE_COMPARE(ELM_SOFTWARE_X11) ||
1983        ENGINE_COMPARE(ELM_SOFTWARE_16_X11) ||
1984        ENGINE_COMPARE(ELM_XRENDER_X11) ||
1985        ENGINE_COMPARE(ELM_OPENGL_X11) ||
1986        ENGINE_COMPARE(ELM_OPENGL_COCOA))
1987 #undef ENGINE_COMPARE
1988      {
1989 #ifdef HAVE_ELEMENTARY_X
1990         ecore_x_disconnect();
1991 #endif
1992      }
1993 }
1994
1995 void
1996 _elm_config_sub_init(void)
1997 {
1998 #define ENGINE_COMPARE(name) (!strcmp(_elm_config->engine, name))
1999    if (ENGINE_COMPARE(ELM_SOFTWARE_X11) ||
2000        ENGINE_COMPARE(ELM_SOFTWARE_16_X11) ||
2001        ENGINE_COMPARE(ELM_XRENDER_X11) ||
2002        ENGINE_COMPARE(ELM_OPENGL_X11) ||
2003        ENGINE_COMPARE(ELM_OPENGL_COCOA))
2004 #undef ENGINE_COMPARE
2005      {
2006 #ifdef HAVE_ELEMENTARY_X
2007         if (!ecore_x_init(NULL))
2008           {
2009              ERR("Cannot connect to X11 display. check $DISPLAY variable");
2010              exit(1);
2011           }
2012         _root_1st = ecore_x_window_root_first_get();
2013
2014         if (!ecore_x_screen_is_composited(0))
2015           _elm_config->compositing = 0;
2016
2017         ecore_x_atoms_get(_atom_names, ATOM_COUNT, _atom);
2018         ecore_x_event_mask_set(_root_1st,
2019                                ECORE_X_EVENT_MASK_WINDOW_PROPERTY);
2020         _prop_change_handler = ecore_event_handler_add
2021             (ECORE_X_EVENT_WINDOW_PROPERTY, _prop_change, NULL);
2022         if (!getenv("ELM_PROFILE"))
2023           {
2024              char *s;
2025
2026              s = ecore_x_window_prop_string_get(_root_1st,
2027                                                 _atom[ATOM_E_PROFILE]);
2028              if (s)
2029                {
2030                   int changed = 0;
2031
2032                   if (_elm_profile)
2033                     {
2034                        if (strcmp(_elm_profile, s)) changed = 1;
2035                        free(_elm_profile);
2036                     }
2037                   _elm_profile = s;
2038                   if (changed) _prop_config_get();
2039                }
2040           }
2041 #endif
2042      }
2043    _config_sub_apply();
2044 }
2045
2046 void
2047 _elm_config_reload(void)
2048 {
2049    _config_free();
2050    _config_load();
2051    _config_apply();
2052    _elm_config_font_overlay_apply();
2053    _elm_rescale();
2054    _elm_recache();
2055 }
2056
2057 void
2058 _elm_config_engine_set(const char *engine)
2059 {
2060    if (_elm_config->engine && strcmp(_elm_config->engine, engine))
2061      eina_stringshare_del(_elm_config->engine);
2062
2063    _elm_config->engine = eina_stringshare_add(engine);
2064 }
2065
2066 EAPI const char *
2067 elm_config_preferred_engine_get(void)
2068 {
2069    return _elm_preferred_engine;
2070 }
2071
2072 EAPI void
2073 elm_config_preferred_engine_set(const char *engine)
2074 {
2075    if (engine)
2076      eina_stringshare_replace(&(_elm_preferred_engine), engine);
2077    else
2078      {
2079         if (_elm_preferred_engine) eina_stringshare_del(_elm_preferred_engine);
2080         _elm_preferred_engine = eina_stringshare_add(_elm_config->engine);
2081      }
2082 }
2083
2084 void
2085 _elm_config_profile_set(const char *profile)
2086 {
2087    Eina_Bool changed = EINA_FALSE;
2088
2089    if (_elm_profile)
2090      {
2091         if (strcmp(_elm_profile, profile))
2092           changed = 1;
2093         free(_elm_profile);
2094      }
2095
2096    _elm_profile = strdup(profile);
2097
2098    if (changed)
2099      {
2100         _config_free();
2101         _config_load();
2102         _config_apply();
2103         _elm_config_font_overlay_apply();
2104         _elm_rescale();
2105         _elm_recache();
2106      }
2107 }
2108
2109 void
2110 _elm_config_shutdown(void)
2111 {
2112 #ifdef HAVE_ELEMENTARY_X
2113    if (_prop_all_update_timer)
2114      {
2115         ecore_timer_del(_prop_all_update_timer);
2116         _prop_all_update_timer = NULL;
2117         _prop_all_update_cb(NULL);
2118      }
2119    if (_prop_change_delay_timer) ecore_timer_del(_prop_change_delay_timer);
2120    _prop_change_delay_timer = NULL;
2121 #endif
2122
2123 #define ENGINE_COMPARE(name) (!strcmp(_elm_config->engine, name))
2124    if (ENGINE_COMPARE(ELM_SOFTWARE_X11) ||
2125        ENGINE_COMPARE(ELM_SOFTWARE_16_X11) ||
2126        ENGINE_COMPARE(ELM_XRENDER_X11) ||
2127        ENGINE_COMPARE(ELM_OPENGL_X11))
2128 #undef ENGINE_COMPARE
2129      {
2130 #ifdef HAVE_ELEMENTARY_X
2131         ecore_event_handler_del(_prop_change_handler);
2132         _prop_change_handler = NULL;
2133 #endif
2134      }
2135    _config_free();
2136    if (_elm_preferred_engine)
2137      {
2138         eina_stringshare_del(_elm_preferred_engine);
2139         _elm_preferred_engine = NULL;
2140      }
2141    if (_elm_profile)
2142      {
2143         free(_elm_profile);
2144         _elm_profile = NULL;
2145      }
2146    _desc_shutdown();
2147 }
2148