De-duplicate some settings code
This commit is contained in:
parent
8fad10a2d1
commit
0fe054b3db
7 changed files with 73 additions and 127 deletions
|
@ -48,6 +48,7 @@ DISTFILES += qml/harbour-seaprint.qml \
|
||||||
qml/components/CylinderGraph.qml \
|
qml/components/CylinderGraph.qml \
|
||||||
qml/components/DocumentFilter.notqml \
|
qml/components/DocumentFilter.notqml \
|
||||||
qml/components/LargeChoiceDialog.qml \
|
qml/components/LargeChoiceDialog.qml \
|
||||||
|
qml/components/SettingsColumn.qml \
|
||||||
qml/components/SupplyItem.qml \
|
qml/components/SupplyItem.qml \
|
||||||
qml/cover/CoverPage.qml \
|
qml/cover/CoverPage.qml \
|
||||||
qml/components/*.qml \
|
qml/components/*.qml \
|
||||||
|
|
|
@ -5,7 +5,7 @@ import seaprint.mimer 1.0
|
||||||
import "../pages/utils.js" as Utils
|
import "../pages/utils.js" as Utils
|
||||||
|
|
||||||
Setting {
|
Setting {
|
||||||
property var choices
|
property var choices: parent.getChoices(name)
|
||||||
property string mime_type
|
property string mime_type
|
||||||
|
|
||||||
property var limited_choices: Utils.limitChoices(name, choices, mime_type, ConvertChecker)
|
property var limited_choices: Utils.limitChoices(name, choices, mime_type, ConvertChecker)
|
||||||
|
|
|
@ -2,8 +2,8 @@ import QtQuick 2.0
|
||||||
import Sailfish.Silica 1.0
|
import Sailfish.Silica 1.0
|
||||||
|
|
||||||
Setting {
|
Setting {
|
||||||
property int low
|
property int low: valid ? parent.printer.attrs[name+"-supported"].value.low : 0
|
||||||
property int high
|
property int high: valid ? parent.printer.attrs[name+"-supported"].value.high : 0
|
||||||
|
|
||||||
property bool suppressChange: false
|
property bool suppressChange: false
|
||||||
|
|
||||||
|
|
|
@ -3,17 +3,10 @@ import Sailfish.Silica 1.0
|
||||||
import seaprint.ippmsg 1.0
|
import seaprint.ippmsg 1.0
|
||||||
|
|
||||||
Setting {
|
Setting {
|
||||||
property var printer
|
valid: ((parent.printer.attrs["media-left-margin-supported"].value.indexOf(0) != -1) &&
|
||||||
|
(parent.printer.attrs["media-right-margin-supported"].value.indexOf(0) != -1) &&
|
||||||
Component.onCompleted: {
|
(parent.printer.attrs["media-top-margin-supported"].value.indexOf(0) != -1) &&
|
||||||
if((printer.attrs["media-left-margin-supported"].value.indexOf(0) != -1) &&
|
(parent.printer.attrs["media-bottom-margin-supported"].value.indexOf(0) != -1))
|
||||||
(printer.attrs["media-right-margin-supported"].value.indexOf(0) != -1) &&
|
|
||||||
(printer.attrs["media-top-margin-supported"].value.indexOf(0) != -1) &&
|
|
||||||
(printer.attrs["media-bottom-margin-supported"].value.indexOf(0) != -1))
|
|
||||||
{
|
|
||||||
valid = true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
displayValue: choice ? qsTr("true") : qsTr("false")
|
displayValue: choice ? qsTr("true") : qsTr("false")
|
||||||
|
|
||||||
|
|
|
@ -8,10 +8,15 @@ Item {
|
||||||
property string name
|
property string name
|
||||||
property string prettyName
|
property string prettyName
|
||||||
property int tag
|
property int tag
|
||||||
property bool valid: false
|
property bool _valid: parent.isValid(name)
|
||||||
|
property bool valid: _valid
|
||||||
|
|
||||||
property var choice
|
property var choice
|
||||||
property var default_choice
|
property var default_choice: parent.getDefaultChoice(name)
|
||||||
|
|
||||||
|
Component.onCompleted: parent.setInitialChoice(this)
|
||||||
|
|
||||||
|
onChoiceChanged: parent.choiceMade(this)
|
||||||
|
|
||||||
signal clicked()
|
signal clicked()
|
||||||
onClicked: {
|
onClicked: {
|
||||||
|
|
50
qml/components/SettingsColumn.qml
Normal file
50
qml/components/SettingsColumn.qml
Normal file
|
@ -0,0 +1,50 @@
|
||||||
|
import QtQuick 2.6
|
||||||
|
import Sailfish.Silica 1.0
|
||||||
|
import seaprint.mimer 1.0
|
||||||
|
import seaprint.ippprinter 1.0
|
||||||
|
|
||||||
|
Column {
|
||||||
|
id: settingsColumn
|
||||||
|
|
||||||
|
property var printer
|
||||||
|
property var jobParams
|
||||||
|
property string selectedFile
|
||||||
|
property string selectedFileType: Mimer.get_type(selectedFile)
|
||||||
|
|
||||||
|
function isValid(name) {
|
||||||
|
return printer.attrs.hasOwnProperty(name+"-supported");
|
||||||
|
}
|
||||||
|
function setInitialChoice(setting) {
|
||||||
|
if(jobParams.hasOwnProperty(setting.name))
|
||||||
|
{
|
||||||
|
if(setting.valid)
|
||||||
|
{
|
||||||
|
setting.choice = jobParams[setting.name].value;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{ // Clear jobParams of invalid settings
|
||||||
|
jobParams[setting.name] = undefined;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
function getChoices(name) {
|
||||||
|
return isValid(name) ? printer.attrs[name+"-supported"].value : [];
|
||||||
|
}
|
||||||
|
function getDefaultChoice(name) {
|
||||||
|
return printer.attrs.hasOwnProperty(name+"-default") ? printer.attrs[name+"-default"].value : undefined;
|
||||||
|
}
|
||||||
|
function choiceMade(setting)
|
||||||
|
{
|
||||||
|
if(setting.choice != undefined)
|
||||||
|
{
|
||||||
|
jobParams[setting.name] = {tag: setting.tag, value: setting.choice};
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
jobParams[setting.name] = undefined;
|
||||||
|
}
|
||||||
|
console.log(JSON.stringify(jobParams));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -10,10 +10,10 @@ Page {
|
||||||
allowedOrientations: Orientation.All
|
allowedOrientations: Orientation.All
|
||||||
|
|
||||||
id: page
|
id: page
|
||||||
property var printer
|
property alias printer: settingsColumn.printer
|
||||||
property var jobParams
|
property alias jobParams: settingsColumn.jobParams
|
||||||
property string selectedFile
|
property alias selectedFile: settingsColumn.selectedFile
|
||||||
property string selectedFileType: Mimer.get_type(selectedFile)
|
property alias selectedFileType: settingsColumn.selectedFileType
|
||||||
|
|
||||||
Connections {
|
Connections {
|
||||||
target: wifi
|
target: wifi
|
||||||
|
@ -24,23 +24,10 @@ Page {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function choiceMade(setting)
|
|
||||||
{
|
|
||||||
if(setting.choice != undefined)
|
|
||||||
{
|
|
||||||
jobParams[setting.name] = {tag: setting.tag, value: setting.choice};
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
jobParams[setting.name] = undefined;
|
|
||||||
}
|
|
||||||
console.log(JSON.stringify(jobParams));
|
|
||||||
}
|
|
||||||
|
|
||||||
// To enable PullDownMenu, place our content in a SilicaFlickable
|
// To enable PullDownMenu, place our content in a SilicaFlickable
|
||||||
SilicaFlickable {
|
SilicaFlickable {
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
contentHeight: settingColumn.height
|
contentHeight: settingsColumn.height
|
||||||
|
|
||||||
// PullDownMenu and PushUpMenu must be declared in SilicaFlickable, SilicaListView or SilicaGridView
|
// PullDownMenu and PushUpMenu must be declared in SilicaFlickable, SilicaListView or SilicaGridView
|
||||||
PullDownMenu {
|
PullDownMenu {
|
||||||
|
@ -85,8 +72,8 @@ Page {
|
||||||
|
|
||||||
VerticalScrollDecorator {}
|
VerticalScrollDecorator {}
|
||||||
|
|
||||||
Column {
|
SettingsColumn {
|
||||||
id: settingColumn
|
id: settingsColumn
|
||||||
width: parent.width
|
width: parent.width
|
||||||
|
|
||||||
PageHeader {
|
PageHeader {
|
||||||
|
@ -95,163 +82,73 @@ Page {
|
||||||
description: Utils.basename(selectedFile)
|
description: Utils.basename(selectedFile)
|
||||||
}
|
}
|
||||||
|
|
||||||
Item {
|
|
||||||
id: utils
|
|
||||||
|
|
||||||
function isValid(name) {
|
|
||||||
return printer.attrs.hasOwnProperty(name+"-supported");
|
|
||||||
}
|
|
||||||
function setInitialChoice(setting) {
|
|
||||||
if(jobParams.hasOwnProperty(setting.name))
|
|
||||||
{
|
|
||||||
if(setting.valid)
|
|
||||||
{
|
|
||||||
setting.choice = jobParams[setting.name].value;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{ // Clear jobParams of invalid settings
|
|
||||||
jobParams[setting.name] = undefined;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
function getChoices(name) {
|
|
||||||
return isValid(name) ? printer.attrs[name+"-supported"].value : [];
|
|
||||||
}
|
|
||||||
function getDefaultChoice(name) {
|
|
||||||
return printer.attrs.hasOwnProperty(name+"-default") ? printer.attrs[name+"-default"].value : undefined;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ChoiceSetting {
|
ChoiceSetting {
|
||||||
tag: IppMsg.Keyword
|
tag: IppMsg.Keyword
|
||||||
name: "sides"
|
name: "sides"
|
||||||
prettyName: qsTr("Sides")
|
prettyName: qsTr("Sides")
|
||||||
valid: utils.isValid(name)
|
|
||||||
choices: utils.getChoices(name)
|
|
||||||
default_choice: utils.getDefaultChoice(name)
|
|
||||||
mime_type: selectedFileType
|
mime_type: selectedFileType
|
||||||
|
|
||||||
onChoiceChanged: page.choiceMade(this)
|
|
||||||
Component.onCompleted: utils.setInitialChoice(this)
|
|
||||||
}
|
}
|
||||||
ChoiceSetting {
|
ChoiceSetting {
|
||||||
tag: IppMsg.Keyword
|
tag: IppMsg.Keyword
|
||||||
name: "media"
|
name: "media"
|
||||||
prettyName: qsTr("Print media")
|
prettyName: qsTr("Print media")
|
||||||
valid: utils.isValid(name)
|
|
||||||
choices: utils.getChoices(name)
|
|
||||||
default_choice: utils.getDefaultChoice(name)
|
|
||||||
mime_type: selectedFileType
|
mime_type: selectedFileType
|
||||||
|
|
||||||
onChoiceChanged: page.choiceMade(this)
|
|
||||||
Component.onCompleted: utils.setInitialChoice(this)
|
|
||||||
}
|
}
|
||||||
IntegerSetting {
|
IntegerSetting {
|
||||||
tag: IppMsg.Integer
|
tag: IppMsg.Integer
|
||||||
name: "copies"
|
name: "copies"
|
||||||
prettyName: qsTr("Copies")
|
prettyName: qsTr("Copies")
|
||||||
valid: utils.isValid(name)
|
|
||||||
low: valid ? printer.attrs[name+"-supported"].value.low : 0
|
|
||||||
high: valid ? printer.attrs[name+"-supported"].value.high : 0
|
|
||||||
default_choice: utils.getDefaultChoice(name)
|
|
||||||
|
|
||||||
onChoiceChanged: page.choiceMade(this)
|
|
||||||
Component.onCompleted: utils.setInitialChoice(this)
|
|
||||||
}
|
}
|
||||||
ChoiceSetting {
|
ChoiceSetting {
|
||||||
tag: IppMsg.Keyword
|
tag: IppMsg.Keyword
|
||||||
name: "multiple-document-handling"
|
name: "multiple-document-handling"
|
||||||
prettyName: qsTr("Collated copies")
|
prettyName: qsTr("Collated copies")
|
||||||
valid: utils.isValid(name)
|
|
||||||
choices: utils.getChoices(name)
|
|
||||||
default_choice: utils.getDefaultChoice(name)
|
|
||||||
mime_type: selectedFileType
|
mime_type: selectedFileType
|
||||||
|
|
||||||
onChoiceChanged: page.choiceMade(this)
|
|
||||||
Component.onCompleted: utils.setInitialChoice(this)
|
|
||||||
}
|
}
|
||||||
RangeSetting {
|
RangeSetting {
|
||||||
tag: IppMsg.IntegerRange
|
tag: IppMsg.IntegerRange
|
||||||
name: "page-ranges"
|
name: "page-ranges"
|
||||||
prettyName: qsTr("Page range")
|
prettyName: qsTr("Page range")
|
||||||
valid: (utils.isValid(name) || ConvertChecker.pdf) &&
|
valid: (_valid || ConvertChecker.pdf) &&
|
||||||
(selectedFileType == "application/pdf" || Mimer.isOffice(selectedFileType))
|
(selectedFileType == "application/pdf" || Mimer.isOffice(selectedFileType))
|
||||||
|
|
||||||
property var pdfpages: ConvertChecker.pdfPages(selectedFile)
|
property var pdfpages: ConvertChecker.pdfPages(selectedFile)
|
||||||
high: pdfpages == 0 ? 65535 : pdfpages
|
high: pdfpages == 0 ? 65535 : pdfpages
|
||||||
|
|
||||||
onChoiceChanged: page.choiceMade(this)
|
|
||||||
Component.onCompleted: utils.setInitialChoice(this)
|
|
||||||
}
|
}
|
||||||
ChoiceSetting {
|
ChoiceSetting {
|
||||||
tag: IppMsg.Keyword
|
tag: IppMsg.Keyword
|
||||||
name: "print-color-mode"
|
name: "print-color-mode"
|
||||||
prettyName: qsTr("Color mode")
|
prettyName: qsTr("Color mode")
|
||||||
valid: utils.isValid(name)
|
|
||||||
choices: utils.getChoices(name)
|
|
||||||
default_choice: utils.getDefaultChoice(name)
|
|
||||||
mime_type: selectedFileType
|
mime_type: selectedFileType
|
||||||
|
|
||||||
onChoiceChanged: page.choiceMade(this)
|
|
||||||
Component.onCompleted: utils.setInitialChoice(this)
|
|
||||||
}
|
}
|
||||||
ChoiceSetting {
|
ChoiceSetting {
|
||||||
tag: IppMsg.Enum
|
tag: IppMsg.Enum
|
||||||
name: "print-quality"
|
name: "print-quality"
|
||||||
prettyName: qsTr("Quality")
|
prettyName: qsTr("Quality")
|
||||||
valid: utils.isValid(name)
|
|
||||||
choices: utils.getChoices(name)
|
|
||||||
default_choice: utils.getDefaultChoice(name)
|
|
||||||
mime_type: selectedFileType
|
mime_type: selectedFileType
|
||||||
|
|
||||||
onChoiceChanged: page.choiceMade(this)
|
|
||||||
Component.onCompleted: utils.setInitialChoice(this)
|
|
||||||
}
|
}
|
||||||
ChoiceSetting {
|
ChoiceSetting {
|
||||||
tag: IppMsg.Resolution
|
tag: IppMsg.Resolution
|
||||||
name: "printer-resolution"
|
name: "printer-resolution"
|
||||||
prettyName: qsTr("Resolution")
|
prettyName: qsTr("Resolution")
|
||||||
valid: utils.isValid(name)
|
|
||||||
choices: utils.getChoices(name)
|
|
||||||
default_choice: utils.getDefaultChoice(name)
|
|
||||||
mime_type: selectedFileType
|
mime_type: selectedFileType
|
||||||
|
|
||||||
onChoiceChanged: page.choiceMade(this)
|
|
||||||
Component.onCompleted: utils.setInitialChoice(this)
|
|
||||||
}
|
}
|
||||||
ChoiceSetting {
|
ChoiceSetting {
|
||||||
tag: IppMsg.MimeMediaType
|
tag: IppMsg.MimeMediaType
|
||||||
name: "document-format"
|
name: "document-format"
|
||||||
prettyName: qsTr("Transfer format")
|
prettyName: qsTr("Transfer format")
|
||||||
valid: utils.isValid(name)
|
|
||||||
choices: utils.getChoices(name)
|
|
||||||
default_choice: utils.getDefaultChoice(name)
|
|
||||||
mime_type: selectedFileType
|
mime_type: selectedFileType
|
||||||
|
|
||||||
onChoiceChanged: page.choiceMade(this)
|
|
||||||
Component.onCompleted: utils.setInitialChoice(this)
|
|
||||||
}
|
}
|
||||||
ChoiceSetting {
|
ChoiceSetting {
|
||||||
tag: IppMsg.Keyword
|
tag: IppMsg.Keyword
|
||||||
name: "media-source"
|
name: "media-source"
|
||||||
prettyName: qsTr("Media source")
|
prettyName: qsTr("Media source")
|
||||||
valid: utils.isValid(name)
|
|
||||||
choices: utils.getChoices(name)
|
|
||||||
default_choice: utils.getDefaultChoice(name)
|
|
||||||
mime_type: selectedFileType
|
mime_type: selectedFileType
|
||||||
|
|
||||||
onChoiceChanged: page.choiceMade(this)
|
|
||||||
Component.onCompleted: utils.setInitialChoice(this)
|
|
||||||
}
|
}
|
||||||
MediaColSetting {
|
MediaColSetting {
|
||||||
tag: IppMsg.BeginCollection
|
tag: IppMsg.BeginCollection
|
||||||
name: "media-col"
|
name: "media-col"
|
||||||
prettyName: qsTr("Zero margins")
|
prettyName: qsTr("Zero margins")
|
||||||
valid: false
|
|
||||||
printer: page.printer
|
|
||||||
|
|
||||||
onChoiceChanged: page.choiceMade(this)
|
|
||||||
Component.onCompleted: utils.setInitialChoice(this)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue