[polari/join-dialog-refresh: 1/8] joinDialog: Update combobox on account changes
- From: Florian Müllner <fmuellner src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [polari/join-dialog-refresh: 1/8] joinDialog: Update combobox on account changes
- Date: Thu, 21 Nov 2013 15:01:57 +0000 (UTC)
commit 3a27b76f6f1ca767ca07512e9567ac57edd44b47
Author: Florian Müllner <fmuellner gnome org>
Date: Thu Nov 21 01:26:24 2013 +0100
joinDialog: Update combobox on account changes
Currently the connection combobox shows the list of accounts that
were available when creating the join dialog. However we will soon
allow to add new connections from within the dialog itself, so we
need to track changes in the list of available accounts to pick up
the additions.
src/joinDialog.js | 49 +++++++++++++++++++++++++++++++++++++++----------
1 files changed, 39 insertions(+), 10 deletions(-)
---
diff --git a/src/joinDialog.js b/src/joinDialog.js
index 61a5b56..742f0b0 100644
--- a/src/joinDialog.js
+++ b/src/joinDialog.js
@@ -14,22 +14,35 @@ const JoinDialog = new Lang.Class({
_init: function() {
this._createWidget();
+ this._accountsMonitor = AccountsMonitor.getDefault();
+
this._accounts = {};
- AccountsMonitor.getDefault().dupAccounts().forEach(Lang.bind(this,
+ this._accountsMonitor.dupAccounts().forEach(Lang.bind(this,
function(a) {
if (!a.enabled)
return;
this._accounts[a.display_name] = a;
}));
- let names = Object.keys(this._accounts).sort(
- function(a, b) {
- // TODO: figure out combo box sorting
- return (a < b) ? -1 : ((a > b) ? 1 : 0);
- });
- for (let i = 0; i < names.length; i++)
- this._connectionCombo.append_text(names[i]);
- this._connectionCombo.set_active(0);
- this._connectionCombo.sensitive = names.length > 1;
+ this._accountAddedId =
+ this._accountsMonitor.connect('account-added', Lang.bind(this,
+ function(am, account) {
+ this._accounts[account.display_name] = account;
+ this._updateConnectionCombo();
+ }));
+ this._accountRemovedId =
+ this._accountsMonitor.connect('account-removed', Lang.bind(this,
+ function(am, account) {
+ delete this._accounts[account.display_name];
+ this._updateConnectionCombo();
+ }));
+
+ this.widget.connect('destroy', Lang.bind(this,
+ function() {
+ this._accountsMonitor.disconnect(this._accountAddedId);
+ this._accountsMonitor.disconnect(this._accountRemovedId);
+ }));
+
+ this._updateConnectionCombo();
this._updateCanConfirm();
},
@@ -61,6 +74,8 @@ const JoinDialog = new Lang.Class({
let selected = this._connectionCombo.get_active_text();
let account = this._accounts[selected];
+ if (!account)
+ return;
let logManager = Tpl.LogManager.dup_singleton();
logManager.get_entities_async(account, Lang.bind(this,
@@ -103,6 +118,20 @@ const JoinDialog = new Lang.Class({
this.widget.response(Gtk.ResponseType.OK);
},
+ _updateConnectionCombo: function() {
+ this._connectionCombo.remove_all();
+
+ let names = Object.keys(this._accounts).sort(
+ function(a, b) {
+ // TODO: figure out combo box sorting
+ return (a < b) ? -1 : ((a > b) ? 1 : 0);
+ });
+ for (let i = 0; i < names.length; i++)
+ this._connectionCombo.append_text(names[i]);
+ this._connectionCombo.sensitive = names.length > 1;
+ this._connectionCombo.set_active(0);
+ },
+
_updateCanConfirm: function() {
let sensitive = this._connectionCombo.get_active() > -1 &&
this._nameEntry.get_text_length() > 0;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]