Engauge Digitizer 2
Loading...
Searching...
No Matches
main.cpp File Reference
#include "ColorFilterMode.h"
#include "Compatibility.h"
#include "FittingCurveCoefficients.h"
#include "ImportImageExtensions.h"
#include "Logger.h"
#include "MainWindow.h"
#include "MainWindowMsg.h"
#include <QApplication>
#include <QCoreApplication>
#include <QDebug>
#include <QDir>
#include <QFileInfo>
#include <QMessageBox>
#include <QObject>
#include <QProcessEnvironment>
#include <QStyleFactory>
#include "TranslatorContainer.h"
#include "ZoomFactor.h"
Include dependency graph for main.cpp:

Go to the source code of this file.

Functions

const QString CMD_DEBUG ("debug")
const QString CMD_DROP_REGRESSION ("dropregression")
const QString CMD_ERROR_REPORT ("errorreport")
const QString CMD_EXPORT_ONLY ("exportonly")
const QString CMD_EXTRACT_IMAGE_ONLY ("extractimageonly")
const QString CMD_FILE_CMD_SCRIPT ("filecmdscript")
const QString CMD_GNUPLOT ("gnuplot")
const QString CMD_HELP ("help")
const QString CMD_REGRESSION ("regression")
const QString CMD_RESET ("reset")
const QString CMD_STYLE ("style")
const QString CMD_STYLES ("styles")
const QString CMD_UPGRADE ("upgrade")
const QString DASH ("-")
const QString DASH_DEBUG ("-"+CMD_DEBUG)
const QString DASH_DROP_REGRESSION ("-"+CMD_DROP_REGRESSION)
const QString DASH_ERROR_REPORT ("-"+CMD_ERROR_REPORT)
const QString DASH_EXTRACT_IMAGE_ONLY ("-"+CMD_EXTRACT_IMAGE_ONLY)
const QString DASH_EXPORT_ONLY ("-"+CMD_EXPORT_ONLY)
const QString DASH_FILE_CMD_SCRIPT ("-"+CMD_FILE_CMD_SCRIPT)
const QString DASH_GNUPLOT ("-"+CMD_GNUPLOT)
const QString DASH_HELP ("-"+CMD_HELP)
const QString DASH_REGRESSION ("-"+CMD_REGRESSION)
const QString DASH_RESET ("-"+CMD_RESET)
const QString DASH_STYLE ("-"+CMD_STYLE)
const QString DASH_STYLES ("-"+CMD_STYLES)
const QString DASH_UPGRADE ("-"+CMD_UPGRADE)
const QString ENGAUGE_LOG_FILE (".engauge.log")
bool checkFileExists (const QString &file)
QString engaugeLogFilename ()
bool engaugeLogFilenameAttempt (const QString &path, QString &pathAndFile)
void parseCmdLine (int argc, char **argv, bool &isDebug, bool &isDropRegression, bool &isReset, QString &errorReportFile, QString &fileCmdScriptFile, bool &isErrorReportRegressionTest, bool &isGnuplot, bool &isExportOnly, bool &isExtractImageOnly, QString &extractImageOnlyExtension, bool &isUpgrade, QStringList &loadStartupFiles, QStringList &commandLineWithoutLoadStartupFiles)
void sanityCheckLoadStartupFiles (bool isRepeatingFlag, const QString &dashForRepeatingFlag, const QString &errorReportFile, const QString &fileCmdScriptFile, const QStringList &loadStartupFiles)
void sanityCheckValue (bool requiredCondition, const QString &arg, const QString &msgUnadorned)
void showMessageAndQuit (const QString &msg)
void showStylesAndQuit ()
void showUsageAndQuit ()
void upgradeFiles (const QStringList &loadStartupFiles)
int main (int argc, char *argv[])

Function Documentation

◆ checkFileExists()

bool checkFileExists ( const QString & file)

Definition at line 91 of file main.cpp.

92{
93 QFileInfo check (file);
94 return check.exists() && check.isFile();
95}

◆ CMD_DEBUG()

const QString CMD_DEBUG ( "debug" )

◆ CMD_DROP_REGRESSION()

const QString CMD_DROP_REGRESSION ( "dropregression" )

◆ CMD_ERROR_REPORT()

const QString CMD_ERROR_REPORT ( "errorreport" )

◆ CMD_EXPORT_ONLY()

