~jbicha/ubuntu/oneiric/gnome-shell/oneiric-3.2.2.1

« back to all changes in this revision

Viewing changes to js/ui/statusMenu.js

  • Committer: Bazaar Package Importer
  • Author(s): Michael Terry
  • Date: 2011-07-20 14:46:28 UTC
  • mfrom: (1.1.25 upstream)
  • Revision ID: james.westby@ubuntu.com-20110720144628-ipirjtz8od4uktpg
Tags: 3.1.3-0ubuntu1
* New upstream release
* debian/control.in:
  - Update dependency versions

Show diffs side-by-side

added added

removed removed

Lines of Context:
9
9
const St = imports.gi.St;
10
10
const Tp = imports.gi.TelepathyGLib;
11
11
const UPowerGlib = imports.gi.UPowerGlib;
12
 
const Gettext = imports.gettext.domain('gnome-shell');
13
 
const _ = Gettext.gettext;
14
12
 
15
13
const GnomeSession = imports.misc.gnomeSession;
16
14
const Main = imports.ui.main;
28
26
 
29
27
const ScreenSaverInterface = {
30
28
    name: BUS_NAME,
31
 
    methods: [ { name: 'Lock', inSignature: '' } ]
 
29
    methods: [ { name: 'Lock', inSignature: '' },
 
30
               { name: 'SetActive', inSignature: 'b' }]
32
31
};
33
32
 
34
33
let ScreenSaverProxy = DBus.makeProxyClass(ScreenSaverInterface);
59
58
        this._presence = new GnomeSession.Presence();
60
59
        this._presenceItems = {};
61
60
        this._session = new GnomeSession.SessionManager();
 
61
        this._haveShutdown = true;
62
62
 
63
63
        this._account_mgr = Tp.AccountManager.dup()
64
64
 
91
91
                                       Lang.bind(this, this._updateSwitchUser));
92
92
        this._lockdownSettings.connect('changed::' + DISABLE_LOG_OUT_KEY,
93
93
                                       Lang.bind(this, this._updateLogout));
 
94
 
94
95
        this._lockdownSettings.connect('changed::' + DISABLE_LOCK_SCREEN_KEY,
95
96
                                       Lang.bind(this, this._updateLockScreen));
96
97
        this._updateSwitchUser();
97
98
        this._updateLogout();
98
99
        this._updateLockScreen();
99
100
 
 
101
        // Whether shutdown is available or not depends on both lockdown
 
102
        // settings (disable-log-out) and Polkit policy - the latter doesn't
 
103
        // notify, so we update the menu item each time the menu opens or
 
104
        // the lockdown setting changes, which should be close enough.
 
105
        this.menu.connect('open-state-changed', Lang.bind(this,
 
106
            function(menu, open) {
 
107
                if (open)
 
108
                    this._updateHaveShutdown();
 
109
            }));
 
110
        this._lockdownSettings.connect('changed::' + DISABLE_LOG_OUT_KEY,
 
111
                                       Lang.bind(this, this._updateHaveShutdown));
 
112
 
100
113
        this._upClient.connect('notify::can-suspend', Lang.bind(this, this._updateSuspendOrPowerOff));
101
114
    },
102
115
 
113
126
    },
114
127
 
115
128
    _updateSessionSeparator: function() {
116
 
        let showSeparator = this._loginScreenItem.actor.visible ||
117
 
                            this._logoutItem.actor.visible ||
118
 
                            this._lockScreenItem.actor.visible;
119
 
        if (showSeparator)
 
129
        let sessionItemsVisible = this._loginScreenItem.actor.visible ||
 
130
                                  this._logoutItem.actor.visible ||
 
131
                                  this._lockScreenItem.actor.visible;
 
132
 
 
133
        let showSessionSeparator = sessionItemsVisible &&
 
134
                                   this._suspendOrPowerOffItem.actor.visible;
 
135
 
 
136
        let showSettingsSeparator = sessionItemsVisible ||
 
137
                                    this._suspendOrPowerOffItem.actor.visible;
 
138
 
 
139
        if (showSessionSeparator)
120
140
            this._sessionSeparator.actor.show();
121
141
        else
122
142
            this._sessionSeparator.actor.hide();
 
143
 
 
144
        if (showSettingsSeparator)
 
145
            this._settingsSeparator.actor.show();
 
146
        else
 
147
            this._settingsSeparator.actor.hide();
123
148
    },
124
149
 
125
150
    _updateSwitchUser: function() {
149
174
        this._updateSessionSeparator();
150
175
    },
151
176
 
 
177
    _updateHaveShutdown: function() {
 
178
        this._session.CanShutdownRemote(Lang.bind(this,
 
179
            function(result, error) {
 
180
                if (!error) {
 
181
                    this._haveShutdown = result;
 
182
                    this._updateSuspendOrPowerOff();
 
183
                }
 
184
            }));
 
185
    },
 
186
 
152
187
    _updateSuspendOrPowerOff: function() {
153
188
        this._haveSuspend = this._upClient.get_can_suspend();
154
189
 
155
190
        if (!this._suspendOrPowerOffItem)
156
191
            return;
157
192
 
 
193
        if (!this._haveShutdown && !this._haveSuspend)
 
194
            this._suspendOrPowerOffItem.actor.hide();
 
195
        else
 
196
            this._suspendOrPowerOffItem.actor.show();
 
197
         this._updateSessionSeparator();
 
198
 
158
199
        // If we can't suspend show Power Off... instead
159
200
        // and disable the alt key
160
201
        if (!this._haveSuspend) {
161
202
            this._suspendOrPowerOffItem.updateText(_("Power Off..."), null);
 
203
        } else if (!this._haveShutdown) {
 
204
            this._suspendOrPowerOffItem.updateText(_("Suspend"), null);
162
205
        } else {
163
206
            this._suspendOrPowerOffItem.updateText(_("Suspend"), _("Power Off..."));
164
207
        }
204
247
 
205
248
        item = new PopupMenu.PopupSeparatorMenuItem();
206
249
        this.menu.addMenuItem(item);
 
250
        this._settingsSeparator = item;
207
251
 
208
252
        item = new PopupMenu.PopupMenuItem(_("Lock Screen"));
209
253
        item.connect('activate', Lang.bind(this, this._onLockScreenActivate));
271
315
 
272
316
        if (this._haveSuspend &&
273
317
            this._suspendOrPowerOffItem.state == PopupMenu.PopupAlternatingMenuItemState.DEFAULT) {
274
 
            this._screenSaverProxy.LockRemote(Lang.bind(this, function() {
 
318
            this._screenSaverProxy.SetActiveRemote(true, Lang.bind(this, function() {
275
319
                this._upClient.suspend_sync(null);
276
320
            }));
277
321
        } else {