2012-05-20 12:30:14 -04:00
|
|
|
// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
|
2019-01-31 09:07:06 -05:00
|
|
|
/* exported UnlockDialog */
|
2012-05-20 12:30:14 -04:00
|
|
|
|
2019-11-28 16:16:53 -05:00
|
|
|
const { AccountsService, Atk, Clutter, Gdm, Gio,
|
|
|
|
GnomeDesktop, GLib, GObject, Meta, Shell, St } = imports.gi;
|
2012-05-20 12:30:14 -04:00
|
|
|
|
2013-07-16 07:31:22 -04:00
|
|
|
const Layout = imports.ui.layout;
|
2012-05-20 12:30:14 -04:00
|
|
|
const Main = imports.ui.main;
|
|
|
|
|
2013-07-23 20:37:42 -04:00
|
|
|
const AuthPrompt = imports.gdm.authPrompt;
|
2012-05-20 12:30:14 -04:00
|
|
|
|
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;
|
|
|
|
|
2019-11-28 16:16:53 -05:00
|
|
|
var Clock = GObject.registerClass(
|
|
|
|
class UnlockDialogClock extends St.BoxLayout {
|
|
|
|
_init() {
|
|
|
|
super._init({ style_class: 'unlock-dialog-clock', vertical: true });
|
|
|
|
|
|
|
|
this._time = new St.Label({
|
|
|
|
style_class: 'unlock-dialog-clock-time',
|
|
|
|
x_align: Clutter.ActorAlign.CENTER,
|
|
|
|
});
|
|
|
|
this._date = new St.Label({
|
|
|
|
style_class: 'unlock-dialog-clock-date',
|
|
|
|
x_align: Clutter.ActorAlign.CENTER,
|
|
|
|
});
|
|
|
|
|
|
|
|
this.add_child(this._time);
|
|
|
|
this.add_child(this._date);
|
|
|
|
|
|
|
|
this._wallClock = new GnomeDesktop.WallClock({ time_only: true });
|
|
|
|
this._wallClock.connect('notify::clock', this._updateClock.bind(this));
|
|
|
|
|
|
|
|
this._updateClock();
|
|
|
|
|
|
|
|
this.connect('destroy', this._onDestroy.bind(this));
|
|
|
|
}
|
|
|
|
|
|
|
|
_updateClock() {
|
|
|
|
this._time.text = this._wallClock.clock;
|
|
|
|
|
|
|
|
let date = new Date();
|
|
|
|
/* Translators: This is a time format for a date in
|
|
|
|
long format */
|
2020-02-10 17:11:26 -05:00
|
|
|
let dateFormat = Shell.util_translate_time_string(N_('%A %B %-d'));
|
2019-11-28 16:16:53 -05:00
|
|
|
this._date.text = date.toLocaleFormat(dateFormat);
|
|
|
|
}
|
|
|
|
|
|
|
|
_onDestroy() {
|
|
|
|
this._wallClock.run_dispose();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2019-09-20 07:17:40 -04:00
|
|
|
var UnlockDialog = GObject.registerClass({
|
2019-11-28 16:22:55 -05:00
|
|
|
Signals: {
|
|
|
|
'failed': {},
|
|
|
|
'wake-up-screen': {},
|
|
|
|
},
|
2019-09-20 07:17:40 -04:00
|
|
|
}, class UnlockDialog extends St.Widget {
|
|
|
|
_init(parentActor) {
|
|
|
|
super._init({
|
|
|
|
accessible_role: Atk.Role.WINDOW,
|
|
|
|
style_class: 'login-dialog',
|
|
|
|
layout_manager: new Clutter.BoxLayout(),
|
|
|
|
visible: false,
|
|
|
|
});
|
2013-07-16 07:31:22 -04:00
|
|
|
|
2019-09-20 07:17:40 -04:00
|
|
|
this.add_constraint(new Layout.MonitorConstraint({ primary: true }));
|
|
|
|
parentActor.add_child(this);
|
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);
|
|
|
|
|
2013-08-26 15:43:27 -04:00
|
|
|
this._promptBox = new St.BoxLayout({ vertical: true,
|
|
|
|
x_align: Clutter.ActorAlign.CENTER,
|
|
|
|
y_align: Clutter.ActorAlign.CENTER,
|
|
|
|
x_expand: true,
|
|
|
|
y_expand: true });
|
2019-09-20 07:17:40 -04:00
|
|
|
this.add_child(this._promptBox);
|
2012-05-20 12:30:14 -04:00
|
|
|
|
2019-11-28 16:16:53 -05:00
|
|
|
this._clock = new Clock();
|
|
|
|
this._promptBox.add_child(this._clock);
|
|
|
|
|
2013-07-22 11:07:35 -04:00
|
|
|
this._authPrompt = new AuthPrompt.AuthPrompt(new Gdm.Client(), AuthPrompt.AuthPromptMode.UNLOCK_ONLY);
|
2017-12-01 19:27:35 -05: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 07:31:22 -04:00
|
|
|
this._authPrompt.nextButton.label = _("Unlock");
|
2012-08-07 10:49:22 -04:00
|
|
|
|
2019-07-16 05:24:13 -04:00
|
|
|
this._promptBox.add_child(this._authPrompt);
|
2012-05-20 12:30:14 -04:00
|
|
|
|
2012-10-24 11:53:19 -04:00
|
|
|
this.allowCancel = false;
|
2012-08-07 11:38:12 -04:00
|
|
|
|
2014-06-24 15:17:09 -04:00
|
|
|
let screenSaverSettings = new Gio.Settings({ schema_id: 'org.gnome.desktop.screensaver' });
|
2013-01-02 19:02:13 -05: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,
|
2019-10-17 17:40:24 -04:00
|
|
|
reactive: true });
|
2017-12-01 19:27:35 -05:00
|
|
|
this._otherUserButton.connect('clicked', this._otherUserClicked.bind(this));
|
2013-07-16 07:31:22 -04:00
|
|
|
this._promptBox.add_child(this._otherUserButton);
|
2013-01-02 19:02:13 -05:00
|
|
|
} else {
|
|
|
|
this._otherUserButton = null;
|
|
|
|
}
|
2012-05-26 11:04:25 -04:00
|
|
|
|
2013-07-28 17:49:50 -04:00
|
|
|
this._authPrompt.reset();
|
2012-11-18 16:36:17 -05:00
|
|
|
this._updateSensitivity(true);
|
|
|
|
|
2019-09-20 07:17:40 -04:00
|
|
|
Main.ctrlAltTabManager.addGroup(this, _("Unlock Window"), 'dialog-password-symbolic');
|
2012-08-10 23:53:59 -04:00
|
|
|
|
2013-08-14 09:47:27 -04:00
|
|
|
this._idleMonitor = Meta.IdleMonitor.get_core();
|
2017-12-01 19:27:35 -05:00
|
|
|
this._idleWatchId = this._idleMonitor.add_idle_watch(IDLE_TIMEOUT * 1000, this._escape.bind(this));
|
2019-09-20 07:17:40 -04:00
|
|
|
|
|
|
|
this.connect('destroy', this._onDestroy.bind(this));
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2012-05-20 12:30:14 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_updateSensitivity(sensitive) {
|
2013-07-16 07:31:22 -04:00
|
|
|
this._authPrompt.updateSensitivity(sensitive);
|
|
|
|
|
2013-01-02 19:02:13 -05:00
|
|
|
if (this._otherUserButton) {
|
|
|
|
this._otherUserButton.reactive = sensitive;
|
|
|
|
this._otherUserButton.can_focus = sensitive;
|
|
|
|
}
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2012-11-01 11:19:17 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_fail() {
|
2013-07-22 11:07:35 -04:00
|
|
|
this.emit('failed');
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2012-10-03 17:15:41 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_onReset(authPrompt, beginRequest) {
|
2013-07-28 17:49:50 -04:00
|
|
|
let userName;
|
|
|
|
if (beginRequest == AuthPrompt.BeginRequestType.PROVIDE_USERNAME) {
|
|
|
|
this._authPrompt.setUser(this._user);
|
|
|
|
userName = this._userName;
|
|
|
|
} else {
|
|
|
|
userName = null;
|
|
|
|
}
|
|
|
|
|
2019-08-19 15:06:04 -04:00
|
|
|
this._authPrompt.begin({ userName });
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2013-07-28 17:49:50 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_escape() {
|
2013-07-28 16:06:04 -04:00
|
|
|
if (this.allowCancel)
|
2013-07-22 11:07:35 -04:00
|
|
|
this._authPrompt.cancel();
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2012-08-03 13:26:30 -04:00
|
|
|
|
2019-02-04 06:30:53 -05:00
|
|
|
_otherUserClicked() {
|
2012-08-14 11:49:46 -04:00
|
|
|
Gdm.goto_login_session_sync(null);
|
2012-05-20 12:30:14 -04:00
|
|
|
|
2013-07-22 11:07:35 -04:00
|
|
|
this._authPrompt.cancel();
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2012-05-20 12:30:14 -04:00
|
|
|
|
2019-09-20 07:17:40 -04:00
|
|
|
_onDestroy() {
|
2013-07-22 11:07:35 -04:00
|
|
|
this.popModal();
|
2012-08-16 15:24:53 -04:00
|
|
|
|
|
|
|
if (this._idleWatchId) {
|
|
|
|
this._idleMonitor.remove_watch(this._idleWatchId);
|
|
|
|
this._idleWatchId = 0;
|
|
|
|
}
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2012-05-20 12:30:14 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
cancel() {
|
2013-07-22 11:07:35 -04:00
|
|
|
this._authPrompt.cancel();
|
2012-05-20 12:30:14 -04:00
|
|
|
|
|
|
|
this.destroy();
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2013-03-05 00:55:54 -05:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
addCharacter(unichar) {
|
2013-07-16 07:31:22 -04:00
|
|
|
this._authPrompt.addCharacter(unichar);
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2013-07-18 08:58:58 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
finish(onComplete) {
|
2013-07-22 11:07:35 -04:00
|
|
|
this._authPrompt.finish(onComplete);
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2013-07-16 07:31:22 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
open(timestamp) {
|
2019-09-20 07:17:40 -04:00
|
|
|
this.show();
|
2013-07-16 07:31:22 -04:00
|
|
|
|
|
|
|
if (this._isModal)
|
|
|
|
return true;
|
2013-07-18 08:58:58 -04:00
|
|
|
|
2019-09-20 07:17:40 -04:00
|
|
|
let modalParams = {
|
|
|
|
timestamp,
|
|
|
|
actionMode: Shell.ActionMode.UNLOCK_SCREEN,
|
|
|
|
};
|
|
|
|
if (!Main.pushModal(this, modalParams))
|
2013-07-16 07:31:22 -04:00
|
|
|
return false;
|
|
|
|
|
|
|
|
this._isModal = true;
|
|
|
|
|
|
|
|
return true;
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2013-07-16 07:31:22 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
popModal(timestamp) {
|
2013-07-16 07:31:22 -04:00
|
|
|
if (this._isModal) {
|
2019-09-20 07:17:40 -04:00
|
|
|
Main.popModal(this, timestamp);
|
2013-07-16 07:31:22 -04:00
|
|
|
this._isModal = false;
|
|
|
|
}
|
2013-07-18 08:58:58 -04:00
|
|
|
}
|
2019-09-20 07:17:40 -04:00
|
|
|
});
|