Skip to content

Commit

Permalink
Move int specialization into ChoiceSetting
Browse files Browse the repository at this point in the history
  • Loading branch information
attah committed Jan 3, 2025
1 parent 40a8cc6 commit 805500c
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 35 deletions.
2 changes: 1 addition & 1 deletion lib/ippprintjob.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<int> numberUp = ChoiceSetting<int>(&_printerAttrs, &jobAttrs, IppTag::Integer, "number-up");

ChoiceSetting<std::string> colorMode = ChoiceSetting<std::string>(&_printerAttrs, &jobAttrs, IppTag::Keyword, "print-color-mode");
ChoiceSetting<int> printQuality = ChoiceSetting<int>(&_printerAttrs, &jobAttrs, IppTag::Enum, "print-quality");
Expand Down
62 changes: 29 additions & 33 deletions lib/setting.h
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,38 @@ class ChoiceSetting : public Setting<T>
}

List<T> getSupported() const
{
return _getSupported(T());
}

private:
template <typename U>
List<U> _getSupported(const U&) const
{
IppAttrs* pa = this->_printerAttrs;
return pa->getList<T>(this->_name+"-supported");
return pa->getList<U>(this->_name+"-supported");
}

List<int> _getSupported(int) const
{
IppAttrs* pa = this->_printerAttrs;
if(pa->has(this->_name+"-supported"))
{
IppAttr val = pa->at(this->_name+"-supported");
if(val.is<IppIntRange>())
{
List<int> res;
IppIntRange range = val.get<IppIntRange>();
for(int i = range.low; i <= range.high; i++)
{
res.push_back(i);
}
return res;
}
}
return pa->getList<int>(this->_name+"-supported");
}

};

template <typename T>
Expand Down Expand Up @@ -247,36 +275,4 @@ class IntegerRangeListSetting : public Setting<IppOneSetOf>
}
};

class IntegerChoiceSetting : public Setting<int>
{
public:
IntegerChoiceSetting(IppAttrs* printerAttrs, IppAttrs* attrs, IppTag tag, std::string name)
: Setting<int>(printerAttrs, attrs, tag, std::move(name))
{}

bool isSupportedValue(int value) const override
{
return getSupported().contains(value);
}

List<int> getSupported() const
{
List<int> res;
if(_printerAttrs->has(_name+"-supported") &&
_printerAttrs->at(_name+"-supported").is<IppIntRange>())
{
IppIntRange range = _printerAttrs->at(_name+"-supported").get<IppIntRange>();
for(int i = range.low; i <= range.high; i++)
{
res.push_back(i);
}
}
else
{
res = _printerAttrs->getList<int>(_name+"-supported");
}
return res;
}
};

#endif // SETTING_H
6 changes: 5 additions & 1 deletion utils/ippclient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -207,6 +208,8 @@ int main(int argc, char** argv)
{"no", "separate-documents-uncollated-copies"}},
{"--collated-copies"}, "Request collated copies (yes/no)");

SwitchArg<int> numberUpOpt(numberUp, {"-n", "--number-up"}, "Pager per page (as per IPP)");

SwitchArg<std::string> paperSizeOpt(paperSize, {"--paper-size"}, "Paper size to output, e.g.: iso_a4_210x297mm");
SwitchArg<uint32_t> resolutionOpt(hwRes, {"-r", "--resolution"}, "Resolution (in DPI) for rasterization");
SwitchArg<uint32_t> resolutionXOpt(hwResX, {"-rx", "--resolution-x"}, "Resolution (in DPI) for rasterization, x-axis");
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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())
Expand Down

0 comments on commit 805500c

Please sign in to comment.