diff --git a/lib/ippprintjob.h b/lib/ippprintjob.h index df37fdb..59b3554 100644 --- a/lib/ippprintjob.h +++ b/lib/ippprintjob.h @@ -38,7 +38,7 @@ class IppPrintJob IntegerRangeListSetting pageRanges = IntegerRangeListSetting(&_printerAttrs, &jobAttrs, IppTag::IntegerRange, "page-ranges"); - IntegerChoiceSetting numberUp = IntegerChoiceSetting(&_printerAttrs, &jobAttrs, IppTag::Integer, "number-up"); + ChoiceSetting numberUp = ChoiceSetting(&_printerAttrs, &jobAttrs, IppTag::Integer, "number-up"); ChoiceSetting colorMode = ChoiceSetting(&_printerAttrs, &jobAttrs, IppTag::Keyword, "print-color-mode"); ChoiceSetting printQuality = ChoiceSetting(&_printerAttrs, &jobAttrs, IppTag::Enum, "print-quality"); diff --git a/lib/setting.h b/lib/setting.h index 00fb786..5b5be5e 100644 --- a/lib/setting.h +++ b/lib/setting.h @@ -145,10 +145,38 @@ class ChoiceSetting : public Setting } List getSupported() const + { + return _getSupported(T()); + } + +private: + template + List _getSupported(const U&) const { IppAttrs* pa = this->_printerAttrs; - return pa->getList(this->_name+"-supported"); + return pa->getList(this->_name+"-supported"); + } + + List _getSupported(int) const + { + IppAttrs* pa = this->_printerAttrs; + if(pa->has(this->_name+"-supported")) + { + IppAttr val = pa->at(this->_name+"-supported"); + if(val.is()) + { + List res; + IppIntRange range = val.get(); + for(int i = range.low; i <= range.high; i++) + { + res.push_back(i); + } + return res; + } + } + return pa->getList(this->_name+"-supported"); } + }; template @@ -247,36 +275,4 @@ class IntegerRangeListSetting : public Setting } }; -class IntegerChoiceSetting : public Setting -{ -public: - IntegerChoiceSetting(IppAttrs* printerAttrs, IppAttrs* attrs, IppTag tag, std::string name) - : Setting(printerAttrs, attrs, tag, std::move(name)) - {} - - bool isSupportedValue(int value) const override - { - return getSupported().contains(value); - } - - List getSupported() const - { - List res; - if(_printerAttrs->has(_name+"-supported") && - _printerAttrs->at(_name+"-supported").is()) - { - IppIntRange range = _printerAttrs->at(_name+"-supported").get(); - for(int i = range.low; i <= range.high; i++) - { - res.push_back(i); - } - } - else - { - res = _printerAttrs->getList(_name+"-supported"); - } - return res; - } -}; - #endif // SETTING_H diff --git a/utils/ippclient.cpp b/utils/ippclient.cpp index d1e65a0..425f9b6 100644 --- a/utils/ippclient.cpp +++ b/utils/ippclient.cpp @@ -164,6 +164,7 @@ int main(int argc, char** argv) std::string pages; int copies; std::string collatedCopies; + int numberUp; std::string paperSize; uint32_t hwRes; uint32_t hwResX; @@ -207,6 +208,8 @@ int main(int argc, char** argv) {"no", "separate-documents-uncollated-copies"}}, {"--collated-copies"}, "Request collated copies (yes/no)"); + SwitchArg numberUpOpt(numberUp, {"-n", "--number-up"}, "Pager per page (as per IPP)"); + SwitchArg paperSizeOpt(paperSize, {"--paper-size"}, "Paper size to output, e.g.: iso_a4_210x297mm"); SwitchArg resolutionOpt(hwRes, {"-r", "--resolution"}, "Resolution (in DPI) for rasterization"); SwitchArg resolutionXOpt(hwResX, {"-rx", "--resolution-x"}, "Resolution (in DPI) for rasterization, x-axis"); @@ -258,7 +261,7 @@ int main(int argc, char** argv) {"cancel-job", {{&helpOpt, &verboseOpt, &idOpt}, {&addrArg}}}, {"print", {{&helpOpt, &verboseOpt, &forceOpt, &oneStageOpt, - &pagesOpt, &copiesOpt, &collatedCopiesOpt, &paperSizeOpt, + &pagesOpt, &copiesOpt, &collatedCopiesOpt, &numberUpOpt, &paperSizeOpt, &resolutionOpt, &resolutionXOpt, &resolutionYOpt, &sidesOpt, &colorModeOpt, &qualityOpt, &scalingOpt, &formatOpt, &mimeTypeOpt, @@ -424,6 +427,7 @@ int main(int argc, char** argv) set_or_fail(copiesOpt, job.copies, copies, force || printer.supportsPrinterRaster()); set_or_fail(collatedCopiesOpt, job.multipleDocumentHandling, collatedCopies, force); + set_or_fail(numberUpOpt, job.numberUp, numberUp, force); set_or_fail(paperSizeOpt, job.media, paperSize, force); if(resolutionXOpt.isSet() != resolutionYOpt.isSet())