2007-04-18 Murray Cumming <murrayc@murrayc.com>
authorMurray Cumming <murrayc@murrayc.com>
Wed, 18 Apr 2007 08:30:27 +0000 (08:30 +0000)
committerMurray Cumming <murrayc@murrayc.com>
Wed, 18 Apr 2007 08:30:27 +0000 (08:30 +0000)
* src/maemo/easysetup/modest-easysetup-serversecurity-combo-box.h:
        * src/maemo/easysetup/modest-easysetup-serversecurity-combo-box.c:
        Added easysetup_serversecurity_combo_box_get_active_serversecurity_port()

        * src/modest-defs.h:
        * src/maemo/modest-account-settings-dialog.c:
        (create_page_incoming), (on_combo_outgoing_security_changed),
        (on_combo_incoming_security_changed), (create_page_outgoing),
        (modest_account_settings_dialog_set_account_name),
        (save_configuration): Load/Save the port number, and change it when the
        security combo changes, to suitable defaults.

pmo-trunk-r1579

ChangeLog2
src/maemo/easysetup/modest-easysetup-serversecurity-combo-box.c
src/maemo/easysetup/modest-easysetup-serversecurity-combo-box.h
src/maemo/modest-account-settings-dialog.c
src/modest-account-mgr-helpers.h
src/modest-defs.h

index b635ca1..40e8b50 100644 (file)
@@ -1,3 +1,17 @@
+2007-04-18  Murray Cumming  <murrayc@murrayc.com>
+
+       * src/maemo/easysetup/modest-easysetup-serversecurity-combo-box.h:
+       * src/maemo/easysetup/modest-easysetup-serversecurity-combo-box.c:
+       Added easysetup_serversecurity_combo_box_get_active_serversecurity_port()
+
+       * src/modest-defs.h:
+       * src/maemo/modest-account-settings-dialog.c:
+       (create_page_incoming), (on_combo_outgoing_security_changed),
+       (on_combo_incoming_security_changed), (create_page_outgoing),
+       (modest_account_settings_dialog_set_account_name),
+       (save_configuration): Load/Save the port number, and change it when the 
+       security combo changes, to suitable defaults.
+
 2007-04-17  Murray Cumming  <murrayc@murrayc.com>
 
        * src/modest-account-mgr.c:
index f2ce3ee..a85f680 100644 (file)
@@ -27,6 +27,7 @@ typedef struct _EasysetupServersecurityComboBoxPrivate EasysetupServersecurityCo
 struct _EasysetupServersecurityComboBoxPrivate
 {
        GtkTreeModel *model;
+       ModestProtocol protocol;
 };
 
 static void
@@ -123,6 +124,7 @@ easysetup_serversecurity_combo_box_new (void)
 void easysetup_serversecurity_combo_box_fill (EasysetupServersecurityComboBox *combobox, ModestProtocol protocol)
 {      
        EasysetupServersecurityComboBoxPrivate *priv = SERVERSECURITY_COMBO_BOX_GET_PRIVATE (combobox);
+       priv->protocol = protocol; /* Remembered for later. */
        
        /* Remove any existing rows: */
        GtkListStore *liststore = GTK_LIST_STORE (priv->model);
@@ -152,6 +154,32 @@ void easysetup_serversecurity_combo_box_fill (EasysetupServersecurityComboBox *c
        }
 }
 
+static gint get_port_for_security (ModestProtocol protocol, ModestProtocol security)
+{
+       /* See the UI spec, section Email Wizards, Incoming Details [MSG-WIZ001]: */
+       gint result = 0;
+
+       /* Get the default port number for this protocol with this security: */
+       if(protocol == MODEST_PROTOCOL_STORE_POP) {
+               if ((security ==  MODEST_PROTOCOL_SECURITY_NONE) || (security ==  MODEST_PROTOCOL_SECURITY_TLS))
+                       result = 110;
+               else if (security ==  MODEST_PROTOCOL_SECURITY_SSL)
+                       result = 995;
+       } else if (protocol == MODEST_PROTOCOL_STORE_IMAP) {
+               if ((security ==  MODEST_PROTOCOL_SECURITY_NONE) || (security ==  MODEST_PROTOCOL_SECURITY_TLS))
+                       result = 143;
+               else if (security ==  MODEST_PROTOCOL_SECURITY_SSL)
+                       result = 993;
+       } else if (protocol == MODEST_PROTOCOL_TRANSPORT_SMTP) {
+               if ((security ==  MODEST_PROTOCOL_SECURITY_NONE) || (security ==  MODEST_PROTOCOL_SECURITY_TLS))
+                       result = 25;
+               else if (security ==  MODEST_PROTOCOL_SECURITY_SSL)
+                       result = 465;
+       }
+
+       return result;
+}
+
 /**
  * Returns the selected serversecurity, 
  * or MODEST_PROTOCOL_UNKNOWN if no serversecurity was selected.
@@ -172,6 +200,20 @@ easysetup_serversecurity_combo_box_get_active_serversecurity (EasysetupServersec
        return MODEST_PROTOCOL_UNKNOWN; /* Failed. */
 }
 
