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