7 #include "ColorFilterMode.h"
10 #include "MainWindow.h"
11 #include <QApplication>
12 #include <QCoreApplication>
17 #include <QProcessEnvironment>
18 #include "TranslatorContainer.h"
22 const QString CMD_DEBUG (
"debug");
23 const QString CMD_ERROR_REPORT (
"errorreport");
24 const QString CMD_FILE_CMD_SCRIPT (
"filecmdscript");
25 const QString CMD_GNUPLOT (
"gnuplot");
26 const QString CMD_HELP (
"help");
27 const QString CMD_REGRESSION (
"regression");
28 const QString DASH (
"-");
29 const QString DASH_DEBUG (
"-" + CMD_DEBUG);
30 const QString DASH_ERROR_REPORT (
"-" + CMD_ERROR_REPORT);
31 const QString DASH_FILE_CMD_SCRIPT (
"-" + CMD_FILE_CMD_SCRIPT);
32 const QString DASH_GNUPLOT (
"-" + CMD_GNUPLOT);
33 const QString DASH_HELP (
"-" + CMD_HELP);
34 const QString DASH_REGRESSION (
"-" + CMD_REGRESSION);
35 const QString ENGAUGE_LOG_FILE (
"engauge.log");
38 bool checkFileExists (
const QString &file);
39 QString engaugeLogFilename ();
40 bool engaugeLogFilenameAttempt (
const QString &path,
41 QString &pathAndFile);
42 void parseCmdLine (
int argc,
45 QString &errorReportFile,
46 QString &fileCmdScriptFile,
47 bool &isRegressionTest,
49 QStringList &loadStartupFiles);
52 bool checkFileExists (
const QString &file)
54 QFileInfo check (file);
55 return check.exists() && check.isFile();
58 QString engaugeLogFilename()
63 QProcessEnvironment env;
66 if (!engaugeLogFilenameAttempt (QCoreApplication::applicationDirPath(), pathAndFile)) {
67 if (!engaugeLogFilenameAttempt (env.value (
"HOME"), pathAndFile)) {
68 if (!engaugeLogFilenameAttempt (env.value (
"TEMP"), pathAndFile)) {
69 pathAndFile = ENGAUGE_LOG_FILE;
78 bool engaugeLogFilenameAttempt (
const QString &path,
84 pathAndFile = QString (
"%1%2%3")
86 .arg (QDir::separator())
87 .arg (ENGAUGE_LOG_FILE);
88 QFile file (pathAndFile);
89 if (file.open(QIODevice::WriteOnly | QIODevice::Text)) {
98 int main(
int argc,
char *argv[])
100 qRegisterMetaType<ColorFilterMode> (
"ColorFilterMode");
102 QApplication app(argc, argv);
108 bool isDebug, isGnuplot, isRegressionTest;
109 QString errorReportFile, fileCmdScriptFile;
110 QStringList loadStartupFiles;
121 initializeLogging (
"engauge",
122 engaugeLogFilename(),
124 LOG4CPP_INFO_S ((*mainCat)) <<
"main args=" << QApplication::arguments().join (
" ").toLatin1().data();
138 void parseCmdLine (
int argc,
141 QString &errorReportFile,
142 QString &fileCmdScriptFile,
143 bool &isRegressionTest,
145 QStringList &loadStartupFiles)
147 const int COLUMN_WIDTH = 20;
148 bool showUsage =
false;
151 bool nextIsErrorReportFile =
false;
152 bool nextIsFileCmdScript =
false;
156 errorReportFile =
"";
157 fileCmdScriptFile =
"";
158 isRegressionTest =
false;
161 for (
int i = 1; i < argc; i++) {
163 if (nextIsErrorReportFile) {
164 errorReportFile = argv [i];
165 showUsage |= !checkFileExists (errorReportFile);
166 nextIsErrorReportFile =
false;
167 }
else if (nextIsFileCmdScript) {
168 fileCmdScriptFile = argv [i];
169 showUsage |= !checkFileExists (fileCmdScriptFile);
170 nextIsFileCmdScript =
false;
171 }
else if (strcmp (argv [i], DASH_DEBUG.toLatin1().data()) == 0) {
173 }
else if (strcmp (argv [i], DASH_ERROR_REPORT.toLatin1().data()) == 0) {
174 nextIsErrorReportFile =
true;
175 }
else if (strcmp (argv [i], DASH_FILE_CMD_SCRIPT.toLatin1().data()) == 0) {
176 nextIsFileCmdScript =
true;
177 }
else if (strcmp (argv [i], DASH_GNUPLOT.toLatin1().data()) == 0) {
179 }
else if (strcmp (argv [i], DASH_HELP.toLatin1().data()) == 0) {
181 }
else if (strcmp (argv [i], DASH_REGRESSION.toLatin1().data()) == 0) {
182 isRegressionTest =
true;
183 }
else if (strncmp (argv [i], DASH.toLatin1().data(), 1) == 0) {
188 QString fileName = argv [i];
189 QFileInfo fInfo (fileName);
190 if (fInfo.isRelative()) {
191 fileName = fInfo.absoluteFilePath();
193 loadStartupFiles << fileName;
197 if (showUsage || nextIsErrorReportFile) {
199 cerr <<
"Usage: engauge "
200 <<
"[" << DASH_DEBUG.toLatin1().data() <<
"] "
201 <<
"[" << DASH_ERROR_REPORT.toLatin1().data() <<
" <file>] "
202 <<
"[" << DASH_FILE_CMD_SCRIPT.toLatin1().data() <<
" <file> "
203 <<
"[" << DASH_GNUPLOT.toLatin1().data() <<
"] "
204 <<
"[" << DASH_HELP.toLatin1().data() <<
"] "
205 <<
"[" << DASH_REGRESSION.toLatin1().data() <<
"] "
206 <<
"[<load_file1>] [<load_file2>] ..." << endl
207 <<
" " << DASH_DEBUG.leftJustified(COLUMN_WIDTH,
' ').toLatin1().data()
208 << QObject::tr (
"Enables extra debug information. Used for debugging").toLatin1().data() << endl
209 <<
" " << DASH_ERROR_REPORT.leftJustified(COLUMN_WIDTH,
' ').toLatin1().data()
210 << QObject::tr (
"Specifies an error report file as input. Used for debugging and testing").toLatin1().data() << endl
211 <<
" " << DASH_FILE_CMD_SCRIPT.leftJustified(COLUMN_WIDTH,
' ').toLatin1().data()
212 << QObject::tr (
"Specifies a file command script file as input. Used for debugging and testing").toLatin1().data() << endl
213 <<
" " << DASH_GNUPLOT.leftJustified(COLUMN_WIDTH,
' ').toLatin1().data()
214 << QObject::tr (
"Output diagnostic gnuplot input files. Used for debugging").toLatin1().data() << endl
215 <<
" " << DASH_HELP.leftJustified(COLUMN_WIDTH,
' ').toLatin1().data()
216 << QObject::tr (
"Show this help information").toLatin1().data() << endl
217 <<
" " << DASH_REGRESSION.leftJustified(COLUMN_WIDTH,
' ').toLatin1().data()
218 << QObject::tr (
"Executes the error report file or file command script. Used for regression testing").toLatin1().data() << endl
219 <<
" " << QString (
"<load file> ").leftJustified(COLUMN_WIDTH,
' ').toLatin1().data()
220 << QObject::tr (
"File(s) to be imported or opened at startup").toLatin1().data() << endl;
Class that stores QTranslator objects for the duration of application execution.
Main window consisting of menu, graphics scene, status bar and optional toolbars as a Single Document...