2012-05-16 18:26:44 -04:00
|
|
|
// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
|
|
|
|
|
2012-11-28 15:14:21 -05:00
|
|
|
const Gio = imports.gi.Gio;
|
|
|
|
const GLib = imports.gi.GLib;
|
2012-05-16 18:26:44 -04:00
|
|
|
const Lang = imports.lang;
|
2012-11-29 12:20:43 -05:00
|
|
|
const Mainloop = imports.mainloop;
|
2012-09-01 08:42:53 -04:00
|
|
|
const Signals = imports.signals;
|
2012-05-16 18:26:44 -04:00
|
|
|
|
2012-11-29 12:20:43 -05:00
|
|
|
const FileUtils = imports.misc.fileUtils;
|
2012-05-17 09:50:51 -04:00
|
|
|
const Main = imports.ui.main;
|
2012-05-16 18:26:44 -04:00
|
|
|
const Params = imports.misc.params;
|
|
|
|
|
2012-09-03 21:26:37 -04:00
|
|
|
const DEFAULT_MODE = 'restrictive';
|
2012-05-16 18:26:44 -04:00
|
|
|
|
|
|
|
const _modes = {
|
2012-09-03 21:26:37 -04:00
|
|
|
'restrictive': {
|
2012-11-29 14:42:38 -05:00
|
|
|
parentMode: null,
|
2013-02-04 22:13:44 -05:00
|
|
|
stylesheetName: 'gnome-shell.css',
|
2013-06-06 10:40:02 -04:00
|
|
|
overridesSchema: 'org.gnome.shell.overrides',
|
2012-09-03 21:23:22 -04:00
|
|
|
hasOverview: false,
|
|
|
|
showCalendarEvents: false,
|
|
|
|
allowSettings: false,
|
|
|
|
allowExtensions: false,
|
2013-07-17 21:22:54 -04:00
|
|
|
allowScreencast: false,
|
2012-11-29 10:09:21 -05:00
|
|
|
enabledExtensions: [],
|
2012-09-03 21:23:22 -04:00
|
|
|
hasRunDialog: false,
|
|
|
|
hasWorkspaces: false,
|
|
|
|
hasWindows: false,
|
2012-08-26 10:53:08 -04:00
|
|
|
hasNotifications: false,
|
2012-09-03 21:26:37 -04:00
|
|
|
isLocked: false,
|
2012-09-04 13:28:19 -04:00
|
|
|
isGreeter: false,
|
2012-09-06 07:21:12 -04:00
|
|
|
isPrimary: false,
|
2012-09-04 13:28:19 -04:00
|
|
|
unlockDialog: null,
|
2012-09-03 21:23:22 -04:00
|
|
|
components: [],
|
2012-09-03 21:26:37 -04:00
|
|
|
panel: {
|
|
|
|
left: [],
|
|
|
|
center: [],
|
|
|
|
right: []
|
|
|
|
},
|
2012-09-21 16:19:27 -04:00
|
|
|
panelStyle: null
|
2012-09-03 21:26:37 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
'gdm': {
|
2012-08-26 10:53:08 -04:00
|
|
|
hasNotifications: true,
|
2012-09-04 13:28:19 -04:00
|
|
|
isGreeter: true,
|
2012-09-06 07:21:12 -04:00
|
|
|
isPrimary: true,
|
2012-09-04 13:28:19 -04:00
|
|
|
unlockDialog: imports.gdm.loginDialog.LoginDialog,
|
2012-09-05 06:50:16 -04:00
|
|
|
components: ['polkitAgent'],
|
2012-09-03 21:23:22 -04:00
|
|
|
panel: {
|
2013-03-22 20:29:23 -04:00
|
|
|
left: [],
|
2012-09-03 21:23:22 -04:00
|
|
|
center: ['dateMenu'],
|
2013-06-06 17:27:32 -04:00
|
|
|
right: ['a11yGreeter', 'keyboard', 'aggregateMenu'],
|
2012-09-21 16:19:27 -04:00
|
|
|
},
|
|
|
|
panelStyle: 'login-screen'
|
2012-09-03 21:23:22 -04:00
|
|
|
},
|
2012-05-16 18:26:44 -04:00
|
|
|
|
2012-09-01 08:42:53 -04:00
|
|
|
'lock-screen': {
|
2012-09-01 17:44:46 -04:00
|
|
|
isLocked: true,
|
2012-09-10 05:34:49 -04:00
|
|
|
isGreeter: undefined,
|
2012-09-04 13:28:19 -04:00
|
|
|
unlockDialog: undefined,
|
2012-09-20 02:53:20 -04:00
|
|
|
components: ['polkitAgent', 'telepathyClient'],
|
2012-09-01 08:42:53 -04:00
|
|
|
panel: {
|
2013-05-22 14:46:47 -04:00
|
|
|
left: [],
|
2012-09-01 08:42:53 -04:00
|
|
|
center: [],
|
2013-06-06 17:27:32 -04:00
|
|
|
right: ['aggregateMenu']
|
2012-09-01 08:42:53 -04:00
|
|
|
},
|
2012-09-21 16:19:27 -04:00
|
|
|
panelStyle: 'lock-screen'
|
2012-09-01 08:42:53 -04:00
|
|
|
},
|
|
|
|
|
2012-08-26 10:53:08 -04:00
|
|
|
'unlock-dialog': {
|
|
|
|
isLocked: true,
|
|
|
|
unlockDialog: undefined,
|
2012-09-20 02:53:20 -04:00
|
|
|
components: ['polkitAgent', 'telepathyClient'],
|
2012-08-26 10:53:08 -04:00
|
|
|
panel: {
|
2013-05-22 14:46:47 -04:00
|
|
|
left: [],
|
2012-08-26 10:53:08 -04:00
|
|
|
center: [],
|
2013-06-06 17:27:32 -04:00
|
|
|
right: ['a11y', 'keyboard', 'aggregateMenu']
|
2012-08-26 10:53:08 -04:00
|
|
|
},
|
2012-09-21 16:19:27 -04:00
|
|
|
panelStyle: 'unlock-screen'
|
2012-08-26 10:53:08 -04:00
|
|
|
},
|
|
|
|
|
2012-09-03 21:23:22 -04:00
|
|
|
'user': {
|
|
|
|
hasOverview: true,
|
|
|
|
showCalendarEvents: true,
|
|
|
|
allowSettings: true,
|
|
|
|
allowExtensions: true,
|
2013-07-17 21:22:54 -04:00
|
|
|
allowScreencast: true,
|
2012-09-03 21:23:22 -04:00
|
|
|
hasRunDialog: true,
|
|
|
|
hasWorkspaces: true,
|
|
|
|
hasWindows: true,
|
2012-08-26 10:53:08 -04:00
|
|
|
hasNotifications: true,
|
2012-09-04 13:28:19 -04:00
|
|
|
isLocked: false,
|
2012-09-06 07:21:12 -04:00
|
|
|
isPrimary: true,
|
2012-08-26 10:53:08 -04:00
|
|
|
unlockDialog: imports.ui.unlockDialog.UnlockDialog,
|
2012-09-03 21:23:22 -04:00
|
|
|
components: ['networkAgent', 'polkitAgent', 'telepathyClient',
|
2013-07-17 21:22:54 -04:00
|
|
|
'keyring', 'autorunManager', 'automountManager'],
|
2012-09-03 21:23:22 -04:00
|
|
|
panel: {
|
|
|
|
left: ['activities', 'appMenu'],
|
|
|
|
center: ['dateMenu'],
|
2013-06-06 17:27:32 -04:00
|
|
|
right: ['a11y', 'keyboard', 'aggregateMenu']
|
2012-09-03 21:23:22 -04:00
|
|
|
}
|
|
|
|
}
|
2012-05-16 18:26:44 -04:00
|
|
|
};
|
|
|
|
|
2013-11-04 10:07:44 -05:00
|
|
|
function _loadMode(file, info) {
|
2012-11-29 12:20:43 -05:00
|
|
|
let name = info.get_name();
|
|
|
|
let suffix = name.indexOf('.json');
|
|
|
|
let modeName = suffix == -1 ? name : name.slice(name, suffix);
|
|
|
|
|
2013-11-04 10:07:44 -05:00
|
|
|
if (_modes.hasOwnProperty(modeName))
|
2012-11-29 12:20:43 -05:00
|
|
|
return;
|
|
|
|
|
|
|
|
let fileContent, success, tag, newMode;
|
2012-11-28 15:14:21 -05:00
|
|
|
try {
|
2012-11-29 12:20:43 -05:00
|
|
|
[success, fileContent, tag] = file.load_contents(null);
|
|
|
|
newMode = JSON.parse(fileContent);
|
2012-11-28 15:14:21 -05:00
|
|
|
} catch(e) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-11-04 10:07:44 -05:00
|
|
|
_modes[modeName] = {};
|
2012-11-29 12:20:43 -05:00
|
|
|
let propBlacklist = ['unlockDialog'];
|
2013-12-06 15:25:15 -05:00
|
|
|
for (let prop in _modes[DEFAULT_MODE]) {
|
2012-11-29 12:20:43 -05:00
|
|
|
if (newMode[prop] !== undefined &&
|
|
|
|
propBlacklist.indexOf(prop) == -1)
|
2013-12-06 15:25:15 -05:00
|
|
|
_modes[modeName][prop] = newMode[prop];
|
2012-11-28 15:14:21 -05:00
|
|
|
}
|
2013-11-04 10:07:44 -05:00
|
|
|
_modes[modeName]['isPrimary'] = true;
|
|
|
|
}
|
|
|
|
|
2013-12-06 15:28:23 -05:00
|
|
|
function _loadModes() {
|
2013-11-04 10:07:44 -05:00
|
|
|
FileUtils.collectFromDatadirs('modes', false, _loadMode);
|
2012-11-28 15:14:21 -05:00
|
|
|
}
|
|
|
|
|
2012-05-17 21:52:57 -04:00
|
|
|
function listModes() {
|
2013-12-06 15:28:23 -05:00
|
|
|
_loadModes();
|
2013-12-06 15:29:37 -05:00
|
|
|
Mainloop.idle_add(function() {
|
2013-12-06 15:28:23 -05:00
|
|
|
let names = Object.getOwnPropertyNames(_modes);
|
2012-11-29 12:20:43 -05:00
|
|
|
for (let i = 0; i < names.length; i++)
|
|
|
|
if (_modes[names[i]].isPrimary)
|
|
|
|
print(names[i]);
|
|
|
|
Mainloop.quit('listModes');
|
|
|
|
});
|
|
|
|
Mainloop.run('listModes');
|
2012-05-17 21:52:57 -04:00
|
|
|
}
|
|
|
|
|
2012-05-16 18:26:44 -04:00
|
|
|
const SessionMode = new Lang.Class({
|
|
|
|
Name: 'SessionMode',
|
|
|
|
|
2013-11-04 10:07:44 -05:00
|
|
|
_init: function() {
|
2013-12-06 15:31:46 -05:00
|
|
|
_loadModes();
|
2013-11-04 10:07:44 -05:00
|
|
|
let isPrimary = (_modes[global.session_mode] &&
|
|
|
|
_modes[global.session_mode].isPrimary);
|
|
|
|
let mode = isPrimary ? global.session_mode : 'user';
|
|
|
|
this._modeStack = [mode];
|
|
|
|
this._sync();
|
2012-09-01 08:42:53 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
pushMode: function(mode) {
|
|
|
|
this._modeStack.push(mode);
|
|
|
|
this._sync();
|
|
|
|
},
|
|
|
|
|
|
|
|
popMode: function(mode) {
|
|
|
|
if (this.currentMode != mode || this._modeStack.length === 1)
|
|
|
|
throw new Error("Invalid SessionMode.popMode");
|
|
|
|
this._modeStack.pop();
|
|
|
|
this._sync();
|
|
|
|
},
|
|
|
|
|
2012-08-26 10:53:08 -04:00
|
|
|
switchMode: function(to) {
|
|
|
|
if (this.currentMode == to)
|
|
|
|
return;
|
|
|
|
this._modeStack[this._modeStack.length - 1] = to;
|
|
|
|
this._sync();
|
|
|
|
},
|
|
|
|
|
2012-09-01 08:42:53 -04:00
|
|
|
get currentMode() {
|
|
|
|
return this._modeStack[this._modeStack.length - 1];
|
|
|
|
},
|
2012-05-16 18:26:44 -04:00
|
|
|
|
2012-09-01 08:42:53 -04:00
|
|
|
_sync: function() {
|
2013-11-04 10:07:44 -05:00
|
|
|
let params = _modes[this.currentMode];
|
2012-11-29 14:42:38 -05:00
|
|
|
let defaults;
|
|
|
|
if (params.parentMode)
|
2013-11-04 10:07:44 -05:00
|
|
|
defaults = Params.parse(_modes[params.parentMode],
|
|
|
|
_modes[DEFAULT_MODE]);
|
2012-11-29 14:42:38 -05:00
|
|
|
else
|
2013-11-04 10:07:44 -05:00
|
|
|
defaults = _modes[DEFAULT_MODE];
|
2012-11-29 14:42:38 -05:00
|
|
|
params = Params.parse(params, defaults);
|
2012-05-17 09:50:51 -04:00
|
|
|
|
2012-09-04 13:28:19 -04:00
|
|
|
// A simplified version of Lang.copyProperties, handles
|
|
|
|
// undefined as a special case for "no change / inherit from previous mode"
|
|
|
|
for (let prop in params) {
|
|
|
|
if (params[prop] !== undefined)
|
|
|
|
this[prop] = params[prop];
|
|
|
|
}
|
2012-05-17 09:50:51 -04:00
|
|
|
|
2012-09-01 08:42:53 -04:00
|
|
|
this.emit('updated');
|
2012-09-04 13:28:19 -04:00
|
|
|
}
|
2012-05-16 18:26:44 -04:00
|
|
|
});
|
2012-09-01 08:42:53 -04:00
|
|
|
Signals.addSignalMethods(SessionMode.prototype);
|