1 /*
2 Copyright © 2008-13 Qtrac Ltd. All rights reserved.
3 This program or module is free software: you can redistribute it
4 and/or modify it under the terms of the GNU General Public License
5 as published by the Free Software Foundation, either version 2 of
6 the License, or (at your option) any later version. This program is
7 distributed in the hope that it will be useful, but WITHOUT ANY
8 WARRANTY; without even the implied warranty of MERCHANTABILITY or
9 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
10 for more details.
11 */
12
13 #include "mainwindow.hpp"
14 #include <QApplication>
15 #include <QIcon>
16 #include <QLibraryInfo>
17 #include <QLocale>
18 #include <QSettings>
19 #include <QTextCodec>
20 #include <QTextStream>
21 #include <QTranslator>
22
23
main(int argc,char * argv[])24 int main(int argc, char *argv[])
25 {
26 QApplication app(argc, argv);
27 #ifdef Q_WS_MAC
28 app.setCursorFlashTime(0);
29 #endif
30 app.setOrganizationName("Qtrac Ltd.");
31 app.setOrganizationDomain("qtrac.eu");
32 app.setApplicationName("DiffPDF");
33 app.setWindowIcon(QIcon(":/icon.png"));
34
35 QTextStream out(stdout);
36 QStringList args = app.arguments().mid(1);
37 QSettings settings;
38 InitialComparisonMode comparisonMode = static_cast<
39 InitialComparisonMode>(settings.value("InitialComparisonMode",
40 CompareWords).toInt());
41 const QString LanguageOption = "--language=";
42 QString filename1;
43 QString filename2;
44 QString language = QLocale::system().name();
45 bool optionsOK = true;
46 Debug debug = DebugOff;
47 foreach (const QString arg, args) {
48 if (optionsOK && (arg == "--appearance" || arg == "-a"))
49 comparisonMode = CompareAppearance;
50 else if (optionsOK && (arg == "--characters" || arg == "-c"))
51 comparisonMode = CompareCharacters;
52 else if (optionsOK && (arg == "--words" || arg == "-w"))
53 comparisonMode = CompareWords;
54 else if (optionsOK && arg.startsWith(LanguageOption))
55 language = arg.mid(LanguageOption.length());
56 else if (optionsOK && (arg == "--help" || arg == "-h")) {
57 out << "usage: diffpdf [options] [file1.pdf [file2.pdf]]\n\n"
58 "A GUI program that compares two PDF files and shows "
59 "their differences.\n"
60 "\nThe files are optional and are normally set "
61 "through the user interface.\n\n"
62 "options:\n"
63 "--help -h show this usage text and terminate "
64 "(run the program without this option and press F1 for "
65 "online help)\n"
66 "--appearance -a set the initial comparison mode to "
67 "Appearance\n"
68 "--characters -c set the initial comparison mode to "
69 "Characters\n"
70 "--words -w set the initial comparison mode to "
71 "Words\n"
72 "--language=xx set the program to use the given "
73 "translation language, e.g., en for English, cz for "
74 "Czech; English will be used if there is no translation "
75 "available\n"
76 "--debug=2 write the text fed to the sequence "
77 "matcher into temporary files (e.g., /tmp/page1.txt "
78 "etc.)\n"
79 "--debug=3 as --debug=3 but also includes "
80 "coordinates in y, x order\n"
81 "\nRun the program without the --help option and click "
82 "About to see copyright and license details\n"
83 ;
84 return 0;
85 }
86 else if (optionsOK && (arg == "--debug" || arg == "--debug=1" ||
87 arg == "--debug1"))
88 ; // basic debug mode currently does nothing (did show zones)
89 else if (optionsOK && (arg == "--debug=2" || arg == "--debug2"))
90 debug = DebugShowTexts;
91 else if (optionsOK && (arg == "--debug=3" || arg == "--debug3"))
92 debug = DebugShowTextsAndYX;
93 else if (optionsOK && arg == "--")
94 optionsOK = false;
95 else if (filename1.isEmpty() && arg.toLower().endsWith(".pdf"))
96 filename1 = arg;
97 else if (filename2.isEmpty() && arg.toLower().endsWith(".pdf"))
98 filename2 = arg;
99 else
100 out << "unrecognized argument '" << arg << "'\n";
101 }
102
103 QTranslator qtTranslator;
104 qtTranslator.load("qt_" + language,
105 QLibraryInfo::location(QLibraryInfo::TranslationsPath));
106 app.installTranslator(&qtTranslator);
107 QTranslator appTranslator;
108 appTranslator.load("diffpdf_" + language, ":/");
109 app.installTranslator(&appTranslator);
110
111 MainWindow window(debug, comparisonMode, filename1, filename2,
112 language.left(2)); // We want de not de_DE etc.
113 window.show();
114 return app.exec();
115 }
116
117