* Reverted a do not wanted change
[modest] / src / modest-main.c
index 44a3505..4e860b2 100644 (file)
@@ -115,6 +115,11 @@ main (int argc, char *argv[])
                { NULL, 0, 0, 0, NULL, NULL, NULL }
        };
 
+       /* Enable threads before anything else, to prevent memory corruption */
+       if (!g_thread_supported())
+               g_thread_init(NULL);
+       gdk_threads_init ();
+
        context = g_option_context_new (NULL);
        g_option_context_add_main_entries (context, options, NULL);
        
@@ -128,25 +133,26 @@ main (int argc, char *argv[])
        }
        g_option_context_free (context);
        
-       if (!modest_init_init_core ()) {
+       if (!modest_init_init_core (argc, argv)) {
                g_printerr ("modest: cannot init modest core\n");
                return MODEST_ERR_INIT;
-               
        }
        
        account_or_default = check_account (account);
        g_free (account);
        
        if (!batch) {
+               gdk_threads_enter ();
                if (!modest_init_init_ui (argc, argv)) {
                        g_printerr ("modest: cannot init modest ui\n");
                        retval = MODEST_ERR_UI;
+                       gdk_threads_leave ();
                        goto cleanup;
                } else {
                        GtkWidget *ui = NULL;
                        retval = start_ui (account_or_default,
                                           mailto, cc, bcc, subject, body, &ui);
-                       if (ui) 
+                       if (G_IS_OBJECT(ui))
                                g_signal_connect (G_OBJECT (ui), "show", G_CALLBACK(on_show), NULL);
                }
        } else {
@@ -241,6 +247,7 @@ start_ui (const gchar *account_name, const gchar* mailto, const gchar *cc, const
        
        gtk_widget_show_all (GTK_WIDGET (win));
        gtk_main();
+       gdk_threads_leave ();
        
        return MODEST_ERR_NONE;
 }