user-status: Honor lockdown settings

Right now, the user status menu always contains actions to logout
and lock the screen, and the user switching action only depends on
the technical availability of the functionality.
All those items should honor the lockdown settings defined in
org.gnome.desktop.lockdown.

https://bugzilla.gnome.org/show_bug.cgi?id=645335
This commit is contained in:
Florian Müllner 2011-03-21 13:51:46 +01:00
parent 291ef07cf3
commit 0eaf141ae4

View File

@ -2,6 +2,7 @@
const Gdm = imports.gi.Gdm; const Gdm = imports.gi.Gdm;
const DBus = imports.dbus; const DBus = imports.dbus;
const Gio = imports.gi.Gio;
const GLib = imports.gi.GLib; const GLib = imports.gi.GLib;
const Lang = imports.lang; const Lang = imports.lang;
const Shell = imports.gi.Shell; const Shell = imports.gi.Shell;
@ -20,6 +21,11 @@ const Util = imports.misc.util;
const BUS_NAME = 'org.gnome.ScreenSaver'; const BUS_NAME = 'org.gnome.ScreenSaver';
const OBJECT_PATH = '/org/gnome/ScreenSaver'; const OBJECT_PATH = '/org/gnome/ScreenSaver';
const LOCKDOWN_SCHEMA = 'org.gnome.desktop.lockdown';
const DISABLE_USER_SWITCH_KEY = 'disable-user-switching';
const DISABLE_LOCK_SCREEN_KEY = 'disable-lock-screen';
const DISABLE_LOG_OUT_KEY = 'disable-log-out';
const ScreenSaverInterface = { const ScreenSaverInterface = {
name: BUS_NAME, name: BUS_NAME,
methods: [ { name: 'Lock', inSignature: '' } ] methods: [ { name: 'Lock', inSignature: '' } ]
@ -44,6 +50,8 @@ StatusMenuButton.prototype = {
let box = new St.BoxLayout({ name: 'panelStatusMenu' }); let box = new St.BoxLayout({ name: 'panelStatusMenu' });
this.actor.set_child(box); this.actor.set_child(box);
this._lockdownSettings = new Gio.Settings({ schema: LOCKDOWN_SCHEMA });
this._gdm = Gdm.UserManager.ref_default(); this._gdm = Gdm.UserManager.ref_default();
this._gdm.queue_load(); this._gdm.queue_load();
@ -79,6 +87,15 @@ StatusMenuButton.prototype = {
this._gdm.connect('notify::is-loaded', Lang.bind(this, this._updateSwitchUser)); this._gdm.connect('notify::is-loaded', Lang.bind(this, this._updateSwitchUser));
this._gdm.connect('user-added', Lang.bind(this, this._updateSwitchUser)); this._gdm.connect('user-added', Lang.bind(this, this._updateSwitchUser));
this._gdm.connect('user-removed', Lang.bind(this, this._updateSwitchUser)); this._gdm.connect('user-removed', Lang.bind(this, this._updateSwitchUser));
this._lockdownSettings.connect('changed::' + DISABLE_USER_SWITCH_KEY,
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();
this._upClient.connect('notify::can-suspend', Lang.bind(this, this._updateSuspendOrPowerOff)); this._upClient.connect('notify::can-suspend', Lang.bind(this, this._updateSuspendOrPowerOff));
}, },
@ -95,11 +112,41 @@ StatusMenuButton.prototype = {
this._name.set_text(""); this._name.set_text("");
}, },
_updateSessionSeparator: function() {
let showSeparator = this._loginScreenItem.actor.visible ||
this._logoutItem.actor.visible ||
this._lockScreenItem.actor.visible;
if (showSeparator)
this._sessionSeparator.actor.show();
else
this._sessionSeparator.actor.hide();
},
_updateSwitchUser: function() { _updateSwitchUser: function() {
if (this._gdm.can_switch ()) let allowSwitch = !this._lockdownSettings.get_boolean(DISABLE_USER_SWITCH_KEY);
if (allowSwitch && this._gdm.can_switch ())
this._loginScreenItem.actor.show(); this._loginScreenItem.actor.show();
else else
this._loginScreenItem.actor.hide(); this._loginScreenItem.actor.hide();
this._updateSessionSeparator();
},
_updateLogout: function() {
let allowLogout = !this._lockdownSettings.get_boolean(DISABLE_LOG_OUT_KEY);
if (allowLogout)
this._logoutItem.actor.show();
else
this._logoutItem.actor.hide();
this._updateSessionSeparator();
},
_updateLockScreen: function() {
let allowLockScreen = !this._lockdownSettings.get_boolean(DISABLE_LOCK_SCREEN_KEY);
if (allowLockScreen)
this._lockScreenItem.actor.show();
else
this._lockScreenItem.actor.hide();
this._updateSessionSeparator();
}, },
_updateSuspendOrPowerOff: function() { _updateSuspendOrPowerOff: function() {
@ -161,6 +208,7 @@ StatusMenuButton.prototype = {
item = new PopupMenu.PopupMenuItem(_("Lock Screen")); item = new PopupMenu.PopupMenuItem(_("Lock Screen"));
item.connect('activate', Lang.bind(this, this._onLockScreenActivate)); item.connect('activate', Lang.bind(this, this._onLockScreenActivate));
this.menu.addMenuItem(item); this.menu.addMenuItem(item);
this._lockScreenItem = item;
item = new PopupMenu.PopupMenuItem(_("Switch User")); item = new PopupMenu.PopupMenuItem(_("Switch User"));
item.connect('activate', Lang.bind(this, this._onLoginScreenActivate)); item.connect('activate', Lang.bind(this, this._onLoginScreenActivate));
@ -170,9 +218,11 @@ StatusMenuButton.prototype = {
item = new PopupMenu.PopupMenuItem(_("Log Out...")); item = new PopupMenu.PopupMenuItem(_("Log Out..."));
item.connect('activate', Lang.bind(this, this._onQuitSessionActivate)); item.connect('activate', Lang.bind(this, this._onQuitSessionActivate));
this.menu.addMenuItem(item); this.menu.addMenuItem(item);
this._logoutItem = item;
item = new PopupMenu.PopupSeparatorMenuItem(); item = new PopupMenu.PopupSeparatorMenuItem();
this.menu.addMenuItem(item); this.menu.addMenuItem(item);
this._sessionSeparator = item;
item = new PopupMenu.PopupAlternatingMenuItem(_("Suspend"), item = new PopupMenu.PopupAlternatingMenuItem(_("Suspend"),
_("Power Off...")); _("Power Off..."));