harbour-seaprint/qml/pages/PrinterPage.qml

249 lines
8.8 KiB
QML
Raw Normal View History

2021-03-21 00:45:58 +03:00
import QtQuick 2.6
2019-12-01 22:27:00 +03:00
import Sailfish.Silica 1.0
2020-06-04 22:31:46 +03:00
import seaprint.mimer 1.0
2020-06-06 18:20:30 +03:00
import seaprint.ippmsg 1.0
2020-08-01 21:18:47 +03:00
import seaprint.convertchecker 1.0
2019-12-01 22:27:00 +03:00
import "utils.js" as Utils
import "../components"
2019-12-01 22:27:00 +03:00
Page {
2020-08-06 18:34:14 +03:00
allowedOrientations: Orientation.All
2019-12-01 22:27:00 +03:00
id: page
property var printer
2021-03-21 00:45:58 +03:00
property var jobParams
2019-12-01 22:27:00 +03:00
property string selectedFile
2021-03-06 19:20:51 +03:00
property string selectedFileType: Mimer.get_type(selectedFile)
2019-12-01 22:27:00 +03:00
2021-02-14 16:38:35 +03:00
Connections {
target: wifi
onConnectedChanged: {
if(!wifi.connected) {
pageStack.pop()
}
}
2019-12-01 22:27:00 +03:00
}
2021-03-20 21:45:06 +03:00
function choiceMade(setting)
2020-11-23 21:55:52 +03:00
{
2021-03-20 21:45:06 +03:00
if(setting.choice != undefined)
2020-11-23 21:55:52 +03:00
{
2021-03-20 21:45:06 +03:00
jobParams[setting.name] = {tag: setting.tag, value: setting.choice};
2020-11-23 21:55:52 +03:00
}
else
{
2021-03-20 21:45:06 +03:00
jobParams[setting.name] = undefined;
2020-11-23 21:55:52 +03:00
}
console.log(JSON.stringify(jobParams));
}
2019-12-01 22:27:00 +03:00
// To enable PullDownMenu, place our content in a SilicaFlickable
SilicaFlickable {
anchors.fill: parent
2020-11-23 20:57:42 +03:00
contentHeight: settingColumn.height
// PullDownMenu and PushUpMenu must be declared in SilicaFlickable, SilicaListView or SilicaGridView
PullDownMenu {
2021-03-21 00:45:58 +03:00
2021-03-21 14:49:54 +03:00
MenuLabel {
text: qsTr("Default settings for %1 on this printer").arg(db.simplifyType(selectedFileType).translatable)
visible: printer.attrs.hasOwnProperty("printer-uuid")
}
2021-03-21 00:45:58 +03:00
MenuItem {
text: qsTr("Clear default settings")
visible: printer.attrs.hasOwnProperty("printer-uuid")
onClicked: {
2021-03-21 14:49:54 +03:00
db.removeJobSettings(printer.attrs["printer-uuid"].value, selectedFileType);
2021-03-21 00:45:58 +03:00
pageStack.pop();
}
}
MenuItem {
text: qsTr("Save default settings")
visible: printer.attrs.hasOwnProperty("printer-uuid")
onClicked: {
var tmp = jobParams;
2021-03-21 14:49:54 +03:00
// Support varies between formats and values varies between documents, would be confusing to save
2021-03-21 00:45:58 +03:00
tmp["page-ranges"] = undefined;
2021-03-21 14:49:54 +03:00
db.setJobSettings(printer.attrs["printer-uuid"].value, selectedFileType, JSON.stringify(tmp))
2021-03-21 00:45:58 +03:00
}
}
MenuItem {
text: qsTr("Print")
onClicked: {
console.log(JSON.stringify(jobParams))
pageStack.replace(Qt.resolvedUrl("BusyPage.qml"),{printer:printer},
PageStackAction.Immediate)
printer.print(jobParams, page.selectedFile,
alwaysConvertSetting.value,
alwaysUseMediaColSetting.value)
2019-12-01 22:27:00 +03:00
}
}
}
VerticalScrollDecorator {}
2019-12-01 22:27:00 +03:00
Column {
id: settingColumn
2019-12-01 22:27:00 +03:00
width: parent.width
PageHeader {
2019-12-01 22:27:00 +03:00
id: pageHeader
title: printer.attrs["printer-name"].value
description: Utils.basename(selectedFile)
2019-12-01 22:27:00 +03:00
}
Item {
id: utils
2019-12-01 22:27:00 +03:00
function isValid(name) {
return printer.attrs.hasOwnProperty(name+"-supported");
2019-12-01 22:27:00 +03:00
}
2021-03-21 00:45:58 +03:00
function getInitialChoice(name) {
return jobParams.hasOwnProperty(name) ? jobParams[name].value : undefined
}
function getChoices(name) {
return isValid(name) ? printer.attrs[name+"-supported"].value : [];
2019-12-01 22:27:00 +03:00
}
function getDefaultChoice(name) {
2020-11-24 20:13:03 +03:00
return printer.attrs.hasOwnProperty(name+"-default") ? printer.attrs[name+"-default"].value : undefined;
}
}
2019-12-01 22:27:00 +03:00
ChoiceSetting {
tag: IppMsg.Keyword
name: "sides"
prettyName: qsTr("Sides")
valid: utils.isValid(name)
2021-03-21 00:45:58 +03:00
choice: utils.getInitialChoice(name)
choices: utils.getChoices(name)
default_choice: utils.getDefaultChoice(name)
2021-03-06 19:20:51 +03:00
mime_type: selectedFileType
2020-11-23 21:55:52 +03:00
2021-03-20 21:45:06 +03:00
onChoiceChanged: page.choiceMade(this)
}
ChoiceSetting {
tag: IppMsg.Keyword
name: "media"
prettyName: qsTr("Print media")
valid: utils.isValid(name)
2021-03-21 00:45:58 +03:00
choice: utils.getInitialChoice(name)
choices: utils.getChoices(name)
default_choice: utils.getDefaultChoice(name)
2021-03-06 19:20:51 +03:00
mime_type: selectedFileType
2020-11-23 21:55:52 +03:00
2021-03-20 21:45:06 +03:00
onChoiceChanged: page.choiceMade(this)
}
IntegerSetting {
tag: IppMsg.Integer
name: "copies"
prettyName: qsTr("Copies")
valid: utils.isValid(name)
2021-03-21 00:45:58 +03:00
choice: utils.getInitialChoice(name)
low: valid ? printer.attrs[name+"-supported"].value.low : 0
high: valid ? printer.attrs[name+"-supported"].value.high : 0
2020-11-24 20:13:03 +03:00
default_choice: utils.getDefaultChoice(name)
2020-11-23 21:55:52 +03:00
2021-03-20 21:45:06 +03:00
onChoiceChanged: page.choiceMade(this)
}
ChoiceSetting {
tag: IppMsg.Keyword
name: "multiple-document-handling"
prettyName: qsTr("Collated copies")
valid: utils.isValid(name)
2021-03-21 00:45:58 +03:00
choice: utils.getInitialChoice(name)
choices: utils.getChoices(name)
default_choice: utils.getDefaultChoice(name)
2021-03-06 19:20:51 +03:00
mime_type: selectedFileType
2020-11-23 21:55:52 +03:00
2021-03-20 21:45:06 +03:00
onChoiceChanged: page.choiceMade(this)
}
RangeSetting {
tag: IppMsg.IntegerRange
name: "page-ranges"
prettyName: qsTr("Page range")
2021-03-06 19:20:51 +03:00
valid: (utils.isValid(name) || ConvertChecker.pdf) &&
(selectedFileType == "application/pdf" || Mimer.isOffice(selectedFileType))
2021-03-21 00:45:58 +03:00
choice: utils.getInitialChoice(name)
property var pdfpages: ConvertChecker.pdfPages(selectedFile)
2021-03-21 00:45:58 +03:00
high: pdfpages == 0 ? 65535 : pdfpages
2020-11-23 21:55:52 +03:00
2021-03-20 21:45:06 +03:00
onChoiceChanged: page.choiceMade(this)
}
ChoiceSetting {
tag: IppMsg.Keyword
name: "print-color-mode"
prettyName: qsTr("Color mode")
valid: utils.isValid(name)
2021-03-21 00:45:58 +03:00
choice: utils.getInitialChoice(name)
choices: utils.getChoices(name)
default_choice: utils.getDefaultChoice(name)
2021-03-06 19:20:51 +03:00
mime_type: selectedFileType
2020-11-23 21:55:52 +03:00
2021-03-20 21:45:06 +03:00
onChoiceChanged: page.choiceMade(this)
}
ChoiceSetting {
tag: IppMsg.Enum
name: "print-quality"
prettyName: qsTr("Quality")
2021-03-21 00:45:58 +03:00
choice: utils.getInitialChoice(name)
valid: utils.isValid(name)
choices: utils.getChoices(name)
default_choice: utils.getDefaultChoice(name)
2021-03-06 19:20:51 +03:00
mime_type: selectedFileType
2020-11-23 21:55:52 +03:00
2021-03-20 21:45:06 +03:00
onChoiceChanged: page.choiceMade(this)
}
ChoiceSetting {
tag: IppMsg.Resolution
name: "printer-resolution"
prettyName: qsTr("Resolution")
valid: utils.isValid(name)
2021-03-21 00:45:58 +03:00
choice: utils.getInitialChoice(name)
choices: utils.getChoices(name)
default_choice: utils.getDefaultChoice(name)
2021-03-06 19:20:51 +03:00
mime_type: selectedFileType
2020-11-23 21:55:52 +03:00
2021-03-20 21:45:06 +03:00
onChoiceChanged: page.choiceMade(this)
}
ChoiceSetting {
tag: IppMsg.MimeMediaType
name: "document-format"
prettyName: qsTr("Transfer format")
valid: utils.isValid(name)
2021-03-21 00:45:58 +03:00
choice: utils.getInitialChoice(name)
choices: utils.getChoices(name)
default_choice: utils.getDefaultChoice(name)
2021-03-06 19:20:51 +03:00
mime_type: selectedFileType
2020-11-23 21:55:52 +03:00
2021-03-20 21:45:06 +03:00
onChoiceChanged: page.choiceMade(this)
}
ChoiceSetting {
tag: IppMsg.Keyword
name: "media-source"
prettyName: qsTr("Media source")
valid: utils.isValid(name)
2021-03-21 00:45:58 +03:00
choice: utils.getInitialChoice(name)
choices: utils.getChoices(name)
default_choice: utils.getDefaultChoice(name)
2021-03-06 19:20:51 +03:00
mime_type: selectedFileType
2020-11-23 21:55:52 +03:00
2021-03-20 21:45:06 +03:00
onChoiceChanged: page.choiceMade(this)
}
MediaColSetting {
tag: IppMsg.BeginCollection
name: "media-col"
prettyName: qsTr("Zero margins")
valid: false
2021-03-21 00:45:58 +03:00
choice: utils.getInitialChoice(name)
printer: page.printer
2020-11-23 21:55:52 +03:00
2021-03-20 21:45:06 +03:00
onChoiceChanged: page.choiceMade(this)
2019-12-01 22:27:00 +03:00
}
}
}
}