2011-09-28 09:16:26 -04:00
|
|
|
// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
|
|
|
|
/*
|
2011-09-06 09:05:40 -04:00
|
|
|
* Copyright 2011 Red Hat, Inc
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2, or (at your option)
|
|
|
|
* any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
|
|
|
|
* 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
2012-10-16 15:32:05 -04:00
|
|
|
const Gio = imports.gi.Gio;
|
2011-09-06 09:05:40 -04:00
|
|
|
const Lang = imports.lang;
|
|
|
|
|
2012-08-18 08:05:52 -04:00
|
|
|
const LoginManager = imports.misc.loginManager;
|
2012-02-10 19:38:41 -05:00
|
|
|
|
2012-10-16 15:32:05 -04:00
|
|
|
const GdmUtil = imports.gdm.util;
|
2011-09-06 09:05:40 -04:00
|
|
|
const PanelMenu = imports.ui.panelMenu;
|
|
|
|
const PopupMenu = imports.ui.popupMenu;
|
|
|
|
|
2011-11-20 09:38:48 -05:00
|
|
|
const PowerMenuButton = new Lang.Class({
|
|
|
|
Name: 'PowerMenuButton',
|
|
|
|
Extends: PanelMenu.SystemStatusButton,
|
2011-09-06 09:05:40 -04:00
|
|
|
|
|
|
|
_init: function() {
|
2012-09-24 13:01:04 -04:00
|
|
|
/* Translators: accessible name of the power menu in the login screen */
|
|
|
|
this.parent('system-shutdown-symbolic', _("Power"));
|
2011-09-06 09:05:40 -04:00
|
|
|
|
2012-08-18 08:05:52 -04:00
|
|
|
this._loginManager = LoginManager.getLoginManager();
|
2012-03-16 12:07:47 -04:00
|
|
|
|
2012-10-16 15:32:05 -04:00
|
|
|
this._settings = new Gio.Settings({ schema: GdmUtil.LOGIN_SCREEN_SCHEMA });
|
|
|
|
this._settings.connect('changed::disable-restart-buttons',
|
|
|
|
Lang.bind(this, this._updateVisibility));
|
|
|
|
|
2011-09-06 09:05:40 -04:00
|
|
|
this._createSubMenu();
|
|
|
|
|
|
|
|
// ConsoleKit doesn't send notifications when shutdown/reboot
|
|
|
|
// are disabled, so we update the menu item each time the menu opens
|
|
|
|
this.menu.connect('open-state-changed', Lang.bind(this,
|
|
|
|
function(menu, open) {
|
|
|
|
if (open) {
|
|
|
|
this._updateHaveShutdown();
|
|
|
|
this._updateHaveRestart();
|
2012-10-19 11:40:55 -04:00
|
|
|
this._updateHaveSuspend();
|
2011-09-06 09:05:40 -04:00
|
|
|
}
|
|
|
|
}));
|
|
|
|
this._updateHaveShutdown();
|
|
|
|
this._updateHaveRestart();
|
2012-10-19 11:40:55 -04:00
|
|
|
this._updateHaveSuspend();
|
2011-09-06 09:05:40 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
_updateVisibility: function() {
|
2012-03-16 18:53:14 -04:00
|
|
|
let shouldBeVisible = (this._haveSuspend || this._haveShutdown || this._haveRestart);
|
2012-10-16 15:32:05 -04:00
|
|
|
this.actor.visible = shouldBeVisible && !this._settings.get_boolean('disable-restart-buttons');
|
2011-09-06 09:05:40 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
_updateHaveShutdown: function() {
|
2012-08-18 08:05:52 -04:00
|
|
|
this._loginManager.canPowerOff(Lang.bind(this, function(result) {
|
|
|
|
this._haveShutdown = result;
|
|
|
|
this._powerOffItem.actor.visible = this._haveShutdown;
|
|
|
|
this._updateVisibility();
|
|
|
|
}));
|
2011-09-06 09:05:40 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
_updateHaveRestart: function() {
|
2012-08-18 08:05:52 -04:00
|
|
|
this._loginManager.canReboot(Lang.bind(this, function(result) {
|
|
|
|
this._haveRestart = result;
|
|
|
|
this._restartItem.actor.visible = this._haveRestart;
|
|
|
|
this._updateVisibility();
|
|
|
|
}));
|
2011-09-06 09:05:40 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
_updateHaveSuspend: function() {
|
2012-10-19 11:40:55 -04:00
|
|
|
this._loginManager.canSuspend(Lang.bind(this, function(result) {
|
|
|
|
this._haveSuspend = result;
|
|
|
|
this._suspendItem.actor.visible = this._haveSuspend;
|
|
|
|
this._updateVisibility();
|
|
|
|
}));
|
2011-09-06 09:05:40 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
_createSubMenu: function() {
|
|
|
|
let item;
|
|
|
|
|
|
|
|
item = new PopupMenu.PopupMenuItem(_("Suspend"));
|
|
|
|
item.connect('activate', Lang.bind(this, this._onActivateSuspend));
|
|
|
|
this.menu.addMenuItem(item);
|
|
|
|
this._suspendItem = item;
|
|
|
|
|
|
|
|
item = new PopupMenu.PopupMenuItem(_("Restart"));
|
|
|
|
item.connect('activate', Lang.bind(this, this._onActivateRestart));
|
|
|
|
this.menu.addMenuItem(item);
|
|
|
|
this._restartItem = item;
|
|
|
|
|
|
|
|
item = new PopupMenu.PopupMenuItem(_("Power Off"));
|
|
|
|
item.connect('activate', Lang.bind(this, this._onActivatePowerOff));
|
|
|
|
this.menu.addMenuItem(item);
|
|
|
|
this._powerOffItem = item;
|
|
|
|
},
|
|
|
|
|
|
|
|
_onActivateSuspend: function() {
|
2012-10-19 11:40:55 -04:00
|
|
|
if (!this._haveSuspend)
|
|
|
|
return;
|
|
|
|
|
|
|
|
this._loginManager.suspend();
|
2011-09-06 09:05:40 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
_onActivateRestart: function() {
|
2012-02-10 19:38:41 -05:00
|
|
|
if (!this._haveRestart)
|
|
|
|
return;
|
|
|
|
|
2012-08-18 08:05:52 -04:00
|
|
|
this._loginManager.reboot();
|
2011-09-06 09:05:40 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
_onActivatePowerOff: function() {
|
2012-02-10 19:38:41 -05:00
|
|
|
if (!this._haveShutdown)
|
|
|
|
return;
|
|
|
|
|
2012-08-18 08:05:52 -04:00
|
|
|
this._loginManager.powerOff();
|
2011-09-06 09:05:40 -04:00
|
|
|
}
|
2011-11-20 09:38:48 -05:00
|
|
|
});
|