From dc02a1aa3f6811ce6adc8664c7852321ca1ecc00 Mon Sep 17 00:00:00 2001 From: Stefan Brand Date: Sun, 9 Feb 2014 10:50:58 +0100 Subject: [PATCH] Preparations for version 0.6 release Added possibility to cycle through the tokens from the cover --- qml/cover/CoverPage.qml | 60 ++++++++++++++++++++++++++-------------- qml/harbour-sailotp.qml | 35 +++++++++++++++++++++++ qml/lib/storage.js | 4 +-- qml/pages/MainView.qml | 49 ++++++++++++++------------------ rpm/harbour-sailotp.yaml | 2 +- 5 files changed, 97 insertions(+), 53 deletions(-) diff --git a/qml/cover/CoverPage.qml b/qml/cover/CoverPage.qml index 7d504ee..f7c21c2 100644 --- a/qml/cover/CoverPage.qml +++ b/qml/cover/CoverPage.qml @@ -38,28 +38,30 @@ CoverBackground { property double lastUpdated: 0 + function updateOTP() { + // get seconds from current Date + var curDate = new Date(); + + if (lOTP.text == "------" || curDate.getSeconds() == 30 || curDate.getSeconds() == 0 || (curDate.getTime() - lastUpdated > 2000)) { + appWin.coverOTP = OTP.calcOTP(appWin.coverSecret, "TOTP", 0); + } + + // Change color of the OTP to red if less than 5 seconds left + if (29 - (curDate.getSeconds() % 30) < 5) { + lOTP.color = "red" + } else { + lOTP.color = Theme.highlightColor + } + + lastUpdated = curDate.getTime(); + } + Timer { interval: 1000 // Timer runs only when cover is visible and favourite is set running: !Qt.application.active && appWin.coverSecret != "" && appWin.coverType == "TOTP" repeat: true - onTriggered: { - // get seconds from current Date - var curDate = new Date(); - - if (lOTP.text == "------" || curDate.getSeconds() == 30 || curDate.getSeconds() == 0 || (curDate.getTime() - lastUpdated > 2000)) { - appWin.coverOTP = OTP.calcOTP(appWin.coverSecret, "TOTP", 0); - } - - // Change color of the OTP to red if less than 5 seconds left - if (29 - (curDate.getSeconds() % 30) < 5) { - lOTP.color = "red" - } else { - lOTP.color = Theme.highlightColor - } - - lastUpdated = curDate.getTime(); - } + onTriggered: updateOTP(); } // Show the SailOTP Logo @@ -79,7 +81,6 @@ CoverBackground { Label { text: appWin.coverTitle anchors.horizontalCenter: parent.horizontalCenter - color: Theme.secondaryColor } Label { id: lOTP @@ -91,11 +92,28 @@ CoverBackground { } // CoverAction to update a HOTP-Token, only visible for HOTP-Type Tokens CoverActionList { - enabled: appWin.coverType == "HOTP" ? true : false CoverAction { - iconSource: "image://theme/icon-m-refresh" + iconSource: appWin.coverType == "HOTP" ? "image://theme/icon-cover-refresh" : "image://theme/icon-cover-previous" onTriggered: { - appWin.coverOTP = OTP.calcOTP(appWin.coverSecret, "HOTP", DB.getCounter(appWin.coverTitle, appWin.coverSecret, true)); + if (appWin.coverType == "HOTP") { + appWin.coverOTP = OTP.calcOTP(appWin.coverSecret, "HOTP", DB.getCounter(appWin.coverTitle, appWin.coverSecret, true)); + } else { + var index = appWin.coverIndex - 1 + if (index < 0) index = appWin.listModel.count - 1 + appWin.setCover(index); + DB.setFav(appWin.coverTitle, appWin.coverSecret) + if (appWin.coverType == "TOTP") updateOTP(); + } + } + } + CoverAction { + iconSource: "image://theme/icon-cover-next" + onTriggered: { + var index = appWin.coverIndex + 1 + if (index >= appWin.listModel.count) index = 0 + appWin.setCover(index); + DB.setFav(appWin.coverTitle, appWin.coverSecret) + if (appWin.coverType == "TOTP") updateOTP(); } } } diff --git a/qml/harbour-sailotp.qml b/qml/harbour-sailotp.qml index fb555f1..b7c76b5 100644 --- a/qml/harbour-sailotp.qml +++ b/qml/harbour-sailotp.qml @@ -37,15 +37,50 @@ ApplicationWindow id: appWin // Properties to pass values between MainPage and Cover + property alias listModel: otpListModel property string coverTitle: "SailOTP" property string coverSecret: "" property string coverType: "" property string coverOTP: "------" + property int coverIndex: 0 + // Global Listmodel for Tokens + ListModel { id: otpListModel } + + // Global Component for showing notification banners NotifyBanner { id: notify } + // Add an entry to the list + function appendOTP(title, secret, type, counter, fav) { + listModel.append({"secret": secret, "title": title, "fav": fav, "type": type, "counter": counter, "otp": "------"}); + } + + // Set the OTP shown on the Cover + function setCover(index) { + if (index >= 0 && index < listModel.count) { + coverTitle = listModel.get(index).title; + coverSecret = listModel.get(index).secret; + coverType = listModel.get(index).type; + coverIndex = index; + if (coverType == "TOTP") { coverOTP = "------"; } else { coverOTP = listModel.get(index).otp; } + for (var i=0; i 2000)) { - var curOTP = OTP.calcOTP(otpListModel.get(i).secret, "TOTP") - otpListModel.setProperty(i, "otp", curOTP); + if (appWin.listModel.get(i).otp == "------" || seconds == 30 || seconds == 0 || (curDate.getTime() - lastUpdated > 2000)) { + var curOTP = OTP.calcOTP(appWin.listModel.get(i).secret, "TOTP") + appWin.listModel.setProperty(i, "otp", curOTP); } - } else if (appWin.coverType == "HOTP" && (curDate.getTime() - lastUpdated > 2000) && otpListModel.get(i).fav == 1) { + } else if (appWin.coverType == "HOTP" && (curDate.getTime() - lastUpdated > 2000) && appWin.listModel.get(i).fav == 1) { // If we are coming back from the CoverPage update OTP value if current favourite is HOTP - otpListModel.setProperty(i, "otp", appWin.coverOTP); + appWin.listModel.setProperty(i, "otp", appWin.coverOTP); } } @@ -98,7 +89,7 @@ Page { Timer { interval: 500 // Timer only runs when app is acitive and we have entries - running: Qt.application.active && otpListModel.count + running: Qt.application.active && appWin.listModel.count repeat: true onTriggered: refreshOTPValues(); } @@ -132,7 +123,7 @@ Page { anchors.top: parent.top anchors.topMargin: 48 // Only show when there are enries - visible: otpListModel.count + visible: appWin.listModel.count } SilicaListView { @@ -141,7 +132,7 @@ Page { title: "SailOTP" } anchors.fill: parent - model: otpListModel + model: appWin.listModel width: parent.width ViewPlaceholder { @@ -158,7 +149,7 @@ Page { function remove() { // Show 5s countdown, then delete from DB and List - remorseAction(qsTr("Deleting"), function() { DB.removeOTP(title, secret); otpListModel.remove(index) }) + remorseAction(qsTr("Deleting"), function() { DB.removeOTP(title, secret); appWin.listModel.remove(index) }) } onClicked: { @@ -178,19 +169,19 @@ Page { onClicked: { if (fav == 0) { DB.setFav(title, secret) - setCoverOTP(title, secret, type) + appWin.setCover(index) if (type == "HOTP") appWin.coverOTP = otp - for (var i=0; i