[polari] connections: Factor out getAccountParams() method



commit 1a23da2aa3f346354b53cc862d411995af05ec5d
Author: Florian Müllner <fmuellner gnome org>
Date:   Fri Sep 9 02:50:12 2016 +0200

    connections: Factor out getAccountParams() method
    
    There are cases where we don't just want to retrieve and unpack
    account parameters, but also make sure that appropriate fallbacks
    for missing values are in place; split out an appropriate help
    function for that.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=771217

 src/connections.js |   19 ++++++++++++++-----
 1 files changed, 14 insertions(+), 5 deletions(-)
---
diff --git a/src/connections.js b/src/connections.js
index 666554b..395fa7d 100644
--- a/src/connections.js
+++ b/src/connections.js
@@ -17,6 +17,17 @@ const ErrorHint = {
     NICK: 2
 };
 
+function getAccountParams(account) {
+    let params = account.dup_parameters_vardict().deep_unpack();
+    for (let p in params)
+        params[p] = params[p].deep_unpack();
+
+    params['use-ssl'] = !!params['use-ssl'];
+    params['port'] = params['port'] || params['use-ssl'] ? DEFAULT_SSL_PORT
+                                                         : DEFAULT_PORT;
+    return params;
+};
+
 const ConnectionRow = new Lang.Class({
     Name: 'ConnectionRow',
     Extends: Gtk.ListBoxRow,
@@ -299,14 +310,12 @@ const ConnectionDetails = new Lang.Class({
     },
 
     _populateFromAccount: function(account) {
-        let params = account.dup_parameters_vardict().deep_unpack();
-        for (let p in params)
-            params[p] = params[p].deep_unpack();
+        let params = getAccountParams(account);
 
-        this._savedSSL = params['use-ssl'] || false;
+        this._savedSSL = params['use-ssl'];
         let defaultPort = this._savedSSL ? DEFAULT_SSL_PORT : DEFAULT_PORT;
         this._savedServer = params.server || '';
-        let port = params.port || defaultPort;
+        let port = params.port;
         this._savedNick = params.account || '';
         this._savedRealname = params.fullname || '';
 


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