-
Notifications
You must be signed in to change notification settings - Fork 15
/
maxview.cpp
305 lines (263 loc) · 7.53 KB
/
maxview.cpp
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
/*
Paper filing system GUI based on scanner
Large chunks of code taken from quiteinsane
Used and tested a lot with the Fujitsu backend
SANE_DEBUG_FUJITSU=30
Fujitsu buttons
function meaning action
1 scan perform a scan into current directory
2 sendto perform a scan into user's sendto directory
3
4
5
6
7
8
9
C copy scan and print to default printer, save to 'photocopy' folder
*/
#include <unistd.h>
#include <getopt.h>
#include <sys/resource.h>
#include <QDebug>
#include <QSettings>
#include <QTranslator>
#include "qapplication.h"
#include "qmessagebox.h"
#include "qsettings.h"
#include "config.h"
#include "desktopmodel.h"
#include "desktopwidget.h"
#include "dirmodel.h"
#include "mainwidget.h"
#include "mainwindow.h"
#include "md5.h"
#include "desk.h"
#include "maxview.h"
#include "op.h"
#include "test/test.h"
/*
extern "C" void rle_test (void);
extern "C" void decpp_set_debug (int d);
extern "C" void decpp_set_hack (int d);
extern "C" int test_main (void);
*/
#include "err.h"
static void usage (void)
{
printf ("maxview - An electronic filing cabinet: scan, print, stack, arrange\n\n");
printf ("(C) 2011 Simon Glass, [email protected], v%s\n\n",
CONFIG_version_str);
printf ("Usage: maxview <opts> <dir/file>\n\n");
printf (" -p|--pdf convert given file to .pdf\n");
printf (" -m|--max convert given file to .max\n");
printf (" -j|--jpeg convert given file to .jpg\n");
/*
printf (" -v|--verbose be verbose\n");
*/
printf (" -h|--help display this usage information\n");
printf (" -s|--sum do an md5 checksum on a directory\n");
/*
printf (" -d|--debug <n> set debug level (0-3)\n");
printf (" -f|--force force overwriting of existing file\n");
printf (" -r|--relocate move a processed file into a 'xxx.old' subdirectory\n");
printf (" -i|--info display full info about a file\n");
printf (" --index <f> build/update an index file f for the given directory\n");
*/
printf (" -t|--test run unit tests\n");
/*
printf ("\n");
printf ("If none of -p, -m, -j are specified, maxview opens in desktop "
"mode, displaying\nthumbails of the given directory\n");
*/
}
int main (int argc, char *argv[])
{
//bool verbose = false, force = false, reloc = false, hack = false;
//int debug = 0;
char *dir = 0;
bool need_gui = false;
// err_info *e;
static struct option long_options[] = {
// {"index", 0, 0, '1'},
{"help", 0, 0, 'h'},
{"jpg", 1, 0, 'j'},
/*
{"debug", 1, 0, 'd'},
{"force", 0, 0, 'f'},
{"info", 0, 0, 'i'},
*/
{"max", 1, 0, 'm'},
{"pdf", 1, 0, 'p'},
/*
{"relocate", 0, 0, 'r'},
*/
{"sum", 1, 0, 's'},
{"test", 0, 0, 't'},
/*
{"verbose", 0, 0, 'v'},
*/
{0, 0, 0, 0}
};
int op_type = -1, c;
QString index;
QString fname;
struct rlimit limit;
if (!getrlimit(RLIMIT_NOFILE, &limit) && limit.rlim_cur < 20000) {
qDebug() << "limit" << limit.rlim_cur;
limit.rlim_cur = 20000;
limit.rlim_cur = 20000;
if (setrlimit(RLIMIT_NOFILE, &limit))
qDebug() << "Setting nofile limit failed";
}
while (c = getopt_long (argc, argv, "hj:m:p:s:t",
long_options, NULL), c != -1)
switch (c)
{
case 's' :
dir = optarg;
op_type = c;
break;
case 'j' :
case 'm' :
case 'p' :
fname = optarg;
op_type = c;
break;
case 't' :
case 'i' :
op_type = c;
break;
case '1' :
op_type = c;
index = QString (optarg);
break;
case 'h' :
case '?' :
usage ();
return 1;
/*
case 'd' : debug = atoi (optarg); break;
case 'v' : verbose = true; break;
case 'f' : force = true; break;
case 'r' : reloc = true; break;
case 'z' : hack = true; break;
*/
}
if (!dir && op_type != 't' && op_type != 'p' && op_type != 'm' &&
op_type != 'j')
need_gui = true;
#ifdef Q_WS_X11
bool useGUI = getenv( "DISPLAY" ) != 0 && op_type == -1;
#else
bool useGUI = op_type == -1;
#endif
if (op_type == 't')
useGUI = true;
if (!need_gui && op_type == -1 && !useGUI)
{
printf ("** Warning: no display available for interactive mode\n");
printf ("Please either run in Gnome/KDE/X or set the DISPLAY variable\n\n");
usage ();
return 1;
}
if (need_gui && !useGUI)
{
usage ();
return 1;
}
QApplication app (argc, argv, useGUI);
QTranslator translator;
translator.load("maxview_en");
app.installTranslator(&translator);
QCoreApplication::setOrganizationName("maxview");
//QCoreApplication::setOrganizationDomain("bluewatersys.com");
QCoreApplication::setApplicationName("maxview");
switch (op_type)
{
case 's' :
{
QString mydir = QString (dir);
Desk *maxdesk = new Desk(mydir, QString());
err_info *err;
// decode everything in the given directory and checksum it
err = maxdesk->checksum();
if (err)
printf("checksum error: %s", err->errstr);
break;
}
case 't' :
{
#if 0
QString fname = QString (dir);
Desk maxdesk (QString(), QString());
dirmodel_tests ();
// maxdesk.runTests ();
// rle_test ();
// decode everything in the given directory and checksum it
// if (e = maxdesk.test_decomp_comp (fname), e)
// if (maxdesk.test_compare_with_tiff (fname))
// if (maxdesk.test (fname))
// printf ("test error %s\n", e->errstr);
#endif
// Drop the -t argument
#ifdef ENABLE_TEST
argv[argc--] = 0;
int result = test_run(argc, argv, &app);
if (result)
qInfo() << "Failed: " << result;
#else
qInfo() << "Use this to build with tests: qmake CONFIG+=test";
#endif
break;
}
case 'j' :
case 'm' :
case 'p' :
{
QDir mydir(fname);
mydir.cdUp();
Desk desk(dir, QString(), false);
File *file, *newfile;
Operation op("Convert file", 0, 0);
err_info *err;
file = desk.createFile(dir, fname);
err = file->load();
if (!err) {
QString leaf = QFileInfo(fname).completeBaseName();
File::e_type type = op_type == 'p' ? File::Type_pdf :
op_type == 'j' ? File::Type_jpeg :
File::Type_max;
err = file->duplicateToDesk(&desk, type, leaf, 3, op,
newfile);
}
if (err)
printf("error: %s", err->errstr);
break;
}
#if 0
case 'i' :
{
Desk maxdesk (QString(), QString(), false, false, false);
QString fname = QString (dir);
// decode print info on the file
e = maxdesk.dumpInfo (fname, debug);
if (e)
printf ("error: %s\n", e->errstr);
break;
}
#endif
case -1 :
QStringList args;
for (int i = 1; i < argc; i++)
args << argv[i];
Mainwindow::runGui(app, args);
#if 0
case 1 :
Desk maxdesk (QString(), QString());
QString fname = QString (dir);
// convert the file to PDF
maxdesk.buildIndex (index, fname);
#endif
}
}