2007-04-29 Murray Cumming <murrayc@murrayc.com>
[modest] / src / maemo / easysetup / modest-easysetup-wizard.c
index f7e6d62..716d794 100644 (file)
@@ -15,7 +15,6 @@
 #include <gtk/gtkcheckbutton.h>
 #include <gtk/gtkmessagedialog.h>
 #include <gtk/gtkseparator.h>
-#include <hildon-widgets/hildon-caption.h>
 #include "maemo/easysetup/modest-easysetup-country-combo-box.h"
 #include "maemo/easysetup/modest-easysetup-provider-combo-box.h"
 #include "maemo/easysetup/modest-easysetup-servertype-combo-box.h"
@@ -28,6 +27,7 @@
 #include "modest-runtime.h" /* For modest_runtime_get_account_mgr(). */
 #include "maemo/modest-connection-specific-smtp-window.h"
 #include "maemo/modest-maemo-ui-constants.h"
+#include "maemo/modest-account-settings-dialog.h"
 #include <gconf/gconf-client.h>
 #include <string.h> /* For strlen(). */
 
@@ -91,6 +91,8 @@ modest_easysetup_wizard_dialog_finalize (GObject *object)
                
        if (self->specific_window)
                gtk_widget_destroy (self->specific_window);
+               
+       g_free (self->saved_account_name);
        
        G_OBJECT_CLASS (modest_easysetup_wizard_dialog_parent_class)->finalize (object);
 }
@@ -190,7 +192,7 @@ static GtkWidget* create_caption_new_with_asterix(ModestEasysetupWizardDialog *s
 static GtkWidget*
 create_page_welcome (ModestEasysetupWizardDialog *self)
 {
-       GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_HALF);
+       GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
        GtkWidget *label = gtk_label_new(_("mcen_ia_emailsetup_intro"));
        gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
        gtk_widget_show (label);
@@ -248,7 +250,7 @@ on_entry_max (ModestValidatingEntry *self, gpointer user_data)
 static GtkWidget*
 create_page_account_details (ModestEasysetupWizardDialog *self)
 {
-       GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_HALF);
+       GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
        GtkWidget *label = gtk_label_new(_("mcen_ia_accountdetails"));
        gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, MODEST_MARGIN_HALF);
        gtk_widget_show (label);
@@ -381,7 +383,7 @@ create_page_account_details (ModestEasysetupWizardDialog *self)
 static GtkWidget*
 create_page_user_details (ModestEasysetupWizardDialog *self)
 {
-       GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_HALF);
+       GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
        
        /* Create a size group to be used by all captions.
         * Note that HildonCaption does not create a default size group if we do not specify one.
@@ -470,7 +472,7 @@ create_page_user_details (ModestEasysetupWizardDialog *self)
 
 static GtkWidget* create_page_complete_easysetup (ModestEasysetupWizardDialog *self)
 {
-       GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_HALF);
+       GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
        GtkWidget *label = gtk_label_new(_("mcen_ia_emailsetup_setup_complete"));
        gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
        gtk_widget_show (label);
@@ -522,7 +524,7 @@ static void on_combo_servertype_changed(GtkComboBox *combobox, gpointer user_dat
            
 static GtkWidget* create_page_custom_incoming (ModestEasysetupWizardDialog *self)
 {
-       GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_HALF);
+       GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
        
        /* Create a size group to be used by all captions.
         * Note that HildonCaption does not create a default size group if we do not specify one.
@@ -631,7 +633,7 @@ on_button_outgoing_smtp_servers (GtkButton *button, gpointer user_data)
 
 static GtkWidget* create_page_custom_outgoing (ModestEasysetupWizardDialog *self)
 {
-       GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_HALF);
+       GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
        
        /* Create a size group to be used by all captions.
         * Note that HildonCaption does not create a default size group if we do not specify one.
@@ -711,9 +713,36 @@ static GtkWidget* create_page_custom_outgoing (ModestEasysetupWizardDialog *self
        return GTK_WIDGET (box);
 }
 
+
+static void
+on_button_edit_advanced_settings (GtkButton *button, gpointer user_data)
+{
+       ModestEasysetupWizardDialog * self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
+       
+       /* Save the new account, so we can edit it with ModestAccountSettingsDialog, 
+        * without recoding it to use non-gconf information.
+        * This account will be deleted if Finish is never actually clicked. */
+
+       const gboolean saved = create_account (self);
+       if (!saved)
+               return;
+               
+       if (!(self->saved_account_name))
+               return;
+       
+       /* Show the Account Settings window: */
+       ModestAccountSettingsDialog *dialog = modest_account_settings_dialog_new ();
+       modest_account_settings_dialog_set_account_name (dialog, self->saved_account_name);
+       
+       gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (self));
+       printf ("debug: before run\n");
+       gtk_dialog_run (GTK_DIALOG (dialog));
+       printf ("debug: after run\n");
+       gtk_widget_destroy (GTK_WIDGET (dialog));
+}
 static GtkWidget* create_page_complete_custom (ModestEasysetupWizardDialog *self)
 {
-       GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_HALF);
+       GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
        GtkWidget *label = gtk_label_new(_("mcen_ia_emailsetup_setup_complete"));
        gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
        gtk_widget_show (label);
