diff --git a/qgroundcontrol.pro b/qgroundcontrol.pro index d6ac06d20dbe6ffa8a86d6e8d51bf8eeda3312cb..c7057995c409be8d3c03cf4d46182868d1ac8699 100644 --- a/qgroundcontrol.pro +++ b/qgroundcontrol.pro @@ -324,8 +324,6 @@ FORMS += \ src/ui/JoystickButton.ui \ src/ui/JoystickAxis.ui \ src/ui/QGCConfigView.ui \ - src/ui/main/QGCViewModeSelection.ui \ - src/ui/main/QGCWelcomeMainWindow.ui \ src/ui/configuration/terminalconsole.ui \ src/ui/configuration/SerialSettingsDialog.ui \ src/ui/px4_configuration/QGCPX4AirframeConfig.ui \ @@ -473,8 +471,6 @@ HEADERS += \ src/ui/JoystickButton.h \ src/ui/JoystickAxis.h \ src/ui/QGCConfigView.h \ - src/ui/main/QGCViewModeSelection.h \ - src/ui/main/QGCWelcomeMainWindow.h \ src/ui/configuration/console.h \ src/ui/configuration/SerialSettingsDialog.h \ src/ui/configuration/terminalconsole.h \ @@ -630,8 +626,6 @@ SOURCES += \ src/ui/JoystickAxis.cc \ src/ui/uas/QGCMessageView.cc \ src/ui/QGCConfigView.cc \ - src/ui/main/QGCViewModeSelection.cc \ - src/ui/main/QGCWelcomeMainWindow.cc \ src/ui/configuration/terminalconsole.cpp \ src/ui/configuration/console.cpp \ src/ui/configuration/SerialSettingsDialog.cc \ diff --git a/src/QGCCore.cc b/src/QGCCore.cc index 375f3c0c8ab76c07faee48255facf98301030221..740290a0f369e719003e4473dfb30473717b730c 100644 --- a/src/QGCCore.cc +++ b/src/QGCCore.cc @@ -45,7 +45,6 @@ This file is part of the QGROUNDCONTROL project #include "QGC.h" #include "QGCCore.h" #include "MainWindow.h" -#include "QGCWelcomeMainWindow.h" #include "GAudioOutput.h" #include "CmdLineOptParser.h" @@ -68,19 +67,16 @@ This file is part of the QGROUNDCONTROL project **/ -QGCCore::QGCCore(bool firstStart, int &argc, char* argv[]) : QApplication(argc, argv), - restartRequested(false), - welcome(NULL) +QGCCore::QGCCore(int &argc, char* argv[]) : + QApplication(argc, argv), + _mainWindow(NULL) { - // Exit main application when last window is closed - connect(this, SIGNAL(lastWindowClosed()), this, SLOT(quit())); - // Set application name this->setApplicationName(QGC_APPLICATION_NAME); this->setApplicationVersion(QGC_APPLICATION_VERSION); this->setOrganizationName(QGC::ORG_NAME); this->setOrganizationDomain(QGC::ORG_DOMAIN); - + // Set settings format QSettings::setDefaultFormat(QSettings::IniFormat); @@ -92,19 +88,38 @@ QGCCore::QGCCore(bool firstStart, int &argc, char* argv[]) : QApplication(argc, { "--clear-settings", &fClearSettingsOptions }, // Add additional command line option flags here }; - + ParseCmdLineOptions(argc, argv, rgCmdLineOptions, sizeof(rgCmdLineOptions)/sizeof(rgCmdLineOptions[0]), false); QSettings settings; - + if (fClearSettingsOptions) { // User requested settings to be cleared on command line settings.clear(); + settings.sync(); } +} + +bool QGCCore::init(void) +{ + QSettings settings; + + // SSL support is required. No reason to go any further without it + if (!QSslSocket::supportsSsl()) { + QMessageBox::critical(NULL, + QObject::tr("Missing SSL Support"), + QObject::tr("QGroundControl requires support for SSL to be installed prior to running. Please see http://www.qgroundcontrol.org/downloads for instructions on installing prerequisites for QGroundControl.")); + return false; + } + + // Exit main application when last window is closed + connect(this, SIGNAL(lastWindowClosed()), this, SLOT(quit())); + + // Show user an upgrade message if QGC got upgraded (see code below, after splash screen) bool upgraded = false; - enum MainWindow::CUSTOM_MODE mode = MainWindow::CUSTOM_MODE_NONE; + enum MainWindow::CUSTOM_MODE mode = MainWindow::CUSTOM_MODE_PX4; QString lastApplicationVersion(""); if (settings.contains("QGC_APPLICATION_VERSION")) { @@ -116,31 +131,18 @@ QGCCore::QGCCore(bool firstStart, int &argc, char* argv[]) : QApplication(argc, // Write current application version settings.setValue("QGC_APPLICATION_VERSION", QGC_APPLICATION_VERSION); upgraded = true; + } else { + mode = (enum MainWindow::CUSTOM_MODE) settings.value("QGC_CUSTOM_MODE", (int)MainWindow::CUSTOM_MODE_PX4).toInt(); } - else - { - mode = (enum MainWindow::CUSTOM_MODE) settings.value("QGC_CUSTOM_MODE", (int)MainWindow::CUSTOM_MODE_NONE).toInt(); - } - } - else - { + } else { // If application version is not set, clear settings anyway settings.clear(); // Write current application version settings.setValue("QGC_APPLICATION_VERSION", QGC_APPLICATION_VERSION); } - + settings.sync(); - - // "Bootload" the application - if ((!settings.contains("QGC_CUSTOM_MODE_STORED") || settings.value("QGC_CUSTOM_MODE_STORED") == false) && firstStart) - { - welcome = new QGCWelcomeMainWindow(); - connect(welcome, SIGNAL(customViewModeSelected(MainWindow::CUSTOM_MODE)), this, SLOT(customViewModeSelected(MainWindow::CUSTOM_MODE))); - restartRequested = true; - return; - } - + // Show splash screen QPixmap splashImage(":/files/images/splash.png"); QSplashScreen* splashScreen = new QSplashScreen(splashImage); @@ -149,7 +151,7 @@ QGCCore::QGCCore(bool firstStart, int &argc, char* argv[]) : QApplication(argc, splashScreen->show(); processEvents(); splashScreen->showMessage(tr("Loading application fonts"), Qt::AlignLeft | Qt::AlignBottom, QColor(62, 93, 141)); - + // Load application font QFontDatabase fontDatabase = QFontDatabase(); const QString fontFileName = ":/general/vera.ttf"; ///< Font file is part of the QRC file and compiled into the app @@ -159,53 +161,48 @@ QGCCore::QGCCore(bool firstStart, int &argc, char* argv[]) : QApplication(argc, // Avoid Using setFont(). In the Qt docu you can read the following: // "Warning: Do not use this function in conjunction with Qt Style Sheets." // setFont(fontDatabase.font(fontFamilyName, "Roman", 12)); - + // Start the comm link manager splashScreen->showMessage(tr("Starting communication links"), Qt::AlignLeft | Qt::AlignBottom, QColor(62, 93, 141)); startLinkManager(); - + // Start the UAS Manager splashScreen->showMessage(tr("Starting UAS manager"), Qt::AlignLeft | Qt::AlignBottom, QColor(62, 93, 141)); startUASManager(); - + // Start the user interface splashScreen->showMessage(tr("Starting user interface"), Qt::AlignLeft | Qt::AlignBottom, QColor(62, 93, 141)); - + // The first call to instance() creates the MainWindow, so make sure it's passed the splashScreen. - mainWindow = MainWindow::instance_mode(splashScreen, mode); - + _mainWindow = MainWindow::instance_mode(splashScreen, mode); + UDPLink* udpLink = NULL; - - if (mainWindow->getCustomMode() == MainWindow::CUSTOM_MODE_WIFI) + + if (_mainWindow->getCustomMode() == MainWindow::CUSTOM_MODE_WIFI) { // Connect links // to make sure that all components are initialized when the // first messages arrive udpLink = new UDPLink(QHostAddress::Any, 14550); LinkManager::instance()->add(udpLink); - } else if (mainWindow->getCustomMode() == MainWindow::CUSTOM_MODE_PX4) { - udpLink = new UDPLink(QHostAddress::Any, 14550); - LinkManager::instance()->add(udpLink); - SerialLink *slink = new SerialLink(); - LinkManager::instance()->add(slink); } else { // We want to have a default serial link available for "quick" connecting. SerialLink *slink = new SerialLink(); LinkManager::instance()->add(slink); } - + #ifdef QGC_RTLAB_ENABLED // Add OpalRT Link, but do not connect OpalLink* opalLink = new OpalLink(); MainWindow::instance()->addLink(opalLink); #endif - + // Remove splash screen - splashScreen->finish(mainWindow); - - if (upgraded) mainWindow->showInfoMessage(tr("Default Settings Loaded"), + splashScreen->finish(_mainWindow); + + if (upgraded) _mainWindow->showInfoMessage(tr("Default Settings Loaded"), tr("qgroundcontrol has been upgraded from version %1 to version %2. Some of your user preferences have been reset to defaults for safety reasons. Please adjust them where needed.").arg(lastApplicationVersion).arg(QGC_APPLICATION_VERSION)); - + // Check if link could be connected if (udpLink && !udpLink->connect()) { @@ -216,17 +213,19 @@ QGCCore::QGCCore(bool firstStart, int &argc, char* argv[]) : QApplication(argc, msgBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No); msgBox.setDefaultButton(QMessageBox::No); int ret = msgBox.exec(); - + // Close the message box shortly after the click to prevent accidental clicks QTimer::singleShot(15000, &msgBox, SLOT(reject())); - + // Exit application if (ret == QMessageBox::Yes) { //mainWindow->close(); - QTimer::singleShot(200, mainWindow, SLOT(close())); + QTimer::singleShot(200, _mainWindow, SLOT(close())); } } + + return true; } /** @@ -235,23 +234,8 @@ QGCCore::QGCCore(bool firstStart, int &argc, char* argv[]) : QApplication(argc, **/ QGCCore::~QGCCore() { - - if (welcome) - { - delete welcome; - } else { - //mainWindow->storeSettings(); - //mainWindow->close(); - //mainWindow->deleteLater(); - // Delete singletons - // First systems - delete UASManager::instance(); - // then links - delete LinkManager::instance(); - // Finally the main window - //delete MainWindow::instance(); - //The main window now autodeletes on close. - } + delete UASManager::instance(); + delete LinkManager::instance(); } /** @@ -305,14 +289,3 @@ void QGCCore::startUASManager() } } } - -void QGCCore::customViewModeSelected(enum MainWindow::CUSTOM_MODE mode) -{ - QSettings settings; - settings.setValue("QGC_CUSTOM_MODE", (unsigned int)mode); - // Store settings only if requested by user - settings.setValue("QGC_CUSTOM_MODE_STORED", welcome->getStoreSettings()); - settings.sync(); - welcome->close(); - -} diff --git a/src/QGCCore.h b/src/QGCCore.h index 742752fb9f8f76ad357a322d6eb736f2e1adfb2b..c6c3c4186712f98940508723153673f0b7d71cd4 100644 --- a/src/QGCCore.h +++ b/src/QGCCore.h @@ -36,15 +36,12 @@ This file is part of the PIXHAWK project #include #include "MainWindow.h" -#include "QGCWelcomeMainWindow.h" #include "UASManager.h" #include "LinkManager.h" -/*#include "ViconTarsusProtocol.h" */ #ifdef QGC_RTLAB_ENABLED - #include "OpalLink.h" - #endif + /** * @brief The main application and management class. * @@ -57,16 +54,12 @@ class QGCCore : public QApplication Q_OBJECT public: - QGCCore(bool firstStart, int &argc, char* argv[]); + QGCCore(int &argc, char* argv[]); ~QGCCore(); - - bool getRestartRequested() - { - return restartRequested; - } - -public slots: - void customViewModeSelected(enum MainWindow::CUSTOM_MODE mode); + + /// @brief Initialize the applicaation. + /// @return false: init failed, app should exit + bool init(void); protected: void startLinkManager(); @@ -79,9 +72,7 @@ protected: void startUASManager(); private: - MainWindow* mainWindow; - bool restartRequested; - QGCWelcomeMainWindow* welcome; + MainWindow* _mainWindow; }; #endif /* _CORE_H_ */ diff --git a/src/main.cc b/src/main.cc index bef2636f13157cb2a9e9165765e76323d6e3569a..519a8b389c14c329b10aa94fd4692046664360dd 100644 --- a/src/main.cc +++ b/src/main.cc @@ -140,26 +140,12 @@ int main(int argc, char *argv[]) } #endif - QGCCore* core = NULL; - int val; - bool firstStart = true; - - do { - if (core) { - delete core; - firstStart = false; - } - core = new QGCCore(firstStart, argc, argv); - - if (!QSslSocket::supportsSsl()) { - QMessageBox::critical(NULL, - QObject::tr("Missing SSL Support"), - QObject::tr("QGroundControl requires support for SSL to be installed prior to running. Please see http://www.qgroundcontrol.org/downloads for instructions on installing prerequisites for QGroundControl.")); - return 1; - } - - val = core->exec(); - } while (core->getRestartRequested()); + QGCCore* core = new QGCCore(argc, argv); + Q_CHECK_PTR(core); + + if (!core->init()) { + return -1; + } - return val; + return core->exec(); } diff --git a/src/ui/QGCWelcomeWidget.cc b/src/ui/QGCWelcomeWidget.cc deleted file mode 100644 index b653ee662ce6bf9d3ece0c715ee1cc8c6771ada3..0000000000000000000000000000000000000000 --- a/src/ui/QGCWelcomeWidget.cc +++ /dev/null @@ -1,14 +0,0 @@ -#include "QGCWelcomeWidget.h" -#include "ui_QGCWelcomeWidget.h" - -QGCWelcomeWidget::QGCWelcomeWidget(QWidget *parent) : - QWidget(parent), - ui(new Ui::QGCWelcomeWidget) -{ - ui->setupUi(this); -} - -QGCWelcomeWidget::~QGCWelcomeWidget() -{ - delete ui; -} diff --git a/src/ui/QGCWelcomeWidget.h b/src/ui/QGCWelcomeWidget.h deleted file mode 100644 index 2916c34200539a1d4723c4223cf6aeb91935169e..0000000000000000000000000000000000000000 --- a/src/ui/QGCWelcomeWidget.h +++ /dev/null @@ -1,22 +0,0 @@ -#ifndef QGCWELCOMEWIDGET_H -#define QGCWELCOMEWIDGET_H - -#include - -namespace Ui { -class QGCWelcomeWidget; -} - -class QGCWelcomeWidget : public QWidget -{ - Q_OBJECT - -public: - explicit QGCWelcomeWidget(QWidget *parent = 0); - ~QGCWelcomeWidget(); - -private: - Ui::QGCWelcomeWidget *ui; -}; - -#endif // QGCWELCOMEWIDGET_H diff --git a/src/ui/QGCWelcomeWidget.ui b/src/ui/QGCWelcomeWidget.ui deleted file mode 100644 index a65557dc0322924338e6ffb5da06be84be3157f4..0000000000000000000000000000000000000000 --- a/src/ui/QGCWelcomeWidget.ui +++ /dev/null @@ -1,66 +0,0 @@ - - - QGCWelcomeWidget - - - - 0 - 0 - 400 - 300 - - - - Form - - - - 30 - - - 30 - - - - - - 100 - 100 - - - - ... - - - - - - - - 100 - 100 - - - - ... - - - - - - - - 100 - 100 - - - - ... - - - - - - - - diff --git a/src/ui/main/QGCViewModeSelection.cc b/src/ui/main/QGCViewModeSelection.cc deleted file mode 100644 index 68932c7c72e5d15c9f334c3f23ef164f693d5718..0000000000000000000000000000000000000000 --- a/src/ui/main/QGCViewModeSelection.cc +++ /dev/null @@ -1,47 +0,0 @@ -#include "QGCViewModeSelection.h" -#include "ui_QGCViewModeSelection.h" -#include "QGC.h" -#include "MainWindow.h" - -QGCViewModeSelection::QGCViewModeSelection(QWidget *parent) : - QWidget(parent), - ui(new Ui::QGCViewModeSelection), - selected(false) -{ - ui->setupUi(this); - - connect(ui->viewModeGeneric, SIGNAL(clicked()), this, SLOT(selectGeneric())); - connect(ui->viewModeAR, SIGNAL(clicked()), this, SLOT(selectWifi())); - connect(ui->viewModePX4, SIGNAL(clicked()), this, SLOT(selectPX4())); - connect(ui->notAgainCheckBox, SIGNAL(clicked(bool)), this, SIGNAL(settingsStorageRequested(bool))); -} - -QGCViewModeSelection::~QGCViewModeSelection() -{ - delete ui; -} - -enum MainWindow::CUSTOM_MODE QGCViewModeSelection::waitForInput() { - while (!selected) - QGC::SLEEP::msleep(200); - - return mode; -} - -void QGCViewModeSelection::selectGeneric() { - emit customViewModeSelected(MainWindow::CUSTOM_MODE_NONE); - mode = MainWindow::CUSTOM_MODE_NONE; - selected = true; -} - -void QGCViewModeSelection::selectWifi() { - emit customViewModeSelected(MainWindow::CUSTOM_MODE_WIFI); - mode = MainWindow::CUSTOM_MODE_WIFI; - selected = true; -} - -void QGCViewModeSelection::selectPX4() { - emit customViewModeSelected(MainWindow::CUSTOM_MODE_PX4); - mode = MainWindow::CUSTOM_MODE_PX4; - selected = true; -} diff --git a/src/ui/main/QGCViewModeSelection.h b/src/ui/main/QGCViewModeSelection.h deleted file mode 100644 index 1d1e81d702b64c063a8c32c97c3a7cfd35742255..0000000000000000000000000000000000000000 --- a/src/ui/main/QGCViewModeSelection.h +++ /dev/null @@ -1,37 +0,0 @@ -#ifndef QGCVIEWMODESELECTION_H -#define QGCVIEWMODESELECTION_H - -#include -#include "MainWindow.h" - -namespace Ui { -class QGCViewModeSelection; -} - -class QGCViewModeSelection : public QWidget -{ - Q_OBJECT - -public: - explicit QGCViewModeSelection(QWidget *parent = 0); - ~QGCViewModeSelection(); - - enum MainWindow::CUSTOM_MODE waitForInput(); - -public slots: - - void selectGeneric(); - void selectPX4(); - void selectWifi(); - -signals: - void customViewModeSelected(enum MainWindow::CUSTOM_MODE mode); - void settingsStorageRequested(bool requested); - -private: - Ui::QGCViewModeSelection *ui; - bool selected; - enum MainWindow::CUSTOM_MODE mode; -}; - -#endif // QGCVIEWMODESELECTION_H diff --git a/src/ui/main/QGCViewModeSelection.ui b/src/ui/main/QGCViewModeSelection.ui deleted file mode 100644 index 968a888a602639cda4616dca15cb9bfb1dd952a5..0000000000000000000000000000000000000000 --- a/src/ui/main/QGCViewModeSelection.ui +++ /dev/null @@ -1,167 +0,0 @@ - - - QGCViewModeSelection - - - - 0 - 0 - 750 - 409 - - - - Form - - - - - - Do not ask again on next startup. The selection can be changed any time in the preferences. - - - - - - - Qt::Horizontal - - - - 47 - 20 - - - - - - - - Qt::Horizontal - - - - 46 - 20 - - - - - - - - - - - - - - - :/files/images/actions/qgroundcontrol-wifi.svg:/files/images/actions/qgroundcontrol-wifi.svg - - - - 120 - 120 - - - - - - - - PX4 Autopilot - - - - - - - WiFi / UDP - - - - - - - - - - - :/files/images/actions/qgroundcontrol-px4.svg:/files/images/actions/qgroundcontrol-px4.svg - - - - 120 - 120 - - - - - - - - - - - - :/files/images/actions/qgroundcontrol-generic.svg:/files/images/actions/qgroundcontrol-generic.svg - - - - 120 - 120 - - - - - - - - Radio / Serial Link - - - - - - - - - - Please select the connection or autopilot you want to use QGroundControl with. - - - - - - - Qt::Vertical - - - - 20 - 76 - - - - - - - - Qt::Vertical - - - - 20 - 76 - - - - - - - - - - - diff --git a/src/ui/main/QGCWelcomeMainWindow.cc b/src/ui/main/QGCWelcomeMainWindow.cc deleted file mode 100644 index 862ce88af6eb429b0786932a6bd04329a79a3327..0000000000000000000000000000000000000000 --- a/src/ui/main/QGCWelcomeMainWindow.cc +++ /dev/null @@ -1,48 +0,0 @@ -#include "QGCWelcomeMainWindow.h" -#include "ui_QGCWelcomeMainWindow.h" -#include "MainWindow.h" -#include "QGCViewModeSelection.h" - -QGCWelcomeMainWindow::QGCWelcomeMainWindow(QWidget *parent) : - QMainWindow(parent), - ui(new Ui::QGCWelcomeMainWindow), - storeSettings(false) -{ - ui->setupUi(this); - - QString windowname = qApp->applicationName() + " " + qApp->applicationVersion(); - setWindowTitle(windowname); - - viewModeSelection = new QGCViewModeSelection(this); - - connect(viewModeSelection, SIGNAL(customViewModeSelected(MainWindow::CUSTOM_MODE)), this, SIGNAL(customViewModeSelected(MainWindow::CUSTOM_MODE))); - connect(viewModeSelection, SIGNAL(settingsStorageRequested(bool)), this, SIGNAL(settingsStorageRequested(bool))); - connect(viewModeSelection, SIGNAL(settingsStorageRequested(bool)), this, SLOT(setStoreSettings(bool))); - - setCentralWidget(viewModeSelection); - - // Load the new stylesheet. - QFile styleSheet(":files/styles/style-dark.css"); - - // Attempt to open the stylesheet. - if (styleSheet.open(QIODevice::ReadOnly | QIODevice::Text)) - { - // Signal to the user that the app will pause to apply a new stylesheet - qApp->setOverrideCursor(Qt::WaitCursor); - - qApp->setStyleSheet(styleSheet.readAll()); - - // Finally restore the cursor before returning. - qApp->restoreOverrideCursor(); - } - - resize(780, 400); - show(); - -} - -QGCWelcomeMainWindow::~QGCWelcomeMainWindow() -{ - delete ui; - delete viewModeSelection; -} diff --git a/src/ui/main/QGCWelcomeMainWindow.h b/src/ui/main/QGCWelcomeMainWindow.h deleted file mode 100644 index 544a2de664a2ed1fd3f3570daeabce293d461c9f..0000000000000000000000000000000000000000 --- a/src/ui/main/QGCWelcomeMainWindow.h +++ /dev/null @@ -1,41 +0,0 @@ -#ifndef QGCWELCOMEMAINWINDOW_H -#define QGCWELCOMEMAINWINDOW_H - -#include -#include "MainWindow.h" -#include "QGCViewModeSelection.h" - -namespace Ui { -class QGCWelcomeMainWindow; -} - -class QGCWelcomeMainWindow : public QMainWindow -{ - Q_OBJECT - -public: - explicit QGCWelcomeMainWindow(QWidget *parent = 0); - ~QGCWelcomeMainWindow(); - - bool getStoreSettings() - { - return storeSettings; - } - -public slots: - void setStoreSettings(bool settings) - { - storeSettings = settings; - } - -signals: - void customViewModeSelected(enum MainWindow::CUSTOM_MODE mode); - void settingsStorageRequested(bool requested); - -private: - Ui::QGCWelcomeMainWindow *ui; - QGCViewModeSelection* viewModeSelection; - bool storeSettings; -}; - -#endif // QGCWELCOMEMAINWINDOW_H diff --git a/src/ui/main/QGCWelcomeMainWindow.ui b/src/ui/main/QGCWelcomeMainWindow.ui deleted file mode 100644 index e4b0441e843077c33b8fbde0cc308d9f96917453..0000000000000000000000000000000000000000 --- a/src/ui/main/QGCWelcomeMainWindow.ui +++ /dev/null @@ -1,20 +0,0 @@ - - - QGCWelcomeMainWindow - - - - 0 - 0 - 800 - 600 - - - - MainWindow - - - - - -