2012-01-10 10:37:26 -05:00
|
|
|
// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
|
|
|
|
|
|
|
|
const Lang = imports.lang;
|
|
|
|
const Shell = imports.gi.Shell;
|
|
|
|
const Clutter = imports.gi.Clutter;
|
|
|
|
const St = imports.gi.St;
|
|
|
|
const Pango = imports.gi.Pango;
|
|
|
|
const Gio = imports.gi.Gio;
|
|
|
|
const GObject = imports.gi.GObject;
|
|
|
|
const Gcr = imports.gi.Gcr;
|
|
|
|
|
|
|
|
const ModalDialog = imports.ui.modalDialog;
|
|
|
|
const ShellEntry = imports.ui.shellEntry;
|
|
|
|
const CheckBox = imports.ui.checkBox;
|
|
|
|
|
|
|
|
const KeyringDialog = new Lang.Class({
|
|
|
|
Name: 'KeyringDialog',
|
|
|
|
Extends: ModalDialog.ModalDialog,
|
|
|
|
|
|
|
|
_init: function() {
|
|
|
|
this.parent({ styleClass: 'prompt-dialog' });
|
|
|
|
|
|
|
|
this.prompt = new Shell.KeyringPrompt();
|
|
|
|
this.prompt.connect('show-password', Lang.bind(this, this._onShowPassword));
|
|
|
|
this.prompt.connect('show-confirm', Lang.bind(this, this._onShowConfirm));
|
2012-09-25 15:53:36 -04:00
|
|
|
this.prompt.connect('prompt-close', Lang.bind(this, this._onHidePrompt));
|
2012-01-10 10:37:26 -05:00
|
|
|
|
|
|
|
let mainContentBox = new St.BoxLayout({ style_class: 'prompt-dialog-main-layout',
|
|
|
|
vertical: false });
|
|
|
|
this.contentLayout.add(mainContentBox);
|
|
|
|
|
|
|
|
let icon = new St.Icon({ icon_name: 'dialog-password-symbolic' });
|
|
|
|
mainContentBox.add(icon,
|
|
|
|
{ x_fill: true,
|
|
|
|
y_fill: false,
|
|
|
|
x_align: St.Align.END,
|
|
|
|
y_align: St.Align.START });
|
|
|
|
|
|
|
|
this._messageBox = new St.BoxLayout({ style_class: 'prompt-dialog-message-layout',
|
|
|
|
vertical: true });
|
|
|
|
mainContentBox.add(this._messageBox,
|
|
|
|
{ y_align: St.Align.START, expand: true, x_fill: true, y_fill: true });
|
|
|
|
|
|
|
|
let subject = new St.Label({ style_class: 'prompt-dialog-headline' });
|
|
|
|
this.prompt.bind_property('message', subject, 'text', GObject.BindingFlags.SYNC_CREATE);
|
|
|
|
|
|
|
|
this._messageBox.add(subject,
|
2013-12-11 15:40:18 -05:00
|
|
|
{ x_fill: false,
|
|
|
|
y_fill: false,
|
|
|
|
x_align: St.Align.START,
|
2012-01-10 10:37:26 -05:00
|
|
|
y_align: St.Align.START });
|
|
|
|
|
|
|
|
let description = new St.Label({ style_class: 'prompt-dialog-description' });
|
|
|
|
description.clutter_text.ellipsize = Pango.EllipsizeMode.NONE;
|
|
|
|
description.clutter_text.line_wrap = true;
|
|
|
|
this.prompt.bind_property('description', description, 'text', GObject.BindingFlags.SYNC_CREATE);
|
|
|
|
this._messageBox.add(description,
|
|
|
|
{ y_fill: true,
|
|
|
|
y_align: St.Align.START });
|
|
|
|
|
|
|
|
this._controlTable = null;
|
|
|
|
|
2012-12-21 11:04:57 -05:00
|
|
|
|
|
|
|
this._cancelButton = this.addButton({ label: '',
|
|
|
|
action: Lang.bind(this, this._onCancelButton),
|
2013-05-09 00:41:07 -04:00
|
|
|
key: Clutter.Escape },
|
|
|
|
{ expand: true, x_fill: false, x_align: St.Align.START });
|
|
|
|
this.placeSpinner({ expand: false,
|
|
|
|
x_fill: false,
|
|
|
|
y_fill: false,
|
|
|
|
x_align: St.Align.END,
|
|
|
|
y_align: St.Align.MIDDLE });
|
2012-12-21 11:04:57 -05:00
|
|
|
this._continueButton = this.addButton({ label: '',
|
|
|
|
action: Lang.bind(this, this._onContinueButton),
|
|
|
|
default: true },
|
2013-05-09 00:41:07 -04:00
|
|
|
{ expand: false, x_fill: false, x_align: St.Align.END });
|
2012-01-10 10:37:26 -05:00
|
|
|
|
|
|
|
this.prompt.bind_property('cancel-label', this._cancelButton, 'label', GObject.BindingFlags.SYNC_CREATE);
|
|
|
|
this.prompt.bind_property('continue-label', this._continueButton, 'label', GObject.BindingFlags.SYNC_CREATE);
|
|
|
|
},
|
|
|
|
|
|
|
|
_buildControlTable: function() {
|
2013-07-08 21:02:58 -04:00
|
|
|
let layout = new Clutter.TableLayout();
|
|
|
|
let table = new St.Widget({ style_class: 'keyring-dialog-control-table',
|
|
|
|
layout_manager: layout });
|
|
|
|
layout.hookup_style(table);
|
2012-01-10 10:37:26 -05:00
|
|
|
let row = 0;
|
|
|
|
|
|
|
|
if (this.prompt.password_visible) {
|
2013-07-08 21:02:58 -04:00
|
|
|
let label = new St.Label({ style_class: 'prompt-dialog-password-label' });
|
2012-01-10 10:37:26 -05:00
|
|
|
label.set_text(_("Password:"));
|
2013-09-18 15:39:23 -04:00
|
|
|
label.clutter_text.ellipsize = Pango.EllipsizeMode.NONE;
|
2013-07-08 21:02:58 -04:00
|
|
|
layout.pack(label, 0, row);
|
|
|
|
layout.child_set(label, { x_expand: false, y_fill: false,
|
|
|
|
x_align: Clutter.TableAlignment.START });
|
2012-01-10 10:37:26 -05:00
|
|
|
this._passwordEntry = new St.Entry({ style_class: 'prompt-dialog-password-entry',
|
|
|
|
text: '',
|
2013-07-08 21:02:58 -04:00
|
|
|
can_focus: true });
|
2012-01-10 10:37:26 -05:00
|
|
|
this._passwordEntry.clutter_text.set_password_char('\u25cf'); // ● U+25CF BLACK CIRCLE
|
|
|
|
ShellEntry.addContextMenu(this._passwordEntry, { isPassword: true });
|
|
|
|
this._passwordEntry.clutter_text.connect('activate', Lang.bind(this, this._onPasswordActivate));
|
2013-07-08 21:02:58 -04:00
|
|
|
layout.pack(this._passwordEntry, 1, row);
|
2012-01-10 10:37:26 -05:00
|
|
|
row++;
|
|
|
|
} else {
|
|
|
|
this._passwordEntry = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.prompt.confirm_visible) {
|
|
|
|
var label = new St.Label(({ style_class: 'prompt-dialog-password-label' }));
|
|
|
|
label.set_text(_("Type again:"));
|
2013-07-08 21:02:58 -04:00
|
|
|
layout.pack(label, 0, row);
|
|
|
|
layout.child_set(label, { x_expand: false, y_fill: false,
|
|
|
|
x_align: Clutter.TableAlignment.START });
|
2012-01-10 10:37:26 -05:00
|
|
|
this._confirmEntry = new St.Entry({ style_class: 'prompt-dialog-password-entry',
|
|
|
|
text: '',
|
2013-07-08 21:02:58 -04:00
|
|
|
can_focus: true });
|
2012-01-10 10:37:26 -05:00
|
|
|
this._confirmEntry.clutter_text.set_password_char('\u25cf'); // ● U+25CF BLACK CIRCLE
|
|
|
|
ShellEntry.addContextMenu(this._confirmEntry, { isPassword: true });
|
|
|
|
this._confirmEntry.clutter_text.connect('activate', Lang.bind(this, this._onConfirmActivate));
|
2013-07-08 21:02:58 -04:00
|
|
|
layout.pack(this._confirmEntry, 1, row);
|
2012-01-10 10:37:26 -05:00
|
|
|
row++;
|
|
|
|
} else {
|
|
|
|
this._confirmEntry = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.prompt.set_password_actor(this._passwordEntry ? this._passwordEntry.clutter_text : null);
|
|
|
|
this.prompt.set_confirm_actor(this._confirmEntry ? this._confirmEntry.clutter_text : null);
|
|
|
|
|
|
|
|
if (this.prompt.choice_visible) {
|
|
|
|
let choice = new CheckBox.CheckBox();
|
|
|
|
this.prompt.bind_property('choice-label', choice.getLabelActor(), 'text', GObject.BindingFlags.SYNC_CREATE);
|
|
|
|
this.prompt.bind_property('choice-chosen', choice.actor, 'checked', GObject.BindingFlags.SYNC_CREATE | GObject.BindingFlags.BIDIRECTIONAL);
|
2013-07-08 21:02:58 -04:00
|
|
|
layout.pack(choice.actor, 1, row);
|
2012-01-10 10:37:26 -05:00
|
|
|
row++;
|
|
|
|
}
|
|
|
|
|
|
|
|
let warning = new St.Label({ style_class: 'prompt-dialog-error-label' });
|
|
|
|
warning.clutter_text.ellipsize = Pango.EllipsizeMode.NONE;
|
|
|
|
warning.clutter_text.line_wrap = true;
|
2013-07-08 21:02:58 -04:00
|
|
|
layout.pack(warning, 1, row);
|
2013-12-11 16:23:23 -05:00
|
|
|
layout.child_set(warning, { x_fill: false, x_align: Clutter.TableAlignment.START });
|
2012-01-10 10:37:26 -05:00
|
|
|
this.prompt.bind_property('warning-visible', warning, 'visible', GObject.BindingFlags.SYNC_CREATE);
|
|
|
|
this.prompt.bind_property('warning', warning, 'text', GObject.BindingFlags.SYNC_CREATE);
|
|
|
|
|
|
|
|
if (this._controlTable) {
|
|
|
|
this._controlTable.destroy_all_children();
|
|
|
|
this._controlTable.destroy();
|
|
|
|
}
|
|
|
|
|
|
|
|
this._controlTable = table;
|
|
|
|
this._messageBox.add(table, { x_fill: true, y_fill: true });
|
|
|
|
},
|
|
|
|
|
2012-12-21 11:07:56 -05:00
|
|
|
_updateSensitivity: function(sensitive) {
|
2013-04-17 06:02:12 -04:00
|
|
|
if (this._passwordEntry) {
|
|
|
|
this._passwordEntry.reactive = sensitive;
|
|
|
|
this._passwordEntry.clutter_text.editable = sensitive;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this._confirmEntry) {
|
|
|
|
this._confirmEntry.reactive = sensitive;
|
|
|
|
this._confirmEntry.clutter_text.editable = sensitive;
|
|
|
|
}
|
2012-12-21 11:07:56 -05:00
|
|
|
|
2012-12-30 12:05:24 -05:00
|
|
|
this._continueButton.can_focus = sensitive;
|
|
|
|
this._continueButton.reactive = sensitive;
|
2013-05-09 00:41:07 -04:00
|
|
|
this.setWorking(!sensitive);
|
2012-12-21 11:07:56 -05:00
|
|
|
},
|
|
|
|
|
2012-01-10 10:37:26 -05:00
|
|
|
_ensureOpen: function() {
|
|
|
|
// NOTE: ModalDialog.open() is safe to call if the dialog is
|
|
|
|
// already open - it just returns true without side-effects
|
|
|
|
if (this.open())
|
|
|
|
return true;
|
|
|
|
|
|
|
|
// The above fail if e.g. unable to get input grab
|
|
|
|
//
|
|
|
|
// In an ideal world this wouldn't happen (because the
|
|
|
|
// Shell is in complete control of the session) but that's
|
|
|
|
// just not how things work right now.
|
|
|
|
|
|
|
|
log('keyringPrompt: Failed to show modal dialog.' +
|
|
|
|
' Dismissing prompt request');
|
|
|
|
this.prompt.cancel()
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
|
|
|
|
_onShowPassword: function(prompt) {
|
|
|
|
this._buildControlTable();
|
|
|
|
this._ensureOpen();
|
2012-12-28 03:20:18 -05:00
|
|
|
this._updateSensitivity(true);
|
2012-01-10 10:37:26 -05:00
|
|
|
this._passwordEntry.grab_key_focus();
|
|
|
|
},
|
|
|
|
|
|
|
|
_onShowConfirm: function(prompt) {
|
|
|
|
this._buildControlTable();
|
|
|
|
this._ensureOpen();
|
2012-12-28 03:20:18 -05:00
|
|
|
this._updateSensitivity(true);
|
2012-01-10 10:37:26 -05:00
|
|
|
this._continueButton.grab_key_focus();
|
|
|
|
},
|
|
|
|
|
|
|
|
_onHidePrompt: function(prompt) {
|
|
|
|
this.close();
|
|
|
|
},
|
|
|
|
|
|
|
|
_onPasswordActivate: function() {
|
2012-12-28 03:20:18 -05:00
|
|
|
if (this.prompt.confirm_visible)
|
2012-01-10 10:37:26 -05:00
|
|
|
this._confirmEntry.grab_key_focus();
|
2012-12-28 03:20:18 -05:00
|
|
|
else
|
2012-01-10 10:37:26 -05:00
|
|
|
this._onContinueButton();
|
|
|
|
},
|
|
|
|
|
|
|
|
_onConfirmActivate: function() {
|
|
|
|
this._onContinueButton();
|
|
|
|
},
|
|
|
|
|
|
|
|
_onContinueButton: function() {
|
2012-12-21 11:07:56 -05:00
|
|
|
this._updateSensitivity(false);
|
2012-09-02 21:23:50 -04:00
|
|
|
this.prompt.complete();
|
2012-01-10 10:37:26 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
_onCancelButton: function() {
|
2012-09-02 21:23:50 -04:00
|
|
|
this.prompt.cancel();
|
2012-01-10 10:37:26 -05:00
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2013-09-18 11:53:26 -04:00
|
|
|
const KeyringDummyDialog = new Lang.Class({
|
|
|
|
Name: 'KeyringDummyDialog',
|
|
|
|
|
|
|
|
_init: function() {
|
|
|
|
this.prompt = new Shell.KeyringPrompt();
|
|
|
|
this.prompt.connect('show-password',
|
|
|
|
Lang.bind(this, this._cancelPrompt));
|
|
|
|
this.prompt.connect('show-confirm', Lang.bind(this,
|
|
|
|
this._cancelPrompt));
|
|
|
|
},
|
|
|
|
|
|
|
|
_cancelPrompt: function() {
|
|
|
|
this.prompt.cancel();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2012-09-02 21:23:50 -04:00
|
|
|
const KeyringPrompter = new Lang.Class({
|
|
|
|
Name: 'KeyringPrompter',
|
|
|
|
|
|
|
|
_init: function() {
|
|
|
|
this._prompter = new Gcr.SystemPrompter();
|
2013-09-18 11:53:26 -04:00
|
|
|
this._prompter.connect('new-prompt', Lang.bind(this,
|
|
|
|
function() {
|
|
|
|
let dialog = this._enabled ? new KeyringDialog()
|
|
|
|
: new KeyringDummyDialog();
|
2013-09-27 10:04:25 -04:00
|
|
|
this._currentPrompt = dialog.prompt;
|
|
|
|
return this._currentPrompt;
|
2013-09-18 11:53:26 -04:00
|
|
|
}));
|
2012-09-02 21:23:50 -04:00
|
|
|
this._dbusId = null;
|
2013-09-18 11:53:26 -04:00
|
|
|
this._registered = false;
|
|
|
|
this._enabled = false;
|
2013-09-27 10:04:25 -04:00
|
|
|
this._currentPrompt = null;
|
2012-09-02 21:23:50 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
enable: function() {
|
2013-09-18 11:53:26 -04:00
|
|
|
if (!this._registered) {
|
|
|
|
this._prompter.register(Gio.DBus.session);
|
|
|
|
this._dbusId = Gio.DBus.session.own_name('org.gnome.keyring.SystemPrompter',
|
|
|
|
Gio.BusNameOwnerFlags.ALLOW_REPLACEMENT, null, null);
|
|
|
|
this._registered = true;
|
|
|
|
}
|
|
|
|
this._enabled = true;
|
2012-09-02 21:23:50 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
disable: function() {
|
2013-09-18 11:53:26 -04:00
|
|
|
this._enabled = false;
|
2013-09-27 10:04:25 -04:00
|
|
|
|
|
|
|
if (this._prompter.prompting)
|
|
|
|
this._currentPrompt.cancel();
|
|
|
|
this._currentPrompt = null;
|
2012-09-02 21:23:50 -04:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
const Component = KeyringPrompter;
|