[geary/wip/714104-refine-account-dialog: 64/69] Provide a means to get the default port for a specific service config



commit 1055036c029a8ca4625ef5350876f1d747ee6eaa
Author: Michael Gratton <mike vee net>
Date:   Fri Nov 30 23:33:50 2018 +1100

    Provide a means to get the default port for a specific service config
    
    Use this to set the default for new accounts before passing to the
    engine for validation.

 src/client/accounts/accounts-editor-add-pane.vala |  8 +++++++
 src/engine/api/geary-engine.vala                  | 18 ---------------
 src/engine/api/geary-service-information.vala     | 27 +++++++++++++++++++++++
 3 files changed, 35 insertions(+), 18 deletions(-)
---
diff --git a/src/client/accounts/accounts-editor-add-pane.vala 
b/src/client/accounts/accounts-editor-add-pane.vala
index a1b80089..a9d3222a 100644
--- a/src/client/accounts/accounts-editor-add-pane.vala
+++ b/src/client/accounts/accounts-editor-add-pane.vala
@@ -298,6 +298,10 @@ internal class Accounts.EditorAddPane : Gtk.Grid, EditorPane {
             service.host = address.hostname;
             service.port = (uint16) address.port;
             service.transport_security = this.imap_tls.value.method;
+
+            if (service.port == 0) {
+                service.port = service.get_default_port();
+            }
         } else {
             this.provider.setup_service(service);
             service.credentials = new Geary.Credentials(
@@ -346,6 +350,10 @@ internal class Accounts.EditorAddPane : Gtk.Grid, EditorPane {
             service.port = (uint16) address.port;
             service.transport_security = this.smtp_tls.value.method;
 
+            if (service.port == 0) {
+                service.port = service.get_default_port();
+            }
+
             debug("SMTP service: TLS: %s, STARTTLS: %s",
                   service.use_ssl.to_string(), service.use_starttls.to_string());
         } else {
diff --git a/src/engine/api/geary-engine.vala b/src/engine/api/geary-engine.vala
index e540c12c..9164ce35 100644
--- a/src/engine/api/geary-engine.vala
+++ b/src/engine/api/geary-engine.vala
@@ -235,13 +235,6 @@ public class Geary.Engine : BaseObject {
                                     GLib.Cancellable? cancellable = null)
         throws GLib.Error {
         check_opened();
-
-        if (service.port == 0) {
-            service.port = service.use_ssl
-                ? Imap.IMAP_TLS_PORT
-                : Imap.IMAP_PORT;
-        }
-
         Endpoint endpoint = get_shared_endpoint(
             account.service_provider, service
         );
@@ -307,17 +300,6 @@ public class Geary.Engine : BaseObject {
                                     GLib.Cancellable? cancellable = null)
         throws GLib.Error {
         check_opened();
-
-        if (service.port == 0) {
-            if (service.use_ssl) {
-                service.port = Smtp.SUBMISSION_TLS_PORT;
-            } else if (service.smtp_noauth) {
-                service.port = Smtp.SMTP_PORT;
-            } else {
-                service.port = Smtp.SUBMISSION_PORT;
-            }
-        }
-
         Endpoint endpoint = get_shared_endpoint(
             account.service_provider, service
         );
diff --git a/src/engine/api/geary-service-information.vala b/src/engine/api/geary-service-information.vala
index 4f3eb8bc..592f4734 100644
--- a/src/engine/api/geary-service-information.vala
+++ b/src/engine/api/geary-service-information.vala
@@ -235,6 +235,33 @@ public abstract class Geary.ServiceInformation : GLib.Object {
 
     public abstract ServiceInformation temp_copy();
 
+    /**
+     * Returns the default port for this service type and settings.
+     */
+    public uint16 get_default_port() {
+        uint16 port = 0;
+
+        switch (this.protocol) {
+        case IMAP:
+            port = this.use_ssl
+                ? Imap.IMAP_TLS_PORT
+                : Imap.IMAP_PORT;
+            break;
+
+        case SMTP:
+            if (this.use_ssl) {
+                port = Smtp.SUBMISSION_TLS_PORT;
+            } else if (this.smtp_noauth) {
+                port = Smtp.SMTP_PORT;
+            } else {
+                port = Smtp.SUBMISSION_PORT;
+            }
+            break;
+        }
+
+        return port;
+    }
+
     public void copy_from(Geary.ServiceInformation from) {
         this.host = from.host;
         this.port = from.port;


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]