1
0
Fork 0
mirror of https://github.com/seiichiro0185/sailotp.git synced 2024-11-22 07:39:42 +00:00

Changed MainView to support favourites

* Added switch to show status
* Save selected favourite to LocalStorage DB
This commit is contained in:
seiichiro 2014-01-09 22:12:55 +01:00
parent 11072b2f16
commit 40f53fc47a
2 changed files with 47 additions and 14 deletions

View file

@ -67,7 +67,7 @@ function getOTP() {
function(tx) { function(tx) {
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); 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);
} }
} }
) )
@ -95,6 +95,17 @@ function removeOTP(title, secret) {
) )
} }
function setFav(title, secret) {
var db = getDB();
db.transaction(
function(tx) {
tx.executeSql("UPDATE OTPStorage set fav = 0");
tx.executeSql("UPDATE OTPStorage set fav = 1 WHERE title=? and secret=?;", [title, secret]);
}
)
}
// 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();

View file

@ -44,15 +44,17 @@ Page {
property double lastUpdated: null property double lastUpdated: null
// Add an entry to the list // Add an entry to the list
function appendOTP(title, secret) { function appendOTP(title, secret, type, counter, fav) {
otpListModel.append({"secret": secret, "title": title, "otp": ""}); otpListModel.append({"secret": secret, "title": title, "fav": fav, "otp": ""});
} }
// Reload the List of OTPs from storage // Reload the List of OTPs from storage
function refreshOTPList() { function refreshOTPList() {
otpList.visible = false;
otpListModel.clear(); otpListModel.clear();
DB.getOTP(); DB.getOTP();
refreshOTPValues(); refreshOTPValues();
otpList.visible = true;
} }
// Calculate new OTPs for every entry // Calculate new OTPs for every entry
@ -67,7 +69,6 @@ Page {
if (otpListModel.get(i).otp == "" || seconds == 30 || seconds == 0 || (curDate.getTime() - lastUpdated > 2000)) { if (otpListModel.get(i).otp == "" || seconds == 30 || seconds == 0 || (curDate.getTime() - lastUpdated > 2000)) {
var curOTP = OTP.calcOTP(otpListModel.get(i).secret) var curOTP = OTP.calcOTP(otpListModel.get(i).secret)
otpListModel.setProperty(i, "otp", curOTP); otpListModel.setProperty(i, "otp", curOTP);
console.log("Updating Value ", i);
} }
} }
@ -79,7 +80,8 @@ Page {
Timer { Timer {
interval: 1000 interval: 1000
running: Qt.application.active // Timer only runs when App is active // Timer only runs when app is acitive and we have entries
running: Qt.application.active && otpListModel.count
repeat: true repeat: true
onTriggered: refreshOTPValues(); onTriggered: refreshOTPValues();
} }
@ -104,6 +106,8 @@ Page {
maximumValue: 29 maximumValue: 29
anchors.top: parent.top anchors.top: parent.top
anchors.topMargin: 48 anchors.topMargin: 48
// Only show when there are enries
visible: otpListModel.count
} }
SilicaListView { SilicaListView {
@ -121,13 +125,11 @@ Page {
hintText: "Pull down to add a OTP" hintText: "Pull down to add a OTP"
} }
delegate: ListItem { delegate: ListItem {
id: otpListItem id: otpListItem
menu: otpContextMenu menu: otpContextMenu
width: otpList.width
contentHeight: Theme.itemSizeMedium contentHeight: Theme.itemSizeMedium
width: parent.width
function remove() { function remove() {
// Show 5s countdown, then delete from DB and List // Show 5s countdown, then delete from DB and List
@ -136,6 +138,26 @@ Page {
ListView.onRemove: animateRemoval() ListView.onRemove: animateRemoval()
Rectangle { Rectangle {
id: listRow
width: parent.width
anchors.horizontalCenter: parent.horizontalCenter
Switch {
checked: model.fav
anchors.left: parent.left
onClicked: {
if (checked) DB.setFav(title, secret)
refreshOTPList();
/*model.fav = checked ? 1 : 0;
for (var i=0; i<otpListModel.count; i++) {
if (i != index) {
otpListModel.setProperty(i, "fav", 0);
}
}*/
}
}
Column {
anchors.horizontalCenter: parent.horizontalCenter anchors.horizontalCenter: parent.horizontalCenter
Label { Label {
@ -147,11 +169,11 @@ Page {
Label { Label {
id: otpValue id: otpValue
anchors.top: otpLabel.bottom
text: model.otp text: model.otp
anchors.horizontalCenter: parent.horizontalCenter
color: Theme.highlightColor color: Theme.highlightColor
font.pixelSize: Theme.fontSizeLarge font.pixelSize: Theme.fontSizeLarge
anchors.horizontalCenter: parent.horizontalCenter
}
} }
} }