Fix favourites handling
This commit is contained in:
parent
bad67372cc
commit
41bd50a3ce
4 changed files with 49 additions and 10 deletions
|
@ -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 {
|
||||
|
|
|
@ -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()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -104,6 +104,10 @@
|
|||
<source>View jobs</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Remove printer</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>JobsPage</name>
|
||||
|
|
|
@ -104,6 +104,10 @@
|
|||
<source>View jobs</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Remove printer</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>JobsPage</name>
|
||||
|
|
Loading…
Reference in a new issue