2007-04-19 Murray Cumming <murrayc@murrayc.com>
authorMurray Cumming <murrayc@murrayc.com>
Thu, 19 Apr 2007 14:34:36 +0000 (14:34 +0000)
committerMurray Cumming <murrayc@murrayc.com>
Thu, 19 Apr 2007 14:34:36 +0000 (14:34 +0000)
* src/maemo/modest-address-book.c: Added include to avoid a warning.

        * po/en_GB.po: Added missing mcen_bd_emailsetup_close string,
        specified for EmailAccountsDialog in UI spec.

        * src/maemo/easysetup/modest-easysetup-wizard.c:
        * src/maemo/easysetup/modest-easysetup-wizard.h:
        * src/maemo/modest-account-settings-dialog.c:
        * src/maemo/modest-account-settings-dialog.h:
        Reuse a member window widget for the connection-specific SMTP server accounts,
        so we can tell it to create/save the accounts only if we actually save changes.

        * src/maemo/modest-connection-specific-smtp-edit-window.h:
        * src/maemo/modest-connection-specific-smtp-edit-window.c:
        (modest_connection_specific_smtp_edit_window_get_settings):
        Return a struct instance for temporarily remembering the entered data.

        * src/maemo/modest-connection-specific-smtp-window.h:
        * src/maemo/modest-connection-specific-smtp-window.c:
        (modest_connection_specific_smtp_window_finalize),
        (modest_connection_specific_smtp_window_fill_with_connections),
        (on_button_edit),
        (modest_connection_specific_smtp_window_save_server_accounts),
        (update_model_server_names): Do not actually save data until asked,
        when the caller calls modest_connection_specific_smtp_window_save_server_accounts().

        (on_selection_changed),
        (modest_connection_specific_smtp_window_init): Disable the edit
        button when nothing is selected.

        * src/modest-account-mgr-helpers.c:
        * src/modest-account-mgr-helpers.h:
        Put modest_account_mgr_free_server_account_data() in the header now that I use the struct
        elsewhere.

pmo-trunk-r1596

13 files changed:
ChangeLog2
po/en_GB.po
src/maemo/easysetup/modest-easysetup-wizard.c
src/maemo/easysetup/modest-easysetup-wizard.h
src/maemo/modest-account-settings-dialog.c
src/maemo/modest-account-settings-dialog.h
src/maemo/modest-address-book.c
src/maemo/modest-connection-specific-smtp-edit-window.c
src/maemo/modest-connection-specific-smtp-edit-window.h
src/maemo/modest-connection-specific-smtp-window.c
src/maemo/modest-connection-specific-smtp-window.h
src/modest-account-mgr-helpers.c
src/modest-account-mgr-helpers.h

index 8f8de14..155ae85 100644 (file)
@@ -1,5 +1,42 @@
 2007-04-19  Murray Cumming  <murrayc@murrayc.com>
 
+       * src/maemo/modest-address-book.c: Added include to avoid a warning.
+
+       * po/en_GB.po: Added missing mcen_bd_emailsetup_close string, 
+       specified for EmailAccountsDialog in UI spec.
+       
+       * src/maemo/easysetup/modest-easysetup-wizard.c:
+       * src/maemo/easysetup/modest-easysetup-wizard.h:
+       * src/maemo/modest-account-settings-dialog.c:
+       * src/maemo/modest-account-settings-dialog.h:
+       Reuse a member window widget for the connection-specific SMTP server accounts, 
+       so we can tell it to create/save the accounts only if we actually save changes.
+
+       * src/maemo/modest-connection-specific-smtp-edit-window.h:      
+       * src/maemo/modest-connection-specific-smtp-edit-window.c:
+       (modest_connection_specific_smtp_edit_window_get_settings): 
+       Return a struct instance for temporarily remembering the entered data.
+
+       * src/maemo/modest-connection-specific-smtp-window.h:
+       * src/maemo/modest-connection-specific-smtp-window.c:
+       (modest_connection_specific_smtp_window_finalize),
+       (modest_connection_specific_smtp_window_fill_with_connections),
+       (on_button_edit),
+       (modest_connection_specific_smtp_window_save_server_accounts),
+       (update_model_server_names): Do not actually save data until asked, 
+       when the caller calls modest_connection_specific_smtp_window_save_server_accounts().
+       
+       (on_selection_changed),
+       (modest_connection_specific_smtp_window_init): Disable the edit 
+       button when nothing is selected.
+       
+       * src/modest-account-mgr-helpers.c:
+       * src/modest-account-mgr-helpers.h: 
+       Put modest_account_mgr_free_server_account_data() in the header now that I use the struct 
+       elsewhere.
+
+2007-04-19  Murray Cumming  <murrayc@murrayc.com>
+
        * src/modest-account-mgr-helpers.h:
        * src/modest-account-mgr-helpers.c:
        (modest_account_mgr_get_unused_account_name),
index 42de3a3..f6ac1b0 100644 (file)
@@ -1506,3 +1506,7 @@ msgstr "Edit"
 msgid "mcen_bd_emailsetup_delete"
 msgstr "Delete"
 