+/**
+ * Returns the default port to be used for the selected serversecurity, 
+ * or 0 if no serversecurity was selected.
+ */
+gint
+easysetup_serversecurity_combo_box_get_active_serversecurity_port (EasysetupServersecurityComboBox *combobox)
+{
+       EasysetupServersecurityComboBoxPrivate *priv = SERVERSECURITY_COMBO_BOX_GET_PRIVATE (combobox);
+       
+       const ModestProtocol security = easysetup_serversecurity_combo_box_get_active_serversecurity 
+               (combobox);
+       return get_port_for_security (priv->protocol, security);
+}
+       
 /* This allows us to pass more than one piece of data to the signal handler,
  * and get a result: */
 typedef struct 
index 916858c..b9fe567 100644 (file)
@@ -51,6 +51,8 @@ ModestProtocol easysetup_serversecurity_combo_box_get_active_serversecurity (Eas
 
 gboolean easysetup_serversecurity_combo_box_set_active_serversecurity (EasysetupServersecurityComboBox *combobox, ModestProtocol serversecurity);
 
+gint easysetup_serversecurity_combo_box_get_active_serversecurity_port (EasysetupServersecurityComboBox *combobox);
+
 
 G_END_DECLS
 
index 58e5484..c9c9b13 100644 (file)
@@ -104,6 +104,12 @@ show_error (GtkWindow *parent_window, const gchar* text);
 static void
 show_ok (GtkWindow *parent_window, const gchar* text);
 
+static void
+on_combo_incoming_security_changed (GtkComboBox *widget, gpointer user_data);
+
+static void
+on_combo_outgoing_security_changed (GtkComboBox *widget, gpointer user_data);
+
 
 static void
 on_caption_entry_changed (GtkEditable *editable, gpointer user_data)
@@ -381,6 +387,10 @@ static GtkWidget* create_page_incoming (ModestAccountSettingsDialog *self)
        gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 2);
        gtk_widget_show (caption);
        
+       /* Show a default port number when the security method changes, as per the UI spec: */
+       g_signal_connect (G_OBJECT (self->combo_incoming_security), "changed", (GCallback)on_combo_incoming_security_changed, self);
+       
+       
        /* The port widgets: */
        /* TODO: There are various rules about this in the UI spec. */
        if (!self->entry_incoming_port)
@@ -463,6 +473,39 @@ on_combo_outgoing_auth_changed (GtkComboBox *widget, gpointer user_data)
        gtk_widget_set_sensitive (self->caption_outgoing_password, secureauth_used);
 }
 
+static void
+on_combo_outgoing_security_changed (GtkComboBox *widget, gpointer user_data)
+{
+       ModestAccountSettingsDialog *self = MODEST_ACCOUNT_SETTINGS_DIALOG (user_data);
+       
+       const gint port_number = 
+               easysetup_serversecurity_combo_box_get_active_serversecurity_port (
+                       EASYSETUP_SERVERSECURITY_COMBO_BOX (self->combo_outgoing_security));
+
+       if(port_number != 0) {
+               gchar* str = g_strdup_printf ("%d", port_number);
+               gtk_entry_set_text (GTK_ENTRY (self->entry_outgoing_port), str);
+               g_free (str);   
+       }               
+}
+
+static void
+on_combo_incoming_security_changed (GtkComboBox *widget, gpointer user_data)
+{
+       ModestAccountSettingsDialog *self = MODEST_ACCOUNT_SETTINGS_DIALOG (user_data);
+       
+       const gint port_number = 
+               easysetup_serversecurity_combo_box_get_active_serversecurity_port (
+                       EASYSETUP_SERVERSECURITY_COMBO_BOX (self->combo_incoming_security));
+
+       if(port_number != 0) {
+               gchar* str = g_strdup_printf ("%d", port_number);
+               gtk_entry_set_text (GTK_ENTRY (self->entry_incoming_port), str);
+               g_free (str);   
+       }               
+}
+
+
 static GtkWidget* create_page_outgoing (ModestAccountSettingsDialog *self)
 {
        GtkWidget *box = gtk_vbox_new (FALSE, 2);
@@ -530,7 +573,10 @@ static GtkWidget* create_page_outgoing (ModestAccountSettingsDialog *self)
                self->combo_outgoing_security, NULL, HILDON_CAPTION_OPTIONAL);
        gtk_widget_show (self->combo_outgoing_security);
        gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 2);
