From 175e5926e0194a8211b846a4eec403a5bdb4afd4 Mon Sep 17 00:00:00 2001 From: "Dirk-Jan C. Binnema" Date: Wed, 31 Oct 2007 10:50:09 +0000 Subject: [PATCH] * this is dirk's version of sergio's patch to only create main-windows when we really need to. it adds a boolean 'create' parameter to modest_window_mgr_get_main_window, and only if this parameter is TRUE will this function create a main_window if it was not yet existing. also, patch makes warning dialogs not show up if there is no main window, including password, cert verification dialogs. thus, the user will not be annoyed unexpectedly anymore. pmo-trunk-r3606 --- src/dbus_api/modest-dbus-callbacks.c | 98 +++++++++++++++++++--------------- src/maemo/modest-main-window.c | 12 +++-- src/maemo/modest-msg-view-window.c | 44 +++++++-------- src/maemo/modest-platform.c | 32 ++++++++--- src/modest-main.c | 13 ++--- src/modest-tny-account-store.c | 37 ++++++++----- src/modest-ui-actions.c | 26 +++++---- src/widgets/modest-folder-view.c | 24 ++++++--- src/widgets/modest-header-view.c | 24 +++++---- src/widgets/modest-window-mgr.c | 16 +++++- src/widgets/modest-window-mgr.h | 22 ++++++-- 11 files changed, 221 insertions(+), 127 deletions(-) diff --git a/src/dbus_api/modest-dbus-callbacks.c b/src/dbus_api/modest-dbus-callbacks.c index 131c071..01b62a8 100644 --- a/src/dbus_api/modest-dbus-callbacks.c +++ b/src/dbus_api/modest-dbus-callbacks.c @@ -540,8 +540,7 @@ on_idle_delete_message (gpointer user_data) const char *uri = NULL, *uid = NULL; gint res = 0; ModestMailOperation *mail_op = NULL; - ModestWindow *win = NULL, *msg_view = NULL; - ModestWindowMgr *win_mgr = NULL; + ModestWindow *main_win = NULL, *msg_view = NULL; uri = (char *) user_data; @@ -549,17 +548,18 @@ on_idle_delete_message (gpointer user_data) msg = find_message_by_url (uri, &account); - if (msg == NULL) { - return OSSO_ERROR; + if (!msg) { + g_warning ("modest: %s: Could not find message '%s'", __FUNCTION__, uri); + return OSSO_ERROR; /* FIXME: is this TRUE or FALSE?! */ } - - g_debug ("modest: %s: Found message", __FUNCTION__); + + main_win = modest_window_mgr_get_main_window (modest_runtime_get_window_mgr(), + FALSE); /* don't create */ msg_header = tny_msg_get_header (msg); uid = tny_header_get_uid (msg_header); folder = tny_msg_get_folder (msg); - /* tny_msg_get_header () flaw: * From tinythingy doc: You can't use the returned instance with the * TnyFolder operations @@ -614,24 +614,23 @@ on_idle_delete_message (gpointer user_data) } res = OSSO_OK; - + /* This is a GDK lock because we are an idle callback and * the code below is or does Gtk+ code */ - gdk_threads_enter (); /* CHECKED */ - win_mgr = modest_runtime_get_window_mgr (); - win = modest_window_mgr_get_main_window (win_mgr); - mail_op = modest_mail_operation_new (win ? G_OBJECT(win) : NULL); + mail_op = modest_mail_operation_new (main_win ? G_OBJECT(main_win) : NULL); modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_op); modest_mail_operation_remove_msg (mail_op, header, FALSE); g_object_unref (G_OBJECT (mail_op)); - - if (modest_window_mgr_find_registered_header (win_mgr, header, &msg_view)) { - if (MODEST_IS_MSG_VIEW_WINDOW (msg_view)) - modest_ui_actions_refresh_message_window_after_delete (MODEST_MSG_VIEW_WINDOW (msg_view)); - } + if (main_win) { /* no need if there's no window */ + if (modest_window_mgr_find_registered_header (modest_runtime_get_window_mgr(), + header, &msg_view)) { + if (MODEST_IS_MSG_VIEW_WINDOW (msg_view)) + modest_ui_actions_refresh_message_window_after_delete (MODEST_MSG_VIEW_WINDOW (msg_view)); + } + } gdk_threads_leave (); /* CHECKED */ if (header) @@ -656,10 +655,18 @@ on_idle_delete_message (gpointer user_data) * (They are not really deleted until contact is made with the server, * so they would appear with a strike-through until then): */ - ModestHeaderView *header_view = MODEST_HEADER_VIEW(modest_main_window_get_child_widget ( - MODEST_MAIN_WINDOW(win), MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW)); - if (header_view && MODEST_IS_HEADER_VIEW (header_view)) - modest_header_view_refilter (header_view); + if (main_win) { /* only needed when there's a mainwindow / UI */ + + /* This is a GDK lock because we are an idle callback and + * the code below is or does Gtk+ code */ + gdk_threads_enter (); /* CHECKED */ + ModestHeaderView *header_view = MODEST_HEADER_VIEW(modest_main_window_get_child_widget ( + MODEST_MAIN_WINDOW(main_win), + MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW)); + if (header_view && MODEST_IS_HEADER_VIEW (header_view)) + modest_header_view_refilter (header_view); + gdk_threads_leave (); + } return res; } @@ -692,19 +699,17 @@ on_delete_message (GArray *arguments, gpointer data, osso_rpc_t *retval) static gboolean on_idle_send_receive(gpointer user_data) { - ModestWindow *win; + ModestWindow *main_win = + modest_window_mgr_get_main_window (modest_runtime_get_window_mgr (), + FALSE); /* don't create */ /* This is a GDK lock because we are an idle callback and * the code below is or does Gtk+ code */ - gdk_threads_enter (); /* CHECKED */ - /* Pick the main window if it exists */ - win = modest_window_mgr_get_main_window (modest_runtime_get_window_mgr ()); - /* Send & receive all if "Update automatically" is set */ /* TODO: check the auto-update parameter in the configuration */ - modest_ui_actions_do_send_receive_all (win); + modest_ui_actions_do_send_receive_all (main_win); gdk_threads_leave (); /* CHECKED */ @@ -731,19 +736,26 @@ static gboolean on_idle_top_application (gpointer user_data); static gboolean on_idle_open_default_inbox(gpointer user_data) { - if (!check_and_offer_account_creation ()) - return FALSE; + ModestWindow *main_win; + GtkWidget *folder_view; + if (!check_and_offer_account_creation ()) /* this has it's only lock already */ + return FALSE; + /* This is a GDK lock because we are an idle callback and * the code below is or does Gtk+ code */ - gdk_threads_enter (); /* CHECKED */ - - ModestWindow *win = - modest_window_mgr_get_main_window (modest_runtime_get_window_mgr ()); + main_win = modest_window_mgr_get_main_window (modest_runtime_get_window_mgr (), + TRUE); /* create if non-existent */ + if (!main_win) { + g_warning ("%s: BUG: no main window", __FUNCTION__); + gdk_threads_leave (); /* CHECKED */ + return FALSE; /* don't call me again */ + } + /* Get the folder view */ - GtkWidget *folder_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (win), + folder_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (main_win), MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW); modest_folder_view_select_first_inbox_or_local (MODEST_FOLDER_VIEW (folder_view)); @@ -772,20 +784,22 @@ static gint on_open_default_inbox(GArray * arguments, gpointer data, osso_rpc_t static gboolean on_idle_top_application (gpointer user_data) { - + ModestWindow *main_win; + /* This is a GDK lock because we are an idle callback and * the code below is or does Gtk+ code */ gdk_threads_enter (); /* CHECKED */ - - ModestWindow *win = - modest_window_mgr_get_main_window (modest_runtime_get_window_mgr ()); - if (win) { + + main_win = modest_window_mgr_get_main_window (modest_runtime_get_window_mgr (), + TRUE); /* create if non-existent */ + if (main_win) { /* Ideally, we would just use gtk_widget_show(), * but this widget is not coded correctly to support that: */ - gtk_widget_show_all (GTK_WIDGET (win)); - gtk_window_present (GTK_WINDOW (win)); - } + gtk_widget_show_all (GTK_WIDGET (main_win)); + gtk_window_present (GTK_WINDOW (main_win)); + } else + g_warning ("%s: BUG: no main window", __FUNCTION__); gdk_threads_leave (); /* CHECKED */ diff --git a/src/maemo/modest-main-window.c b/src/maemo/modest-main-window.c index 6de49fc..738b709 100644 --- a/src/maemo/modest-main-window.c +++ b/src/maemo/modest-main-window.c @@ -2285,9 +2285,15 @@ static void refresh_account (const gchar *account_name) { ModestWindow *win; - - win = MODEST_WINDOW (modest_window_mgr_get_main_window (modest_runtime_get_window_mgr ())); - + + /* win must already exists here, obviously */ + win = modest_window_mgr_get_main_window (modest_runtime_get_window_mgr (), + FALSE); + if (!win) { + g_warning ("%s: BUG: no main window!", __FUNCTION__); + return; + } + /* If account_name == NULL, we must update all (option All) */ if (!account_name) modest_ui_actions_do_send_receive_all (win); diff --git a/src/maemo/modest-msg-view-window.c b/src/maemo/modest-msg-view-window.c index d766758..85f1e2a 100644 --- a/src/maemo/modest-msg-view-window.c +++ b/src/maemo/modest-msg-view-window.c @@ -542,9 +542,8 @@ modest_msg_view_window_disconnect_signals (ModestWindow *self) { ModestMsgViewWindowPrivate *priv; ModestHeaderView *header_view = NULL; - ModestMainWindow *main_window = NULL; - ModestWindowMgr *window_mgr = NULL; - + ModestWindow *main_window = NULL; + priv = MODEST_MSG_VIEW_WINDOW_GET_PRIVATE (self); if (gtk_clipboard_get (GDK_SELECTION_PRIMARY) && @@ -585,19 +584,15 @@ modest_msg_view_window_disconnect_signals (ModestWindow *self) priv->rows_reordered_handler); } - window_mgr = modest_runtime_get_window_mgr(); - g_assert(window_mgr != NULL); - - main_window = MODEST_MAIN_WINDOW( - modest_window_mgr_get_main_window(window_mgr)); - - if(main_window == NULL) + main_window = modest_window_mgr_get_main_window (modest_runtime_get_window_mgr(), + FALSE); /* don't create */ + if (!main_window) return; - + header_view = MODEST_HEADER_VIEW( modest_main_window_get_child_widget( - main_window, MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW)); - + MODEST_MAIN_WINDOW(main_window), + MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW)); if (header_view == NULL) return; @@ -844,6 +839,7 @@ modest_msg_view_window_construct (ModestMsgViewWindow *self, } +/* FIXME: parameter checks */ ModestWindow * modest_msg_view_window_new_with_header_model (TnyMsg *msg, const gchar *modest_account_name, @@ -855,24 +851,28 @@ modest_msg_view_window_new_with_header_model (TnyMsg *msg, ModestMsgViewWindowPrivate *priv = NULL; TnyFolder *header_folder = NULL; ModestHeaderView *header_view = NULL; - ModestMainWindow *main_window = NULL; - ModestWindowMgr *window_mgr = NULL; - + ModestWindow *main_window = NULL; + window = g_object_new(MODEST_TYPE_MSG_VIEW_WINDOW, NULL); g_return_val_if_fail (MODEST_IS_MSG_VIEW_WINDOW (window), NULL); + modest_msg_view_window_construct (window, modest_account_name, msg_uid); priv = MODEST_MSG_VIEW_WINDOW_GET_PRIVATE (window); /* Remember the message list's TreeModel so we can detect changes * and change the list selection when necessary: */ - window_mgr = modest_runtime_get_window_mgr(); - g_assert(window_mgr != NULL); - main_window = MODEST_MAIN_WINDOW( - modest_window_mgr_get_main_window(window_mgr)); - g_assert(main_window != NULL); + + main_window = modest_window_mgr_get_main_window( + modest_runtime_get_window_mgr(), FALSE); /* don't create */ + if (!main_window) { + g_warning ("%s: BUG: no main window", __FUNCTION__); + return NULL; + } + header_view = MODEST_HEADER_VIEW(modest_main_window_get_child_widget( - main_window, MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW)); + MODEST_MAIN_WINDOW(main_window), + MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW)); if (header_view != NULL){ header_folder = modest_header_view_get_folder(header_view); g_assert(header_folder != NULL); diff --git a/src/maemo/modest-platform.c b/src/maemo/modest-platform.c index 614aa13..eac54a7 100644 --- a/src/maemo/modest-platform.c +++ b/src/maemo/modest-platform.c @@ -1637,14 +1637,24 @@ modest_platform_run_certificate_confirmation_dialog (const gchar* server_name, { GtkWidget *note; gint response; - GtkWindow *main_win = - (GtkWindow*)modest_window_mgr_get_main_window (modest_runtime_get_window_mgr()); + ModestWindow *main_win; + + if (!modest_window_mgr_main_window_exists (modest_runtime_get_window_mgr())) { + g_warning ("%s: don't show dialogs if there's no main window; assuming 'Cancel'", + __FUNCTION__); + return FALSE; + } + /* don't create it */ + main_win = modest_window_mgr_get_main_window (modest_runtime_get_window_mgr(), FALSE); + g_return_val_if_fail (main_win, FALSE); /* should not happen */ + + gchar *question = g_strdup_printf (_("mcen_nc_unknown_certificate"), server_name); note = hildon_note_new_confirmation_add_buttons ( - main_win, + GTK_WINDOW(main_win), question, _("mcen_bd_dialog_ok"), GTK_RESPONSE_OK, _("mcen_bd_view"), GTK_RESPONSE_HELP, /* abusing this... */ @@ -1671,8 +1681,16 @@ gboolean modest_platform_run_alert_dialog (const gchar* prompt, gboolean is_question) { - ModestWindow *main_window = - modest_window_mgr_get_main_window (modest_runtime_get_window_mgr ()); + ModestWindow *main_win; + + if (!modest_window_mgr_main_window_exists (modest_runtime_get_window_mgr())) { + g_warning ("%s:\n'%s'\ndon't show dialogs if there's no main window;" + " assuming 'Cancel' for questions, 'Ok' otherwise", prompt, __FUNCTION__); + return is_question ? FALSE : TRUE; + } + + main_win = modest_window_mgr_get_main_window (modest_runtime_get_window_mgr (), FALSE); + g_return_val_if_fail (main_win, FALSE); /* should not happen */ gboolean retval = TRUE; if (is_question) { @@ -1680,7 +1698,7 @@ modest_platform_run_alert_dialog (const gchar* prompt, * when it is a question. * Obviously, we need tinymail to use more specific error codes instead, * so we know what buttons to show. */ - GtkWidget *dialog = GTK_WIDGET (hildon_note_new_confirmation (GTK_WINDOW (main_window), + GtkWidget *dialog = GTK_WIDGET (hildon_note_new_confirmation (GTK_WINDOW (main_win), prompt)); modest_window_mgr_set_modal (modest_runtime_get_window_mgr (), GTK_WINDOW (dialog)); @@ -1691,7 +1709,7 @@ modest_platform_run_alert_dialog (const gchar* prompt, on_destroy_dialog (GTK_DIALOG(dialog)); } else { /* Just show the error text and use the default response: */ - modest_platform_run_information_dialog (GTK_WINDOW (main_window), + modest_platform_run_information_dialog (GTK_WINDOW (main_win), prompt); } return retval; diff --git a/src/modest-main.c b/src/modest-main.c index 4ca4f15..14e2c8d 100644 --- a/src/modest-main.c +++ b/src/modest-main.c @@ -45,13 +45,14 @@ main (int argc, char *argv[]) * be called. But that's annoying when starting from the * command line.: */ gboolean show_ui_without_top_application_method = FALSE; + + ModestWindow *main_win; + int retval = 0; + if (argc >= 2) { if (strcmp (argv[1], "showui") == 0) show_ui_without_top_application_method = TRUE; } - - ModestWindow *win; - int retval = 0; if (!g_thread_supported()) g_thread_init (NULL); @@ -72,8 +73,8 @@ main (int argc, char *argv[]) } /* this will create & register the window */ - win = modest_window_mgr_get_main_window (modest_runtime_get_window_mgr()); - if (!win) { + main_win = modest_window_mgr_get_main_window (modest_runtime_get_window_mgr(), TRUE); + if (!main_win) { g_printerr ("modest: failed to get main window instance\n"); retval = 1; goto cleanup; @@ -86,7 +87,7 @@ main (int argc, char *argv[]) * when we receive the "top_application" D-Bus method. */ if (show_ui_without_top_application_method) { - gtk_widget_show_all (GTK_WIDGET(win)); + gtk_widget_show_all (GTK_WIDGET(main_win)); /* Remove new mail notifications if exist */ modest_platform_remove_new_mail_notifications (); diff --git a/src/modest-tny-account-store.c b/src/modest-tny-account-store.c index a1c1f3d..ac7dd11 100644 --- a/src/modest-tny-account-store.c +++ b/src/modest-tny-account-store.c @@ -499,22 +499,34 @@ static void show_password_warning_only () { ModestWindow *main_window = - modest_window_mgr_get_main_window (modest_runtime_get_window_mgr ()); - + modest_window_mgr_get_main_window (modest_runtime_get_window_mgr (), FALSE); /* don't create */ + /* Show an explanatory temporary banner: */ - hildon_banner_show_information ( - GTK_WIDGET(main_window), NULL, _("mcen_ib_username_pw_incorrect")); + if (main_window) + hildon_banner_show_information ( + GTK_WIDGET(main_window), NULL, _("mcen_ib_username_pw_incorrect")); + else + g_warning ("%s: %s", __FUNCTION__, _("mcen_ib_username_pw_incorrect")); } - + + static void show_wrong_password_dialog (TnyAccount *account) { /* This is easier than using a struct for the user_data: */ ModestTnyAccountStore *self = modest_runtime_get_account_store(); ModestTnyAccountStorePrivate *priv = MODEST_TNY_ACCOUNT_STORE_GET_PRIVATE(self); - - const gchar *modest_account_name = - modest_tny_account_get_parent_modest_account_name_for_server_account (account); + ModestWindow *main_window; + const gchar *modest_account_name; + + main_window = modest_window_mgr_get_main_window (modest_runtime_get_window_mgr (), + FALSE); /* don't create */ + if (!main_window) { + g_warning ("%s: password was wrong; ignoring because no main window", __FUNCTION__); + return; + } + + modest_account_name = modest_tny_account_get_parent_modest_account_name_for_server_account (account); if (!modest_account_name) { g_warning ("%s: modest_tny_account_get_parent_modest_account_name_for_server_account() failed.\n", __FUNCTION__); @@ -531,9 +543,6 @@ show_wrong_password_dialog (TnyAccount *account) } ModestAccountSettingsDialog *dialog = dialog_as_gpointer; - ModestWindow *main_window = - modest_window_mgr_get_main_window (modest_runtime_get_window_mgr ()); - gboolean created_dialog = FALSE; if (!found || !dialog) { dialog = modest_account_settings_dialog_new (); @@ -574,9 +583,9 @@ request_password_and_wait (ModestTnyAccountStore *account_store, gboolean *cancel, gboolean *remember) { - g_signal_emit (G_OBJECT(account_store), signals[PASSWORD_REQUESTED_SIGNAL], 0, - server_account_id, /* server_account_name */ - username, password, cancel, remember); + g_signal_emit (G_OBJECT(account_store), signals[PASSWORD_REQUESTED_SIGNAL], 0, + server_account_id, /* server_account_name */ + username, password, cancel, remember); } /* This callback will be called by Tinymail when it needs the password diff --git a/src/modest-ui-actions.c b/src/modest-ui-actions.c index 62c9403..40e4c12 100644 --- a/src/modest-ui-actions.c +++ b/src/modest-ui-actions.c @@ -224,11 +224,12 @@ modest_ui_actions_run_account_setup_wizard (ModestWindow *win) modest_window_mgr_set_modal (modest_runtime_get_window_mgr(), wizard); /* always present a main window in the background - * we do it here, so we cannot end up with to wizards (as this + * we do it here, so we cannot end up with two wizards (as this * function might be called in modest_window_mgr_get_main_window as well */ if (!win) - win = modest_window_mgr_get_main_window (modest_runtime_get_window_mgr()); - + win = modest_window_mgr_get_main_window (modest_runtime_get_window_mgr(), + TRUE); /* create if not existent */ + /* make sure the mainwindow is visible */ gtk_widget_show_all (GTK_WIDGET(win)); gtk_window_present (GTK_WINDOW(win)); @@ -403,6 +404,7 @@ modest_ui_actions_refresh_message_window_after_delete (ModestMsgViewWindow* win) } } + void modest_ui_actions_on_delete_message (GtkAction *action, ModestWindow *win) { @@ -529,9 +531,8 @@ modest_ui_actions_on_delete_message (GtkAction *action, ModestWindow *win) /* Get main window */ mgr = modest_runtime_get_window_mgr (); - main_window = modest_window_mgr_get_main_window (mgr); - } - else { + main_window = modest_window_mgr_get_main_window (mgr, FALSE); /* don't create */ + } else { /* Move cursor to next row */ main_window = win; @@ -4055,7 +4056,11 @@ modest_ui_actions_move_folder_error_handler (ModestMailOperation *mail_op, } /* Disable next automatic folder selection */ - main_window = modest_window_mgr_get_main_window (modest_runtime_get_window_mgr ()); + main_window = modest_window_mgr_get_main_window (modest_runtime_get_window_mgr (), + FALSE); /* don't create */ + if (!main_window) + g_warning ("%s: BUG: no main window", __FUNCTION__); + folder_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (main_window), MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW); modest_folder_view_disable_next_folder_selection (MODEST_FOLDER_VIEW(folder_view)); @@ -4446,7 +4451,8 @@ modest_ui_actions_on_move_to (GtkAction *action, main_window = MODEST_MAIN_WINDOW (win); else main_window = - MODEST_MAIN_WINDOW (modest_window_mgr_get_main_window (modest_runtime_get_window_mgr ())); + MODEST_MAIN_WINDOW (modest_window_mgr_get_main_window (modest_runtime_get_window_mgr (), + FALSE)); /* don't create */ /* Get the folder view widget if exists */ if (main_window) @@ -4859,8 +4865,8 @@ modest_ui_actions_on_send_queue_status_changed (ModestTnySendQueue *send_queue, TnyFolderType folder_type; mgr = modest_runtime_get_window_mgr (); - main_window = MODEST_MAIN_WINDOW (modest_window_mgr_get_main_window (mgr)); - + main_window = MODEST_MAIN_WINDOW (modest_window_mgr_get_main_window (mgr, + FALSE));/* don't create */ if (!main_window) return; diff --git a/src/widgets/modest-folder-view.c b/src/widgets/modest-folder-view.c index b2e6695..9c7af11 100644 --- a/src/widgets/modest-folder-view.c +++ b/src/widgets/modest-folder-view.c @@ -1670,7 +1670,12 @@ drag_and_drop_from_header_view (GtkTreeModel *source_model, goto cleanup; /* verboten! */ /* Ask for confirmation to move */ - main_win = modest_window_mgr_get_main_window (mgr); + main_win = modest_window_mgr_get_main_window (mgr, FALSE); /* don't create */ + if (!main_win) { + g_warning ("%s: BUG: no main window found", __FUNCTION__); + goto cleanup; + } + response = modest_ui_actions_msgs_move_to_confirmation (main_win, folder, TRUE, headers); if (response == GTK_RESPONSE_CANCEL) @@ -1717,7 +1722,14 @@ drag_and_drop_from_folder_view (GtkTreeModel *source_model, TnyFolderStore *dest_folder = NULL; TnyFolderStore *folder = NULL; gboolean forbidden = FALSE; + ModestWindow *win; + win = modest_window_mgr_get_main_window (modest_runtime_get_window_mgr(), FALSE); /* don't create */ + if (!win) { + g_warning ("%s: BUG: no main window", __FUNCTION__); + return; + } + if (!forbidden) { /* check the folder rules for the destination */ folder = tree_path_to_folder (dest_model, dest_row); @@ -1767,13 +1779,11 @@ drag_and_drop_from_folder_view (GtkTreeModel *source_model, /* Offer the connection dialog if necessary, for the destination parent folder and source folder: */ if (modest_platform_connect_and_wait_if_network_folderstore (NULL, dest_folder) && modest_platform_connect_and_wait_if_network_folderstore (NULL, TNY_FOLDER_STORE (folder))) { - ModestWindowMgr *mgr = modest_runtime_get_window_mgr (); - + /* Do the mail operation */ - mail_op = - modest_mail_operation_new_with_error_handling ((GObject *) modest_window_mgr_get_main_window (mgr), - modest_ui_actions_move_folder_error_handler, - folder, NULL); + mail_op = modest_mail_operation_new_with_error_handling ((GObject *) win, + modest_ui_actions_move_folder_error_handler, + folder, NULL); modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_op); diff --git a/src/widgets/modest-header-view.c b/src/widgets/modest-header-view.c index 972a7dd..9e3b663 100644 --- a/src/widgets/modest-header-view.c +++ b/src/widgets/modest-header-view.c @@ -1159,12 +1159,20 @@ modest_header_view_set_folder (ModestHeaderView *self, gpointer user_data) { ModestHeaderViewPrivate *priv; - ModestWindowMgr *mgr = NULL; - GObject *source = NULL; SetFolderHelper *info; - - priv = MODEST_HEADER_VIEW_GET_PRIVATE(self); + ModestWindow *main_win; + + g_return_if_fail (self); + priv = MODEST_HEADER_VIEW_GET_PRIVATE(self); + + main_win = modest_window_mgr_get_main_window (modest_runtime_get_window_mgr (), + FALSE); /* don't create */ + if (!main_win) { + g_warning ("%s: BUG: no main window", __FUNCTION__); + return; + } + if (priv->folder) { g_mutex_lock (priv->observers_lock); tny_folder_remove_observer (priv->folder, TNY_FOLDER_OBSERVER (self)); @@ -1177,13 +1185,9 @@ modest_header_view_set_folder (ModestHeaderView *self, ModestMailOperation *mail_op = NULL; GtkTreeSelection *selection; - /* Get main window to use it as source of mail operation */ - mgr = modest_runtime_get_window_mgr (); - source = G_OBJECT (modest_window_mgr_get_main_window (modest_runtime_get_window_mgr ())); - /* Set folder in the model */ modest_header_view_set_folder_intern (self, folder); - + /* Pick my reference. Nothing to do with the mail operation */ priv->folder = g_object_ref (folder); @@ -1203,7 +1207,7 @@ modest_header_view_set_folder (ModestHeaderView *self, info->user_data = user_data; /* Create the mail operation (source will be the parent widget) */ - mail_op = modest_mail_operation_new (source); + mail_op = modest_mail_operation_new (G_OBJECT(main_win)); modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_op); diff --git a/src/widgets/modest-window-mgr.c b/src/widgets/modest-window-mgr.c index fa2db44..0451e9f 100644 --- a/src/widgets/modest-window-mgr.c +++ b/src/widgets/modest-window-mgr.c @@ -815,7 +815,7 @@ modest_window_mgr_show_toolbars (ModestWindowMgr *self, } ModestWindow* -modest_window_mgr_get_main_window (ModestWindowMgr *self) +modest_window_mgr_get_main_window (ModestWindowMgr *self, gboolean create) { ModestWindowMgrPrivate *priv; @@ -823,7 +823,7 @@ modest_window_mgr_get_main_window (ModestWindowMgr *self) priv = MODEST_WINDOW_MGR_GET_PRIVATE (self); /* create the main window, if it hasn't been created yet */ - if (!priv->main_window) { + if (!priv->main_window && create) { /* modest_window_mgr_register_window will set priv->main_window */ modest_window_mgr_register_window (self, modest_main_window_new ()); g_debug ("%s: created main window: %p\n", __FUNCTION__, priv->main_window); @@ -833,6 +833,18 @@ modest_window_mgr_get_main_window (ModestWindowMgr *self) } +gboolean +modest_window_mgr_main_window_exists (ModestWindowMgr *self) +{ + ModestWindowMgrPrivate *priv; + + g_return_val_if_fail (MODEST_IS_WINDOW_MGR (self), FALSE); + priv = MODEST_WINDOW_MGR_GET_PRIVATE (self); + + return priv->main_window != NULL; +} + + GtkWindow * modest_window_mgr_get_modal (ModestWindowMgr *self) { diff --git a/src/widgets/modest-window-mgr.h b/src/widgets/modest-window-mgr.h index 1e65c49..642648c 100644 --- a/src/widgets/modest-window-mgr.h +++ b/src/widgets/modest-window-mgr.h @@ -128,13 +128,27 @@ void modest_window_mgr_show_toolbars (ModestWindowMgr *self, /** * modest_window_mgr_get_main_window: * @self: a #ModestWindowMgr + * @create: if TRUE, create the main window if it was not yet existing * - * get the main window, or create if it's not there. don't destroy - * it. + * get the main window, and depending on @create, create one if it does not exist yet * - * Returns: the main window or NULL in case of error + * Returns: the main window or NULL in case of error, or the main-window + * did not yet exist **/ -ModestWindow* modest_window_mgr_get_main_window (ModestWindowMgr *self); +ModestWindow* modest_window_mgr_get_main_window (ModestWindowMgr *self, + gboolean create); + + +/** + * modest_window_mgr_main_window_exists: + * @self: a #ModestWindowMgr + * + * do we have a main window? + * + * Returns: TRUE if there's a main window, FALSE otherwise + **/ +gboolean modest_window_mgr_main_window_exists (ModestWindowMgr *self); + /** -- 1.7.9.5