[gnome-shell/wip/gdbus: 2/4] screensaver, gnomesession: port to GDBus based bindings



commit 7b7bb4331b681964abf95c3e7b723696b7c9c158
Author: Giovanni Campagna <gcampagna src gnome org>
Date:   Tue Aug 16 14:24:39 2011 +0200

    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

 js/misc/gnomeSession.js   |  143 ++++++++++++--------------------------------
 js/misc/screenSaver.js    |   87 +++++++++++++--------------
 js/ui/automountManager.js |    7 +-
 js/ui/endSessionDialog.js |   72 ++++++++++++-----------
 js/ui/layout.js           |   15 +++--
 js/ui/messageTray.js      |   11 ++-
 js/ui/userMenu.js         |   21 ++++---
 7 files changed, 147 insertions(+), 209 deletions(-)
---
diff --git a/js/misc/gnomeSession.js b/js/misc/gnomeSession.js
index a2b61fd..dc58abd 100644
--- a/js/misc/gnomeSession.js
+++ b/js/misc/gnomeSession.js
@@ -1,20 +1,18 @@
 // -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
 
-const DBus = imports.dbus;
+const Gio = imports.gi.Gio;
 const Lang = imports.lang;
 const Signals = imports.signals;
 
-const PresenceIface = {
-    name: 'org.gnome.SessionManager.Presence',
-    methods: [{ name: 'SetStatus',
-                inSignature: 'u',
-                outSignature: '' }],
-    properties: [{ name: 'status',
-                   signature: 'u',
-                   access: 'readwrite' }],
-    signals: [{ name: 'StatusChanged',
-                inSignature: 'u' }]
-};
+const PresenceIface = <interface name="org.gnome.SessionManager.Presence">
+<method name="SetStatus">
+    <arg type="u" direction="in"/>
+</method>
+<property name="status" type="u" access="readwrite"/>
+<signal name="StatusChanged">
+    <arg type="u" direction="out"/>
+</signal>
+</interface>;
 
 const PresenceStatus = {
     AVAILABLE: 0,
@@ -23,104 +21,41 @@ const PresenceStatus = {
     IDLE: 3
 };
 
-function Presence() {
-    this._init();
+var PresenceProxy = Gio.DBusProxy.makeProxyWrapper(PresenceIface);
+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
 // change at runtime (changes always come in the form
 // of new inhibitors)
-const InhibitorIface = {
-    name: 'org.gnome.SessionManager.Inhibitor',
-    properties: [{ name: 'app_id',
-                   signature: 's',
-                   access: 'readonly' },
-                 { name: 'client_id',
-                   signature: 's',
-                   access: 'readonly' },
-                 { 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) {
-    this._init(objectPath);
+const InhibitorIface = <interface name="org.gnome.SessionManager.Inhibitor">
+<property name="app_id" type="s" access="read" />
+<property name="client_id" type="s" access="read" />
+<property name="reason" type="s" access="read" />
+<property name="flags" type="u" access="read" />
+<property name="toplevel_xid" type="u" access="read" />
+<property name="cookie" type="u" access="read" />
+</interface>;
+
+var InhibitorProxy = Gio.DBusProxy.makeProxyWrapper(InhibitorIface);
+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
-const SessionManagerIface = {
-    name: 'org.gnome.SessionManager',
-    methods: [
-        { name: 'Logout', inSignature: 'u', outSignature: '' },
-        { name: 'Shutdown', inSignature: '', outSignature: '' },
-        { name: 'CanShutdown', inSignature: '', outSignature: 'b' }
-    ]
-};
-
-function SessionManager() {
-    this._init();
+const SessionManagerIface = <interface name="org.gnome.SessionManager">
+<method name="Logout">
+    <arg type="u" direction="in" />
+</method>
+<method name="Shutdown" />
+<method name="CanShutdown">
+    <arg type="b" direction="out" />
+</method>
+</interface>;
+
+var SessionManagerProxy = Gio.DBusProxy.makeProxyWrapper(SessionManagerIface);
+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);
\ No newline at end of file
diff --git a/js/misc/screenSaver.js b/js/misc/screenSaver.js
index c471856..87687e1 100644
--- a/js/misc/screenSaver.js
+++ b/js/misc/screenSaver.js
@@ -1,53 +1,48 @@
 // -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
 
-const DBus = imports.dbus;
+const Gio = imports.gi.Gio;
 const Lang = imports.lang;
 
-const ScreenSaverIface = {
-    name: 'org.gnome.ScreenSaver',
-    methods: [{ name: 'GetActive',
-                inSignature: '',
-                outSignature: 'b' },
-              { name: 'Lock',
-                inSignature: '' },
-              { name: 'SetActive',
-                inSignature: 'b' }],
-    signals: [{ name: 'ActiveChanged',
-                inSignature: 'b' }]
-};
+const ScreenSaverIface = <interface name="org.gnome.ScreenSaver">
+<method name="GetActive">
+    <arg type="b" direction="out" />
+</method>
+<method name="Lock" />
+<method name="SetActive">
+    <arg type="b" direction="in" />
+</method>
+<signal name="ActiveChanged">
+    <arg type="b" direction="out" />
+</signal>
+</interface>;
+
+const ScreenSaverInfo = Gio.DBusInterfaceInfo.new_for_xml(ScreenSaverIface);
 
 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);
diff --git a/js/ui/automountManager.js b/js/ui/automountManager.js
index 9a73da2..e3dfe4d 100644
--- a/js/ui/automountManager.js
+++ b/js/ui/automountManager.js
@@ -86,9 +86,8 @@ AutomountManager.prototype = {
         this.ckListener = new ConsoleKitManager();
 
         this._ssProxy = new ScreenSaver.ScreenSaverProxy();
-        this._ssProxy.connect('ActiveChanged',
-                              Lang.bind(this,
-                                        this._screenSaverActiveChanged));
+        this._ssProxy.connectSignal('ActiveChanged',
+                                    Lang.bind(this, this._screenSaverActiveChanged));
 
         this._volumeMonitor = Gio.VolumeMonitor.get();
 
@@ -111,7 +110,7 @@ AutomountManager.prototype = {
         Mainloop.idle_add(Lang.bind(this, this._startupMountAll));
     },
 
-    _screenSaverActiveChanged: function(object, isActive) {
+    _screenSaverActiveChanged: function(object, senderName, [isActive]) {
         if (!isActive) {
             this._volumeQueue.forEach(Lang.bind(this, function(volume) {
                 this._checkAndMountVolume(volume);
diff --git a/js/ui/endSessionDialog.js b/js/ui/endSessionDialog.js
index 4dcd87f..81c42b0 100644
--- a/js/ui/endSessionDialog.js
+++ b/js/ui/endSessionDialog.js
@@ -18,19 +18,19 @@
  * 02111-1307, USA.
  */
 
-const DBus = imports.dbus;
 const Lang = imports.lang;
 const Signals = imports.signals;
 
 const AccountsService = imports.gi.AccountsService;
 const Clutter = imports.gi.Clutter;
+const Gio = imports.gi.Gio;
 const GLib = imports.gi.GLib;
 const Gtk = imports.gi.Gtk;
 const Pango = imports.gi.Pango;
 const St = imports.gi.St;
 const Shell = imports.gi.Shell;
 
-const GnomeSession = imports.misc.gnomeSession
+const GnomeSession = imports.misc.gnomeSession;
 const Lightbox = imports.ui.lightbox;
 const Main = imports.ui.main;
 const ModalDialog = imports.ui.modalDialog;
@@ -43,18 +43,19 @@ const _DIALOG_ICON_SIZE = 32;
 
 const GSM_SESSION_MANAGER_LOGOUT_FORCE = 2;
 
-const EndSessionDialogIface = {
-    name: 'org.gnome.SessionManager.EndSessionDialog',
-    methods: [{ name: 'Open',
-                inSignature: 'uuuao',
-                outSignature: ''
-              }
-             ],
-    signals: [{ name: 'Canceled',
-                inSignature: '',
-              }],
-    properties: []
-};
+const EndSessionDialogIface = <interface name="org.gnome.SessionManager.EndSessionDialog">
+<method name="Open">
+    <arg type="u" direction="in" />
+    <arg type="u" direction="in" />
+    <arg type="u" direction="in" />
+    <arg type="ao" direction="in" />
+</method>
+<signal name="ConfirmedLogout" />
+<signal name="ConfirmedReboot" />
+<signal name="ConfirmedShutdown" />
+<signal name="Canceled" />
+<signal name="Closed" />
+</interface>;
 
 const logoutDialogContent = {
     subjectWithUser: C_("title", "Log Out %s"),
@@ -232,8 +233,6 @@ function _setLabelText(label, text) {
 function EndSessionDialog() {
     if (_endSessionDialog == null) {
         this._init();
-        DBus.session.exportObject('/org/gnome/SessionManager/EndSessionDialog',
-                                  this);
         _endSessionDialog = this;
     }
 
@@ -326,6 +325,9 @@ EndSessionDialog.prototype = {
                                           if (this._applicationList.get_children().length == 0)
                                               scrollView.hide();
                                       }));
+
+        this._dbusImpl = Gio.DBusExportedObject.wrapJSObject(EndSessionDialogIface, this);
+        this._dbusImpl.export(Gio.DBus.session, '/org/gnome/SessionManager/EndSessionDialog');
     },
 
     _onDestroy: function() {
@@ -440,25 +442,19 @@ EndSessionDialog.prototype = {
 
     close: function() {
         ModalDialog.ModalDialog.prototype.close.call(this);
-        DBus.session.emit_signal('/org/gnome/SessionManager/EndSessionDialog',
-                                 'org.gnome.SessionManager.EndSessionDialog',
-                                 'Closed', '', []);
+        this._dbusImpl.emit_signal('Closed', null);
     },
 
     cancel: function() {
         this._stopTimer();
-        DBus.session.emit_signal('/org/gnome/SessionManager/EndSessionDialog',
-                                 'org.gnome.SessionManager.EndSessionDialog',
-                                 'Canceled', '', []);
+        this._dbusImpl.emit_signal('Canceled', null);
         this.close(global.get_current_time());
     },
 
     _confirm: function(signal) {
         this._fadeOutDialog();
         this._stopTimer();
-        DBus.session.emit_signal('/org/gnome/SessionManager/EndSessionDialog',
-                                 'org.gnome.SessionManager.EndSessionDialog',
-                                 signal, '', []);
+        this._dbusImpl.emit_signal(signal, null);
     },
 
     _onOpened: function() {
@@ -510,18 +506,23 @@ EndSessionDialog.prototype = {
         this._updateContent();
     },
 
-    OpenAsync: function(type, timestamp, totalSecondsToStayOpen, inhibitorObjectPaths, callback) {
+    OpenAsync: function(parameters, invocation) {
+        let [type, timestamp, totalSecondsToStayOpen, inhibitorObjectPaths] = parameters;
         this._totalSecondsToStayOpen = totalSecondsToStayOpen;
         this._inhibitors = [];
         this._applicationList.destroy_children();
         this._type = type;
 
-        if (!(this._type in DialogContent))
-            throw new DBus.DBusError('org.gnome.Shell.ModalDialog.TypeError',
-                                     "Unknown dialog type requested");
+        if (!(this._type in DialogContent)) {
+            invocation.report_dbus_error('org.gnome.Shell.ModalDialog.TypeError',
+                                         "Unknown dialog type requested");
+            return;
+        }
 
         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() {
@@ -532,17 +533,18 @@ EndSessionDialog.prototype = {
 
         this._updateButtons();
 
-        if (!this.open(timestamp))
-            throw new DBus.DBusError('org.gnome.Shell.ModalDialog.GrabError',
-                                     "Cannot grab pointer and keyboard");
+        if (!this.open(timestamp)) {
+            invocation.report_dbus_error('org.gnome.Shell.ModalDialog.GrabError',
+                                         "Cannot grab pointer and keyboard");
+            return;
+        }
 
         this._updateContent();
 
         let signalId = this.connect('opened',
                                     Lang.bind(this, function() {
-                                        callback();
+                                        invocation.return_value(null);
                                         this.disconnect(signalId);
                                     }));
     }
 };
-DBus.conformExport(EndSessionDialog.prototype, EndSessionDialogIface);
diff --git a/js/ui/layout.js b/js/ui/layout.js
index 04e8e4a..e4fcb62 100644
--- a/js/ui/layout.js
+++ b/js/ui/layout.js
@@ -587,12 +587,13 @@ Chrome.prototype = {
 
         this._screenSaverActive = false;
         this._screenSaverProxy = new ScreenSaver.ScreenSaverProxy();
-        this._screenSaverProxy.connect('ActiveChanged', Lang.bind(this, this._onScreenSaverActiveChanged));
-        this._screenSaverProxy.GetActiveRemote(Lang.bind(this,
-            function(result, err) {
-                if (!err)
-                    this._onScreenSaverActiveChanged(this._screenSaverProxy, result);
-            }));
+        this._screenSaverProxy.connectSignal('ActiveChanged', Lang.bind(this, function(proxy, senderName, [isActive]) {
+            this._onScreenSaverActiveChanged(isActive);
+        }));
+        this._screenSaverProxy.GetActiveRemote(Lang.bind(this, function(result, err) {
+            if (!err)
+                this._onScreenSaverActiveChanged(result[0]);
+        }));
 
         this._relayout();
     },
@@ -733,7 +734,7 @@ Chrome.prototype = {
         this._queueUpdateRegions();
     },
 
-    _onScreenSaverActiveChanged: function(proxy, screenSaverActive) {
+    _onScreenSaverActiveChanged: function(screenSaverActive) {
         this._screenSaverActive = screenSaverActive;
         this._updateVisibility();
         this._queueUpdateRegions();
diff --git a/js/ui/messageTray.js b/js/ui/messageTray.js
index 64c84aa..ef5c19b 100644
--- a/js/ui/messageTray.js
+++ b/js/ui/messageTray.js
@@ -1349,12 +1349,15 @@ function MessageTray() {
 
 MessageTray.prototype = {
     _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._busy = false;
         this._backFromAway = false;
-        this._presence.connect('StatusChanged', Lang.bind(this, this._onStatusChanged));
-        this._presence.getStatus(Lang.bind(this, this._onStatusChanged));
+        this._presence.connectSignal('StatusChanged', Lang.bind(this, function(proxy, senderName, [status]) {
+            this._onStatusChanged(status);
+        }));
 
         this.actor = new St.Group({ name: 'message-tray',
                                     reactive: true,
@@ -1902,7 +1905,7 @@ MessageTray.prototype = {
         this._updateState();
     },
 
-    _onStatusChanged: function(presence, status) {
+    _onStatusChanged: function(status) {
         this._backFromAway = (this._userStatus == GnomeSession.PresenceStatus.IDLE && this._userStatus != status);
         this._userStatus = status;
 
diff --git a/js/ui/userMenu.js b/js/ui/userMenu.js
index 8e71319..5d84bf9 100644
--- a/js/ui/userMenu.js
+++ b/js/ui/userMenu.js
@@ -157,8 +157,9 @@ IMStatusChooserItem.prototype = {
                             Lang.bind(this, this._changeIMStatus));
 
         this._presence = new GnomeSession.Presence();
-        this._presence.connect('StatusChanged',
-                               Lang.bind(this, this._sessionStatusChanged));
+        this._presence.connectSignal('StatusChanged', Lang.bind(this, function(proxy, senderName, [status]) {
+	    this._sessionStatusChanged(status);
+        }));
 
         this._sessionPresenceRestored = false;
         this._imPresenceRestored = false;
@@ -292,7 +293,9 @@ IMStatusChooserItem.prototype = {
         this._setComboboxPresence(presence);
 
         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;
         }
 
@@ -376,14 +379,14 @@ IMStatusChooserItem.prototype = {
         return this._currentPresence;
     },
 
-    _sessionStatusChanged: function(sessionPresence, sessionStatus) {
+    _sessionStatusChanged: function(sessionStatus) {
         if (!this._imPresenceRestored)
             return;
 
         if (!this._sessionPresenceRestored) {
             let savedStatus = global.settings.get_int('saved-session-presence');
             if (sessionStatus != savedStatus) {
-                this._presence.setStatus(savedStatus);
+                this._presence.status = savedStatus;
                 return;
             }
             this._sessionPresenceRestored = true;
@@ -452,9 +455,9 @@ UserMenuButton.prototype = {
         this._idleIcon = new St.Icon({ icon_name: 'user-idle',
                                        style_class: 'popup-menu-icon' });
 
-        this._presence.connect('StatusChanged',
-                               Lang.bind(this, this._updateSwitch));
-        this._presence.getStatus(Lang.bind(this, this._updateSwitch));
+        this._presence.connectSignal('StatusChanged', Lang.bind(this, function (proxy, senderName, [status]) {
+	    this._updateSwitch(status);
+	}));
 
         this._accountMgr.connect('most-available-presence-changed',
                                   Lang.bind(this, this._updatePresenceIcon));
@@ -575,7 +578,7 @@ UserMenuButton.prototype = {
         }
     },
 
-    _updateSwitch: function(presence, status) {
+    _updateSwitch: function(status) {
         let active = status == GnomeSession.PresenceStatus.AVAILABLE;
         this._notificationsSwitch.setToggleState(active);
     },



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]