[gnome-shell/hotplug: 3/14] autorun: follow gsettings preferences for autorun



commit febc1d60b145a81cd113c7bdc033796052df1637
Author: Cosimo Cecchi <cosimoc gnome org>
Date:   Mon Jul 11 09:31:56 2011 -0400

    autorun: follow gsettings preferences for autorun
    
    https://bugzilla.gnome.org/show_bug.cgi?id=653520

 js/ui/autorunManager.js |   67 ++++++++++++++++++++++++++++++++++++++++++-----
 1 files changed, 60 insertions(+), 7 deletions(-)
---
diff --git a/js/ui/autorunManager.js b/js/ui/autorunManager.js
index 88ef2ac..66f07bb 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;
 
@@ -344,6 +347,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) {
@@ -361,6 +384,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))
@@ -370,13 +403,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) {



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