-       gtk_widget_show (caption);      
+       gtk_widget_show (caption);
+       
+       /* Show a default port number when the security method changes, as per the UI spec: */
+       g_signal_connect (G_OBJECT (self->combo_outgoing_security), "changed", (GCallback)on_combo_outgoing_security_changed, self);
        
        /* The port widgets: */
        if (!self->entry_outgoing_port)
@@ -768,8 +814,7 @@ void modest_account_settings_dialog_set_account_name (ModestAccountSettingsDialo
                
        const gboolean leave_on_server = modest_account_mgr_get_bool (dialog->account_manager, account_name,
                MODEST_ACCOUNT_LEAVE_ON_SERVER, FALSE /* not server account */);
-       gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dialog->checkbox_leave_messages), leave_on_server);
-               
+       gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dialog->checkbox_leave_messages), leave_on_server);    
                
        ModestServerAccountData *incoming_account = account_data->store_account;
        if (incoming_account) {
@@ -792,6 +837,12 @@ void modest_account_settings_dialog_set_account_name (ModestAccountSettingsDialo
                easysetup_serversecurity_combo_box_set_active_serversecurity (
                        EASYSETUP_SERVERSECURITY_COMBO_BOX (dialog->combo_incoming_security), security);
                
+               const gint port_num = modest_account_mgr_get_int (dialog->account_manager, incoming_account->account_name,
+                       MODEST_ACCOUNT_PORT, TRUE /* server account */);
+               gchar *port_str = g_strdup_printf ("%d", port_num);
+               gtk_entry_set_text (GTK_ENTRY (dialog->entry_incoming_port), port_str);
+               g_free (port_str);
+       
                /* TODO:
        gchar            *uri;
        ModestProtocol    proto;
@@ -826,7 +877,11 @@ void modest_account_settings_dialog_set_account_name (ModestAccountSettingsDialo
                easysetup_serversecurity_combo_box_set_active_serversecurity (
                        EASYSETUP_SERVERSECURITY_COMBO_BOX (dialog->combo_outgoing_security), security);
                
-               /* TODO: set port. */
+               const gint port_num = modest_account_mgr_get_int (dialog->account_manager, outgoing_account->account_name,
+                       MODEST_ACCOUNT_PORT, TRUE /* server account */);
+               gchar *port_str = g_strdup_printf ("%d", port_num);
+               gtk_entry_set_text (GTK_ENTRY (dialog->entry_outgoing_port), port_str);
+               g_free (port_str);
        }
        
        /* account_data->is_enabled,  */
@@ -896,6 +951,14 @@ save_configuration (ModestAccountSettingsDialog *dialog)
                EASYSETUP_SERVERSECURITY_COMBO_BOX (dialog->combo_incoming_security));
        modest_server_account_set_option_security (dialog->account_manager, incoming_account_name, protocol_security_incoming);
        
+       /* port: */
+       const gchar* port_str = gtk_entry_get_text (GTK_ENTRY (dialog->entry_incoming_port));
+       gint port_num = 0;
+       if (port_str)
+               port_num = atoi (port_str);
+       modest_account_mgr_set_int (dialog->account_manager, incoming_account_name,
+                       MODEST_ACCOUNT_PORT, port_num, TRUE /* server account */);
+               
        g_free (incoming_account_name);
        
        /* Outgoing: */
@@ -929,6 +992,14 @@ save_configuration (ModestAccountSettingsDialog *dialog)
                EASYSETUP_SECUREAUTH_COMBO_BOX (dialog->combo_outgoing_auth));
        modest_server_account_set_option_secure_auth (dialog->account_manager, outgoing_account_name, protocol_authentication_outgoing);        
                
+       /* port: */
+       port_str = gtk_entry_get_text (GTK_ENTRY (dialog->entry_outgoing_port));
+       port_num = 0;
+       if (port_str)
+               port_num = atoi (port_str);
+       modest_account_mgr_set_int (dialog->account_manager, outgoing_account_name,
+                       MODEST_ACCOUNT_PORT, port_num, TRUE /* server account */);
+                       
        g_free (outgoing_account_name);
        
        
index ca4d7c9..1723d4d 100644 (file)
@@ -48,6 +48,7 @@ typedef struct {
        ModestProtocol    proto; /*< The store or transport. Not ORed. */
        gchar            *password;
        time_t            last_updated;
+       gint             port; /* Or 0, if the default should be used. */
        GSList           *options;
 } ModestServerAccountData;
 
index bfdcfb4..de7fe4f 100644 (file)
 
 #define MODEST_ACCOUNT_LEAVE_ON_SERVER   "leave_on_server"   /* boolean */
 #define MODEST_ACCOUNT_PREFERRED_CNX     "preferred_cnx"     /* string */
+#define MODEST_ACCOUNT_PORT                     "port"              /* int */
 #define MODEST_ACCOUNT_OPTIONS          "options"           /* list */
 #define MODEST_ACCOUNT_AUTH_MECH        "auth_mech"         /* string */