screensaver, gnomesession: port to GDBus based bindings

Port org.gnome.ScreenSaver and org.gnome.SessionManager glue code
to use GDBus, and move /org/gnome/Shell/EndSessionDialog to the
GDBus connection, so it is backed by the org.gnome.Shell name.

https://bugzilla.gnome.org/show_bug.cgi?id=648651
This commit is contained in:
Giovanni Campagna 2011-08-16 14:24:39 +02:00 committed by Colin Walters
parent 5350302b09
commit adc187c32e
7 changed files with 145 additions and 211 deletions

View File

@ -1,20 +1,18 @@
// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*- // -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
const DBus = imports.dbus; const Gio = imports.gi.Gio;
const Lang = imports.lang; const Lang = imports.lang;
const Signals = imports.signals; const Signals = imports.signals;
const PresenceIface = { const PresenceIface = <interface name="org.gnome.SessionManager.Presence">
name: 'org.gnome.SessionManager.Presence', <method name="SetStatus">
methods: [{ name: 'SetStatus', <arg type="u" direction="in"/>
inSignature: 'u', </method>
outSignature: '' }], <property name="status" type="u" access="readwrite"/>
properties: [{ name: 'status', <signal name="StatusChanged">
signature: 'u', <arg type="u" direction="out"/>
access: 'readwrite' }], </signal>
signals: [{ name: 'StatusChanged', </interface>;
inSignature: 'u' }]
};
const PresenceStatus = { const PresenceStatus = {
AVAILABLE: 0, AVAILABLE: 0,
@ -23,104 +21,41 @@ const PresenceStatus = {
IDLE: 3 IDLE: 3
}; };
function Presence() { var PresenceProxy = Gio.DBusProxy.makeProxyWrapper(PresenceIface);
this._init(); function Presence(initCallback, cancellable) {
return new PresenceProxy(Gio.DBus.session, 'org.gnome.SessionManager',
'/org/gnome/SessionManager/Presence', initCallback, cancellable);
} }
Presence.prototype = {
_init: function() {
DBus.session.proxifyObject(this, 'org.gnome.SessionManager', '/org/gnome/SessionManager/Presence', this);
},
getStatus: function(callback) {
this.GetRemote('status', Lang.bind(this,
function(status, ex) {
if (!ex)
callback(this, status);
}));
},
setStatus: function(status) {
this.SetStatusRemote(status);
}
};
DBus.proxifyPrototype(Presence.prototype, PresenceIface);
// Note inhibitors are immutable objects, so they don't // Note inhibitors are immutable objects, so they don't
// change at runtime (changes always come in the form // change at runtime (changes always come in the form
// of new inhibitors) // of new inhibitors)
const InhibitorIface = { const InhibitorIface = <interface name="org.gnome.SessionManager.Inhibitor">
name: 'org.gnome.SessionManager.Inhibitor', <property name="app_id" type="s" access="read" />
properties: [{ name: 'app_id', <property name="client_id" type="s" access="read" />
signature: 's', <property name="reason" type="s" access="read" />
access: 'readonly' }, <property name="flags" type="u" access="read" />
{ name: 'client_id', <property name="toplevel_xid" type="u" access="read" />
signature: 's', <property name="cookie" type="u" access="read" />
access: 'readonly' }, </interface>;
{ name: 'reason',
signature: 's',
access: 'readonly' },
{ name: 'flags',
signature: 'u',
access: 'readonly' },
{ name: 'toplevel_xid',
signature: 'u',
access: 'readonly' },
{ name: 'cookie',
signature: 'u',
access: 'readonly' }],
};
function Inhibitor(objectPath) { var InhibitorProxy = Gio.DBusProxy.makeProxyWrapper(InhibitorIface);
this._init(objectPath); function Inhibitor(objectPath, initCallback, cancellable) {
return new InhibitorProxy(Gio.DBus.session, 'org.gnome.SessionManager', objectPath, initCallback, cancellable);
} }
Inhibitor.prototype = {
_init: function(objectPath) {
DBus.session.proxifyObject(this,
'org.gnome.SessionManager',
objectPath);
this.isLoaded = false;
this._loadingPropertiesCount = InhibitorIface.properties.length;
for (let i = 0; i < InhibitorIface.properties.length; i++) {
let propertyName = InhibitorIface.properties[i].name;
this.GetRemote(propertyName, Lang.bind(this,
function(value, exception) {
if (exception)
return;
this[propertyName] = value;
this._loadingPropertiesCount--;
if (this._loadingPropertiesCount == 0) {
this.isLoaded = true;
this.emit('is-loaded');
}
}));
}
},
};
DBus.proxifyPrototype(Inhibitor.prototype, InhibitorIface);
Signals.addSignalMethods(Inhibitor.prototype);
// Not the full interface, only the methods we use // Not the full interface, only the methods we use
const SessionManagerIface = { const SessionManagerIface = <interface name="org.gnome.SessionManager">
name: 'org.gnome.SessionManager', <method name="Logout">
methods: [ <arg type="u" direction="in" />
{ name: 'Logout', inSignature: 'u', outSignature: '' }, </method>
{ name: 'Shutdown', inSignature: '', outSignature: '' }, <method name="Shutdown" />
{ name: 'CanShutdown', inSignature: '', outSignature: 'b' } <method name="CanShutdown">
] <arg type="b" direction="out" />
}; </method>
</interface>;
function SessionManager() { var SessionManagerProxy = Gio.DBusProxy.makeProxyWrapper(SessionManagerIface);
this._init(); function SessionManager(initCallback, cancellable) {
return new SessionManagerProxy(Gio.DBus.session, 'org.gnome.SessionManager', '/org/gnome/SessionManager', initCallback, cancellable);
} }
SessionManager.prototype = {
_init: function() {
DBus.session.proxifyObject(this, 'org.gnome.SessionManager', '/org/gnome/SessionManager');
}
};
DBus.proxifyPrototype(SessionManager.prototype, SessionManagerIface);

View File

@ -1,53 +1,48 @@
// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*- // -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
const DBus = imports.dbus; const Gio = imports.gi.Gio;
const Lang = imports.lang; const Lang = imports.lang;
const ScreenSaverIface = { const ScreenSaverIface = <interface name="org.gnome.ScreenSaver">
name: 'org.gnome.ScreenSaver', <method name="GetActive">
methods: [{ name: 'GetActive', <arg type="b" direction="out" />
inSignature: '', </method>
outSignature: 'b' }, <method name="Lock" />
{ name: 'Lock', <method name="SetActive">
inSignature: '' }, <arg type="b" direction="in" />
{ name: 'SetActive', </method>
inSignature: 'b' }], <signal name="ActiveChanged">
signals: [{ name: 'ActiveChanged', <arg type="b" direction="out" />
inSignature: 'b' }] </signal>
}; </interface>;
const ScreenSaverInfo = Gio.DBusInterfaceInfo.new_for_xml(ScreenSaverIface);
function ScreenSaverProxy() { function ScreenSaverProxy() {
this._init(); var self = new Gio.DBusProxy({ g_connection: Gio.DBus.session,
g_interface_name: ScreenSaverInfo.name,
g_interface_info: ScreenSaverInfo,
g_name: 'org.gnome.ScreenSaver',
g_object_path: '/org/gnome/ScreenSaver',
g_flags: (Gio.DBusProxyFlags.DO_NOT_AUTO_START |
Gio.DBusProxyFlags.DO_NOT_LOAD_PROPERTIES) });
self.init(null);
self.screenSaverActive = false;
self.connectSignal('ActiveChanged', function(proxy, senderName, [isActive]) {
self.screenSaverActive = isActive;
});
self.connect('notify::g-name-owner', function() {
if (self.g_name_owner) {
self.GetActiveRemote(function(result, excp) {
if (result) {
let [isActive] = result;
self.screenSaverActive = isActive;
}
});
} else
self.screenSaverActive = false;
});
return self;
} }
ScreenSaverProxy.prototype = {
_init: function() {
DBus.session.proxifyObject(this,
'org.gnome.ScreenSaver',
'/org/gnome/ScreenSaver');
DBus.session.watch_name('org.gnome.ScreenSaver',
false, // do not launch a name-owner if none exists
Lang.bind(this, this._onSSAppeared),
Lang.bind(this, this._onSSVanished));
this.screenSaverActive = false;
this.connect('ActiveChanged',
Lang.bind(this, this._onActiveChanged));
},
_onSSAppeared: function(owner) {
this.GetActiveRemote(Lang.bind(this, function(isActive) {
this.screenSaverActive = isActive;
}))
},
_onSSVanished: function(oldOwner) {
this.screenSaverActive = false;
},
_onActiveChanged: function(object, isActive) {
this.screenSaverActive = isActive;
}
};
DBus.proxifyPrototype(ScreenSaverProxy.prototype, ScreenSaverIface);

View File

@ -86,9 +86,8 @@ AutomountManager.prototype = {
this.ckListener = new ConsoleKitManager(); this.ckListener = new ConsoleKitManager();
this._ssProxy = new ScreenSaver.ScreenSaverProxy(); this._ssProxy = new ScreenSaver.ScreenSaverProxy();
this._ssProxy.connect('ActiveChanged', this._ssProxy.connectSignal('ActiveChanged',
Lang.bind(this, Lang.bind(this, this._screenSaverActiveChanged));
this._screenSaverActiveChanged));
this._volumeMonitor = Gio.VolumeMonitor.get(); this._volumeMonitor = Gio.VolumeMonitor.get();
@ -111,7 +110,7 @@ AutomountManager.prototype = {
Mainloop.idle_add(Lang.bind(this, this._startupMountAll)); Mainloop.idle_add(Lang.bind(this, this._startupMountAll));
}, },
_screenSaverActiveChanged: function(object, isActive) { _screenSaverActiveChanged: function(object, senderName, [isActive]) {
if (!isActive) { if (!isActive) {
this._volumeQueue.forEach(Lang.bind(this, function(volume) { this._volumeQueue.forEach(Lang.bind(this, function(volume) {
this._checkAndMountVolume(volume); this._checkAndMountVolume(volume);

View File

@ -18,19 +18,19 @@
* 02111-1307, USA. * 02111-1307, USA.
*/ */
const DBus = imports.dbus;
const Lang = imports.lang; const Lang = imports.lang;
const Signals = imports.signals; const Signals = imports.signals;
const AccountsService = imports.gi.AccountsService; const AccountsService = imports.gi.AccountsService;
const Clutter = imports.gi.Clutter; const Clutter = imports.gi.Clutter;
const Gio = imports.gi.Gio;
const GLib = imports.gi.GLib; const GLib = imports.gi.GLib;
const Gtk = imports.gi.Gtk; const Gtk = imports.gi.Gtk;
const Pango = imports.gi.Pango; const Pango = imports.gi.Pango;
const St = imports.gi.St; const St = imports.gi.St;
const Shell = imports.gi.Shell; const Shell = imports.gi.Shell;
const GnomeSession = imports.misc.gnomeSession const GnomeSession = imports.misc.gnomeSession;
const Lightbox = imports.ui.lightbox; const Lightbox = imports.ui.lightbox;
const Main = imports.ui.main; const Main = imports.ui.main;
const ModalDialog = imports.ui.modalDialog; const ModalDialog = imports.ui.modalDialog;
@ -43,18 +43,19 @@ const _DIALOG_ICON_SIZE = 32;
const GSM_SESSION_MANAGER_LOGOUT_FORCE = 2; const GSM_SESSION_MANAGER_LOGOUT_FORCE = 2;
const EndSessionDialogIface = { const EndSessionDialogIface = <interface name="org.gnome.SessionManager.EndSessionDialog">
name: 'org.gnome.SessionManager.EndSessionDialog', <method name="Open">
methods: [{ name: 'Open', <arg type="u" direction="in" />
inSignature: 'uuuao', <arg type="u" direction="in" />
outSignature: '' <arg type="u" direction="in" />
} <arg type="ao" direction="in" />
], </method>
signals: [{ name: 'Canceled', <signal name="ConfirmedLogout" />
inSignature: '', <signal name="ConfirmedReboot" />
}], <signal name="ConfirmedShutdown" />
properties: [] <signal name="Canceled" />
}; <signal name="Closed" />
</interface>;
const logoutDialogContent = { const logoutDialogContent = {
subjectWithUser: C_("title", "Log Out %s"), subjectWithUser: C_("title", "Log Out %s"),
@ -232,8 +233,6 @@ function _setLabelText(label, text) {
function EndSessionDialog() { function EndSessionDialog() {
if (_endSessionDialog == null) { if (_endSessionDialog == null) {
this._init(); this._init();
DBus.session.exportObject('/org/gnome/SessionManager/EndSessionDialog',
this);
_endSessionDialog = this; _endSessionDialog = this;
} }
@ -326,6 +325,9 @@ EndSessionDialog.prototype = {
if (this._applicationList.get_children().length == 0) if (this._applicationList.get_children().length == 0)
scrollView.hide(); scrollView.hide();
})); }));
this._dbusImpl = Gio.DBusExportedObject.wrapJSObject(EndSessionDialogIface, this);
this._dbusImpl.export(Gio.DBus.session, '/org/gnome/SessionManager/EndSessionDialog');
}, },
_onDestroy: function() { _onDestroy: function() {
@ -440,25 +442,19 @@ EndSessionDialog.prototype = {
close: function() { close: function() {
ModalDialog.ModalDialog.prototype.close.call(this); ModalDialog.ModalDialog.prototype.close.call(this);
DBus.session.emit_signal('/org/gnome/SessionManager/EndSessionDialog', this._dbusImpl.emit_signal('Closed', null);
'org.gnome.SessionManager.EndSessionDialog',
'Closed', '', []);
}, },
cancel: function() { cancel: function() {
this._stopTimer(); this._stopTimer();
DBus.session.emit_signal('/org/gnome/SessionManager/EndSessionDialog', this._dbusImpl.emit_signal('Canceled', null);
'org.gnome.SessionManager.EndSessionDialog',
'Canceled', '', []);
this.close(global.get_current_time()); this.close(global.get_current_time());
}, },
_confirm: function(signal) { _confirm: function(signal) {
this._fadeOutDialog(); this._fadeOutDialog();
this._stopTimer(); this._stopTimer();
DBus.session.emit_signal('/org/gnome/SessionManager/EndSessionDialog', this._dbusImpl.emit_signal(signal, null);
'org.gnome.SessionManager.EndSessionDialog',
signal, '', []);
}, },
_onOpened: function() { _onOpened: function() {
@ -510,39 +506,41 @@ EndSessionDialog.prototype = {
this._updateContent(); this._updateContent();
}, },
OpenAsync: function(type, timestamp, totalSecondsToStayOpen, inhibitorObjectPaths, callback) { OpenAsync: function(parameters, invocation) {
let [type, timestamp, totalSecondsToStayOpen, inhibitorObjectPaths] = parameters;
this._totalSecondsToStayOpen = totalSecondsToStayOpen; this._totalSecondsToStayOpen = totalSecondsToStayOpen;
this._inhibitors = []; this._inhibitors = [];
this._applicationList.destroy_children(); this._applicationList.destroy_children();
this._type = type; this._type = type;
if (!(this._type in DialogContent)) if (!(this._type in DialogContent)) {
throw new DBus.DBusError('org.gnome.Shell.ModalDialog.TypeError', invocation.report_dbus_error('org.gnome.Shell.ModalDialog.TypeError',
"Unknown dialog type requested"); "Unknown dialog type requested");
return;
}
for (let i = 0; i < inhibitorObjectPaths.length; i++) { for (let i = 0; i < inhibitorObjectPaths.length; i++) {
let inhibitor = new GnomeSession.Inhibitor(inhibitorObjectPaths[i]); let inhibitor = new GnomeSession.Inhibitor(inhibitorObjectPaths[i], Lang.bind(this, function(proxy, error) {
this._onInhibitorLoaded(proxy);
}));
inhibitor.connect('is-loaded',
Lang.bind(this, function() {
this._onInhibitorLoaded(inhibitor);
}));
this._inhibitors.push(inhibitor); this._inhibitors.push(inhibitor);
} }
this._updateButtons(); this._updateButtons();
if (!this.open(timestamp)) if (!this.open(timestamp)) {
throw new DBus.DBusError('org.gnome.Shell.ModalDialog.GrabError', invocation.report_dbus_error('org.gnome.Shell.ModalDialog.GrabError',
"Cannot grab pointer and keyboard"); "Cannot grab pointer and keyboard");
return;
}
this._updateContent(); this._updateContent();
let signalId = this.connect('opened', let signalId = this.connect('opened',
Lang.bind(this, function() { Lang.bind(this, function() {
callback(); invocation.return_value(null);
this.disconnect(signalId); this.disconnect(signalId);
})); }));
} }
}; };
DBus.conformExport(EndSessionDialog.prototype, EndSessionDialogIface);

View File

@ -587,12 +587,13 @@ Chrome.prototype = {
this._screenSaverActive = false; this._screenSaverActive = false;
this._screenSaverProxy = new ScreenSaver.ScreenSaverProxy(); this._screenSaverProxy = new ScreenSaver.ScreenSaverProxy();
this._screenSaverProxy.connect('ActiveChanged', Lang.bind(this, this._onScreenSaverActiveChanged)); this._screenSaverProxy.connectSignal('ActiveChanged', Lang.bind(this, function(proxy, senderName, [isActive]) {
this._screenSaverProxy.GetActiveRemote(Lang.bind(this, this._onScreenSaverActiveChanged(isActive);
function(result, err) { }));
if (!err) this._screenSaverProxy.GetActiveRemote(Lang.bind(this, function(result, err) {
this._onScreenSaverActiveChanged(this._screenSaverProxy, result); if (!err)
})); this._onScreenSaverActiveChanged(result[0]);
}));
this._relayout(); this._relayout();
}, },
@ -733,7 +734,7 @@ Chrome.prototype = {
this._queueUpdateRegions(); this._queueUpdateRegions();
}, },
_onScreenSaverActiveChanged: function(proxy, screenSaverActive) { _onScreenSaverActiveChanged: function(screenSaverActive) {
this._screenSaverActive = screenSaverActive; this._screenSaverActive = screenSaverActive;
this._updateVisibility(); this._updateVisibility();
this._queueUpdateRegions(); this._queueUpdateRegions();

View File

@ -1349,12 +1349,15 @@ function MessageTray() {
MessageTray.prototype = { MessageTray.prototype = {
_init: function() { _init: function() {
this._presence = new GnomeSession.Presence(); this._presence = new GnomeSession.Presence(Lang.bind(this, function(proxy, error) {
this._onStatusChanged(proxy.status);
}));
this._userStatus = GnomeSession.PresenceStatus.AVAILABLE; this._userStatus = GnomeSession.PresenceStatus.AVAILABLE;
this._busy = false; this._busy = false;
this._backFromAway = false; this._backFromAway = false;
this._presence.connect('StatusChanged', Lang.bind(this, this._onStatusChanged)); this._presence.connectSignal('StatusChanged', Lang.bind(this, function(proxy, senderName, [status]) {
this._presence.getStatus(Lang.bind(this, this._onStatusChanged)); this._onStatusChanged(status);
}));
this.actor = new St.Group({ name: 'message-tray', this.actor = new St.Group({ name: 'message-tray',
reactive: true, reactive: true,
@ -1902,7 +1905,7 @@ MessageTray.prototype = {
this._updateState(); this._updateState();
}, },
_onStatusChanged: function(presence, status) { _onStatusChanged: function(status) {
this._backFromAway = (this._userStatus == GnomeSession.PresenceStatus.IDLE && this._userStatus != status); this._backFromAway = (this._userStatus == GnomeSession.PresenceStatus.IDLE && this._userStatus != status);
this._userStatus = status; this._userStatus = status;

View File

@ -157,8 +157,9 @@ IMStatusChooserItem.prototype = {
Lang.bind(this, this._changeIMStatus)); Lang.bind(this, this._changeIMStatus));
this._presence = new GnomeSession.Presence(); this._presence = new GnomeSession.Presence();
this._presence.connect('StatusChanged', this._presence.connectSignal('StatusChanged', Lang.bind(this, function(proxy, senderName, [status]) {
Lang.bind(this, this._sessionStatusChanged)); this._sessionStatusChanged(status);
}));
this._sessionPresenceRestored = false; this._sessionPresenceRestored = false;
this._imPresenceRestored = false; this._imPresenceRestored = false;
@ -292,7 +293,9 @@ IMStatusChooserItem.prototype = {
this._setComboboxPresence(presence); this._setComboboxPresence(presence);
if (!this._sessionPresenceRestored) { if (!this._sessionPresenceRestored) {
this._presence.getStatus(Lang.bind(this, this._sessionStatusChanged)); this._presence.connectSignal('StatusChanged', Lang.bind(this, function (proxy, senderName, [status]) {
this._sessionStatusChanged(status);
}));
return; return;
} }
@ -376,14 +379,14 @@ IMStatusChooserItem.prototype = {
return this._currentPresence; return this._currentPresence;
}, },
_sessionStatusChanged: function(sessionPresence, sessionStatus) { _sessionStatusChanged: function(sessionStatus) {
if (!this._imPresenceRestored) if (!this._imPresenceRestored)
return; return;
if (!this._sessionPresenceRestored) { if (!this._sessionPresenceRestored) {
let savedStatus = global.settings.get_int('saved-session-presence'); let savedStatus = global.settings.get_int('saved-session-presence');
if (sessionStatus != savedStatus) { if (sessionStatus != savedStatus) {
this._presence.setStatus(savedStatus); this._presence.status = savedStatus;
return; return;
} }
this._sessionPresenceRestored = true; this._sessionPresenceRestored = true;
@ -452,9 +455,9 @@ UserMenuButton.prototype = {
this._idleIcon = new St.Icon({ icon_name: 'user-idle', this._idleIcon = new St.Icon({ icon_name: 'user-idle',
style_class: 'popup-menu-icon' }); style_class: 'popup-menu-icon' });
this._presence.connect('StatusChanged', this._presence.connectSignal('StatusChanged', Lang.bind(this, function (proxy, senderName, [status]) {
Lang.bind(this, this._updateSwitch)); this._updateSwitch(status);
this._presence.getStatus(Lang.bind(this, this._updateSwitch)); }));
this._accountMgr.connect('most-available-presence-changed', this._accountMgr.connect('most-available-presence-changed',
Lang.bind(this, this._updatePresenceIcon)); Lang.bind(this, this._updatePresenceIcon));
@ -575,7 +578,7 @@ UserMenuButton.prototype = {
} }
}, },
_updateSwitch: function(presence, status) { _updateSwitch: function(status) {
let active = status == GnomeSession.PresenceStatus.AVAILABLE; let active = status == GnomeSession.PresenceStatus.AVAILABLE;
this._notificationsSwitch.setToggleState(active); this._notificationsSwitch.setToggleState(active);
}, },