harbour-seaprint/qml/pages/AddPrinterDialog.qml

172 lines
4.4 KiB
QML
Raw Normal View History

2019-12-02 22:23:44 +03:00
import QtQuick 2.0
import Sailfish.Silica 1.0
import seaprint.ippprinter 1.0
import "utils.js" as Utils
2019-12-02 22:23:44 +03:00
Dialog {
id: dialog
2020-08-06 18:34:14 +03:00
allowedOrientations: Orientation.All
2019-12-02 22:23:44 +03:00
property string value
property string ssid
2020-01-03 00:10:58 +03:00
property var printerName: false
canAccept: Object.keys(printer.attrs).length != 0
2019-12-02 22:23:44 +03:00
2021-02-15 20:03:35 +03:00
Connections {
target: wifi
onConnectedChanged: {
if(!wifi.connected) {
dialog.reject()
}
}
}
2021-02-15 19:57:52 +03:00
Component.onCompleted: {
valueField.forceActiveFocus()
}
IppPrinter {
id: printer
url: valueField.text
onAttrsChanged: {
if(printer.attrs.hasOwnProperty("printer-name")) {
printerName = Utils.unknownForEmptyString(printer.attrs["printer-name"].value)
2021-02-15 19:57:52 +03:00
}
else
{
printerName = qsTr("Unknown")
2021-02-15 19:57:52 +03:00
}
}
}
2019-12-02 22:23:44 +03:00
Column {
2021-02-15 19:57:52 +03:00
id: col
2019-12-02 22:23:44 +03:00
width: parent.width
DialogHeader {
title: qsTr("Add printer")
}
TextField {
id: valueField
width: parent.width
placeholderText: "192.168.1.1/ipp/print"
2021-06-28 21:14:09 +03:00
inputMethodHints: Qt.ImhUrlCharactersOnly | Qt.ImhNoAutoUppercase
2019-12-02 22:23:44 +03:00
label: title
}
Row {
x: Theme.paddingLarge
spacing: Theme.paddingMedium
Label {
id: wifi_label
2020-09-21 23:09:12 +03:00
text: qsTr("On WiFi:")
2019-12-02 22:23:44 +03:00
}
Label {
id: ssid_label
color: Theme.secondaryColor
2021-02-15 20:03:35 +03:00
text: wifi.ssid
2019-12-02 22:23:44 +03:00
}
}
Row {
x: Theme.paddingLarge
spacing: Theme.paddingMedium
Label {
id: found_label
text: canAccept ? qsTr("Found:") : qsTr("No printer found")
2019-12-02 22:23:44 +03:00
}
Label {
id: printer_label
color: Theme.secondaryColor
text: canAccept ? printerName : ""
2019-12-02 22:23:44 +03:00
}
}
2021-06-28 21:15:21 +03:00
Item {
width: 1
height: 2*Theme.paddingLarge
}
Row {
visible: valueField.text.indexOf(":9100") != -1
x: Theme.paddingLarge
width: parent.width-2*Theme.paddingLarge
spacing: Theme.paddingMedium
Icon {
id: warningIcon
source: "image://theme/icon-m-warning"
anchors.verticalCenter: parent.verticalCenter
}
Label {
width: parent.width-warningIcon.width-Theme.paddingMedium
anchors.verticalCenter: parent.verticalCenter
color: Theme.highlightColor
wrapMode: Text.WordWrap
text: qsTr("Port 9100 is not used for IPP.")
}
}
Row {
id: suffixWarning
visible: canAccept && !printer.correctSuffix
x: Theme.paddingLarge
width: parent.width-2*Theme.paddingLarge
spacing: Theme.paddingMedium
2021-02-15 19:57:52 +03:00
2021-06-28 21:15:21 +03:00
Icon {
id: warningIcon2
source: "image://theme/icon-m-warning"
anchors.verticalCenter: parent.verticalCenter
}
2021-02-15 19:57:52 +03:00
2021-06-28 21:15:21 +03:00
Label {
width: parent.width-warningIcon2.width-Theme.paddingMedium
anchors.verticalCenter: parent.verticalCenter
color: Theme.highlightColor
wrapMode: Text.WordWrap
text: qsTr("The uri suffix is not in the printer's supported list.")+" "+
qsTr("It might not accept print jobs on this address.")+" "+
qsTr("Consider using a suffix like \"/ipp/print\".")
}
2019-12-02 22:23:44 +03:00
}
2021-06-28 21:15:21 +03:00
Item {
width: 1
height: 2*Theme.paddingLarge
2021-02-15 19:57:52 +03:00
}
2021-06-28 21:15:21 +03:00
Label
{
x: Theme.paddingLarge
visible: suffixWarning.visible && printer.suffixes.length != 0
text: qsTr("The printer/server lists these suffixes:")
}
Repeater
{
model: suffixWarning.visible ? printer.suffixes : 0
Label
{
x: Theme.paddingLarge
text: printer.suffixes[index]
}
}
2019-12-02 22:23:44 +03:00
}
onDone: {
if (result == DialogResult.Accepted) {
value = valueField.text
2021-02-15 20:03:35 +03:00
ssid = wifi.ssid
2019-12-02 22:23:44 +03:00
}
}
}