~ubuntu-branches/debian/sid/gnome-shell/sid

« back to all changes in this revision

Viewing changes to .pc/10-make-NetworkManager-optional.patch/js/ui/sessionMode.js

  • Committer: Package Import Robot
  • Author(s): Emilio Pozuelo Monfort, Petr Salinger, Emilio Pozuelo Monfort
  • Date: 2013-10-13 17:47:35 UTC
  • mfrom: (1.2.17) (18.1.41 experimental)
  • Revision ID: package-import@ubuntu.com-20131013174735-2npsu0w5wk0e6vgb
Tags: 3.8.4-4
[ Petr Salinger ]
* Restrict dependency on gir1.2-nmgtk-1.0 to linux-any (Closes: #726099)

[ Emilio Pozuelo Monfort ]
* Upload to unstable.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
 
2
 
 
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;
 
8
 
 
9
const FileUtils = imports.misc.fileUtils;
 
10
const Main = imports.ui.main;
 
11
const Params = imports.misc.params;
 
12
 
 
13
const DEFAULT_MODE = 'restrictive';
 
14
 
 
15
const _modes = {
 
16
    'restrictive': {
 
17
        parentMode: null,
 
18
        stylesheetName: 'gnome-shell.css',
 
19
        overridesSchema: 'org.gnome.shell.overrides',
 
20
        hasOverview: false,
 
21
        showCalendarEvents: false,
 
22
        allowSettings: false,
 
23
        allowExtensions: false,
 
24
        enabledExtensions: [],
 
25
        hasRunDialog: false,
 
26
        hasWorkspaces: false,
 
27
        hasWindows: false,
 
28
        hasNotifications: false,
 
29
        isLocked: false,
 
30
        isGreeter: false,
 
31
        isPrimary: false,
 
32
        unlockDialog: null,
 
33
        components: [],
 
34
        panel: {
 
35
            left: [],
 
36
            center: [],
 
37
            right: []
 
38
        },
 
39
        panelStyle: null
 
40
    },
 
41
 
 
42
    'gdm': {
 
43
        hasNotifications: true,
 
44
        isGreeter: true,
 
45
        isPrimary: true,
 
46
        unlockDialog: imports.gdm.loginDialog.LoginDialog,
 
47
        components: ['polkitAgent'],
 
48
        panel: {
 
49
            left: [],
 
50
            center: ['dateMenu'],
 
51
            right: ['a11yGreeter', 'display', 'keyboard',
 
52
                    'volume', 'battery', 'powerMenu']
 
53
        },
 
54
        panelStyle: 'login-screen'
 
55
    },
 
56
 
 
57
    'lock-screen': {
 
58
        isLocked: true,
 
59
        isGreeter: undefined,
 
60
        unlockDialog: undefined,
 
61
        components: ['polkitAgent', 'telepathyClient'],
 
62
        panel: {
 
63
            left: ['userMenu'],
 
64
            center: [],
 
65
            right: ['lockScreen']
 
66
        },
 
67
        panelStyle: 'lock-screen'
 
68
    },
 
69
 
 
70
    'unlock-dialog': {
 
71
        isLocked: true,
 
72
        unlockDialog: undefined,
 
73
        components: ['polkitAgent', 'telepathyClient'],
 
74
        panel: {
 
75
            left: ['userMenu'],
 
76
            center: [],
 
77
            right: ['a11y', 'keyboard', 'lockScreen']
 
78
        },
 
79
        panelStyle: 'unlock-screen'
 
80
    },
 
81
 
 
82
    'initial-setup': {
 
83
        hasWindows: true,
 
84
        isPrimary: true,
 
85
        components: ['networkAgent', 'keyring'],
 
86
        panel: {
 
87
            left: [],
 
88
            center: ['dateMenu'],
 
89
            right: ['a11yGreeter', 'keyboard', 'volume', 'battery']
 
90
        }
 
91
    },
 
92
 
 
93
    'user': {
 
94
        hasOverview: true,
 
95
        showCalendarEvents: true,
 
96
        allowSettings: true,
 
97
        allowExtensions: true,
 
98
        hasRunDialog: true,
 
99
        hasWorkspaces: true,
 
100
        hasWindows: true,
 
101
        hasNotifications: true,
 
102
        isLocked: false,
 
103
        isPrimary: true,
 
104
        unlockDialog: imports.ui.unlockDialog.UnlockDialog,
 
105
        components: ['networkAgent', 'polkitAgent', 'telepathyClient',
 
106
                     'keyring', 'recorder', 'autorunManager', 'automountManager'],
 
107
        panel: {
 
108
            left: ['activities', 'appMenu'],
 
109
            center: ['dateMenu'],
 
110
            right: ['a11y', 'keyboard', 'volume', 'bluetooth',
 
111
                    'network', 'battery', 'userMenu']
 
112
        }
 
113
    }
 
114
};
 
115
 
 
116
function _getModes(modesLoadedCallback) {
 
117
    FileUtils.collectFromDatadirsAsync('modes',
 
118
                                       { processFile: _loadMode,
 
119
                                         loadedCallback: modesLoadedCallback,
 
120
                                         data: _modes });
 
121
}
 
122
 
 
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);
 