+# Button label
+msgid "mcen_bd_emailsetup_close"
+msgstr "Close"
+
index 06010ca..9ee8fdd 100644 (file)
@@ -86,6 +86,9 @@ modest_easysetup_wizard_dialog_finalize (GObject *object)
                
        if (priv->presets)
                modest_presets_destroy (priv->presets);
+               
+       if (self->specific_window)
+               gtk_widget_destroy (self->specific_window);
        
        G_OBJECT_CLASS (modest_easysetup_wizard_dialog_parent_class)->finalize (object);
 }
@@ -573,29 +576,23 @@ enable_widget_for_togglebutton (GtkWidget *widget, GtkToggleButton* button)
        /* Set the starting sensitivity: */
        on_toggle_button_changed (button, widget);
 }
-       
-static void
-on_smtp_servers_window_hide (GtkWindow *window, gpointer user_data)
-{
-       /* Destroy the window when it is closed: */
-       gtk_widget_destroy (GTK_WIDGET (window));
-}
 
 static void
 on_button_outgoing_smtp_servers (GtkButton *button, gpointer user_data)
 {
        ModestEasysetupWizardDialog * self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
        
-       /* Show the window: */
-       /* TODO: Retrieve the chosen settings,
-        * so we can supply them when creating the connection somehow.
-        */
-       GtkWidget *window = GTK_WIDGET (modest_connection_specific_smtp_window_new ());
+       /* Create the window, if necessary: */
+       if (!(self->specific_window)) {
+               self->specific_window = GTK_WIDGET (modest_connection_specific_smtp_window_new ());
+               modest_connection_specific_smtp_window_fill_with_connections (
+                       MODEST_CONNECTION_SPECIFIC_SMTP_WINDOW (self->specific_window), self->account_manager, 
+                       NULL /* account_name, not known yet. */);
+       }
 
-       gtk_window_set_transient_for (GTK_WINDOW (window), GTK_WINDOW (self));
-       g_signal_connect (G_OBJECT (window), "hide",
-               G_CALLBACK (on_smtp_servers_window_hide), self);
-       gtk_widget_show (window);
+       /* Show the window: */
+       gtk_window_set_transient_for (GTK_WINDOW (self->specific_window), GTK_WINDOW (self));
+       gtk_widget_show (self->specific_window);
 }
 
 static GtkWidget* create_page_custom_outgoing (ModestEasysetupWizardDialog *self)
@@ -943,13 +940,13 @@ on_before_next (ModestWizardDialog *dialog, GtkWidget *current_page, GtkWidget *
         */
        if (current_page == account_wizard->page_account_details) {     
                /* Check that the title is not already in use: */
-               const gchar* account_name = gtk_entry_get_text (GTK_ENTRY (account_wizard->entry_account_title));
-               if ((!account_name) || (strlen(account_name) == 0))
+               const gchar* account_title = gtk_entry_get_text (GTK_ENTRY (account_wizard->entry_account_title));
+               if ((!account_title) || (strlen(account_title) == 0))
                        return FALSE;
                        
                /* Aavoid a clash with an existing display name: */
                const gboolean name_in_use = modest_account_mgr_account_with_display_name_exists (
-                       account_wizard->account_manager, account_name);
+                       account_wizard->account_manager, account_title);
 
                if (name_in_use) {
                        /* Warn the user via a dialog: */
@@ -1315,6 +1312,11 @@ create_account (ModestEasysetupWizardDialog *self)
        modest_account_mgr_set_string (self->account_manager, account_name,
                MODEST_ACCOUNT_DISPLAY_NAME, display_name, FALSE /* not server account */);
 
+       /* Save the connection-specific SMTP server accounts. */
+       if (self->specific_window)
+               return modest_connection_specific_smtp_window_save_server_accounts (
+                       MODEST_CONNECTION_SPECIFIC_SMTP_WINDOW (self->specific_window), account_name);
+                       
        g_free (account_name);
 
        return FALSE;
index d415fff..289472f 100644 (file)
@@ -75,6 +75,8 @@ typedef struct {
        GtkWidget *page_complete_customsetup;
        GtkWidget *button_edit;
        
+       GtkWidget *specific_window;
+       
 } ModestEasysetupWizardDialog;
 
 typedef struct {
index ce3dd19..25d74f3 100644 (file)
@@ -96,6 +96,9 @@ modest_account_settings_dialog_finalize (GObject *object)
                
        if (self->account_manager)
                g_object_unref (G_OBJECT (self->account_manager));
+               
+       if (self->specific_window)
+               gtk_widget_destroy (self->specific_window);
        
        G_OBJECT_CLASS (modest_account_settings_dialog_parent_class)->finalize (object);
 }
@@ -499,30 +502,24 @@ enable_widget_for_togglebutton (GtkWidget *widget, GtkToggleButton* button)
        /* Set the starting sensitivity: */
        on_toggle_button_changed (button, widget);
 }
-       
-static void
-on_smtp_servers_window_hide (GtkWindow *window, gpointer user_data)
-{
-       /* Destroy the window when it is closed: */
-       gtk_widget_destroy (GTK_WIDGET (window));
-}
 
 static void
 on_button_outgoing_smtp_servers (GtkButton *button, gpointer user_data)
 {
        ModestAccountSettingsDialog * self = MODEST_ACCOUNT_SETTINGS_DIALOG (user_data);
        
-       /* Show the window: */
-       /* TODO: Retrieve the chosen settings,
-        * so we can supply them when creating the connection somehow.
-        */
-       GtkWidget *window = GTK_WIDGET (modest_connection_specific_smtp_window_new ());
-       gtk_window_set_transient_for (GTK_WINDOW (window), GTK_WINDOW (self));
-       gtk_window_set_modal (GTK_WINDOW (window), TRUE);
-    gtk_widget_show (window);
-    
-    g_signal_connect (G_OBJECT (window), "hide",
-        G_CALLBACK (on_smtp_servers_window_hide), self);
+       /* Create the window if necessary: */
+       if (!(self->specific_window)) {
+               self->specific_window = GTK_WIDGET (modest_connection_specific_smtp_window_new ());
+               modest_connection_specific_smtp_window_fill_with_connections (
+                       MODEST_CONNECTION_SPECIFIC_SMTP_WINDOW (self->specific_window), self->account_manager, 
+                       self->account_name);
+       }
+
+       /* Show the window: */  
+       gtk_window_set_transient_for (GTK_WINDOW (self->specific_window), GTK_WINDOW (self));
+       gtk_window_set_modal (GTK_WINDOW (self->specific_window), TRUE);
+    gtk_widget_show (self->specific_window);
 }
 
 static void
@@ -1133,7 +1130,12 @@ save_configuration (ModestAccountSettingsDialog *dialog)
                        return FALSE;
        }
        