const QString CMD_EXPORT_ONLY ( "exportonly" )

◆ CMD_EXTRACT_IMAGE_ONLY()

const QString CMD_EXTRACT_IMAGE_ONLY ( "extractimageonly" )

◆ CMD_FILE_CMD_SCRIPT()

const QString CMD_FILE_CMD_SCRIPT ( "filecmdscript" )

◆ CMD_GNUPLOT()

const QString CMD_GNUPLOT ( "gnuplot" )

◆ CMD_HELP()

const QString CMD_HELP ( "help" )

◆ CMD_REGRESSION()

const QString CMD_REGRESSION ( "regression" )

◆ CMD_RESET()

const QString CMD_RESET ( "reset" )

◆ CMD_STYLE()

const QString CMD_STYLE ( "style" )

◆ CMD_STYLES()

const QString CMD_STYLES ( "styles" )

◆ CMD_UPGRADE()

const QString CMD_UPGRADE ( "upgrade" )

◆ DASH()

const QString DASH ( "-" )

◆ DASH_DEBUG()

const QString DASH_DEBUG ( "-"+ CMD_DEBUG)

◆ DASH_DROP_REGRESSION()

const QString DASH_DROP_REGRESSION ( "-"+ CMD_DROP_REGRESSION)

◆ DASH_ERROR_REPORT()

const QString DASH_ERROR_REPORT ( "-"+ CMD_ERROR_REPORT)

◆ DASH_EXPORT_ONLY()

const QString DASH_EXPORT_ONLY ( "-"+ CMD_EXPORT_ONLY)

◆ DASH_EXTRACT_IMAGE_ONLY()

const QString DASH_EXTRACT_IMAGE_ONLY ( "-"+ CMD_EXTRACT_IMAGE_ONLY)

◆ DASH_FILE_CMD_SCRIPT()

const QString DASH_FILE_CMD_SCRIPT ( "-"+ CMD_FILE_CMD_SCRIPT)

◆ DASH_GNUPLOT()

const QString DASH_GNUPLOT ( "-"+ CMD_GNUPLOT)

◆ DASH_HELP()

const QString DASH_HELP ( "-"+ CMD_HELP)

◆ DASH_REGRESSION()

const QString DASH_REGRESSION ( "-"+ CMD_REGRESSION)

◆ DASH_RESET()

const QString DASH_RESET ( "-"+ CMD_RESET)

◆ DASH_STYLE()

const QString DASH_STYLE ( "-"+ CMD_STYLE)

◆ DASH_STYLES()

const QString DASH_STYLES ( "-"+ CMD_STYLES)

◆ DASH_UPGRADE()

const QString DASH_UPGRADE ( "-"+ CMD_UPGRADE)

◆ ENGAUGE_LOG_FILE()

const QString ENGAUGE_LOG_FILE ( ".engauge.log" )

◆ engaugeLogFilename()

QString engaugeLogFilename ( )

Definition at line 97 of file main.cpp.

98{
99 QString pathAndFile; // Return empty value in OSX which is unused
100
101#if !defined(OSX_RELEASE) && !defined(WIN_RELEASE) && !defined(APPIMAGE_RELEASE)
102 QProcessEnvironment env;
103
104 // Make multiple attempts until a directory is found where the log file can be written
105 if (!engaugeLogFilenameAttempt (QCoreApplication::applicationDirPath(), pathAndFile)) {
106 if (!engaugeLogFilenameAttempt (env.value ("HOME"), pathAndFile)) {
107 if (!engaugeLogFilenameAttempt (env.value ("TEMP"), pathAndFile)) {
108 pathAndFile = ENGAUGE_LOG_FILE; // Current directory will have to do
109 }
110 }
111 }
112#endif
113
114 return pathAndFile;
115}
bool engaugeLogFilenameAttempt(const QString &path, QString &pathAndFile)
Definition main.cpp:117
const QString ENGAUGE_LOG_FILE(".engauge.log")

◆ engaugeLogFilenameAttempt()

bool engaugeLogFilenameAttempt ( const QString & path,
QString & pathAndFile )

Definition at line 117 of file main.cpp.

