1
// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
3
const Gio = imports.gi.Gio;
4
const GLib = imports.gi.GLib;
5
const Lang = imports.lang;
6
const Mainloop = imports.mainloop;
7
const Signals = imports.signals;
9
const FileUtils = imports.misc.fileUtils;
10
const Main = imports.ui.main;
11
const Params = imports.misc.params;
13
const DEFAULT_MODE = 'restrictive';
18
stylesheetName: 'gnome-shell.css',
19
overridesSchema: 'org.gnome.shell.overrides',
21
showCalendarEvents: false,
23
allowExtensions: false,
24
enabledExtensions: [],
28
hasNotifications: false,
43
hasNotifications: true,
46
unlockDialog: imports.gdm.loginDialog.LoginDialog,
47
components: ['polkitAgent'],
51
right: ['a11yGreeter', 'display', 'keyboard',
52
'volume', 'battery', 'powerMenu']
54
panelStyle: 'login-screen'
60
unlockDialog: undefined,
61
components: ['polkitAgent', 'telepathyClient'],
67
panelStyle: 'lock-screen'
72
unlockDialog: undefined,
73
components: ['polkitAgent', 'telepathyClient'],
77
right: ['a11y', 'keyboard', 'lockScreen']
79
panelStyle: 'unlock-screen'
85
components: ['networkAgent', 'keyring'],
89
right: ['a11yGreeter', 'keyboard', 'volume', 'battery']
95
showCalendarEvents: true,
97
allowExtensions: true,
101
hasNotifications: true,
104
unlockDialog: imports.ui.unlockDialog.UnlockDialog,
105
components: ['networkAgent', 'polkitAgent', 'telepathyClient',
106
'keyring', 'recorder', 'autorunManager', 'automountManager'],
108
left: ['activities', 'appMenu'],
109
center: ['dateMenu'],
110
right: ['a11y', 'keyboard', 'volume', 'bluetooth',
111
'network', 'battery', 'userMenu']
116
function _getModes(modesLoadedCallback) {
117
FileUtils.collectFromDatadirsAsync('modes',
118
{ processFile: _loadMode,
119
loadedCallback: modesLoadedCallback,
123
function _loadMode(file, info, loadedData) {
124
let name = info.get_name();
125
let suffix = name.indexOf('.json');
126
let modeName = suffix == -1 ? name : name.slice(name, suffix);
128
if (loadedData.hasOwnProperty(modeName))
131
let fileContent, success, tag, newMode;
133
[success, fileContent, tag] = file.load_contents(null);
134
newMode = JSON.parse(fileContent);
139
loadedData[modeName] = {};
140
let propBlacklist = ['unlockDialog'];
141
for (let prop in loadedData[DEFAULT_MODE]) {
142
if (newMode[prop] !== undefined &&
143
propBlacklist.indexOf(prop) == -1)
144
loadedData[modeName][prop]= newMode[prop];
146
loadedData[modeName]['isPrimary'] = true;
149
function listModes() {
150
_getModes(function(modes) {
151
let names = Object.getOwnPropertyNames(modes);
152
for (let i = 0; i < names.length; i++)
153
if (_modes[names[i]].isPrimary)
155
Mainloop.quit('listModes');
157
Mainloop.run('listModes');
160
const SessionMode = new Lang.Class({
164
_getModes(Lang.bind(this, function(modes) {
166
let primary = modes[global.session_mode] &&
167
modes[global.session_mode].isPrimary;
168
let mode = primary ? global.session_mode : 'user';
169
this._modeStack = [mode];
172
this.emit('sessions-loaded');
176
pushMode: function(mode) {
177
this._modeStack.push(mode);
181
popMode: function(mode) {
182
if (this.currentMode != mode || this._modeStack.length === 1)
183
throw new Error("Invalid SessionMode.popMode");
184
this._modeStack.pop();
188
switchMode: function(to) {
189
if (this.currentMode == to)
191
this._modeStack[this._modeStack.length - 1] = to;
196
return this._modeStack[this._modeStack.length - 1];
199
get allowScreencast() {
200
return this.components.indexOf('recorder') != -1;
204
let params = this._modes[this.currentMode];
206
if (params.parentMode)
207
defaults = Params.parse(this._modes[params.parentMode],
208
this._modes[DEFAULT_MODE]);
210
defaults = this._modes[DEFAULT_MODE];
211
params = Params.parse(params, defaults);
213
// A simplified version of Lang.copyProperties, handles
214
// undefined as a special case for "no change / inherit from previous mode"
215
for (let prop in params) {
216
if (params[prop] !== undefined)
217
this[prop] = params[prop];
220
this.emit('updated');
223
Signals.addSignalMethods(SessionMode.prototype);