2012-05-20 12:30:14 -04:00
|
|
|
// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
|
|
|
|
|
|
|
|
const AccountsService = imports.gi.AccountsService;
|
|
|
|
const Clutter = imports.gi.Clutter;
|
|
|
|
const Gdm = imports.gi.Gdm;
|
|
|
|
const Gio = imports.gi.Gio;
|
|
|
|
const GLib = imports.gi.GLib;
|
|
|
|
const Gtk = imports.gi.Gtk;
|
|
|
|
const Lang = imports.lang;
|
|
|
|
const Signals = imports.signals;
|
|
|
|
const Shell = imports.gi.Shell;
|
|
|
|
const St = imports.gi.St;
|
|
|
|
|
|
|
|
const Main = imports.ui.main;
|
|
|
|
const ModalDialog = imports.ui.modalDialog;
|
|
|
|
const ShellEntry = imports.ui.shellEntry;
|
|
|
|
const Tweener = imports.ui.tweener;
|
|
|
|
const UserMenu = imports.ui.userMenu;
|
|
|
|
|
|
|
|
const Batch = imports.gdm.batch;
|
|
|
|
const GdmUtil = imports.gdm.util;
|
|
|
|
|
2012-08-16 15:24:53 -04:00
|
|
|
// The timeout before going back automatically to the lock screen (in seconds)
|
|
|
|
const IDLE_TIMEOUT = 2 * 60;
|
|
|
|
|
2012-05-20 12:30:14 -04:00
|
|
|
// A widget showing the user avatar and name
|
|
|
|
const UserWidget = new Lang.Class({
|
|
|
|
Name: 'UserWidget',
|
|
|
|
|
|
|
|
_init: function(user) {
|
|
|
|
this._user = user;
|
|
|
|
|
|
|
|
this.actor = new St.BoxLayout({ style_class: 'unlock-dialog-user-name-container',
|
|
|
|
vertical: false });
|
|
|
|
|
2012-08-31 17:18:26 -04:00
|
|
|
this._avatar = new UserMenu.UserAvatarWidget(user);
|
2012-05-20 12:30:14 -04:00
|
|
|
this.actor.add(this._avatar.actor,
|
|
|
|
{ x_fill: true, y_fill: true });
|
|
|
|
|
2012-06-03 13:31:34 -04:00
|
|
|
this._label = new St.Label({ style_class: 'login-dialog-username' });
|
2012-05-20 12:30:14 -04:00
|
|
|
this.actor.add(this._label,
|
|
|
|
{ expand: true,
|
|
|
|
x_fill: true,
|
2012-09-05 13:23:45 -04:00
|
|
|
y_fill: false,
|
2012-06-03 13:31:34 -04:00
|
|
|
y_align: St.Align.MIDDLE });
|
2012-05-20 12:30:14 -04: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));
|
|
|
|
if (this._user.is_loaded)
|
|
|
|
this._updateUser();
|
|
|
|
},
|
|
|
|
|
|
|
|
destroy: function() {
|
|
|
|
if (this._userLoadedId != 0) {
|
|
|
|
this._user.disconnect(this._userLoadedId);
|
|
|
|
this._userLoadedId = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this._userChangedId != 0) {
|
|
|
|
this._user.disconnect(this._userChangedId);
|
|
|
|
this._userChangedId = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.actor.destroy();
|
|
|
|
},
|
|
|
|
|
|
|
|
_updateUser: function() {
|
|
|
|
if (this._user.is_loaded)
|
|
|
|
this._label.text = this._user.get_real_name();
|
|
|
|
else
|
|
|
|
this._label.text = '';
|
|
|
|
|
|
|
|
this._avatar.update();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
const UnlockDialog = new Lang.Class({
|
|
|
|
Name: 'UnlockDialog',
|
|
|
|
Extends: ModalDialog.ModalDialog,
|
|
|
|
|
2012-05-24 16:47:48 -04:00
|
|
|
_init: function(parentActor) {
|
2012-05-20 12:30:14 -04:00
|
|
|
this.parent({ shellReactive: true,
|
2012-05-24 16:47:48 -04:00
|
|
|
styleClass: 'login-dialog',
|
|
|
|
parentActor: parentActor
|
|
|
|
});
|
2012-05-20 12:30:14 -04:00
|
|
|
|
|
|
|
this._userManager = AccountsService.UserManager.get_default();
|
|
|
|
this._userName = GLib.get_user_name();
|
|
|
|
this._user = this._userManager.get_user(this._userName);
|
|
|
|
|
2012-08-07 10:49:22 -04:00
|
|
|
this._failCounter = 0;
|
2012-08-13 06:49:04 -04:00
|
|
|
this._firstQuestion = true;
|
2012-08-07 10:49:22 -04:00
|
|
|
|
2012-05-20 12:30:14 -04:00
|
|
|
this._greeterClient = new Gdm.Client();
|
2012-08-03 11:10:45 -04:00
|
|
|
this._userVerifier = new GdmUtil.ShellUserVerifier(this._greeterClient, { reauthenticationOnly: true });
|
2012-05-20 12:30:14 -04:00
|
|
|
|
|
|
|
this._userVerifier.connect('ask-question', Lang.bind(this, this._onAskQuestion));
|
2012-08-07 10:49:22 -04:00
|
|
|
this._userVerifier.connect('show-message', Lang.bind(this, this._showMessage));
|
2012-05-20 12:30:14 -04:00
|
|
|
this._userVerifier.connect('verification-complete', Lang.bind(this, this._onVerificationComplete));
|
2012-08-07 10:49:22 -04:00
|
|
|
this._userVerifier.connect('reset', Lang.bind(this, this._onReset));
|
2012-05-20 12:30:14 -04:00
|
|
|
|
2012-08-19 20:15:18 -04:00
|
|
|
this._userVerifier.connect('show-login-hint', Lang.bind(this, this._showLoginHint));
|
|
|
|
this._userVerifier.connect('hide-login-hint', Lang.bind(this, this._hideLoginHint));
|
2012-05-20 12:30:14 -04:00
|
|
|
|
|
|
|
this._userWidget = new UserWidget(this._user);
|
|
|
|
this.contentLayout.add_actor(this._userWidget.actor);
|
|
|
|
|
|
|
|
this._promptLayout = new St.BoxLayout({ style_class: 'login-dialog-prompt-layout',
|
2012-08-07 11:57:38 -04:00
|
|
|
vertical: true });
|
2012-05-20 12:30:14 -04:00
|
|
|
|
|
|
|
this._promptLabel = new St.Label({ style_class: 'login-dialog-prompt-label' });
|
|
|
|
this._promptLayout.add(this._promptLabel,
|
2012-06-03 13:31:34 -04:00
|
|
|
{ x_align: St.Align.START });
|
2012-05-20 12:30:14 -04:00
|
|
|
|
|
|
|
this._promptEntry = new St.Entry({ style_class: 'login-dialog-prompt-entry',
|
|
|
|
can_focus: true });
|
2012-08-13 06:49:04 -04:00
|
|
|
this._promptEntry.clutter_text.set_password_char('\u25cf');
|
|
|
|
ShellEntry.addContextMenu(this._promptEntry, { isPassword: true });
|
2012-05-20 12:30:14 -04:00
|
|
|
this.setInitialKeyFocus(this._promptEntry);
|
|
|
|
this._promptEntry.clutter_text.connect('activate', Lang.bind(this, this._doUnlock));
|
|
|
|
|
|
|
|
this._promptLayout.add(this._promptEntry,
|
|
|
|
{ expand: true,
|
2012-06-03 13:31:34 -04:00
|
|
|
x_fill: true });
|
2012-05-20 12:30:14 -04:00
|
|
|
|
|
|
|
this.contentLayout.add_actor(this._promptLayout);
|
|
|
|
|
2012-08-07 10:49:22 -04:00
|
|
|
this._promptMessage = new St.Label({ visible: false });
|
|
|
|
this.contentLayout.add(this._promptMessage, { x_fill: true });
|
|
|
|
|
2012-08-19 20:15:18 -04:00
|
|
|
this._promptLoginHint = new St.Label({ style_class: 'login-dialog-prompt-login-hint' });
|
|
|
|
this._promptLoginHint.hide();
|
|
|
|
this.contentLayout.add_actor(this._promptLoginHint);
|
2012-05-20 12:30:14 -04:00
|
|
|
|
2012-08-16 16:53:21 -04:00
|
|
|
let cancelButton = { label: _("Cancel"),
|
|
|
|
action: Lang.bind(this, this._escape),
|
|
|
|
key: Clutter.KEY_Escape };
|
2012-08-07 11:38:12 -04:00
|
|
|
this._okButton = { label: _("Unlock"),
|
|
|
|
action: Lang.bind(this, this._doUnlock),
|
|
|
|
default: true };
|
2012-08-16 16:53:21 -04:00
|
|
|
this.setButtons([cancelButton, this._okButton]);
|
2012-08-07 11:38:12 -04:00
|
|
|
|
2012-08-13 06:49:04 -04:00
|
|
|
this._updateOkButton(true);
|
2012-08-07 11:38:12 -04:00
|
|
|
|
2012-08-18 22:58:50 -04:00
|
|
|
let otherUserLabel = new St.Label({ text: _("Log in as another user"),
|
2012-05-20 12:30:14 -04:00
|
|
|
style_class: 'login-dialog-not-listed-label' });
|
|
|
|
this._otherUserButton = new St.Button({ style_class: 'login-dialog-not-listed-button',
|
|
|
|
can_focus: true,
|
|
|
|
child: otherUserLabel,
|
|
|
|
reactive: true,
|
|
|
|
x_align: St.Align.START,
|
|
|
|
x_fill: true });
|
|
|
|
this._otherUserButton.connect('clicked', Lang.bind(this, this._otherUserClicked));
|
2012-08-07 11:38:12 -04:00
|
|
|
this.dialogLayout.add(this._otherUserButton,
|
|
|
|
{ x_align: St.Align.START,
|
|
|
|
x_fill: false });
|
2012-05-26 11:04:25 -04:00
|
|
|
|
2012-08-07 10:49:22 -04:00
|
|
|
let batch = new Batch.Hold();
|
|
|
|
this._userVerifier.begin(this._userName, batch);
|
|
|
|
|
2012-05-26 11:04:25 -04:00
|
|
|
GLib.idle_add(GLib.PRIORITY_DEFAULT, Lang.bind(this, function() {
|
|
|
|
this.emit('loaded');
|
|
|
|
return false;
|
|
|
|
}));
|
2012-08-16 15:24:53 -04:00
|
|
|
|
|
|
|
this._idleMonitor = Shell.IdleMonitor.get();
|
|
|
|
// this dialog is only created after user activity (curtain drag or
|
|
|
|
// escape key press), so the timeout will fire after IDLE_TIMEOUT seconds of inactivity
|
|
|
|
this._idleWatchId = this._idleMonitor.add_watch(IDLE_TIMEOUT * 1000, Lang.bind(this, this._escape));
|
2012-05-20 12:30:14 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
_updateOkButton: function(sensitive) {
|
|
|
|
this._okButton.button.reactive = sensitive;
|
2012-08-13 06:49:04 -04:00
|
|
|
this._okButton.button.can_focus = sensitive;
|
2012-05-20 12:30:14 -04:00
|
|
|
},
|
|
|
|
|
2012-08-07 10:49:22 -04:00
|
|
|
_showMessage: function(userVerifier, message, styleClass) {
|
|
|
|
this._promptMessage.text = message;
|
|
|
|
this._promptMessage.styleClass = styleClass;
|
|
|
|
GdmUtil.fadeInActor(this._promptMessage);
|
2012-05-20 12:30:14 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
_onAskQuestion: function(verifier, serviceName, question, passwordChar) {
|
2012-08-13 06:49:04 -04:00
|
|
|
if (this._firstQuestion && this._firstQuestionAnswer) {
|
|
|
|
this._userVerifier.answerQuery(serviceName, this._firstQuestionAnswer);
|
|
|
|
this._firstQuestionAnswer = null;
|
|
|
|
this._firstQuestion = false;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-05-20 12:30:14 -04:00
|
|
|
this._promptLabel.text = question;
|
|
|
|
|
2012-08-13 06:49:04 -04:00
|
|
|
if (!this._firstQuestion)
|
|
|
|
this._promptEntry.text = '';
|
|
|
|
else
|
|
|
|
this._firstQuestion = false;
|
|
|
|
|
2012-05-20 12:30:14 -04:00
|
|
|
this._promptEntry.clutter_text.set_password_char(passwordChar);
|
|
|
|
this._promptEntry.menu.isPassword = passwordChar != '';
|
|
|
|
|
|
|
|
this._currentQuery = serviceName;
|
|
|
|
this._updateOkButton(true);
|
|
|
|
},
|
|
|
|
|
2012-08-19 20:15:18 -04:00
|
|
|
_showLoginHint: function(verifier, message) {
|
|
|
|
this._promptLoginHint.set_text(message)
|
|
|
|
GdmUtil.fadeInActor(this._promptLoginHint);
|
2012-05-20 12:30:14 -04:00
|
|
|
},
|
|
|
|
|
2012-08-19 20:15:18 -04:00
|
|
|
_hideLoginHint: function() {
|
|
|
|
GdmUtil.fadeOutActor(this._promptLoginHint);
|
2012-05-20 12:30:14 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
_doUnlock: function() {
|
2012-08-13 06:49:04 -04:00
|
|
|
if (this._firstQuestion) {
|
|
|
|
// we haven't received a query yet, so stash the answer
|
|
|
|
// and make ourself non-reactive
|
|
|
|
// the actual reply to GDM will be sent as soon as asked
|
|
|
|
this._firstQuestionAnswer = this._promptEntry.text;
|
|
|
|
this._updateOkButton(false);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-05-20 12:30:14 -04:00
|
|
|
if (!this._currentQuery)
|
|
|
|
return;
|
|
|
|
|
|
|
|
let query = this._currentQuery;
|
|
|
|
this._currentQuery = null;
|
|
|
|
|
|
|
|
this._updateOkButton(false);
|
|
|
|
|
|
|
|
this._userVerifier.answerQuery(query, this._promptEntry.text);
|
|
|
|
},
|
|
|
|
|
|
|
|
_onVerificationComplete: function() {
|
|
|
|
this._userVerifier.clear();
|
|
|
|
this.emit('unlocked');
|
|
|
|
},
|
|
|
|
|
2012-08-07 10:49:22 -04:00
|
|
|
_onReset: function() {
|
2012-05-20 12:30:14 -04:00
|
|
|
this.emit('failed');
|
|
|
|
},
|
|
|
|
|
2012-08-03 13:26:30 -04:00
|
|
|
_escape: function() {
|
2012-08-07 10:49:22 -04:00
|
|
|
this._userVerifier.cancel();
|
|
|
|
this.emit('failed');
|
2012-08-03 13:26:30 -04:00
|
|
|
},
|
|
|
|
|
2012-05-20 12:30:14 -04:00
|
|
|
_otherUserClicked: function(button, event) {
|
2012-08-14 11:49:46 -04:00
|
|
|
Gdm.goto_login_session_sync(null);
|
2012-05-20 12:30:14 -04:00
|
|
|
|
|
|
|
this._userVerifier.cancel();
|
|
|
|
this.emit('failed');
|
|
|
|
},
|
|
|
|
|
|
|
|
destroy: function() {
|
|
|
|
this._userVerifier.clear();
|
2012-08-16 15:24:53 -04:00
|
|
|
|
|
|
|
if (this._idleWatchId) {
|
|
|
|
this._idleMonitor.remove_watch(this._idleWatchId);
|
|
|
|
this._idleWatchId = 0;
|
|
|
|
}
|
|
|
|
|
2012-05-20 12:30:14 -04:00
|
|
|
this.parent();
|
|
|
|
},
|
|
|
|
|
|
|
|
cancel: function() {
|
|
|
|
this._userVerifier.cancel(null);
|
|
|
|
|
|
|
|
this.destroy();
|
|
|
|
},
|
|
|
|
});
|