119{
120 bool success = false;
121
122 // Test if file can be opened. Checking permissions on directory is unreliable in Windows/OSX
123 pathAndFile = QString ("%1%2%3")
124 .arg (path)
125 .arg (QDir::separator())
126 .arg (ENGAUGE_LOG_FILE);
127 QFile file (pathAndFile);
128 if (file.open(QIODevice::WriteOnly | QIODevice::Text)) {
129 // Success
130 file.close();
131 file.remove(); // Cleanup
132 success = true;
133 }
134
135 return success;
136}

◆ main()

int main ( int argc,
char * argv[] )

Definition at line 138 of file main.cpp.

139{
140 qRegisterMetaType<ColorFilterMode> ("ColorFilterMode");
141 qRegisterMetaType<FittingCurveCoefficients> ("FilterCurveCoefficients");
142 qRegisterMetaType<ZoomFactor> ("ZoomFactor");
143
144 QApplication app(argc, argv);
145
146 // Translations
147 TranslatorContainer translatorContainer (app); // Must exist until execution terminates
148
149 // Command line
150 bool isDebug, isDropRegression, isReset, isGnuplot, isErrorReportRegressionTest, isExportOnly, isExtractImageOnly, isUpgrade;
151 QString errorReportFile, extractImageOnlyExtension, fileCmdScriptFile;
152 QStringList loadStartupFiles, commandLineWithoutLoadStartupFiles;
153 parseCmdLine (argc,
154 argv,
155 isDebug,
156 isDropRegression,
157 isReset,
158 errorReportFile,
159 fileCmdScriptFile,
160 isErrorReportRegressionTest,
161 isGnuplot,
162 isExportOnly,
163 isExtractImageOnly,
164 extractImageOnlyExtension,
165 isUpgrade,
166 loadStartupFiles,
167 commandLineWithoutLoadStartupFiles);
168
169 // Logging
170 initializeLogging ("engauge",
172 isDebug);
173 LOG4CPP_INFO_S ((*mainCat)) << "main args=" << QApplication::arguments().join (" ").toLatin1().data();
174
175 // Upgrade or run normally
176 int rtn = 0;
177 if (isUpgrade) {
178 upgradeFiles (loadStartupFiles);
179 } else {
180 // Create and show main window
181 MainWindow w (errorReportFile,
182 fileCmdScriptFile,
183 isDropRegression,
184 isErrorReportRegressionTest,
185 isGnuplot,
186 isReset,
187 isExportOnly,
188 isExtractImageOnly,
189 extractImageOnlyExtension,
190 loadStartupFiles,
191 commandLineWithoutLoadStartupFiles);
192 w.show();
193
194 // Event loop
195 rtn = app.exec();
196 }
197
198 return rtn;
199}
log4cpp::Category * mainCat
Definition Logger.cpp:14
void initializeLogging(const QString &name, const QString &filename, bool isDebug)
Definition Logger.cpp:21
Main window consisting of menu, graphics scene, status bar and optional toolbars as a Single Document...
Definition MainWindow.h:95
Class that stores QTranslator objects for the duration of application execution.
#define LOG4CPP_INFO_S(logger)
Definition convenience.h:18
void parseCmdLine(int argc, char **argv, bool &isDebug, bool &isDropRegression, bool &isReset, QString &errorReportFile, QString &fileCmdScriptFile, bool &isErrorReportRegressionTest, bool &isGnuplot, bool &isExportOnly, bool &isExtractImageOnly, QString &extractImageOnlyExtension, bool &isUpgrade, QStringList &loadStartupFiles, QStringList &commandLineWithoutLoadStartupFiles)
Definition main.cpp:201
QString engaugeLogFilename()
Definition main.cpp:97
void upgradeFiles(const QStringList &loadStartupFiles)
Definition main.cpp:509

◆ parseCmdLine()

void parseCmdLine ( int argc,
char ** argv,
bool & isDebug,
bool & isDropRegression,
bool & isReset,
QString & errorReportFile,
QString & fileCmdScriptFile,
bool & isErrorReportRegressionTest,
bool & isGnuplot,
bool & isExportOnly,
bool & isExtractImageOnly,
QString & extractImageOnlyExtension,
bool & isUpgrade,
QStringList & loadStartupFiles,
QStringList & commandLineWithoutLoadStartupFiles )

Definition at line 201 of file main.cpp.

