2012-05-20 16:30:14 +00:00
|
|
|
// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
|
|
|
|
|
|
|
|
const AccountsService = imports.gi.AccountsService;
|
2013-07-16 11:31:22 +00:00
|
|
|
const Atk = imports.gi.Atk;
|
2012-05-20 16:30:14 +00:00
|
|
|
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 Gtk = imports.gi.Gtk;
|
2013-08-14 13:47:27 +00:00
|
|
|
const Meta = imports.gi.Meta;
|
2012-05-20 16:30:14 +00:00
|
|
|
const Signals = imports.signals;
|
|
|
|
const Shell = imports.gi.Shell;
|
|
|
|
const St = imports.gi.St;
|
|
|
|
|
2013-07-16 11:31:22 +00:00
|
|
|
const Layout = imports.ui.layout;
|
2012-05-20 16:30:14 +00:00
|
|
|
const Main = imports.ui.main;
|
2012-11-18 21:49:54 +00:00
|
|
|
const Panel = imports.ui.panel;
|
2012-05-20 16:30:14 +00:00
|
|
|
const Tweener = imports.ui.tweener;
|
2013-02-18 01:54:46 +00:00
|
|
|
const UserWidget = imports.ui.userWidget;
|
2012-05-20 16:30:14 +00:00
|
|
|
|
2013-07-24 00:37:42 +00:00
|
|
|
const AuthPrompt = imports.gdm.authPrompt;
|
2012-05-20 16:30:14 +00:00
|
|
|
const Batch = imports.gdm.batch;
|
|
|
|
const GdmUtil = imports.gdm.util;
|
2012-11-18 21:49:54 +00:00
|
|
|
const LoginDialog = imports.gdm.loginDialog;
|
2012-05-20 16:30:14 +00:00
|
|
|
|
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;
|
|
|
|
|
2017-10-31 01:19:44 +00:00
|
|
|
var UnlockDialog = class {
|
|
|
|
constructor(parentActor) {
|
2013-07-16 11:31:22 +00:00
|
|
|
this.actor = new St.Widget({ accessible_role: Atk.Role.WINDOW,
|
|
|
|
style_class: 'login-dialog',
|
2013-08-26 19:43:27 +00:00
|
|
|
layout_manager: new Clutter.BoxLayout(),
|
2013-07-16 11:31:22 +00:00
|
|
|
visible: false });
|
|
|
|
|
|
|
|
this.actor.add_constraint(new Layout.MonitorConstraint({ primary: true }));
|
|
|
|
parentActor.add_child(this.actor);
|
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);
|
|
|
|
|
2013-08-26 19:43:27 +00:00
|
|
|
this._promptBox = new St.BoxLayout({ vertical: true,
|
|
|
|
x_align: Clutter.ActorAlign.CENTER,
|
|
|
|
y_align: Clutter.ActorAlign.CENTER,
|
|
|
|
x_expand: true,
|
|
|
|
y_expand: true });
|
2013-07-16 11:31:22 +00:00
|
|
|
this.actor.add_child(this._promptBox);
|
2012-05-20 16:30:14 +00:00
|
|
|
|
2013-07-22 15:07:35 +00:00
|
|
|
this._authPrompt = new AuthPrompt.AuthPrompt(new Gdm.Client(), AuthPrompt.AuthPromptMode.UNLOCK_ONLY);
|
2017-12-02 00:27:35 +00:00
|
|
|
this._authPrompt.connect('failed', this._fail.bind(this));
|
|
|
|
this._authPrompt.connect('cancelled', this._fail.bind(this));
|
|
|
|
this._authPrompt.connect('reset', this._onReset.bind(this));
|
2013-07-16 11:31:22 +00:00
|
|
|
this._authPrompt.setPasswordChar('\u25cf');
|
|
|
|
this._authPrompt.nextButton.label = _("Unlock");
|
2012-08-07 14:49:22 +00:00
|
|
|
|
2013-07-16 11:31:22 +00:00
|
|
|
this._promptBox.add_child(this._authPrompt.actor);
|
2012-05-20 16:30:14 +00:00
|
|
|
|
2012-10-24 15:53:19 +00:00
|
|
|
this.allowCancel = false;
|
2012-08-07 15:38:12 +00:00
|
|
|
|
2014-06-24 19:17:09 +00:00
|
|
|
let screenSaverSettings = new Gio.Settings({ schema_id: 'org.gnome.desktop.screensaver' });
|
2013-01-03 00:02:13 +00:00
|
|
|
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,
|
2013-12-11 20:36:49 +00:00
|
|
|
x_fill: false });
|
2017-12-02 00:27:35 +00:00
|
|
|
this._otherUserButton.connect('clicked', this._otherUserClicked.bind(this));
|
2013-07-16 11:31:22 +00:00
|
|
|
this._promptBox.add_child(this._otherUserButton);
|
2013-01-03 00:02:13 +00:00
|
|
|
} else {
|
|
|
|
this._otherUserButton = null;
|
|
|
|
}
|
2012-05-26 15:04:25 +00:00
|
|
|
|
2013-07-28 21:49:50 +00:00
|
|
|
this._authPrompt.reset();
|
2012-11-18 21:36:17 +00:00
|
|
|
this._updateSensitivity(true);
|
|
|
|
|
2013-07-16 11:31:22 +00:00
|
|
|
Main.ctrlAltTabManager.addGroup(this.actor, _("Unlock Window"), 'dialog-password-symbolic');
|
2012-08-11 03:53:59 +00:00
|
|
|
|
2013-08-14 13:47:27 +00:00
|
|
|
this._idleMonitor = Meta.IdleMonitor.get_core();
|
2017-12-02 00:27:35 +00:00
|
|
|
this._idleWatchId = this._idleMonitor.add_idle_watch(IDLE_TIMEOUT * 1000, this._escape.bind(this));
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2012-05-20 16:30:14 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_updateSensitivity(sensitive) {
|
2013-07-16 11:31:22 +00:00
|
|
|
this._authPrompt.updateSensitivity(sensitive);
|
|
|
|
|
2013-01-03 00:02:13 +00:00
|
|
|
if (this._otherUserButton) {
|
|
|
|
this._otherUserButton.reactive = sensitive;
|
|
|
|
this._otherUserButton.can_focus = sensitive;
|
|
|
|
}
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2012-11-01 15:19:17 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_fail() {
|
2013-07-22 15:07:35 +00:00
|
|
|
this.emit('failed');
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2012-10-03 21:15:41 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_onReset(authPrompt, beginRequest) {
|
2013-07-28 21:49:50 +00:00
|
|
|
let userName;
|
|
|
|
if (beginRequest == AuthPrompt.BeginRequestType.PROVIDE_USERNAME) {
|
|
|
|
this._authPrompt.setUser(this._user);
|
|
|
|
userName = this._userName;
|
|
|
|
} else {
|
|
|
|
userName = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
this._authPrompt.begin({ userName: userName });
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2013-07-28 21:49:50 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_escape() {
|
2013-07-28 20:06:04 +00:00
|
|
|
if (this.allowCancel)
|
2013-07-22 15:07:35 +00:00
|
|
|
this._authPrompt.cancel();
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2012-08-03 17:26:30 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_otherUserClicked(button, event) {
|
2012-08-14 15:49:46 +00:00
|
|
|
Gdm.goto_login_session_sync(null);
|
2012-05-20 16:30:14 +00:00
|
|
|
|
2013-07-22 15:07:35 +00:00
|
|
|
this._authPrompt.cancel();
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2012-05-20 16:30:14 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
destroy() {
|
2013-07-22 15:07:35 +00:00
|
|
|
this.popModal();
|
2013-07-16 11:31:22 +00:00
|
|
|
this.actor.destroy();
|
2012-08-16 19:24:53 +00:00
|
|
|
|
|
|
|
if (this._idleWatchId) {
|
|
|
|
this._idleMonitor.remove_watch(this._idleWatchId);
|
|
|
|
this._idleWatchId = 0;
|
|
|
|
}
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2012-05-20 16:30:14 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
cancel() {
|
2013-07-22 15:07:35 +00:00
|
|
|
this._authPrompt.cancel();
|
2012-05-20 16:30:14 +00:00
|
|
|
|
|
|
|
this.destroy();
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2013-03-05 05:55:54 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
addCharacter(unichar) {
|
2013-07-16 11:31:22 +00:00
|
|
|
this._authPrompt.addCharacter(unichar);
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2013-07-18 12:58:58 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
finish(onComplete) {
|
2013-07-22 15:07:35 +00:00
|
|
|
this._authPrompt.finish(onComplete);
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2013-07-16 11:31:22 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
open(timestamp) {
|
2013-07-16 11:31:22 +00:00
|
|
|
this.actor.show();
|
|
|
|
|
|
|
|
if (this._isModal)
|
|
|
|
return true;
|
2013-07-18 12:58:58 +00:00
|
|
|
|
2013-07-16 11:31:22 +00:00
|
|
|
if (!Main.pushModal(this.actor, { timestamp: timestamp,
|
2014-12-11 14:35:40 +00:00
|
|
|
actionMode: Shell.ActionMode.UNLOCK_SCREEN }))
|
2013-07-16 11:31:22 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
this._isModal = true;
|
|
|
|
|
|
|
|
return true;
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2013-07-16 11:31:22 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
popModal(timestamp) {
|
2013-07-16 11:31:22 +00:00
|
|
|
if (this._isModal) {
|
|
|
|
Main.popModal(this.actor, timestamp);
|
|
|
|
this._isModal = false;
|
|
|
|
}
|
2013-07-18 12:58:58 +00:00
|
|
|
}
|
2017-10-31 01:19:44 +00:00
|
|
|
};
|
2013-07-16 11:31:22 +00:00
|
|
|
Signals.addSignalMethods(UnlockDialog.prototype);
|