Skip to content

Commit

Permalink
Merge pull request mavlink#930 from DonLakeFlyer/CustomModePrompt
Browse files Browse the repository at this point in the history
Remove custom mode startup screen
  • Loading branch information
LorenzMeier committed Oct 30, 2014
2 parents bc7a05b + 964600d commit c972425
Show file tree
Hide file tree
Showing 13 changed files with 67 additions and 585 deletions.
6 changes: 0 additions & 6 deletions qgroundcontrol.pro
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down Expand Up @@ -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 \
Expand Down Expand Up @@ -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 \
Expand Down
133 changes: 53 additions & 80 deletions src/QGCCore.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand All @@ -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);

Expand All @@ -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"))
{
Expand All @@ -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);
Expand All @@ -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
Expand All @@ -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())
{
Expand All @@ -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;
}

/**
Expand All @@ -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();
}

/**
Expand Down Expand Up @@ -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();

}
23 changes: 7 additions & 16 deletions src/QGCCore.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,12 @@ This file is part of the PIXHAWK project
#include <QApplication>

#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.
*
Expand All @@ -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();
Expand All @@ -79,9 +72,7 @@ public slots:
void startUASManager();

private:
MainWindow* mainWindow;
bool restartRequested;
QGCWelcomeMainWindow* welcome;
MainWindow* _mainWindow;
};

#endif /* _CORE_H_ */
28 changes: 7 additions & 21 deletions src/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
14 changes: 0 additions & 14 deletions src/ui/QGCWelcomeWidget.cc

This file was deleted.

Loading

0 comments on commit c972425

Please sign in to comment.