Commit 21bee722 authored by Florian Müllner's avatar Florian Müllner Committed by Bastian Ilsø Hougaard

Use PolariAccount:visible instead of :enabled

Return to showing disabled accounts in the UI by switching to the
:visible property to control an account's visibility. In a next
step, we will also expose enable and disable in the UI again.

https://bugzilla.gnome.org/show_bug.cgi?id=771889
parent 243868f2
......@@ -35,8 +35,8 @@ var AccountsMonitor = class {
return [...this._accounts.values()];
}
get enabledAccounts() {
return [...this._accounts.values()].filter(a => a.enabled);
get visibleAccounts() {
return [...this._accounts.values()].filter(a => a.visible);
}
get accountManager() {
......@@ -121,6 +121,12 @@ var AccountsMonitor = class {
account.connect('notify::connection-status', () => {
this.emit('account-status-changed', account);
});
account._visibleNotifyId =
account.connect('notify::visible', () => {
this.emit(account.visible ? 'account-shown'
: 'account-hidden', account);
this.emit('accounts-changed');
});
this._accounts.set(account.object_path, account);
this.emit('account-added', account);
......@@ -134,6 +140,9 @@ var AccountsMonitor = class {
account.disconnect(account._statusNotifyId);
delete account._statusNotifyId;
account.disconnect(account._visibleNotifyId);
delete account._visibleNotifyId;
this.emit('account-removed', account);
this.emit('accounts-changed');
}
......
......@@ -345,7 +345,7 @@ var Application = GObject.registerClass({
_openURIs(uris, time) {
let map = {};
this._accountsMonitor.enabledAccounts.forEach(a => {
this._accountsMonitor.visibleAccounts.forEach(a => {
let params = a.dup_parameters_vardict().deep_unpack();
map[a.get_object_path()] = {
server: params.server.deep_unpack(),
......@@ -658,10 +658,14 @@ var Application = GObject.registerClass({
action.change_state(GLib.Variant.new('b', !state.get_boolean()));
}
_onRemoveConnection(action, parameter){
_onRemoveConnection(action, parameter) {
let accountPath = parameter.deep_unpack();
let account = this._accountsMonitor.lookupAccount(accountPath);
account.set_enabled_async(false, () => {
account.set_enabled_async(false, (o, res) => {
account.set_enabled_finish(res);
account.visible = false;
let label = _("%s removed.").format(account.display_name);
let n = new AppNotifications.UndoNotification(label);
this.notificationQueue.addNotification(n);
......@@ -672,8 +676,9 @@ var Application = GObject.registerClass({
});
});
n.connect('undo', () => {
account.set_enabled_async(true, (a, res) => {
a.set_enabled_finish(res); // TODO: Check for errors
account.set_enabled_async(true, (o, res) => {
account.set_enabled_finish(res);
account.visible = true;
});
});
});
......
......@@ -53,7 +53,7 @@ var JoinDialog = GObject.registerClass({
this._accountsMonitor = AccountsMonitor.getDefault();
this._accounts = new Map();
this._accountsMonitor.enabledAccounts.forEach(a => {
this._accountsMonitor.visibleAccounts.forEach(a => {
this._accounts.set(a.display_name, a);
});
this._accountAddedId =
......
......@@ -273,7 +273,7 @@ var MainWindow = GObject.registerClass({
}
_onAccountsChanged(am) {
let hasAccounts = this._accountsMonitor.enabledAccounts.length > 0;
let hasAccounts = this._accountsMonitor.visibleAccounts.length > 0;
this._roomListRevealer.reveal_child = hasAccounts;
}
......@@ -351,7 +351,7 @@ var MainWindow = GObject.registerClass({
let roomId = null;
let account = this._accountsMonitor.lookupAccount(selectedRoom.account);
let channelName = selectedRoom.channel;
if (account && account.enabled && channelName)
if (account && account.visible && channelName)
roomId = Polari.create_room_id(account, channelName, Tp.HandleType.ROOM);
this.active_room = this._roomManager.lookupRoom(roomId) ||
......
......@@ -436,10 +436,10 @@ class RoomList extends Gtk.ListBox {
this._accountAdded.bind(this));
this._accountsMonitor.connect('account-removed',
this._accountRemoved.bind(this));
this._accountsMonitor.connect('account-enabled', (mon, account) => {
this._accountsMonitor.connect('account-shown', (mon, account) => {
this._updatePlaceholderVisibility(account);
});
this._accountsMonitor.connect('account-disabled', (mon, account) => {
this._accountsMonitor.connect('account-hidden', (mon, account) => {
this._updatePlaceholderVisibility(account);
});
this._accountsMonitor.prepare(() => {
......@@ -620,7 +620,7 @@ class RoomList extends Gtk.ListBox {
}
_updatePlaceholderVisibility(account) {
if (!account.enabled) {
if (!account.visible) {
this._placeholders.get(account).hide();
return;
}
......
......@@ -36,10 +36,10 @@ var RoomManager = class {
this._app.lookup_action(a.name).connect('activate', a.handler);
});
this._accountsMonitor.connect('account-enabled', (mon, account) => {
this._accountsMonitor.connect('account-shown', (mon, account) => {
this._restoreRooms(account.object_path);
});
this._accountsMonitor.connect('account-disabled', (mon, account) => {
this._accountsMonitor.connect('account-hidden', (mon, account) => {
this._removeRooms(account.object_path);
});
this._accountsMonitor.connect('account-removed', (mon, account) => {
......@@ -164,7 +164,7 @@ var RoomManager = class {
return null;
}
if (!account.enabled)
if (!account.visible)
return null;
let id = Polari.create_room_id(account, channelName, type);
......
......@@ -29,7 +29,7 @@ var ServerRoomManager = class {
this._accountsMonitor.connect('account-removed',
this._onAccountRemoved.bind(this));
this._accountsMonitor.prepare(() => {
this._accountsMonitor.enabledAccounts.forEach(a => {
this._accountsMonitor.visibleAccounts.forEach(a => {
this._onAccountStatusChanged(this._accountsMonitor, a);
});
});
......
......@@ -184,10 +184,10 @@ class TelepathyClient extends Tp.BaseClient {
this._accountsMonitor.connect('account-added', (mon, account) => {
this._connectAccount(account);
});
this._accountsMonitor.connect('account-enabled', (mon, account) => {
this._accountsMonitor.connect('account-shown', (mon, account) => {
this._connectAccount(account);
});
this._accountsMonitor.enabledAccounts.forEach(a => {
this._accountsMonitor.visibleAccounts.forEach(a => {
this._onAccountStatusChanged(this._accountsMonitor, a);
});
......@@ -203,7 +203,7 @@ class TelepathyClient extends Tp.BaseClient {
debug('Network changed to %s'.format(connected ? 'available'
: 'unavailable'));
this._accountsMonitor.enabledAccounts.forEach(a => {
this._accountsMonitor.visibleAccounts.forEach(a => {
this._setAccountPresence(a, presence);
});
}
......@@ -225,6 +225,9 @@ class TelepathyClient extends Tp.BaseClient {
}
_setAccountPresence(account, presence) {
if (!account.enabled)
return;
let statuses = Object.keys(Tp.ConnectionPresenceType).map(s =>
s.replace(/_/g, '-').toLowerCase()
);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment