22
22
const UPowerGlib = imports.gi.UPowerGlib;
24
24
const ConsoleKit = imports.gdm.consoleKit;
25
const Systemd = imports.gdm.systemd;
25
27
const PanelMenu = imports.ui.panelMenu;
26
28
const PopupMenu = imports.ui.popupMenu;
28
function PowerMenuButton() {
32
PowerMenuButton.prototype = {
33
__proto__: PanelMenu.SystemStatusButton.prototype,
30
const PowerMenuButton = new Lang.Class({
31
Name: 'PowerMenuButton',
32
Extends: PanelMenu.SystemStatusButton,
35
34
_init: function() {
36
PanelMenu.SystemStatusButton.prototype._init.call(this, 'system-shutdown', null);
35
this.parent('system-shutdown', null);
37
36
this._consoleKitManager = new ConsoleKit.ConsoleKitManager();
37
this._systemdLoginManager = new Systemd.SystemdLoginManager();
38
38
this._upClient = new UPowerGlib.Client();
40
40
this._createSubMenu();
66
66
_updateHaveShutdown: function() {
67
this._consoleKitManager.CanStopRemote(Lang.bind(this,
68
function(result, error) {
70
this._haveShutdown = result;
72
this._haveShutdown = false;
74
if (this._haveShutdown) {
75
this._powerOffItem.actor.show();
77
this._powerOffItem.actor.hide();
80
this._updateVisibility();
68
if (Systemd.haveSystemd()) {
69
this._systemdLoginManager.CanPowerOffRemote(Lang.bind(this,
70
function(result, error) {
72
this._haveShutdown = result != 'no';
74
this._haveShutdown = false;
76
if (this._haveShutdown)
77
this._powerOffItem.actor.show();
79
this._powerOffItem.actor.hide();
81
this._updateVisibility();
84
this._consoleKitManager.CanStopRemote(Lang.bind(this,
85
function(result, error) {
87
this._haveShutdown = result;
89
this._haveShutdown = false;
91
if (this._haveShutdown) {
92
this._powerOffItem.actor.show();
94
this._powerOffItem.actor.hide();
97
this._updateVisibility();
84
102
_updateHaveRestart: function() {
85
this._consoleKitManager.CanRestartRemote(Lang.bind(this,
86
function(result, error) {
88
this._haveRestart = result;
90
this._haveRestart = false;
92
if (this._haveRestart) {
93
this._restartItem.actor.show();
95
this._restartItem.actor.hide();
98
this._updateVisibility();
104
if (Systemd.haveSystemd()) {
105
this._systemdLoginManager.CanRebootRemote(Lang.bind(this,
106
function(result, error) {
108
this._haveRestart = result != 'no';
110
this._haveRestart = false;
112
if (this._haveRestart)
113
this._restartItem.actor.show();
115
this._restartItem.actor.hide();
117
this._updateVisibility();
120
this._consoleKitManager.CanRestartRemote(Lang.bind(this,
121
function(result, error) {
123
this._haveRestart = result;
125
this._haveRestart = false;
127
if (this._haveRestart) {
128
this._restartItem.actor.show();
130
this._restartItem.actor.hide();
133
this._updateVisibility();
102
138
_updateHaveSuspend: function() {
137
173
_onActivateRestart: function() {
138
if (this._haveRestart)
174
if (!this._haveRestart)
177
if (Systemd.haveSystemd())
178
this._systemdLoginManager.RebootRemote(true);
139
180
this._consoleKitManager.RestartRemote();
142
183
_onActivatePowerOff: function() {
143
if (this._haveShutdown)
184
if (!this._haveShutdown)
187
if (Systemd.haveSystemd())
188
this._systemdLoginManager.PowerOffRemote(true);
144
190
this._consoleKitManager.StopRemote();