2012-05-20 16:30:14 +00:00
|
|
|
// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
|
|
|
|
|
|
|
|
const AccountsService = imports.gi.AccountsService;
|
|
|
|
const Clutter = imports.gi.Clutter;
|
2012-07-08 15:42:15 +00:00
|
|
|
const Gdm = imports.gi.Gdm;
|
2012-05-20 16:30:14 +00:00
|
|
|
const Gio = imports.gi.Gio;
|
|
|
|
const GLib = imports.gi.GLib;
|
2012-08-20 04:06:50 +00:00
|
|
|
const GnomeDesktop = imports.gi.GnomeDesktop;
|
2012-05-20 16:30:14 +00:00
|
|
|
const Lang = imports.lang;
|
|
|
|
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;
|
2013-02-18 01:54:46 +00:00
|
|
|
const UserWidget = imports.ui.userWidget;
|
2012-05-20 16:30:14 +00:00
|
|
|
|
2013-06-14 13:03:05 +00:00
|
|
|
const Batch = imports.misc.batch;
|
2012-05-20 16:30:14 +00:00
|
|
|
const GdmUtil = imports.gdm.util;
|
|
|
|
|
2012-08-16 19:24:53 +00:00
|
|
|
// The timeout before going back automatically to the lock screen (in seconds)
|
|
|
|
const IDLE_TIMEOUT = 2 * 60;
|
|
|
|
|
2012-05-20 16:30:14 +00:00
|
|
|
const UnlockDialog = new Lang.Class({
|
|
|
|
Name: 'UnlockDialog',
|
|
|
|
Extends: ModalDialog.ModalDialog,
|
|
|
|
|
2012-05-24 20:47:48 +00:00
|
|
|
_init: function(parentActor) {
|
2012-05-20 16:30:14 +00:00
|
|
|
this.parent({ shellReactive: true,
|
2012-05-24 20:47:48 +00:00
|
|
|
styleClass: 'login-dialog',
|
2012-12-12 13:14:13 +00:00
|
|
|
keybindingMode: Shell.KeyBindingMode.UNLOCK_SCREEN,
|
2012-05-24 20:47:48 +00:00
|
|
|
parentActor: parentActor
|
|
|
|
});
|
2012-05-20 16:30:14 +00:00
|
|
|
|
|
|
|
this._userManager = AccountsService.UserManager.get_default();
|
|
|
|
this._userName = GLib.get_user_name();
|
|
|
|
this._user = this._userManager.get_user(this._userName);
|
|
|
|
|
2012-08-07 14:49:22 +00:00
|
|
|
this._failCounter = 0;
|
2012-08-13 10:49:04 +00:00
|
|
|
this._firstQuestion = true;
|
2012-08-07 14:49:22 +00:00
|
|
|
|
2012-05-20 16:30:14 +00:00
|
|
|
this._greeterClient = new Gdm.Client();
|
2012-08-03 15:10:45 +00:00
|
|
|
this._userVerifier = new GdmUtil.ShellUserVerifier(this._greeterClient, { reauthenticationOnly: true });
|
2013-03-18 05:14:44 +00:00
|
|
|
this._userVerified = false;
|
2012-05-20 16:30:14 +00:00
|
|
|
|
|
|
|
this._userVerifier.connect('ask-question', Lang.bind(this, this._onAskQuestion));
|
2012-08-07 14:49:22 +00:00
|
|
|
this._userVerifier.connect('show-message', Lang.bind(this, this._showMessage));
|
2012-05-20 16:30:14 +00:00
|
|
|
this._userVerifier.connect('verification-complete', Lang.bind(this, this._onVerificationComplete));
|
2012-10-03 21:15:41 +00:00
|
|
|
this._userVerifier.connect('verification-failed', Lang.bind(this, this._onVerificationFailed));
|
2012-08-07 14:49:22 +00:00
|
|
|
this._userVerifier.connect('reset', Lang.bind(this, this._onReset));
|
2012-05-20 16:30:14 +00:00
|
|
|
|
2012-08-20 00:15:18 +00: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 16:30:14 +00:00
|
|
|
|
2013-02-18 01:54:46 +00:00
|
|
|
this._userWidget = new UserWidget.UserWidget(this._user);
|
2012-05-20 16:30:14 +00:00
|
|
|
this.contentLayout.add_actor(this._userWidget.actor);
|
|
|
|
|
|
|
|
this._promptLayout = new St.BoxLayout({ style_class: 'login-dialog-prompt-layout',
|
2012-08-07 15:57:38 +00:00
|
|
|
vertical: true });
|
2012-05-20 16:30:14 +00:00
|
|
|
|
|
|
|
this._promptLabel = new St.Label({ style_class: 'login-dialog-prompt-label' });
|
|
|
|
this._promptLayout.add(this._promptLabel,
|
2012-06-03 17:31:34 +00:00
|
|
|
{ x_align: St.Align.START });
|
2012-05-20 16:30:14 +00:00
|
|
|
|
|
|
|
this._promptEntry = new St.Entry({ style_class: 'login-dialog-prompt-entry',
|
|
|
|
can_focus: true });
|
2013-03-05 07:04:02 +00:00
|
|
|
this._promptEntry.clutter_text.connect('activate', Lang.bind(this, this._doUnlock));
|
2012-08-13 10:49:04 +00:00
|
|
|
this._promptEntry.clutter_text.set_password_char('\u25cf');
|
|
|
|
ShellEntry.addContextMenu(this._promptEntry, { isPassword: true });
|
2012-05-20 16:30:14 +00:00
|
|
|
this.setInitialKeyFocus(this._promptEntry);
|
2012-11-01 15:19:17 +00:00
|
|
|
this._promptEntry.clutter_text.connect('text-changed', Lang.bind(this, function() {
|
|
|
|
this._updateOkButtonSensitivity(this._promptEntry.text.length > 0);
|
|
|
|
}));
|
2012-05-20 16:30:14 +00:00
|
|
|
|
|
|
|
this._promptLayout.add(this._promptEntry,
|
|
|
|
{ expand: true,
|
2012-06-03 17:31:34 +00:00
|
|
|
x_fill: true });
|
2012-05-20 16:30:14 +00:00
|
|
|
|
|
|
|
this.contentLayout.add_actor(this._promptLayout);
|
|
|
|
|
2012-08-07 14:49:22 +00:00
|
|
|
this._promptMessage = new St.Label({ visible: false });
|
|
|
|
this.contentLayout.add(this._promptMessage, { x_fill: true });
|
|
|
|
|
2012-08-20 00:15:18 +00: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 16:30:14 +00:00
|
|
|
|
2012-10-24 15:53:19 +00:00
|
|
|
this.allowCancel = false;
|
2012-11-18 21:49:54 +00:00
|
|
|
this.buttonLayout.visible = true;
|
|
|
|
this.addButton({ label: _("Cancel"),
|
|
|
|
action: Lang.bind(this, this._escape),
|
|
|
|
key: Clutter.KEY_Escape },
|
|
|
|
{ expand: true,
|
|
|
|
x_fill: false,
|
|
|
|
y_fill: false,
|
|
|
|
x_align: St.Align.START,
|
|
|
|
y_align: St.Align.MIDDLE });
|
2013-05-09 04:41:07 +00:00
|
|
|
this.placeSpinner({ expand: false,
|
|
|
|
x_fill: false,
|
|
|
|
y_fill: false,
|
|
|
|
x_align: St.Align.END,
|
|
|
|
y_align: St.Align.MIDDLE });
|
2012-11-18 21:49:54 +00:00
|
|
|
this._okButton = this.addButton({ label: _("Unlock"),
|
|
|
|
action: Lang.bind(this, this._doUnlock),
|
|
|
|
default: true },
|
|
|
|
{ expand: false,
|
|
|
|
x_fill: false,
|
|
|
|
y_fill: false,
|
|
|
|
x_align: St.Align.END,
|
|
|
|
y_align: St.Align.MIDDLE });
|
2012-08-07 15:38:12 +00:00
|
|
|
|
2013-01-03 00:02:13 +00:00
|
|
|
let screenSaverSettings = new Gio.Settings({ schema: 'org.gnome.desktop.screensaver' });
|
|
|
|
if (screenSaverSettings.get_boolean('user-switch-enabled')) {
|
|
|
|
let otherUserLabel = new St.Label({ text: _("Log in as another user"),
|
|
|
|
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));
|
|
|
|
this.dialogLayout.add(this._otherUserButton,
|
|
|
|
{ x_align: St.Align.START,
|
|
|
|
x_fill: false });
|
|
|
|
} else {
|
|
|
|
this._otherUserButton = null;
|
|
|
|
}
|
2012-05-26 15:04:25 +00:00
|
|
|
|
2012-11-18 21:36:17 +00:00
|
|
|
this._updateSensitivity(true);
|
|
|
|
|
2012-08-07 14:49:22 +00:00
|
|
|
let batch = new Batch.Hold();
|
|
|
|
this._userVerifier.begin(this._userName, batch);
|
|
|
|
|
2012-08-11 03:53:59 +00:00
|
|
|
Main.ctrlAltTabManager.addGroup(this.dialogLayout, _("Unlock Window"), 'dialog-password-symbolic');
|
|
|
|
|
2012-08-20 04:06:50 +00:00
|
|
|
this._idleMonitor = new GnomeDesktop.IdleMonitor();
|
2013-02-15 17:19:49 +00:00
|
|
|
this._idleWatchId = this._idleMonitor.add_idle_watch(IDLE_TIMEOUT * 1000, Lang.bind(this, this._escape));
|
2012-05-20 16:30:14 +00:00
|
|
|
},
|
|
|
|
|
2012-10-03 20:43:38 +00:00
|
|
|
_updateSensitivity: function(sensitive) {
|
|
|
|
this._promptEntry.reactive = sensitive;
|
|
|
|
this._promptEntry.clutter_text.editable = sensitive;
|
2012-11-01 15:19:17 +00:00
|
|
|
this._updateOkButtonSensitivity(sensitive && this._promptEntry.text.length > 0);
|
2013-01-03 00:02:13 +00:00
|
|
|
if (this._otherUserButton) {
|
|
|
|
this._otherUserButton.reactive = sensitive;
|
|
|
|
this._otherUserButton.can_focus = sensitive;
|
|
|
|
}
|
2012-11-01 15:19:17 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
_updateOkButtonSensitivity: function(sensitive) {
|
2012-11-18 21:49:54 +00:00
|
|
|
this._okButton.reactive = sensitive;
|
|
|
|
this._okButton.can_focus = sensitive;
|
|
|
|
},
|
|
|
|
|
2012-08-07 14:49:22 +00:00
|
|
|
_showMessage: function(userVerifier, message, styleClass) {
|
2012-10-29 16:39:00 +00:00
|
|
|
if (message) {
|
|
|
|
this._promptMessage.text = message;
|
|
|
|
this._promptMessage.styleClass = styleClass;
|
|
|
|
GdmUtil.fadeInActor(this._promptMessage);
|
|
|
|
} else {
|
|
|
|
GdmUtil.fadeOutActor(this._promptMessage);
|
|
|
|
}
|
2012-05-20 16:30:14 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
_onAskQuestion: function(verifier, serviceName, question, passwordChar) {
|
2012-08-13 10:49:04 +00:00
|
|
|
if (this._firstQuestion && this._firstQuestionAnswer) {
|
|
|
|
this._userVerifier.answerQuery(serviceName, this._firstQuestionAnswer);
|
|
|
|
this._firstQuestionAnswer = null;
|
|
|
|
this._firstQuestion = false;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-05-20 16:30:14 +00:00
|
|
|
this._promptLabel.text = question;
|
|
|
|
|
2012-08-13 10:49:04 +00:00
|
|
|
if (!this._firstQuestion)
|
|
|
|
this._promptEntry.text = '';
|
|
|
|
else
|
|
|
|
this._firstQuestion = false;
|
|
|
|
|
2012-05-20 16:30:14 +00:00
|
|
|
this._promptEntry.clutter_text.set_password_char(passwordChar);
|
|
|
|
this._promptEntry.menu.isPassword = passwordChar != '';
|
|
|
|
|
|
|
|
this._currentQuery = serviceName;
|
2012-10-03 20:43:38 +00:00
|
|
|
this._updateSensitivity(true);
|
2013-05-09 04:41:07 +00:00
|
|
|
this.setWorking(false);
|
2012-05-20 16:30:14 +00:00
|
|
|
},
|
|
|
|
|
2012-08-20 00:15:18 +00:00
|
|
|
_showLoginHint: function(verifier, message) {
|
|
|
|
this._promptLoginHint.set_text(message)
|
|
|
|
GdmUtil.fadeInActor(this._promptLoginHint);
|
2012-05-20 16:30:14 +00:00
|
|
|
},
|
|
|
|
|
2012-08-20 00:15:18 +00:00
|
|
|
_hideLoginHint: function() {
|
|
|
|
GdmUtil.fadeOutActor(this._promptLoginHint);
|
2012-05-20 16:30:14 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
_doUnlock: function() {
|
2012-08-13 10:49:04 +00: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;
|
2012-10-03 20:43:38 +00:00
|
|
|
this._updateSensitivity(false);
|
2013-05-09 04:41:07 +00:00
|
|
|
this.setWorking(true);
|
2012-08-13 10:49:04 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-05-20 16:30:14 +00:00
|
|
|
if (!this._currentQuery)
|
|
|
|
return;
|
|
|
|
|
|
|
|
let query = this._currentQuery;
|
|
|
|
this._currentQuery = null;
|
|
|
|
|
2012-10-03 20:43:38 +00:00
|
|
|
this._updateSensitivity(false);
|
2013-05-09 04:41:07 +00:00
|
|
|
this.setWorking(true);
|
2012-05-20 16:30:14 +00:00
|
|
|
|
|
|
|
this._userVerifier.answerQuery(query, this._promptEntry.text);
|
|
|
|
},
|
|
|
|
|
2013-03-18 04:59:56 +00:00
|
|
|
_finishUnlock: function() {
|
2012-05-20 16:30:14 +00:00
|
|
|
this._userVerifier.clear();
|
|
|
|
this.emit('unlocked');
|
|
|
|
},
|
|
|
|
|
2013-03-18 04:59:56 +00:00
|
|
|
_onVerificationComplete: function() {
|
|
|
|
this._userVerified = true;
|
|
|
|
if (!this._userVerifier.hasPendingMessages) {
|
|
|
|
this._finishUnlock();
|
|
|
|
} else {
|
|
|
|
let signalId = this._userVerifier.connect('no-more-messages',
|
|
|
|
Lang.bind(this, function() {
|
|
|
|
this._userVerifier.disconnect(signalId);
|
|
|
|
this._finishUnlock();
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2012-08-07 14:49:22 +00:00
|
|
|
_onReset: function() {
|
2013-03-18 05:14:44 +00:00
|
|
|
if (!this._userVerified) {
|
|
|
|
this._userVerifier.clear();
|
|
|
|
this.emit('failed');
|
|
|
|
}
|
2012-05-20 16:30:14 +00:00
|
|
|
},
|
|
|
|
|
2012-10-03 21:15:41 +00:00
|
|
|
_onVerificationFailed: function() {
|
|
|
|
this._currentQuery = null;
|
|
|
|
this._firstQuestion = true;
|
2013-03-18 05:14:44 +00:00
|
|
|
this._userVerified = false;
|
2012-10-03 21:15:41 +00:00
|
|
|
|
2012-10-29 16:43:28 +00:00
|
|
|
this._promptEntry.text = '';
|
2012-11-20 23:08:23 +00:00
|
|
|
this._promptEntry.clutter_text.set_password_char('\u25cf');
|
|
|
|
this._promptEntry.menu.isPassword = true;
|
2012-10-03 21:15:41 +00:00
|
|
|
|
|
|
|
this._updateSensitivity(false);
|
2013-05-09 04:41:07 +00:00
|
|
|
this.setWorking(false);
|
2012-10-03 21:15:41 +00:00
|
|
|
},
|
|
|
|
|
2012-08-03 17:26:30 +00:00
|
|
|
_escape: function() {
|
2012-10-24 15:53:19 +00:00
|
|
|
if (this.allowCancel) {
|
|
|
|
this._userVerifier.cancel();
|
|
|
|
this.emit('failed');
|
|
|
|
}
|
2012-08-03 17:26:30 +00:00
|
|
|
},
|
|
|
|
|
2012-05-20 16:30:14 +00:00
|
|
|
_otherUserClicked: function(button, event) {
|
2012-08-14 15:49:46 +00:00
|
|
|
Gdm.goto_login_session_sync(null);
|
2012-05-20 16:30:14 +00:00
|
|
|
|
|
|
|
this._userVerifier.cancel();
|
|
|
|
this.emit('failed');
|
|
|
|
},
|
|
|
|
|
|
|
|
destroy: function() {
|
|
|
|
this._userVerifier.clear();
|
2012-08-16 19:24:53 +00:00
|
|
|
|
|
|
|
if (this._idleWatchId) {
|
|
|
|
this._idleMonitor.remove_watch(this._idleWatchId);
|
|
|
|
this._idleWatchId = 0;
|
|
|
|
}
|
|
|
|
|
2012-05-20 16:30:14 +00:00
|
|
|
this.parent();
|
|
|
|
},
|
|
|
|
|
|
|
|
cancel: function() {
|
|
|
|
this._userVerifier.cancel(null);
|
|
|
|
|
|
|
|
this.destroy();
|
|
|
|
},
|
2013-03-05 05:55:54 +00:00
|
|
|
|
|
|
|
addCharacter: function(unichar) {
|
|
|
|
this._promptEntry.clutter_text.insert_unichar(unichar);
|
|
|
|
},
|
2012-05-20 16:30:14 +00:00
|
|
|
});
|