From 603b8b7b60070014faea29748beb774cfb52d291 Mon Sep 17 00:00:00 2001 From: Joan CiberSheep Date: Sun, 13 Feb 2022 22:04:12 +0100 Subject: [PATCH 1/2] Added paste URI for add otp --- qml/Components/KeyToEdit.qml | 119 ++++++++++++++++++++++++------ qml/Components/PageBackup.qml | 2 +- qml/Components/PageEditAddKey.qml | 49 +++++------- qml/Components/PageHubImport.qml | 2 +- qml/Main.qml | 7 +- 5 files changed, 119 insertions(+), 60 deletions(-) diff --git a/qml/Components/KeyToEdit.qml b/qml/Components/KeyToEdit.qml index 460ab31..ece78b1 100644 --- a/qml/Components/KeyToEdit.qml +++ b/qml/Components/KeyToEdit.qml @@ -35,6 +35,77 @@ Column { cAlg.selectedAlg = uriJson.algorithm } + Row { + width: parent.width + spacing: units.gu(2) + + Text { + anchors.verticalCenter: parent.verticalCenter + id: descTxt + text: "" + i18n.tr("Description") + "" + color: theme.palette.normal.overlayText + } + + TextField { + width: parent.width - units.gu(2) - descTxt.width + id: userDescTF + placeholderText: i18n.tr("Add a description") + inputMethodHints: Qt.ImhNoPredictiveText + + onAccepted: { + focus = false; + issuerTF.focus = true; + } + } + } + + Label { + visible: !editMode + text: "" + i18n.tr("Paste an otpauth:// URI") + "" + height: units.gu(6) + anchors.horizontalCenter: parent.horizontalCenter + verticalAlignment: Text.AlignBottom + textSize: Label.Medium + } + + Row { + visible: !editMode + width: parent.width + spacing: units.gu(2) + + TextField { + id: pasteURI + width: parent.width -renderURI.width -units.gu(2) + placeholderText: i18n.tr("Paste URI") + inputMethodHints: Qt.ImhNoPredictiveText + onAccepted: renderURI.clicked() + } + + Button { + id: renderURI + text: i18n.tr("Add") + color: theme.palette.normal.positive + enabled: pasteURI.text != "" + onClicked: fillInfo(pasteURI.text) + } + } + + Label { + id: errorMsg + visible: false + width: parent.width + wrapMode: Text.WordWrap + } + + Label { + visible: !editMode + text: "" + i18n.tr("Or type the information") + "" + height: units.gu(6) + anchors.horizontalCenter: parent.horizontalCenter + verticalAlignment: Text.AlignBottom + textSize: Label.Medium + } + Row { width: parent.width spacing: units.gu(2) @@ -64,30 +135,6 @@ Column { } } - Row { - width: parent.width - spacing: units.gu(2) - - Text { - anchors.verticalCenter: parent.verticalCenter - id: descTxt - text: "" + i18n.tr("Description") + "" - color: theme.palette.normal.overlayText - } - - TextField { - width: parent.width - units.gu(2) - descTxt.width - id: userDescTF - placeholderText: i18n.tr("Add a description") - inputMethodHints: Qt.ImhNoPredictiveText - - onAccepted: { - focus = false; - issuerTF.focus = true; - } - } - } - Row { width: parent.width spacing: units.gu(2) @@ -296,4 +343,28 @@ Column { return returnKey; } + + function fillInfo(uri){ + console.log("Checking pasted URI") + uri = root.checkUri(uri) + + try { + uriJson = OTPAuth.URI.parse(uri); + } catch(e) { + console.log("Error",e); + errorMsg.text = i18n.tr("URI format is invalid. The expected format is 'otpauth://totp/[ID]?secret=[CODE]`") + errorMsg.visible = true + hideErrorMsg.start() + } + } + + Timer { + //General ticker. It ticks every second + id: hideErrorMsg + running: false + repeat: false + interval: 6000 + + onTriggered: errorMsg.visible = false; + } } diff --git a/qml/Components/PageBackup.qml b/qml/Components/PageBackup.qml index 3df1c97..ed9d754 100644 --- a/qml/Components/PageBackup.qml +++ b/qml/Components/PageBackup.qml @@ -136,7 +136,7 @@ Page { onIsImporting: if (isJson) importButton.visible = false; onDoneImporting: { - console.log("!!!!!!!!!!!!!!!!!!!!!!!!") + console.log("Debug: Finished importing") if (isJson) importButton.visible = true; } } diff --git a/qml/Components/PageEditAddKey.qml b/qml/Components/PageEditAddKey.qml index 3bb31c4..cc9ef4f 100644 --- a/qml/Components/PageEditAddKey.qml +++ b/qml/Components/PageEditAddKey.qml @@ -18,6 +18,18 @@ Page { header: HeaderBase { id: pageHeader title: i18n.tr("Key Information") + + trailingActionBar { + actions: Action { + iconName: "ok" + text: editMode + ? i18n.tr("Edit") + : i18n.tr("Add") + + enabled: !info.isInfoEmpty + onTriggered: addKey() + } + } } ScrollView { @@ -30,41 +42,17 @@ Page { id: editAddFlickable width: parent.width height: parent.height - contentHeight: mainColumn.height + contentHeight: info.height topMargin: Qt.inputMethod.visible && !editMode ? Qt.inputMethod.keyboardRectangle.height + units.gu(2) : pageHeader.height + units.gu(2) bottomMargin: units.gu(4) - Column { - id: mainColumn - width: parent.width - spacing: units.gu(2) - - KeyToEdit { - id: info - width: parent.width * .85 - anchors.horizontalCenter: parent.horizontalCenter - editMode: editAddKeyPage.editMode - } - - Button { - width: Math.min(parent.width * .7, units.gu(39)) - anchors.horizontalCenter: parent.horizontalCenter - text: editMode - ? i18n.tr("Edit") - : i18n.tr("Add") - color: theme.palette.normal.positive - enabled: !info.isInfoEmpty - onClicked: addKey() - } - - Button { - width: Math.min(parent.width * .7, units.gu(39)) - anchors.horizontalCenter: parent.horizontalCenter - text: i18n.tr("Cancel") - onClicked: closingPop() - } + KeyToEdit { + id: info + width: parent.width * .85 + anchors.horizontalCenter: parent.horizontalCenter + editMode: editAddKeyPage.editMode } } @@ -79,7 +67,6 @@ Page { if (editMode) { KeysDB.updateStoredKey(idToUpdate, Date(), editedKey.toString(), info.userDesc); - } else { KeysDB.storeKey(Date(), editedKey.toString(), info.userDesc); } diff --git a/qml/Components/PageHubImport.qml b/qml/Components/PageHubImport.qml index 028f55c..b769f5f 100644 --- a/qml/Components/PageHubImport.qml +++ b/qml/Components/PageHubImport.qml @@ -84,7 +84,7 @@ Page { selectedItems.push( String(importPage.activeTransfer.items[i].url) //Don't remove .replace("file://", "") ); - console.log("SEEE",selectedItems[i]) + console.log("Charged. Items:",selectedItems[i]) } accept(selectedItems); diff --git a/qml/Main.qml b/qml/Main.qml index 17e9b1c..078de8f 100644 --- a/qml/Main.qml +++ b/qml/Main.qml @@ -165,6 +165,7 @@ MainView { } function checkUri(uri) { + console.log("Checking URI") var checkIssuer = findParam("issuer=", uri, "&"); var checkFirstIssuer; @@ -172,12 +173,12 @@ MainView { if (!checkFirstIssuer) { //We have no issuer and ":[user]" - console.log("Issuer problem") + console.log("Checking problem with 'issuer'. We have no issuer and ':[user]'") return uri.replace("/:","/") } if (checkIssuer) { - console.log("Issuer problem2") + console.log("Checking problem with issuer (2)...") if (checkFirstIssuer !== checkIssuer) { console.log(checkFirstIssuer,checkIssuer) uri = uri.replace("issuer=" + checkIssuer,"") @@ -186,7 +187,6 @@ MainView { } } - //console.log("issuer",checkIssuer,"first issuer:",checkFirstIssuer) return uri; } @@ -200,6 +200,7 @@ MainView { } function formatCode(code, split) { + //Format the code to add spaces only for viewing it if (split) { if (code.length > 6) { return code.replace(/(\d{3})(\d{3})(\d)/, '$1 $2 $3'); -- GitLab From da3efad7d9fd4e930ceadae5d67b79deac94495f Mon Sep 17 00:00:00 2001 From: Joan CiberSheep Date: Sun, 13 Feb 2022 23:39:42 +0100 Subject: [PATCH 2/2] Remove ScrollView from edit key page, make sure view in bottom edge is visible --- qml/Components/PageEditAddKey.qml | 13 ++++--------- qml/Main.qml | 2 -- 2 files changed, 4 insertions(+), 11 deletions(-) diff --git a/qml/Components/PageEditAddKey.qml b/qml/Components/PageEditAddKey.qml index cc9ef4f..1bb0f03 100644 --- a/qml/Components/PageEditAddKey.qml +++ b/qml/Components/PageEditAddKey.qml @@ -32,21 +32,16 @@ Page { } } - ScrollView { - width: parent.width - height: parent.height - contentItem: editAddFlickable - } - Flickable { id: editAddFlickable width: parent.width height: parent.height + clip: true contentHeight: info.height - topMargin: Qt.inputMethod.visible && !editMode + topMargin: pageHeader.height + units.gu(2) + bottomMargin: Qt.inputMethod.visible && !editMode ? Qt.inputMethod.keyboardRectangle.height + units.gu(2) - : pageHeader.height + units.gu(2) - bottomMargin: units.gu(4) + : units.gu(4) KeyToEdit { id: info diff --git a/qml/Main.qml b/qml/Main.qml index 078de8f..011c1c7 100644 --- a/qml/Main.qml +++ b/qml/Main.qml @@ -61,7 +61,6 @@ MainView { BottomEdge { id: bottomEdge enabled: resumeIsMainPage && !isResumeFlicking && !Qt.inputMethod.visible - height: root.height hint.visible: enabled hint.text: i18n.tr("Add Key") @@ -72,7 +71,6 @@ MainView { commit(); collapse(); } - } //Handle incoming otpauth:// url -- GitLab