disable uuid store
[platform/upstream/enlightenment.git] / src / bin / e_main.c
1 #include "e.h"
2 #ifdef __linux__
3 # include <sys/prctl.h>
4 #endif
5
6 #define MAX_LEVEL 80
7
8 #define TS_DO
9 #ifdef TS_DO
10 # define TS(x)                                                    \
11   {                                                               \
12      t1 = ecore_time_unix_get();                                  \
13      printf("ESTART: %1.5f [%1.5f] - %s\n", t1 - t0, t1 - t2, x); \
14      t2 = t1;                                                     \
15   }
16 static double t0, t1, t2;
17 #else
18 # define TS(x)
19 #endif
20
21 /*
22  * i need to make more use of these when i'm baffled as to when something is
23  * up. other hooks:
24  *
25  *      void *(*__malloc_hook)(size_t size, const void *caller);
26  *
27  *      void *(*__realloc_hook)(void *ptr, size_t size, const void *caller);
28  *
29  *      void *(*__memalign_hook)(size_t alignment, size_t size,
30  *                               const void *caller);
31  *
32  *      void (*__free_hook)(void *ptr, const void *caller);
33  *
34  *      void (*__malloc_initialize_hook)(void);
35  *
36  *      void (*__after_morecore_hook)(void);
37  *
38
39    static void my_init_hook(void);
40    static void my_free_hook(void *p, const void *caller);
41
42    static void (*old_free_hook)(void *ptr, const void *caller) = NULL;
43    void (*__free_hook)(void *ptr, const void *caller);
44
45    void (*__malloc_initialize_hook) (void) = my_init_hook;
46    static void
47    my_init_hook(void)
48    {
49    old_free_hook = __free_hook;
50    __free_hook = my_free_hook;
51    }
52
53    //void *magicfree = NULL;
54
55    static void
56    my_free_hook(void *p, const void *caller)
57    {
58    __free_hook = old_free_hook;
59    //   if ((p) && (p == magicfree))
60    //     {
61    //   printf("CAUGHT!!!!! %p ...\n", p);
62    //   abort();
63    //     }
64    free(p);
65    __free_hook = my_free_hook;
66    }
67  */
68
69 /* local function prototypes */
70 static void      _e_main_shutdown(int errcode);
71 static void      _e_main_shutdown_push(int (*func)(void));
72 static void      _e_main_parse_arguments(int argc, char **argv);
73 static Eina_Bool _e_main_cb_signal_exit(void *data EINA_UNUSED, int ev_type EINA_UNUSED, void *ev EINA_UNUSED);
74 static Eina_Bool _e_main_cb_signal_hup(void *data EINA_UNUSED, int ev_type EINA_UNUSED, void *ev EINA_UNUSED);
75 static Eina_Bool _e_main_cb_signal_user(void *data EINA_UNUSED, int ev_type EINA_UNUSED, void *ev);
76 static int       _e_main_dirs_init(void);
77 static int       _e_main_dirs_shutdown(void);
78 static int       _e_main_path_init(void);
79 static int       _e_main_path_shutdown(void);
80 static void      _e_main_test_formats(void);
81 static int       _e_main_screens_init(void);
82 static int       _e_main_screens_shutdown(void);
83 static void      _e_main_desk_save(void);
84 static void      _e_main_desk_restore(void);
85 static void      _e_main_efreet_paths_init(void);
86 static void      _e_main_modules_load(Eina_Bool safe_mode);
87 static Eina_Bool _e_main_cb_idle_before(void *data EINA_UNUSED);
88 static Eina_Bool _e_main_cb_idle_after(void *data EINA_UNUSED);
89 static Eina_Bool _e_main_cb_startup_fake_end(void *data EINA_UNUSED);
90
91 /* local variables */
92 static Eina_Bool really_know = EINA_FALSE;
93 static Eina_Bool locked = EINA_FALSE;
94 static Eina_Bool inloop = EINA_FALSE;
95 static jmp_buf x_fatal_buff;
96
97 static int _e_main_lvl = 0;
98 static int(*_e_main_shutdown_func[MAX_LEVEL]) (void);
99
100 static Ecore_Idle_Enterer *_idle_before = NULL;
101 static Ecore_Idle_Enterer *_idle_after = NULL;
102
103 static Ecore_Event_Handler *mod_init_end = NULL;
104
105 /* external variables */
106 E_API Eina_Bool e_precache_end = EINA_FALSE;
107 E_API Eina_Bool x_fatal = EINA_FALSE;
108 E_API Eina_Bool good = EINA_FALSE;
109 E_API Eina_Bool evil = EINA_FALSE;
110 E_API Eina_Bool starting = EINA_TRUE;
111 E_API Eina_Bool stopping = EINA_FALSE;
112 E_API Eina_Bool restart = EINA_FALSE;
113 E_API Eina_Bool e_nopause = EINA_FALSE;
114 EINTERN const char *e_first_frame = NULL;
115 EINTERN double e_first_frame_start_time = -1;
116
117 static Eina_Bool
118 _xdg_check_str(const char *env, const char *str)
119 {
120    const char *p;
121    size_t len;
122
123    len = strlen(str);
124    for (p = strstr(env, str); p; p++, p = strstr(p, str))
125      {
126         if ((!p[len]) || (p[len] == ':')) return EINA_TRUE;
127      }
128    return EINA_FALSE;
129 }
130
131 static void
132 _xdg_data_dirs_augment(void)
133 {
134    const char *s;
135    const char *p = e_prefix_get();
136    char newpath[4096], buf[4096];
137
138    if (!p) return;
139
140    s = getenv("XDG_DATA_DIRS");
141    if (s)
142      {
143         Eina_Bool pfxdata, pfx;
144
145         pfxdata = !_xdg_check_str(s, e_prefix_data_get());
146         snprintf(newpath, sizeof(newpath), "%s/share", p);
147         pfx = !_xdg_check_str(s, newpath);
148         if (pfxdata || pfx)
149           {
150              snprintf(buf, sizeof(buf), "%s%s%s%s%s",
151                pfxdata ? e_prefix_data_get() : "",
152                pfxdata ? ":" : "",
153                pfx ? newpath : "",
154                pfx ? ":" : "",
155                s);
156              e_util_env_set("XDG_DATA_DIRS", buf);
157           }
158      }
159    else
160      {
161         snprintf(buf, sizeof(buf), "%s:%s/share:/usr/local/share:/usr/share", e_prefix_data_get(), p);
162         e_util_env_set("XDG_DATA_DIRS", buf);
163      }
164
165    s = getenv("XDG_CONFIG_DIRS");
166    snprintf(newpath, sizeof(newpath), "%s/etc/xdg", p);
167    if (s)
168      {
169         if (!_xdg_check_str(s, newpath))
170           {
171              snprintf(buf, sizeof(buf), "%s:%s", newpath, s);
172              e_util_env_set("XDG_CONFIG_DIRS", buf);
173           }
174      }
175    else
176      {
177         snprintf(buf, sizeof(buf), "%s:/etc/xdg", newpath);
178         e_util_env_set("XDG_CONFIG_DIRS", buf);
179      }
180
181    if (!getenv("XDG_RUNTIME_DIR"))
182      {
183         const char *dir;
184
185         snprintf(buf, sizeof(buf), "/tmp/xdg-XXXXXX");
186         dir = mkdtemp(buf);
187         if (!dir) dir = "/tmp";
188         else
189           {
190              e_util_env_set("XDG_RUNTIME_DIR", dir);
191              snprintf(buf, sizeof(buf), "%s/.e-deleteme", dir);
192              ecore_file_mkdir(buf);
193           }
194      }
195
196    /* set menu prefix so we get our e menu */
197    if (!getenv("XDG_MENU_PREFIX"))
198      {
199         e_util_env_set("XDG_MENU_PREFIX", "e-");
200      }
201 }
202
203 static Eina_Bool
204 _e_main_shelf_init_job(void *data EINA_UNUSED)
205 {
206    e_shelf_config_update();
207    return ECORE_CALLBACK_CANCEL;
208 }
209
210 /* externally accessible functions */
211 int
212 main(int argc, char **argv)
213 {
214    Eina_Bool nostartup = EINA_FALSE;
215    Eina_Bool safe_mode = EINA_FALSE;
216    Eina_Bool after_restart = EINA_FALSE;
217    Eina_Bool waslocked = EINA_FALSE;
218    double t = 0.0, tstart = 0.0;
219    char *s = NULL, buff[32];
220    struct sigaction action;
221
222 #ifdef __linux__
223 # ifdef PR_SET_PTRACER
224 #  ifdef PR_SET_PTRACER_ANY
225    prctl(PR_SET_PTRACER, PR_SET_PTRACER_ANY);
226 #  endif
227 # endif
228 #endif
229    
230 #ifdef TS_DO
231    t0 = t1 = t2 = ecore_time_unix_get();
232 #endif
233    TS("Begin Startup");
234
235    /* trap deadly bug signals and allow some form of sane recovery */
236    /* or ability to gdb attach and debug at this point - better than your */
237    /* wm/desktop vanishing and not knowing what happened */
238    if (!getenv("NOTIFY_SOCKET"))
239      {
240         TS("Signal Trap");
241         action.sa_sigaction = e_sigseg_act;
242         action.sa_flags = SA_NODEFER | SA_RESETHAND | SA_SIGINFO;
243         sigemptyset(&action.sa_mask);
244         sigaction(SIGSEGV, &action, NULL);
245
246         action.sa_sigaction = e_sigill_act;
247         action.sa_flags = SA_NODEFER | SA_RESETHAND | SA_SIGINFO;
248         sigemptyset(&action.sa_mask);
249         sigaction(SIGILL, &action, NULL);
250
251         action.sa_sigaction = e_sigfpe_act;
252         action.sa_flags = SA_NODEFER | SA_RESETHAND | SA_SIGINFO;
253         sigemptyset(&action.sa_mask);
254         sigaction(SIGFPE, &action, NULL);
255
256 #ifndef HAVE_WAYLAND_ONLY
257         action.sa_sigaction = e_sigbus_act;
258         action.sa_flags = SA_NODEFER | SA_RESETHAND | SA_SIGINFO;
259         sigemptyset(&action.sa_mask);
260         sigaction(SIGBUS, &action, NULL);
261 #endif
262
263         action.sa_sigaction = e_sigabrt_act;
264         action.sa_flags = SA_NODEFER | SA_RESETHAND | SA_SIGINFO;
265         sigemptyset(&action.sa_mask);
266         sigaction(SIGABRT, &action, NULL);
267         TS("Signal Trap Done");
268      }
269
270    t = ecore_time_unix_get();
271    s = getenv("E_START_TIME");
272    if ((s) && (!getenv("E_RESTART_OK")))
273      {
274         tstart = atof(s);
275         if ((t - tstart) < 5.0) safe_mode = EINA_TRUE;
276      }
277    tstart = t;
278    snprintf(buff, sizeof(buff), "%1.1f", tstart);
279    e_util_env_set("E_START_TIME", buff);
280
281    if (getenv("E_START_MTRACK"))
282      e_util_env_set("MTRACK", NULL);
283    TS("Eina Init");
284    if (!eina_init())
285      {
286         e_error_message_show(_("Enlightenment cannot initialize Eina!\n"));
287         _e_main_shutdown(-1);
288      }
289    _e_main_shutdown_push(eina_shutdown);
290    if (!e_log_init())
291      {
292         e_error_message_show(_("Enlightenment could not create a logging domain!\n"));
293         _e_main_shutdown(-1);
294      }
295 #ifdef TS_DO
296 #undef TS
297 # define TS(x)                                                    \
298   {                                                               \
299      t1 = ecore_time_unix_get();                                  \
300      printf("ESTART: %1.5f [%1.5f] - %s\n", t1 - t0, t1 - t2, x); \
301      t2 = t1;                                                     \
302   }
303 #endif
304    TS("Eina Init Done");
305    _e_main_shutdown_push(e_log_shutdown);
306
307    TS("Determine Prefix");
308    if (!e_prefix_determine(argv[0]))
309      {
310         fprintf(stderr,
311                 "ERROR: Enlightenment cannot determine it's installed\n"
312                 "       prefix from the system or argv[0].\n"
313                 "       This is because it is not on Linux AND has been\n"
314                 "       executed strangely. This is unusual.\n");
315      }
316    TS("Determine Prefix Done");
317
318    /* for debugging by redirecting stdout of e to a log file to tail */
319    setvbuf(stdout, NULL, _IONBF, 0);
320
321    TS("Environment Variables");
322    if (getenv("E_RESTART")) after_restart = EINA_TRUE;
323    if (getenv("DESKTOP_STARTUP_ID"))
324      e_util_env_set("DESKTOP_STARTUP_ID", NULL);
325    e_util_env_set("E_RESTART_OK", NULL);
326    e_util_env_set("PANTS", "ON");
327    e_util_env_set("DESKTOP", "Enlightenment");
328    TS("Environment Variables Done");
329
330    TS("Parse Arguments");
331    _e_main_parse_arguments(argc, argv);
332    TS("Parse Arguments Done");
333
334    /*** Initialize Core EFL Libraries We Need ***/
335
336    TS("Eet Init");
337    if (!eet_init())
338      {
339         e_error_message_show(_("Enlightenment cannot initialize Eet!\n"));
340         _e_main_shutdown(-1);
341      }
342    TS("Eet Init Done");
343    _e_main_shutdown_push(eet_shutdown);
344
345    TS("Ecore Init");
346    if (!ecore_init())
347      {
348         e_error_message_show(_("Enlightenment cannot initialize Ecore!\n"));
349         _e_main_shutdown(-1);
350      }
351    TS("Ecore Init Done");
352    _e_main_shutdown_push(ecore_shutdown);
353
354    e_first_frame = getenv("E_FIRST_FRAME");
355    if (e_first_frame && (!e_first_frame[0]))
356      e_first_frame = NULL;
357    else
358      e_first_frame_start_time = ecore_time_get();
359
360    TS("EIO Init");
361    if (!eio_init())
362      {
363         e_error_message_show(_("Enlightenment cannot initialize EIO!\n"));
364         _e_main_shutdown(-1);
365      }
366    TS("EIO Init Done");
367    _e_main_shutdown_push(eio_shutdown);
368
369    ecore_app_args_set(argc, (const char **)argv);
370
371    TS("Ecore Event Handlers");
372    if (!ecore_event_handler_add(ECORE_EVENT_SIGNAL_EXIT,
373                                 _e_main_cb_signal_exit, NULL))
374      {
375         e_error_message_show(_("Enlightenment cannot set up an exit signal handler.\n"
376                                "Perhaps you are out of memory?"));
377         _e_main_shutdown(-1);
378      }
379    if (!ecore_event_handler_add(ECORE_EVENT_SIGNAL_HUP,
380                                 _e_main_cb_signal_hup, NULL))
381      {
382         e_error_message_show(_("Enlightenment cannot set up a HUP signal handler.\n"
383                                "Perhaps you are out of memory?"));
384         _e_main_shutdown(-1);
385      }
386    if (!ecore_event_handler_add(ECORE_EVENT_SIGNAL_USER,
387                                 _e_main_cb_signal_user, NULL))
388      {
389         e_error_message_show(_("Enlightenment cannot set up a USER signal handler.\n"
390                                "Perhaps you are out of memory?"));
391         _e_main_shutdown(-1);
392      }
393    TS("Ecore Event Handlers Done");
394
395    TS("Ecore_File Init");
396    if (!ecore_file_init())
397      {
398         e_error_message_show(_("Enlightenment cannot initialize Ecore_File!\n"));
399         _e_main_shutdown(-1);
400      }
401    TS("Ecore_File Init Done");
402    _e_main_shutdown_push(ecore_file_shutdown);
403
404    TS("Ecore_Con Init");
405    if (!ecore_con_init())
406      {
407         e_error_message_show(_("Enlightenment cannot initialize Ecore_Con!\n"));
408         _e_main_shutdown(-1);
409      }
410    TS("Ecore_Con Init Done");
411    _e_main_shutdown_push(ecore_con_shutdown);
412
413    TS("Ecore_Ipc Init");
414    if (!ecore_ipc_init())
415      {
416         e_error_message_show(_("Enlightenment cannot initialize Ecore_Ipc!\n"));
417         _e_main_shutdown(-1);
418      }
419    TS("Ecore_Ipc Init Done");
420    _e_main_shutdown_push(ecore_ipc_shutdown);
421
422    _idle_before = ecore_idle_enterer_before_add(_e_main_cb_idle_before, NULL);
423
424    _xdg_data_dirs_augment();
425
426    TS("Ecore_Evas Init");
427    if (!ecore_evas_init())
428      {
429         e_error_message_show(_("Enlightenment cannot initialize Ecore_Evas!\n"));
430         _e_main_shutdown(-1);
431      }
432    TS("Ecore_Evas Init Done");
433 //   _e_main_shutdown_push(ecore_evas_shutdown);
434
435    TS("Elementary Init");
436    if (!elm_init(argc, argv))
437      {
438         e_error_message_show(_("Enlightenment cannot initialize Elementary!\n"));
439         _e_main_shutdown(-1);
440      }
441    TS("Elementary Init Done");
442    //_e_main_shutdown_push(elm_shutdown);
443
444    TS("Emotion Init");
445    if (!emotion_init())
446      {
447         e_error_message_show(_("Enlightenment cannot initialize Emotion!\n"));
448         _e_main_shutdown(-1);
449      }
450    TS("Emotion Init Done");
451    _e_main_shutdown_push((void *)emotion_shutdown);
452
453    /* e doesn't sync to compositor - it should be one */
454    ecore_evas_app_comp_sync_set(0);
455
456    TS("Ecore_Evas Engine Check");
457 #ifdef HAVE_WAYLAND_ONLY
458    if (!ecore_evas_engine_type_supported_get(ECORE_EVAS_ENGINE_WAYLAND_SHM))
459      {
460         e_error_message_show(_("Enlightenment found ecore_evas doesn't support the Wayland SHM\n"
461                                "rendering in Evas. Please check your installation of Evas and\n"
462                                 "Ecore and check they support the Wayland SHM rendering engine."));
463         _e_main_shutdown(-1);
464      }
465 #else
466    if (!ecore_evas_engine_type_supported_get(ECORE_EVAS_ENGINE_SOFTWARE_XCB))
467      {
468         if (!ecore_evas_engine_type_supported_get(ECORE_EVAS_ENGINE_SOFTWARE_XLIB))
469           {
470              e_error_message_show(_("Enlightenment found ecore_evas doesn't support the Software X11\n"
471                                     "rendering in Evas. Please check your installation of Evas and\n"
472                                     "Ecore and check they support the Software X11 rendering engine."));
473              _e_main_shutdown(-1);
474           }
475      }
476 #endif
477    if (!ecore_evas_engine_type_supported_get(ECORE_EVAS_ENGINE_SOFTWARE_BUFFER))
478      {
479         e_error_message_show(_("Enlightenment found ecore_evas doesn't support the Software Buffer\n"
480                                "rendering in Evas. Please check your installation of Evas and\n"
481                                "Ecore and check they support the Software Buffer rendering engine."));
482         _e_main_shutdown(-1);
483      }
484    TS("Ecore_Evas Engine Check Done");
485
486    TS("Edje Init");
487    if (!edje_init())
488      {
489         e_error_message_show(_("Enlightenment cannot initialize Edje!\n"));
490         _e_main_shutdown(-1);
491      }
492    TS("Edje Init Done");
493    _e_main_shutdown_push(edje_shutdown);
494    edje_freeze();
495
496    /*** Initialize E Subsystems We Need ***/
497
498    TS("E Intl Init");
499    if (!e_intl_init())
500      {
501         e_error_message_show(_("Enlightenment cannot initialize E_Intl!\n"));
502         _e_main_shutdown(-1);
503      }
504    TS("E Intl Init Done");
505    _e_main_shutdown_push(e_intl_shutdown);
506
507 #ifndef HAVE_WAYLAND_ONLY
508    /* init white box of death alert */
509    TS("E_Alert Init");
510    if (!e_alert_init())
511      {
512         e_error_message_show(_("Enlightenment cannot initialize its emergency alert system.\n"
513                                "Have you set your DISPLAY variable?"));
514         _e_main_shutdown(-1);
515      }
516    TS("E_Alert Init Done");
517    _e_main_shutdown_push(e_alert_shutdown);
518 #endif
519
520 #ifdef 0
521 //#ifdef HAVE_WAYLAND
522    /* init uuid store for window/surface properties */
523    TS("E_UUID_Store Init");
524    if (!e_uuid_store_init())
525      {
526         e_error_message_show(_("Enlightenment cannot initialize its UUID store.\n"));
527         _e_main_shutdown(-1);
528      }
529    TS("E_UUID_Store Init Done");
530    _e_main_shutdown_push(e_uuid_store_shutdown);
531 #endif
532
533    TS("E_Configure Init");
534    e_configure_init();
535    TS("E_Configure Init Done");
536
537    TS("E Directories Init");
538    /* setup directories we will be using for configurations storage etc. */
539    if (!_e_main_dirs_init())
540      {
541         e_error_message_show(_("Enlightenment cannot create directories in your home directory.\n"
542                                "Perhaps you have no home directory or the disk is full?"));
543         _e_main_shutdown(-1);
544      }
545    TS("E Directories Init Done");
546    _e_main_shutdown_push(_e_main_dirs_shutdown);
547
548    TS("E_Filereg Init");
549    if (!e_filereg_init())
550      {
551         e_error_message_show(_("Enlightenment cannot set up its file registry system.\n"));
552         _e_main_shutdown(-1);
553      }
554    TS("E_Filereg Init Done");
555    _e_main_shutdown_push(e_filereg_shutdown);
556
557    TS("E_Config Init");
558    if (!e_config_init())
559      {
560         e_error_message_show(_("Enlightenment cannot set up its config system.\n"));
561         _e_main_shutdown(-1);
562      }
563    TS("E_Config Init Done");
564    _e_main_shutdown_push(e_config_shutdown);
565
566    TS("E_Env Init");
567    if (!e_env_init())
568      {
569         e_error_message_show(_("Enlightenment cannot set up its environment.\n"));
570         _e_main_shutdown(-1);
571      }
572    TS("E_Env Init Done");
573    _e_main_shutdown_push(e_env_shutdown);
574
575    efreet_desktop_environment_set(e_config->desktop_environment);
576    e_util_env_set("E_ICON_THEME", e_config->icon_theme);
577    ecore_exe_run_priority_set(e_config->priority);
578    locked |= e_config->desklock_start_locked;
579
580    s = getenv("E_DESKLOCK_LOCKED");
581    if ((s) && (!strcmp(s, "locked"))) waslocked = EINA_TRUE;
582
583    TS("E Paths Init");
584    if (!_e_main_path_init())
585      {
586         e_error_message_show(_("Enlightenment cannot set up paths for finding files.\n"
587                                "Perhaps you are out of memory?"));
588         _e_main_shutdown(-1);
589      }
590    TS("E Paths Init Done");
591    _e_main_shutdown_push(_e_main_path_shutdown);
592
593    TS("E_Ipc Init");
594    if (!e_ipc_init()) _e_main_shutdown(-1);
595    TS("E_Ipc Init Done");
596    _e_main_shutdown_push(e_ipc_shutdown);
597
598    edje_frametime_set(1.0 / e_config->framerate);
599
600    TS("E_Font Init");
601    if (!e_font_init())
602      {
603         e_error_message_show(_("Enlightenment cannot set up its font system.\n"));
604         _e_main_shutdown(-1);
605      }
606    TS("E_Font Init Done");
607    _e_main_shutdown_push(e_font_shutdown);
608
609    TS("E_Font Apply");
610    e_font_apply();
611    TS("E_Font Apply Done");
612
613    TS("E_Theme Init");
614    if (!e_theme_init())
615      {
616         e_error_message_show(_("Enlightenment cannot set up its theme system.\n"));
617         _e_main_shutdown(-1);
618      }
619    TS("E_Theme Init Done");
620    _e_main_shutdown_push(e_theme_shutdown);
621
622    TS("E_Moveresize Init");
623    e_moveresize_init();
624    TS("E_Moveresize Init Done");
625    _e_main_shutdown_push(e_moveresize_shutdown);
626
627    if (e_config->show_splash)
628      e_init_status_set(_("Setup Message Bus"));
629    TS("E_Msgbus Init");
630    if (e_msgbus_init())
631      _e_main_shutdown_push(e_msgbus_shutdown);
632    TS("E_Msgbus Init Done");
633
634    TS("Efreet Init");
635    if (!efreet_init())
636      {
637         e_error_message_show(_("Enlightenment cannot initialize the FDO desktop system.\n"
638                                "Perhaps you lack permissions on ~/.cache/efreet or are\n"
639                                "out of memory or disk space?"));
640         _e_main_shutdown(-1);
641      }
642    TS("Efreet Init Done");
643    _e_main_shutdown_push(efreet_shutdown);
644
645    if (e_config->show_splash)
646      e_init_status_set(_("Starting International Support"));
647    TS("E_Intl Post Init");
648    if (!e_intl_post_init())
649      {
650         e_error_message_show(_("Enlightenment cannot set up its intl system.\n"));
651         _e_main_shutdown(-1);
652      }
653    TS("E_Intl Post Init Done");
654    _e_main_shutdown_push(e_intl_post_shutdown);
655
656    e_screensaver_preinit();
657
658    if (e_config->show_splash)
659      e_init_status_set(_("Setup Actions"));
660    TS("E_Actions Init");
661    if (!e_actions_init())
662      {
663         e_error_message_show(_("Enlightenment cannot set up its actions system.\n"));
664         _e_main_shutdown(-1);
665      }
666    TS("E_Actions Init Done");
667    _e_main_shutdown_push(e_actions_shutdown);
668
669    /* these just add event handlers and can't fail
670     * timestamping them is dumb.
671     */
672    e_zone_init();
673    e_desk_init();
674    e_exehist_init();
675
676    if (e_config->show_splash)
677      e_init_status_set(_("Setup Powersave Modes"));
678    TS("E_Powersave Init");
679    if (!e_powersave_init())
680      {
681         e_error_message_show(_("Enlightenment cannot set up its powersave modes.\n"));
682         _e_main_shutdown(-1);
683      }
684    TS("E_Powersave Init Done");
685    _e_main_shutdown_push(e_powersave_shutdown);
686
687    if (e_config->show_splash)
688      e_init_status_set(_("Setup Screensaver"));
689    TS("E_Screensaver Init");
690    if (!e_screensaver_init())
691      {
692         e_error_message_show(_("Enlightenment cannot configure the X screensaver.\n"));
693         _e_main_shutdown(-1);
694      }
695    TS("E_Screensaver Init Done");
696    _e_main_shutdown_push(e_screensaver_shutdown);
697
698    if (e_config->show_splash)
699      e_init_status_set(_("Setup Screens"));
700    TS("Screens Init");
701    if (!_e_main_screens_init())
702      {
703         e_error_message_show(_("Enlightenment set up window management for all the screens on your system\n"
704                                "failed. Perhaps another window manager is running?\n"));
705         _e_main_shutdown(-1);
706      }
707    TS("Screens Init Done");
708    _e_main_shutdown_push(_e_main_screens_shutdown);
709    e_screensaver_force_update();
710
711    TS("E_Pointer Init");
712    if (!e_pointer_init())
713      {
714         e_error_message_show(_("Enlightenment cannot set up its pointer system.\n"));
715         _e_main_shutdown(-1);
716      }
717    TS("E_Pointer Init Done");
718    _e_main_shutdown_push(e_pointer_shutdown);
719    e_menu_init();
720
721    TS("E_Scale Init");
722    if (!e_scale_init())
723      {
724         e_error_message_show(_("Enlightenment cannot set up its scale system.\n"));
725         _e_main_shutdown(-1);
726      }
727    TS("E_Scale Init Done");
728    _e_main_shutdown_push(e_scale_shutdown);
729
730    if (e_config->show_splash)
731      {
732         TS("E_Splash Init");
733         if (!e_init_init())
734           {
735              e_error_message_show(_("Enlightenment cannot set up its init screen.\n"));
736              _e_main_shutdown(-1);
737           }
738         TS("E_Splash Init Done");
739         _e_main_shutdown_push(e_init_shutdown);
740      }
741    if (!((!e_config->show_splash) || (after_restart)))
742      e_init_show();
743
744    if (!really_know)
745      {
746         TS("Test File Format Support");
747         _e_main_test_formats();
748         TS("Test File Format Support Done");
749      }
750    else
751      {
752         efreet_icon_extension_add(".svg");
753         efreet_icon_extension_add(".jpg");
754         efreet_icon_extension_add(".png");
755         efreet_icon_extension_add(".edj");
756      }
757
758    if (e_config->show_splash)
759      e_init_status_set(_("Setup ACPI"));
760    TS("E_Acpi Init");
761    e_acpi_init();
762    TS("E_Acpi Init Done");
763    _e_main_shutdown_push(e_acpi_shutdown);
764
765    if (e_config->show_splash)
766      e_init_status_set(_("Setup Backlight"));
767    TS("E_Backlight Init");
768    if (!e_backlight_init())
769      {
770         e_error_message_show(_("Enlightenment cannot configure the backlight.\n"));
771         _e_main_shutdown(-1);
772      }
773    TS("E_Backlight Init Done");
774
775    if (e_config->show_splash)
776      e_init_status_set(_("Setup DPMS"));
777    TS("E_Dpms Init");
778    if (!e_dpms_init())
779      {
780         e_error_message_show(_("Enlightenment cannot configure the DPMS settings.\n"));
781         _e_main_shutdown(-1);
782      }
783    TS("E_Dpms Init Done");
784    _e_main_shutdown_push(e_dpms_shutdown);
785
786    if (e_config->show_splash)
787      e_init_status_set(_("Setup Desklock"));
788    TS("E_Desklock Init");
789    if (!e_desklock_init())
790      {
791         e_error_message_show(_("Enlightenment cannot set up its desk locking system.\n"));
792         _e_main_shutdown(-1);
793      }
794    TS("E_Desklock Init Done");
795    _e_main_shutdown_push(e_desklock_shutdown);
796
797    if (waslocked || (locked && ((!after_restart) || (!getenv("E_DESKLOCK_UNLOCKED")))))
798      e_desklock_show(EINA_TRUE);
799
800    if (e_config->show_splash)
801      e_init_status_set(_("Setup Paths"));
802    TS("Efreet Paths");
803    _e_main_efreet_paths_init();
804    TS("Efreet Paths Done");
805
806    if (e_config->show_splash)
807      e_init_status_set(_("Setup System Controls"));
808    TS("E_Sys Init");
809    if (!e_sys_init())
810      {
811         e_error_message_show(_("Enlightenment cannot initialize the System Command system.\n"));
812         _e_main_shutdown(-1);
813      }
814    TS("E_Sys Init Done");
815    _e_main_shutdown_push(e_sys_shutdown);
816
817    if (e_config->show_splash)
818      e_init_status_set(_("Setup Execution System"));
819    TS("E_Exec Init");
820    if (!e_exec_init())
821      {
822         e_error_message_show(_("Enlightenment cannot set up its exec system.\n"));
823         _e_main_shutdown(-1);
824      }
825    TS("E_Exec Init Done");
826
827    TS("E_Comp Freeze");
828    e_comp_all_freeze();
829    TS("E_Comp Freeze Done");
830
831    if (e_config->show_splash)
832      e_init_status_set(_("Setup Filemanager"));
833    TS("E_Fm2 Init");
834    if (!e_fm2_init())
835      {
836         e_error_message_show(_("Enlightenment cannot initialize the File manager.\n"));
837         _e_main_shutdown(-1);
838      }
839    TS("E_Fm2 Init Done");
840    _e_main_shutdown_push(e_fm2_shutdown);
841
842    if (e_config->show_splash)
843      e_init_status_set(_("Setup Message System"));
844    TS("E_Msg Init");
845    if (!e_msg_init())
846      {
847         e_error_message_show(_("Enlightenment cannot set up its msg system.\n"));
848         _e_main_shutdown(-1);
849      }
850    TS("E_Msg Init Done");
851    _e_main_shutdown_push(e_msg_shutdown);
852
853    if (e_config->show_splash)
854      e_init_status_set(_("Setup Grab Input Handling"));
855    TS("E_Grabinput Init");
856    if (!e_grabinput_init())
857      {
858         e_error_message_show(_("Enlightenment cannot set up its grab input handling system.\n"));
859         _e_main_shutdown(-1);
860      }
861    TS("E_Grabinput Init Done");
862    _e_main_shutdown_push(e_grabinput_shutdown);
863
864    if (e_config->show_splash)
865      e_init_status_set(_("Setup Modules"));
866    TS("E_Module Init");
867    if (!e_module_init())
868      {
869         e_error_message_show(_("Enlightenment cannot set up its module system.\n"));
870         _e_main_shutdown(-1);
871      }
872    TS("E_Module Init Done");
873    _e_main_shutdown_push(e_module_shutdown);
874
875    if (e_config->show_splash)
876      e_init_status_set(_("Setup Remembers"));
877    TS("E_Remember Init");
878    if (!e_remember_init(after_restart ? E_STARTUP_RESTART : E_STARTUP_START))
879      {
880         e_error_message_show(_("Enlightenment cannot setup remember settings.\n"));
881         _e_main_shutdown(-1);
882      }
883    TS("E_Remember Init Done");
884    _e_main_shutdown_push(e_remember_shutdown);
885
886    if (e_config->show_splash)
887      e_init_status_set(_("Setup Gadcon"));
888    TS("E_Gadcon Init");
889    if (!e_gadcon_init())
890      {
891         e_error_message_show(_("Enlightenment cannot set up its gadget control system.\n"));
892         _e_main_shutdown(-1);
893      }
894    TS("E_Gadcon Init Done");
895    _e_main_shutdown_push(e_gadcon_shutdown);
896
897    if (e_config->show_splash)
898      e_init_status_set(_("Setup Toolbars"));
899    TS("E_Toolbar Init");
900    if (!e_toolbar_init())
901      {
902         e_error_message_show(_("Enlightenment cannot set up its toolbars.\n"));
903         _e_main_shutdown(-1);
904      }
905    TS("E_Toolbar Init Done");
906    _e_main_shutdown_push(e_toolbar_shutdown);
907
908    if (e_config->show_splash)
909      e_init_status_set(_("Setup Wallpaper"));
910    TS("E_Bg Init");
911    if (!e_bg_init())
912      {
913         e_error_message_show(_("Enlightenment cannot set up its desktop background system.\n"));
914         _e_main_shutdown(-1);
915      }
916    TS("E_Bg Init Done");
917    _e_main_shutdown_push(e_bg_shutdown);
918
919    if (e_config->show_splash)
920      e_init_status_set(_("Setup Mouse"));
921    TS("E_Mouse Init");
922    if (!e_mouse_update())
923      {
924         e_error_message_show(_("Enlightenment cannot configure the mouse settings.\n"));
925         _e_main_shutdown(-1);
926      }
927    TS("E_Mouse Init Done");
928
929    if (e_config->show_splash)
930      e_init_status_set(_("Setup Bindings"));
931    TS("E_Bindings Init");
932    if (!e_bindings_init())
933      {
934         e_error_message_show(_("Enlightenment cannot set up its bindings system.\n"));
935         _e_main_shutdown(-1);
936      }
937    TS("E_Bindings Init Done");
938    _e_main_shutdown_push(e_bindings_shutdown);
939
940    if (e_config->show_splash)
941      e_init_status_set(_("Setup Thumbnailer"));
942    TS("E_Thumb Init");
943    if (!e_thumb_init())
944      {
945         e_error_message_show(_("Enlightenment cannot initialize the Thumbnailing system.\n"));
946         _e_main_shutdown(-1);
947      }
948    TS("E_Thumb Init Done");
949    _e_main_shutdown_push(e_thumb_shutdown);
950
951    TS("E_Icon Init");
952    if (!e_icon_init())
953      {
954         e_error_message_show(_("Enlightenment cannot initialize the Icon Cache system.\n"));
955         _e_main_shutdown(-1);
956      }
957    TS("E_Icon Init Done");
958    _e_main_shutdown_push(e_icon_shutdown);
959
960    TS("E_Update Init");
961    if (!e_update_init())
962      {
963         e_error_message_show(_("Enlightenment cannot initialize the Update system.\n"));
964         _e_main_shutdown(-1);
965      }
966    TS("E_Update Init Done");
967    _e_main_shutdown_push(e_update_shutdown);
968
969    if (e_config->show_splash)
970      e_init_status_set(_("Setup Desktop Environment"));
971    TS("E_Deskenv Init");
972    if (!e_deskenv_init())
973      {
974         e_error_message_show(_("Enlightenment cannot initialize its desktop environment.\n"));
975         _e_main_shutdown(-1);
976      }
977    TS("E_Deskenv Init Done");
978    _e_main_shutdown_push(e_deskenv_shutdown);
979
980    if (e_config->show_splash)
981      e_init_status_set(_("Setup File Ordering"));
982    TS("E_Order Init");
983    if (!e_order_init())
984      {
985         e_error_message_show(_("Enlightenment cannot set up its order file system.\n"));
986         _e_main_shutdown(-1);
987      }
988    TS("E_Order Init Done");
989    _e_main_shutdown_push(e_order_shutdown);
990
991    TS("E_Comp_Canvas Keys Grab");
992    e_comp_canvas_keys_grab();
993    TS("E_Comp_Canvas Keys Grab Done");
994
995    if (e_config->show_splash)
996      e_init_status_set(_("Load Modules"));
997    TS("Load Modules");
998    _e_main_modules_load(safe_mode);
999    TS("Load Modules Done");
1000
1001    TS("Run Startup Apps");
1002    if (!nostartup)
1003      {
1004         if (after_restart)
1005           e_startup(E_STARTUP_RESTART);
1006         else
1007           e_startup(E_STARTUP_START);
1008      }
1009    TS("Run Startup Apps Done");
1010
1011    if (e_config->show_splash && (!after_restart))
1012      ecore_timer_add(2.0, _e_main_cb_startup_fake_end, NULL);
1013
1014    TS("E_Comp Thaw");
1015    e_comp_all_thaw();
1016    TS("E_Comp Thaw Done");
1017
1018    TS("E_Test Init");
1019    e_test();
1020    TS("E_Test Done");
1021
1022    if (e_config->show_splash)
1023      e_init_status_set(_("Setup Shelves"));
1024    TS("E_Shelf Init");
1025    if (!e_shelf_init())
1026      {
1027         e_error_message_show(_("Enlightenment cannot set up its module system.\n"));
1028         _e_main_shutdown(-1);
1029      }
1030    TS("E_Shelf Init Done");
1031
1032    ecore_idle_enterer_before_add(_e_main_shelf_init_job, NULL);
1033
1034    _idle_after = ecore_idle_enterer_add(_e_main_cb_idle_after, NULL);
1035
1036    if (e_config->show_splash)
1037      e_init_status_set(_("Almost Done"));
1038
1039    starting = EINA_FALSE;
1040    inloop = EINA_TRUE;
1041
1042    e_util_env_set("E_RESTART", "1");
1043
1044    TS("MAIN LOOP AT LAST");
1045    if (!setjmp(x_fatal_buff))
1046      ecore_main_loop_begin();
1047    else
1048      CRI("FATAL: X Died. Connection gone. Abbreviated Shutdown\n");
1049
1050    inloop = EINA_FALSE;
1051    stopping = EINA_TRUE;
1052
1053    //if (!x_fatal) e_canvas_idle_flush();
1054
1055    e_config_save_flush();
1056    _e_main_desk_save();
1057    e_remember_internal_save();
1058    e_comp_internal_save();
1059
1060    _e_main_shutdown(0);
1061
1062    if (restart)
1063      {
1064         e_util_env_set("E_RESTART_OK", "1");
1065         if (getenv("E_START_MTRACK"))
1066           e_util_env_set("MTRACK", "track");
1067         ecore_app_restart();
1068      }
1069
1070    e_prefix_shutdown();
1071
1072    return 0;
1073 }
1074
1075 E_API double
1076 e_main_ts(const char *str)
1077 {
1078    double ret;
1079    t1 = ecore_time_unix_get();
1080    printf("ESTART: %1.5f [%1.5f] - %s\n", t1 - t0, t1 - t2, str);
1081    ret = t1 - t2;
1082    t2 = t1;
1083    return ret;
1084 }
1085
1086 /* local functions */
1087 static void
1088 _e_main_shutdown(int errcode)
1089 {
1090    int i = 0;
1091    char buf[PATH_MAX];
1092    const char *dir;
1093
1094    printf("E: Begin Shutdown Procedure!\n");
1095
1096    if (_idle_before) ecore_idle_enterer_del(_idle_before);
1097    _idle_before = NULL;
1098    if (_idle_after) ecore_idle_enterer_del(_idle_after);
1099    _idle_after = NULL;
1100
1101    dir = getenv("XDG_RUNTIME_DIR");
1102    if (dir)
1103      {
1104         snprintf(buf, sizeof(buf), "%s/.e-deleteme", dir);
1105         if (ecore_file_exists(buf)) ecore_file_recursive_rm(dir);
1106      }
1107    for (i = (_e_main_lvl - 1); i >= 0; i--)
1108      (*_e_main_shutdown_func[i])();
1109    if (errcode < 0) exit(errcode);
1110 }
1111
1112 static void
1113 _e_main_shutdown_push(int (*func)(void))
1114 {
1115    _e_main_lvl++;
1116    if (_e_main_lvl > MAX_LEVEL)
1117      {
1118         _e_main_lvl--;
1119         e_error_message_show("WARNING: too many init levels. MAX = %i\n",
1120                              MAX_LEVEL);
1121         return;
1122      }
1123    _e_main_shutdown_func[_e_main_lvl - 1] = func;
1124 }
1125
1126 static void
1127 _e_main_parse_arguments(int argc, char **argv)
1128 {
1129    char *s = NULL;
1130    int i = 0;
1131
1132    /* handle some command-line parameters */
1133    for (i = 1; i < argc; i++)
1134      {
1135         if ((!strcmp(argv[i], "-display")) && (i < (argc - 1)))
1136           {
1137              i++;
1138              e_util_env_set("DISPLAY", argv[i]);
1139           }
1140         else if ((!strcmp(argv[i], "-fake-xinerama-screen")) && (i < (argc - 1)))
1141           {
1142              int x, y, w, h;
1143
1144              i++;
1145              if (sscanf(argv[i], "%ix%i+%i+%i", &w, &h, &x, &y) == 4)
1146                e_xinerama_fake_screen_add(x, y, w, h);
1147           }
1148         else if (!strcmp(argv[i], "-good"))
1149           {
1150              good = EINA_TRUE;
1151              evil = EINA_FALSE;
1152              printf("LA LA LA\n");
1153           }
1154         else if (!strcmp(argv[i], "-evil"))
1155           {
1156              good = EINA_FALSE;
1157              evil = EINA_TRUE;
1158              printf("MUHAHAHAHHAHAHAHAHA\n");
1159           }
1160         else if (!strcmp(argv[i], "-psychotic"))
1161           {
1162              good = EINA_TRUE;
1163              evil = EINA_TRUE;
1164              printf("MUHAHALALALALALALALA\n");
1165           }
1166         else if ((!strcmp(argv[i], "-profile")) && (i < (argc - 1)))
1167           {
1168              i++;
1169              if (!getenv("E_CONF_PROFILE"))
1170                e_util_env_set("E_CONF_PROFILE", argv[i]);
1171           }
1172         else if (!strcmp(argv[i], "-i-really-know-what-i-am-doing-and-accept-full-responsibility-for-it"))
1173           really_know = EINA_TRUE;
1174         else if (!strcmp(argv[i], "-locked"))
1175           locked = EINA_TRUE;
1176         else if (!strcmp(argv[i], "-nopause"))
1177           e_nopause = EINA_TRUE;
1178         else if ((!strcmp(argv[i], "-version")) ||
1179                  (!strcmp(argv[i], "--version")))
1180           {
1181              printf(_("Version: %s\n"), PACKAGE_VERSION);
1182              _e_main_shutdown(-1);
1183           }
1184         else if ((!strcmp(argv[i], "-h")) ||
1185                  (!strcmp(argv[i], "-help")) ||
1186                  (!strcmp(argv[i], "--help")))
1187           {
1188              printf
1189                (_(
1190                  "Options:\n"
1191                  "\t-display DISPLAY\n"
1192                  "\t\tConnect to display named DISPLAY.\n"
1193                  "\t\tEG: -display :1.0\n"
1194                  "\t-fake-xinerama-screen WxH+X+Y\n"
1195                  "\t\tAdd a FAKE xinerama screen (instead of the real ones)\n"
1196                  "\t\tgiven the geometry. Add as many as you like. They all\n"
1197                  "\t\treplace the real xinerama screens, if any. This can\n"
1198                  "\t\tbe used to simulate xinerama.\n"
1199                  "\t\tEG: -fake-xinerama-screen 800x600+0+0 -fake-xinerama-screen 800x600+800+0\n"
1200                  "\t-profile CONF_PROFILE\n"
1201                  "\t\tUse the configuration profile CONF_PROFILE instead of the user selected default or just \"default\".\n"
1202                  "\t-good\n"
1203                  "\t\tBe good.\n"
1204                  "\t-evil\n"
1205                  "\t\tBe evil.\n"
1206                  "\t-psychotic\n"
1207                  "\t\tBe psychotic.\n"
1208                  "\t-locked\n"
1209                  "\t\tStart with desklock on, so password will be asked.\n"
1210                  "\t-i-really-know-what-i-am-doing-and-accept-full-responsibility-for-it\n"
1211                  "\t\tIf you need this help, you don't need this option.\n"
1212                  "\t-version\n"
1213                  )
1214                );
1215              _e_main_shutdown(-1);
1216           }
1217      }
1218
1219    /* fix up DISPLAY to be :N.0 if no .screen is in it */
1220    s = getenv("DISPLAY");
1221    if (s)
1222      {
1223         char *p, buff[4096];
1224
1225         if (!(p = strrchr(s, ':')))
1226           {
1227              snprintf(buff, sizeof(buff), "%s:0.0", s);
1228              e_util_env_set("DISPLAY", buff);
1229           }
1230         else
1231           {
1232              if (!strrchr(p, '.'))
1233                {
1234                   snprintf(buff, sizeof(buff), "%s.0", s);
1235                   e_util_env_set("DISPLAY", buff);
1236                }
1237           }
1238      }
1239
1240    /* we want to have been launched by enlightenment_start. there is a very */
1241    /* good reason we want to have been launched this way, thus check */
1242    if (!getenv("E_START"))
1243      {
1244         e_error_message_show(_("You are executing enlightenment directly. This is\n"
1245                                "bad. Please do not execute the \"enlightenment\"\n"
1246                                "binary. Use the \"enlightenment_start\" launcher. It\n"
1247                                "will handle setting up environment variables, paths,\n"
1248                                "and launching any other required services etc.\n"
1249                                "before enlightenment itself begins running.\n"));
1250         _e_main_shutdown(-1);
1251      }
1252 }
1253
1254 EINTERN void
1255 _e_main_cb_x_fatal(void *data EINA_UNUSED)
1256 {
1257    e_error_message_show("Lost X Connection.\n");
1258    ecore_main_loop_quit();
1259    if (!x_fatal)
1260      {
1261         x_fatal = EINA_TRUE;
1262         if (inloop) longjmp(x_fatal_buff, -99);
1263      }
1264 }
1265
1266 static Eina_Bool
1267 _e_main_cb_signal_exit(void *data EINA_UNUSED, int ev_type EINA_UNUSED, void *ev EINA_UNUSED)
1268 {
1269    /* called on ctrl-c, kill (pid) (also SIGINT, SIGTERM and SIGQIT) */
1270    e_sys_action_do(E_SYS_EXIT, NULL);
1271    return ECORE_CALLBACK_RENEW;
1272 }
1273
1274 static Eina_Bool
1275 _e_main_cb_signal_hup(void *data EINA_UNUSED, int ev_type EINA_UNUSED, void *ev EINA_UNUSED)
1276 {
1277    e_sys_action_do(E_SYS_RESTART, NULL);
1278    return ECORE_CALLBACK_RENEW;
1279 }
1280
1281 static Eina_Bool
1282 _e_main_cb_signal_user(void *data EINA_UNUSED, int ev_type EINA_UNUSED, void *ev)
1283 {
1284    Ecore_Event_Signal_User *e = ev;
1285
1286    if (e->number == 1)
1287      {
1288 //        E_Action *a = e_action_find("configuration");
1289 //        if ((a) && (a->func.go)) a->func.go(NULL, NULL);
1290      }
1291    else if (e->number == 2)
1292      {
1293         // comp module has its own handler for this for enabling/disabling fps debug
1294      }
1295    return ECORE_CALLBACK_RENEW;
1296
1297 }
1298
1299 static int
1300 _e_main_dirs_init(void)
1301 {
1302    const char *base;
1303    const char *dirs[] =
1304    {
1305       "images",
1306       "fonts",
1307       "themes",
1308       "icons",
1309       "backgrounds",
1310       "applications",
1311       "applications/menu",
1312       "applications/menu/favorite",
1313       "applications/menu/all",
1314       "applications/bar",
1315       "applications/bar/default",
1316       "applications/startup",
1317       "applications/restart",
1318       "applications/trash",
1319       "applications/desk-lock",
1320       "applications/desk-unlock",
1321       "modules",
1322       "config",
1323       "locale",
1324       "input_methods",
1325       NULL
1326    };
1327
1328    base = e_user_dir_get();
1329    if (ecore_file_mksubdirs(base, dirs) != sizeof(dirs) / sizeof(dirs[0]) - 1)
1330      {
1331         e_error_message_show("Could not create one of the required "
1332                              "subdirectories of '%s'\n", base);
1333         return 0;
1334      }
1335
1336    return 1;
1337 }
1338
1339 static int
1340 _e_main_dirs_shutdown(void)
1341 {
1342    return 1;
1343 }
1344
1345 static int
1346 _e_main_path_init(void)
1347 {
1348    char buf[PATH_MAX];
1349
1350    /* setup data paths */
1351    path_data = e_path_new();
1352    if (!path_data)
1353      {
1354         e_error_message_show("Cannot allocate path for path_data\n");
1355         return 0;
1356      }
1357    e_prefix_data_concat_static(buf, "data");
1358    e_path_default_path_append(path_data, buf);
1359    e_path_user_path_set(path_data, &(e_config->path_append_data));
1360
1361    /* setup image paths */
1362    path_images = e_path_new();
1363    if (!path_images)
1364      {
1365         e_error_message_show("Cannot allocate path for path_images\n");
1366         return 0;
1367      }
1368    e_user_dir_concat_static(buf, "/images");
1369    e_path_default_path_append(path_images, buf);
1370    e_prefix_data_concat_static(buf, "data/images");
1371    e_path_default_path_append(path_images, buf);
1372    e_path_user_path_set(path_images, &(e_config->path_append_images));
1373
1374    /* setup font paths */
1375    path_fonts = e_path_new();
1376    if (!path_fonts)
1377      {
1378         e_error_message_show("Cannot allocate path for path_fonts\n");
1379         return 0;
1380      }
1381    e_user_dir_concat_static(buf, "/fonts");
1382    e_path_default_path_append(path_fonts, buf);
1383    e_prefix_data_concat_static(buf, "data/fonts");
1384    e_path_default_path_append(path_fonts, buf);
1385    e_path_user_path_set(path_fonts, &(e_config->path_append_fonts));
1386
1387    /* setup icon paths */
1388    path_icons = e_path_new();
1389    if (!path_icons)
1390      {
1391         e_error_message_show("Cannot allocate path for path_icons\n");
1392         return 0;
1393      }
1394    e_user_dir_concat_static(buf, "/icons");
1395    e_path_default_path_append(path_icons, buf);
1396    e_prefix_data_concat_static(buf, "data/icons");
1397    e_path_default_path_append(path_icons, buf);
1398    e_path_user_path_set(path_icons, &(e_config->path_append_icons));
1399
1400    /* setup module paths */
1401    path_modules = e_path_new();
1402    if (!path_modules)
1403      {
1404         e_error_message_show("Cannot allocate path for path_modules\n");
1405         return 0;
1406      }
1407    e_user_dir_concat_static(buf, "/modules");
1408    e_path_default_path_append(path_modules, buf);
1409    snprintf(buf, sizeof(buf), "%s/enlightenment/modules", e_prefix_lib_get());
1410    e_path_default_path_append(path_modules, buf);
1411    /* FIXME: eventually this has to go - moduels should have installers that
1412     * add appropriate install paths (if not installed to user homedir) to
1413     * e's module search dirs
1414     */
1415    snprintf(buf, sizeof(buf), "%s/enlightenment/modules_extra", e_prefix_lib_get());
1416    e_path_default_path_append(path_modules, buf);
1417    e_path_user_path_set(path_modules, &(e_config->path_append_modules));
1418
1419    /* setup background paths */
1420    path_backgrounds = e_path_new();
1421    if (!path_backgrounds)
1422      {
1423         e_error_message_show("Cannot allocate path for path_backgrounds\n");
1424         return 0;
1425      }
1426    e_user_dir_concat_static(buf, "/backgrounds");
1427    e_path_default_path_append(path_backgrounds, buf);
1428    e_prefix_data_concat_static(buf, "data/backgrounds");
1429    e_path_default_path_append(path_backgrounds, buf);
1430    e_path_user_path_set(path_backgrounds, &(e_config->path_append_backgrounds));
1431
1432    path_messages = e_path_new();
1433    if (!path_messages)
1434      {
1435         e_error_message_show("Cannot allocate path for path_messages\n");
1436         return 0;
1437      }
1438    e_user_dir_concat_static(buf, "/locale");
1439    e_path_default_path_append(path_messages, buf);
1440    e_path_default_path_append(path_messages, e_prefix_locale_get());
1441    e_path_user_path_set(path_messages, &(e_config->path_append_messages));
1442
1443    return 1;
1444 }
1445
1446 static int
1447 _e_main_path_shutdown(void)
1448 {
1449    if (path_data)
1450      {
1451         e_object_del(E_OBJECT(path_data));
1452         path_data = NULL;
1453      }
1454    if (path_images)
1455      {
1456         e_object_del(E_OBJECT(path_images));
1457         path_images = NULL;
1458      }
1459    if (path_fonts)
1460      {
1461         e_object_del(E_OBJECT(path_fonts));
1462         path_fonts = NULL;
1463      }
1464    if (path_icons)
1465      {
1466         e_object_del(E_OBJECT(path_icons));
1467         path_icons = NULL;
1468      }
1469    if (path_modules)
1470      {
1471         e_object_del(E_OBJECT(path_modules));
1472         path_modules = NULL;
1473      }
1474    if (path_backgrounds)
1475      {
1476         e_object_del(E_OBJECT(path_backgrounds));
1477         path_backgrounds = NULL;
1478      }
1479    if (path_messages)
1480      {
1481         e_object_del(E_OBJECT(path_messages));
1482         path_messages = NULL;
1483      }
1484    return 1;
1485 }
1486
1487 static void
1488 _e_main_test_formats(void)
1489 {
1490    Evas *evas;
1491    Ecore_Evas *ee;
1492    Evas_Object *im, *txt;
1493    Evas_Coord tw, th;
1494    char buff[PATH_MAX];
1495
1496    if (e_config->show_splash)
1497      e_init_status_set(_("Testing Format Support"));
1498
1499    if (!(ee = ecore_evas_buffer_new(1, 1)))
1500      {
1501         e_error_message_show(_("Enlightenment found Evas can't create a buffer canvas. Please check\n"
1502                                "Evas has Software Buffer engine support.\n"));
1503         _e_main_shutdown(-1);
1504      }
1505    evas = ecore_evas_get(ee);
1506    im = evas_object_image_add(evas);
1507
1508    e_prefix_data_concat_static(buff, "data/images/test.svg");
1509    evas_object_image_file_set(im, buff, NULL);
1510    if (evas_object_image_load_error_get(im) != EVAS_LOAD_ERROR_NONE)
1511      {
1512         e_error_message_show(_("Enlightenment found Evas can't load SVG files. "
1513                                "Check Evas has SVG loader support.\n"));
1514      }
1515    else
1516      efreet_icon_extension_add(".svg");
1517
1518    e_prefix_data_concat_static(buff, "data/images/test.jpg");
1519    evas_object_image_file_set(im, buff, NULL);
1520    if (evas_object_image_load_error_get(im) != EVAS_LOAD_ERROR_NONE)
1521      {
1522         e_error_message_show(_("Enlightenment found Evas can't load JPEG files. "
1523                                "Check Evas has JPEG loader support.\n"));
1524         _e_main_shutdown(-1);
1525      }
1526    efreet_icon_extension_add(".jpg");
1527
1528    e_prefix_data_concat_static(buff, "data/images/test.png");
1529    evas_object_image_file_set(im, buff, NULL);
1530    if (evas_object_image_load_error_get(im) != EVAS_LOAD_ERROR_NONE)
1531      {
1532         e_error_message_show(_("Enlightenment found Evas can't load PNG files. "
1533                                "Check Evas has PNG loader support.\n"));
1534         _e_main_shutdown(-1);
1535      }
1536    efreet_icon_extension_add(".png");
1537
1538    e_prefix_data_concat_static(buff, "data/images/test.edj");
1539    evas_object_image_file_set(im, buff, "images/0");
1540    if (evas_object_image_load_error_get(im) != EVAS_LOAD_ERROR_NONE)
1541      {
1542         e_error_message_show(_("Enlightenment found Evas can't load EET files. "
1543                                "Check Evas has EET loader support.\n"));
1544         _e_main_shutdown(-1);
1545      }
1546    efreet_icon_extension_add(".edj");
1547
1548    evas_object_del(im);
1549
1550    txt = evas_object_text_add(evas);
1551    evas_object_text_font_set(txt, "Sans", 10);
1552    evas_object_text_text_set(txt, "Hello");
1553    evas_object_geometry_get(txt, NULL, NULL, &tw, &th);
1554    if ((tw <= 0) && (th <= 0))
1555      {
1556         e_error_message_show(_("Enlightenment found Evas can't load the 'Sans' font. Check Evas has fontconfig\n"
1557                                "support and system fontconfig defines a 'Sans' font.\n"));
1558         _e_main_shutdown(-1);
1559      }
1560    evas_object_del(txt);
1561    ecore_evas_free(ee);
1562 }
1563
1564 static int
1565 _e_main_screens_init(void)
1566 {
1567    TS("\tscreens: client");
1568    if (!e_client_init()) return 0;
1569    TS("\tscreens: win");
1570    if (!e_win_init()) return 0;
1571 #ifndef HAVE_WAYLAND_ONLY
1572    TS("E_Xkb Init");
1573    if (!e_xkb_init())
1574      {
1575         e_error_message_show(_("Enlightenment cannot setup XKB Keyboard layouts.\n"));
1576         _e_main_shutdown(-1);
1577      }
1578    TS("E_Xkb Init Done");
1579 #endif
1580
1581    TS("Compositor Init");
1582    if (!e_comp_init())
1583      {
1584         e_error_message_show(_("Enlightenment cannot create a compositor.\n"));
1585         _e_main_shutdown(-1);
1586      }
1587
1588    _e_main_desk_restore();
1589
1590 #ifndef HAVE_WAYLAND_ONLY
1591    if (e_config->show_splash)
1592      e_init_status_set(_("Setup DND"));
1593    TS("E_Dnd Init");
1594    if (!e_dnd_init())
1595      {
1596         e_error_message_show(_("Enlightenment cannot set up its dnd system.\n"));
1597         _e_main_shutdown(-1);
1598      }
1599    TS("E_Dnd Init Done");
1600    _e_main_shutdown_push(e_dnd_shutdown);
1601 #endif
1602
1603    return 1;
1604 }
1605
1606 static int
1607 _e_main_screens_shutdown(void)
1608 {
1609    e_win_shutdown();
1610    e_menu_shutdown();
1611    e_shelf_shutdown();
1612    e_comp_shutdown();
1613    e_client_shutdown();
1614    e_exehist_shutdown();
1615    e_backlight_shutdown();
1616    e_exec_shutdown();
1617
1618    e_desk_shutdown();
1619    e_zone_shutdown();
1620    return 1;
1621 }
1622
1623 static void
1624 _e_main_desk_save(void)
1625 {
1626    const Eina_List *l;
1627    char env[1024], name[1024];
1628    E_Zone *zone;
1629
1630    EINA_LIST_FOREACH(e_comp->zones, l, zone)
1631      {
1632         snprintf(name, sizeof(name), "DESK_%d_%d", 0, zone->num);
1633         snprintf(env, sizeof(env), "%d,%d", zone->desk_x_current, zone->desk_y_current);
1634         e_util_env_set(name, env);
1635      }
1636 }
1637
1638 static void
1639 _e_main_desk_restore(void)
1640 {
1641    const Eina_List *l;
1642    E_Zone *zone;
1643    char *env;
1644    char name[1024];
1645
1646    EINA_LIST_FOREACH(e_comp->zones, l, zone)
1647      {
1648         E_Desk *desk;
1649         int desk_x, desk_y;
1650
1651         snprintf(name, sizeof(name), "DESK_%d_%d", 0, zone->num);
1652         env = getenv(name);
1653         if (!env) continue;
1654         if (!sscanf(env, "%d,%d", &desk_x, &desk_y)) continue;
1655         desk = e_desk_at_xy_get(zone, desk_x, desk_y);
1656         if (!desk) continue;
1657         e_desk_show(desk);
1658      }
1659 }
1660
1661 static void
1662 _e_main_efreet_paths_init(void)
1663 {
1664    Eina_List **list;
1665
1666    if ((list = efreet_icon_extra_list_get()))
1667      {
1668         char buff[PATH_MAX];
1669
1670         e_user_dir_concat_static(buff, "icons");
1671         *list = eina_list_prepend(*list, (void *)eina_stringshare_add(buff));
1672         e_prefix_data_concat_static(buff, "data/icons");
1673         *list = eina_list_prepend(*list, (void *)eina_stringshare_add(buff));
1674      }
1675 }
1676
1677 static Eina_Bool
1678 _e_main_modules_load_after(void *d EINA_UNUSED, int type EINA_UNUSED, void *ev EINA_UNUSED)
1679 {
1680    e_int_config_modules(NULL, NULL);
1681    E_FREE_FUNC(mod_init_end, ecore_event_handler_del);
1682    return ECORE_CALLBACK_RENEW;
1683 }
1684
1685 static void
1686 _e_main_modules_load(Eina_Bool safe_mode)
1687 {
1688    if (!safe_mode)
1689      e_module_all_load();
1690    else
1691      {
1692         E_Module *m;
1693         char *crashmodule;
1694
1695         crashmodule = getenv("E_MODULE_LOAD");
1696         if (crashmodule) m = e_module_new(crashmodule);
1697
1698         if ((crashmodule) && (m))
1699           {
1700              e_module_disable(m);
1701              e_object_del(E_OBJECT(m));
1702
1703              e_error_message_show
1704                (_("Enlightenment crashed early on start and has<br>"
1705                   "been restarted. There was an error loading the<br>"
1706                   "module named: %s. This module has been disabled<br>"
1707                   "and will not be loaded."), crashmodule);
1708              e_util_dialog_show
1709                (_("Enlightenment crashed early on start and has been restarted"),
1710                _("Enlightenment crashed early on start and has been restarted.<br>"
1711                  "There was an error loading the module named: %s<br><br>"
1712                  "This module has been disabled and will not be loaded."), crashmodule);
1713              e_module_all_load();
1714           }
1715         else
1716           {
1717              e_error_message_show
1718                (_("Enlightenment crashed early on start and has<br>"
1719                   "been restarted. All modules have been disabled<br>"
1720                   "and will not be loaded to help remove any problem<br>"
1721                   "modules from your configuration. The module<br>"
1722                   "configuration dialog should let you select your<br>"
1723                   "modules again.\n"));
1724              e_util_dialog_show
1725                (_("Enlightenment crashed early on start and has been restarted"),
1726                _("Enlightenment crashed early on start and has been restarted.<br>"
1727                  "All modules have been disabled and will not be loaded to help<br>"
1728                  "remove any problem modules from your configuration.<br><br>"
1729                  "The module configuration dialog should let you select your<br>"
1730                  "modules again."));
1731           }
1732         mod_init_end = ecore_event_handler_add(E_EVENT_MODULE_INIT_END, _e_main_modules_load_after, NULL);
1733      }
1734 }
1735
1736 static Eina_Bool
1737 _e_main_cb_idle_before(void *data EINA_UNUSED)
1738 {
1739    e_menu_idler_before();
1740    e_client_idler_before();
1741    e_pointer_idler_before();
1742    edje_thaw();
1743    return ECORE_CALLBACK_RENEW;
1744 }
1745
1746 static Eina_Bool
1747 _e_main_cb_idle_after(void *data EINA_UNUSED)
1748 {
1749    static int first_idle = 1;
1750
1751    eet_clearcache();
1752    edje_freeze();
1753
1754 #ifdef E_RELEASE_BUILD
1755    if (first_idle)
1756      {
1757         TS("SLEEP");
1758         first_idle = 0;
1759         e_precache_end = EINA_TRUE;
1760      }
1761 #else
1762    if (first_idle++ < 60)
1763      {
1764         TS("SLEEP");
1765         if (!first_idle)
1766           e_precache_end = EINA_TRUE;
1767      }
1768 #endif
1769
1770    return ECORE_CALLBACK_RENEW;
1771 }
1772
1773 static Eina_Bool
1774 _e_main_cb_startup_fake_end(void *data EINA_UNUSED)
1775 {
1776    e_init_hide();
1777    return ECORE_CALLBACK_CANCEL;
1778 }