216{
217 bool showUsage = false;
218
219 ImportImageExtensions importImageExtensions;
220
221 // State
222 bool nextIsErrorReportFile = false;
223 bool nextIsExtractImageOnly = false;
224 bool nextIsFileCmdScript = false;
225
226 // Defaults
227 isDebug = false;
228 isDropRegression = false;
229 isReset = false;
230 errorReportFile = "";
231 fileCmdScriptFile = "";
232 isErrorReportRegressionTest = false;
233 isGnuplot = false;
234 isExportOnly = false;
235 isExtractImageOnly = false;
236 extractImageOnlyExtension = "";
237 isUpgrade = false;
238
239 for (int i = 1; i < argc; i++) {
240
241 bool isLoadStartupFile = false;
242
243 if (nextIsErrorReportFile) {
245 argv [i],
246 QObject::tr ("is not a valid file name"));
247 errorReportFile = argv [i];
248 nextIsErrorReportFile = false;
249 } else if (nextIsExtractImageOnly) {
250 sanityCheckValue (importImageExtensions.offers (argv [i]),
251 argv [i],
252 QObject::tr ("is not a valid image file extension"));
253 extractImageOnlyExtension = argv [i];
254 nextIsExtractImageOnly = false;
255 } else if (nextIsFileCmdScript) {
257 argv [i],
258 QObject::tr ("is not a valid file name"));
259 fileCmdScriptFile = argv [i];
260 nextIsFileCmdScript = false;
261 } else if (strcmp (argv [i], DASH_DEBUG.toLatin1().data()) == 0) {
262 isDebug = true;
263 } else if (strcmp (argv [i], DASH_DROP_REGRESSION.toLatin1().data()) == 0) {
264 isDropRegression = true;
265 } else if (strcmp (argv [i], DASH_ERROR_REPORT.toLatin1().data()) == 0) {
266 nextIsErrorReportFile = true;
267 } else if (strcmp (argv [i], DASH_EXPORT_ONLY.toLatin1().data()) == 0) {
268 isExportOnly = true;
269 } else if (strcmp (argv [i], DASH_EXTRACT_IMAGE_ONLY.toLatin1().data()) == 0) {
270 isExtractImageOnly = true;
271 nextIsExtractImageOnly = true;
272 } else if (strcmp (argv [i], DASH_FILE_CMD_SCRIPT.toLatin1().data()) == 0) {
273 nextIsFileCmdScript = true;
274 } else if (strcmp (argv [i], DASH_GNUPLOT.toLatin1().data()) == 0) {
275 isGnuplot = true;
276 } else if (strcmp (argv [i], DASH_HELP.toLatin1().data()) == 0) {
277 showUsage = true; // User requested help
278 } else if (strcmp (argv [i], DASH_REGRESSION.toLatin1().data()) == 0) {
279 isErrorReportRegressionTest = true;
280 } else if (strcmp (argv [i], DASH_RESET.toLatin1().data()) == 0) {
281 isReset = true;
282 } else if (strcmp (argv [i], DASH_STYLE.toLatin1().data()) == 0) {
283 // This branch never executes because Qt strips out '-style <style>' and processes it.
284 // This comment is here just to document that special handling
285 } else if (strcmp (argv [i], DASH_STYLES.toLatin1().data()) == 0) {
287 } else if (strcmp (argv [i], DASH_UPGRADE.toLatin1().data()) == 0) {
288 isUpgrade = true;
289 } else if (strncmp (argv [i], DASH.toLatin1().data(), 1) == 0) {
290 showUsage = true; // User entered an unrecognized token
291 } else {
292 // MainWindow will change current directory (which is often some obscure application directory),
293 // so relative paths must be changed in advance to absolute so the files can still be found
294 QString fileName = argv [i];
295 QFileInfo fInfo (fileName);
296 if (fInfo.isRelative() && !fileName.startsWith ("http")) {
297 fileName = fInfo.absoluteFilePath();
298 }
299
300 isLoadStartupFile = true;
301 loadStartupFiles << fileName; // Save file name
302 }
303
304 // keep command line arguments
305 if (!isLoadStartupFile) {
306 commandLineWithoutLoadStartupFiles << argv [i];
307 }
308 }
309
310 // Sanity checks
311 sanityCheckLoadStartupFiles (isExportOnly,
313 errorReportFile,
314 fileCmdScriptFile,
315 loadStartupFiles);
316 sanityCheckLoadStartupFiles (isExtractImageOnly,
318 errorReportFile,
319 fileCmdScriptFile,
320 loadStartupFiles);
321
322 // Usage
323 if (showUsage || nextIsErrorReportFile || nextIsExtractImageOnly || nextIsFileCmdScript) {
324
326
327 }
328}
Provides list of file extensions for import.
bool offers(const QString &fileExtension) const
Return true if specified file extension is supported.
void sanityCheckLoadStartupFiles(bool isRepeatingFlag, const QString &dashForRepeatingFlag, const QString &errorReportFile, const QString &fileCmdScriptFile, const QStringList &loadStartupFiles)
Definition main.cpp:330
const QString DASH_ERROR_REPORT("-"+CMD_ERROR_REPORT)
const QString DASH_GNUPLOT("-"+CMD_GNUPLOT)
const QString DASH_EXTRACT_IMAGE_ONLY("-"+CMD_EXTRACT_IMAGE_ONLY)
void showUsageAndQuit()
Definition main.cpp:381
void sanityCheckValue(bool requiredCondition, const QString &arg, const QString &msgUnadorned)
Definition main.cpp:349
const QString DASH_HELP("-"+CMD_HELP)
const QString DASH_UPGRADE("-"+CMD_UPGRADE)
const QString DASH_RESET("-"+CMD_RESET)
const QString DASH_STYLES("-"+CMD_STYLES)
const QString DASH_REGRESSION("-"+CMD_REGRESSION)
const QString DASH_EXPORT_ONLY("-"+CMD_EXPORT_ONLY)
const QString DASH_DROP_REGRESSION("-"+CMD_DROP_REGRESSION)
const QString DASH_DEBUG("-"+CMD_DEBUG)
const QString DASH_STYLE("-"+CMD_STYLE)
bool checkFileExists(const QString &file)
Definition main.cpp:91
void showStylesAndQuit()
Definition main.cpp:373
const QString DASH("-")
const QString DASH_FILE_CMD_SCRIPT("-"+CMD_FILE_CMD_SCRIPT)