-       return TRUE;
+       /* Save connection-specific SMTP server accounts: */
+       if (dialog->specific_window)
+               return modest_connection_specific_smtp_window_save_server_accounts (
+                       MODEST_CONNECTION_SPECIFIC_SMTP_WINDOW (dialog->specific_window), account_name);
+       else
+               return TRUE;
 }
 
 static gboolean entry_is_empty (GtkWidget *entry)
index ba4e734..0d95354 100644 (file)
@@ -79,6 +79,8 @@ typedef struct {
        GtkWidget *checkbox_outgoing_smtp_specific;
        GtkWidget *button_outgoing_smtp_servers;
        
+       GtkWidget *specific_window;
+       
 } ModestAccountSettingsDialog;
 
 typedef struct {
index b65fae3..3e76c39 100644 (file)
@@ -45,6 +45,7 @@
 #include <gtk/gtklabel.h>
 #include <gtk/gtkcellrenderertext.h>
 #include <gtk/gtktreeselection.h>
+#include <gtk/gtkentry.h>
 
 static OssoABookContactModel *contact_model =  NULL;
 static EBook *book = NULL;
index ea6e9db..afb1848 100644 (file)
@@ -207,17 +207,40 @@ modest_connection_specific_smtp_edit_window_new (void)
 
 void
 modest_connection_specific_smtp_edit_window_set_connection (
-       ModestConnectionSpecificSmtpEditWindow *window, const gchar* iap_id, const gchar* iap_name)
+       ModestConnectionSpecificSmtpEditWindow *window, const gchar* iap_id, const gchar* iap_name,
+       const ModestServerAccountData *data)
 {
+       ModestConnectionSpecificSmtpEditWindowPrivate *priv = 
+               CONNECTION_SPECIFIC_SMTP_EDIT_WINDOW_GET_PRIVATE (window);
+
        /* This causes a warning because of the %s in the translation, but not in the original string: */
        gchar* title = g_strdup_printf (_("mcen_ti_connection_connection_name"), iap_name);
-       
        gtk_window_set_title (GTK_WINDOW (window), title);
        g_free (title);
+       
+       if (data) 
+       {
+               gtk_entry_set_text (GTK_ENTRY (priv->entry_outgoingserver), data->hostname);
+               gtk_entry_set_text (GTK_ENTRY (priv->entry_user_username), data->username);     
+               gtk_entry_set_text (GTK_ENTRY (priv->entry_user_password), data->password);
+       
+               easysetup_serversecurity_combo_box_set_active_serversecurity (
+               EASYSETUP_SERVERSECURITY_COMBO_BOX (priv->combo_outgoing_security), data->security);
+       
+               easysetup_secureauth_combo_box_set_active_secureauth (
+               EASYSETUP_SECUREAUTH_COMBO_BOX (priv->combo_outgoing_auth), data->secure_auth);
+               
+               /* port: */
+               gchar * port_str = g_strdup_printf ("%d", data->port);
+               gtk_entry_set_text (GTK_ENTRY (priv->entry_port), port_str);
+               g_free (port_str);
+       }
 }
 
