-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathdesk.h
620 lines (462 loc) · 21.8 KB
/
desk.h
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
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
/*
License: GPL-2
An electronic filing cabinet: scan, print, stack, arrange
Copyright (C) 2009 Simon Glass, [email protected]
.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
.
This program 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 General Public License for more details.
.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
X-Comment: On Debian GNU/Linux systems, the complete text of the GNU General
Public License can be found in the /usr/share/common-licenses/GPL file.
*/
#ifndef __desk_h
#define __desk_h
#include <list>
#include <vector>
#include "qpoint.h"
#include "qsize.h"
#include "qstring.h"
#include <QPixmap>
#include "err.h"
class File;
class Operation;
class QFileInfo;
class QPixmap;
class QPoint;
class QImage;
class Measure;
class Paperstack;
struct max_page_info;
struct max_info;
#if 0
/** information about a single file on the desktop */
typedef struct file_info
{
QString filename; //!< filename within directory (not full path)
QString pathname; //!< full path name
QPoint pos; //!< current position on desktop
int pagenum; //!< current page visible
int pagecount; //!< number of pages
int size; //!< file size
QPixmap *pixmap; //!< preview image for this file
QSize preview_maxsize; //!< max preview size for file (this is the preview pixmap)
QSize title_maxsize; //!< max pixel size for file (stack) title
QSize pagename_maxsize; //!< max pixel size for all page titles
struct max_info *max; //!< max file info
time_t time; //!< last modification time
int order; //!< numerical order in list
QPoint ipos; //!< position of image
err_info serr; //!< place to put error
err_info *err; //!< last error which occured with this item
} file_info;
typedef struct filelist_info
{
std::vector <file_info> file;
int last;
} filelist_info;
#endif
class Desk
{
public:
/** read the maxdesk info from the given directory
\param dir the directory to read
\param rootdir the directory to contain the trash dir
\param readDesk true to read the maxdesk.ini file
*/
Desk(const QString &dir, const QString &rootdir, bool do_readDesk = true);
/** set up an empty temporary desk */
Desk (void);
//! destructor
~Desk ();
void clear (void);
/**
* @brief Add files from a directory which are not already present
* @param dirPath Patch to scan
*/
void addFiles(const QString &dirPath, Measure *meas);
/**
* @brief Add new filenames to a desk
* @param dirPath Common initial path for all matches, with trailing "/"
* @param matches List of filenames to add, each relative to dirPath
*/
void addMatches(const QString &dirPath, const QStringList& matche,
Measure *meas);
/** read the maxdesk.ini file which contains positional and size
information for each stack in the directory
\param read_sizes read the size information (otherwise it is
ignored and will be recalculated */
void readDesk (bool read_sizes = true);
/** write the maxdesk.ini file */
bool writeDesk (void);
// allocate and zero a new file structure
// file_info *alloc_file (void);
// operations we can do on files
enum operation_t
{
op_rotate,
op_hflip,
op_vflip,
op_count
};
/** create a new file of the correct type
\param dir directory
\param fname file name (the file extension determines the type) */
File *createFile (const QString &dir, const QString fname);
/** given a filename, try to make it unique by adding numbers, etc.
\param fname the original filename (excluding extension)
\param dir the directory to check (null for current)
\param ext the file extension with dot - e.g. ".max"
\param returns the unique filename (without extension or directory), or
null if nothing unique can be found (probably a
filesystem fault) */
QString findNextFilename (QString fname, QString dir = QString(), QString ext = QString());
/** adds a new file to a desk. The file is normally positioned
at the bottom of the view, but it is possible to place it next
to an existing file. In this case, fbase and seq should be provided
to indicate the existing file (for positioning only) and the sequence
number of this new file relative to it. Sequence number 0 will be on
top of the existing file, 1 will be offset slightly down and to the
right, etc.
\param fp the file to add
\param fbase base file to position against (0 to add at bottom)
\param seq sequence number relative to fbase
\returns the row number that the file was added to (normally the last one!) */
int newFile (File *fnew, File *fbase = 0, int seq = -1);
void removeRows (int row, int count);
/** get the directory this maxdesk relates to (full path)
\returns directory */
QString &dir (void);
QString &rootDir (void) { return _rootDir; }
File *takeAt (int row);
/** similar to the above but also returns the file position */
File *findFile (QString fileName, int &pos);
File *getFile (int itemnum);
int rowCount (void); //!< our 'official' record of row count
void updateRowCount (void); //!< update our official row count record
QString trashdir (void);
void arrangeBy (int type);
// Re-read the directory and .paperdesk file
void refresh();
/** rescan a file after it has been changed */
// err_info *rescanFile (file_info *f);
/** dispose of a file, but don't remove it from the list */
// void disposeFile (file_info *f);
//! start iterating and return the first file in the list
// file_info *first (void);
//! return the next file in the list
// file_info *next (void);
//! returns the n'th item in the list
// file_info *item (int n);
//! returns the number of files in the list
int fileCount (void);
#if 0
/** read a preview pixmap for page 'pagenum' of the file
\returns 0 if all ok, else -ve error value */
struct err_info *getPreviewPixmap (file_info *f, int pagenum, QString &title,
QPixmap &pixmap, int &bpp, bool blank);
/** read an image pixmap for page 'pagenum' of the file
\param f file to read
\param pagenum page number to read
\param pixmapp returns a new pixmap
\param Size returns display size of image (pixmap may be slightly
larger)
\param bpp returns number of bits per pixel in orginal image.
Note that the pixmap will generally be the same depth
as the current screen mode, i.e. normally 24bpp
\param smooth true if smoothing should be used to give a better
result (but slow!)
\returns true if all ok */
err_info *getImagePixmap (file_info *f, int pagenum,
QPixmap **pixmapp, QSize &Size, QSize &scaledSize, int &bpp, bool smooth = false);
struct err_info *getImageQImage (file_info *f, int pagenum, bool do_scale,
QImage **imagep, QSize &Size, QSize &trueSize, int &bpp);
err_info *getImageQImageRef (file_info *f, int pagenum, bool do_scale,
QImage &image, QSize &Size, QSize &trueSize, int &bpp, bool blank = false);
err_info *get_image_qimage_ref (max_info *max, int pagenum, bool do_scale,
QImage &image, QSize &Size, QSize &trueSize, int &bpp, bool blank);
err_info *get_image_qimage (max_info *max, int pagenum, bool do_scale,
QImage **imagep, QSize &Size, QSize &trueSize, int &bpp);
/** returns information about a page from a file
\param f file to read
\param pagenum page number to read
\param Size returns display size of image (pixmap may be slightly
larger)
\param trueSize returns pixmap size of image (includes required margins)
\param bpp returns number of bits per pixel in orginal image.
Note that the pixmap will generally be the same depth
as the current screen mode, i.e. normally 24bpp
\param csize returns compressed size of page image
\param dt return page timestamp
\returns error, or NULL if none */
struct err_info *getImageInfo (file_info *f, int pagenum,
QSize &Size, QSize &trueSize, int &bpp, int &csize, QDateTime &dt);
/** returns information about a preview of a page from a file
\param f file to read
\param pagenum page number to read
\param Size returns display size of preview
\param bpp returns number of bits per pixel in preview
\returns error, or NULL if none */
struct err_info *getPreviewInfo (file_info *f, int pagenum,
QSize &Size, int &bpp);
/** reads the OCR text from a page
\param f file to read
\param pagenum page number to read
\param str returns string containing OCR text */
struct err_info *getPageText (file_info *f, int pagenum, QString &str);
struct err_info *ensureMax (file_info *f);
#endif
/** decode all images in a directory, checksum them, and write the checksums to
a 'checksums' file
\\return true if all ok */
struct err_info *checksum (void);
/** adds a new stack to the maxdesk, returns true if ok
\param stack_name name of new stack
\param fnew returns pointer to new file
\param item returns item number of new file in the desk */
err_info *addPaperstack (const QString &stack_name, File *&fnew, int &item);
#if 0
/** simple test that compression and decompression work ok */
err_info *test_compare_with_tiff (QString &fname);
err_info *test1 (QString &fname);
err_info *test_decomp_comp (QString &fname);
/** stack the pages from fsrc into fdest */
struct err_info *stackItem (file_info *fdest, file_info *fsrc);
/** unstack the given page from the file, creating it as a new stack.
The position of this new stack will simply be at the end, unless 'seq'
is specified, in which case it will be relative to f, and 'seq'
positions offset from it
\param f stack to operate on
\param pagenum page number to unstack
\param remove true to remove the page (otherwise the old page is left alone)
\param fnewp returns pointer to new stack
\param newname returns the new filename chosen
\param seq sequence number we are up to (for positioning), -1 for none */
struct err_info *unstackPage (file_info *f, int pagenum, bool remove,
file_info **fnewp, QString &newname, int seq = -1);
/** unstack a range of pages from a stack, creating them as a new stack.
The position of this new stack will simply be at the end, unless 'seq'
is specified, in which case it will be relative to f, and 'seq'
positions offset from it
\param f stack to operate on
\param pagenum first page number to unstack
\param remove true to remove the pages (otherwise the old pages are left alone)
\param fnewp returns pointer to new stack
\param newname name to use for new stack, returns name chosen
\param pagecount number of pages to unstack */
err_info *unstackPages (file_info *f, int pagenum, bool remove,
file_info **fnewp, QString &newname, int pagecount);
/** remove a number of pages from a stack
The data returned in del_info can be passed to restorePages
\param f stack to operate on
\param pages page numbers to remove, bit n true means remove page n
\param del_info a place to put information about the deleted pages
\param count returns number of pages removed */
err_info *removePages (file_info *f, QBitArray &pages,
QByteArray &del_info, int &count);
/** restore a number of pages to a stack
The data in del_info must have been created from removePages()
\param f stack to operate on
\param pages page numbers to restore, bit n true means remove page n
see Desktopmodel::opUndeletePages() for more info
\param del_info a place with information about the deleted pages
\param count number of pages to restore */
err_info *restorePages (file_info *f, QBitArray &pages,
QByteArray &del_info, int count);
/** duplicate a stack, creating a new one just next to it
\param f stack to duplicate
\param *fnewp returns the duplicate
\param newname the name given to the new file
\returns error, or NULL if none */
err_info *duplicate (file_info *f, file_info **fnewp, QString &newname);
QString removeExtension (QString &fname, QString &ext);
err_info *copyFile (QString from, QString to);
/** remove a stack
\param f stack to remove
\returns error, or NULL if none */
err_info *remove (file_info *f);
/** move a stack to the trash. It may need to be renamed.
\param f stack to move to trash
\param trashname returns its new filename in the trash
\returns error, or NULL if none */
err_info *moveToTrash (file_info *f, QString &trashname);
#endif
err_info *deleteFromTrash (QString &trashname);
err_info *deleteFromDir (QString &src, QString &trashname);
/** move a stack from the trash. It may need to be renamed
\param trashname filename to move
\param filename desired new filename (updated on return)
\param fnew returns the resulting stack
\returns error, or NULL if none */
err_info *moveFromTrash (QString &trashname, QString &filename,
File *&fnew);
#if 0 //p
/** move a stack to a new directory. Note that the stack may need to be
renamed if a stack with the same name already exists in that
directory
\param f stack to move
\param newDir new directory to send to (QString() for trash)
\param newName returns the new name
\returns error, or NULL if none */
err_info *move (file_info *f, QString &newDir, QString &newName);
#endif
/** move a stack from a source directory. It may need to be renamed
\param src source directory
\param trashname filename to move
\param filename desired new filename (updated on return)
\param fnew returns the resulting stack
\returns error, or NULL if none */
err_info *moveFromDir (QString &src, QString &trashname, QString &filename,
File *&fnew);
#if 0//p
err_info *viewFile (file_info *f);
/** duplicate a file f as a .max file, returning it in fnewp
\param f file to duplicate
\param *fnewp returns point to the duplicate created
\returns error, or NULL if none */
err_info *duplicateMax (file_info *f, int odd_even, file_info **fnewp,
Operation &op, QString &newname);
/** duplicate a file f as a .pdf file, returning it in fnewp */
err_info *duplicatePdf (file_info *f, file_info **fnewp, Operation &op, QString &newname);
/** duplicate a file f as a .tiff file, returning it in fnewp */
err_info *duplicateTiff (file_info *f, file_info **fnewp, Operation &op, QString &newname);
/** add a page to a file
\param flush flush the max file to disc */
err_info *addPage (file_info *file, const struct max_page_info *mp, bool flush);
/** flush an item, ensuring it is updated on disc */
err_info *flushItem (file_info *file);
/** rename an item
\param f item to rename
\param name new name, including extension (but not directory)
\param auto_rename automatically rename the file if there is already
one in the directory by the same name */
err_info *rename (file_info *f, QString &name, bool auto_rename = false);
/** rename a page
\param f item to rename
\param pagenum page number to rename
\param name new name, including extension (but not directory) */
err_info *renamePage (file_info *f, int pagenum, QString &name);
/** convert a file to .pdf format, leaving the old file there */
err_info *convertPdf (QString &old);
/** convert a file to .max format, and check that it is correct
\param odd_even which pages to duplicate: 1 = even, 2 = odd, 3 = both */
err_info *convertMax (QString &old, QString newf, bool verbose,
bool force, bool reloc, int odd_even = 3);
err_info *convert_to_pdf (max_info *max, QString fname, Operation *op);
/** dump information about a file */
err_info *dumpInfo (QString &fname, int debug_level);
/** perform an operation on a file */
err_info *operation (file_info *f, int pagenum, operation_t type, int ival);
err_info *do_convert (QImage *image, QImage &newimage,
operation_t type, int ival);
err_info *convert_to_jpeg (max_info *max, QString fname,
int pagenum, Operation *op);
err_info *convertJpeg (QString &old);
// err_info *buildIndex (QString fname, QString dir);
#endif
/** sets the debug level to use for newly created max files */
void setDebugLevel (int level);
#if 0
/** returns the file before 'old' in the list */
file_info *findPrevFile (file_info *old);
/** returns the file after 'old' in the list */
file_info *findNextFile (file_info *old);
/** run some tests on Desk */
void runTests (void);
#endif
/** set whether to allow dispose or not */
void setAllowDispose (bool allow);
/** set whether to allow dispose or not */
bool getAllowDispose (void);
#if 0 //p
/** get strings from the annotation block
\param f file
\param type annotation type (MAXA_...) */
QString getAnnot (file_info *f, int type);
/** returns the title of the a page
\param pagenum page number to look up (-1 for current)
*/
QString getPageTitle (file_info *f, int pagenum = -1);
/** figure out the next position to place a stack */
void detectNextPosition (void);
#endif
/** indicate that the desk is dirty and must be written back to the
filesystem */
void dirty (void);
/** flush the desk to the filesystem */
void flush (void);
/** advance the current position to the next free space */
void advance (void);
void addFromDir(const QString& inPath, Measure *meas);
private:
/** check if a file exists in a maxdesk
\param fileName File to search for
\returns pointer to file info if found, else NULL */
File *findFile (QString fileName);
//! set up some things for a new desk
void setup (void);
/** advance the current position by one space */
void advanceOne (void);
/** ensure there is enough space in the current row, or move to next */
void ensureSpace(int width);
/** advance by the given width, moving to next row if needed */
void advanceBy(int width);
/** reset the position to the start */
void resetPos (void);
/** returns true if the given position clashes with any existing item */
bool clashes (QPoint &pos);
bool addToExistingFile (QString &fname);
#if 0
err_info *scan_file (QString dir_name, QFileInfo *fi,
filelist_info &old, filelist_info &file);
file_info *find_file (filelist_info &fl, QString &fname);
err_info *scan_dir (QString dir_name, filelist_info &old,
filelist_info &file);
/** internal test: that incrementing the first string results in the second */
void testInc (QString in, QString out);
/** colour the image slighty to show it as blue
\param image image to colour*/
void colour_image_for_blank (QImage &image);
#endif // 0
/**
* @brief add a new file to the structure and position it
* @param fname Filename of file to add (without path)
* @param dir Full path of the directory containing the file,
* with trailing "/"
* @param meas Measurer for text
*
* This function does nothing if the file is already present
*/
void addFile(const QString& fname, const QString& dir,
Measure *mes = nullptr);
private:
QList<File *> _files;
int _row_count; //!< number of files last time we checked
// std::list<file_info *> _file;
// std::list<file_info *>::iterator _it;
QString _dir; //!< directory the files are in
QString _rootDir; //!< root directory for this model (where trash is)
QPoint _pos; //!< next position for a file to appear
int _rightMargin; //!< right margin for items
int _debug_level; //!< the debug level to use for max debugging
struct debug_info *_debug; //!< debug settings to pass max decoder
bool _do_writeDesk; //!< true to write back the maxdesk.ini file
bool _allow_dispose; //!< whether to allow disposal of this maxdesk (just a flag for clients)
/* these fields help with positioning of a number of newly created files
with respect to an existing base file. Here we keep track of the
sequence number we are up to, and the position */
QPoint _fbase_pos; //!< current position to use with respect to base file
int _fbase_seq; //!< current sequence number with respect to base file (0 for none)
QString _trash_dir; //!< current trash directory
bool _dirty; //!< true if the desk has been changed and we must write it back
};
#endif