22 ******************************************************************************
33 *
44 * @file main.cpp
5- * @author The LibrePilot Team http://www.librepilot.org Copyright (C) 2015 .
5+ * @author The LibrePilot Team http://www.librepilot.org Copyright (C) 2017 .
66 * The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
77 * Parts by Nokia Corporation (qt-info@nokia.com) Copyright (C) 2009.
88 * @brief
8282 */
8383
8484#include " qtsingleapplication.h"
85- #include " utils/xmlconfig .h"
85+ #include " gcssplashscreen .h"
8686#include " utils/pathutils.h"
87+ #include " utils/settingsutils.h"
8788#include " utils/filelogger.h"
88- #include " gcssplashscreen.h"
8989
9090#include < extensionsystem/pluginmanager.h>
9191#include < extensionsystem/pluginspec.h>
9292#include < extensionsystem/iplugin.h>
9393
9494#include < QtCore/QDir>
95- #include < QtCore/QFile>
9695#include < QtCore/QElapsedTimer>
9796#include < QtCore/QTextStream>
9897#include < QtCore/QFileInfo>
101100#include < QtCore/QLibraryInfo>
102101#include < QtCore/QTranslator>
103102#include < QtCore/QSettings>
104- #include < QtCore/QVariant>
105103
106104#include < QMessageBox>
107- #include < QtWidgets/QApplication>
108- #include < QMainWindow>
109- #include < QSplashScreen>
105+ #include < QApplication>
110106#include < QSurfaceFormat>
111107
112108typedef QList<ExtensionSystem::PluginSpec *> PluginSpecSet;
@@ -350,78 +346,6 @@ AppOptionValues parseCommandLine(SharedTools::QtSingleApplication &app,
350346 return appOptionValues;
351347}
352348
353- void loadFactoryDefaults (QSettings &settings, AppOptionValues &appOptionValues)
354- {
355- QDir directory (Utils::GetDataPath () + QString (" configurations" ));
356-
357- qDebug () << " Looking for factory defaults configuration files in:" << directory.absolutePath ();
358-
359- QString fileName;
360-
361- // check if command line option -config-file contains a file name
362- QString commandLine = appOptionValues.value (CONFIG_FILE_OPTION);
363- if (!commandLine.isEmpty ()) {
364- QFileInfo fi (commandLine);
365- if (fi.isRelative ()) {
366- // file name specified on command line has a relative path
367- commandLine = directory.absolutePath () + QDir::separator () + commandLine;
368- }
369- if (QFile::exists (commandLine)) {
370- fileName = commandLine;
371- qDebug () << " Configuration file" << fileName << " specified on command line will be loaded." ;
372- } else {
373- qWarning () << " Configuration file" << commandLine << " specified on command line does not exist." ;
374- }
375- }
376-
377- if (fileName.isEmpty ()) {
378- // check default file
379- if (QFile::exists (directory.absolutePath () + QDir::separator () + DEFAULT_CONFIG_FILENAME)) {
380- // use default file name
381- fileName = directory.absolutePath () + QDir::separator () + DEFAULT_CONFIG_FILENAME;
382- qDebug () << " Default configuration file" << fileName << " will be loaded." ;
383- } else {
384- qWarning () << " No default configuration file found in" << directory.absolutePath ();
385- }
386- }
387-
388- if (fileName.isEmpty ()) {
389- // TODO should we exit violently?
390- qCritical () << " No default configuration file found!" ;
391- return ;
392- }
393-
394- // create settings from file
395- QSettings qs (fileName, XmlConfig::XmlSettingsFormat);
396-
397- // transfer loaded settings to application settings
398- QStringList keys = qs.allKeys ();
399- foreach (QString key, keys) {
400- settings.setValue (key, qs.value (key));
401- }
402-
403- qDebug () << " Configuration file" << fileName << " was loaded." ;
404- }
405-
406- void overrideSettings (QSettings &settings, const QStringList &arguments)
407- {
408- // Options like -D My/setting=test
409- QRegExp rx (" ([^=]+)=(.*)" );
410-
411- for (int i = 0 ; i < arguments.size (); ++i) {
412- if (CONFIG_OPTION == arguments[i]) {
413- if (rx.indexIn (arguments[++i]) > -1 ) {
414- QString key = rx.cap (1 );
415- QString value = rx.cap (2 );
416- qDebug () << " User setting" << key << " set to value" << value;
417- settings.setValue (key, value);
418- }
419- }
420- }
421-
422- settings.sync ();
423- }
424-
425349void loadTranslators (QString language, QTranslator &translator, QTranslator &qtTranslator)
426350{
427351 const QString &creatorTrPath = Utils::GetDataPath () + QLatin1String (" translations" );
@@ -454,15 +378,14 @@ int runApplication(int argc, char * *argv)
454378
455379 QCoreApplication::setApplicationName (APP_NAME);
456380 QCoreApplication::setOrganizationName (ORG_NAME);
457- QSettings::setDefaultFormat (XmlConfig::XmlSettingsFormat);
458381
459382 // initialize the plugin manager
460383 ExtensionSystem::PluginManager pluginManager;
461384 pluginManager.setFileExtension (QLatin1String (" pluginspec" ));
462385 pluginManager.setPluginPaths (Utils::GetPluginPaths ());
463386
464387 // parse command line
465- qDebug () << " Command line" << app.arguments ();
388+ qDebug () << " main - command line" << app.arguments ();
466389 QString errorMessage;
467390 AppOptionValues appOptionValues = parseCommandLine (app, pluginManager, errorMessage);
468391 if (!errorMessage.isEmpty ()) {
@@ -473,39 +396,32 @@ int runApplication(int argc, char * *argv)
473396 return -1 ;
474397 }
475398
399+ // start logging to file if requested
476400 if (appOptionValues.contains (LOG_FILE_OPTION)) {
477401 QString logFileName = appOptionValues.value (LOG_FILE_OPTION);
478402 logInit (logFileName);
479403 // relog command line arguments for the benefit of the file logger...
480- qDebug () << " Command line" << app.arguments ();
404+ qDebug () << " main - command line" << app.arguments ();
481405 }
482406
407+ // init settings
408+ Utils::initSettings (appOptionValues.value (CONFIG_FILE_OPTION));
409+
483410 // load user settings
484- // Must be done before any QSettings class is created
485- // keep this in sync with the MainWindow ctor in coreplugin/mainwindow.cpp
486- QString settingsPath = Utils::GetDataPath ();
487- qDebug () << " Loading system settings from" << settingsPath;
488- QSettings::setPath (XmlConfig::XmlSettingsFormat, QSettings::SystemScope, settingsPath);
489411 QSettings settings;
490- qDebug () << " Loading user settings from" << settings.fileName ();
491-
492- // need to reset all user settings?
493- if (appOptionValues.contains (RESET_OPTION)) {
494- qDebug () << " Resetting user settings!" ;
495- settings.clear ();
496- }
412+ qDebug () << " main - loading user settings from" << settings.fileName ();
497413
498- // check if we have user settings
499- if (!settings.allKeys ().count ()) {
500- // no user settings, load the factory defaults
501- qDebug () << " No user settings found, loading factory defaults..." ;
502- loadFactoryDefaults (settings, appOptionValues);
414+ // need to reset user settings?
415+ if (settings.allKeys ().isEmpty () || appOptionValues.contains (RESET_OPTION)) {
416+ qDebug () << " main - resetting user settings" ;
417+ Utils::resetToFactoryDefaults (settings);
503418 }
419+ Utils::mergeFactoryDefaults (settings);
504420
505421 // override settings with command line provided values
506422 // take notice that the overridden values will be saved in the user settings and will continue to be effective
507423 // in subsequent GCS runs
508- overrideSettings (settings, app. arguments () );
424+ Utils:: overrideSettings (settings, argc, argv );
509425
510426 // initialize GCS locale
511427 // use the value defined by the General/Locale setting or default to system Locale.
@@ -559,8 +475,8 @@ int runApplication(int argc, char * *argv)
559475 }
560476 if (!coreplugin) {
561477 QString nativePaths = QDir::toNativeSeparators (Utils::GetPluginPaths ().join (QLatin1String (" ," )));
562- const QString reason = QCoreApplication::translate (" Application" , " Could not find 'Core .pluginspec' in %1 " ). arg (
563- nativePaths);
478+ const QString reason = QCoreApplication::translate (" Application" , " Could not find '%1 .pluginspec' in %2 " )
479+ . arg (CORE_PLUGIN_NAME). arg ( nativePaths);
564480 displayError (msgCoreLoadFailure (reason));
565481 return 1 ;
566482 }
@@ -591,19 +507,17 @@ int runApplication(int argc, char * *argv)
591507 return 1 ;
592508 }
593509
594- {
595- QStringList errors;
596- foreach (ExtensionSystem::PluginSpec * p, pluginManager.plugins ()) {
597- if (p->hasError ()) {
598- errors.append (p->errorString ());
599- }
600- }
601- if (!errors.isEmpty ()) {
602- QMessageBox::warning (0 ,
603- QCoreApplication::translate (" Application" , " %1 - Plugin loader messages" ).arg (GCS_BIG_NAME),
604- errors.join (QString::fromLatin1 (" \n\n " )));
510+ QStringList errors;
511+ foreach (ExtensionSystem::PluginSpec * p, pluginManager.plugins ()) {
512+ if (p->hasError ()) {
513+ errors.append (p->errorString ());
605514 }
606515 }
516+ if (!errors.isEmpty ()) {
517+ QMessageBox::warning (0 ,
518+ QCoreApplication::translate (" Application" , " %1 - Plugin loader messages" ).arg (GCS_BIG_NAME),
519+ errors.join (QString::fromLatin1 (" \n\n " )));
520+ }
607521
608522 if (isFirstInstance) {
609523 // Set up lock and remote arguments for the first instance only.
0 commit comments