* src/modest-text-utils.[ch]:
[modest] / src / modest-main.c
index bd59104..ba4242f 100644 (file)
@@ -71,11 +71,31 @@ static gchar*           check_account (const gchar *account);
 
 static ModestErrorCode  start_ui      (const gchar *account,
                                       const gchar* mailto, const gchar *cc,
-                                      const gchar *bcc, const gchar* subject, const gchar *body);
+                                      const gchar *bcc, const gchar* subject, const gchar *body, GtkWidget **ui);
 
 static ModestErrorCode  send_mail     (const gchar* account,
                                       const gchar* mailto, const gchar *cc, const gchar *bcc,
                                       const gchar* subject, const gchar *body);
+
+static void 
+on_show (GtkWidget *widget, gpointer user_data)
+{
+       if (modest_conf_get_bool (modest_runtime_get_conf(),
+               MODEST_CONF_CONNECT_AT_STARTUP, NULL))
+       modest_platform_connect_and_wait(NULL);
+}
+
+static void
+log_default_handler (const gchar *log_domain,
+                    GLogLevelFlags log_level,
+                    const gchar *message,
+                    gpointer unused_data)
+{
+       if (log_level == G_LOG_LEVEL_ERROR || 
+           log_level == G_LOG_LEVEL_CRITICAL)
+               g_print ("EEEEE ------ %s\n", message);
+}
+
 int
 main (int argc, char *argv[])
 {
@@ -119,6 +139,8 @@ main (int argc, char *argv[])
        }
        g_option_context_free (context);
        
+       g_log_set_default_handler (log_default_handler, NULL);
+
        if (!modest_init_init_core ()) {
                g_printerr ("modest: cannot init modest core\n");
                return MODEST_ERR_INIT;
@@ -134,12 +156,11 @@ main (int argc, char *argv[])
                        retval = MODEST_ERR_UI;
                        goto cleanup;
                } else {
-                       if (modest_conf_get_bool (modest_runtime_get_conf(),
-                                                 MODEST_CONF_CONNECT_AT_STARTUP, NULL))
-                               modest_platform_connect_and_wait(NULL);
-                       
+                       GtkWidget *ui = NULL;
                        retval = start_ui (account_or_default,
-                                          mailto, cc, bcc, subject, body);
+                                          mailto, cc, bcc, subject, body, &ui);
+                       if (ui) 
+                               g_signal_connect (G_OBJECT (ui), "show", G_CALLBACK(on_show), NULL);
                }
        } else {
                if (!account_or_default) {
@@ -168,7 +189,7 @@ cleanup:
 
 static ModestErrorCode 
 start_ui (const gchar *account_name, const gchar* mailto, const gchar *cc, const gchar *bcc,
-         const gchar* subject, const gchar *body)
+         const gchar* subject, const gchar *body, GtkWidget **ui)
 {
        ModestWindow *win = NULL;
 
@@ -227,6 +248,7 @@ start_ui (const gchar *account_name, const gchar* mailto, const gchar *cc, const
        } else {
                ModestWindowMgr *mgr = modest_runtime_get_window_mgr ();
                modest_window_mgr_register_window (mgr, win);
+               *ui = (GtkWidget*) win;
                g_object_unref (win);
        }