1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
|
/* This file is part of the KDE Project
Copyright (C) 1999 Klaas Freitag <freitag@suse.de>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#ifndef _KSCANDEV_H_
#define _KSCANDEV_H_
#include <tqwidget.h>
#include <tqasciidict.h>
#include <tqsize.h>
#include <tqobject.h>
#include <tqstrlist.h>
#include <tqsocketnotifier.h>
#include "kscanoption.h"
#include "kscanoptset.h"
#define DEFAULT_OPTIONSET "saveSet"
#define SCANNER_DB_FILE "scannerrc"
class ImgScanInfo;
extern "C" {
#include <sane/sane.h>
#include <sane/saneopts.h>
}
/**
* This is KScanDevice, a class for accessing the SANE scanning functions under KDE
*
* @short KScanDevice
* @author Klaas Freitag
* @version 0.1alpha
*
*/
typedef enum {
SSTAT_SILENT, SSTAT_IN_PROGRESS, SSTAT_NEXT_FRAME, SSTAT_STOP_NOW, STTAT_STOP_ADF_FINISHED
} SCANSTATUS;
/**
* KScanStat
* shows the status of a KScan operation
**/
class KScanDevice : public TQObject
{
Q_OBJECT
TQ_OBJECT
/* Hmmm - No TQ_PROPS ? */
public:
/**
* KScanDevice - the KDE Scanner Device
* constructor. Does not much.
*
* @see openDevice
*
*/
KScanDevice( TQObject *parent = 0 );
/**
* Destructor
*
* releases internal allocated memory.
*/
~KScanDevice( );
/**
* opens the device named backend.
* @return the state of the operation
* @param backend: the name of the backend to open
*/
KScanStat openDevice( const TQCString& backend );
/**
* returns the names of all existing Scan Devices in the system.
* @param enable_net: allow net devices.
* @return a TQStrList of available Scanners in the system
* @see KScanDevice
*/
TQStrList getDevices( ) const
{ return( scanner_avail ); }
/**
* returns the short, technical name of the currently attached backend.
* It is in the form 'umax:/dev/sg1'.
*/
TQCString shortScannerName() const { return scanner_name; }
/**
* returns a long, human readable name of the scanner, like
* 'Mustek SP1200 Flatbed scanner'. The parameter name takes
* the name of a backend, what means something like "/dev/scanner".
* If the name of the backend is skipped, the selected backend is
* returned.
*
* @param a TQString with a backend string
* @return a TQString containing a human readable scanner name
**/
TQString getScannerName( const TQCString& name = 0 ) const;
/*
* ========= Preview Functions ==========
*/
/**
* TQImage * acquirePreview( bool forceGray = 0, int dpi = 0 )
*
* acquires a preview on the selected device. KScanDevice allocs
* memory for the qimage returned. This qimage remains valid
* until the next call to acquirePreview or until KScanDevice is
* destructed.
*
* @return a pointer to a qimage or null on error
* @param bool forceGray if true, acquire a preview in gray
* @param int dpi dpi setting. If 0, the dpi setting is
* elected by the object, e.g. is the smallest possible
* resolution.
*/
KScanStat acquirePreview( bool forceGray = 0, int dpi = 0 );
/** acquires a qimage on the given settings.
* the Parameter image needs to point to a object qimage,
* which is filled by the SANE-Dev. After the function returns,
* the qimage is valid, if the returnvalue is OK.
* @param TQImage *image - Pointer to a reserved image
* @return the state of the operation in KScanStat
*/
KScanStat acquire( const TQString& filename = TQString() );
/**
* returns the default filename of the preview image of this scanner.
* @return default filename
**/
const TQString previewFile();
/**
* loads the last saved previewed image on this device from the default file
* @return a bitmap as TQImage
**/
TQImage loadPreviewImage();
/**
* saves current previewed image from this device to the default file
* @param image current preview image which should be saved
* @return true if the saving was sucessful
**/
bool savePreviewImage( const TQImage& image );
/*
* ========= List Functions ==========
*/
/**
* returns all existing options of the selected device.
* @see openDevice
* @return a TQStrList with the names of all options
**/
TQStrList getAllOptions();
/**
* returns the common options of the device. A frontend should
* display the returned options in a convinient way and easy to
* use.
* @see getAllOptions
* @see getAdvancedOptions
* @return a TQStrList with with names of the common options.
*/
TQStrList getCommonOptions();
/**
* returns a list of advanced scan options. A frontend should
* display these options in a special dialog.
* @see getAllOptions
* @see getCommonOptions
* @return a TQStrList with names of advanced scan options.
*/
TQStrList getAdvancedOptions();
/**
* retrieves a set of the current scan options and writes them
* to the object pointed to by parameter optSet
* @see KScanOptSet
* @param optSet, a pointer to the option set object
*/
void getCurrentOptions( KScanOptSet *optSet );
/**
* load scanner parameter sets. All options stored in @param optSet
* are loaded into the scan device.
*/
void loadOptionSet( KScanOptSet *optSet );
/**
* applys the values in an scan-option object. The value to
* set must be set in the KScanOption object prior. However,
* it takes effect after being applied with this function.
* @see KScanOption
* @return the status of the operation
* @param a scan-option object with the scanner option to set and
* an optional boolean parameter if it is a gamma table.
**/
KScanStat apply( KScanOption *opt, bool=false );
/**
* returns true if the option exists in that device.
* @param name: the name of a option from a returned option-List
* @return true, if the option exists
*/
bool optionExists( const TQCString& name );
/**
* checks if the backend knows the option with the required name under
* a different name, like some backends do. If it does, the known name
* is returned, otherwise a null TQCString.
*/
TQCString aliasName( const TQCString& name );
/**
* returns a Widget suitable for the selected Option and creates the
* KScanOption. It is internally connected to the scan device, every
* change to the widget is automaticly considered by the scan device.
* @param name: Name of the SANE Option
* @param parent: pointer to the parent widget
* @param desc: pointer to the text appearing as widget text
* @param tooltip: tooltip text. If zero, the SANE text will be used.
**/
KScanOption *getGuiElement( const TQCString& name, TQWidget *parent,
const TQString& desc = TQString(),
const TQString& tooltip = TQString() );
/**
* returns the pointer to an already created Scanoption from the
* gui element list. Cares for option name aliases.
*/
KScanOption *getExistingGuiElement( const TQCString& name );
/**
* sets an widget of the named option enabled/disabled
**/
void guiSetEnabled( const TQCString& name, bool state );
/**
* returns the maximum scan size. This is interesting e.g. for the
* preview widget etc.
* The unit of the return value is millimeter, if the sane backend
* returns millimeter. (TODO)
**/
TQSize getMaxScanSize( void ) const;
/**
* returns the information bit stored for the currently attached scanner
* identified by the key.
*/
TQString getConfig( const TQString& key, const TQString& def = TQString() ) const;
static bool scanner_initialised;
static SANE_Handle scanner_handle;
static TQAsciiDict<int>* option_dic;
static SANE_Device const **dev_list;
static KScanOptSet *gammaTables;
public slots:
void slOptChanged( KScanOption* );
/**
* The setting of some options require a complete reload of all
* options, because they might have changed. In that case, slot
* slReloadAll() is called.
**/
void slReloadAll( );
/**
* This slot does the same as ReloadAll, but it does not reload
* the scanner option given as parameter. This is useful to make
* sure that no recursion takes places during reload of options.
**/
void slReloadAllBut( KScanOption*);
/**
* Notifies the scan device to stop the current scanning.
* This slot only makes sense, if a scan is in progress.
* Note that if the slot is called, it can take a few moments
* to stop the scanning
*/
void slStopScanning( void );
/**
* Image ready-slot in asynchronous scanning
*/
void slScanFinished( KScanStat );
/**
* Save the current configuration parameter set. Only changed options are saved.
**/
void slSaveScanConfigSet( const TQString&, const TQString& );
void slSetDirty( const TQCString& name );
/**
* Closes the scan device and frees all related data, makes
* the system ready to open a new, other scanner.
*/
void slCloseDevice( );
/**
* stores the info bit in a config file for the currently connected
* scanner. For this, the config file $TDEHOME/.kde/share/config/scannerrc
* is opened, a group is created that identifies the scanner and the
* device where it is connected. The information is stored into that group.
*/
void slStoreConfig( const TQString&, const TQString& );
signals:
/**
* emitted, if an option change was applied, which made other
* options changed. The application may connect a slot to this
* signal to see, if other options became active/inactive.
**/
void sigOptionsChanged();
/**
* emitted, if an option change was applied, which made the
* scan parameters change. The parameters need to be reread
* by sane_get_parameters().
**/
void sigScanParamsChanged();
/**
* emitted if a new image was acquired. The image has to be
* copied in the signal handler.
*/
void sigNewImage( TQImage*, ImgScanInfo* );
/**
* emitted if a new preview was acquired. The image has to be
* copied in the signal handler.
*/
void sigNewPreview( TQImage*, ImgScanInfo* );
/**
* emitted to tell the application the start of scanning. That is
* before the enquiry of the scanner starts. Between this signal
* and @see sigScanProgress(0) can be some time consumed by a scanner
* warming up etc.
*/
void sigScanStart();
/**
* signal to indicate the start of acquireing data. It is equal
* to @see sigScanProgress emitted with value 0 and thus it is sent
* after sigScanStart.
* The time between sigScanStart and sigAcquireStart differs very much
* from scanner to scanner.
*/
void sigAcquireStart();
/**
* emitted to tell the application the progress of the scanning
* of one page. The final value is always 1000. The signal is
* emitted for zero to give the change to initialize the progress
* dialog.
**/
void sigScanProgress( int );
/**
* emitted to show that a scan finished and provides a status how
* the scan finished.
*/
void sigScanFinished( KScanStat );
/**
* emitted to give all objects using this device to free all dependencies
* on the scan device, because this signal means, that the scan device is
* going to be closed. The can not be stopped. All receiving objects have
* to free their stuff using the device and pray. While handling the signal,
* the device is still open and valid.
*/
void sigCloseDevice( );
private slots:
/**
* Slot to acquire a whole image */
void doProcessABlock( void );
private:
/**
* Function which applies all Options which need to be applied.
* See SANE-Documentation Table 4.5, description for SANE_CAP_SOFT_DETECT.
* The function sets the options which have SANE_CAP_AUTOMATIC set,
* to autmatic adjust.
**/
void prepareScan( void );
KScanStat createNewImage( SANE_Parameters *p );
// not implemented
// TQWidget *entryField( TQWidget *parent, const TQString& text,
// const TQString& tooltip );
KScanStat find_options(); // help fct. to process options
KScanStat acquire_data( bool isPreview = false );
TQStrList scanner_avail; // list of names of all scan dev.
TQStrList option_list; // list of names of all options
TQStrList dirtyList; // option changes
inline TQString optionNotifyString(int) const;
TQPtrList<KScanOption> gui_elements;
TQAsciiDict<SANE_Device> scannerDevices;
TQSocketNotifier *sn;
SCANSTATUS scantqStatus;
/* Data for the scan process */
/* This could/should go to a small help object */
TQCString scanner_name;
SANE_Byte *data;
TQImage *img;
SANE_Parameters sane_scan_param;
long overall_bytes;
int rest_bytes;
int pixel_x, pixel_y;
bool scanningPreview;
KScanOptSet *storeOptions;
class KScanDevicePrivate;
KScanDevicePrivate *d;
};
#endif
|