[gnome-shell/eos3.8: 179/255] eos-payg: Better segregate Pay As You Go classes
- From: Matthew Leeds <mwleeds src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-shell/eos3.8: 179/255] eos-payg: Better segregate Pay As You Go classes
- Date: Wed, 10 Jun 2020 19:13:02 +0000 (UTC)
commit 1015c4ec568d03a61a45d4e3443251c36a326a49
Author: Mazen Asef <mazen asefali gmail com>
Date: Wed Jun 26 14:22:13 2019 -0300
eos-payg: Better segregate Pay As You Go classes
Auxiliary classes were in the paygUnlockDialog file, while the payg.js
was written to cover for this kind of functionality
js/ui/payg.js | 135 +++++++++++++++++++++++++++++++++++++++++
js/ui/paygUnlockDialog.js | 151 +---------------------------------------------
2 files changed, 137 insertions(+), 149 deletions(-)
---
diff --git a/js/ui/payg.js b/js/ui/payg.js
index bdd9325351..d64b11cb93 100644
--- a/js/ui/payg.js
+++ b/js/ui/payg.js
@@ -48,6 +48,141 @@ var UnlockStatus = {
SUCCEEDED: 4,
};
+var PaygUnlockCodeEntry = GObject.registerClass({
+ Signals: {
+ 'code-changed': { param_types: [GObject.TYPE_STRING] },
+ },
+}, class PaygUnlockCodeEntry extends St.Entry {
+
+ _init() {
+ super._init({
+ style_class: 'unlock-dialog-payg-entry',
+ reactive: true,
+ can_focus: true,
+ x_align: Clutter.ActorAlign.FILL,
+ x_expand: true,
+ y_expand: false,
+ });
+
+ this._code = '';
+ this.clutter_text.ellipsize = Pango.EllipsizeMode.NONE;
+ this.clutter_text.x_align = Clutter.ActorAlign.CENTER;
+
+ this._enabled = false;
+ this._buttonPressEventId = this.connect('button-press-event', this._onButtonPressEvent.bind(this));
+ this._capturedEventId = this.clutter_text.connect('captured-event',
this._onCapturedEvent.bind(this));
+ this._textChangedId = this.clutter_text.connect('text-changed', this._onTextChanged.bind(this));
+
+ this.connect('destroy', this._onDestroy.bind(this));
+ }
+
+ _onDestroy() {
+ if (this._buttonPressEventId > 0) {
+ this.disconnect(this._buttonPressEventId);
+ this._buttonPressEventId = 0;
+ }
+
+ if (this._capturedEventId > 0) {
+ this.clutter_text.disconnect(this._capturedEventId);
+ this._capturedEventId = 0;
+ }
+
+ if (this._textChangedId > 0) {
+ this.clutter_text.disconnect(this._textChangedId);
+ this._textChangedId = 0;
+ }
+ }
+
+ _onCapturedEvent(textActor, event) {
+ if (event.type() !== Clutter.EventType.KEY_PRESS)
+ return Clutter.EVENT_PROPAGATE;
+
+ let keysym = event.get_key_symbol();
+ let isDeleteKey =
+ keysym === Clutter.KEY_Delete ||
+ keysym === Clutter.KEY_KP_Delete ||
+ keysym === Clutter.KEY_BackSpace;
+ let isEnterKey =
+ keysym === Clutter.KEY_Return ||
+ keysym === Clutter.KEY_KP_Enter ||
+ keysym === Clutter.KEY_ISO_Enter;
+ let isExitKey =
+ keysym === Clutter.KEY_Escape ||
+ keysym === Clutter.KEY_Tab;
+ let isMovementKey =
+ keysym === Clutter.KEY_Left ||
+ keysym === Clutter.KEY_Right ||
+ keysym === Clutter.KEY_Home ||
+ keysym === Clutter.KEY_KP_Home ||
+ keysym === Clutter.KEY_End ||
+ keysym === Clutter.KEY_KP_End;
+
+ // Make sure we can leave the entry and delete and
+ // navigate numbers with the keyboard.
+ if (isExitKey || isEnterKey || isDeleteKey || isMovementKey)
+ return Clutter.EVENT_PROPAGATE;
+
+ let character = event.get_key_unicode();
+ this.addCharacter(character);
+
+ return Clutter.EVENT_STOP;
+ }
+
+ _onTextChanged(textActor) {
+ this._code = textActor.text;
+ this.emit('code-changed', this._code);
+ }
+
+ _onButtonPressEvent() {
+ if (!this._enabled)
+ return;
+
+ this.grab_key_focus();
+ return false;
+ }
+
+ addCharacter(character) {
+ if (!this._enabled || !GLib.unichar_isprint(character) ||
+ character === Main.paygManager.codeFormatPrefix ||
+ character === Main.paygManager.codeFormatSuffix)
+ return;
+
+ let pos = this.clutter_text.get_cursor_position();
+ let before = pos === -1 ? this._code : this._code.slice(0, pos);
+ let after = pos === -1 ? '' : this._code.slice(pos);
+ let newCode = before + character + after;
+
+ if (!Main.paygManager.validateCode(newCode, true))
+ return;
+
+ this.clutter_text.insert_unichar(character);
+ }
+
+ setEnabled(value) {
+ if (this._enabled === value)
+ return;
+
+ this._enabled = value;
+ this.reactive = value;
+ this.can_focus = value;
+ this.clutter_text.reactive = value;
+ this.clutter_text.editable = value;
+ this.clutter_text.cursor_visible = value;
+ }
+
+ reset() {
+ this.text = '';
+ }
+
+ get code() {
+ return this._code;
+ }
+
+ get length() {
+ return this._code.length;
+ }
+});
+
var PaygUnlockUi = GObject.registerClass({
Signals: {
'code-reset': {},
diff --git a/js/ui/paygUnlockDialog.js b/js/ui/paygUnlockDialog.js
index 93f0236fe9..fc5960f7fb 100644
--- a/js/ui/paygUnlockDialog.js
+++ b/js/ui/paygUnlockDialog.js
@@ -20,11 +20,9 @@
/* exported PaygUnlockDialog */
-const { Atk, Clutter, Gio, GLib,
+const { Atk, Clutter, GLib,
GObject, Meta, Pango, Shell, St } = imports.gi;
-const Gettext = imports.gettext;
-const PaygManager = imports.misc.paygManager;
const Payg = imports.ui.payg;
const Animation = imports.ui.animation;
@@ -36,151 +34,6 @@ const MSEC_PER_SEC = 1000;
// The timeout before going back automatically to the lock screen
const IDLE_TIMEOUT_SECS = 2 * 60;
-const SPINNER_ICON_SIZE_PIXELS = 16;
-
-var UnlockStatus = {
- NOT_VERIFYING: 0,
- VERIFYING: 1,
- FAILED: 2,
- TOO_MANY_ATTEMPTS: 3,
- SUCCEEDED: 4,
-};
-
-var PaygUnlockCodeEntry = GObject.registerClass({
- Signals: {
- 'code-changed': { param_types: [GObject.TYPE_STRING] },
- },
-}, class PaygUnlockCodeEntry extends St.Entry {
-
- _init() {
- super._init({
- style_class: 'unlock-dialog-payg-entry',
- reactive: true,
- can_focus: true,
- x_align: Clutter.ActorAlign.FILL,
- x_expand: true,
- y_expand: false,
- });
-
- this._code = '';
- this.clutter_text.ellipsize = Pango.EllipsizeMode.NONE;
- this.clutter_text.x_align = Clutter.ActorAlign.CENTER;
-
- this._enabled = false;
- this._buttonPressEventId = this.connect('button-press-event', this._onButtonPressEvent.bind(this));
- this._capturedEventId = this.clutter_text.connect('captured-event',
this._onCapturedEvent.bind(this));
- this._textChangedId = this.clutter_text.connect('text-changed', this._onTextChanged.bind(this));
-
- this.connect('destroy', this._onDestroy.bind(this));
- }
-
- _onDestroy() {
- if (this._buttonPressEventId > 0) {
- this.disconnect(this._buttonPressEventId);
- this._buttonPressEventId = 0;
- }
-
- if (this._capturedEventId > 0) {
- this.clutter_text.disconnect(this._capturedEventId);
- this._capturedEventId = 0;
- }
-
- if (this._textChangedId > 0) {
- this.clutter_text.disconnect(this._textChangedId);
- this._textChangedId = 0;
- }
- }
-
- _onCapturedEvent(textActor, event) {
- if (event.type() !== Clutter.EventType.KEY_PRESS)
- return Clutter.EVENT_PROPAGATE;
-
- let keysym = event.get_key_symbol();
- let isDeleteKey =
- keysym === Clutter.KEY_Delete ||
- keysym === Clutter.KEY_KP_Delete ||
- keysym === Clutter.KEY_BackSpace;
- let isEnterKey =
- keysym === Clutter.KEY_Return ||
- keysym === Clutter.KEY_KP_Enter ||
- keysym === Clutter.KEY_ISO_Enter;
- let isExitKey =
- keysym === Clutter.KEY_Escape ||
- keysym === Clutter.KEY_Tab;
- let isMovementKey =
- keysym === Clutter.KEY_Left ||
- keysym === Clutter.KEY_Right ||
- keysym === Clutter.KEY_Home ||
- keysym === Clutter.KEY_KP_Home ||
- keysym === Clutter.KEY_End ||
- keysym === Clutter.KEY_KP_End;
-
- // Make sure we can leave the entry and delete and
- // navigate numbers with the keyboard.
- if (isExitKey || isEnterKey || isDeleteKey || isMovementKey)
- return Clutter.EVENT_PROPAGATE;
-
- let character = event.get_key_unicode();
- this.addCharacter(character);
-
- return Clutter.EVENT_STOP;
- }
-
- _onTextChanged(textActor) {
- this._code = textActor.text;
- this.emit('code-changed', this._code);
- }
-
- _onButtonPressEvent() {
- if (!this._enabled)
- return;
-
- this.grab_key_focus();
- return false;
- }
-
- addCharacter(character) {
- if (!this._enabled || !GLib.unichar_isprint(character) ||
- character === Main.paygManager.codeFormatPrefix ||
- character === Main.paygManager.codeFormatSuffix)
- return;
-
- let pos = this.clutter_text.get_cursor_position();
- let before = pos === -1 ? this._code : this._code.slice(0, pos);
- let after = pos === -1 ? '' : this._code.slice(pos);
- let newCode = before + character + after;
-
- if (!Main.paygManager.validateCode(newCode, true))
- return;
-
- this.clutter_text.insert_unichar(character);
- }
-
- setEnabled(value) {
- if (this._enabled === value)
- return;
-
- this._enabled = value;
- this.reactive = value;
- this.can_focus = value;
- this.clutter_text.reactive = value;
- this.clutter_text.editable = value;
- this.clutter_text.cursor_visible = value;
- }
-
- reset() {
- this.text = '';
- }
-
- get code() {
- return this._code;
- }
-
- get length() {
- return this._code.length;
- }
-});
-
var PaygUnlockDialog = GObject.registerClass({
Signals: {
'code-added': {},
@@ -428,7 +281,7 @@ var PaygUnlockDialog = GObject.registerClass({
entryBox.add_child(prefix);
}
- this._entry = new PaygUnlockCodeEntry();
+ this._entry = new Payg.PaygUnlockCodeEntry();
entryBox.add_child(this._entry);
if (Main.paygManager.codeFormatSuffix !== '') {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]