[polari/wip/fmuellner/connection-list: 15/22] connections: Set ConnectionDetails account after creation



commit 6149d53a3f4fcdb1ae5ba7f419753acb21b7809b
Author: Florian Müllner <fmuellner gnome org>
Date:   Wed Feb 3 23:10:27 2016 +0100

    connections: Set ConnectionDetails account after creation
    
    Not having to pass the account at construction time makes it possible to
    use ConnectionDetails directly in .ui files.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=761859

 src/connections.js |   35 +++++++++++++++++++++--------------
 1 files changed, 21 insertions(+), 14 deletions(-)
---
diff --git a/src/connections.js b/src/connections.js
index 160a931..7e574d5 100644
--- a/src/connections.js
+++ b/src/connections.js
@@ -25,11 +25,6 @@ const ConnectionDetails = new Lang.Class({
     Signals: { 'account-created': { param_types: [Tp.Account.$gtype] }},
 
     _init: function(params) {
-        if (params) {
-            this._account = params.account;
-            delete params.account;
-        }
-
         this.parent(params);
 
         this._nameEntry.connect('changed',
@@ -52,14 +47,6 @@ const ConnectionDetails = new Lang.Class({
         this._realnameEntry.set_completion(completion);
 
         this.reset();
-
-        if (!this._account)
-            return;
-
-        this._populateFromAccount(this._account);
-
-        this._account.connect('notify::connection-status', Lang.bind(this, this._syncErrorMessage));
-        this._syncErrorMessage();
     },
 
     _syncErrorMessage: function() {
@@ -152,6 +139,25 @@ const ConnectionDetails = new Lang.Class({
                paramsChanged;
     },
 
+    set account(account) {
+        if (this._connectionStatusChangedId)
+            this._account.disconnect(this._connectionStatusChangedId);
+        this._connectionStatusChangedId = 0;
+
+        this._account = account;
+
+        this.reset();
+
+        if (this._account) {
+            this._populateFromAccount(this._account);
+
+            this._connectionStatusChangedId =
+                this._account.connect('notify::connection-status',
+                                      Lang.bind(this, this._syncErrorMessage));
+            this._syncErrorMessage();
+        }
+    },
+
     save: function() {
         if (!this.can_confirm)
             return;
@@ -247,7 +253,8 @@ const ConnectionProperties = new Lang.Class({
         this._confirmButton = this.add_button(_("A_pply"), Gtk.ResponseType.OK);
         this._confirmButton.get_style_context().add_class('suggested-action');
 
-        this._details = new ConnectionDetails({ account: account });
+        this._details = new ConnectionDetails();
+        this._details.account = account;
         this._details.bind_property('can-confirm',
                                     this._confirmButton, 'sensitive',
                                     GObject.BindingFlags.SYNC_CREATE);


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