[gnome-shell] user-status: Hide "Power off" option if shutdown is disabled



commit 6b2b3475c8f2270994ca25b6c0709a0c5cf2df02
Author: Florian MÃllner <fmuellner gnome org>
Date:   Sat Jun 4 00:10:55 2011 +0200

    user-status: Hide "Power off" option if shutdown is disabled
    
    Due to lockdown settings or Polkit policy, shutdown may not be
    available. If this is the case, the "Power off ..." action should
    be hidden from the user status menu.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=652038

 js/misc/gnomeSession.js |    3 +-
 js/ui/statusMenu.js     |   53 +++++++++++++++++++++++++++++++++++++++++++---
 2 files changed, 51 insertions(+), 5 deletions(-)
---
diff --git a/js/misc/gnomeSession.js b/js/misc/gnomeSession.js
index 1a52a6f..c661d41 100644
--- a/js/misc/gnomeSession.js
+++ b/js/misc/gnomeSession.js
@@ -109,7 +109,8 @@ const SessionManagerIface = {
     name: 'org.gnome.SessionManager',
     methods: [
         { name: 'Logout', inSignature: 'u', outSignature: '' },
-        { name: 'Shutdown', inSignature: '', outSignature: '' }
+        { name: 'Shutdown', inSignature: '', outSignature: '' },
+        { name: 'CanShutdown', inSignature: '', outSignature: 'b' }
     ]
 };
 
diff --git a/js/ui/statusMenu.js b/js/ui/statusMenu.js
index b778d1f..7d49743 100644
--- a/js/ui/statusMenu.js
+++ b/js/ui/statusMenu.js
@@ -58,6 +58,7 @@ StatusMenuButton.prototype = {
         this._presence = new GnomeSession.Presence();
         this._presenceItems = {};
         this._session = new GnomeSession.SessionManager();
+        this._haveShutdown = true;
 
         this._account_mgr = Tp.AccountManager.dup()
 
@@ -90,12 +91,25 @@ StatusMenuButton.prototype = {
                                        Lang.bind(this, this._updateSwitchUser));
         this._lockdownSettings.connect('changed::' + DISABLE_LOG_OUT_KEY,
                                        Lang.bind(this, this._updateLogout));
+
         this._lockdownSettings.connect('changed::' + DISABLE_LOCK_SCREEN_KEY,
                                        Lang.bind(this, this._updateLockScreen));
         this._updateSwitchUser();
         this._updateLogout();
         this._updateLockScreen();
 
+        // Whether shutdown is available or not depends on both lockdown
+        // settings (disable-log-out) and Polkit policy - the latter doesn't
+        // notify, so we update the menu item each time the menu opens or
+        // the lockdown setting changes, which should be close enough.
+        this.menu.connect('open-state-changed', Lang.bind(this,
+            function(menu, open) {
+                if (open)
+                    this._updateHaveShutdown();
+            }));
+        this._lockdownSettings.connect('changed::' + DISABLE_LOG_OUT_KEY,
+                                       Lang.bind(this, this._updateHaveShutdown));
+
         this._upClient.connect('notify::can-suspend', Lang.bind(this, this._updateSuspendOrPowerOff));
     },
 
@@ -112,13 +126,25 @@ StatusMenuButton.prototype = {
     },
 
     _updateSessionSeparator: function() {
-        let showSeparator = this._loginScreenItem.actor.visible ||
-                            this._logoutItem.actor.visible ||
-                            this._lockScreenItem.actor.visible;
-        if (showSeparator)
+        let sessionItemsVisible = this._loginScreenItem.actor.visible ||
+                                  this._logoutItem.actor.visible ||
+                                  this._lockScreenItem.actor.visible;
+
+        let showSessionSeparator = sessionItemsVisible &&
+                                   this._suspendOrPowerOffItem.actor.visible;
+
+        let showSettingsSeparator = sessionItemsVisible ||
+                                    this._suspendOrPowerOffItem.actor.visible;
+
+        if (showSessionSeparator)
             this._sessionSeparator.actor.show();
         else
             this._sessionSeparator.actor.hide();
+
+        if (showSettingsSeparator)
+            this._settingsSeparator.actor.show();
+        else
+            this._settingsSeparator.actor.hide();
     },
 
     _updateSwitchUser: function() {
@@ -148,16 +174,34 @@ StatusMenuButton.prototype = {
         this._updateSessionSeparator();
     },
 
+    _updateHaveShutdown: function() {
+        this._session.CanShutdownRemote(Lang.bind(this,
+            function(result, error) {
+                if (!error) {
+                    this._haveShutdown = result;
+                    this._updateSuspendOrPowerOff();
+                }
+            }));
+    },
+
     _updateSuspendOrPowerOff: function() {
         this._haveSuspend = this._upClient.get_can_suspend();
 
         if (!this._suspendOrPowerOffItem)
             return;
 
+        if (!this._haveShutdown && !this._haveSuspend)
+            this._suspendOrPowerOffItem.actor.hide();
+        else
+            this._suspendOrPowerOffItem.actor.show();
+         this._updateSessionSeparator();
+
         // If we can't suspend show Power Off... instead
         // and disable the alt key
         if (!this._haveSuspend) {
             this._suspendOrPowerOffItem.updateText(_("Power Off..."), null);
+        } else if (!this._haveShutdown) {
+            this._suspendOrPowerOffItem.updateText(_("Suspend"), null);
         } else {
             this._suspendOrPowerOffItem.updateText(_("Suspend"), _("Power Off..."));
         }
@@ -203,6 +247,7 @@ StatusMenuButton.prototype = {
 
         item = new PopupMenu.PopupSeparatorMenuItem();
         this.menu.addMenuItem(item);
+        this._settingsSeparator = item;
 
         item = new PopupMenu.PopupMenuItem(_("Lock Screen"));
         item.connect('activate', Lang.bind(this, this._onLockScreenActivate));



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]