2011-09-28 09:16:26 -04:00
|
|
|
// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
|
2011-07-12 09:47:43 -04:00
|
|
|
|
|
|
|
const Lang = imports.lang;
|
|
|
|
const Gio = imports.gi.Gio;
|
|
|
|
const St = imports.gi.St;
|
|
|
|
|
2013-02-08 11:25:08 -05:00
|
|
|
const GnomeSession = imports.misc.gnomeSession;
|
2011-07-12 09:47:43 -04:00
|
|
|
const Main = imports.ui.main;
|
|
|
|
const MessageTray = imports.ui.messageTray;
|
2011-06-22 16:43:16 -04:00
|
|
|
const ShellMountOperation = imports.ui.shellMountOperation;
|
2011-07-12 09:47:43 -04:00
|
|
|
|
|
|
|
// GSettings keys
|
|
|
|
const SETTINGS_SCHEMA = 'org.gnome.desktop.media-handling';
|
|
|
|
const SETTING_DISABLE_AUTORUN = 'autorun-never';
|
2011-07-11 09:31:56 -04:00
|
|
|
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 AutorunSetting = {
|
|
|
|
RUN: 0,
|
|
|
|
IGNORE: 1,
|
|
|
|
FILES: 2,
|
|
|
|
ASK: 3
|
|
|
|
};
|
2011-07-12 09:47:43 -04:00
|
|
|
|
|
|
|
// misc utils
|
2012-06-19 15:06:44 -04:00
|
|
|
function shouldAutorunMount(mount, forTransient) {
|
2011-07-12 09:47:43 -04:00
|
|
|
let root = mount.get_root();
|
|
|
|
let volume = mount.get_volume();
|
|
|
|
|
2012-06-19 15:06:44 -04:00
|
|
|
if (!volume || (!volume.allowAutorun && forTransient))
|
2012-06-19 15:17:07 -04:00
|
|
|
return false;
|
|
|
|
|
|
|
|
if (!root.is_native() || isMountRootHidden(root))
|
2011-07-12 09:47:43 -04:00
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
function isMountRootHidden(root) {
|
|
|
|
let path = root.get_path();
|
|
|
|
|
|
|
|
// skip any mounts in hidden directory hierarchies
|
|
|
|
return (path.indexOf('/.') != -1);
|
|
|
|
}
|
|
|
|
|
2012-09-16 13:54:25 -04:00
|
|
|
function isMountNonLocal(mount) {
|
2012-10-16 13:50:13 -04:00
|
|
|
// If the mount doesn't have an associated volume, that means it's
|
|
|
|
// an uninteresting filesystem. Most devices that we care about will
|
|
|
|
// have a mount, like media players and USB sticks.
|
2012-09-16 13:54:25 -04:00
|
|
|
let volume = mount.get_volume();
|
|
|
|
if (volume == null)
|
2012-10-16 13:50:13 -04:00
|
|
|
return true;
|
2012-09-16 13:54:25 -04:00
|
|
|
|
|
|
|
return (volume.get_identifier("class") == "network");
|
|
|
|
}
|
|
|
|
|
2011-07-12 09:47:43 -04:00
|
|
|
function startAppForMount(app, mount) {
|
|
|
|
let files = [];
|
|
|
|
let root = mount.get_root();
|
2011-07-11 09:31:56 -04:00
|
|
|
let retval = false;
|
|
|
|
|
2011-07-12 09:47:43 -04:00
|
|
|
files.push(root);
|
|
|
|
|
|
|
|
try {
|
2011-07-11 09:31:56 -04:00
|
|
|
retval = app.launch(files,
|
|
|
|
global.create_app_launch_context())
|
2011-07-12 09:47:43 -04:00
|
|
|
} catch (e) {
|
|
|
|
log('Unable to launch the application ' + app.get_name()
|
|
|
|
+ ': ' + e.toString());
|
|
|
|
}
|
2011-07-11 09:31:56 -04:00
|
|
|
|
|
|
|
return retval;
|
2011-07-12 09:47:43 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************/
|
|
|
|
|
2011-08-16 08:28:53 -04:00
|
|
|
const HotplugSnifferIface = <interface name="org.gnome.Shell.HotplugSniffer">
|
|
|
|
<method name="SniffURI">
|
|
|
|
<arg type="s" direction="in" />
|
|
|
|
<arg type="as" direction="out" />
|
|
|
|
</method>
|
|
|
|
</interface>;
|
2011-07-12 10:37:14 -04:00
|
|
|
|
2011-08-16 08:28:53 -04:00
|
|
|
const HotplugSnifferProxy = Gio.DBusProxy.makeProxyWrapper(HotplugSnifferIface);
|
|
|
|
function HotplugSniffer() {
|
|
|
|
return new HotplugSnifferProxy(Gio.DBus.session,
|
2011-07-12 10:37:14 -04:00
|
|
|
'org.gnome.Shell.HotplugSniffer',
|
|
|
|
'/org/gnome/Shell/HotplugSniffer');
|
2011-08-16 08:28:53 -04:00
|
|
|
}
|
2011-07-12 10:37:14 -04:00
|
|
|
|
2011-11-20 12:56:27 -05:00
|
|
|
const ContentTypeDiscoverer = new Lang.Class({
|
|
|
|
Name: 'ContentTypeDiscoverer',
|
2011-07-12 09:47:43 -04:00
|
|
|
|
|
|
|
_init: function(callback) {
|
|
|
|
this._callback = callback;
|
2012-09-16 13:24:25 -04:00
|
|
|
this._settings = new Gio.Settings({ schema: SETTINGS_SCHEMA });
|
2011-07-12 09:47:43 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
guessContentTypes: function(mount) {
|
2012-09-16 13:24:25 -04:00
|
|
|
let autorunEnabled = !this._settings.get_boolean(SETTING_DISABLE_AUTORUN);
|
2012-09-16 13:54:25 -04:00
|
|
|
let shouldScan = autorunEnabled && !isMountNonLocal(mount);
|
2012-09-16 13:24:25 -04:00
|
|
|
|
2012-09-16 13:54:25 -04:00
|
|
|
if (shouldScan) {
|
2012-09-16 13:24:25 -04:00
|
|
|
// guess mount's content types using GIO
|
|
|
|
mount.guess_content_type(false, null,
|
|
|
|
Lang.bind(this,
|
|
|
|
this._onContentTypeGuessed));
|
|
|
|
} else {
|
|
|
|
this._emitCallback(mount, []);
|
|
|
|
}
|
2011-07-12 09:47:43 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
_onContentTypeGuessed: function(mount, res) {
|
|
|
|
let contentTypes = [];
|
|
|
|
|
|
|
|
try {
|
|
|
|
contentTypes = mount.guess_content_type_finish(res);
|
|
|
|
} catch (e) {
|
|
|
|
log('Unable to guess content types on added mount ' + mount.get_name()
|
|
|
|
+ ': ' + e.toString());
|
|
|
|
}
|
|
|
|
|
2011-07-12 10:37:14 -04:00
|
|
|
if (contentTypes.length) {
|
|
|
|
this._emitCallback(mount, contentTypes);
|
|
|
|
} else {
|
|
|
|
let root = mount.get_root();
|
|
|
|
|
|
|
|
let hotplugSniffer = new HotplugSniffer();
|
2011-08-16 08:28:53 -04:00
|
|
|
hotplugSniffer.SniffURIRemote(root.get_uri(),
|
|
|
|
Lang.bind(this, function([contentTypes]) {
|
2011-07-12 10:37:14 -04:00
|
|
|
this._emitCallback(mount, contentTypes);
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
_emitCallback: function(mount, contentTypes) {
|
|
|
|
if (!contentTypes)
|
|
|
|
contentTypes = [];
|
|
|
|
|
2011-07-12 09:47:43 -04:00
|
|
|
// we're not interested in win32 software content types here
|
|
|
|
contentTypes = contentTypes.filter(function(type) {
|
|
|
|
return (type != 'x-content/win32-software');
|
|
|
|
});
|
|
|
|
|
2011-07-12 10:37:14 -04:00
|
|
|
let apps = [];
|
|
|
|
contentTypes.forEach(function(type) {
|
|
|
|
let app = Gio.app_info_get_default_for_type(type, false);
|
|
|
|
|
|
|
|
if (app)
|
|
|
|
apps.push(app);
|
|
|
|
});
|
|
|
|
|
|
|
|
if (apps.length == 0)
|
|
|
|
apps.push(Gio.app_info_get_default_for_type('inode/directory', false));
|
|
|
|
|
|
|
|
this._callback(mount, apps, contentTypes);
|
2011-07-12 09:47:43 -04:00
|
|
|
}
|
2011-11-20 12:56:27 -05:00
|
|
|
});
|
2011-07-12 09:47:43 -04:00
|
|
|
|
2011-11-20 12:56:27 -05:00
|
|
|
const AutorunManager = new Lang.Class({
|
|
|
|
Name: 'AutorunManager',
|
2011-07-12 09:47:43 -04:00
|
|
|
|
|
|
|
_init: function() {
|
2013-02-08 11:25:08 -05:00
|
|
|
this._session = new GnomeSession.SessionManager();
|
2011-07-12 09:47:43 -04:00
|
|
|
this._volumeMonitor = Gio.VolumeMonitor.get();
|
|
|
|
|
2012-09-02 21:23:50 -04:00
|
|
|
this._transDispatcher = new AutorunTransientDispatcher(this);
|
|
|
|
},
|
2011-07-12 09:47:43 -04:00
|
|
|
|
2012-09-04 20:24:56 -04:00
|
|
|
_ensureResidentSource: function() {
|
|
|
|
if (this._residentSource)
|
|
|
|
return;
|
|
|
|
|
2012-09-02 21:23:50 -04:00
|
|
|
this._residentSource = new AutorunResidentSource(this);
|
2012-09-04 20:24:56 -04:00
|
|
|
let destroyId = this._residentSource.connect('destroy', Lang.bind(this, function() {
|
|
|
|
this._residentSource.disconnect(destroyId);
|
|
|
|
this._residentSource = null;
|
|
|
|
}));
|
|
|
|
},
|
|
|
|
|
|
|
|
enable: function() {
|
2012-09-02 21:23:50 -04:00
|
|
|
this._scanMounts();
|
2011-07-12 09:47:43 -04:00
|
|
|
|
2012-09-02 21:23:50 -04:00
|
|
|
this._mountAddedId = this._volumeMonitor.connect('mount-added', Lang.bind(this, this._onMountAdded));
|
|
|
|
this._mountRemovedId = this._volumeMonitor.connect('mount-removed', Lang.bind(this, this._onMountRemoved));
|
|
|
|
},
|
|
|
|
|
|
|
|
disable: function() {
|
2012-09-05 12:46:55 -04:00
|
|
|
if (this._residentSource)
|
|
|
|
this._residentSource.destroy();
|
2012-09-02 21:23:50 -04:00
|
|
|
this._volumeMonitor.disconnect(this._mountAddedId);
|
|
|
|
this._volumeMonitor.disconnect(this._mountRemovedId);
|
|
|
|
},
|
2011-07-12 09:47:43 -04:00
|
|
|
|
2012-09-19 00:38:26 -04:00
|
|
|
_processMount: function(mount, hotplug) {
|
|
|
|
let discoverer = new ContentTypeDiscoverer(Lang.bind(this, function(mount, apps, contentTypes) {
|
|
|
|
this._ensureResidentSource();
|
|
|
|
this._residentSource.addMount(mount, apps);
|
|
|
|
|
|
|
|
if (hotplug)
|
|
|
|
this._transDispatcher.addMount(mount, apps, contentTypes);
|
|
|
|
}));
|
|
|
|
discoverer.guessContentTypes(mount);
|
|
|
|
},
|
|
|
|
|
2012-09-02 21:23:50 -04:00
|
|
|
_scanMounts: function() {
|
|
|
|
let mounts = this._volumeMonitor.get_mounts();
|
2012-09-19 00:38:26 -04:00
|
|
|
mounts.forEach(Lang.bind(this, function(mount) {
|
|
|
|
this._processMount(mount, false);
|
2011-07-12 09:47:43 -04:00
|
|
|
}));
|
|
|
|
},
|
|
|
|
|
|
|
|
_onMountAdded: function(monitor, mount) {
|
2011-06-20 15:16:40 -04:00
|
|
|
// don't do anything if our session is not the currently
|
|
|
|
// active one
|
2013-02-03 16:24:33 -05:00
|
|
|
if (!this._session.SessionIsActive)
|
2011-06-20 15:16:40 -04:00
|
|
|
return;
|
|
|
|
|
2012-09-19 00:38:26 -04:00
|
|
|
this._processMount(mount, true);
|
2011-07-12 09:47:43 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
_onMountRemoved: function(monitor, mount) {
|
|
|
|
this._transDispatcher.removeMount(mount);
|
2012-09-04 20:24:56 -04:00
|
|
|
if (this._residentSource)
|
|
|
|
this._residentSource.removeMount(mount);
|
2011-07-12 09:47:43 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
ejectMount: function(mount) {
|
2011-06-22 16:43:16 -04:00
|
|
|
let mountOp = new ShellMountOperation.ShellMountOperation(mount);
|
|
|
|
|
2011-06-23 10:08:17 -04:00
|
|
|
// first, see if we have a drive
|
|
|
|
let drive = mount.get_drive();
|
|
|
|
let volume = mount.get_volume();
|
|
|
|
|
|
|
|
if (drive &&
|
|
|
|
drive.get_start_stop_type() == Gio.DriveStartStopType.SHUTDOWN &&
|
|
|
|
drive.can_stop()) {
|
|
|
|
drive.stop(0, mountOp.mountOp, null,
|
|
|
|
Lang.bind(this, this._onStop));
|
|
|
|
} else {
|
|
|
|
if (mount.can_eject()) {
|
|
|
|
mount.eject_with_operation(0, mountOp.mountOp, null,
|
|
|
|
Lang.bind(this, this._onEject));
|
|
|
|
} else if (volume && volume.can_eject()) {
|
|
|
|
volume.eject_with_operation(0, mountOp.mountOp, null,
|
|
|
|
Lang.bind(this, this._onEject));
|
|
|
|
} else if (drive && drive.can_eject()) {
|
|
|
|
drive.eject_with_operation(0, mountOp.mountOp, null,
|
|
|
|
Lang.bind(this, this._onEject));
|
|
|
|
} else if (mount.can_unmount()) {
|
|
|
|
mount.unmount_with_operation(0, mountOp.mountOp, null,
|
|
|
|
Lang.bind(this, this._onUnmount));
|
|
|
|
}
|
|
|
|
}
|
2011-07-12 09:47:43 -04:00
|
|
|
},
|
|
|
|
|
2011-06-23 10:08:17 -04:00
|
|
|
_onUnmount: function(mount, res) {
|
2011-07-12 09:47:43 -04:00
|
|
|
try {
|
2011-06-23 10:08:17 -04:00
|
|
|
mount.unmount_with_operation_finish(res);
|
2011-07-12 09:47:43 -04:00
|
|
|
} catch (e) {
|
2012-06-20 16:35:29 -04:00
|
|
|
if (!e.matches(Gio.IOErrorEnum, Gio.IOErrorEnum.FAILED_HANDLED))
|
|
|
|
log('Unable to eject the mount ' + mount.get_name()
|
|
|
|
+ ': ' + e.toString());
|
2011-07-12 09:47:43 -04:00
|
|
|
}
|
|
|
|
},
|
2011-06-23 10:08:17 -04:00
|
|
|
|
|
|
|
_onEject: function(source, res) {
|
|
|
|
try {
|
|
|
|
source.eject_with_operation_finish(res);
|
|
|
|
} catch (e) {
|
2012-06-20 16:35:29 -04:00
|
|
|
if (!e.matches(Gio.IOErrorEnum, Gio.IOErrorEnum.FAILED_HANDLED))
|
|
|
|
log('Unable to eject the drive ' + source.get_name()
|
|
|
|
+ ': ' + e.toString());
|
2011-06-23 10:08:17 -04:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
_onStop: function(drive, res) {
|
|
|
|
try {
|
|
|
|
drive.stop_finish(res);
|
|
|
|
} catch (e) {
|
2012-06-20 16:35:29 -04:00
|
|
|
if (!e.matches(Gio.IOErrorEnum, Gio.IOErrorEnum.FAILED_HANDLED))
|
|
|
|
log('Unable to stop the drive ' + drive.get_name()
|
|
|
|
+ ': ' + e.toString());
|
2011-06-23 10:08:17 -04:00
|
|
|
}
|
|
|
|
},
|
2011-11-20 12:56:27 -05:00
|
|
|
});
|
2011-07-12 09:47:43 -04:00
|
|
|
|
2011-11-20 10:12:02 -05:00
|
|
|
const AutorunResidentSource = new Lang.Class({
|
|
|
|
Name: 'AutorunResidentSource',
|
|
|
|
Extends: MessageTray.Source,
|
2011-07-12 09:47:43 -04:00
|
|
|
|
2012-09-02 21:23:50 -04:00
|
|
|
_init: function(manager) {
|
2012-05-30 09:58:37 -04:00
|
|
|
this.parent(_("Removable Devices"), 'media-removable');
|
2011-07-12 09:47:43 -04:00
|
|
|
|
|
|
|
this._mounts = [];
|
|
|
|
|
2012-09-02 21:23:50 -04:00
|
|
|
this._manager = manager;
|
2012-09-04 20:24:56 -04:00
|
|
|
this._notification = new AutorunResidentNotification(this._manager, this);
|
2011-07-12 09:47:43 -04:00
|
|
|
},
|
|
|
|
|
2012-10-16 11:08:54 -04:00
|
|
|
_createPolicy: function() {
|
|
|
|
return new MessageTray.NotificationPolicy({ showInLockScreen: false });
|
|
|
|
},
|
|
|
|
|
2012-09-05 11:34:01 -04:00
|
|
|
buildRightClickMenu: function() {
|
|
|
|
return null;
|
|
|
|
},
|
|
|
|
|
2011-07-12 10:37:14 -04:00
|
|
|
addMount: function(mount, apps) {
|
2012-06-19 15:06:44 -04:00
|
|
|
if (!shouldAutorunMount(mount, false))
|
2011-07-12 09:47:43 -04:00
|
|
|
return;
|
|
|
|
|
|
|
|
let filtered = this._mounts.filter(function (element) {
|
|
|
|
return (element.mount == mount);
|
|
|
|
});
|
|
|
|
|
|
|
|
if (filtered.length != 0)
|
|
|
|
return;
|
|
|
|
|
2011-07-12 10:37:14 -04:00
|
|
|
let element = { mount: mount, apps: apps };
|
2011-07-12 09:47:43 -04:00
|
|
|
this._mounts.push(element);
|
|
|
|
this._redisplay();
|
|
|
|
},
|
|
|
|
|
|
|
|
removeMount: function(mount) {
|
|
|
|
this._mounts =
|
|
|
|
this._mounts.filter(function (element) {
|
|
|
|
return (element.mount != mount);
|
|
|
|
});
|
|
|
|
|
|
|
|
this._redisplay();
|
|
|
|
},
|
|
|
|
|
|
|
|
_redisplay: function() {
|
|
|
|
if (this._mounts.length == 0) {
|
|
|
|
this._notification.destroy();
|
|
|
|
this.destroy();
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
this._notification.updateForMounts(this._mounts);
|
|
|
|
|
|
|
|
// add ourselves as a source, and push the notification
|
|
|
|
if (!Main.messageTray.contains(this)) {
|
|
|
|
Main.messageTray.add(this);
|
|
|
|
this.pushNotification(this._notification);
|
|
|
|
}
|
|
|
|
}
|
2011-11-20 10:12:02 -05:00
|
|
|
});
|
2011-07-12 09:47:43 -04:00
|
|
|
|
2011-11-20 10:12:02 -05:00
|
|
|
const AutorunResidentNotification = new Lang.Class({
|
|
|
|
Name: 'AutorunResidentNotification',
|
|
|
|
Extends: MessageTray.Notification,
|
2011-07-12 09:47:43 -04:00
|
|
|
|
2012-09-02 21:23:50 -04:00
|
|
|
_init: function(manager, source) {
|
2011-11-20 10:12:02 -05:00
|
|
|
this.parent(source, source.title, null, { customContent: true });
|
2011-07-12 09:47:43 -04:00
|
|
|
|
|
|
|
// set the notification as resident
|
|
|
|
this.setResident(true);
|
|
|
|
|
|
|
|
this._layout = new St.BoxLayout ({ style_class: 'hotplug-resident-box',
|
|
|
|
vertical: true });
|
2012-09-02 21:23:50 -04:00
|
|
|
this._manager = manager;
|
2011-07-12 09:47:43 -04:00
|
|
|
|
|
|
|
this.addActor(this._layout,
|
|
|
|
{ x_expand: true,
|
|
|
|
x_fill: true });
|
|
|
|
},
|
|
|
|
|
|
|
|
updateForMounts: function(mounts) {
|
|
|
|
// remove all the layout content
|
2012-02-16 13:27:09 -05:00
|
|
|
this._layout.destroy_all_children();
|
2011-07-12 09:47:43 -04:00
|
|
|
|
|
|
|
for (let idx = 0; idx < mounts.length; idx++) {
|
|
|
|
let element = mounts[idx];
|
|
|
|
|
2011-07-12 10:37:14 -04:00
|
|
|
let actor = this._itemForMount(element.mount, element.apps);
|
2011-07-12 09:47:43 -04:00
|
|
|
this._layout.add(actor, { x_fill: true,
|
|
|
|
expand: true });
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2011-07-12 10:37:14 -04:00
|
|
|
_itemForMount: function(mount, apps) {
|
2011-07-12 09:47:43 -04:00
|
|
|
let item = new St.BoxLayout();
|
|
|
|
|
|
|
|
// prepare the mount button content
|
|
|
|
let mountLayout = new St.BoxLayout();
|
|
|
|
|
|
|
|
let mountIcon = new St.Icon({ gicon: mount.get_icon(),
|
|
|
|
style_class: 'hotplug-resident-mount-icon' });
|
|
|
|
mountLayout.add_actor(mountIcon);
|
|
|
|
|
|
|
|
let labelBin = new St.Bin({ y_align: St.Align.MIDDLE });
|
|
|
|
let mountLabel =
|
|
|
|
new St.Label({ text: mount.get_name(),
|
|
|
|
style_class: 'hotplug-resident-mount-label',
|
|
|
|
track_hover: true,
|
|
|
|
reactive: true });
|
|
|
|
labelBin.add_actor(mountLabel);
|
|
|
|
mountLayout.add_actor(labelBin);
|
|
|
|
|
|
|
|
let mountButton = new St.Button({ child: mountLayout,
|
|
|
|
x_align: St.Align.START,
|
|
|
|
x_fill: true,
|
|
|
|
style_class: 'hotplug-resident-mount',
|
|
|
|
button_mask: St.ButtonMask.ONE });
|
|
|
|
item.add(mountButton, { x_align: St.Align.START,
|
|
|
|
expand: true });
|
|
|
|
|
|
|
|
let ejectIcon =
|
2012-10-13 08:29:06 -04:00
|
|
|
new St.Icon({ icon_name: 'media-eject-symbolic',
|
2011-07-12 09:47:43 -04:00
|
|
|
style_class: 'hotplug-resident-eject-icon' });
|
|
|
|
|
|
|
|
let ejectButton =
|
|
|
|
new St.Button({ style_class: 'hotplug-resident-eject-button',
|
|
|
|
button_mask: St.ButtonMask.ONE,
|
|
|
|
child: ejectIcon });
|
|
|
|
item.add(ejectButton, { x_align: St.Align.END });
|
|
|
|
|
|
|
|
// now connect signals
|
|
|
|
mountButton.connect('clicked', Lang.bind(this, function(actor, event) {
|
2012-09-04 20:24:56 -04:00
|
|
|
startAppForMount(apps[0], mount);
|
2011-07-12 09:47:43 -04:00
|
|
|
}));
|
|
|
|
|
|
|
|
ejectButton.connect('clicked', Lang.bind(this, function() {
|
2012-09-02 21:23:50 -04:00
|
|
|
this._manager.ejectMount(mount);
|
2011-07-12 09:47:43 -04:00
|
|
|
}));
|
|
|
|
|
|
|
|
return item;
|
|
|
|
},
|
2011-11-20 10:12:02 -05:00
|
|
|
});
|
2011-07-12 09:47:43 -04:00
|
|
|
|
2011-11-20 12:56:27 -05:00
|
|
|
const AutorunTransientDispatcher = new Lang.Class({
|
|
|
|
Name: 'AutorunTransientDispatcher',
|
2011-07-12 09:47:43 -04:00
|
|
|
|
2012-09-02 21:23:50 -04:00
|
|
|
_init: function(manager) {
|
|
|
|
this._manager = manager;
|
2011-07-12 09:47:43 -04:00
|
|
|
this._sources = [];
|
|
|
|
this._settings = new Gio.Settings({ schema: SETTINGS_SCHEMA });
|
|
|
|
},
|
|
|
|
|
2011-07-11 09:31:56 -04:00
|
|
|
_getAutorunSettingForType: function(contentType) {
|
|
|
|
let runApp = this._settings.get_strv(SETTING_START_APP);
|
|
|
|
if (runApp.indexOf(contentType) != -1)
|
|
|
|
return AutorunSetting.RUN;
|
|
|
|
|
|
|
|
let ignore = this._settings.get_strv(SETTING_IGNORE);
|
|
|
|
if (ignore.indexOf(contentType) != -1)
|
|
|
|
return AutorunSetting.IGNORE;
|
|
|
|
|
|
|
|
let openFiles = this._settings.get_strv(SETTING_OPEN_FOLDER);
|
|
|
|
if (openFiles.indexOf(contentType) != -1)
|
|
|
|
return AutorunSetting.FILES;
|
|
|
|
|
|
|
|
return AutorunSetting.ASK;
|
|
|
|
},
|
|
|
|
|
2011-07-12 09:47:43 -04:00
|
|
|
_getSourceForMount: function(mount) {
|
|
|
|
let filtered =
|
|
|
|
this._sources.filter(function (source) {
|
|
|
|
return (source.mount == mount);
|
|
|
|
});
|
|
|
|
|
|
|
|
// we always make sure not to add two sources for the same
|
|
|
|
// mount in addMount(), so it's safe to assume filtered.length
|
|
|
|
// is always either 1 or 0.
|
|
|
|
if (filtered.length == 1)
|
|
|
|
return filtered[0];
|
|
|
|
|
|
|
|
return null;
|
|
|
|
},
|
|
|
|
|
2011-07-12 10:37:14 -04:00
|
|
|
_addSource: function(mount, apps) {
|
2011-07-11 09:31:56 -04:00
|
|
|
// if we already have a source showing for this
|
|
|
|
// mount, return
|
|
|
|
if (this._getSourceForMount(mount))
|
|
|
|
return;
|
|
|
|
|
|
|
|
// add a new source
|
2012-09-02 21:23:50 -04:00
|
|
|
this._sources.push(new AutorunTransientSource(this._manager, mount, apps));
|
2011-07-11 09:31:56 -04:00
|
|
|
},
|
|
|
|
|
2011-07-12 10:37:14 -04:00
|
|
|
addMount: function(mount, apps, contentTypes) {
|
2011-07-12 09:47:43 -04:00
|
|
|
// if autorun is disabled globally, return
|
|
|
|
if (this._settings.get_boolean(SETTING_DISABLE_AUTORUN))
|
|
|
|
return;
|
|
|
|
|
|
|
|
// if the mount doesn't want to be autorun, return
|
2012-06-19 15:06:44 -04:00
|
|
|
if (!shouldAutorunMount(mount, true))
|
2011-07-12 09:47:43 -04:00
|
|
|
return;
|
|
|
|
|
2011-07-11 09:31:56 -04:00
|
|
|
let setting = this._getAutorunSettingForType(contentTypes[0]);
|
|
|
|
|
|
|
|
// check at the settings for the first content type
|
|
|
|
// to see whether we should ask
|
|
|
|
if (setting == AutorunSetting.IGNORE)
|
|
|
|
return; // return right away
|
|
|
|
|
|
|
|
let success = false;
|
|
|
|
let app = null;
|
|
|
|
|
|
|
|
if (setting == AutorunSetting.RUN) {
|
2011-10-03 16:17:32 -04:00
|
|
|
app = Gio.app_info_get_default_for_type(contentTypes[0], false);
|
2011-07-11 09:31:56 -04:00
|
|
|
} else if (setting == AutorunSetting.FILES) {
|
|
|
|
app = Gio.app_info_get_default_for_type('inode/directory', false);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (app)
|
|
|
|
success = startAppForMount(app, mount);
|
|
|
|
|
|
|
|
// 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)
|
2011-07-12 10:37:14 -04:00
|
|
|
this._addSource(mount, apps);
|
2011-07-12 09:47:43 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
removeMount: function(mount) {
|
|
|
|
let source = this._getSourceForMount(mount);
|
|
|
|
|
|
|
|
// if we aren't tracking this mount, don't do anything
|
|
|
|
if (!source)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// destroy the notification source
|
|
|
|
source.destroy();
|
|
|
|
}
|
2011-11-20 12:56:27 -05:00
|
|
|
});
|
2011-07-12 09:47:43 -04:00
|
|
|
|
2011-11-20 10:12:02 -05:00
|
|
|
const AutorunTransientSource = new Lang.Class({
|
|
|
|
Name: 'AutorunTransientSource',
|
|
|
|
Extends: MessageTray.Source,
|
2011-07-12 09:47:43 -04:00
|
|
|
|
2012-09-02 21:23:50 -04:00
|
|
|
_init: function(manager, mount, apps) {
|
|
|
|
this._manager = manager;
|
2011-07-12 09:47:43 -04:00
|
|
|
this.mount = mount;
|
2011-07-12 10:37:14 -04:00
|
|
|
this.apps = apps;
|
2011-07-12 09:47:43 -04:00
|
|
|
|
2011-10-08 18:00:32 -04:00
|
|
|
this.parent(mount.get_name());
|
|
|
|
|
2012-09-02 21:23:50 -04:00
|
|
|
this._notification = new AutorunTransientNotification(this._manager, this);
|
2011-07-12 09:47:43 -04:00
|
|
|
|
|
|
|
// add ourselves as a source, and popup the notification
|
|
|
|
Main.messageTray.add(this);
|
|
|
|
this.notify(this._notification);
|
|
|
|
},
|
|
|
|
|
2012-09-15 02:10:15 -04:00
|
|
|
getIcon: function() {
|
|
|
|
return this.mount.get_icon();
|
2011-07-12 09:47:43 -04:00
|
|
|
}
|
2011-11-20 10:12:02 -05:00
|
|
|
});
|
2011-07-12 09:47:43 -04:00
|
|
|
|
2011-11-20 10:12:02 -05:00
|
|
|
const AutorunTransientNotification = new Lang.Class({
|
|
|
|
Name: 'AutorunTransientNotification',
|
|
|
|
Extends: MessageTray.Notification,
|
2011-07-12 09:47:43 -04:00
|
|
|
|
2012-09-02 21:23:50 -04:00
|
|
|
_init: function(manager, source) {
|
2011-11-20 10:12:02 -05:00
|
|
|
this.parent(source, source.title, null, { customContent: true });
|
2011-07-12 09:47:43 -04:00
|
|
|
|
2012-09-02 21:23:50 -04:00
|
|
|
this._manager = manager;
|
2011-07-12 09:47:43 -04:00
|
|
|
this._box = new St.BoxLayout({ style_class: 'hotplug-transient-box',
|
|
|
|
vertical: true });
|
|
|
|
this.addActor(this._box);
|
|
|
|
|
|
|
|
this._mount = source.mount;
|
|
|
|
|
2011-07-12 10:37:14 -04:00
|
|
|
source.apps.forEach(Lang.bind(this, function (app) {
|
|
|
|
let actor = this._buttonForApp(app);
|
2011-07-12 09:47:43 -04:00
|
|
|
|
|
|
|
if (actor)
|
|
|
|
this._box.add(actor, { x_fill: true,
|
|
|
|
x_align: St.Align.START });
|
|
|
|
}));
|
|
|
|
|
|
|
|
this._box.add(this._buttonForEject(), { x_fill: true,
|
|
|
|
x_align: St.Align.START });
|
|
|
|
|
|
|
|
// set the notification to transient and urgent, so that it
|
|
|
|
// expands out
|
|
|
|
this.setTransient(true);
|
|
|
|
this.setUrgency(MessageTray.Urgency.CRITICAL);
|
|
|
|
},
|
|
|
|
|
2011-07-12 10:37:14 -04:00
|
|
|
_buttonForApp: function(app) {
|
2011-07-12 09:47:43 -04:00
|
|
|
let box = new St.BoxLayout();
|
|
|
|
let icon = new St.Icon({ gicon: app.get_icon(),
|
|
|
|
style_class: 'hotplug-notification-item-icon' });
|
|
|
|
box.add(icon);
|
|
|
|
|
|
|
|
let label = new St.Bin({ y_align: St.Align.MIDDLE,
|
|
|
|
child: new St.Label
|
2011-12-03 06:56:04 -05:00
|
|
|
({ text: _("Open with %s").format(app.get_name()) })
|
2011-07-12 09:47:43 -04:00
|
|
|
});
|
|
|
|
box.add(label);
|
|
|
|
|
|
|
|
let button = new St.Button({ child: box,
|
2011-07-12 10:37:14 -04:00
|
|
|
x_fill: true,
|
|
|
|
x_align: St.Align.START,
|
2011-07-12 09:47:43 -04:00
|
|
|
button_mask: St.ButtonMask.ONE,
|
|
|
|
style_class: 'hotplug-notification-item' });
|
|
|
|
|
|
|
|
button.connect('clicked', Lang.bind(this, function() {
|
|
|
|
startAppForMount(app, this._mount);
|
|
|
|
this.destroy();
|
|
|
|
}));
|
|
|
|
|
|
|
|
return button;
|
|
|
|
},
|
|
|
|
|
|
|
|
_buttonForEject: function() {
|
|
|
|
let box = new St.BoxLayout();
|
2012-10-13 08:29:06 -04:00
|
|
|
let icon = new St.Icon({ icon_name: 'media-eject-symbolic',
|
2011-07-12 09:47:43 -04:00
|
|
|
style_class: 'hotplug-notification-item-icon' });
|
|
|
|
box.add(icon);
|
|
|
|
|
|
|
|
let label = new St.Bin({ y_align: St.Align.MIDDLE,
|
|
|
|
child: new St.Label
|
|
|
|
({ text: _("Eject") })
|
|
|
|
});
|
|
|
|
box.add(label);
|
|
|
|
|
|
|
|
let button = new St.Button({ child: box,
|
|
|
|
x_fill: true,
|
|
|
|
x_align: St.Align.START,
|
|
|
|
button_mask: St.ButtonMask.ONE,
|
|
|
|
style_class: 'hotplug-notification-item' });
|
|
|
|
|
|
|
|
button.connect('clicked', Lang.bind(this, function() {
|
2012-09-02 21:23:50 -04:00
|
|
|
this._manager.ejectMount(this._mount);
|
2011-07-12 09:47:43 -04:00
|
|
|
}));
|
|
|
|
|
|
|
|
return button;
|
|
|
|
}
|
2011-11-20 10:12:02 -05:00
|
|
|
});
|
2011-07-12 09:47:43 -04:00
|
|
|
|
2012-09-02 21:23:50 -04:00
|
|
|
const Component = AutorunManager;
|