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