@@ -727,6 +756,9 @@ static GtkWidget* create_page_complete_custom (ModestEasysetupWizardDialog *self
        gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
        gtk_widget_show (caption);
        
+       g_signal_connect (G_OBJECT (self->button_edit), "clicked", 
+               G_CALLBACK (on_button_edit_advanced_settings), self);
+       
        gtk_widget_show (GTK_WIDGET (box));
        return GTK_WIDGET (box);
 }
@@ -740,6 +772,15 @@ on_response (ModestWizardDialog *wizard_dialog,
        gpointer user_data)
 {
        ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (wizard_dialog);
+       
+       if (response_id == GTK_RESPONSE_CANCEL) {
+               /* Remove any temporarily-saved account that will not actually be needed: */
+               if (self->saved_account_name) {
+                       modest_account_mgr_remove_account (self->account_manager,
+                                                                    self->saved_account_name, FALSE);
+               }       
+       }
+       
        invoke_enable_buttons_vfunc (self);
 }
 
@@ -1136,14 +1177,17 @@ modest_easysetup_wizard_dialog_class_init (ModestEasysetupWizardDialogClass *kla
 static void
 show_error (GtkWindow *parent_window, const gchar* text)
 {
+       GtkDialog *dialog = GTK_DIALOG (hildon_note_new_information (parent_window, text));
+       /*
        GtkDialog *dialog = GTK_DIALOG (gtk_message_dialog_new (parent_window,
                (GtkDialogFlags)0,
                 GTK_MESSAGE_ERROR,
                 GTK_BUTTONS_OK,
                 text ));
+       */
                 
-                gtk_dialog_run (dialog);
-                gtk_widget_destroy (GTK_WIDGET (dialog));
+       gtk_dialog_run (dialog);
+       gtk_widget_destroy (GTK_WIDGET (dialog));
 }
 
 /** Attempt to create the account from the information that the user has entered.
@@ -1357,13 +1401,17 @@ create_account (ModestEasysetupWizardDialog *self)
                MODEST_ACCOUNT_DISPLAY_NAME, display_name, FALSE /* not server account */);
 
        /* Save the connection-specific SMTP server accounts. */
+       gboolean result = TRUE;
        if (self->specific_window)
-               return modest_connection_specific_smtp_window_save_server_accounts (
+               result = modest_connection_specific_smtp_window_save_server_accounts (
                        MODEST_CONNECTION_SPECIFIC_SMTP_WINDOW (self->specific_window), account_name);
                        
+       g_free (self->saved_account_name);
+       self->saved_account_name = g_strdup (account_name);
+       
        g_free (account_name);
 
-       return FALSE;
+       return result;
 }