- GOptionContext *context = NULL;
-
- GError *err = NULL;
- int retval = MODEST_ERR_NONE;
-
- static gboolean batch = FALSE;
- static gchar *mailto=NULL, *subject=NULL, *bcc=NULL,
- *cc=NULL, *body=NULL, *account=NULL;
-
- static GOptionEntry options[] = {
- { "mailto", 'm', 0, G_OPTION_ARG_STRING, &mailto,
- N_("New email to <addresses> (comma-separated)"), NULL},
- { "subject", 's', 0, G_OPTION_ARG_STRING, &subject,
- N_("Subject for a new mail"), NULL},
- { "body", 'b', 0, G_OPTION_ARG_STRING, &body,
- N_("Body for a new email"), NULL},
- { "cc", 'c', 0, G_OPTION_ARG_STRING, &cc,
- N_("Cc: addresses for a new mail (comma-separated)"), NULL},
- { "bcc", 'x', 0, G_OPTION_ARG_STRING, &bcc,
- N_("Bcc: addresses for a new mail (comma-separated)"), NULL},
- { "account", 'a', 0, G_OPTION_ARG_STRING, &account,
- N_("Account to use (if none specified, the default account will be used)"), NULL},
- { "batch", 'y', 0, G_OPTION_ARG_NONE, &batch,
- N_("Run in batch mode (don't show UI)"), NULL},
- { NULL, 0, 0, 0, NULL, NULL, NULL }
- };
-
- if (!modest_runtime_init ()) {
- g_printerr ("modest: cannot init runtime\n");
- return MODEST_ERR_INIT;
- }
-
- context = g_option_context_new (NULL);
- g_option_context_add_main_entries (context, options, NULL);
-
- if (!g_option_context_parse (context, &argc, &argv, &err)) {
- g_printerr ("modest: error in command line parameter(s): '%s', exiting\n",
- err ? err->message : "");
- g_error_free (err);
- g_option_context_free (context);
- retval = MODEST_ERR_OPTIONS;
- goto cleanup;
- }
- g_option_context_free (context);
-
- if (!batch) {
- if (!modest_runtime_init_ui (argc, argv)) {
- g_printerr ("modest: cannot start UI\n");
- retval = MODEST_ERR_UI;
- goto cleanup;
- } else
- retval = start_ui (mailto, cc, bcc, subject, body);
+ MainSignalHandlers *handlers;
+ ModestMailOperationQueue *mail_op_queue;
+
+ /* Protect the Gtk calls */
+ gdk_threads_enter ();
+ mail_op_queue = modest_runtime_get_mail_operation_queue ();
+
+ if (modest_mail_operation_queue_running_shutdown (mail_op_queue)) {
+
+ /* Disconnect signals. Will be freed by the destroy notify */
+ handlers = (MainSignalHandlers *) data;
+ g_signal_handler_disconnect (modest_runtime_get_mail_operation_queue (),
+ handlers->queue_handler);
+ g_signal_handler_disconnect (modest_runtime_get_window_mgr (),
+ handlers->window_list_handler);
+ g_signal_handler_disconnect (modest_runtime_get_account_store (),
+ handlers->get_password_handler);
+ g_free (handlers);
+
+ /* Wait for remaining tasks */
+ while (gtk_events_pending ())
+ gtk_main_iteration ();
+
+ gtk_main_quit ();