File indexing completed on 2024-12-08 07:19:38
0001 /* 0002 * SPDX-FileCopyrightText: 2009 Kare Sars <kare dot sars at iki dot fi> 0003 * SPDX-FileCopyrightText: 2014 Gregor Mitsch : port to KDE5 frameworks 0004 * 0005 * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL 0006 */ 0007 0008 #ifndef KSANE_BASE_OPTION_H 0009 #define KSANE_BASE_OPTION_H 0010 0011 // Qt includes 0012 #include <QObject> 0013 0014 //KDE includes 0015 0016 #include <KLocalizedString> 0017 0018 // Sane includes 0019 extern "C" 0020 { 0021 #include <sane/sane.h> 0022 #include <sane/saneopts.h> 0023 } 0024 0025 #include "../option.h" 0026 0027 #define SANE_TRANSLATION_DOMAIN "sane-backends" 0028 0029 namespace KSaneCore 0030 { 0031 0032 inline QString sane_i18n(const char *text) { 0033 return i18nd(SANE_TRANSLATION_DOMAIN, text); 0034 } 0035 0036 0037 class BaseOption : public QObject 0038 { 0039 Q_OBJECT 0040 0041 public: 0042 0043 BaseOption(); 0044 BaseOption(const SANE_Handle handle, const int index); 0045 ~BaseOption() override; 0046 static Option::OptionType optionType(const SANE_Option_Descriptor *optDesc); 0047 0048 bool needsPolling() const; 0049 virtual void readOption(); 0050 virtual void readValue(); 0051 0052 0053 virtual QString name() const; 0054 virtual QString title() const; 0055 virtual QString description() const; 0056 virtual Option::OptionType type() const; 0057 virtual Option::OptionState state() const; 0058 virtual QVariant minimumValue() const; 0059 virtual QVariant maximumValue() const; 0060 virtual QVariant stepValue() const; 0061 virtual QVariant value() const; 0062 virtual QVariantList valueList() const; 0063 virtual QVariantList internalValueList() const; 0064 virtual Option::OptionUnit valueUnit() const; 0065 virtual int valueSize() const; 0066 virtual QString valueAsString() const; 0067 0068 bool storeCurrentData(); 0069 bool restoreSavedData(); 0070 0071 Q_SIGNALS: 0072 void optionsNeedReload(); 0073 void valuesNeedReload(); 0074 void optionReloaded(); 0075 void valueChanged(const QVariant &value); 0076 0077 public Q_SLOTS: 0078 0079 virtual bool setValue(const QVariant &value); 0080 0081 protected: 0082 0083 static SANE_Word toSANE_Word(unsigned char *data); 0084 static void fromSANE_Word(unsigned char *data, SANE_Word from); 0085 bool writeData(void *data); 0086 void beginOptionReload(); 0087 void endOptionReload(); 0088 0089 SANE_Handle m_handle = nullptr; 0090 int m_index = -1; 0091 const SANE_Option_Descriptor *m_optDesc = nullptr; ///< This pointer is provided by sane 0092 unsigned char *m_data= nullptr; 0093 Option::OptionType m_optionType = Option::TypeDetectFail; 0094 }; 0095 0096 } // namespace KSaneCore 0097 0098 #endif // KSANE_BASE_OPTION_H 0099