2012-08-19 21:37:54 -04:00
|
|
|
// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
|
|
|
|
|
|
|
|
const Gio = imports.gi.Gio;
|
|
|
|
const Shell = imports.gi.Shell;
|
|
|
|
const Signals = imports.signals;
|
|
|
|
|
2018-09-05 20:55:20 -04:00
|
|
|
const { loadInterfaceXML } = imports.misc.fileUtils;
|
|
|
|
|
|
|
|
const ProviderIface = loadInterfaceXML("org.freedesktop.realmd.Provider");
|
2012-08-19 21:37:54 -04:00
|
|
|
const Provider = Gio.DBusProxy.makeProxyWrapper(ProviderIface);
|
|
|
|
|
2018-09-05 20:55:20 -04:00
|
|
|
const ServiceIface = loadInterfaceXML("org.freedesktop.realmd.Service");
|
2012-08-19 21:37:54 -04:00
|
|
|
const Service = Gio.DBusProxy.makeProxyWrapper(ServiceIface);
|
|
|
|
|
2018-09-05 20:55:20 -04:00
|
|
|
const RealmIface = loadInterfaceXML("org.freedesktop.realmd.Realm");
|
2012-08-19 21:37:54 -04:00
|
|
|
const Realm = Gio.DBusProxy.makeProxyWrapper(RealmIface);
|
|
|
|
|
2017-10-30 21:19:44 -04:00
|
|
|
var Manager = class {
|
|
|
|
constructor(parentActor) {
|
2012-08-19 21:37:54 -04:00
|
|
|
this._aggregateProvider = Provider(Gio.DBus.system,
|
|
|
|
'org.freedesktop.realmd',
|
|
|
|
'/org/freedesktop/realmd',
|
2017-12-01 19:27:35 -05:00
|
|
|
this._reloadRealms.bind(this))
|
2012-08-19 21:37:54 -04:00
|
|
|
this._realms = {};
|
|
|
|
|
2013-04-19 03:07:04 -04:00
|
|
|
this._signalId = this._aggregateProvider.connect('g-properties-changed',
|
2017-10-30 20:38:18 -04:00
|
|
|
(proxy, properties) => {
|
|
|
|
if ('Realms' in properties.deep_unpack())
|
|
|
|
this._reloadRealms();
|
|
|
|
});
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2012-08-19 21:37:54 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_reloadRealms() {
|
2012-08-19 21:37:54 -04:00
|
|
|
let realmPaths = this._aggregateProvider.Realms;
|
|
|
|
|
|
|
|
if (!realmPaths)
|
|
|
|
return;
|
|
|
|
|
|
|
|
for (let i = 0; i < realmPaths.length; i++) {
|
|
|
|
let realm = Realm(Gio.DBus.system,
|
|
|
|
'org.freedesktop.realmd',
|
|
|
|
realmPaths[i],
|
2017-12-01 19:27:35 -05:00
|
|
|
this._onRealmLoaded.bind(this));
|
2012-08-19 21:37:54 -04:00
|
|
|
}
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2012-08-19 21:37:54 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_reloadRealm(realm) {
|
2012-08-19 21:37:54 -04:00
|
|
|
if (!realm.Configured) {
|
|
|
|
if (this._realms[realm.get_object_path()])
|
|
|
|
delete this._realms[realm.get_object_path()];
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
this._realms[realm.get_object_path()] = realm;
|
|
|
|
|
|
|
|
this._updateLoginFormat();
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2012-08-19 21:37:54 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_onRealmLoaded(realm, error) {
|
2012-08-19 21:37:54 -04:00
|
|
|
if (error)
|
|
|
|
return;
|
|
|
|
|
|
|
|
this._reloadRealm(realm);
|
|
|
|
|
2017-10-30 20:38:18 -04:00
|
|
|
realm.connect('g-properties-changed', (proxy, properties) => {
|
|
|
|
if ('Configured' in properties.deep_unpack())
|
|
|
|
this._reloadRealm(realm);
|
|
|
|
});
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2012-08-19 21:37:54 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_updateLoginFormat() {
|
2012-08-19 21:37:54 -04:00
|
|
|
let newLoginFormat;
|
|
|
|
|
|
|
|
for (let realmPath in this._realms) {
|
|
|
|
let realm = this._realms[realmPath];
|
|
|
|
if (realm.LoginFormats && realm.LoginFormats.length > 0) {
|
|
|
|
newLoginFormat = realm.LoginFormats[0];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this._loginFormat != newLoginFormat) {
|
|
|
|
this._loginFormat = newLoginFormat;
|
|
|
|
this.emit('login-format-changed', newLoginFormat);
|
|
|
|
}
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2012-08-19 21:37:54 -04:00
|
|
|
|
|
|
|
get loginFormat() {
|
|
|
|
if (this._loginFormat !== undefined)
|
|
|
|
return this._loginFormat;
|
|
|
|
|
|
|
|
this._updateLoginFormat();
|
|
|
|
|
|
|
|
return this._loginFormat;
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2013-04-19 03:07:04 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
release() {
|
2013-04-19 03:07:04 -04:00
|
|
|
Service(Gio.DBus.system,
|
|
|
|
'org.freedesktop.realmd',
|
|
|
|
'/org/freedesktop/realmd',
|
2017-10-30 20:38:18 -04:00
|
|
|
service => { service.ReleaseRemote(); });
|
2013-04-19 03:07:04 -04:00
|
|
|
this._aggregateProvider.disconnect(this._signalId);
|
|
|
|
this._realms = { };
|
|
|
|
this._updateLoginFormat();
|
2012-08-19 21:37:54 -04:00
|
|
|
}
|
2017-10-30 21:19:44 -04:00
|
|
|
};
|
2012-08-19 21:37:54 -04:00
|
|
|
Signals.addSignalMethods(Manager.prototype)
|