KSaneCore

interface.h
1/*
2 * SPDX-FileCopyrightText: 2007-2010 Kare Sars <kare dot sars at iki dot fi>
3 * SPDX-FileCopyrightText: 2007 Gilles Caulier <caulier dot gilles at gmail dot com>
4 * SPDX-FileCopyrightText: 2014 Gregor Mitsch : port to KDE5 frameworks
5 * SPDX-FileCopyrightText: 2021 Alexander Stippich <a.stippich@gmx.net>
6 *
7 * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
8 */
9
10#ifndef KSANE_COREINTERFACE_H
11#define KSANE_COREINTERFACE_H
12
13#include "ksanecore_export.h"
14
15#include <memory>
16
17#include <QImage>
18#include <QList>
19#include <QObject>
20
21#include "deviceinformation.h"
22
23namespace KSaneCore
24{
25
26class InterfacePrivate;
27class Option;
28
29/**
30 * This class provides the core interface for accessing the scan controls and options.
31 */
32class KSANECORE_EXPORT Interface : public QObject
33{
34 Q_OBJECT
35 friend class InterfacePrivate;
36
37public:
38 /**
39 * Enum defining the message level of the returned scan status string.
40 * @note There might come more enumerations in the future.
41 */
43 NoError, // The scanning has finished successfully
44 ErrorGeneral, // The error string should contain an error message.
45 Information // There is some information to the user.
46 };
47
48 /**
49 * Enum determining whether the scanner opened correctly.
50 */
52 OpeningSucceeded, // scanner opened successfully
53 OpeningDenied, // access was denied,
54 OpeningFailed, // opening the scanner failed for unknown reasons
55 };
56
57 /**
58 * This enumeration is used to obtain a specific option with getOption(KSaneOptionName).
59 * Depending on the backend, not all options are available, nor this list is complete.
60 * For the remaining options, getOptionsList() must be used.
61 */
63 SourceOption,
64 ScanModeOption,
65 BitDepthOption,
66 ResolutionOption,
67 TopLeftXOption,
68 TopLeftYOption,
69 BottomRightXOption,
70 BottomRightYOption,
71 FilmTypeOption,
72 NegativeOption,
73 InvertColorOption,
74 PageSizeOption,
75 ThresholdOption,
76 XResolutionOption,
77 YResolutionOption,
78 PreviewOption,
79 WaitForButtonOption,
80 BrightnessOption,
81 ContrastOption,
82 GammaOption,
83 GammaRedOption,
84 GammaGreenOption,
85 GammaBlueOption,
86 BlackLevelOption,
87 WhiteLevelOption,
88 BatchModeOption,
89 BatchDelayOption,
90 };
91
92 /**
93 * This enumeration is used to filter the devices found by SANE.
94 * Sometimes, webcam may show up as scanner device and some
95 * more special scanner are also classified as cameras.
96 */
97 enum DeviceType { AllDevices, NoCameraAndVirtualDevices };
98
99 /**
100 * This constructor initializes the private class variables.
101 */
102 explicit Interface(QObject *parent = nullptr);
103
104 /**
105 * Standard destructor.
106 */
107 ~Interface() override;
108
109 /**
110 * Get the list of available scanning devices. Connect to availableDevices()
111 * which is fired once these devices are known. While the querying is done in a
112 * separate thread and thus not blocking the application, the application must
113 * ensure that no other action accessing the scanner device (settings options etc.)
114 * is performed during this period.
115 * @return whether the devices list are being reloaded or not
116 * @param type specify whether only specific device types shall be queried
117 */
118 bool reloadDevicesList(DeviceType type = AllDevices);
119
120 /**
121 * This method opens the specified scanner device and adds the scan options to the
122 * options list.
123 * @param deviceName is the SANE device name for the scanner to open.
124 * @return the status of the opening action.
125 */
126 OpenStatus openDevice(const QString &deviceName);
127
128 /**
129 * This method opens the specified scanner device with a specified username and password.
130 * Adds the scan options to the options list.
131 * @param deviceName is the SANE device name for the scanner to open.
132 * @param userName the username required to open for the scanner.
133 * @param password the password required to open for the scanner.
134 * @return the status of the opening action.
135 */
136 OpenStatus openRestrictedDevice(const QString &deviceName, const QString &userName, const QString &password);
137
138 /**
139 * This method closes the currently open scanner device.
140 * @return 'true' if all goes well and 'false' if no device is open.
141 */
142 bool closeDevice();
143
144 /**
145 * This method returns the internal device name of the currently opened scanner.
146 * @note Due to limitations of the SANE API, this will function will return an empty string
147 * if reloadDevicesList() has not been called before.
148 */
149 QString deviceName() const;
150
151 /**
152 * This method returns the vendor name of the currently opened scanner.
153 * @note Due to limitations of the SANE API, this will function will return an empty string
154 * if reloadDevicesList() has not been called before.
155 */
156 QString deviceVendor() const;
157
158 /**
159 * This method returns the model of the currently opened scanner.
160 * @note Due to limitations of the SANE API, this will function will return an empty string
161 * if reloadDevicesList() has not been called before.
162 */
163 QString deviceModel() const;
164
165 /**
166 * This function returns all available options when a device is opened.
167 * @return list containing pointers to all KSaneOptions provided by the backend.
168 * Becomes invalid when closing a device.
169 * The pointers must not be deleted by the client.
170 */
171 QList<Option *> getOptionsList();
172
173 /**
174 * This function returns a specific option.
175 * @param optionEnum the enum specifying the option.
176 * @return pointer to the KSaneOption. Returns a nullptr in case the options
177 * is not available for the currently opened device.
178 */
179 Option *getOption(OptionName optionEnum);
180
181 /**
182 * This function returns a specific option.
183 * @param optionName the internal name of the option defined by SANE.
184 * @return pointer to the KSaneOption. Returns a nullptr in case the options
185 * is not available for the currently opened device.
186 */
187 Option *getOption(const QString &optionName);
188
189 /**
190 * This method reads the available parameters and their values and
191 * returns them in a QMap (Name, value)
192 * @return map with the parameter names and their values.
193 */
194 QMap<QString, QString> getOptionsMap();
195
196 /**
197 * This method can be used to write many parameter values at once.
198 * @param options a QMap with the parameter names and values.
199 * @return This function returns the number of successful writes
200 * or -1 if scanning is in progress.
201 */
202 int setOptionsMap(const QMap<QString, QString> &options);
203
204 /**
205 * Gives direct access to the QImage that is used to store the image
206 * data retrieved from the scanner.
207 * Useful to display an in-progress image while scanning.
208 * When accessing the direct image pointer during a scan, the image
209 * must be locked before accessing the image and unlocked afterwards
210 * using the lockScanImage() and unlockScanImage() functions.
211 * @return pointer for direct access of the QImage data.
212 */
213 QImage *scanImage() const;
214
215 /**
216 * Locks the mutex protecting the QImage pointer of scanImage() from
217 * concurrent access during scanning.
218 */
219 void lockScanImage();
220
221 /**
222 * Unlocks the mutex protecting the QImage pointer of scanImage() from
223 * concurrent access during scanning. The scanning progress will blocked
224 * when lockScanImage() is called until unlockScanImage() is called.
225 */
226 void unlockScanImage();
227
228public Q_SLOTS:
229 /**
230 * This method is used to cancel a scan or prevent an automatic new scan.
231 */
232 void stopScan();
233
234 /**
235 * This method is used to start a scan.
236 * @note CoreInterface may return one or more images as a result of one invocation of this slot.
237 * If no more images are wanted stopScan() should be called in the slot handling the
238 * imageReady signal.
239 */
240 void startScan();
241
242Q_SIGNALS:
243 /**
244 * This signal is emitted when a final scan is ready.
245 * @param scannedImage is the QImage containing the scanned image data.
246 */
247 void scannedImageReady(const QImage &scannedImage);
248
249 /**
250 * This signal is emitted when the scanning has ended.
251 * @param status contains a ScanStatus status code.
252 * @param strStatus If an error has occurred this string will contain an error message.
253 * otherwise the string is empty.
254 */
256
257 /**
258 * This signal is emitted when the user is to be notified about something.
259 * @param type contains a ScanStatus code to identify the type of message (error/info/...).
260 * @param strStatus If an error has occurred this string will contain an error message.
261 * otherwise the string is empty.
262 */
264
265 /**
266 * This signal is emitted for progress information during a scan.
267 * @param percent is the percentage of the scan progress (0-100).
268 * A negative value indicates that a scan is being prepared.
269 */
270 void scanProgress(int percent);
271
272 /**
273 * This signal is emitted every time the device list is updated or
274 * after reloadDevicesList() is called.
275 * @param deviceList is a QList of KSane::DeviceInformation that contain the
276 * device name, model, vendor and type of the attached scanners.
277 * @note The list is only a snapshot of the current available devices. Devices
278 * might be added or removed/opened after the signal is emitted.
279 */
281
282 /**
283 * This signal is emitted when a hardware button is pressed.
284 * @param optionName is the untranslated technical name of the sane-option.
285 * @param optionLabel is the translated user visible label of the sane-option.
286 * @param pressed indicates if the value is true or false.
287 * @note The SANE standard does not specify hardware buttons and their behaviors,
288 * so this signal is emitted for sane-options that behave like hardware buttons.
289 * That is the sane-options are read-only and type boolean. The naming of hardware
290 * buttons also differ from backend to backend.
291 */
292 void buttonPressed(const QString &optionName, const QString &optionLabel, bool pressed);
293
294 /**
295 * This signal is emitted for the count down when in batch mode.
296 * @param remainingSeconds are the remaining seconds until the next scan starts.
297 */
298 void batchModeCountDown(int remainingSeconds);
299
300private:
301 std::unique_ptr<InterfacePrivate> d;
302};
303
304} // namespace KSaneCore
305
306#endif // KSANE_COREINTERFACE_H
This class provides the core interface for accessing the scan controls and options.
Definition interface.h:33
OptionName
This enumeration is used to obtain a specific option with getOption(KSaneOptionName).
Definition interface.h:62
void scannedImageReady(const QImage &scannedImage)
This signal is emitted when a final scan is ready.
ScanStatus
Enum defining the message level of the returned scan status string.
Definition interface.h:42
void availableDevices(const QList< DeviceInformation * > &deviceList)
This signal is emitted every time the device list is updated or after reloadDevicesList() is called.
void scanFinished(KSaneCore::Interface::ScanStatus status, const QString &strStatus)
This signal is emitted when the scanning has ended.
OpenStatus
Enum determining whether the scanner opened correctly.
Definition interface.h:51
void batchModeCountDown(int remainingSeconds)
This signal is emitted for the count down when in batch mode.
void userMessage(KSaneCore::Interface::ScanStatus status, const QString &strStatus)
This signal is emitted when the user is to be notified about something.
DeviceType
This enumeration is used to filter the devices found by SANE.
Definition interface.h:97
void scanProgress(int percent)
This signal is emitted for progress information during a scan.
void buttonPressed(const QString &optionName, const QString &optionLabel, bool pressed)
This signal is emitted when a hardware button is pressed.
A wrapper class providing access to the internal KSaneBaseOption to access all options provided by KS...
Definition option.h:29
Q_SCRIPTABLE CaptureState status()
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Tue Mar 26 2024 11:19:34 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.