[gnome-shell/hotplug: 1/13] screensaver: factor out a ScreenSaverProxy helper class



commit 507784d511cde4d8c9bc5b249d5717d09f983a41
Author: Cosimo Cecchi <cosimoc gnome org>
Date:   Tue Jul 12 11:42:33 2011 -0400

    screensaver: factor out a ScreenSaverProxy helper class
    
    This class will be shared between StatusMenu and the upcoming
    AutomountManager classes.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=653520

 js/Makefile.am         |    1 +
 js/misc/screenSaver.js |   45 +++++++++++++++++++++++++++++++++++++++++++++
 js/ui/statusMenu.js    |   14 +++-----------
 3 files changed, 49 insertions(+), 11 deletions(-)
---
diff --git a/js/Makefile.am b/js/Makefile.am
index 758b4c0..33e86c2 100644
--- a/js/Makefile.am
+++ b/js/Makefile.am
@@ -10,6 +10,7 @@ nobase_dist_js_DATA = 	\
 	misc/history.js		\
 	misc/modemManager.js	\
 	misc/params.js		\
+	misc/screenSaver.js     \
 	misc/util.js		\
 	perf/core.js		\
 	ui/altTab.js		\
diff --git a/js/misc/screenSaver.js b/js/misc/screenSaver.js
new file mode 100644
index 0000000..a742406
--- /dev/null
+++ b/js/misc/screenSaver.js
@@ -0,0 +1,45 @@
+/* -*- mode: js2; js2-basic-offset: 4; indent-tabs-mode: nil -*- */
+
+const DBus = imports.dbus;
+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' }]
+};
+
+function ScreenSaverProxy() {
+    this._init();
+}
+
+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));
+    },
+
+    _onSSAppeared: function(owner) {
+        this.GetActiveRemote(Lang.bind(this, function(isActive) {
+            this.screenSaverActive = isActive;
+        }))
+    },
+
+    _onSSVanished: function(oldOwner) {
+        this.screenSaverActive = false;
+    },
+};
+DBus.proxifyPrototype(ScreenSaverProxy.prototype, ScreenSaverIface);
diff --git a/js/ui/statusMenu.js b/js/ui/statusMenu.js
index 7d49743..8837686 100644
--- a/js/ui/statusMenu.js
+++ b/js/ui/statusMenu.js
@@ -10,27 +10,19 @@ const St = imports.gi.St;
 const Tp = imports.gi.TelepathyGLib;
 const UPowerGlib = imports.gi.UPowerGlib;
 
+const ScreenSaver = imports.misc.screenSaver;
 const GnomeSession = imports.misc.gnomeSession;
 const Main = imports.ui.main;
 const PanelMenu = imports.ui.panelMenu;
 const PopupMenu = imports.ui.popupMenu;
 const Util = imports.misc.util;
 
-const BUS_NAME = 'org.gnome.ScreenSaver';
-const OBJECT_PATH = '/org/gnome/ScreenSaver';
-
 const LOCKDOWN_SCHEMA = 'org.gnome.desktop.lockdown';
 const DISABLE_USER_SWITCH_KEY = 'disable-user-switching';
 const DISABLE_LOCK_SCREEN_KEY = 'disable-lock-screen';
 const DISABLE_LOG_OUT_KEY = 'disable-log-out';
 
-const ScreenSaverInterface = {
-    name: BUS_NAME,
-    methods: [ { name: 'Lock', inSignature: '' },
-               { name: 'SetActive', inSignature: 'b' }]
-};
-
-let ScreenSaverProxy = DBus.makeProxyClass(ScreenSaverInterface);
+let ScreenSaverProxy = new ScreenSaver.ScreenSaverProxy();
 
 // Adapted from gdm/gui/user-switch-applet/applet.c
 //
@@ -63,7 +55,7 @@ StatusMenuButton.prototype = {
         this._account_mgr = Tp.AccountManager.dup()
 
         this._upClient = new UPowerGlib.Client();
-        this._screenSaverProxy = new ScreenSaverProxy(DBus.session, BUS_NAME, OBJECT_PATH);
+        this._screenSaverProxy = new ScreenSaver.ScreenSaverProxy();
         this.actor.connect('destroy', Lang.bind(this, this._onDestroy));
 
         this._iconBox = new St.Bin();



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