[gnome-shell/hotplug: 2/21] automount: add automountManager
- From: Cosimo Cecchi <cosimoc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-shell/hotplug: 2/21] automount: add automountManager
- Date: Mon, 27 Jun 2011 19:52:07 +0000 (UTC)
commit 26a80f979648142845389a4c6a4dbe3754bb76d0
Author: Cosimo Cecchi <cosimoc gnome org>
Date: Mon Jun 20 15:16:40 2011 -0400
automount: add automountManager
js/Makefile.am | 1 +
js/ui/automountManager.js | 247 +++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 248 insertions(+), 0 deletions(-)
---
diff --git a/js/Makefile.am b/js/Makefile.am
index 55deff2..a3757b5 100644
--- a/js/Makefile.am
+++ b/js/Makefile.am
@@ -15,6 +15,7 @@ nobase_dist_js_DATA = \
ui/altTab.js \
ui/appDisplay.js \
ui/appFavorites.js \
+ ui/automountManager.js \
ui/autorunManager.js \
ui/boxpointer.js \
ui/calendar.js \
diff --git a/js/ui/automountManager.js b/js/ui/automountManager.js
new file mode 100644
index 0000000..d6dcadc
--- /dev/null
+++ b/js/ui/automountManager.js
@@ -0,0 +1,247 @@
+/* -*- mode: js2; js2-basic-offset: 4; indent-tabs-mode: nil -*- */
+
+const Lang = imports.lang;
+const DBus = imports.dbus;
+const Mainloop = imports.mainloop;
+const Gio = imports.gi.Gio;
+
+const Main = imports.ui.main;
+
+// GSettings keys
+const SETTINGS_SCHEMA = 'org.gnome.desktop.media-handling';
+const SETTING_ENABLE_AUTOMOUNT = 'automount';
+
+const ConsoleKitSessionIface = {
+ name: 'org.freedesktop.ConsoleKit.Session',
+ methods: [{ name: 'IsActive',
+ inSignature: '',
+ outSignature: 'b' }],
+ signals: [{ name: 'ActiveChanged',
+ inSignature: 'b' }]
+};
+
+const ConsoleKitSession = function(sessionPath) {
+ this._init(sessionPath);
+};
+
+ConsoleKitSession.prototype = {
+ _init: function(sessionPath) {
+ DBus.system.proxifyObject(this, 'org.freedesktop.ConsoleKit', sessionPath);
+ }
+};
+DBus.proxifyPrototype(ConsoleKitSession.prototype, ConsoleKitSessionIface);
+
+const ConsoleKitManagerIface = {
+ name: 'org.freedesktop.ConsoleKit.Manager',
+ methods: [{ name: 'GetCurrentSession',
+ inSignature: '',
+ outSignature: 'o' }]
+};
+
+const ConsoleKitManager = function() {
+ this._init();
+};
+
+ConsoleKitManager.prototype = {
+ _init: function() {
+ this.sessionActive = true;
+
+ DBus.system.proxifyObject(this,
+ 'org.freedesktop.ConsoleKit',
+ '/org/freedesktop/ConsoleKit/Manager');
+
+ DBus.system.watch_name('org.freedesktop.ConsoleKit',
+ false, // do not launch a name-owner if none exists
+ Lang.bind(this, this._onManagerAppeared),
+ Lang.bind(this, this._onManagerVanished));
+ },
+
+ _onManagerAppeared: function(owner) {
+ this.GetCurrentSessionRemote(Lang.bind(this, this._onCurrentSession));
+ },
+
+ _onManagerVanished: function(oldOwner) {
+ this.sessionActive = true;
+ },
+
+ _onCurrentSession: function(session) {
+ this._ckSession = new ConsoleKitSession(session);
+ this._ckSession.connect('ActiveChanged',
+ Lang.bind(this, this._onActiveChanged));
+ this._ckSession.IsActiveRemote(Lang.bind(this, this._onIsActive));
+ },
+
+ _onIsActive: function(isActive) {
+ this.sessionActive = isActive;
+ },
+
+ _onActiveChanged: function(object, isActive) {
+ this.sessionActive = isActive;
+ },
+};
+DBus.proxifyPrototype(ConsoleKitManager.prototype, ConsoleKitManagerIface);
+
+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, this._onGetActive));
+ },
+
+ _onSSVanished: function(oldOwner) {
+ this.screenSaverActive = false;
+ },
+
+ _onGetActive: function(isActive) {
+ this.screenSaverActive = isActive;
+ },
+};
+DBus.proxifyPrototype(ScreenSaverProxy.prototype, ScreenSaverIface);
+
+function AutomountManager() {
+ this._init();
+}
+
+AutomountManager.prototype = {
+ _init: function() {
+ this._settings = new Gio.Settings({ schema: SETTINGS_SCHEMA });
+ this._volumeQueue = new Array();
+
+ this._initConsoleKitListener();
+ this._initScreenSaverProxy();
+ this._initVolumeMonitor();
+
+ Mainloop.idle_add(Lang.bind(this, this._startupMountAll));
+ },
+
+ _initConsoleKitListener: function() {
+ this.ckListener = new ConsoleKitManager();
+ },
+
+ _initScreenSaverProxy: function() {
+ this._ssProxy = new ScreenSaverProxy();
+ this._ssProxy.connect('ActiveChanged',
+ Lang.bind(this,
+ this._screenSaverActiveChanged));
+ },
+
+ _initVolumeMonitor: function() {
+ this._volumeMonitor = Gio.VolumeMonitor.get();
+
+ this._volumeMonitor.connect('volume-added',
+ Lang.bind(this,
+ this._onVolumeAdded));
+ this._volumeMonitor.connect('volume-removed',
+ Lang.bind(this,
+ this._onVolumeRemoved));
+ },
+
+ _screenSaverActiveChanged: function(object, isActive) {
+ this._ssProxy.screenSaverActive = isActive;
+
+ if (!isActive) {
+ this._volumeQueue.forEach(Lang.bind(this, function(volume) {
+ this._checkAndMountVolume(volume);
+ }));
+ }
+
+ // clear the queue anyway
+ this._volumeQueue = new Array();
+ },
+
+ _startupMountAll: function() {
+ if (!this._settings.get_boolean(SETTING_ENABLE_AUTOMOUNT))
+ return false;
+
+ let volumes = this._volumeMonitor.get_volumes();
+ volumes.forEach(Lang.bind(this, function(volume) {
+ if (!volume.should_automount() ||
+ !volume.can_mount())
+ return;
+
+ // if it's already mounted, don't attempt to mount it again
+ if (volume.get_mount())
+ return;
+
+ this._mountVolume(volume, null);
+ }));
+
+ return false;
+ },
+
+ _onVolumeAdded: function(monitor, volume) {
+ this._checkAndMountVolume(volume);
+ },
+
+ _checkAndMountVolume: function(volume) {
+ if (!this._settings.get_boolean(SETTING_ENABLE_AUTOMOUNT))
+ return;
+
+ if (!volume.should_automount() ||
+ !volume.can_mount())
+ return;
+
+ // if we're not in the current ConsoleKit session,
+ // don't attempt automount
+ if (!this.ckListener.sessionActive)
+ return;
+
+ if (this._ssProxy.screenSaverActive) {
+ if (this._volumeQueue.indexOf(volume) == -1)
+ this._volumeQueue.push(volume);
+
+ return;
+ }
+
+ // TODO: mount op
+ this._mountVolume(volume, null);
+ },
+
+ _mountVolume: function(volume, operation) {
+ volume.mount(0, operation, null,
+ Lang.bind(this, this._onVolumeMounted));
+ },
+
+ _onVolumeMounted: function(volume, res) {
+ try {
+ volume.mount_finish(res);
+ } catch (e) {
+ log('Unable to mount volume ' + volume.get_name() + ': ' +
+ e.toString());
+ return;
+ }
+ },
+
+ _onVolumeRemoved: function(monitor, volume) {
+ this._volumeQueue =
+ this._volumeQueue.filter(function(element) {
+ return (element != volume);
+ });
+ }
+}
\ No newline at end of file
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]