mirror of
https://github.com/seiichiro0185/sailotp.git
synced 2024-11-22 07:39:42 +00:00
Finalized favourites feature
* Favourite is now shown on the ActiveCover * Added possibility to "unstar" a favourite
This commit is contained in:
parent
eb08a4eee1
commit
7f781b8d90
4 changed files with 85 additions and 13 deletions
|
@ -29,11 +29,39 @@
|
||||||
|
|
||||||
import QtQuick 2.0
|
import QtQuick 2.0
|
||||||
import Sailfish.Silica 1.0
|
import Sailfish.Silica 1.0
|
||||||
|
import "../lib/crypto.js" as OTP
|
||||||
|
|
||||||
// Define the Layout of the Active Cover
|
// Define the Layout of the Active Cover
|
||||||
CoverBackground {
|
CoverBackground {
|
||||||
|
id: coverPage
|
||||||
|
|
||||||
// Show the SailOTP Logo
|
property double lastUpdated: 0
|
||||||
|
|
||||||
|
Timer {
|
||||||
|
interval: 1000
|
||||||
|
// Timer runs only when cover is visible and favourite is set
|
||||||
|
running: !Qt.application.active && appWin.coverSecret != ""
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Show the SailOTP Logo
|
||||||
Image {
|
Image {
|
||||||
id: logo
|
id: logo
|
||||||
source: "../sailotp.png"
|
source: "../sailotp.png"
|
||||||
|
@ -42,10 +70,22 @@ CoverBackground {
|
||||||
anchors.topMargin: 48
|
anchors.topMargin: 48
|
||||||
}
|
}
|
||||||
|
|
||||||
// Show the Application Name
|
Column {
|
||||||
Label {
|
anchors.top: logo.bottom
|
||||||
id: label
|
anchors.topMargin: 48
|
||||||
anchors.centerIn: parent
|
anchors.horizontalCenter: parent.horizontalCenter
|
||||||
text: "SailOTP"
|
|
||||||
|
Label {
|
||||||
|
text: appWin.coverTitle
|
||||||
|
anchors.horizontalCenter: parent.horizontalCenter
|
||||||
|
color: Theme.secondaryColor
|
||||||
|
}
|
||||||
|
Label {
|
||||||
|
id: lOTP
|
||||||
|
text: appWin.coverOTP
|
||||||
|
anchors.horizontalCenter: parent.horizontalCenter
|
||||||
|
color: Theme.highlightColor
|
||||||
|
font.pixelSize: Theme.fontSizeExtraLarge
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,6 +33,13 @@ import "pages"
|
||||||
|
|
||||||
ApplicationWindow
|
ApplicationWindow
|
||||||
{
|
{
|
||||||
|
id: appWin
|
||||||
|
|
||||||
|
// Properties to pass values between MainPage and Cover
|
||||||
|
property string coverTitle: "SailOTP"
|
||||||
|
property string coverSecret: ""
|
||||||
|
property string coverOTP: ""
|
||||||
|
|
||||||
initialPage: Component { MainView { } }
|
initialPage: Component { MainView { } }
|
||||||
cover: Qt.resolvedUrl("cover/CoverPage.qml")
|
cover: Qt.resolvedUrl("cover/CoverPage.qml")
|
||||||
}
|
}
|
||||||
|
|
|
@ -68,6 +68,7 @@ function getOTP() {
|
||||||
var res = tx.executeSql("select * from OTPStorage;");
|
var res = tx.executeSql("select * from OTPStorage;");
|
||||||
for (var i=0; i < res.rows.length; i++) {
|
for (var i=0; i < res.rows.length; i++) {
|
||||||
mainPage.appendOTP(res.rows.item(i).title, res.rows.item(i).secret, res.rows.item(i).type, res.rows.item(i).counter, res.rows.item(i).fav);
|
mainPage.appendOTP(res.rows.item(i).title, res.rows.item(i).secret, res.rows.item(i).type, res.rows.item(i).counter, res.rows.item(i).fav);
|
||||||
|
if (res.rows.item(i).fav) mainPage.setCoverOTP(res.rows.item(i).title, res.rows.item(i).secret);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
@ -106,6 +107,16 @@ function setFav(title, secret) {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function resetFav(title, secret) {
|
||||||
|
var db = getDB();
|
||||||
|
|
||||||
|
db.transaction(
|
||||||
|
function(tx) {
|
||||||
|
tx.executeSql("UPDATE OTPStorage set fav = 0");
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
// Change an existing OTP
|
// Change an existing OTP
|
||||||
function changeOTP(title, secret, oldtitle, oldsecret) {
|
function changeOTP(title, secret, oldtitle, oldsecret) {
|
||||||
var db = getDB();
|
var db = getDB();
|
||||||
|
|
|
@ -41,13 +41,20 @@ Page {
|
||||||
}
|
}
|
||||||
|
|
||||||
// This holds the time of the last update of the page as Unix Timestamp (in Milliseconds)
|
// This holds the time of the last update of the page as Unix Timestamp (in Milliseconds)
|
||||||
property double lastUpdated: null
|
property double lastUpdated: 0
|
||||||
|
|
||||||
// Add an entry to the list
|
// Add an entry to the list
|
||||||
function appendOTP(title, secret, type, counter, fav) {
|
function appendOTP(title, secret, type, counter, fav) {
|
||||||
otpListModel.append({"secret": secret, "title": title, "fav": fav, "otp": ""});
|
otpListModel.append({"secret": secret, "title": title, "fav": fav, "otp": ""});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Hand favorite over to the cover
|
||||||
|
function setCoverOTP(title, secret) {
|
||||||
|
appWin.coverTitle = title
|
||||||
|
appWin.coverSecret = secret
|
||||||
|
if (secret == "") appWin.coverOTP = ""
|
||||||
|
}
|
||||||
|
|
||||||
// Reload the List of OTPs from storage
|
// Reload the List of OTPs from storage
|
||||||
function refreshOTPList() {
|
function refreshOTPList() {
|
||||||
otpList.visible = false;
|
otpList.visible = false;
|
||||||
|
@ -146,13 +153,20 @@ Page {
|
||||||
icon.source: fav == 1 ? "image://theme/icon-m-favorite-selected" : "image://theme/icon-m-favorite"
|
icon.source: fav == 1 ? "image://theme/icon-m-favorite-selected" : "image://theme/icon-m-favorite"
|
||||||
anchors.left: parent.left
|
anchors.left: parent.left
|
||||||
onClicked: {
|
onClicked: {
|
||||||
DB.setFav(title, secret)
|
if (fav == 0) {
|
||||||
for (var i=0; i<otpListModel.count; i++) {
|
DB.setFav(title, secret)
|
||||||
if (i != index) {
|
setCoverOTP(title, secret)
|
||||||
otpListModel.setProperty(i, "fav", 0);
|
for (var i=0; i<otpListModel.count; i++) {
|
||||||
} else {
|
if (i != index) {
|
||||||
otpListModel.setProperty(i, "fav", 1);
|
otpListModel.setProperty(i, "fav", 0);
|
||||||
|
} else {
|
||||||
|
otpListModel.setProperty(i, "fav", 1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
DB.resetFav(title, secret)
|
||||||
|
setCoverOTP("SailOTP", "")
|
||||||
|
otpListModel.setProperty(index, "fav", 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue