+ /* Do not allow standalone editors or standalone viewers */
+ if (!current_top &&
+ (MODEST_IS_MSG_VIEW_WINDOW (window) ||
+ MODEST_IS_MSG_EDIT_WINDOW (window)))
+ modest_window_mgr_show_initial_window (self);
+
+ if (MODEST_IS_MSG_VIEW_WINDOW (window)) {
+ gchar *uid;
+ TnyHeader *header;
+
+ uid = g_strdup (modest_msg_view_window_get_message_uid (MODEST_MSG_VIEW_WINDOW (window)));
+
+ header = modest_msg_view_window_get_header (MODEST_MSG_VIEW_WINDOW (window));
+
+ if (uid == NULL)
+ uid = modest_tny_folder_get_header_unique_id (header);
+ /* Embedded messages do not have uid */
+ if (uid) {
+ if (g_list_find_custom (priv->window_list, uid, (GCompareFunc) compare_msguids)) {
+ g_debug ("%s found another view window showing the same header", __FUNCTION__);
+ g_free (uid);
+ g_object_unref (header);
+ return FALSE;
+ }
+ g_free (uid);
+ } else if (header) {
+ if (g_list_find_custom (priv->window_list, header, (GCompareFunc) compare_headers)) {
+ g_debug ("%s found another view window showing the same header", __FUNCTION__);
+ g_object_unref (header);
+ return FALSE;
+ }
+ }
+ if (header)
+ g_object_unref (header);
+ }
+
+ /* Rules
+ * * toplevel = msg edit -> if not modified, close, if modified, stay
+ * * same account -> no action
+ * * window = accounts -> no action
+ * * window = folders, mailboxes, headers: close all up to accounts window
+ */
+
+ if (MODEST_IS_MSG_EDIT_WINDOW (current_top) &&
+ !modest_msg_edit_window_is_modified (MODEST_MSG_EDIT_WINDOW (current_top))) {
+ gboolean retval;
+
+ g_signal_emit_by_name (G_OBJECT (current_top), "delete-event", NULL, &retval);
+ current_top = (ModestWindow *) hildon_window_stack_peek (stack);
+ }
+
+ if (MODEST_IS_MSG_EDIT_WINDOW (current_top) ||
+ (current_top && MODEST_IS_ACCOUNTS_WINDOW (window))) {
+ gtk_window_present (GTK_WINDOW (current_top));
+ return FALSE;
+ }
+
+ acc_name = modest_window_get_active_account (window);
+
+ if (MODEST_IS_MSG_VIEW_WINDOW (current_top) ||
+ MODEST_IS_HEADER_WINDOW (current_top) ||
+ MODEST_IS_FOLDER_WINDOW (current_top) ||
+ MODEST_IS_MAILBOXES_WINDOW (current_top)) {
+ toplevel_acc_name = modest_window_get_active_account (current_top);
+
+ if (acc_name != NULL && g_strcmp0 (toplevel_acc_name, acc_name) == 0) {
+ /* Same account, no action */
+
+ if (window_precedence (GTK_WINDOW (current_top)) >= window_precedence (GTK_WINDOW (window))) {
+ if (!(MODEST_IS_MSG_VIEW_WINDOW (current_top) && MODEST_IS_MSG_VIEW_WINDOW (window))) {
+ gtk_window_present (GTK_WINDOW (current_top));
+ return FALSE;
+ }
+ }
+ } else {
+ while (current_top && !MODEST_IS_ACCOUNTS_WINDOW (current_top)) {
+ gboolean retval;
+ g_signal_emit_by_name (G_OBJECT (current_top), "delete-event", NULL, &retval);
+
+ if (retval) {
+ gtk_window_present (GTK_WINDOW (current_top));
+ return FALSE;
+ }
+ current_top = (ModestWindow *) hildon_window_stack_peek (stack);
+ }
+ }
+ }
+
+ /* Trying to open a folders window and a mailboxes window at
+ the same time from the accounts window is not allowed */
+ if (MODEST_IS_MAILBOXES_WINDOW (current_top) &&
+ MODEST_IS_FOLDER_WINDOW (window) &&
+ MODEST_IS_ACCOUNTS_WINDOW (parent)) {
+ gtk_window_present (GTK_WINDOW (window));
+ return FALSE;
+ }
+
+ if (MODEST_IS_HEADER_WINDOW (current_top) && MODEST_IS_HEADER_WINDOW (window)) {
+ g_debug ("Trying to register a second header window is not allowed");
+ gtk_window_present (GTK_WINDOW (current_top));
+ return FALSE;
+ }