[polari] Add AccountsMonitor
- From: Florian Müllner <fmuellner src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [polari] Add AccountsMonitor
- Date: Thu, 8 Aug 2013 13:09:22 +0000 (UTC)
commit b6cd11af43084ec75c0514921de9d8ba5c649ad2
Author: Florian Müllner <fmuellner gnome org>
Date: Thu Jul 25 00:48:15 2013 +0200
Add AccountsMonitor
src/Makefile.am | 1 +
src/accountsMonitor.js | 83 ++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 84 insertions(+), 0 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index ff8e0a3..2fce7de 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -27,6 +27,7 @@ polari: polari.in
jsdir = $(pkgdatadir)/js/
dist_js_DATA = \
+ accountsMonitor.js \
application.js \
appNotifications.js \
chatroomManager.js \
diff --git a/src/accountsMonitor.js b/src/accountsMonitor.js
new file mode 100644
index 0000000..e81b5ab
--- /dev/null
+++ b/src/accountsMonitor.js
@@ -0,0 +1,83 @@
+const Tp = imports.gi.TelepathyGLib;
+
+const Lang = imports.lang;
+const Signals = imports.signals;
+
+let _singleton = null;
+
+function getDefault() {
+ if (_singleton == null)
+ _singleton = new AccountsMonitor();
+ return _singleton;
+}
+
+const AccountsMonitor = new Lang.Class({
+ Name: 'AccountsMonitor',
+
+ _init: function() {
+ this._accounts = [];
+
+ this._accountManager = Tp.AccountManager.dup();
+ this._accountManager.prepare_async(null,
+ Lang.bind(this, this._onPrepared));
+ },
+
+ dupAccounts: function() {
+ return this._accounts.slice();
+ },
+
+ _onPrepared: function(am, res) {
+ am.prepare_finish(res);
+
+ am.dup_valid_accounts().forEach(Lang.bind(this, this._addAccount));
+
+ am.connect('account-validity-changed', Lang.bind(this,
+ function(am, account, valid) {
+ if (valid)
+ this._addAccount(account);
+ else
+ this._removeAccount(account);
+ }));
+ am.connect('account-removed', Lang.bind(this,
+ function(am, account) {
+ this._removeAccount(account);
+ }));
+ am.connect('account-enabled',
+ Lang.bind(this, this._accountEnabledChanged));
+ am.connect('account-disabled',
+ Lang.bind(this, this._accountEnabledChanged));
+ },
+
+ _shouldMonitorAccount: function(account) {
+ return account.protocol_name == 'irc';
+ },
+
+ _addAccount: function(account) {
+ if (!this._shouldMonitorAccount(account))
+ return;
+
+ this._accounts.push(account);
+
+ this.emit('account-added', account);
+ this.emit('accounts-changed');
+ },
+
+ _removeAccount: function(account) {
+ let index = this._accounts.indexOf(account);
+
+ if (index == -1)
+ return;
+
+ this._accounts.splice(index, 1);
+
+ this.emit('account-removed', account);
+ this.emit('accounts-changed');
+ },
+
+ _accountEnabledChanged: function(am, account) {
+ if (this._accounts.indexOf(account) == -1)
+ return;
+ this.emit('accounts-changed');
+ }
+});
+Signals.addSignalMethods(AccountsMonitor.prototype);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]