Improve SSID handling

This commit is contained in:
Anton Thomasson 2019-12-02 20:23:44 +01:00
parent 662babf5db
commit 7c54a90fbb
6 changed files with 128 additions and 68 deletions

View file

@ -0,0 +1,77 @@
import QtQuick 2.0
import Sailfish.Silica 1.0
import seaprint.ippprinter 1.0
Dialog {
id: dialog
property string value
property string ssid
canAccept: printer_label.text != ""
Column {
width: parent.width
DialogHeader {
title: qsTr("Add printer")
}
TextField {
id: valueField
width: parent.width
placeholderText: "192.168.1.1/ipp/print"
label: title
}
Row {
x: Theme.paddingLarge
spacing: Theme.paddingMedium
Label {
id: wifi_label
text: qsTr("On WiFI:")
}
Label {
id: ssid_label
color: Theme.secondaryColor
text: ssid
}
}
Row {
x: Theme.paddingLarge
spacing: Theme.paddingMedium
Label {
id: found_label
text: printer_label.text != "" ? qsTr("Found:") : qsTr("No printer found")
}
Label {
id: printer_label
color: Theme.secondaryColor
text: ""
}
}
IppPrinter {
id: printer
url: valueField.text
onAttrsChanged: {
if(printer.attrs["printer-name"]) {
printer_label.text = printer.attrs["printer-name"].value
}
else
{
printer_label.text = ""
}
}
}
}
onDone: {
if (result == DialogResult.Accepted) {
value = valueField.text
}
}
}

View file

@ -40,6 +40,11 @@ Page {
signalsEnabled: true signalsEnabled: true
function servicesChanged() {
console.log("services changed");
go();
}
function go() { function go() {
call("GetServices", undefined, call("GetServices", undefined,
function(result) { function(result) {
@ -73,12 +78,14 @@ Page {
PullDownMenu { PullDownMenu {
MenuItem { MenuItem {
text: qsTr("Add by URL") text: qsTr("Add by URL")
onClicked: {var dialog = pageStack.push(Qt.resolvedUrl("InputDialog.qml"), enabled: currentSSID != ""
{value: qsTr("Add favourite"), title: qsTr("URL")}); onClicked: {
dialog.accepted.connect(function() { var dialog = pageStack.push(Qt.resolvedUrl("AddPrinterDialog.qml"),
db.addFavourite(page.currentSSID, dialog.value); {ssid: currentSSID, title: qsTr("URL")});
discovery.favourites = db.getFavourites(page.currentSSID); dialog.accepted.connect(function() {
}) db.addFavourite(page.currentSSID, dialog.value);
discovery.favourites = db.getFavourites(page.currentSSID);
})
} }
} }
MenuItem { MenuItem {

View file

@ -1,52 +0,0 @@
import QtQuick 2.0
import Sailfish.Silica 1.0
import seaprint.ippprinter 1.0
Dialog {
id: dialog
property string value
property string title
canAccept: label.text != label._default
Column {
width: parent.width
DialogHeader { }
TextField {
id: valueField
width: parent.width
placeholderText: "192.168.1.1/ipp/print"
label: title
}
Label {
id: label
x: Theme.paddingLarge
property string _default: "No printer found"
text: _default
}
IppPrinter {
id: printer
url: valueField.text
onAttrsChanged: {
if(printer.attrs["printer-name"]) {
label.text = "Found: "+printer.attrs["printer-name"].value
}
else
{
label.text = label._default
}
}
}
}
onDone: {
if (result == DialogResult.Accepted) {
value = valueField.text
}
}
}

View file

@ -43,7 +43,6 @@ Page {
ListElement {name: "print-color-mode"; prettyName: "Color mode"; tag: 0x23} ListElement {name: "print-color-mode"; prettyName: "Color mode"; tag: 0x23}
// ListElement {name: "orientation-requested"; prettyName: "Orientation"; tag: 0x23} // ListElement {name: "orientation-requested"; prettyName: "Orientation"; tag: 0x23}
ListElement {name: "print-quality"; prettyName: "Quality"; tag: 0x23} ListElement {name: "print-quality"; prettyName: "Quality"; tag: 0x23}
// Bleh, can't create the json object with another object as value, for whatever reason
ListElement {name: "printer-resolution"; prettyName: "Resolution"; tag: 0x32} ListElement {name: "printer-resolution"; prettyName: "Resolution"; tag: 0x32}
} }
@ -72,7 +71,6 @@ Page {
Loader { Loader {
id: loader id: loader
anchors.fill: parent anchors.fill: parent
property var menu
} }
Component.onCompleted: { Component.onCompleted: {

View file

@ -1,6 +1,25 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE TS> <!DOCTYPE TS>
<TS version="2.1"> <TS version="2.1">
<context>
<name>AddPrinterDialog</name>
<message>
<source>Add printer</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>On WiFI:</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Found:</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>No printer found</source>
<translation type="unfinished"></translation>
</message>
</context>
<context> <context>
<name>CoverPage</name> <name>CoverPage</name>
<message> <message>
@ -14,10 +33,6 @@
<source>Add by URL</source> <source>Add by URL</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message>
<source>Add favourite</source>
<translation type="unfinished"></translation>
</message>
<message> <message>
<source>URL</source> <source>URL</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>

View file

@ -1,6 +1,25 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE TS> <!DOCTYPE TS>
<TS version="2.1"> <TS version="2.1">
<context>
<name>AddPrinterDialog</name>
<message>
<source>Add printer</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>On WiFI:</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Found:</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>No printer found</source>
<translation type="unfinished"></translation>
</message>
</context>
<context> <context>
<name>CoverPage</name> <name>CoverPage</name>
<message> <message>
@ -14,10 +33,6 @@
<source>Add by URL</source> <source>Add by URL</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message>
<source>Add favourite</source>
<translation type="unfinished"></translation>
</message>
<message> <message>
<source>URL</source> <source>URL</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>