[gnome-shell/hotplug: 4/21] autorun: follow gsettings preferences for autorun
- From: Cosimo Cecchi <cosimoc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-shell/hotplug: 4/21] autorun: follow gsettings preferences for autorun
- Date: Mon, 27 Jun 2011 19:52:17 +0000 (UTC)
commit 4f5ee913ac66efc7412b3d97c2f8a4b38c0aa007
Author: Cosimo Cecchi <cosimoc gnome org>
Date: Tue Jun 21 12:55:50 2011 -0400
autorun: follow gsettings preferences for autorun
js/ui/autorunManager.js | 109 +++++++++++++++++++++++++++++++++--------------
1 files changed, 77 insertions(+), 32 deletions(-)
---
diff --git a/js/ui/autorunManager.js b/js/ui/autorunManager.js
index 2fbe344..1894421 100644
--- a/js/ui/autorunManager.js
+++ b/js/ui/autorunManager.js
@@ -10,6 +10,9 @@ const MessageTray = imports.ui.messageTray;
// GSettings keys
const SETTINGS_SCHEMA = 'org.gnome.desktop.media-handling';
const SETTING_DISABLE_AUTORUN = 'autorun-never';
+const SETTING_START_APP = 'autorun-x-content-start-app';
+const SETTING_IGNORE = 'autorun-x-content-ignore';
+const SETTING_OPEN_FOLDER = 'autorun-x-content-open-folder';
const HOTPLUG_ICON_SIZE = 16;
@@ -32,6 +35,20 @@ function isMountRootHidden(root) {
return (path.indexOf('/.') != -1);
}
+function startAppForMount(app, mount) {
+ let files = [];
+ let root = mount.get_root();
+ files.push(root);
+
+ try {
+ app.launch(files,
+ global.create_app_launch_context())
+ } catch (e) {
+ log('Unable to launch the application ' + app.get_name()
+ + ': ' + e.toString());
+ }
+}
+
/******************************************/
function ContentTypeDiscoverer(callback) {
@@ -305,19 +322,8 @@ AutorunResidentNotification.prototype = {
contentTypes.push('inode/directory');
let app = Gio.app_info_get_default_for_type(contentTypes[0], false);
- let files = [];
- let root = mount.get_root();
-
- files.push(root);
-
- try {
- app.launch(files,
- global.create_app_launch_context())
- } catch (e) {
- log('Unable to launch the application ' + app.get_name()
- + ': ' + e.toString());
- }
-
+ startAppForMount(app, mount);
+
return true;
}));
@@ -339,6 +345,26 @@ AutorunTransientDispatcher.prototype = {
this._settings = new Gio.Settings({ schema: SETTINGS_SCHEMA });
},
+ _getSettingsForType: function(contentType) {
+ let runApp = this._settings.get_strv(SETTING_START_APP);
+ if (runApp.some(function(type) {
+ return (type == contentType);
+ }))
+ return 'run';
+
+ let ignore = this._settings.get_strv(SETTING_IGNORE);
+ if (ignore.some(function(type) {
+ return (type == contentType);
+ }))
+ return 'ignore';
+
+ let openFiles = this._settings.get_strv(SETTING_OPEN_FOLDER);
+ if (openFiles.some(function(type) {
+ return (type == contentType);
+ }))
+ return 'files';
+
+ return 'ask';
},
_getSourceForMount: function(mount) {
@@ -356,6 +382,16 @@ AutorunTransientDispatcher.prototype = {
return null;
},
+ _addSource: function(mount, contentTypes) {
+ // if we already have a source showing for this
+ // mount, return
+ if (this._getSourceForMount(mount))
+ return;
+
+ // add a new source
+ this._sources.push(new AutorunTransientSource(mount, contentTypes));
+ },
+
addMount: function(mount, contentTypes) {
// if autorun is disabled globally, return
if (this._settings.get_boolean(SETTING_DISABLE_AUTORUN))
@@ -365,13 +401,33 @@ AutorunTransientDispatcher.prototype = {
if (ignoreAutorunForMount(mount))
return;
- // finally, if we already have a source showing for this
- // mount, return
- if (this._getSourceForMount(mount))
- return;
-
- // add a new source
- this._sources.push(new AutorunTransientSource(mount, contentTypes));
+ let success = false;
+ let settings = this._getSettingsForType(contentTypes[0]);
+
+ // check at the settings for the first content type
+ // to see whether we should ask
+ if (settings == 'ignore') {
+ return; // return right away
+ } else if (settings == 'run') {
+ let app = Gio.app_info_get_default_for_type(type, false);
+
+ if (app) {
+ startAppForMount(app, mount);
+ success = true;
+ }
+ } else if (settings == 'files') {
+ let app = Gio.app_info_get_default_for_type('inode/directory', false);
+
+ if (app) {
+ startAppForMount(app, mount);
+ success = true;
+ }
+ }
+
+ // we fallback here also in case the settings did not specify 'ask',
+ // but we failed launching the default app or the default file manager
+ if (!success)
+ this._addSource(mount, contentTypes);
},
removeMount: function(mount) {
@@ -462,20 +518,9 @@ AutorunTransientSource.prototype = {
},
_onAppButtonClicked: function(actor, button) {
- let files = [];
let app = actor._delegate;
- let root = this._mount.get_root();
-
- files.push(root);
-
- try {
- app.launch(files,
- global.create_app_launch_context())
- } catch (e) {
- log('Unable to launch the application ' + app.get_name()
- + ': ' + e.toString());
- }
+ startAppForMount(app, this._mount);
this.destroy();
},
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]