2009-11-10 17:13:58 +00:00
|
|
|
/* -*- mode: js2; js2-basic-offset: 4; indent-tabs-mode: nil -*- */
|
|
|
|
|
2011-05-10 14:13:05 +00:00
|
|
|
const AccountsService = imports.gi.AccountsService;
|
2011-03-09 20:59:26 +00:00
|
|
|
const DBus = imports.dbus;
|
2011-03-21 12:51:46 +00:00
|
|
|
const Gio = imports.gi.Gio;
|
2009-11-10 17:13:58 +00:00
|
|
|
const GLib = imports.gi.GLib;
|
|
|
|
const Lang = imports.lang;
|
|
|
|
const Shell = imports.gi.Shell;
|
|
|
|
const St = imports.gi.St;
|
2011-02-28 16:03:35 +00:00
|
|
|
const Tp = imports.gi.TelepathyGLib;
|
2011-02-04 23:37:54 +00:00
|
|
|
const UPowerGlib = imports.gi.UPowerGlib;
|
2009-11-10 17:13:58 +00:00
|
|
|
|
2010-04-29 17:13:20 +00:00
|
|
|
const GnomeSession = imports.misc.gnomeSession;
|
2010-06-03 23:21:08 +00:00
|
|
|
const Main = imports.ui.main;
|
2010-06-22 21:02:26 +00:00
|
|
|
const PanelMenu = imports.ui.panelMenu;
|
2010-05-20 15:18:46 +00:00
|
|
|
const PopupMenu = imports.ui.popupMenu;
|
2011-07-12 15:42:33 +00:00
|
|
|
const ScreenSaver = imports.misc.screenSaver;
|
2010-11-17 16:43:08 +00:00
|
|
|
const Util = imports.misc.util;
|
2009-11-10 17:13:58 +00:00
|
|
|
|
2011-03-21 12:51:46 +00:00
|
|
|
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';
|
|
|
|
|
2011-07-28 14:59:03 +00:00
|
|
|
const WRAP_WIDTH = 150;
|
|
|
|
const DIALOG_ICON_SIZE = 64;
|
|
|
|
|
|
|
|
const IMStatus = {
|
|
|
|
AVAILABLE: 0,
|
|
|
|
BUSY: 1,
|
|
|
|
HIDDEN: 2,
|
|
|
|
AWAY: 3,
|
|
|
|
IDLE: 4,
|
|
|
|
OFFLINE: 5,
|
|
|
|
LAST: 6
|
|
|
|
};
|
|
|
|
|
2009-11-10 17:13:58 +00:00
|
|
|
// Adapted from gdm/gui/user-switch-applet/applet.c
|
|
|
|
//
|
|
|
|
// Copyright (C) 2004-2005 James M. Cape <jcape@ignore-your.tv>.
|
|
|
|
// Copyright (C) 2008,2009 Red Hat, Inc.
|
|
|
|
|
2011-07-28 14:59:03 +00:00
|
|
|
|
|
|
|
function IMStatusItem(label, iconName) {
|
|
|
|
this._init(label, iconName);
|
|
|
|
}
|
|
|
|
|
|
|
|
IMStatusItem.prototype = {
|
|
|
|
__proto__: PopupMenu.PopupBaseMenuItem.prototype,
|
|
|
|
|
|
|
|
_init: function(label, iconName) {
|
|
|
|
PopupMenu.PopupBaseMenuItem.prototype._init.call(this);
|
|
|
|
|
|
|
|
this.actor.add_style_class_name('status-chooser-status-item');
|
|
|
|
|
|
|
|
this._icon = new St.Icon({ style_class: 'popup-menu-icon' });
|
|
|
|
this.addActor(this._icon);
|
|
|
|
|
|
|
|
if (iconName)
|
|
|
|
this._icon.icon_name = iconName;
|
|
|
|
|
|
|
|
this.label = new St.Label({ text: label });
|
|
|
|
this.addActor(this.label);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
function IMUserNameItem() {
|
|
|
|
this._init();
|
|
|
|
}
|
|
|
|
|
|
|
|
IMUserNameItem.prototype = {
|
|
|
|
__proto__: PopupMenu.PopupBaseMenuItem.prototype,
|
|
|
|
|
|
|
|
_init: function() {
|
|
|
|
PopupMenu.PopupBaseMenuItem.prototype._init.call(this,
|
|
|
|
{ reactive: false,
|
|
|
|
style_class: 'status-chooser-user-name' });
|
|
|
|
|
|
|
|
this._wrapper = new Shell.GenericContainer();
|
|
|
|
this._wrapper.connect('get-preferred-width',
|
|
|
|
Lang.bind(this, this._wrapperGetPreferredWidth));
|
|
|
|
this._wrapper.connect('get-preferred-height',
|
|
|
|
Lang.bind(this, this._wrapperGetPreferredHeight));
|
|
|
|
this._wrapper.connect('allocate',
|
|
|
|
Lang.bind(this, this._wrapperAllocate));
|
|
|
|
this.addActor(this._wrapper, { expand: true, span: -1 });
|
|
|
|
|
|
|
|
this.label = new St.Label();
|
|
|
|
this.label.clutter_text.set_line_wrap(true);
|
|
|
|
this._wrapper.add_actor(this.label);
|
|
|
|
},
|
|
|
|
|
|
|
|
_wrapperGetPreferredWidth: function(actor, forHeight, alloc) {
|
|
|
|
[alloc.min_size, alloc.natural_size] = this.label.get_preferred_width(-1);
|
|
|
|
if (alloc.natural_size > WRAP_WIDTH)
|
|
|
|
alloc.natural_size = WRAP_WIDTH;
|
|
|
|
},
|
|
|
|
|
|
|
|
_wrapperGetPreferredHeight: function(actor, forWidth, alloc) {
|
|
|
|
let minWidth, natWidth;
|
|
|
|
[alloc.min_size, alloc.natural_size] = this.label.get_preferred_height(forWidth);
|
|
|
|
[minWidth, natWidth] = this.label.get_preferred_width(-1);
|
|
|
|
if (natWidth > WRAP_WIDTH) {
|
|
|
|
alloc.min_size *= 2;
|
|
|
|
alloc.natural_size *= 2;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
_wrapperAllocate: function(actor, box, flags) {
|
|
|
|
let availWidth = box.x2 - box.x1;
|
|
|
|
let availHeight = box.y2 - box.y1;
|
|
|
|
this.label.allocate(box, flags);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
function IMStatusChooserItem() {
|
|
|
|
this._init();
|
|
|
|
}
|
|
|
|
|
|
|
|
IMStatusChooserItem.prototype = {
|
|
|
|
__proto__: PopupMenu.PopupBaseMenuItem.prototype,
|
|
|
|
|
|
|
|
_init: function() {
|
|
|
|
PopupMenu.PopupBaseMenuItem.prototype._init.call (this,
|
|
|
|
{ reactive: false,
|
|
|
|
style_class: 'status-chooser' });
|
|
|
|
|
|
|
|
this._iconBin = new St.Button({ style_class: 'status-chooser-user-icon' });
|
|
|
|
this.addActor(this._iconBin);
|
|
|
|
|
|
|
|
this._iconBin.connect('clicked', Lang.bind(this,
|
|
|
|
function() {
|
|
|
|
this.activate();
|
|
|
|
}));
|
|
|
|
|
|
|
|
this._section = new PopupMenu.PopupMenuSection();
|
|
|
|
this.addActor(this._section.actor);
|
|
|
|
|
|
|
|
this._name = new IMUserNameItem();
|
|
|
|
this._section.addMenuItem(this._name);
|
|
|
|
|
|
|
|
this._combo = new PopupMenu.PopupComboBoxMenuItem({ style_class: 'status-chooser-combo' });
|
|
|
|
this._section.addMenuItem(this._combo);
|
|
|
|
|
|
|
|
let item;
|
|
|
|
|
|
|
|
item = new IMStatusItem(_("Available"), 'user-available');
|
|
|
|
this._combo.addMenuItem(item, IMStatus.AVAILABLE);
|
|
|
|
|
|
|
|
item = new IMStatusItem(_("Busy"), 'user-busy');
|
|
|
|
this._combo.addMenuItem(item, IMStatus.BUSY);
|
|
|
|
|
|
|
|
item = new IMStatusItem(_("Hidden"), 'user-invisible');
|
|
|
|
this._combo.addMenuItem(item, IMStatus.HIDDEN);
|
|
|
|
|
|
|
|
item = new IMStatusItem(_("Away"), 'user-away');
|
|
|
|
this._combo.addMenuItem(item, IMStatus.AWAY);
|
|
|
|
|
|
|
|
item = new IMStatusItem(_("Idle"), 'user-idle');
|
|
|
|
this._combo.addMenuItem(item, IMStatus.IDLE);
|
|
|
|
|
|
|
|
item = new IMStatusItem(_("Unavailable"), 'user-offline');
|
|
|
|
this._combo.addMenuItem(item, IMStatus.OFFLINE);
|
|
|
|
|
|
|
|
this._combo.connect('active-item-changed',
|
|
|
|
Lang.bind(this, this._changeIMStatus));
|
|
|
|
|
|
|
|
this._presence = new GnomeSession.Presence();
|
|
|
|
this._presence.getStatus(Lang.bind(this, this._sessionStatusChanged));
|
|
|
|
this._presence.connect('StatusChanged',
|
|
|
|
Lang.bind(this, this._sessionStatusChanged));
|
|
|
|
|
|
|
|
this._previousPresence = undefined;
|
|
|
|
|
|
|
|
this._accountMgr = Tp.AccountManager.dup()
|
|
|
|
this._accountMgr.connect('most-available-presence-changed',
|
|
|
|
Lang.bind(this, this._IMStatusChanged));
|
|
|
|
this._accountMgr.prepare_async(null, Lang.bind(this,
|
|
|
|
function(mgr) {
|
|
|
|
let [presence, s, msg] = mgr.get_most_available_presence();
|
|
|
|
|
|
|
|
this._previousPresence = presence;
|
|
|
|
this._IMStatusChanged(mgr, presence, s, msg);
|
|
|
|
}));
|
|
|
|
|
2011-05-10 14:13:05 +00:00
|
|
|
this._userManager = AccountsService.UserManager.get_default();
|
2011-07-28 14:59:03 +00:00
|
|
|
|
2011-05-10 14:13:05 +00:00
|
|
|
this._user = this._userManager.get_user(GLib.get_user_name());
|
2011-07-28 14:59:03 +00:00
|
|
|
|
|
|
|
this._userLoadedId = this._user.connect('notify::is-loaded',
|
|
|
|
Lang.bind(this,
|
|
|
|
this._updateUser));
|
|
|
|
this._userChangedId = this._user.connect('changed',
|
|
|
|
Lang.bind(this,
|
|
|
|
this._updateUser));
|
|
|
|
},
|
|
|
|
|
|
|
|
// Override getColumnWidths()/setColumnWidths() to make the item
|
|
|
|
// independent from the overall column layout of the menu
|
|
|
|
getColumnWidths: function() {
|
|
|
|
return [];
|
|
|
|
},
|
|
|
|
|
|
|
|
setColumnWidths: function(widths) {
|
|
|
|
this._columnWidths = PopupMenu.PopupBaseMenuItem.prototype.getColumnWidths.call(this);
|
|
|
|
let sectionWidths = this._section.getColumnWidths();
|
|
|
|
this._section.setColumnWidths(sectionWidths);
|
|
|
|
},
|
|
|
|
|
|
|
|
_updateUser: function() {
|
|
|
|
let iconFile = null;
|
|
|
|
if (this._user.is_loaded) {
|
|
|
|
this._name.label.set_text(this._user.get_real_name());
|
|
|
|
iconFile = this._user.get_icon_file();
|
|
|
|
if (!GLib.file_test(iconFile, GLib.FileTest.EXISTS))
|
|
|
|
iconFile = null;
|
|
|
|
} else {
|
|
|
|
this._name.label.set_text("");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (iconFile)
|
|
|
|
this._setIconFromFile(iconFile);
|
|
|
|
else
|
|
|
|
this._setIconFromName('avatar-default');
|
|
|
|
},
|
|
|
|
|
|
|
|
_setIconFromFile: function(iconFile) {
|
|
|
|
this._iconBin.set_style('background-image: url("' + iconFile + '");');
|
|
|
|
},
|
|
|
|
|
|
|
|
_setIconFromName: function(iconName) {
|
|
|
|
this._iconBin.set_style(null);
|
|
|
|
|
|
|
|
if (iconName != null) {
|
|
|
|
let textureCache = St.TextureCache.get_default();
|
|
|
|
let icon = textureCache.load_icon_name(this._iconBin.get_theme_node(),
|
|
|
|
iconName,
|
|
|
|
St.IconType.SYMBOLIC,
|
|
|
|
DIALOG_ICON_SIZE);
|
|
|
|
|
|
|
|
this._iconBin.child = icon;
|
|
|
|
this._iconBin.show();
|
|
|
|
} else {
|
|
|
|
this._iconBin.child = null;
|
|
|
|
this._iconBin.hide();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
_statusForPresence: function(presence) {
|
|
|
|
switch(presence) {
|
|
|
|
case Tp.ConnectionPresenceType.AVAILABLE:
|
|
|
|
return _("Available");
|
|
|
|
case Tp.ConnectionPresenceType.BUSY:
|
|
|
|
return _("Busy");
|
|
|
|
case Tp.ConnectionPresenceType.OFFLINE:
|
|
|
|
return _("Unavailable");
|
|
|
|
case Tp.ConnectionPresenceType.HIDDEN:
|
|
|
|
return _("Hidden");
|
|
|
|
case Tp.ConnectionPresenceType.AWAY:
|
|
|
|
return _("Away");
|
|
|
|
case Tp.ConnectionPresenceType.EXTENDED_AWAY:
|
|
|
|
return _("Idle");
|
|
|
|
default:
|
|
|
|
return _("Unknown");
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
_IMStatusChanged: function(accountMgr, presence, status, message) {
|
|
|
|
if (presence == Tp.ConnectionPresenceType.AVAILABLE)
|
|
|
|
this._presence.setStatus(GnomeSession.PresenceStatus.AVAILABLE);
|
|
|
|
|
|
|
|
if (!this._expectedPresence || presence != this._expectedPresence)
|
|
|
|
this._previousPresence = presence;
|
|
|
|
else
|
|
|
|
this._expectedPresence = undefined;
|
|
|
|
|
|
|
|
let activatedItem;
|
|
|
|
|
|
|
|
if (presence == Tp.ConnectionPresenceType.AVAILABLE)
|
|
|
|
activatedItem = IMStatus.AVAILABLE;
|
|
|
|
else if (presence == Tp.ConnectionPresenceType.BUSY)
|
|
|
|
activatedItem = IMStatus.BUSY;
|
|
|
|
else if (presence == Tp.ConnectionPresenceType.HIDDEN)
|
|
|
|
activatedItem = IMStatus.HIDDEN;
|
|
|
|
else if (presence == Tp.ConnectionPresenceType.AWAY)
|
|
|
|
activatedItem = IMStatus.AWAY;
|
|
|
|
else if (presence == Tp.ConnectionPresenceType.EXTENDED_AWAY)
|
|
|
|
activatedItem = IMStatus.IDLE;
|
|
|
|
else
|
|
|
|
activatedItem = IMStatus.OFFLINE;
|
|
|
|
|
|
|
|
this._combo.setActiveItem(activatedItem);
|
|
|
|
for (let i = 0; i < IMStatus.LAST; i++) {
|
|
|
|
if (i == IMStatus.AVAILABLE || i == IMStatus.OFFLINE)
|
|
|
|
continue; // always visible
|
|
|
|
|
|
|
|
this._combo.setItemVisible(i, i == activatedItem);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
_changeIMStatus: function(menuItem, id) {
|
|
|
|
let [presence, s, msg] = this._accountMgr.get_most_available_presence();
|
|
|
|
let newPresence, status;
|
|
|
|
|
|
|
|
if (id == IMStatus.AVAILABLE) {
|
|
|
|
newPresence = Tp.ConnectionPresenceType.AVAILABLE;
|
|
|
|
} else if (id == IMStatus.OFFLINE) {
|
|
|
|
newPresence = Tp.ConnectionPresenceType.OFFLINE;
|
|
|
|
} else
|
|
|
|
return;
|
|
|
|
|
|
|
|
status = this._statusForPresence(newPresence);
|
|
|
|
msg = msg ? msg : "";
|
|
|
|
this._accountMgr.set_all_requested_presences(newPresence, status, msg);
|
|
|
|
},
|
|
|
|
|
|
|
|
_sessionStatusChanged: function(sessionPresence, sessionStatus) {
|
|
|
|
let [presence, s, msg] = this._accountMgr.get_most_available_presence();
|
|
|
|
let newPresence, status;
|
|
|
|
|
|
|
|
if (sessionStatus == GnomeSession.PresenceStatus.AVAILABLE) {
|
|
|
|
newPresence = this._previousPresence;
|
|
|
|
} else if (sessionStatus == GnomeSession.PresenceStatus.BUSY) {
|
|
|
|
// Only change presence if the current one is "more present" than
|
|
|
|
// busy, or if coming back from idle
|
|
|
|
if (presence == Tp.ConnectionPresenceType.AVAILABLE ||
|
|
|
|
presence == Tp.ConnectionPresenceType.EXTENDED_AWAY) {
|
|
|
|
newPresence = Tp.ConnectionPresenceType.BUSY;
|
|
|
|
} else {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else if (sessionStatus == GnomeSession.PresenceStatus.IDLE) {
|
|
|
|
// Only change presence if the current one is "more present" than
|
|
|
|
// idle
|
|
|
|
if (presence != Tp.ConnectionPresenceType.OFFLINE)
|
|
|
|
newPresence = Tp.ConnectionPresenceType.EXTENDED_AWAY;
|
|
|
|
else
|
|
|
|
return;
|
|
|
|
} else {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (newPresence == undefined)
|
|
|
|
return;
|
|
|
|
|
|
|
|
status = this._statusForPresence(newPresence);
|
|
|
|
msg = msg ? msg : "";
|
|
|
|
|
|
|
|
this._expectedPresence = newPresence;
|
|
|
|
this._accountMgr.set_all_requested_presences(newPresence, status, msg);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2011-08-29 19:56:22 +00:00
|
|
|
function UserMenuButton() {
|
2009-11-10 17:13:58 +00:00
|
|
|
this._init();
|
|
|
|
}
|
|
|
|
|
2011-08-29 19:56:22 +00:00
|
|
|
UserMenuButton.prototype = {
|
2010-06-22 21:02:26 +00:00
|
|
|
__proto__: PanelMenu.Button.prototype,
|
2010-05-10 13:46:54 +00:00
|
|
|
|
2009-11-10 17:13:58 +00:00
|
|
|
_init: function() {
|
2011-02-09 17:27:00 +00:00
|
|
|
PanelMenu.Button.prototype._init.call(this, 0.0);
|
2010-05-10 13:46:54 +00:00
|
|
|
let box = new St.BoxLayout({ name: 'panelStatusMenu' });
|
|
|
|
this.actor.set_child(box);
|
|
|
|
|
2011-03-21 12:51:46 +00:00
|
|
|
this._lockdownSettings = new Gio.Settings({ schema: LOCKDOWN_SCHEMA });
|
|
|
|
|
2011-05-10 14:13:05 +00:00
|
|
|
this._userManager = AccountsService.UserManager.get_default();
|
2010-10-07 22:22:20 +00:00
|
|
|
|
2011-05-10 14:13:05 +00:00
|
|
|
this._user = this._userManager.get_user(GLib.get_user_name());
|
2010-04-29 17:13:20 +00:00
|
|
|
this._presence = new GnomeSession.Presence();
|
2011-03-12 20:34:01 +00:00
|
|
|
this._session = new GnomeSession.SessionManager();
|
2011-06-03 22:10:55 +00:00
|
|
|
this._haveShutdown = true;
|
2009-11-10 17:13:58 +00:00
|
|
|
|
2011-02-28 16:03:35 +00:00
|
|
|
this._account_mgr = Tp.AccountManager.dup()
|
|
|
|
|
2011-02-04 23:37:54 +00:00
|
|
|
this._upClient = new UPowerGlib.Client();
|
2011-07-12 15:42:33 +00:00
|
|
|
this._screenSaverProxy = new ScreenSaver.ScreenSaverProxy();
|
2009-11-10 17:13:58 +00:00
|
|
|
this.actor.connect('destroy', Lang.bind(this, this._onDestroy));
|
|
|
|
|
2009-11-10 21:34:13 +00:00
|
|
|
this._iconBox = new St.Bin();
|
2010-05-10 13:46:54 +00:00
|
|
|
box.add(this._iconBox, { y_align: St.Align.MIDDLE, y_fill: false });
|
2009-11-10 21:34:13 +00:00
|
|
|
|
2010-02-09 17:42:07 +00:00
|
|
|
let textureCache = St.TextureCache.get_default();
|
2011-07-28 14:59:03 +00:00
|
|
|
this._offlineIcon = new St.Icon({ icon_name: 'user-offline',
|
|
|
|
style_class: 'popup-menu-icon' });
|
|
|
|
this._availableIcon = new St.Icon({ icon_name: 'user-available',
|
|
|
|
style_class: 'popup-menu-icon' });
|
|
|
|
this._busyIcon = new St.Icon({ icon_name: 'user-busy',
|
|
|
|
style_class: 'popup-menu-icon' });
|
|
|
|
this._invisibleIcon = new St.Icon({ icon_name: 'user-invisible',
|
|
|
|
style_class: 'popup-menu-icon' });
|
|
|
|
this._awayIcon = new St.Icon({ icon_name: 'user-away',
|
|
|
|
style_class: 'popup-menu-icon' });
|
|
|
|
this._idleIcon = new St.Icon({ icon_name: 'user-idle',
|
|
|
|
style_class: 'popup-menu-icon' });
|
|
|
|
|
|
|
|
this._presence.connect('StatusChanged',
|
|
|
|
Lang.bind(this, this._updateSwitch));
|
|
|
|
this._presence.getStatus(Lang.bind(this, this._updateSwitch));
|
|
|
|
|
|
|
|
this._account_mgr.connect('most-available-presence-changed',
|
|
|
|
Lang.bind(this, this._updatePresenceIcon));
|
|
|
|
this._account_mgr.prepare_async(null, Lang.bind(this,
|
|
|
|
function(mgr) {
|
|
|
|
let [presence, s, msg] = mgr.get_most_available_presence();
|
|
|
|
this._updatePresenceIcon(mgr, presence, s, msg);
|
|
|
|
}));
|
2009-11-10 21:34:13 +00:00
|
|
|
|
2010-10-07 22:22:20 +00:00
|
|
|
this._name = new St.Label();
|
2010-05-10 13:46:54 +00:00
|
|
|
box.add(this._name, { y_align: St.Align.MIDDLE, y_fill: false });
|
2010-10-07 22:22:20 +00:00
|
|
|
this._userLoadedId = this._user.connect('notify::is-loaded', Lang.bind(this, this._updateUserName));
|
|
|
|
this._userChangedId = this._user.connect('changed', Lang.bind(this, this._updateUserName));
|
2009-11-10 17:13:58 +00:00
|
|
|
|
|
|
|
this._createSubMenu();
|
2011-05-10 14:13:05 +00:00
|
|
|
this._userManager.connect('notify::is-loaded',
|
|
|
|
Lang.bind(this, this._updateSwitchUser));
|
|
|
|
this._userManager.connect('user-added',
|
|
|
|
Lang.bind(this, this._updateSwitchUser));
|
|
|
|
this._userManager.connect('user-removed',
|
|
|
|
Lang.bind(this, this._updateSwitchUser));
|
2011-03-21 12:51:46 +00:00
|
|
|
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));
|
2011-06-03 22:10:55 +00:00
|
|
|
|
2011-03-21 12:51:46 +00:00
|
|
|
this._lockdownSettings.connect('changed::' + DISABLE_LOCK_SCREEN_KEY,
|
|
|
|
Lang.bind(this, this._updateLockScreen));
|
|
|
|
this._updateSwitchUser();
|
|
|
|
this._updateLogout();
|
|
|
|
this._updateLockScreen();
|
2011-02-04 23:37:54 +00:00
|
|
|
|
2011-06-03 22:10:55 +00:00
|
|
|
// 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));
|
|
|
|
|
2011-02-04 23:37:54 +00:00
|
|
|
this._upClient.connect('notify::can-suspend', Lang.bind(this, this._updateSuspendOrPowerOff));
|
2009-11-10 17:13:58 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
_onDestroy: function() {
|
2010-10-07 22:22:20 +00:00
|
|
|
this._user.disconnect(this._userLoadedId);
|
|
|
|
this._user.disconnect(this._userChangedId);
|
2009-11-10 17:13:58 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
_updateUserName: function() {
|
2010-10-07 22:22:20 +00:00
|
|
|
if (this._user.is_loaded)
|
2011-07-28 14:59:03 +00:00
|
|
|
this._name.set_text(this._user.get_real_name());
|
2010-10-07 22:22:20 +00:00
|
|
|
else
|
2011-07-28 14:59:03 +00:00
|
|
|
this._name.set_text("");
|
2009-11-10 17:13:58 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
_updateSwitchUser: function() {
|
2011-03-21 12:51:46 +00:00
|
|
|
let allowSwitch = !this._lockdownSettings.get_boolean(DISABLE_USER_SWITCH_KEY);
|
2011-05-10 14:13:05 +00:00
|
|
|
if (allowSwitch && this._userManager.can_switch ())
|
2010-05-10 13:46:54 +00:00
|
|
|
this._loginScreenItem.actor.show();
|
2009-11-10 17:13:58 +00:00
|
|
|
else
|
2010-05-10 13:46:54 +00:00
|
|
|
this._loginScreenItem.actor.hide();
|
2011-03-21 12:51:46 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
_updateLogout: function() {
|
|
|
|
let allowLogout = !this._lockdownSettings.get_boolean(DISABLE_LOG_OUT_KEY);
|
|
|
|
if (allowLogout)
|
|
|
|
this._logoutItem.actor.show();
|
|
|
|
else
|
|
|
|
this._logoutItem.actor.hide();
|
|
|
|
},
|
|
|
|
|
|
|
|
_updateLockScreen: function() {
|
|
|
|
let allowLockScreen = !this._lockdownSettings.get_boolean(DISABLE_LOCK_SCREEN_KEY);
|
|
|
|
if (allowLockScreen)
|
|
|
|
this._lockScreenItem.actor.show();
|
|
|
|
else
|
|
|
|
this._lockScreenItem.actor.hide();
|
2009-11-10 17:13:58 +00:00
|
|
|
},
|
|
|
|
|
2011-06-03 22:10:55 +00:00
|
|
|
_updateHaveShutdown: function() {
|
|
|
|
this._session.CanShutdownRemote(Lang.bind(this,
|
|
|
|
function(result, error) {
|
|
|
|
if (!error) {
|
|
|
|
this._haveShutdown = result;
|
|
|
|
this._updateSuspendOrPowerOff();
|
|
|
|
}
|
|
|
|
}));
|
|
|
|
},
|
|
|
|
|
2011-02-04 23:37:54 +00:00
|
|
|
_updateSuspendOrPowerOff: function() {
|
|
|
|
this._haveSuspend = this._upClient.get_can_suspend();
|
|
|
|
|
|
|
|
if (!this._suspendOrPowerOffItem)
|
|
|
|
return;
|
|
|
|
|
2011-06-03 22:10:55 +00:00
|
|
|
if (!this._haveShutdown && !this._haveSuspend)
|
|
|
|
this._suspendOrPowerOffItem.actor.hide();
|
|
|
|
else
|
|
|
|
this._suspendOrPowerOffItem.actor.show();
|
|
|
|
|
2011-02-04 23:37:54 +00:00
|
|
|
// If we can't suspend show Power Off... instead
|
|
|
|
// and disable the alt key
|
|
|
|
if (!this._haveSuspend) {
|
|
|
|
this._suspendOrPowerOffItem.updateText(_("Power Off..."), null);
|
2011-06-03 22:10:55 +00:00
|
|
|
} else if (!this._haveShutdown) {
|
|
|
|
this._suspendOrPowerOffItem.updateText(_("Suspend"), null);
|
2011-02-04 23:37:54 +00:00
|
|
|
} else {
|
2011-03-24 18:11:20 +00:00
|
|
|
this._suspendOrPowerOffItem.updateText(_("Suspend"), _("Power Off..."));
|
2011-02-04 23:37:54 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2011-07-28 14:59:03 +00:00
|
|
|
_updateSwitch: function(presence, status) {
|
|
|
|
let active = status == GnomeSession.PresenceStatus.BUSY;
|
|
|
|
this._dontDisturbSwitch.setToggleState(active);
|
|
|
|
},
|
|
|
|
|
|
|
|
_updatePresenceIcon: function(accountMgr, presence, status, message) {
|
|
|
|
if (presence == Tp.ConnectionPresenceType.AVAILABLE)
|
2009-11-10 21:34:13 +00:00
|
|
|
this._iconBox.child = this._availableIcon;
|
2011-07-28 14:59:03 +00:00
|
|
|
else if (presence == Tp.ConnectionPresenceType.BUSY)
|
2009-11-10 21:34:13 +00:00
|
|
|
this._iconBox.child = this._busyIcon;
|
2011-07-28 14:59:03 +00:00
|
|
|
else if (presence == Tp.ConnectionPresenceType.HIDDEN)
|
2009-11-10 21:34:13 +00:00
|
|
|
this._iconBox.child = this._invisibleIcon;
|
2011-07-28 14:59:03 +00:00
|
|
|
else if (presence == Tp.ConnectionPresenceType.AWAY)
|
|
|
|
this._iconBox.child = this._awayIcon;
|
|
|
|
else if (presence == Tp.ConnectionPresenceType.EXTENDED_AWAY)
|
2009-11-10 21:34:13 +00:00
|
|
|
this._iconBox.child = this._idleIcon;
|
2011-07-28 14:59:03 +00:00
|
|
|
else
|
|
|
|
this._iconBox.child = this._offlineIcon;
|
2009-11-10 21:34:13 +00:00
|
|
|
},
|
|
|
|
|
2009-11-10 17:13:58 +00:00
|
|
|
_createSubMenu: function() {
|
|
|
|
let item;
|
|
|
|
|
2011-07-28 14:59:03 +00:00
|
|
|
item = new IMStatusChooserItem();
|
|
|
|
item.connect('activate', Lang.bind(this, this._onMyAccountActivate));
|
2010-05-10 13:46:54 +00:00
|
|
|
this.menu.addMenuItem(item);
|
2009-11-10 21:34:13 +00:00
|
|
|
|
2011-07-28 14:59:03 +00:00
|
|
|
item = new PopupMenu.PopupSwitchMenuItem(_("Do Not Disturb"));
|
|
|
|
item.connect('activate', Lang.bind(this, this._updatePresenceStatus));
|
2010-05-10 13:46:54 +00:00
|
|
|
this.menu.addMenuItem(item);
|
2011-07-28 14:59:03 +00:00
|
|
|
this._dontDisturbSwitch = item;
|
2009-11-10 21:34:13 +00:00
|
|
|
|
2010-05-20 15:18:46 +00:00
|
|
|
item = new PopupMenu.PopupSeparatorMenuItem();
|
2010-05-10 13:46:54 +00:00
|
|
|
this.menu.addMenuItem(item);
|
2009-11-10 21:34:13 +00:00
|
|
|
|
2011-07-28 14:59:03 +00:00
|
|
|
item = new PopupMenu.PopupMenuItem(_("Online Accounts"));
|
|
|
|
item.connect('activate', Lang.bind(this, this._onOnlineAccountsActivate));
|
2010-05-10 13:46:54 +00:00
|
|
|
this.menu.addMenuItem(item);
|
2009-11-10 17:13:58 +00:00
|
|
|
|
2010-11-22 20:19:37 +00:00
|
|
|
item = new PopupMenu.PopupMenuItem(_("System Settings"));
|
2009-11-10 17:13:58 +00:00
|
|
|
item.connect('activate', Lang.bind(this, this._onPreferencesActivate));
|
2010-05-10 13:46:54 +00:00
|
|
|
this.menu.addMenuItem(item);
|
2009-11-10 17:13:58 +00:00
|
|
|
|
2010-05-20 15:18:46 +00:00
|
|
|
item = new PopupMenu.PopupSeparatorMenuItem();
|
2010-05-10 13:46:54 +00:00
|
|
|
this.menu.addMenuItem(item);
|
2009-11-10 17:13:58 +00:00
|
|
|
|
2010-10-19 15:59:23 +00:00
|
|
|
item = new PopupMenu.PopupMenuItem(_("Lock Screen"));
|
2009-11-10 17:13:58 +00:00
|
|
|
item.connect('activate', Lang.bind(this, this._onLockScreenActivate));
|
2010-05-10 13:46:54 +00:00
|
|
|
this.menu.addMenuItem(item);
|
2011-03-21 12:51:46 +00:00
|
|
|
this._lockScreenItem = item;
|
2009-11-10 17:13:58 +00:00
|
|
|
|
2010-10-19 15:59:23 +00:00
|
|
|
item = new PopupMenu.PopupMenuItem(_("Switch User"));
|
2009-11-10 17:13:58 +00:00
|
|
|
item.connect('activate', Lang.bind(this, this._onLoginScreenActivate));
|
2010-05-10 13:46:54 +00:00
|
|
|
this.menu.addMenuItem(item);
|
2009-11-10 17:13:58 +00:00
|
|
|
this._loginScreenItem = item;
|
|
|
|
|
2010-10-19 15:59:23 +00:00
|
|
|
item = new PopupMenu.PopupMenuItem(_("Log Out..."));
|
2009-11-10 17:13:58 +00:00
|
|
|
item.connect('activate', Lang.bind(this, this._onQuitSessionActivate));
|
2010-05-10 13:46:54 +00:00
|
|
|
this.menu.addMenuItem(item);
|
2011-03-21 12:51:46 +00:00
|
|
|
this._logoutItem = item;
|
2009-11-10 17:13:58 +00:00
|
|
|
|
2010-10-19 16:04:58 +00:00
|
|
|
item = new PopupMenu.PopupSeparatorMenuItem();
|
|
|
|
this.menu.addMenuItem(item);
|
|
|
|
|
2011-02-04 23:37:54 +00:00
|
|
|
item = new PopupMenu.PopupAlternatingMenuItem(_("Suspend"),
|
|
|
|
_("Power Off..."));
|
2010-05-10 13:46:54 +00:00
|
|
|
this.menu.addMenuItem(item);
|
2011-02-04 23:37:54 +00:00
|
|
|
this._suspendOrPowerOffItem = item;
|
|
|
|
item.connect('activate', Lang.bind(this, this._onSuspendOrPowerOffActivate));
|
|
|
|
this._updateSuspendOrPowerOff();
|
2009-11-10 17:13:58 +00:00
|
|
|
},
|
|
|
|
|
2011-07-28 14:59:03 +00:00
|
|
|
_updatePresenceStatus: function(item, event) {
|
|
|
|
let status = item.state ? GnomeSession.PresenceStatus.BUSY
|
|
|
|
: GnomeSession.PresenceStatus.AVAILABLE;
|
2009-11-10 21:34:13 +00:00
|
|
|
this._presence.setStatus(status);
|
|
|
|
},
|
|
|
|
|
2010-10-19 16:04:58 +00:00
|
|
|
_onMyAccountActivate: function() {
|
2010-06-03 23:21:08 +00:00
|
|
|
Main.overview.hide();
|
Kill off ShellAppInfo, move into ShellApp
This dramatically thins down and sanitizes the application code.
The ShellAppSystem changes in a number of ways:
* Preferences are special cased more explicitly; they aren't apps,
they're shortcuts for an app), and we don't have many of them, so
don't need e.g. the optimizations in ShellAppSystem for searching.
* get_app() changes to lookup_app() and returns null if an app isn't
found. The semantics where it tried to find the .desktop file
if we didn't know about it were just broken; I am pretty sure no
caller needs this, and if they do we'll fix them.
* ShellAppSystem maintains two indexes on apps (by desktop file id
and by GMenuTreeEntry), but is no longer in the business of
dealing with GMenuTree as far as hierarchy and categories go. That
is moved up into js/ui/appDisplay.js. Actually, it flattens both
apps and settings.
Also, ShellWindowTracker is now the sole reference-owner for
window-backed apps. We still do the weird "window:0x1234beef" id
for these apps, but a reference is not stored in ShellAppSystem.
The js/ui/appDisplay.js code is rewritten, and sucks a lot less.
Variable names are clearer:
_apps -> _appIcons
_filterApp -> _visibleApps
_filters -> _categoryBox
Similarly for function names. We no longer call (for every app) a
recursive lookup in GMenuTree to see if it's in a particular section
on every category switch; it's all cached.
NOTE - this intentionally reverts the incremental loading code from
commit 7813c5b93f6bcde8c4beae286e82bfc472b2b656. It's fast enough
here without that.
https://bugzilla.gnome.org/show_bug.cgi?id=648149
2011-04-21 17:35:01 +00:00
|
|
|
let app = Shell.AppSystem.get_default().lookup_setting('gnome-user-accounts-panel.desktop');
|
2011-08-11 09:35:23 +00:00
|
|
|
app.activate();
|
2009-11-10 17:13:58 +00:00
|
|
|
},
|
|
|
|
|
2011-07-28 14:59:03 +00:00
|
|
|
_onOnlineAccountsActivate: function() {
|
|
|
|
Main.overview.hide();
|
|
|
|
let app = Shell.AppSystem.get_default().lookup_setting('gnome-online-accounts-panel.desktop');
|
|
|
|
app.activate(-1);
|
|
|
|
},
|
|
|
|
|
2009-11-10 17:13:58 +00:00
|
|
|
_onPreferencesActivate: function() {
|
2010-06-03 23:21:08 +00:00
|
|
|
Main.overview.hide();
|
Kill off ShellAppInfo, move into ShellApp
This dramatically thins down and sanitizes the application code.
The ShellAppSystem changes in a number of ways:
* Preferences are special cased more explicitly; they aren't apps,
they're shortcuts for an app), and we don't have many of them, so
don't need e.g. the optimizations in ShellAppSystem for searching.
* get_app() changes to lookup_app() and returns null if an app isn't
found. The semantics where it tried to find the .desktop file
if we didn't know about it were just broken; I am pretty sure no
caller needs this, and if they do we'll fix them.
* ShellAppSystem maintains two indexes on apps (by desktop file id
and by GMenuTreeEntry), but is no longer in the business of
dealing with GMenuTree as far as hierarchy and categories go. That
is moved up into js/ui/appDisplay.js. Actually, it flattens both
apps and settings.
Also, ShellWindowTracker is now the sole reference-owner for
window-backed apps. We still do the weird "window:0x1234beef" id
for these apps, but a reference is not stored in ShellAppSystem.
The js/ui/appDisplay.js code is rewritten, and sucks a lot less.
Variable names are clearer:
_apps -> _appIcons
_filterApp -> _visibleApps
_filters -> _categoryBox
Similarly for function names. We no longer call (for every app) a
recursive lookup in GMenuTree to see if it's in a particular section
on every category switch; it's all cached.
NOTE - this intentionally reverts the incremental loading code from
commit 7813c5b93f6bcde8c4beae286e82bfc472b2b656. It's fast enough
here without that.
https://bugzilla.gnome.org/show_bug.cgi?id=648149
2011-04-21 17:35:01 +00:00
|
|
|
let app = Shell.AppSystem.get_default().lookup_app('gnome-control-center.desktop');
|
2011-08-11 09:35:23 +00:00
|
|
|
app.activate();
|
2009-11-10 17:13:58 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
_onLockScreenActivate: function() {
|
2010-06-03 23:21:08 +00:00
|
|
|
Main.overview.hide();
|
2011-03-09 20:59:26 +00:00
|
|
|
this._screenSaverProxy.LockRemote();
|
2009-11-10 17:13:58 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
_onLoginScreenActivate: function() {
|
2010-06-03 23:21:08 +00:00
|
|
|
Main.overview.hide();
|
2011-07-05 13:29:05 +00:00
|
|
|
// Ensure we only move to GDM after the screensaver has activated; in some
|
|
|
|
// OS configurations, the X server may block event processing on VT switch
|
2011-07-13 21:43:23 +00:00
|
|
|
this._screenSaverProxy.SetActiveRemote(true, Lang.bind(this, function() {
|
2011-05-10 14:13:05 +00:00
|
|
|
this._userManager.goto_login_session();
|
2011-07-05 13:29:05 +00:00
|
|
|
}));
|
2009-11-10 17:13:58 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
_onQuitSessionActivate: function() {
|
2010-06-03 23:21:08 +00:00
|
|
|
Main.overview.hide();
|
2011-03-12 20:34:01 +00:00
|
|
|
this._session.LogoutRemote(0);
|
2009-11-10 17:13:58 +00:00
|
|
|
},
|
|
|
|
|
2011-02-04 23:37:54 +00:00
|
|
|
_onSuspendOrPowerOffActivate: function() {
|
2010-06-03 23:21:08 +00:00
|
|
|
Main.overview.hide();
|
2011-02-04 23:37:54 +00:00
|
|
|
|
|
|
|
if (this._haveSuspend &&
|
|
|
|
this._suspendOrPowerOffItem.state == PopupMenu.PopupAlternatingMenuItemState.DEFAULT) {
|
2011-07-05 13:29:05 +00:00
|
|
|
// Ensure we only suspend after the screensaver has activated
|
2011-06-10 20:58:54 +00:00
|
|
|
this._screenSaverProxy.SetActiveRemote(true, Lang.bind(this, function() {
|
2011-03-09 20:59:50 +00:00
|
|
|
this._upClient.suspend_sync(null);
|
|
|
|
}));
|
2011-02-04 23:37:54 +00:00
|
|
|
} else {
|
2011-03-12 20:34:01 +00:00
|
|
|
this._session.ShutdownRemote();
|
2011-02-04 23:37:54 +00:00
|
|
|
}
|
2009-11-10 17:13:58 +00:00
|
|
|
}
|
|
|
|
};
|