From 41bd50a3cea6690240e83272ea60b64de8d6dcde Mon Sep 17 00:00:00 2001 From: Anton Thomasson Date: Fri, 13 Dec 2019 19:14:50 +0100 Subject: [PATCH] Fix favourites handling --- qml/harbour-seaprint.qml | 25 +++++++++++++++++++++---- qml/pages/FirstPage.qml | 26 ++++++++++++++++++++------ translations/harbour-seaprint-de.ts | 4 ++++ translations/harbour-seaprint.ts | 4 ++++ 4 files changed, 49 insertions(+), 10 deletions(-) diff --git a/qml/harbour-seaprint.qml b/qml/harbour-seaprint.qml index 667e220..2b6acc8 100644 --- a/qml/harbour-seaprint.qml +++ b/qml/harbour-seaprint.qml @@ -24,7 +24,7 @@ ApplicationWindow function addFavourite(ssid, url) { db_conn.transaction(function (tx) { - tx.executeSql('INSERT INTO Favourites VALUES(?, ?)', [ssid, url] ); + tx.executeSql('REPLACE INTO Favourites VALUES(?, ?)', [ssid, url] ); }); } @@ -32,14 +32,31 @@ ApplicationWindow var favs = []; db_conn.transaction(function (tx) { var res = tx.executeSql('SELECT * FROM Favourites WHERE ssid=?', [ssid]); - if (res.rows.length !== 0) { - console.log(res.rows.item(0).url) - favs.push(res.rows.item(0).url); + for (var i = 0; i < res.rows.length; i++) { + console.log(res.rows.item(i).url) + favs.push(res.rows.item(i).url); } }); console.log(ssid, favs); return favs } + + function isFavourite(ssid, url) { + var isfav = false; + db_conn.transaction(function (tx) { + var res = tx.executeSql('SELECT * FROM Favourites WHERE ssid=? AND url=?', [ssid, url]); + if (res.rows.length > 0) { + isfav = true; + } + }); + return isfav + } + + function removeFavourite(ssid, url) { + db_conn.transaction(function (tx) { + tx.executeSql('DELETE FROM Favourites WHERE ssid=? AND url=?', [ssid, url] ); + }); + } } Notification { diff --git a/qml/pages/FirstPage.qml b/qml/pages/FirstPage.qml index d1a00d4..cfc308b 100644 --- a/qml/pages/FirstPage.qml +++ b/qml/pages/FirstPage.qml @@ -49,6 +49,7 @@ Page { var dialog = pageStack.push(Qt.resolvedUrl("AddPrinterDialog.qml"), {ssid: wifi.ssid, title: qsTr("URL")}); dialog.accepted.connect(function() { + console.log("add", wifi.ssid, dialog.value); db.addFavourite(wifi.ssid, dialog.value); discovery.favourites = db.getFavourites(wifi.ssid); }) @@ -73,8 +74,13 @@ Page { id: delegate contentItem.height: visible ? Math.max(column.implicitHeight, Theme.itemSizeLarge+2*Theme.paddingMedium) : 0 visible: printer.attrs["printer-name"] ? true : false - enabled: Utils.can_print(printer, selectedFile) + + property string name: printer.attrs["printer-name"].value + property bool canPrint: Utils.can_print(printer, selectedFile) + onClicked: { + if(!canPrint) + return; if(selectedFile != "") { pageStack.push(Qt.resolvedUrl("PrinterPage.qml"), {printer: printer, selectedFile: selectedFile}) @@ -111,27 +117,27 @@ Page { Label { id: name_label - color: delegate.enabled ? Theme.primaryColor : Theme.secondaryColor - text: printer.attrs["printer-name"].value + color: canPrint ? Theme.primaryColor : Theme.secondaryColor + text: name } Label { id: mm_label - color: delegate.enabled ? Theme.primaryColor : Theme.secondaryColor + color: canPrint ? Theme.primaryColor : Theme.secondaryColor font.pixelSize: Theme.fontSizeExtraSmall text: printer.attrs["printer-make-and-model"].value } Label { id: uri_label - color: Theme.secondaryColor + color: canPrint ? Theme.highlightColor : Theme.secondaryColor font.pixelSize: Theme.fontSizeTiny text: model.display } Label { id: format_label - color: delegate.enabled ? Theme.primaryColor : "red" + color: canPrint ? Theme.primaryColor : "red" font.pixelSize: Theme.fontSizeExtraSmall text: Utils.supported_formats(printer) } @@ -142,6 +148,14 @@ Page { text: qsTr("View jobs") onClicked: pageStack.push(Qt.resolvedUrl("JobsPage.qml"), {printer: printer}) } + MenuItem { + text: qsTr("Remove printer") + visible: db.isFavourite(wifi.ssid, model.display) + onClicked: { + db.removeFavourite(wifi.ssid, model.display) + discovery.favourites = db.getFavourites() + } + } } } diff --git a/translations/harbour-seaprint-de.ts b/translations/harbour-seaprint-de.ts index 4c9b7b6..020699a 100644 --- a/translations/harbour-seaprint-de.ts +++ b/translations/harbour-seaprint-de.ts @@ -104,6 +104,10 @@ View jobs + + Remove printer + + JobsPage diff --git a/translations/harbour-seaprint.ts b/translations/harbour-seaprint.ts index cfc3df2..67f7f19 100644 --- a/translations/harbour-seaprint.ts +++ b/translations/harbour-seaprint.ts @@ -104,6 +104,10 @@ View jobs + + Remove printer + + JobsPage