* automatically register the main window
authorDirk-Jan C. Binnema <dirk-jan.binnema@nokia.com>
Fri, 24 Aug 2007 07:29:46 +0000 (07:29 +0000)
committerDirk-Jan C. Binnema <dirk-jan.binnema@nokia.com>
Fri, 24 Aug 2007 07:29:46 +0000 (07:29 +0000)
* make sure only one ModestEasySetupWizardDialog instance can be alive at any time,
  letting modest-easysetup-wizard.c keep track of that
* if the we're asked for a new instance, present the old one instead

Fixes: NB#66408, and all other cases where this could happen.

pmo-trunk-r3061

src/dbus_api/modest-dbus-callbacks.c
src/maemo/easysetup/modest-easysetup-wizard.c
src/maemo/easysetup/modest-easysetup-wizard.h
src/maemo/modest-account-view-window.c
src/modest-main.c
src/modest-ui-actions.c

index cfd92a8..9b3837a 100644 (file)
@@ -196,7 +196,8 @@ check_and_offer_account_creation()
                const gboolean created = modest_run_account_setup_wizard (NULL);
                printf ("DEBUG1: %s\n", __FUNCTION__);
                if (!created) {
-                       g_debug ("modest: %s: No account exists even after offering.\n", __FUNCTION__);
+                       g_debug ("modest: %s: no account exists even after offering, "
+                                "or account setup was already underway.\n", __FUNCTION__);
                        result = FALSE;
                }
        }
index c00ffe3..62c15e9 100644 (file)
@@ -70,6 +70,11 @@ G_DEFINE_TYPE (ModestEasysetupWizardDialog, modest_easysetup_wizard_dialog, MODE
 
 typedef struct _ModestEasysetupWizardDialogPrivate ModestEasysetupWizardDialogPrivate;
 
+/* global to make sure there is only one of this
+ * dialog at any time
+ */
+static ModestEasysetupWizardDialog *_instance = NULL;
+
 typedef enum {
        MODEST_EASYSETUP_WIZARD_DIALOG_INCOMING_CHANGED = 0x01,
        MODEST_EASYSETUP_WIZARD_DIALOG_OUTGOING_CHANGED = 0x02
@@ -140,6 +145,8 @@ modest_easysetup_wizard_dialog_finalize (GObject *object)
        g_free (self->saved_account_name);
        
        G_OBJECT_CLASS (modest_easysetup_wizard_dialog_parent_class)->finalize (object);
+
+       _instance = NULL;
 }
 
 static void
@@ -1152,9 +1159,16 @@ modest_easysetup_wizard_dialog_init (ModestEasysetupWizardDialog *self)
 }
 
 ModestEasysetupWizardDialog*
-modest_easysetup_wizard_dialog_new (void)
-{
-       return g_object_new (MODEST_TYPE_EASYSETUP_WIZARD_DIALOG, NULL);
+modest_easysetup_wizard_dialog_new_or_present (void)
+{      
+       if (_instance) {
+               g_message ("%s: already instantiated; presenting\n",
+                          __FUNCTION__);
+               gtk_window_present (GTK_WINDOW(_instance));
+               return NULL;
+       }
+       
+       return _instance = g_object_new (MODEST_TYPE_EASYSETUP_WIZARD_DIALOG, NULL);
 }
 
 static void create_subsequent_customsetup_pages (ModestEasysetupWizardDialog *self)
index 6814280..a417223 100644 (file)
@@ -125,7 +125,12 @@ typedef struct {
 
 GType modest_easysetup_wizard_dialog_get_type (void);
 
-ModestEasysetupWizardDialog* modest_easysetup_wizard_dialog_new (void);
+/*
+ * NOTE: can be instantiated only once; after that, this function will
+ * return NULL, until the one before is destroyed; if it returns NULL
+ * it will gtk_window_present the existing one.
+ */
+ModestEasysetupWizardDialog* modest_easysetup_wizard_dialog_new_or_present (void);
 
 G_END_DECLS
 
index 3c2dc72..e36899a 100644 (file)
@@ -262,8 +262,8 @@ on_edit_button_clicked (GtkWidget *button, ModestAccountViewWindow *self)
                
                /* Show the Account Settings window: */
                ModestAccountSettingsDialog *dialog = modest_account_settings_dialog_new ();
+
                modest_account_settings_dialog_set_account_name (dialog, account_name);
-               
                modest_maemo_show_dialog_and_forget (GTK_WINDOW (self), GTK_DIALOG (dialog));
        }
        
@@ -299,13 +299,15 @@ on_new_button_clicked (GtkWidget *button, ModestAccountViewWindow *self)
                gtk_window_present (GTK_WINDOW (priv->wizard));
        } else {
                /* Create and show the dialog: */
-               priv->wizard = modest_easysetup_wizard_dialog_new ();
-               
-               gtk_window_set_transient_for (GTK_WINDOW (priv->wizard), GTK_WINDOW (self));
-               
-               /* Destroy the dialog when it is closed: */
-               g_signal_connect (G_OBJECT (priv->wizard), "response", G_CALLBACK (on_wizard_response), self);
-               gtk_widget_show (GTK_WIDGET (priv->wizard));
+               priv->wizard = modest_easysetup_wizard_dialog_new_or_present ();
+               if (priv->wizard) {
+                       gtk_window_set_transient_for (GTK_WINDOW (priv->wizard), GTK_WINDOW (self));
+                       /* Destroy the dialog when it is closed: */
+                       g_signal_connect (G_OBJECT (priv->wizard), "response", G_CALLBACK (on_wizard_response), self);
+                       gtk_widget_show (GTK_WIDGET (priv->wizard));
+               } else
+                       /* in this case, the existing one will be topped */
+                       g_message ("%s: easysetup dialog already exists; ignoring", __FUNCTION__);
        }
 }
 
index c943088..52ad08b 100644 (file)
@@ -71,10 +71,10 @@ main (int argc, char *argv[])
                goto cleanup;
        }
 
-       win = modest_main_window_new ();
-                       
+       /* this will create & register the window */
+       win = modest_window_mgr_get_main_window (modest_runtime_get_window_mgr());
        if (!win) {
-               g_printerr ("modest: failed to create main window\n");
+               g_printerr ("modest: failed to get main window instance\n");
                retval = 1;
                goto cleanup;
        }
@@ -88,9 +88,6 @@ main (int argc, char *argv[])
        if (show_ui_without_top_application_method)
                gtk_widget_show_all (GTK_WIDGET(win));
        
-       modest_window_mgr_register_window (modest_runtime_get_window_mgr(), 
-                                          win);
-       g_object_unref (win);
        
        gtk_main ();    
        retval = 0;
index 840ad29..fda048a 100644 (file)
@@ -164,9 +164,17 @@ modest_run_account_setup_wizard (ModestWindow *win)
                
        g_return_val_if_fail (MODEST_IS_WINDOW(win), FALSE);
        
-       wizard = modest_easysetup_wizard_dialog_new ();
+       wizard = modest_easysetup_wizard_dialog_new_or_present ();
+
+       /* if wizard == NULL it means there is already a easy setup thingy running;
+        * in that case, don't do anything here; the call above will present it instead */
+       if (!wizard) {
+               g_message ("%s: easysetup wizard already running", __FUNCTION__);
+               return FALSE;
+       }
+
        gtk_window_set_transient_for (GTK_WINDOW (wizard), GTK_WINDOW (win));
-       
+
        /* Don't make this a modal window, because secondary windows will then 
         * be unusable, freezing the UI: */
        /* gtk_window_set_modal (GTK_WINDOW (wizard), TRUE); */