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