2012-05-16 22:26:44 +00:00
|
|
|
// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
|
|
|
|
|
2012-11-28 20:14:21 +00:00
|
|
|
const Gio = imports.gi.Gio;
|
|
|
|
const GLib = imports.gi.GLib;
|
2012-05-16 22:26:44 +00:00
|
|
|
const Lang = imports.lang;
|
2012-11-29 17:20:43 +00:00
|
|
|
const Mainloop = imports.mainloop;
|
2012-09-01 12:42:53 +00:00
|
|
|
const Signals = imports.signals;
|
2012-05-16 22:26:44 +00:00
|
|
|
|
2012-11-29 17:20:43 +00:00
|
|
|
const FileUtils = imports.misc.fileUtils;
|
2012-05-17 13:50:51 +00:00
|
|
|
const Main = imports.ui.main;
|
2012-05-16 22:26:44 +00:00
|
|
|
const Params = imports.misc.params;
|
|
|
|
|
2012-09-04 01:26:37 +00:00
|
|
|
const DEFAULT_MODE = 'restrictive';
|
2012-05-16 22:26:44 +00:00
|
|
|
|
|
|
|
const _modes = {
|
2012-09-04 01:26:37 +00:00
|
|
|
'restrictive': {
|
2012-11-29 19:42:38 +00:00
|
|
|
parentMode: null,
|
2013-02-05 03:13:44 +00:00
|
|
|
stylesheetName: 'gnome-shell.css',
|
2012-09-04 01:23:22 +00:00
|
|
|
hasOverview: false,
|
|
|
|
showCalendarEvents: false,
|
|
|
|
allowSettings: false,
|
|
|
|
allowExtensions: false,
|
2012-11-29 15:09:21 +00:00
|
|
|
enabledExtensions: [],
|
2012-09-04 01:23:22 +00:00
|
|
|
hasRunDialog: false,
|
|
|
|
hasWorkspaces: false,
|
|
|
|
hasWindows: false,
|
2012-08-26 14:53:08 +00:00
|
|
|
hasNotifications: false,
|
2012-09-04 01:26:37 +00:00
|
|
|
isLocked: false,
|
2012-09-04 17:28:19 +00:00
|
|
|
isGreeter: false,
|
2012-09-06 11:21:12 +00:00
|
|
|
isPrimary: false,
|
2012-09-04 17:28:19 +00:00
|
|
|
unlockDialog: null,
|
2012-09-04 01:23:22 +00:00
|
|
|
components: [],
|
2012-09-04 01:26:37 +00:00
|
|
|
panel: {
|
|
|
|
left: [],
|
|
|
|
center: [],
|
|
|
|
right: []
|
|
|
|
},
|
2012-09-21 20:19:27 +00:00
|
|
|
panelStyle: null
|
2012-09-04 01:26:37 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
'gdm': {
|
2012-08-26 14:53:08 +00:00
|
|
|
hasNotifications: true,
|
2012-09-04 17:28:19 +00:00
|
|
|
isGreeter: true,
|
2012-09-06 11:21:12 +00:00
|
|
|
isPrimary: true,
|
2012-09-04 17:28:19 +00:00
|
|
|
unlockDialog: imports.gdm.loginDialog.LoginDialog,
|
2012-09-05 10:50:16 +00:00
|
|
|
components: ['polkitAgent'],
|
2012-09-04 01:23:22 +00:00
|
|
|
panel: {
|
2012-10-17 16:33:47 +00:00
|
|
|
left: ['logo'],
|
2012-09-04 01:23:22 +00:00
|
|
|
center: ['dateMenu'],
|
2012-08-13 17:04:03 +00:00
|
|
|
right: ['a11yGreeter', 'display', 'keyboard',
|
2012-09-04 01:23:22 +00:00
|
|
|
'volume', 'battery', 'powerMenu']
|
2012-09-21 20:19:27 +00:00
|
|
|
},
|
|
|
|
panelStyle: 'login-screen'
|
2012-09-04 01:23:22 +00:00
|
|
|
},
|
2012-05-16 22:26:44 +00:00
|
|
|
|
2012-09-01 12:42:53 +00:00
|
|
|
'lock-screen': {
|
2012-09-01 21:44:46 +00:00
|
|
|
isLocked: true,
|
2012-09-10 09:34:49 +00:00
|
|
|
isGreeter: undefined,
|
2012-09-04 17:28:19 +00:00
|
|
|
unlockDialog: undefined,
|
2012-09-20 06:53:20 +00:00
|
|
|
components: ['polkitAgent', 'telepathyClient'],
|
2012-09-01 12:42:53 +00:00
|
|
|
panel: {
|
|
|
|
left: ['userMenu'],
|
|
|
|
center: [],
|
|
|
|
right: ['lockScreen']
|
|
|
|
},
|
2012-09-21 20:19:27 +00:00
|
|
|
panelStyle: 'lock-screen'
|
2012-09-01 12:42:53 +00:00
|
|
|
},
|
|
|
|
|
2012-08-26 14:53:08 +00:00
|
|
|
'unlock-dialog': {
|
|
|
|
isLocked: true,
|
|
|
|
unlockDialog: undefined,
|
2012-09-20 06:53:20 +00:00
|
|
|
components: ['polkitAgent', 'telepathyClient'],
|
2012-08-26 14:53:08 +00:00
|
|
|
panel: {
|
|
|
|
left: ['userMenu'],
|
|
|
|
center: [],
|
|
|
|
right: ['a11y', 'keyboard', 'lockScreen']
|
|
|
|
},
|
2012-09-21 20:19:27 +00:00
|
|
|
panelStyle: 'unlock-screen'
|
2012-08-26 14:53:08 +00:00
|
|
|
},
|
|
|
|
|
2012-09-04 01:23:22 +00:00
|
|
|
'initial-setup': {
|
2012-09-06 11:21:12 +00:00
|
|
|
isPrimary: true,
|
2012-09-04 01:23:22 +00:00
|
|
|
components: ['keyring'],
|
|
|
|
panel: {
|
|
|
|
left: [],
|
|
|
|
center: ['dateMenu'],
|
2012-08-13 17:04:03 +00:00
|
|
|
right: ['a11yGreeter', 'keyboard', 'volume']
|
2012-09-04 01:23:22 +00:00
|
|
|
}
|
|
|
|
},
|
2012-05-24 03:37:09 +00:00
|
|
|
|
2012-09-04 01:23:22 +00:00
|
|
|
'user': {
|
|
|
|
hasOverview: true,
|
|
|
|
showCalendarEvents: true,
|
|
|
|
allowSettings: true,
|
|
|
|
allowExtensions: true,
|
|
|
|
hasRunDialog: true,
|
|
|
|
hasWorkspaces: true,
|
|
|
|
hasWindows: true,
|
2012-08-26 14:53:08 +00:00
|
|
|
hasNotifications: true,
|
2012-09-04 17:28:19 +00:00
|
|
|
isLocked: false,
|
2012-09-06 11:21:12 +00:00
|
|
|
isPrimary: true,
|
2012-08-26 14:53:08 +00:00
|
|
|
unlockDialog: imports.ui.unlockDialog.UnlockDialog,
|
2012-09-04 01:23:22 +00:00
|
|
|
components: ['networkAgent', 'polkitAgent', 'telepathyClient',
|
|
|
|
'keyring', 'recorder', 'autorunManager', 'automountManager'],
|
|
|
|
panel: {
|
|
|
|
left: ['activities', 'appMenu'],
|
|
|
|
center: ['dateMenu'],
|
|
|
|
right: ['a11y', 'keyboard', 'volume', 'bluetooth',
|
|
|
|
'network', 'battery', 'userMenu']
|
|
|
|
}
|
|
|
|
}
|
2012-05-16 22:26:44 +00:00
|
|
|
};
|
|
|
|
|
2012-11-29 17:20:43 +00:00
|
|
|
function _getModes(modesLoadedCallback) {
|
|
|
|
FileUtils.collectFromDatadirsAsync('modes',
|
|
|
|
{ processFile: _loadMode,
|
|
|
|
loadedCallback: modesLoadedCallback,
|
|
|
|
data: _modes });
|
2012-11-28 20:14:21 +00:00
|
|
|
}
|
|
|
|
|
2012-11-29 17:20:43 +00:00
|
|
|
function _loadMode(file, info, loadedData) {
|
|
|
|
let name = info.get_name();
|
|
|
|
let suffix = name.indexOf('.json');
|
|
|
|
let modeName = suffix == -1 ? name : name.slice(name, suffix);
|
|
|
|
|
|
|
|
if (loadedData.hasOwnProperty(modeName))
|
|
|
|
return;
|
|
|
|
|
|
|
|
let fileContent, success, tag, newMode;
|
2012-11-28 20:14:21 +00:00
|
|
|
try {
|
2012-11-29 17:20:43 +00:00
|
|
|
[success, fileContent, tag] = file.load_contents(null);
|
|
|
|
newMode = JSON.parse(fileContent);
|
2012-11-28 20:14:21 +00:00
|
|
|
} catch(e) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-11-29 17:20:43 +00:00
|
|
|
loadedData[modeName] = {};
|
|
|
|
let propBlacklist = ['unlockDialog'];
|
|
|
|
for (let prop in loadedData[DEFAULT_MODE]) {
|
|
|
|
if (newMode[prop] !== undefined &&
|
|
|
|
propBlacklist.indexOf(prop) == -1)
|
|
|
|
loadedData[modeName][prop]= newMode[prop];
|
2012-11-28 20:14:21 +00:00
|
|
|
}
|
2012-11-29 17:20:43 +00:00
|
|
|
loadedData[modeName]['isPrimary'] = true;
|
2012-11-28 20:14:21 +00:00
|
|
|
}
|
|
|
|
|
2012-05-18 01:52:57 +00:00
|
|
|
function listModes() {
|
2012-11-29 17:20:43 +00:00
|
|
|
_getModes(function(modes) {
|
|
|
|
let names = Object.getOwnPropertyNames(modes);
|
|
|
|
for (let i = 0; i < names.length; i++)
|
|
|
|
if (_modes[names[i]].isPrimary)
|
|
|
|
print(names[i]);
|
|
|
|
Mainloop.quit('listModes');
|
|
|
|
});
|
|
|
|
Mainloop.run('listModes');
|
2012-05-18 01:52:57 +00:00
|
|
|
}
|
|
|
|
|
2012-05-16 22:26:44 +00:00
|
|
|
const SessionMode = new Lang.Class({
|
|
|
|
Name: 'SessionMode',
|
|
|
|
|
|
|
|
_init: function() {
|
2012-09-01 12:42:53 +00:00
|
|
|
global.connect('notify::session-mode', Lang.bind(this, this._sync));
|
2012-11-29 17:20:43 +00:00
|
|
|
this._modes = _modes;
|
|
|
|
this._modeStack = [DEFAULT_MODE];
|
2012-09-01 12:42:53 +00:00
|
|
|
this._sync();
|
2012-11-29 17:20:43 +00:00
|
|
|
|
|
|
|
_getModes(Lang.bind(this, function(modes) {
|
|
|
|
this._modes = modes;
|
|
|
|
let primary = modes[global.session_mode] &&
|
|
|
|
modes[global.session_mode].isPrimary;
|
|
|
|
let mode = primary ? global.session_mode : 'user';
|
|
|
|
this._modeStack = [mode];
|
|
|
|
this._sync();
|
|
|
|
}));
|
2012-09-01 12:42:53 +00: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 14:53:08 +00:00
|
|
|
switchMode: function(to) {
|
|
|
|
if (this.currentMode == to)
|
|
|
|
return;
|
|
|
|
this._modeStack[this._modeStack.length - 1] = to;
|
|
|
|
this._sync();
|
|
|
|
},
|
|
|
|
|
2012-09-01 12:42:53 +00:00
|
|
|
get currentMode() {
|
|
|
|
return this._modeStack[this._modeStack.length - 1];
|
|
|
|
},
|
2012-05-16 22:26:44 +00:00
|
|
|
|
2012-09-01 12:42:53 +00:00
|
|
|
_sync: function() {
|
2012-11-28 20:14:21 +00:00
|
|
|
let params = this._modes[this.currentMode];
|
2012-11-29 19:42:38 +00:00
|
|
|
let defaults;
|
|
|
|
if (params.parentMode)
|
|
|
|
defaults = Params.parse(this._modes[params.parentMode],
|
|
|
|
this._modes[DEFAULT_MODE]);
|
|
|
|
else
|
|
|
|
defaults = this._modes[DEFAULT_MODE];
|
|
|
|
params = Params.parse(params, defaults);
|
2012-05-17 13:50:51 +00:00
|
|
|
|
2012-09-04 17:28:19 +00: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 13:50:51 +00:00
|
|
|
|
2012-09-01 12:42:53 +00:00
|
|
|
this.emit('updated');
|
2012-09-04 17:28:19 +00:00
|
|
|
}
|
2012-05-16 22:26:44 +00:00
|
|
|
});
|
2012-09-01 12:42:53 +00:00
|
|
|
Signals.addSignalMethods(SessionMode.prototype);
|