diff --git a/OTPListModel.py b/OTPListModel.py index 7a997e5ca55572165389d632e4979d97bb780283..fc999b3123962f320357fa63ecd0ad4d45d2fa2b 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 8b04080412a3e5e5f9d9bc6b535c3657d4083f0c..dbd2b232ac4158c53466b716178f5e0d0ca46356 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