◆ sanityCheckLoadStartupFiles()

void sanityCheckLoadStartupFiles ( bool isRepeatingFlag,
const QString & dashForRepeatingFlag,
const QString & errorReportFile,
const QString & fileCmdScriptFile,
const QStringList & loadStartupFiles )

Definition at line 330 of file main.cpp.

335{
336 if (isRepeatingFlag && (!errorReportFile.isEmpty() ||
337 !fileCmdScriptFile.isEmpty() ||
338 loadStartupFiles.size() == 0)) {
339
340 // Condition that at only load files are specified, and there is at least one of them, is not satisfied so
341 // show more specific error message than showUsageAndQuit, and then quit
342 QString msg;
343 QTextStream str (&msg);
344 str << dashForRepeatingFlag.toLatin1().data() << " " << QObject::tr ("is used only with one or more load files");
345 showMessageAndQuit (msg);
346 }
347}
void showMessageAndQuit(const QString &msg)
Definition main.cpp:363

◆ sanityCheckValue()

void sanityCheckValue ( bool requiredCondition,
const QString & arg,
const QString & msgUnadorned )

Definition at line 349 of file main.cpp.

352{
353 if (!requiredCondition) {
354
355 // Required condition is not satisfied. Show a more specific error message than showUsageAndQuit and then quit
356 QString msg = QString ("%1 %2")
357 .arg (arg)
358 .arg (msgUnadorned);
359 showMessageAndQuit (msg);
360 }
361}

◆ showMessageAndQuit()

void showMessageAndQuit ( const QString & msg)

Definition at line 363 of file main.cpp.

364{
365 MainWindowMsg w (msg);
366 w.show ();
367
368 qApp->exec();
369
370 // Execution never reaches this point since MainWindowMsg shuts everything down
371}
Main window for momentary message dialog.

◆ showStylesAndQuit()

void showStylesAndQuit ( )

Definition at line 373 of file main.cpp.

374{
375 QString msg;
376 QTextStream str (&msg);
377 str << QObject::tr ("Available styles") << ": " << QStyleFactory::keys ().join (", ");
378 showMessageAndQuit (msg);
379}

◆ showUsageAndQuit()

void showUsageAndQuit ( )

Definition at line 381 of file main.cpp.

