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()
60 QProcessEnvironment env;
64 if (!engaugeLogFilenameAttempt (QCoreApplication::applicationDirPath(), pathAndFile)) {
65 if (!engaugeLogFilenameAttempt (env.value (
"HOME"), pathAndFile)) {
66 if (!engaugeLogFilenameAttempt (env.value (
"TEMP"), pathAndFile)) {
67 pathAndFile = ENGAUGE_LOG_FILE;
75 bool engaugeLogFilenameAttempt (
const QString &path,
81 pathAndFile = QString (
"%1%2%3")
83 .arg (QDir::separator())
84 .arg (ENGAUGE_LOG_FILE);
85 QFile file (pathAndFile);
86 if (file.open(QIODevice::WriteOnly | QIODevice::Text)) {
95 int main(
int argc,
char *argv[])
97 qRegisterMetaType<ColorFilterMode> (
"ColorFilterMode");
99 QApplication app(argc, argv);
105 bool isDebug, isGnuplot, isRegressionTest;
106 QString errorReportFile, fileCmdScriptFile;
107 QStringList loadStartupFiles;
118 initializeLogging (
"engauge",
119 engaugeLogFilename(),
121 LOG4CPP_INFO_S ((*mainCat)) <<
"main args=" << QApplication::arguments().join (
" ").toLatin1().data();
135 void parseCmdLine (
int argc,
138 QString &errorReportFile,
139 QString &fileCmdScriptFile,
140 bool &isRegressionTest,
142 QStringList &loadStartupFiles)
144 const int COLUMN_WIDTH = 20;
145 bool showUsage =
false;
148 bool nextIsErrorReportFile =
false;
149 bool nextIsFileCmdScript =
false;
153 errorReportFile =
"";
154 fileCmdScriptFile =
"";
155 isRegressionTest =
false;
158 for (
int i = 1; i < argc; i++) {
160 if (nextIsErrorReportFile) {
161 errorReportFile = argv [i];
162 showUsage |= !checkFileExists (errorReportFile);
163 nextIsErrorReportFile =
false;
164 }
else if (nextIsFileCmdScript) {
165 fileCmdScriptFile = argv [i];
166 showUsage |= !checkFileExists (fileCmdScriptFile);
167 nextIsFileCmdScript =
false;
168 }
else if (strcmp (argv [i], DASH_DEBUG.toLatin1().data()) == 0) {
170 }
else if (strcmp (argv [i], DASH_ERROR_REPORT.toLatin1().data()) == 0) {
171 nextIsErrorReportFile =
true;
172 }
else if (strcmp (argv [i], DASH_FILE_CMD_SCRIPT.toLatin1().data()) == 0) {
173 nextIsFileCmdScript =
true;
174 }
else if (strcmp (argv [i], DASH_GNUPLOT.toLatin1().data()) == 0) {
176 }
else if (strcmp (argv [i], DASH_HELP.toLatin1().data()) == 0) {
178 }
else if (strcmp (argv [i], DASH_REGRESSION.toLatin1().data()) == 0) {
179 isRegressionTest =
true;
180 }
else if (strncmp (argv [i], DASH.toLatin1().data(), 1) == 0) {
185 QString fileName = argv [i];
186 QFileInfo fInfo (fileName);
187 if (fInfo.isRelative()) {
188 fileName = fInfo.absoluteFilePath();
190 loadStartupFiles << fileName;
194 if (showUsage || nextIsErrorReportFile) {
196 cerr <<
"Usage: engauge " 197 <<
"[" << DASH_DEBUG.toLatin1().data() <<
"] " 198 <<
"[" << DASH_ERROR_REPORT.toLatin1().data() <<
" <file>] " 199 <<
"[" << DASH_FILE_CMD_SCRIPT.toLatin1().data() <<
" <file> " 200 <<
"[" << DASH_GNUPLOT.toLatin1().data() <<
"] " 201 <<
"[" << DASH_HELP.toLatin1().data() <<
"] " 202 <<
"[" << DASH_REGRESSION.toLatin1().data() <<
"] " 203 <<
"[<load_file1>] [<load_file2>] ..." << endl
204 <<
" " << DASH_DEBUG.leftJustified(COLUMN_WIDTH,
' ').toLatin1().data()
205 << QObject::tr (
"Enables extra debug information. Used for debugging").toLatin1().data() << endl
206 <<
" " << DASH_ERROR_REPORT.leftJustified(COLUMN_WIDTH,
' ').toLatin1().data()
207 << QObject::tr (
"Specifies an error report file as input. Used for debugging and testing").toLatin1().data() << endl
208 <<
" " << DASH_FILE_CMD_SCRIPT.leftJustified(COLUMN_WIDTH,
' ').toLatin1().data()
209 << QObject::tr (
"Specifies a file command script file as input. Used for debugging and testing").toLatin1().data() << endl
210 <<
" " << DASH_GNUPLOT.leftJustified(COLUMN_WIDTH,
' ').toLatin1().data()
211 << QObject::tr (
"Output diagnostic gnuplot input files. Used for debugging").toLatin1().data() << endl
212 <<
" " << DASH_HELP.leftJustified(COLUMN_WIDTH,
' ').toLatin1().data()
213 << QObject::tr (
"Show this help information").toLatin1().data() << endl
214 <<
" " << DASH_REGRESSION.leftJustified(COLUMN_WIDTH,
' ').toLatin1().data()
215 << QObject::tr (
"Executes the error report file or file command script. Used for regression testing").toLatin1().data() << endl
216 <<
" " << QString (
"<load file> ").leftJustified(COLUMN_WIDTH,
' ').toLatin1().data()
217 << 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...