harbour-seaprint/qml/components/SettingsColumn.qml

90 lines
2.5 KiB
QML
Raw Normal View History

2021-03-21 16:01:19 +03:00
import QtQuick 2.6
import Sailfish.Silica 1.0
import seaprint.mimer 1.0
import seaprint.ippprinter 1.0
import seaprint.ippmsg 1.0
2021-03-21 16:01:19 +03:00
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(setting.valid)
2021-03-21 16:01:19 +03:00
{
if(setting.subkey == "")
2021-03-21 16:01:19 +03:00
{
if(jobParams.hasOwnProperty(setting.name))
{
setting.choice = jobParams[setting.name].value;
}
2021-03-21 16:01:19 +03:00
}
else
{
if(jobParams.hasOwnProperty(setting.subkey) &&jobParams[setting.subkey].value.hasOwnProperty(setting.name))
{
setting.choice = jobParams[setting.subkey].value[setting.name].value;
}
2021-03-21 16:01:19 +03:00
}
}
else
{ // Clear jobParams of invalid settings
delete jobParams[setting.name];
}
2021-03-21 16:01:19 +03:00
}
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.subkey == "")
2021-03-21 16:01:19 +03:00
{
if(setting.choice != undefined)
{
jobParams[setting.name] = {tag: setting.tag, value: setting.choice};
}
else
{
delete jobParams[setting.name];
2021-03-21 16:01:19 +03:00
}
}
else
{
var tmpObj = Object();
if(jobParams.hasOwnProperty(setting.subkey))
{
tmpObj = jobParams[setting.subkey].value;
}
2021-03-21 16:01:19 +03:00
if(setting.choice != undefined)
{
tmpObj[setting.name] = {tag: setting.tag, value: setting.choice};
}
else
{
delete tmpObj[setting.name];
}
2021-03-21 16:01:19 +03:00
if(Object.keys(tmpObj).length != 0)
{
jobParams[setting.subkey] = {tag: IppMsg.BeginCollection, value: tmpObj};
}
else
{
delete jobParams[setting.subkey];
}
}
2022-01-19 22:18:00 +03:00
// console.log(JSON.stringify(jobParams));
}
2021-03-21 16:01:19 +03:00
}