127
 
 
128
    if (loadedData.hasOwnProperty(modeName))
 
129
        return;
 
130
 
 
131
    let fileContent, success, tag, newMode;
 
132
    try {
 
133
        [success, fileContent, tag] = file.load_contents(null);
 
134
        newMode = JSON.parse(fileContent);
 
135
    } catch(e) {
 
136
        return;
 
137
    }
 
138
 
 
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];
 
145
    }
 
146
    loadedData[modeName]['isPrimary'] = true;
 
147
}
 
148
 
 
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)
 
154
                print(names[i]);
 
155
        Mainloop.quit('listModes');
 
156
    });
 
157
    Mainloop.run('listModes');
 
158
}
 
159
 
 
160
const SessionMode = new Lang.Class({
 
161
    Name: 'SessionMode',
 
162
 
 
163
    init: function() {
 
164
        _getModes(Lang.bind(this, function(modes) {
 
165
            this._modes = 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];
 
170
            this._sync();
 
171
 
 
172
            this.emit('sessions-loaded');
 
173
        }));
 
174
    },
 
175
 
 
176
    pushMode: function(mode) {
 
177
        this._modeStack.push(mode);
 
178
        this._sync();
 
179
    },
 
180
 
 
181
    popMode: function(mode) {
 
182
        if (this.currentMode != mode || this._modeStack.length === 1)
 
183
            throw new Error("Invalid SessionMode.popMode");
 
184
        this._modeStack.pop();
 
185
        this._sync();
 
186
    },
 
187
 
 
188
    switchMode: function(to) {
 
189
        if (this.currentMode == to)
 
190
            return;
 
191
        this._modeStack[this._modeStack.length - 1] = to;
 
192
        this._sync();
 
193
    },
 
194
 
 
195
    get currentMode() {
 
196
        return this._modeStack[this._modeStack.length - 1];
 
197
    },
 
198
 
 
199
    get allowScreencast() {
 
200
        return this.components.indexOf('recorder') != -1;
 
201
    },
 
202
 
 
203
    _sync: function() {
 
204
        let params = this._modes[this.currentMode];
 
205
        let defaults;
 
206
        if (params.parentMode)
 
207
            defaults = Params.parse(this._modes[params.parentMode],
 
208
                                    this._modes[DEFAULT_MODE]);
 
209
        else
 
210
            defaults = this._modes[DEFAULT_MODE];
 
211
        params = Params.parse(params, defaults);
 
212
 
 
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];
 
218
        }
 
219
 
 
220
        this.emit('updated');
 
221
    }
 
222
});
 
223
Signals.addSignalMethods(SessionMode.prototype);