382{
383 QString msg;
384 QTextStream str (&msg);
385 str << "<html>Usage: engauge "
386 << "[" << DASH_DEBUG.toLatin1().data() << "] "
387 << "[" << DASH_DROP_REGRESSION.toLatin1().data() << "] "
388 << "[" << DASH_ERROR_REPORT.toLatin1().data() << " &lt;file&gt;] "
389 << "[" << DASH_EXPORT_ONLY.toLatin1().data() << "] "
390 << "[" << DASH_EXTRACT_IMAGE_ONLY.toLatin1().data() << " &lt;extension&gt;] "
391 << "[" << DASH_FILE_CMD_SCRIPT.toLatin1().data() << " &lt;file&gt; "
392 << "[" << DASH_GNUPLOT.toLatin1().data() << "] "
393 << "[" << DASH_HELP.toLatin1().data() << "] "
394 << "[" << DASH_REGRESSION.toLatin1().data() << "] "
395 << "[" << DASH_RESET.toLatin1().data () << "] "
396 << "[" << DASH_STYLE.toLatin1().data () << " &lt;style&gt;] "
397 << "[" << DASH_STYLES.toLatin1().data () << "] "
398 << "[&lt;load_file1&gt;] [&lt;load_file2&gt;] ..." << "\n"
399 << "<table>"
400 << "<tr>"
401 << "<td>" << QObject::tr ("where") << "</td>"
402 << "<td>&nbsp;</td>"
403 << "</tr>"
404 << "<tr>"
405 << "<td>" << DASH_DEBUG.toLatin1().data() << "</td>"
406 << "<td>"
407 << QObject::tr ("Enables extra debug information. Used for debugging").toLatin1().data()
408 << "</td>"
409 << "</tr>"
410 << "<tr>"
411 << "<td>" << DASH_DROP_REGRESSION.toLatin1().data() << "</td>"
412 << "<td>"
413 << QObject::tr ("Indicates files opened at startup are for testing drag and drop. Used for regression testing").toLatin1().data()
414 << "</td>"
415 << "</tr>"
416 << "<tr>"
417 << "<td>" << DASH_ERROR_REPORT.toLatin1().data() << "</td>"
418 << "<td>"
419 << QObject::tr ("Specifies an error report file as input. Used for debugging and regression testing").toLatin1().data()
420 << "</td>"
421 << "</tr>"
422 << "<tr>"
423 << "<td>" << DASH_EXPORT_ONLY.toLatin1().data() << "</td>"
424 << "<td>"
425 << QObject::tr ("Export each loaded startup file, which must have all axis points defined, then stop").toLatin1().data()
426 << "</td>"
427 << "</tr>"
428 << "<tr>"
429 << "<td>" << DASH_EXTRACT_IMAGE_ONLY.toLatin1().data() << "</td>"
430 << "<td>"
431 << QObject::tr ("Extract image in each loaded startup file to a file with the specified extension, then stop").toLatin1().data()
432 << "</td>"
433 << "</tr>"
434 << "<tr>"
435 << "<td>" << DASH_FILE_CMD_SCRIPT.toLatin1().data() << "</td>"
436 << "<td>"
437 << QObject::tr ("Specifies a file command script file as input. Used for debugging and testing").toLatin1().data()
438 << "</td>"
439 << "</tr>"
440 << "<tr>"
441 << "<td>" << DASH_GNUPLOT.toLatin1().data() << "</td>"
442 << "<td>"
443 << QObject::tr ("Output diagnostic gnuplot input files. Used for debugging").toLatin1().data()
444 << "</td>"
445 << "</tr>"
446 << "<tr>"
447 << "<td>" << DASH_HELP.toLatin1().data() << "</td>"
448 << "<td>"
449 << QObject::tr ("Show this help information").toLatin1().data()
450 << "</td>"
451 << "</tr>"
452 << "<tr>"
453 << "<td>" << DASH_REGRESSION.toLatin1().data() << "</td>"
454 << "<td>"
455 << QObject::tr ("Executes the error report file or file command script. Used for regression testing").toLatin1().data()
456 << "</td>"
457 << "</tr>"
458 << "<tr>"
459 << "<td>" << DASH_RESET.toLatin1().data() << "</td>"
460 << "<td>"
461 << QObject::tr ("Removes all stored settings, including window positions. Used when windows start up offscreen").toLatin1().data()
462 << "</td>"
463 << "</tr>"
464 << "<tr>"
465 << "<td>" << DASH_STYLE.toLatin1().data() << "</td>"
466 << "<td>"
467 << QString ("%1 %2")
468 .arg (QObject::tr ("Set the window style to one of the styles listed by the command line option"))
469 .arg (DASH_STYLES).toLatin1().data()
470 << "</td>"
471 << "</tr>"
472 << "<tr>"
473 << "<td>" << DASH_STYLES.toLatin1().data() << "</td>"
474 << "<td>"
475 << QString ("%1 %2")
476 .arg (QObject::tr ("Show a list of available styles that can be used with the command line option"))
477 .arg (DASH_STYLE).toLatin1().data()
478 << "</td>"
479 << "</tr>"
480 << "<tr>"
481 << "<td>" << DASH_UPGRADE.toLatin1().data() << "</td>"
482 << "<td>"
483 << QObject::tr ("Upgrade files opened at startup to the most recent version").toLatin1().data()
484 << "</td>"
485 << "</tr>"
486 << "<tr>"
487 << "<td>" << QString ("&lt;load file&gt; ").toLatin1().data() << "</td>"
488 << "<td>"
489 << QObject::tr ("File(s) to be imported or opened at startup").toLatin1().data()
490 << "</td>"
491 << "</tr>"
492 << "<tr>"
493 << "<td>&nbsp;</td>"
494 << "<td>&nbsp;</td>"
495 << "</tr>"
496 << "<tr>"
497 << "<td>" << QObject::tr ("Useful environment variables:") << "</td>"
498 << "<td>&nbsp;</td>"
499 << "</tr>"
500 << "<tr>"
501 << "<td>TZ</td>" // Do not translate
502 << "<td>" << QObject::tr ("Set timezone to add or subtract hours in time values. Timezone values are listed as TZ Database Names in Wikipedia").toLatin1().data() << "</td>"
503 << "</tr>"
504 << "</table></html>";
505
506 showMessageAndQuit (msg);
507}