-gboolean
-modest_connection_specific_smtp_edit_window_save_settings (
+/*
+ * The result must be freed with modest_account_mgr_free_server_account_data(). */
+ModestServerAccountData*
+modest_connection_specific_smtp_edit_window_get_settings (
        ModestConnectionSpecificSmtpEditWindow *window, 
        ModestAccountMgr *account_manager, const gchar* server_account_name)
 {
@@ -226,39 +249,24 @@ modest_connection_specific_smtp_edit_window_save_settings (
        
        g_assert (server_account_name);
        
-       const gchar* hostname = gtk_entry_get_text (GTK_ENTRY (priv->entry_outgoingserver));
-       gboolean test = modest_account_mgr_set_string (account_manager, server_account_name,
-               MODEST_ACCOUNT_HOSTNAME, hostname, TRUE /* server account */);
-       if (!test)
-               return FALSE;
-               
-       const gchar* username = gtk_entry_get_text (GTK_ENTRY (priv->entry_user_username));
-       test = modest_account_mgr_set_string (account_manager, server_account_name,
-               MODEST_ACCOUNT_USERNAME, username, TRUE /* server account */);
-       if (!test)
-               return FALSE;
-               
-       const gchar* password = gtk_entry_get_text (GTK_ENTRY (priv->entry_user_password));
-       test = modest_account_mgr_set_string (account_manager, server_account_name,
-               MODEST_ACCOUNT_PASSWORD, password, TRUE /*  server account */);
-       if (!test)
-               return FALSE;
+       /* Use g_slice_new0(), because that's what modest_account_mgr_free_server_account_data() 
+        * expects us to use. */
+       ModestServerAccountData *result = g_slice_new0 (ModestServerAccountData);
+       
+       result->hostname = g_strdup (gtk_entry_get_text (GTK_ENTRY (priv->entry_outgoingserver)));
+       result->username = g_strdup (gtk_entry_get_text (GTK_ENTRY (priv->entry_user_username)));       
+       result->password = g_strdup (gtk_entry_get_text (GTK_ENTRY (priv->entry_user_password)));
        
-       const ModestProtocol protocol_security_outgoing = easysetup_serversecurity_combo_box_get_active_serversecurity (
+       result->security = easysetup_serversecurity_combo_box_get_active_serversecurity (
                EASYSETUP_SERVERSECURITY_COMBO_BOX (priv->combo_outgoing_security));
-       modest_server_account_set_security (account_manager, server_account_name, protocol_security_outgoing);
        
-       const ModestProtocol protocol_authentication_outgoing = easysetup_secureauth_combo_box_get_active_secureauth (
+       result->secure_auth = easysetup_secureauth_combo_box_get_active_secureauth (
                EASYSETUP_SECUREAUTH_COMBO_BOX (priv->combo_outgoing_auth));
-       modest_server_account_set_secure_auth (account_manager, server_account_name, protocol_authentication_outgoing); 
                
        /* port: */
        const gchar * port_str = gtk_entry_get_text (GTK_ENTRY (priv->entry_port));
-       gint port_num = 0;
        if (port_str)
-               port_num = atoi (port_str);
-       modest_account_mgr_set_int (account_manager, server_account_name,
-                       MODEST_ACCOUNT_PORT, port_num, TRUE /* server account */);
+               result->port = atoi (port_str);
                        
-       return TRUE;
+       return result;
 }
index 3626fc4..a7deadc 100644 (file)
@@ -31,6 +31,7 @@
 #define __MODEST_MAEMO_CONNECTION_SPECIFIC_SMTP_EDIT_WINDOW
 
 #include <modest-account-mgr.h>
+#include <modest-account-mgr-helpers.h> /* For ModestServerAccountData */
 #include <gtk/gtkdialog.h>
 #include <gtk/gtktreeview.h>
 
@@ -72,9 +73,10 @@ GType modest_connection_specific_smtp_edit_window_get_type (void);
 ModestConnectionSpecificSmtpEditWindow* modest_connection_specific_smtp_edit_window_new (void);
 
 void modest_connection_specific_smtp_edit_window_set_connection (
-       ModestConnectionSpecificSmtpEditWindow *window, const gchar* iap_id, const gchar* iap_name);
+       ModestConnectionSpecificSmtpEditWindow *window, const gchar* iap_id, const gchar* iap_name, 
+       const ModestServerAccountData *data);
        
-gboolean modest_connection_specific_smtp_edit_window_save_settings (
+ModestServerAccountData* modest_connection_specific_smtp_edit_window_get_settings (
        ModestConnectionSpecificSmtpEditWindow *window, 
        ModestAccountMgr *account_manager, const gchar* server_account_name);
        
index 769a2e0..3e018fe 100644 (file)
@@ -29,6 +29,7 @@ struct _ModestConnectionSpecificSmtpWindowPrivate
 {
        GtkTreeView *treeview;
        GtkTreeModel *model;
+       GtkWidget *button_edit;
        
        ModestAccountMgr *account_manager;
        gchar* account_name;
@@ -61,11 +62,39 @@ modest_connection_specific_smtp_window_dispose (GObject *object)
                G_OBJECT_CLASS (modest_connection_specific_smtp_window_parent_class)->dispose (object);
 }
 
+enum MODEL_COLS {
+       MODEL_COL_NAME = 0, /* libconic IAP Name: a string */
+       MODEL_COL_ID = 1, /* libconic IAP ID: a string */
+       MODEL_COL_SERVER_ACCOUNT_NAME = 2, /* a string */
+       MODEL_COL_SERVER_NAME = 3, /* a string */
+       MODEL_COL_SERVER_ACCOUNT_DATA = 4 /* a gpointer */
+};
+
+
+void update_model_server_names (ModestConnectionSpecificSmtpWindow *self);
+
 static void
 modest_connection_specific_smtp_window_finalize (GObject *object)
 {
        ModestConnectionSpecificSmtpWindowPrivate *priv = CONNECTION_SPECIFIC_SMTP_WINDOW_GET_PRIVATE (object);
-
+       
+       /* Free all the data items from the treemodel: */
+       GtkTreeIter iter;
+       gboolean valid = gtk_tree_model_get_iter_first (priv->model, &iter);
+       while (valid) {
+               ModestServerAccountData *data = NULL;
+               
+               gtk_tree_model_get (priv->model, &iter, 
+                                   MODEL_COL_SERVER_ACCOUNT_DATA, &data,
+                                   -1);
+                                
+               if (data)
+                       modest_account_mgr_free_server_account_data (priv->account_manager, data);
+                       
+               /* Get next row: */
+               valid = gtk_tree_model_iter_next (priv->model, &iter);
+       }
+       
        g_object_unref (G_OBJECT (priv->model));
        g_free (priv->account_name);
        
@@ -85,13 +114,6 @@ modest_connection_specific_smtp_window_class_init (ModestConnectionSpecificSmtpW
        object_class->finalize = modest_connection_specific_smtp_window_finalize;
 }
 
-enum MODEL_COLS {
-       MODEL_COL_NAME = 0, /* libconic IAP Name: a string */
-       MODEL_COL_ID = 1, /* libconic IAP ID: a string */
-       MODEL_COL_SERVER_ACCOUNT_NAME = 2, /* a string */
-       MODEL_COL_SERVER_NAME = 3 /* a string */
-};
-
 void
 modest_connection_specific_smtp_window_fill_with_connections (ModestConnectionSpecificSmtpWindow *self, ModestAccountMgr *account_manager,
        const gchar* account_name)
@@ -99,7 +121,7 @@ modest_connection_specific_smtp_window_fill_with_connections (ModestConnectionSp
        ModestConnectionSpecificSmtpWindowPrivate *priv = 
                CONNECTION_SPECIFIC_SMTP_WINDOW_GET_PRIVATE (self);
        priv->account_manager = account_manager;
-       priv->account_name = g_strdup (account_name);
+       priv->account_name = account_name ? g_strdup (account_name) : NULL;
        
        GtkListStore *liststore = GTK_LIST_STORE (priv->model);
        
@@ -120,10 +142,22 @@ modest_connection_specific_smtp_window_fill_with_connections (ModestConnectionSp
                        const gchar *id = con_ic_iap_get_id (iap);
                        printf ("debug: iac name=%s, id=%s\n", name, id);
                        
+                       /* Get any already-associated connection-specific server account: */
+                       gchar *server_account_name = NULL;
+                       if (priv->account_name)
+                               server_account_name = modest_account_mgr_get_connection_specific_smtp (
+                                       priv->account_manager, priv->account_name, name);
+                                       
                        /* Add the row to the model: */
                        GtkTreeIter iter;
                        gtk_list_store_append (liststore, &iter);
-                       gtk_list_store_set(liststore, &iter, MODEL_COL_ID, id, MODEL_COL_NAME, name, -1);
+                       gtk_list_store_set(liststore, &iter, 
+                               MODEL_COL_ID, id, 
+                               MODEL_COL_NAME, name,
+                               MODEL_COL_SERVER_ACCOUNT_NAME, server_account_name,
+                               -1);
+                               
+                       g_free (server_account_name);
                }
                
                iter = g_slist_next (iter);     
@@ -131,8 +165,9 @@ modest_connection_specific_smtp_window_fill_with_connections (ModestConnectionSp
                
        if (list_iaps)
                tny_maemo_conic_device_free_iap_list (maemo_device, list_iaps);
+               
+       update_model_server_names (self);
 }
-
        
 static void
 on_button_edit (GtkButton *button, gpointer user_data)
@@ -143,7 +178,8 @@ on_button_edit (GtkButton *button, gpointer user_data)
        gchar *id = NULL;
        gchar *connection_name = NULL;
        gchar *server_account_name = NULL;
-       GtkTreeSelection *sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (self));
+       ModestServerAccountData *data = NULL;
+       GtkTreeSelection *sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
        GtkTreeIter iter;
        GtkTreeModel *model = 0;
        if (gtk_tree_selection_get_selected (sel, &model, &iter)) {
@@ -151,43 +187,48 @@ on_button_edit (GtkButton *button, gpointer user_data)
                                    MODEL_COL_ID, &id, 
                                    MODEL_COL_NAME, &connection_name, 
                                    MODEL_COL_SERVER_ACCOUNT_NAME, &server_account_name,
+                                   MODEL_COL_SERVER_ACCOUNT_DATA, &data,
                                    -1);
        
                /* TODO: Is 0 an allowed libconic IAP ID? 
                 * If not then we should check for it. */
                
+               /* Get existing server account data if a server account is already specified: */
+               ModestServerAccountData *data_retrieved = NULL;
+               if (server_account_name && !data) {
+                       data_retrieved = modest_account_mgr_get_server_account_data (priv->account_manager, 
+                               server_account_name);
+                       data =  data_retrieved;
+               }
+               
                GtkWidget * window = GTK_WIDGET (modest_connection_specific_smtp_edit_window_new ());
                modest_connection_specific_smtp_edit_window_set_connection (
-                       MODEST_CONNECTION_SPECIFIC_SMTP_EDIT_WINDOW (window), id, connection_name);
+                       MODEST_CONNECTION_SPECIFIC_SMTP_EDIT_WINDOW (window), id, connection_name, data);
+                       
+               if (data_retrieved)
+                       modest_account_mgr_free_server_account_data (priv->account_manager, data_retrieved);
                        
                gtk_window_set_transient_for (GTK_WINDOW (self), GTK_WINDOW (window));
                gint response = gtk_dialog_run (GTK_DIALOG (window));
                gtk_widget_hide (window);
                
                if (response == GTK_RESPONSE_OK) {
-                       if (server_account_name) {
-                               /* Change the existing server account. */
-                               modest_connection_specific_smtp_edit_window_save_settings (
-                                       MODEST_CONNECTION_SPECIFIC_SMTP_EDIT_WINDOW (window), 
-                                       priv->account_manager, server_account_name);    
-                       } else {
-                               /* Add a new server account, building a (non-human-visible) name: */
-                               gchar *name_start = g_strdup_printf("%s_specific_%s", 
-                                       priv->account_name, connection_name);
-                               server_account_name = modest_account_mgr_get_unused_account_name (
-                                       priv->account_manager, name_start, TRUE /* server account. */);
-                               g_free (name_start);
-                               
-                               modest_connection_specific_smtp_edit_window_save_settings (
-                                       MODEST_CONNECTION_SPECIFIC_SMTP_EDIT_WINDOW (window), 
-                                       priv->account_manager, server_account_name);
-                                       
-                               /* Store it in the model so it can be edited again: */
-                               gtk_list_store_set (GTK_LIST_STORE (priv->model), &iter, 
-                                   MODEL_COL_SERVER_ACCOUNT_NAME, server_account_name,
-                                   -1);
+                       /* Delete any previous data for this row: */
+                       if (data) 
+                       {
+                               modest_account_mgr_free_server_account_data (priv->account_manager, data);
+                               data = NULL;
                        }
-               }               
+                       
+                       /* Get the new account data and save it in the row for later:
+                        * We free this in finalize(). */
+                       data = modest_connection_specific_smtp_edit_window_get_settings (
+                                               MODEST_CONNECTION_SPECIFIC_SMTP_EDIT_WINDOW (window), 
+                                               priv->account_manager, server_account_name);    
+                       gtk_list_store_set (GTK_LIST_STORE (priv->model), &iter, 
+                                           MODEL_COL_SERVER_ACCOUNT_DATA, data,
+                                           -1);
+               }
        }
        
        g_free (connection_name);
@@ -206,6 +247,20 @@ on_button_cancel (GtkButton *button, gpointer user_data)
 }
 
 static void
+on_selection_changed (GtkTreeSelection *sel, ModestConnectionSpecificSmtpWindow *self)
+{
+       ModestConnectionSpecificSmtpWindowPrivate *priv = 
+               CONNECTION_SPECIFIC_SMTP_WINDOW_GET_PRIVATE (self);
+
+       GtkTreeModel *model = NULL;
+       GtkTreeIter iter;
+       const gboolean has_selection =
+               gtk_tree_selection_get_selected (sel, &model, &iter);
+
+       gtk_widget_set_sensitive (priv->button_edit, has_selection);
+}
+
+static void
 modest_connection_specific_smtp_window_init (ModestConnectionSpecificSmtpWindow *self)
 {
        /* This seems to be necessary to make the window show at the front with decoration.
@@ -214,13 +269,15 @@ modest_connection_specific_smtp_window_init (ModestConnectionSpecificSmtpWindow
        gtk_window_set_type_hint (GTK_WINDOW (self),
                            GDK_WINDOW_TYPE_HINT_DIALOG);
                            
-       ModestConnectionSpecificSmtpWindowPrivate *priv = CONNECTION_SPECIFIC_SMTP_WINDOW_GET_PRIVATE (self);
+       ModestConnectionSpecificSmtpWindowPrivate *priv = 
+               CONNECTION_SPECIFIC_SMTP_WINDOW_GET_PRIVATE (self);
 
        /* Create a tree model for the tree view:
         * with a string for the name, a string for the server name, and an int for the ID.
         * This must match our MODEL_COLS enum constants.
         */
-       priv->model = GTK_TREE_MODEL (gtk_list_store_new (4, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING));
+       priv->model = GTK_TREE_MODEL (gtk_list_store_new (4, 
+               G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_POINTER));
 
        /* Setup the tree view: */
        priv->treeview = GTK_TREE_VIEW (gtk_tree_view_new_with_model (priv->model));
@@ -261,10 +318,10 @@ modest_connection_specific_smtp_window_init (ModestConnectionSpecificSmtpWindow
        gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 2);
        gtk_widget_show (hbox);
        
-       GtkWidget *button_edit = gtk_button_new_from_stock (GTK_STOCK_EDIT);
-       gtk_box_pack_start (GTK_BOX (hbox), button_edit, TRUE, FALSE, 2);
-       gtk_widget_show (button_edit);
-       g_signal_connect (G_OBJECT (button_edit), "clicked",
+       priv->button_edit = gtk_button_new_from_stock (GTK_STOCK_EDIT);
+       gtk_box_pack_start (GTK_BOX (hbox), priv->button_edit, TRUE, FALSE, 2);
+       gtk_widget_show (priv->button_edit);
+       g_signal_connect (G_OBJECT (priv->button_edit), "clicked",
                G_CALLBACK (on_button_edit), self);
        
        GtkWidget *button_cancel = gtk_button_new_from_stock (GTK_STOCK_CLOSE);
@@ -275,6 +332,12 @@ modest_connection_specific_smtp_window_init (ModestConnectionSpecificSmtpWindow
        
        gtk_container_add (GTK_CONTAINER (self), GTK_WIDGET (vbox));
        gtk_widget_show (vbox);
+       
+       /* Disable the Edit button when nothing is selected: */
+       GtkTreeSelection *sel = gtk_tree_view_get_selection (priv->treeview);
+       g_signal_connect (sel, "changed",
+                         G_CALLBACK(on_selection_changed), self);
+       on_selection_changed (sel, self);
 }
 
 ModestConnectionSpecificSmtpWindow*
@@ -283,3 +346,125 @@ modest_connection_specific_smtp_window_new (void)
        return g_object_new (MODEST_TYPE_CONNECTION_SPECIFIC_SMTP_WINDOW, NULL);
 }
 
+/** The application should call this when the user changes should be saved.
+ * @account_name: Specify this again in case it was not previously known.
+ */
+gboolean
+modest_connection_specific_smtp_window_save_server_accounts (ModestConnectionSpecificSmtpWindow *self, 
+       const gchar* account_name)
+{
+       ModestConnectionSpecificSmtpWindowPrivate *priv = 
+               CONNECTION_SPECIFIC_SMTP_WINDOW_GET_PRIVATE (self);
+       
+       
+       /* Get the first iter in the list */
+       GtkTreeIter iter;
+       gboolean valid = gtk_tree_model_get_iter_first (priv->model, &iter);
+
+       /* Walk through the list, reading each row */
+       while (valid) {
+       gchar *id = NULL;
+               gchar *connection_name = NULL;
+               gchar *server_account_name = NULL;
+               ModestServerAccountData *data = NULL;
+               
+               gtk_tree_model_get (priv->model, &iter, 
+                                   MODEL_COL_ID, &id, 
+                                   MODEL_COL_NAME, &connection_name, 
+                                   MODEL_COL_SERVER_ACCOUNT_NAME, &server_account_name,
+                                   MODEL_COL_SERVER_ACCOUNT_DATA, &data,
+                                   -1);
+                                
+               gboolean success = TRUE;   
+               if (id && data) { /* The presence of data suggests that there is something to save. */
+                       if (!server_account_name) {
+                               /* Add a new server account, building a (non-human-visible) name: */
+                               gchar *name_start = g_strdup_printf("%s_specific_%s", 
+                                       priv->account_name, connection_name);
+                               server_account_name = modest_account_mgr_get_unused_account_name (
+                                       priv->account_manager, name_start, TRUE /* server account. */);
+                               g_free (name_start);
+                               
+                               success = modest_account_mgr_add_server_account (priv->account_manager,
+                                       server_account_name,
+                                       data->hostname,
+                                       data->username, data->password,
+                                       MODEST_PROTOCOL_TRANSPORT_SMTP,
+                                       data->security,
+                                       data->secure_auth);
+                                       
+                               /* associate the specific server account with this connection for this account: */
+                               success = success && modest_account_mgr_set_connection_specific_smtp (
+                                       priv->account_manager, priv->account_name,
+                                        connection_name, server_account_name);
+       
+                               /* Save the new name in the treemodel, so it can be edited again later: */
+                               gtk_list_store_set (GTK_LIST_STORE (priv->model), &iter, 
+                                       MODEL_COL_SERVER_ACCOUNT_NAME, server_account_name, -1);
+                               
+                       } else {
+                               /* Change an existing server account: */
+                               success = modest_account_mgr_set_string (priv->account_manager, server_account_name,
+                                       MODEST_ACCOUNT_HOSTNAME, data->hostname, TRUE /* server account */);
+                                                       
+                               success = success &&  modest_account_mgr_set_string (priv->account_manager, server_account_name,
+                                       MODEST_ACCOUNT_USERNAME, data->username, TRUE /* server account */);
+                                                       
+                               success = success &&  modest_account_mgr_set_string (priv->account_manager, server_account_name,
+                                       MODEST_ACCOUNT_PASSWORD, data->password, TRUE /*  server account */);
+                                               
+                               modest_server_account_set_secure_auth (priv->account_manager, server_account_name, 
+                                       data->secure_auth);
+                                               
+                               modest_server_account_set_security (priv->account_manager, server_account_name, 
+                                       data->security);
+                               
+                               modest_account_mgr_set_int (priv->account_manager, server_account_name,
+                                               MODEST_ACCOUNT_PORT, data->port, TRUE /* server account */);
+                       }
+               }
+               
+               g_free (connection_name);
+               g_free (id);
+               g_free (server_account_name);
+               
+               if (!success)
+                       return FALSE;
+                       
+               /* Get next row: */
+               valid = gtk_tree_model_iter_next (priv->model, &iter);
+       }
+       
+       update_model_server_names (self);
+       
+       return TRUE;
+}
+
+void update_model_server_names (ModestConnectionSpecificSmtpWindow *self)
+{
+       ModestConnectionSpecificSmtpWindowPrivate *priv = CONNECTION_SPECIFIC_SMTP_WINDOW_GET_PRIVATE (self);
+
+       GtkTreeIter iter;
+       gboolean valid = gtk_tree_model_get_iter_first (priv->model, &iter);
+       while (valid) {
+               
+               gchar *server_account_name = NULL;
+               gtk_tree_model_get (priv->model, &iter, 
+                                   MODEL_COL_SERVER_ACCOUNT_NAME, &server_account_name,
+                                   -1);
+                                
+               if (server_account_name) {
+                       /* Get the server hostname and show it in the treemodel: */     
+                       gchar *hostname = modest_account_mgr_get_string (priv->account_manager, 
+                               server_account_name, MODEST_ACCOUNT_HOSTNAME, TRUE /* server account */);
+                       gtk_list_store_set (GTK_LIST_STORE (priv->model), &iter, 
+                                           MODEL_COL_SERVER_NAME, hostname,
+                                           -1);
+                       g_free (hostname);
+               }
+                       
+               /* Get next row: */
+               valid = gtk_tree_model_iter_next (priv->model, &iter);
+       }
+}
+
index b584703..f94a93f 100644 (file)
@@ -75,6 +75,10 @@ void
 modest_connection_specific_smtp_window_fill_with_connections (ModestConnectionSpecificSmtpWindow *self, 
        ModestAccountMgr *account_manager, const gchar* account_name);
 
+gboolean
+modest_connection_specific_smtp_window_save_server_accounts (ModestConnectionSpecificSmtpWindow *self, 
+       const gchar* account_name);
+
 G_END_DECLS
 
 #endif /* __MODEST_MAEMO_CONNECTION_SPECIFIC_SMTP_WINDOW */
index 8a7e320..cd6a49f 100644 (file)
@@ -340,7 +340,7 @@ modest_account_mgr_get_server_account_option (ModestAccountMgr *self,
 }
 #endif
 
-static ModestServerAccountData*
+ModestServerAccountData*
 modest_account_mgr_get_server_account_data (ModestAccountMgr *self, const gchar* name)
 {
        ModestServerAccountData *data;
@@ -378,7 +378,7 @@ modest_account_mgr_get_server_account_data (ModestAccountMgr *self, const gchar*
 }
 
 
-static void
+void
 modest_account_mgr_free_server_account_data (ModestAccountMgr *self,
                                             ModestServerAccountData* data)
 {
index 00034b5..8ac5efc 100644 (file)
@@ -225,6 +225,13 @@ modest_server_account_get_security (ModestAccountMgr *self, const gchar* account
 void
 modest_server_account_set_security (ModestAccountMgr *self, const gchar* account_name, 
        ModestProtocol security);
+
+ModestServerAccountData*
+modest_account_mgr_get_server_account_data (ModestAccountMgr *self, const gchar* name);
+
+void
+modest_account_mgr_free_server_account_data (ModestAccountMgr *self,
+                                            ModestServerAccountData* data);
        
 #if 0
 /**
@@ -281,7 +288,7 @@ gchar * modest_account_mgr_get_from_string (ModestAccountMgr *self, const gchar*
 gchar*
 modest_account_mgr_get_unused_account_name (ModestAccountMgr *self, const gchar* starting_name,
        gboolean server_account);
-       
+
 /**
  * modest_account_mgr_get_unused_account_display name
  * @self: a #ModestAccountMgr instance