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
function servicesChanged() {
console.log("services changed");
go();
}
function go() {
call("GetServices", undefined,
function(result) {
@ -73,12 +78,14 @@ Page {
PullDownMenu {
MenuItem {
text: qsTr("Add by URL")
onClicked: {var dialog = pageStack.push(Qt.resolvedUrl("InputDialog.qml"),
{value: qsTr("Add favourite"), title: qsTr("URL")});
dialog.accepted.connect(function() {
db.addFavourite(page.currentSSID, dialog.value);
discovery.favourites = db.getFavourites(page.currentSSID);
})
enabled: currentSSID != ""
onClicked: {
var dialog = pageStack.push(Qt.resolvedUrl("AddPrinterDialog.qml"),
{ssid: currentSSID, title: qsTr("URL")});
dialog.accepted.connect(function() {
db.addFavourite(page.currentSSID, dialog.value);
discovery.favourites = db.getFavourites(page.currentSSID);
})
}
}
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: "orientation-requested"; prettyName: "Orientation"; 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}
}
@ -72,7 +71,6 @@ Page {
Loader {
id: loader
anchors.fill: parent
property var menu
}
Component.onCompleted: {

View file

@ -1,6 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE TS>
<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>
<name>CoverPage</name>
<message>
@ -14,10 +33,6 @@
<source>Add by URL</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Add favourite</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>URL</source>
<translation type="unfinished"></translation>

View file

@ -1,6 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE TS>
<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>
<name>CoverPage</name>
<message>
@ -14,10 +33,6 @@
<source>Add by URL</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Add favourite</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>URL</source>
<translation type="unfinished"></translation>