◆ upgradeFiles()

void upgradeFiles ( const QStringList & loadStartupFiles)

Definition at line 509 of file main.cpp.

510{
511 QString FILE_SUFFIX (".dig");
512 QString UPGRADE_TOKEN ("_upgrade");
513
514 QString msg;
515
516 QStringList::const_iterator itr;
517 for (itr = loadStartupFiles.begin(); itr != loadStartupFiles.end(); itr++) {
518
519 QString filenameOld = *itr;
520 QString filenameNew;
521
522 // First try to insert upgrade token before file prefix if it is recognized
523 if (filenameOld.endsWith (FILE_SUFFIX,
524 Qt::CaseInsensitive)) {
525 QString withoutSuffix = filenameOld.left (filenameOld.size () - FILE_SUFFIX.size ());
526 filenameNew = QString ("%1%2%3")
527 .arg (withoutSuffix)
528 .arg (UPGRADE_TOKEN)
529 .arg (FILE_SUFFIX);
530 } else {
531
532 // Otherwise append upgrade token
533 filenameNew = QString ("%1%2")
534 .arg (filenameOld)
535 .arg (UPGRADE_TOKEN);
536 }
537
538 // Get old file
539 Document document (filenameOld);
540
541 // Make new file
542 QFile file (filenameNew);
543 if (!file.open (QFile::WriteOnly)) {
544
545 msg += QString ("%1 %2")
546 .arg (QObject::tr ("Could not write to"))
547 .arg (filenameNew);
548
549 } else {
550
551 QXmlStreamWriter writer (&file);
552 writer.setAutoFormatting (true);
553 writer.writeStartDocument();
554 writer.writeDTD ("<!DOCTYPE engauge>");
555 document.saveXml (writer);
556 writer.writeEndDocument ();
557
558 msg += QString ("%1 %2 %3 %4")
559 .arg (QObject::tr ("Upgraded"))
560 .arg (filenameOld)
561 .arg (QObject::tr ("to"))
562 .arg (filenameNew);
563 }
564 }
565
566 // Do not show a message using QMessageBox since upgrade mode may be called hundreds
567 // of times successively by python scripts. Logging is used instead
568 LOG4CPP_INFO_S ((*mainCat)) << "Upgrade results: " << msg.toLatin1().data ();
569
570 exit (0);
571}
Storage of one imported image and the data attached to that image.
Definition Document.h:44