@ -45,7 +45,6 @@ This file is part of the QGROUNDCONTROL project
@@ -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
@@ -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,
@@ -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,
@@ -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,
@@ -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,
@@ -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,
@@ -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,
@@ -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()
@@ -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 ( ) ;
}