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) {
|
function addFavourite(ssid, url) {
|
||||||
db_conn.transaction(function (tx) {
|
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 = [];
|
var favs = [];
|
||||||
db_conn.transaction(function (tx) {
|
db_conn.transaction(function (tx) {
|
||||||
var res = tx.executeSql('SELECT * FROM Favourites WHERE ssid=?', [ssid]);
|
var res = tx.executeSql('SELECT * FROM Favourites WHERE ssid=?', [ssid]);
|
||||||
if (res.rows.length !== 0) {
|
for (var i = 0; i < res.rows.length; i++) {
|
||||||
console.log(res.rows.item(0).url)
|
console.log(res.rows.item(i).url)
|
||||||
favs.push(res.rows.item(0).url);
|
favs.push(res.rows.item(i).url);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
console.log(ssid, favs);
|
console.log(ssid, favs);
|
||||||
return 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 {
|
Notification {
|
||||||
|
|
|
@ -49,6 +49,7 @@ Page {
|
||||||
var dialog = pageStack.push(Qt.resolvedUrl("AddPrinterDialog.qml"),
|
var dialog = pageStack.push(Qt.resolvedUrl("AddPrinterDialog.qml"),
|
||||||
{ssid: wifi.ssid, title: qsTr("URL")});
|
{ssid: wifi.ssid, title: qsTr("URL")});
|
||||||
dialog.accepted.connect(function() {
|
dialog.accepted.connect(function() {
|
||||||
|
console.log("add", wifi.ssid, dialog.value);
|
||||||
db.addFavourite(wifi.ssid, dialog.value);
|
db.addFavourite(wifi.ssid, dialog.value);
|
||||||
discovery.favourites = db.getFavourites(wifi.ssid);
|
discovery.favourites = db.getFavourites(wifi.ssid);
|
||||||
})
|
})
|
||||||
|
@ -73,8 +74,13 @@ Page {
|
||||||
id: delegate
|
id: delegate
|
||||||
contentItem.height: visible ? Math.max(column.implicitHeight, Theme.itemSizeLarge+2*Theme.paddingMedium) : 0
|
contentItem.height: visible ? Math.max(column.implicitHeight, Theme.itemSizeLarge+2*Theme.paddingMedium) : 0
|
||||||
visible: printer.attrs["printer-name"] ? true : false
|
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: {
|
onClicked: {
|
||||||
|
if(!canPrint)
|
||||||
|
return;
|
||||||
if(selectedFile != "")
|
if(selectedFile != "")
|
||||||
{
|
{
|
||||||
pageStack.push(Qt.resolvedUrl("PrinterPage.qml"), {printer: printer, selectedFile: selectedFile})
|
pageStack.push(Qt.resolvedUrl("PrinterPage.qml"), {printer: printer, selectedFile: selectedFile})
|
||||||
|
@ -111,27 +117,27 @@ Page {
|
||||||
|
|
||||||
Label {
|
Label {
|
||||||
id: name_label
|
id: name_label
|
||||||
color: delegate.enabled ? Theme.primaryColor : Theme.secondaryColor
|
color: canPrint ? Theme.primaryColor : Theme.secondaryColor
|
||||||
text: printer.attrs["printer-name"].value
|
text: name
|
||||||
}
|
}
|
||||||
|
|
||||||
Label {
|
Label {
|
||||||
id: mm_label
|
id: mm_label
|
||||||
color: delegate.enabled ? Theme.primaryColor : Theme.secondaryColor
|
color: canPrint ? Theme.primaryColor : Theme.secondaryColor
|
||||||
font.pixelSize: Theme.fontSizeExtraSmall
|
font.pixelSize: Theme.fontSizeExtraSmall
|
||||||
text: printer.attrs["printer-make-and-model"].value
|
text: printer.attrs["printer-make-and-model"].value
|
||||||
}
|
}
|
||||||
|
|
||||||
Label {
|
Label {
|
||||||
id: uri_label
|
id: uri_label
|
||||||
color: Theme.secondaryColor
|
color: canPrint ? Theme.highlightColor : Theme.secondaryColor
|
||||||
font.pixelSize: Theme.fontSizeTiny
|
font.pixelSize: Theme.fontSizeTiny
|
||||||
text: model.display
|
text: model.display
|
||||||
}
|
}
|
||||||
|
|
||||||
Label {
|
Label {
|
||||||
id: format_label
|
id: format_label
|
||||||
color: delegate.enabled ? Theme.primaryColor : "red"
|
color: canPrint ? Theme.primaryColor : "red"
|
||||||
font.pixelSize: Theme.fontSizeExtraSmall
|
font.pixelSize: Theme.fontSizeExtraSmall
|
||||||
text: Utils.supported_formats(printer)
|
text: Utils.supported_formats(printer)
|
||||||
}
|
}
|
||||||
|
@ -142,6 +148,14 @@ Page {
|
||||||
text: qsTr("View jobs")
|
text: qsTr("View jobs")
|
||||||
onClicked: pageStack.push(Qt.resolvedUrl("JobsPage.qml"), {printer: printer})
|
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>
|
<source>View jobs</source>
|
||||||
<translation type="unfinished"></translation>
|
<translation type="unfinished"></translation>
|
||||||
</message>
|
</message>
|
||||||
|
<message>
|
||||||
|
<source>Remove printer</source>
|
||||||
|
<translation type="unfinished"></translation>
|
||||||
|
</message>
|
||||||
</context>
|
</context>
|
||||||
<context>
|
<context>
|
||||||
<name>JobsPage</name>
|
<name>JobsPage</name>
|
||||||
|
|
|
@ -104,6 +104,10 @@
|
||||||
<source>View jobs</source>
|
<source>View jobs</source>
|
||||||
<translation type="unfinished"></translation>
|
<translation type="unfinished"></translation>
|
||||||
</message>
|
</message>
|
||||||
|
<message>
|
||||||
|
<source>Remove printer</source>
|
||||||
|
<translation type="unfinished"></translation>
|
||||||
|
</message>
|
||||||
</context>
|
</context>
|
||||||
<context>
|
<context>
|
||||||
<name>JobsPage</name>
|
<name>JobsPage</name>
|
||||||
|
|
Loading…
Reference in a new issue