10#include <ksanecore_debug.h>
15BaseOption::BaseOption() :
QObject()
19BaseOption::BaseOption(
const SANE_Handle handle,
const int index)
20 :
QObject(), m_handle(handle), m_index(index)
24BaseOption::~BaseOption()
32void BaseOption::readOption()
38void BaseOption::beginOptionReload()
40 if (m_handle !=
nullptr) {
41 m_optDesc = sane_get_option_descriptor(m_handle, m_index);
45void BaseOption::endOptionReload()
47 Q_EMIT optionReloaded();
50Option::OptionState BaseOption::state()
const
52 if (m_optDesc ==
nullptr) {
53 return Option::StateHidden;
56 if (((m_optDesc->cap & SANE_CAP_SOFT_DETECT) == 0) || (m_optDesc->cap & SANE_CAP_INACTIVE) || ((m_optDesc->size == 0) && (
type() != Option::TypeAction))) {
57 return Option::StateHidden;
58 }
else if ((m_optDesc->cap & SANE_CAP_SOFT_SELECT) == 0) {
59 return Option::StateDisabled;
61 return Option::StateActive;
64bool BaseOption::needsPolling()
const
70 if ((m_optDesc->cap & SANE_CAP_SOFT_DETECT) && !(m_optDesc->cap & SANE_CAP_SOFT_SELECT)) {
71 qCDebug(KSANECORE_LOG) <<
name() <<
"optDesc->cap =" << m_optDesc->cap;
80 if (m_optDesc ==
nullptr) {
86QString BaseOption::title()
const
88 if (m_optDesc ==
nullptr) {
91 return sane_i18n(m_optDesc->title);
94QString BaseOption::description()
const
96 if (m_optDesc ==
nullptr) {
99 return sane_i18n(m_optDesc->desc);
102Option::OptionType BaseOption::type()
const
107bool BaseOption::writeData(
void *data)
112 if (state() == Option::StateDisabled) {
116 status = sane_control_option(m_handle, m_index, SANE_ACTION_SET_VALUE, data, &res);
117 if (
status != SANE_STATUS_GOOD) {
118 qCDebug(KSANECORE_LOG) << m_optDesc->name <<
"sane_control_option returned:" << sane_strstatus(
status);
123 if (res & SANE_INFO_INEXACT) {
128 if (res & SANE_INFO_RELOAD_OPTIONS) {
129 Q_EMIT optionsNeedReload();
131 }
else if (res & SANE_INFO_RELOAD_PARAMS) {
133 Q_EMIT valuesNeedReload();
139void BaseOption::readValue() {}
141SANE_Word BaseOption::toSANE_Word(
unsigned char *data)
145#if __BYTE_ORDER == __LITTLE_ENDIAN
146 tmp = (data[0] & 0xff);
147 tmp += ((SANE_Word)(data[1] & 0xff)) << 8;
148 tmp += ((SANE_Word)(data[2] & 0xff)) << 16;
149 tmp += ((SANE_Word)(data[3] & 0xff)) << 24;
151 tmp = (data[3] & 0xff);
152 tmp += ((SANE_Word)(data[2] & 0xff)) << 8;
153 tmp += ((SANE_Word)(data[1] & 0xff)) << 16;
154 tmp += ((SANE_Word)(data[0] & 0xff)) << 24;
159void BaseOption::fromSANE_Word(
unsigned char *data, SANE_Word from)
162#if __BYTE_ORDER == __LITTLE_ENDIAN
163 data[0] = (from & 0x000000FF);
164 data[1] = (from & 0x0000FF00) >> 8;
165 data[2] = (from & 0x00FF0000) >> 16;
166 data[3] = (from & 0xFF000000) >> 24;
168 data[3] = (from & 0x000000FF);
169 data[2] = (from & 0x0000FF00) >> 8;
170 data[1] = (from & 0x00FF0000) >> 16;
171 data[0] = (from & 0xFF000000) >> 24;
180QVariant BaseOption::minimumValue()
const
185QVariant BaseOption::maximumValue()
const
190QVariant BaseOption::stepValue()
const
195QVariantList BaseOption::valueList()
const
197 return QVariantList();
200QVariantList BaseOption::internalValueList()
const
202 return QVariantList();
205Option::OptionUnit BaseOption::valueUnit()
const
207 if (m_optDesc !=
nullptr) {
208 switch (m_optDesc->unit) {
209 case SANE_UNIT_PIXEL:
210 return Option::UnitPixel;
212 return Option::UnitBit;
214 return Option::UnitMilliMeter;
216 return Option::UnitDPI;
217 case SANE_UNIT_PERCENT:
218 return Option::UnitPercent;
219 case SANE_UNIT_MICROSECOND:
220 return Option::UnitMicroSecond;
222 return Option::UnitNone;
225 return Option::UnitNone;
229int BaseOption::valueSize()
const
231 if (m_optDesc !=
nullptr) {
232 return m_optDesc->size /
sizeof(SANE_Word);
237QString BaseOption::valueAsString()
const
242bool BaseOption::setValue(
const QVariant &)
247bool BaseOption::storeCurrentData()
253 if (state() == Option::StateHidden) {
258 if (m_data !=
nullptr) {
261 m_data = (
unsigned char *)malloc(m_optDesc->size);
262 status = sane_control_option(m_handle, m_index, SANE_ACTION_GET_VALUE, m_data, &res);
263 if (
status != SANE_STATUS_GOOD) {
264 qCDebug(KSANECORE_LOG) << m_optDesc->name <<
"sane_control_option returned" <<
status;
270bool BaseOption::restoreSavedData()
273 if (m_data ==
nullptr) {
278 if (state() == Option::StateHidden) {
281 if (state() == Option::StateDisabled) {
290Option::OptionType BaseOption::optionType(
const SANE_Option_Descriptor *optDesc)
293 return Option::TypeDetectFail;
296 switch (optDesc->constraint_type) {
297 case SANE_CONSTRAINT_NONE:
298 switch (optDesc->type) {
300 return Option::TypeBool;
302 if (optDesc->size ==
sizeof(SANE_Word)) {
303 return Option::TypeInteger;
305 qCDebug(KSANECORE_LOG) <<
"Can not handle:" << optDesc->title;
306 qCDebug(KSANECORE_LOG) <<
"SANE_CONSTRAINT_NONE && SANE_TYPE_INT";
307 qCDebug(KSANECORE_LOG) <<
"size" << optDesc->size <<
"!= sizeof(SANE_Word)";
309 case SANE_TYPE_FIXED:
310 if (optDesc->size ==
sizeof(SANE_Word)) {
311 return Option::TypeDouble;
313 qCDebug(KSANECORE_LOG) <<
"Can not handle:" << optDesc->title;
314 qCDebug(KSANECORE_LOG) <<
"SANE_CONSTRAINT_NONE && SANE_TYPE_FIXED";
315 qCDebug(KSANECORE_LOG) <<
"size" << optDesc->size <<
"!= sizeof(SANE_Word)";
317 case SANE_TYPE_BUTTON:
318 return Option::TypeAction;
319 case SANE_TYPE_STRING:
320 return Option::TypeString;
321 case SANE_TYPE_GROUP:
322 return Option::TypeDetectFail;
325 case SANE_CONSTRAINT_RANGE:
326 switch (optDesc->type) {
328 return Option::TypeBool;
330 if (optDesc->size ==
sizeof(SANE_Word)) {
331 return Option::TypeInteger;
334 if ((strcmp(optDesc->name, SANE_NAME_GAMMA_VECTOR) == 0) ||
335 (strcmp(optDesc->name, SANE_NAME_GAMMA_VECTOR_R) == 0) ||
336 (strcmp(optDesc->name, SANE_NAME_GAMMA_VECTOR_G) == 0) ||
337 (strcmp(optDesc->name, SANE_NAME_GAMMA_VECTOR_B) == 0)) {
338 return Option::TypeGamma;
340 qCDebug(KSANECORE_LOG) <<
"Can not handle:" << optDesc->title;
341 qCDebug(KSANECORE_LOG) <<
"SANE_CONSTRAINT_RANGE && SANE_TYPE_INT && !SANE_NAME_GAMMA_VECTOR...";
342 qCDebug(KSANECORE_LOG) <<
"size" << optDesc->size <<
"!= sizeof(SANE_Word)";
344 case SANE_TYPE_FIXED:
345 if (optDesc->size ==
sizeof(SANE_Word)) {
346 return Option::TypeDouble;
348 qCDebug(KSANECORE_LOG) <<
"Can not handle:" << optDesc->title;
349 qCDebug(KSANECORE_LOG) <<
"SANE_CONSTRAINT_RANGE && SANE_TYPE_FIXED";
350 qCDebug(KSANECORE_LOG) <<
"size" << optDesc->size <<
"!= sizeof(SANE_Word)";
351 qCDebug(KSANECORE_LOG) <<
"Analog Gamma vector?";
353 case SANE_TYPE_STRING:
354 qCDebug(KSANECORE_LOG) <<
"Can not handle:" << optDesc->title;
355 qCDebug(KSANECORE_LOG) <<
"SANE_CONSTRAINT_RANGE && SANE_TYPE_STRING";
356 return Option::TypeDetectFail;
357 case SANE_TYPE_BUTTON:
358 return Option::TypeAction;
359 case SANE_TYPE_GROUP:
360 return Option::TypeDetectFail;
363 case SANE_CONSTRAINT_WORD_LIST:
364 case SANE_CONSTRAINT_STRING_LIST:
365 return Option::TypeValueList;
367 return Option::TypeDetectFail;
372#include "moc_baseoption.cpp"
Q_SCRIPTABLE CaptureState status()
VehicleSection::Type type(QStringView coachNumber, QStringView coachClassification)
QString name(StandardAction id)
QString fromUtf8(QByteArrayView str)