From fdf52edaf16688cd0b7c17404fd1ad6f403b70f5 Mon Sep 17 00:00:00 2001 From: Kevin Whitaker Date: Wed, 26 Sep 2018 11:16:07 -0400 Subject: [PATCH] Add code to allow TOTP codes to be made and shown. Not sure if the code given by pyotp is always fresh, will have to see if it gives any indication. --- OTPListModel.py | 1 + qml/otplist.qml | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/OTPListModel.py b/OTPListModel.py index 7a997e5..fc999b3 100644 --- a/OTPListModel.py +++ b/OTPListModel.py @@ -75,6 +75,7 @@ class OTPModel(QtCore.QObject): def setAlgo(self,algo): self._algo = algo + @QtCore.Slot(result=str) def getOTPCode(self): if self._OTPType == "TOTP": return pyotp.TOTP(self._secret).now() diff --git a/qml/otplist.qml b/qml/otplist.qml index 8b04080..dbd2b23 100644 --- a/qml/otplist.qml +++ b/qml/otplist.qml @@ -32,6 +32,19 @@ Item { Layout.fillWidth: true visible: true } + Timer { + id: timeoutTimer + repeat: true + signal stopTOTP + onTriggered: { + if(timeout.value > 0) { + timeout.value = timeout.value - 1 + } else { + timeoutTimer.stop() + stopTOTP() + } + } + } } } ListView { @@ -52,6 +65,28 @@ Item { width: 2 color: "grey" } + MouseArea { + anchors.fill: parent + onClicked: { + if(display.OTPType == "TOTP") { + if(!timeoutTimer.running) { + timeout.to = display.timeout + timeout.value = display.timeout + otpCode.text = display.getOTPCode() + timeoutTimer.start() + timeoutTimer.stopTOTP.connect(removeCode) + } else { + timeoutTimer.stop() + timeout.value = 0 + otpCode.text = "" + } + } + } + function removeCode() { + otpCode.text = "" + timeoutTimer.stopTOTP.disconnect(removeCode) + } + } RowLayout { anchors.verticalCenter: parent.verticalCenter anchors.left: parent.left -- GitLab