File indexing completed on 2025-01-19 12:59:19
0001 /************************************************************************ 0002 * * 0003 * This file is part of Kooka, a scanning/OCR application using * 0004 * Qt <http://www.qt.io> and KDE Frameworks <http://www.kde.org>. * 0005 * * 0006 * Copyright (C) 2000-2016 Klaas Freitag <freitag@suse.de> * 0007 * Jonathan Marten <jjm@keelhaul.me.uk> * 0008 * * 0009 * Kooka is free software; you can redistribute it and/or modify it * 0010 * under the terms of the GNU Library General Public License as * 0011 * published by the Free Software Foundation and appearing in the * 0012 * file COPYING included in the packaging of this file; either * 0013 * version 2 of the License, or (at your option) any later version. * 0014 * * 0015 * As a special exception, permission is given to link this program * 0016 * with any version of the KADMOS OCR/ICR engine (a product of * 0017 * reRecognition GmbH, Kreuzlingen), and distribute the resulting * 0018 * executable without including the source code for KADMOS in the * 0019 * source distribution. * 0020 * * 0021 * This program is distributed in the hope that it will be useful, * 0022 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 0023 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 0024 * GNU General Public License for more details. * 0025 * * 0026 * You should have received a copy of the GNU General Public * 0027 * License along with this program; see the file COPYING. If * 0028 * not, see <http://www.gnu.org/licenses/>. * 0029 * * 0030 ************************************************************************/ 0031 0032 #ifndef KSCANOPTSET_H 0033 #define KSCANOPTSET_H 0034 0035 #include "kookascan_export.h" 0036 0037 #include <qhash.h> 0038 #include <qmap.h> 0039 #include <qbytearray.h> 0040 0041 class KScanOption; 0042 0043 /** 0044 * @short A set of scanner parameters. 0045 * 0046 * Named scanner parameters can be added to the set, which stores 0047 * their names and values. They can be enumerated and retrieved from 0048 * the set. 0049 * 0050 * A set can be saved to and restored from the global scanner 0051 * configuration file. This can be used to save scanner options 0052 * between runs of an application, or to manage a repertoire of 0053 * saved scanner configurations. 0054 * 0055 * The saved sets available can be listed, and a saved set can be 0056 * deleted from the configuration file. 0057 * 0058 * @author Klaas Freitag 0059 * @author Jonathan Marten 0060 **/ 0061 0062 class KOOKASCAN_EXPORT KScanOptSet : public QHash<QByteArray, QByteArray> 0063 { 0064 0065 public: 0066 /** 0067 * A map as returned by @c readList(). 0068 */ 0069 typedef QMap<QString, QString> StringMap; 0070 0071 /** 0072 * Create a new option set container. 0073 * 0074 * @param setName name for the option set. When saving to or loading 0075 * from a configuration file, the set name specified here is used as 0076 * the group name. 0077 **/ 0078 explicit KScanOptSet(const QString &setName); 0079 0080 /** 0081 * Destructor. 0082 **/ 0083 ~KScanOptSet(); 0084 0085 /** 0086 * Save the current value of an option. 0087 * 0088 * @param opt The option whose value is to be saved 0089 * @return @c true if the option was successfully stored 0090 */ 0091 bool backupOption(const KScanOption *opt); 0092 0093 /** 0094 * Return the currently stored value of an option. 0095 * 0096 * @param optName The name of the required option 0097 * @return The value of the option, or a null string if no 0098 * option of that name is present. 0099 * @deprecated Use QHash::value() instead. 0100 **/ 0101 QByteArray Q_DECL_DEPRECATED getValue(const QByteArray &optName) const; 0102 0103 /** 0104 * Save the option set to the global scanner configuration file. 0105 * 0106 * @param scannerName The SANE device name of the scanner to which 0107 * this configuration applies. 0108 * @param desc A description for the option set. If this is a null or 0109 * empty string, the description set by setDescription() is used. 0110 * 0111 * @note This does not automatically read the current options from the 0112 * scanner before saving them to the configuration file, the values last 0113 * read by backupOption() are used. Therefore, to ensure the saved 0114 * option set correctly reflects the current scanner parameters, the 0115 * following should be done: 0116 * 0117 * @code 0118 * KScanOptSet optSet(setName); 0119 * saneDevice->getCurrentOptions(&optSet); 0120 * optSet.saveConfig(saneDevice->scannerBackendName(), setDesc); 0121 * @endcode 0122 **/ 0123 void saveConfig(const QByteArray &scannerName, const QString &desc = QString()) const; 0124 0125 /** 0126 * Load an option set from the global scanner configuration file. 0127 * 0128 * @param scannerName The SANE device name of the scanner to which 0129 * this configuration is intended to apply. If it does not match the 0130 * scanner name that this option set was saved for, a warning message 0131 * is output (but the load will succeed, as far as is possible, anyway). 0132 * If this is a null or empty string, no check is made. 0133 * @return @c true if the load was successful. 0134 * 0135 * @note The option values read are not automatically sent to the scanner. 0136 * Therefore, to ensure that the scanner uses the loaded values, the 0137 * following should be done: 0138 * 0139 * @code 0140 * KScanOptSet optSet(setName); 0141 * optSet.loadConfig(); 0142 * saneDevice->loadOptionSet(&optSet); 0143 * saneDevice->reloadAll(); 0144 * @endcode 0145 * 0146 * @note The option set is not cleared before it is loaded from the 0147 * configuration file, so any preexisting options which are not present 0148 * in the file will retain their previous values. If a clean loaded 0149 * set is required for a previously-used option set, then simply use 0150 * @c clear() on it before calling @c loadConfig(). 0151 **/ 0152 bool loadConfig(const QByteArray &scannerName = ""); 0153 0154 /** 0155 * Set a description for the option set. 0156 * 0157 * @param desc The new description 0158 **/ 0159 void setDescription(const QString &desc); 0160 0161 /** 0162 * Get the description of the option set. 0163 * 0164 * @return The option set description 0165 **/ 0166 QString getDescription() const { return (mSetDescription); } 0167 0168 /** 0169 * Set a new name for the option set. 0170 * 0171 * @param newName The new option set name 0172 **/ 0173 void setSetName(const QString &newName); 0174 0175 /** 0176 * Get the name of the option set. 0177 * 0178 * @return The option set name 0179 **/ 0180 const QString &getSetName() const { return (mSetName); } 0181 0182 /** 0183 * Read all of the available saved option set names and descriptions 0184 * from the configuration file. 0185 * 0186 * @return A map from each available set name to its description 0187 **/ 0188 static StringMap readList(); 0189 0190 /** 0191 * Delete a saved option set from the configuration file. 0192 * 0193 * @param setName The name of the set to delete 0194 **/ 0195 static void deleteSet(const QString &setName); 0196 0197 /** 0198 * Get the name of the default startup option set. 0199 * 0200 * @return The set name 0201 **/ 0202 static QString startupSetName() { return ("saveSet"); } 0203 0204 private: 0205 QString mSetName; 0206 QString mSetDescription; 0207 }; 0208 0209 #endif // KSCANOPTSET_H