2009-11-10 12:13:58 -05:00
|
|
|
/* -*- mode: js2; js2-basic-offset: 4; indent-tabs-mode: nil -*- */
|
|
|
|
|
|
|
|
const Gdm = imports.gi.Gdm;
|
|
|
|
const GLib = imports.gi.GLib;
|
|
|
|
const Lang = imports.lang;
|
|
|
|
const Shell = imports.gi.Shell;
|
|
|
|
const St = imports.gi.St;
|
|
|
|
const Gettext = imports.gettext.domain('gnome-shell');
|
|
|
|
const _ = Gettext.gettext;
|
|
|
|
|
2010-04-29 13:13:20 -04:00
|
|
|
const GnomeSession = imports.misc.gnomeSession;
|
2010-06-03 19:21:08 -04:00
|
|
|
const Main = imports.ui.main;
|
2010-06-22 17:02:26 -04:00
|
|
|
const PanelMenu = imports.ui.panelMenu;
|
2010-05-20 11:18:46 -04:00
|
|
|
const PopupMenu = imports.ui.popupMenu;
|
2010-11-17 11:43:08 -05:00
|
|
|
const Util = imports.misc.util;
|
2009-11-10 12:13:58 -05: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.
|
|
|
|
|
2010-05-10 09:46:54 -04:00
|
|
|
function StatusMenuButton() {
|
2009-11-10 12:13:58 -05:00
|
|
|
this._init();
|
|
|
|
}
|
|
|
|
|
2010-05-10 09:46:54 -04:00
|
|
|
StatusMenuButton.prototype = {
|
2010-06-22 17:02:26 -04:00
|
|
|
__proto__: PanelMenu.Button.prototype,
|
2010-05-10 09:46:54 -04:00
|
|
|
|
2009-11-10 12:13:58 -05:00
|
|
|
_init: function() {
|
2011-02-09 12:27:00 -05:00
|
|
|
PanelMenu.Button.prototype._init.call(this, 0.0);
|
2010-05-10 09:46:54 -04:00
|
|
|
let box = new St.BoxLayout({ name: 'panelStatusMenu' });
|
|
|
|
this.actor.set_child(box);
|
|
|
|
|
2009-11-10 12:13:58 -05:00
|
|
|
this._gdm = Gdm.UserManager.ref_default();
|
2010-11-17 11:43:08 -05:00
|
|
|
this._gdm.queue_load();
|
2010-10-07 18:22:20 -04:00
|
|
|
|
2009-11-10 12:13:58 -05:00
|
|
|
this._user = this._gdm.get_user(GLib.get_user_name());
|
2010-04-29 13:13:20 -04:00
|
|
|
this._presence = new GnomeSession.Presence();
|
2010-10-20 12:43:22 -04:00
|
|
|
this._presenceItems = {};
|
2009-11-10 12:13:58 -05:00
|
|
|
|
|
|
|
this.actor.connect('destroy', Lang.bind(this, this._onDestroy));
|
|
|
|
|
2009-11-10 16:34:13 -05:00
|
|
|
this._iconBox = new St.Bin();
|
2010-05-10 09:46:54 -04:00
|
|
|
box.add(this._iconBox, { y_align: St.Align.MIDDLE, y_fill: false });
|
2009-11-10 16:34:13 -05:00
|
|
|
|
2010-02-09 12:42:07 -05:00
|
|
|
let textureCache = St.TextureCache.get_default();
|
2010-11-02 18:33:22 -04:00
|
|
|
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._idleIcon = new St.Icon({ icon_name: 'user-idle', style_class: 'popup-menu-icon' });
|
2009-11-10 16:34:13 -05:00
|
|
|
|
|
|
|
this._presence.connect('StatusChanged', Lang.bind(this, this._updatePresenceIcon));
|
|
|
|
this._presence.getStatus(Lang.bind(this, this._updatePresenceIcon));
|
|
|
|
|
2010-10-07 18:22:20 -04:00
|
|
|
this._name = new St.Label();
|
2010-05-10 09:46:54 -04:00
|
|
|
box.add(this._name, { y_align: St.Align.MIDDLE, y_fill: false });
|
2010-10-07 18:22:20 -04: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 12:13:58 -05:00
|
|
|
|
|
|
|
this._createSubMenu();
|
2010-10-07 18:22:20 -04:00
|
|
|
this._gdm.connect('notify::is-loaded', Lang.bind(this, this._updateSwitchUser));
|
2009-11-10 12:13:58 -05:00
|
|
|
this._gdm.connect('user-added', Lang.bind(this, this._updateSwitchUser));
|
|
|
|
this._gdm.connect('user-removed', Lang.bind(this, this._updateSwitchUser));
|
|
|
|
},
|
|
|
|
|
|
|
|
_onDestroy: function() {
|
2010-10-07 18:22:20 -04:00
|
|
|
this._user.disconnect(this._userLoadedId);
|
|
|
|
this._user.disconnect(this._userChangedId);
|
2009-11-10 12:13:58 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
_updateUserName: function() {
|
2010-10-07 18:22:20 -04:00
|
|
|
if (this._user.is_loaded)
|
|
|
|
this._name.set_text(this._user.get_real_name());
|
|
|
|
else
|
|
|
|
this._name.set_text("");
|
2009-11-10 12:13:58 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
_updateSwitchUser: function() {
|
2010-10-07 18:22:20 -04:00
|
|
|
if (this._gdm.can_switch ())
|
2010-05-10 09:46:54 -04:00
|
|
|
this._loginScreenItem.actor.show();
|
2009-11-10 12:13:58 -05:00
|
|
|
else
|
2010-05-10 09:46:54 -04:00
|
|
|
this._loginScreenItem.actor.hide();
|
2009-11-10 12:13:58 -05:00
|
|
|
},
|
|
|
|
|
2009-11-10 16:34:13 -05:00
|
|
|
_updatePresenceIcon: function(presence, status) {
|
2010-04-29 13:13:20 -04:00
|
|
|
if (status == GnomeSession.PresenceStatus.AVAILABLE)
|
2009-11-10 16:34:13 -05:00
|
|
|
this._iconBox.child = this._availableIcon;
|
2010-04-29 13:13:20 -04:00
|
|
|
else if (status == GnomeSession.PresenceStatus.BUSY)
|
2009-11-10 16:34:13 -05:00
|
|
|
this._iconBox.child = this._busyIcon;
|
2010-04-29 13:13:20 -04:00
|
|
|
else if (status == GnomeSession.PresenceStatus.INVISIBLE)
|
2009-11-10 16:34:13 -05:00
|
|
|
this._iconBox.child = this._invisibleIcon;
|
|
|
|
else
|
|
|
|
this._iconBox.child = this._idleIcon;
|
2010-10-20 12:43:22 -04:00
|
|
|
|
|
|
|
for (let itemStatus in this._presenceItems)
|
|
|
|
this._presenceItems[itemStatus].setShowDot(itemStatus == status);
|
2009-11-10 16:34:13 -05:00
|
|
|
},
|
|
|
|
|
2009-11-10 12:13:58 -05:00
|
|
|
_createSubMenu: function() {
|
|
|
|
let item;
|
|
|
|
|
2011-01-25 16:06:40 -05:00
|
|
|
item = new PopupMenu.PopupImageMenuItem(_("Available"), 'user-available');
|
2010-04-29 13:13:20 -04:00
|
|
|
item.connect('activate', Lang.bind(this, this._setPresenceStatus, GnomeSession.PresenceStatus.AVAILABLE));
|
2010-05-10 09:46:54 -04:00
|
|
|
this.menu.addMenuItem(item);
|
2010-10-20 12:43:22 -04:00
|
|
|
this._presenceItems[GnomeSession.PresenceStatus.AVAILABLE] = item;
|
2009-11-10 16:34:13 -05:00
|
|
|
|
2011-01-25 16:06:40 -05:00
|
|
|
item = new PopupMenu.PopupImageMenuItem(_("Busy"), 'user-busy');
|
2010-04-29 13:13:20 -04:00
|
|
|
item.connect('activate', Lang.bind(this, this._setPresenceStatus, GnomeSession.PresenceStatus.BUSY));
|
2010-05-10 09:46:54 -04:00
|
|
|
this.menu.addMenuItem(item);
|
2010-10-20 12:43:22 -04:00
|
|
|
this._presenceItems[GnomeSession.PresenceStatus.BUSY] = item;
|
2009-11-10 16:34:13 -05:00
|
|
|
|
2010-05-20 11:18:46 -04:00
|
|
|
item = new PopupMenu.PopupSeparatorMenuItem();
|
2010-05-10 09:46:54 -04:00
|
|
|
this.menu.addMenuItem(item);
|
2009-11-10 16:34:13 -05:00
|
|
|
|
2010-11-22 15:19:37 -05:00
|
|
|
item = new PopupMenu.PopupMenuItem(_("My Account"));
|
2010-10-19 12:04:58 -04:00
|
|
|
item.connect('activate', Lang.bind(this, this._onMyAccountActivate));
|
2010-05-10 09:46:54 -04:00
|
|
|
this.menu.addMenuItem(item);
|
2009-11-10 12:13:58 -05:00
|
|
|
|
2010-11-22 15:19:37 -05:00
|
|
|
item = new PopupMenu.PopupMenuItem(_("System Settings"));
|
2009-11-10 12:13:58 -05:00
|
|
|
item.connect('activate', Lang.bind(this, this._onPreferencesActivate));
|
2010-05-10 09:46:54 -04:00
|
|
|
this.menu.addMenuItem(item);
|
2009-11-10 12:13:58 -05:00
|
|
|
|
2010-05-20 11:18:46 -04:00
|
|
|
item = new PopupMenu.PopupSeparatorMenuItem();
|
2010-05-10 09:46:54 -04:00
|
|
|
this.menu.addMenuItem(item);
|
2009-11-10 12:13:58 -05:00
|
|
|
|
2010-10-19 11:59:23 -04:00
|
|
|
item = new PopupMenu.PopupMenuItem(_("Lock Screen"));
|
2009-11-10 12:13:58 -05:00
|
|
|
item.connect('activate', Lang.bind(this, this._onLockScreenActivate));
|
2010-05-10 09:46:54 -04:00
|
|
|
this.menu.addMenuItem(item);
|
2009-11-10 12:13:58 -05:00
|
|
|
|
2010-10-19 11:59:23 -04:00
|
|
|
item = new PopupMenu.PopupMenuItem(_("Switch User"));
|
2009-11-10 12:13:58 -05:00
|
|
|
item.connect('activate', Lang.bind(this, this._onLoginScreenActivate));
|
2010-05-10 09:46:54 -04:00
|
|
|
this.menu.addMenuItem(item);
|
2009-11-10 12:13:58 -05:00
|
|
|
this._loginScreenItem = item;
|
|
|
|
|
2010-10-19 11:59:23 -04:00
|
|
|
item = new PopupMenu.PopupMenuItem(_("Log Out..."));
|
2009-11-10 12:13:58 -05:00
|
|
|
item.connect('activate', Lang.bind(this, this._onQuitSessionActivate));
|
2010-05-10 09:46:54 -04:00
|
|
|
this.menu.addMenuItem(item);
|
2009-11-10 12:13:58 -05:00
|
|
|
|
2010-10-19 12:04:58 -04:00
|
|
|
item = new PopupMenu.PopupSeparatorMenuItem();
|
|
|
|
this.menu.addMenuItem(item);
|
|
|
|
|
2011-02-04 17:25:20 -05:00
|
|
|
// This is temporarily removed, see
|
|
|
|
// http://bugzilla.gnome.org/show_bug.cgi?id=636680
|
|
|
|
// for details.
|
|
|
|
//item = new PopupMenu.PopupMenuItem(_("Suspend..."));
|
|
|
|
//item.connect('activate', Lang.bind(this, this._onShutDownActivate));
|
|
|
|
//this.menu.addMenuItem(item);
|
2010-10-19 12:04:58 -04:00
|
|
|
|
2010-10-19 11:59:23 -04:00
|
|
|
item = new PopupMenu.PopupMenuItem(_("Shut Down..."));
|
2009-11-10 12:13:58 -05:00
|
|
|
item.connect('activate', Lang.bind(this, this._onShutDownActivate));
|
2010-05-10 09:46:54 -04:00
|
|
|
this.menu.addMenuItem(item);
|
2009-11-10 12:13:58 -05:00
|
|
|
},
|
|
|
|
|
2010-05-11 14:20:01 -04:00
|
|
|
_setPresenceStatus: function(item, event, status) {
|
2009-11-10 16:34:13 -05:00
|
|
|
this._presence.setStatus(status);
|
|
|
|
},
|
|
|
|
|
2010-10-19 12:04:58 -04:00
|
|
|
_onMyAccountActivate: function() {
|
2010-06-03 19:21:08 -04:00
|
|
|
Main.overview.hide();
|
2010-11-17 11:43:08 -05:00
|
|
|
Util.spawnDesktop('gnome-user-accounts-panel');
|
2009-11-10 12:13:58 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
_onPreferencesActivate: function() {
|
2010-06-03 19:21:08 -04:00
|
|
|
Main.overview.hide();
|
2010-11-17 11:43:08 -05:00
|
|
|
Util.spawnDesktop('gnome-control-center');
|
2009-11-10 12:13:58 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
_onLockScreenActivate: function() {
|
2010-06-03 19:21:08 -04:00
|
|
|
Main.overview.hide();
|
2010-11-17 11:43:08 -05:00
|
|
|
Util.spawn(['gnome-screensaver-command', '--lock']);
|
2009-11-10 12:13:58 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
_onLoginScreenActivate: function() {
|
2010-06-03 19:21:08 -04:00
|
|
|
Main.overview.hide();
|
2009-11-10 12:13:58 -05:00
|
|
|
this._gdm.goto_login_session();
|
|
|
|
this._onLockScreenActivate();
|
|
|
|
},
|
|
|
|
|
|
|
|
_onQuitSessionActivate: function() {
|
2010-06-03 19:21:08 -04:00
|
|
|
Main.overview.hide();
|
2010-11-17 11:43:08 -05:00
|
|
|
Util.spawn(['gnome-session-save', '--logout-dialog']);
|
2009-11-10 12:13:58 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
_onShutDownActivate: function() {
|
2010-06-03 19:21:08 -04:00
|
|
|
Main.overview.hide();
|
2010-11-17 11:43:08 -05:00
|
|
|
Util.spawn(['gnome-session-save', '--shutdown-dialog']);
|
2009-11-10 12:13:58 -05:00
|
|
|
}
|
|
|
|
};
|