2019-12-01 22:27:00 +03:00
|
|
|
import QtQuick 2.0
|
|
|
|
import Sailfish.Silica 1.0
|
|
|
|
import "utils.js" as Utils
|
|
|
|
|
|
|
|
Page {
|
|
|
|
id: page
|
|
|
|
property var printer
|
|
|
|
property var jobParams: new Object();
|
|
|
|
property string selectedFile
|
|
|
|
|
|
|
|
Component.onCompleted: {
|
|
|
|
console.log(JSON.stringify(printer.attrs))
|
|
|
|
}
|
|
|
|
|
|
|
|
Connections {
|
|
|
|
target: printer
|
2019-12-17 22:18:57 +03:00
|
|
|
onJobAttrsFinished: {
|
|
|
|
var msg = printer.jobAttrs["job-state-message"] && printer.jobAttrs["job-state-message"].value != ""
|
2020-01-03 15:50:21 +03:00
|
|
|
? printer.jobAttrs["job-state-message"].value : Utils.ippName("job-state", printer.jobAttrs["job-state"].value)
|
2019-12-17 22:18:57 +03:00
|
|
|
if(status == true) {
|
|
|
|
notifier.notify(qsTr("Print success: ") + msg)
|
|
|
|
pageStack.pop() //or replace?
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
notifier.notify(qsTr("Print failed: ") + msg)
|
|
|
|
}
|
2019-12-01 22:27:00 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// To enable PullDownMenu, place our content in a SilicaFlickable
|
|
|
|
SilicaFlickable {
|
|
|
|
anchors.fill: parent
|
|
|
|
|
|
|
|
// PullDownMenu and PushUpMenu must be declared in SilicaFlickable, SilicaListView or SilicaGridView
|
|
|
|
PullDownMenu {
|
|
|
|
MenuItem {
|
|
|
|
text: qsTr("Print")
|
|
|
|
onClicked: {
|
|
|
|
console.log(JSON.stringify(jobParams))
|
|
|
|
printer.print(jobParams, page.selectedFile)
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ListModel {
|
|
|
|
id:mod
|
2019-12-07 12:36:36 +03:00
|
|
|
ListElement {name: "sides"; prettyName: qsTr("Sides"); tag: 0x23}
|
|
|
|
ListElement {name: "copies"; prettyName: qsTr("Copies"); tag: 0x21}
|
|
|
|
// ListElement {name: "page-ranges"; prettyName: qsTr("Page range"); tag: 0x33}
|
|
|
|
ListElement {name: "print-color-mode"; prettyName: qsTr("Color mode"); tag: 0x23}
|
|
|
|
// ListElement {name: "orientation-requested"; prettyName: qsTr("Orientation"); tag: 0x23}
|
|
|
|
ListElement {name: "print-quality"; prettyName: qsTr("Quality"); tag: 0x23}
|
|
|
|
ListElement {name: "printer-resolution"; prettyName: qsTr("Resolution"); tag: 0x32}
|
2019-12-01 22:27:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
SilicaListView {
|
|
|
|
id: listView
|
|
|
|
model: mod
|
|
|
|
clip: true
|
|
|
|
|
|
|
|
anchors.fill: parent
|
|
|
|
width: parent.width
|
|
|
|
header: PageHeader {
|
|
|
|
id: pageHeader
|
|
|
|
title: printer.attrs["printer-name"].value
|
|
|
|
description: selectedFile
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
delegate: ListItem {
|
|
|
|
id: delegate
|
|
|
|
property alias loaderItem: loader.item
|
|
|
|
|
|
|
|
openMenuOnPressAndHold: false
|
|
|
|
|
|
|
|
Loader {
|
|
|
|
id: loader
|
|
|
|
anchors.fill: parent
|
|
|
|
}
|
|
|
|
|
|
|
|
Component.onCompleted: {
|
2020-02-17 21:58:46 +03:00
|
|
|
console.log("handling", tag, name, prettyName, JSON.stringify(printer.attrs), JSON.stringify(printer.attrs[name+"-supported"]), JSON.stringify(printer.attrs[name+"-default"]))
|
2019-12-01 22:27:00 +03:00
|
|
|
switch(tag) {
|
|
|
|
case 0x21:
|
2019-12-17 23:10:05 +03:00
|
|
|
loader.setSource("../components/IntegerSetting.qml",
|
2019-12-01 22:27:00 +03:00
|
|
|
{name: name,
|
|
|
|
prettyName: prettyName,
|
|
|
|
tag: tag,
|
2020-02-17 21:58:46 +03:00
|
|
|
valid: printer.attrs.hasOwnProperty(name+"-supported"),
|
2019-12-01 22:27:00 +03:00
|
|
|
low: printer.attrs[name+"-supported"].value.low,
|
|
|
|
high: printer.attrs[name+"-supported"].value.high,
|
|
|
|
default_choice: printer.attrs[name+"-default"].value
|
|
|
|
})
|
|
|
|
break
|
|
|
|
case 0x33:
|
2019-12-17 23:10:05 +03:00
|
|
|
loader.setSource("../components/RangeSetting.qml",
|
2019-12-01 22:27:00 +03:00
|
|
|
{name: name,
|
|
|
|
prettyName: prettyName,
|
2020-02-17 21:58:46 +03:00
|
|
|
tag: tag,
|
|
|
|
valid: false //TODO printer.attrs.hasOwnProperty(name+"-supported"),
|
2019-12-01 22:27:00 +03:00
|
|
|
})
|
|
|
|
break
|
|
|
|
case 0x32:
|
|
|
|
case 0x23:
|
2019-12-17 23:10:05 +03:00
|
|
|
loader.setSource("../components/ChoiceSetting.qml",
|
2019-12-01 22:27:00 +03:00
|
|
|
{name: name,
|
|
|
|
prettyName: prettyName,
|
|
|
|
tag: tag,
|
2020-02-17 21:58:46 +03:00
|
|
|
valid: printer.attrs.hasOwnProperty(name+"-supported"),
|
2019-12-01 22:27:00 +03:00
|
|
|
choices: printer.attrs[name+"-supported"].value,
|
|
|
|
default_choice: printer.attrs[name+"-default"].value
|
|
|
|
})
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
onLoaderItemChanged: {
|
|
|
|
menu = loaderItem.menu
|
|
|
|
loaderItem.clicked.connect(function() {
|
|
|
|
openMenu()
|
|
|
|
})
|
|
|
|
loaderItem.choiceMade.connect(function(tag, choice) {
|
|
|
|
console.log("choice changed", tag, JSON.stringify(choice))
|
|
|
|
jobParams[name] = {tag: tag, value: choice};
|
|
|
|
console.log(JSON.stringify(jobParams));
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
VerticalScrollDecorator {}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|