7 #include "ColorFilterMode.h" 8 #include "FittingCurveCoefficients.h" 11 #include "MainWindow.h" 12 #include <QApplication> 13 #include <QCoreApplication> 18 #include <QProcessEnvironment> 19 #include <QStyleFactory> 20 #include "TranslatorContainer.h" 24 const QString CMD_DEBUG (
"debug");
25 const QString CMD_ERROR_REPORT (
"errorreport");
26 const QString CMD_FILE_CMD_SCRIPT (
"filecmdscript");
27 const QString CMD_GNUPLOT (
"gnuplot");
28 const QString CMD_HELP (
"help");
29 const QString CMD_REGRESSION (
"regression");
30 const QString CMD_RESET (
"reset");
31 const QString CMD_STYLES (
"styles");
32 const QString DASH (
"-");
33 const QString DASH_DEBUG (
"-" + CMD_DEBUG);
34 const QString DASH_ERROR_REPORT (
"-" + CMD_ERROR_REPORT);
35 const QString DASH_FILE_CMD_SCRIPT (
"-" + CMD_FILE_CMD_SCRIPT);
36 const QString DASH_GNUPLOT (
"-" + CMD_GNUPLOT);
37 const QString DASH_HELP (
"-" + CMD_HELP);
38 const QString DASH_REGRESSION (
"-" + CMD_REGRESSION);
39 const QString DASH_RESET (
"-" + CMD_RESET);
40 const QString DASH_STYLES (
"-" + CMD_STYLES);
41 const QString ENGAUGE_LOG_FILE (
"engauge.log");
44 bool checkFileExists (
const QString &file);
45 QString engaugeLogFilename ();
46 bool engaugeLogFilenameAttempt (
const QString &path,
47 QString &pathAndFile);
48 void parseCmdLine (
int argc,
52 QString &errorReportFile,
53 QString &fileCmdScriptFile,
54 bool &isErrorReportRegressionTest,
56 QStringList &loadStartupFiles);
57 void showStylesAndExit ();
60 bool checkFileExists (
const QString &file)
62 QFileInfo check (file);
63 return check.exists() && check.isFile();
66 QString engaugeLogFilename()
70 #if !defined(OSX_RELEASE) && !defined(WIN_RELEASE) && !defined(APPIMAGE_RELEASE) 71 QProcessEnvironment env;
74 if (!engaugeLogFilenameAttempt (QCoreApplication::applicationDirPath(), pathAndFile)) {
75 if (!engaugeLogFilenameAttempt (env.value (
"HOME"), pathAndFile)) {
76 if (!engaugeLogFilenameAttempt (env.value (
"TEMP"), pathAndFile)) {
77 pathAndFile = ENGAUGE_LOG_FILE;
86 bool engaugeLogFilenameAttempt (
const QString &path,
92 pathAndFile = QString (
"%1%2%3")
94 .arg (QDir::separator())
95 .arg (ENGAUGE_LOG_FILE);
96 QFile file (pathAndFile);
97 if (file.open(QIODevice::WriteOnly | QIODevice::Text)) {
106 int main(
int argc,
char *argv[])
108 qRegisterMetaType<ColorFilterMode> (
"ColorFilterMode");
109 qRegisterMetaType<FittingCurveCoefficients> (
"FilterCurveCoefficients");
111 QApplication app(argc, argv);
117 bool isDebug, isReset, isGnuplot, isErrorReportRegressionTest;
118 QString errorReportFile, fileCmdScriptFile;
119 QStringList loadStartupFiles;
126 isErrorReportRegressionTest,
131 initializeLogging (
"engauge",
132 engaugeLogFilename(),
134 LOG4CPP_INFO_S ((*mainCat)) <<
"main args=" << QApplication::arguments().join (
" ").toLatin1().data();
139 isErrorReportRegressionTest,
149 void parseCmdLine (
int argc,
153 QString &errorReportFile,
154 QString &fileCmdScriptFile,
155 bool &isErrorReportRegressionTest,
157 QStringList &loadStartupFiles)
159 const int COLUMN_WIDTH = 20;
160 bool showUsage =
false;
163 bool nextIsErrorReportFile =
false;
164 bool nextIsFileCmdScript =
false;
169 errorReportFile =
"";
170 fileCmdScriptFile =
"";
171 isErrorReportRegressionTest =
false;
174 for (
int i = 1; i < argc; i++) {
176 if (nextIsErrorReportFile) {
177 errorReportFile = argv [i];
178 showUsage |= !checkFileExists (errorReportFile);
179 nextIsErrorReportFile =
false;
180 }
else if (nextIsFileCmdScript) {
181 fileCmdScriptFile = argv [i];
182 showUsage |= !checkFileExists (fileCmdScriptFile);
183 nextIsFileCmdScript =
false;
184 }
else if (strcmp (argv [i], DASH_DEBUG.toLatin1().data()) == 0) {
186 }
else if (strcmp (argv [i], DASH_ERROR_REPORT.toLatin1().data()) == 0) {
187 nextIsErrorReportFile =
true;
188 }
else if (strcmp (argv [i], DASH_FILE_CMD_SCRIPT.toLatin1().data()) == 0) {
189 nextIsFileCmdScript =
true;
190 }
else if (strcmp (argv [i], DASH_GNUPLOT.toLatin1().data()) == 0) {
192 }
else if (strcmp (argv [i], DASH_HELP.toLatin1().data()) == 0) {
194 }
else if (strcmp (argv [i], DASH_REGRESSION.toLatin1().data()) == 0) {
195 isErrorReportRegressionTest =
true;
196 }
else if (strcmp (argv [i], DASH_RESET.toLatin1().data()) == 0) {
198 }
else if (strcmp (argv [i], DASH_STYLES.toLatin1().data()) == 0) {
199 showStylesAndExit ();
200 }
else if (strncmp (argv [i], DASH.toLatin1().data(), 1) == 0) {
205 QString fileName = argv [i];
206 QFileInfo fInfo (fileName);
207 if (fInfo.isRelative()) {
208 fileName = fInfo.absoluteFilePath();
210 loadStartupFiles << fileName;
214 if (showUsage || nextIsErrorReportFile) {
216 cerr <<
"Usage: engauge " 217 <<
"[" << DASH_DEBUG.toLatin1().data() <<
"] " 218 <<
"[" << DASH_ERROR_REPORT.toLatin1().data() <<
" <file>] " 219 <<
"[" << DASH_FILE_CMD_SCRIPT.toLatin1().data() <<
" <file> " 220 <<
"[" << DASH_GNUPLOT.toLatin1().data() <<
"] " 221 <<
"[" << DASH_HELP.toLatin1().data() <<
"] " 222 <<
"[" << DASH_REGRESSION.toLatin1().data() <<
"] " 223 <<
"[" << DASH_RESET.toLatin1().data () <<
"] " 224 <<
"[" << DASH_STYLES.toLatin1().data () <<
"] " 225 <<
"[<load_file1>] [<load_file2>] ..." << endl
226 <<
" " << DASH_DEBUG.leftJustified(COLUMN_WIDTH,
' ').toLatin1().data()
227 << QObject::tr (
"Enables extra debug information. Used for debugging").toLatin1().data() << endl
228 <<
" " << DASH_ERROR_REPORT.leftJustified(COLUMN_WIDTH,
' ').toLatin1().data()
229 << QObject::tr (
"Specifies an error report file as input. Used for debugging and testing").toLatin1().data() << endl
230 <<
" " << DASH_FILE_CMD_SCRIPT.leftJustified(COLUMN_WIDTH,
' ').toLatin1().data()
231 << QObject::tr (
"Specifies a file command script file as input. Used for debugging and testing").toLatin1().data() << endl
232 <<
" " << DASH_GNUPLOT.leftJustified(COLUMN_WIDTH,
' ').toLatin1().data()
233 << QObject::tr (
"Output diagnostic gnuplot input files. Used for debugging").toLatin1().data() << endl
234 <<
" " << DASH_HELP.leftJustified(COLUMN_WIDTH,
' ').toLatin1().data()
235 << QObject::tr (
"Show this help information").toLatin1().data() << endl
236 <<
" " << DASH_REGRESSION.leftJustified(COLUMN_WIDTH,
' ').toLatin1().data()
237 << QObject::tr (
"Executes the error report file or file command script. Used for regression testing").toLatin1().data() << endl
238 <<
" " << DASH_RESET.leftJustified(COLUMN_WIDTH,
' ').toLatin1().data()
239 << QObject::tr (
"Removes all stored settings, including window positions. Used when windows start up offscreen").toLatin1().data() << endl
240 <<
" " << DASH_STYLES.leftJustified(COLUMN_WIDTH,
' ').toLatin1().data()
241 << QObject::tr (
"Show a list of available styles that can be used with the -style command").toLatin1().data() << endl
242 <<
" " << QString (
"<load file> ").leftJustified(COLUMN_WIDTH,
' ').toLatin1().data()
243 << QObject::tr (
"File(s) to be imported or opened at startup").toLatin1().data() << endl;
249 void showStylesAndExit ()
251 cout <<
"Available styles: " << QStyleFactory::keys ().join (
", ").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...