@ -24,6 +24,7 @@
@@ -24,6 +24,7 @@
# include <QStyleFactory>
# include <QAction>
# include <QStringListModel>
# include <QRegularExpression>
# ifdef QGC_ENABLE_BLUETOOTH
# include <QBluetoothLocalDevice>
@ -87,6 +88,7 @@
@@ -87,6 +88,7 @@
# include "EditPositionDialogController.h"
# include "FactValueSliderListModel.h"
# include "KMLFileHelper.h"
# include "QGCFileDownload.h"
# ifndef NO_SERIAL_LINK
# include "SerialLink.h"
@ -149,17 +151,21 @@ static QObject* kmlFileHelperSingletonFactory(QQmlEngine*, QJSEngine*)
@@ -149,17 +151,21 @@ static QObject* kmlFileHelperSingletonFactory(QQmlEngine*, QJSEngine*)
QGCApplication : : QGCApplication ( int & argc , char * argv [ ] , bool unitTesting )
# ifdef __mobile__
: QGuiApplication ( argc , argv )
, _qmlAppEngine ( nullptr )
: QGuiApplication ( argc , argv )
, _qmlAppEngine ( nullptr )
# else
: QApplication ( argc , argv )
: QApplication ( argc , argv )
# endif
, _runningUnitTests ( unitTesting )
, _logOutput ( false )
, _fakeMobile ( false )
, _settingsUpgraded ( false )
, _toolbox ( nullptr )
, _bluetoothAvailable ( false )
, _runningUnitTests ( unitTesting )
, _logOutput ( false )
, _fakeMobile ( false )
, _settingsUpgraded ( false )
, _majorVersion ( 0 )
, _minorVersion ( 0 )
, _buildVersion ( 0 )
, _currentVersionDownload ( nullptr )
, _toolbox ( nullptr )
, _bluetoothAvailable ( false )
{
_app = this ;
@ -330,6 +336,8 @@ QGCApplication::QGCApplication(int &argc, char* argv[], bool unitTesting)
@@ -330,6 +336,8 @@ QGCApplication::QGCApplication(int &argc, char* argv[], bool unitTesting)
_toolbox = new QGCToolbox ( this ) ;
_toolbox - > setChildToolboxes ( ) ;
_checkForNewVersion ( ) ;
}
void QGCApplication : : _shutdown ( void )
@ -702,3 +710,68 @@ bool QGCApplication::isInternetAvailable()
@@ -702,3 +710,68 @@ bool QGCApplication::isInternetAvailable()
{
return getQGCMapEngine ( ) - > isInternetActive ( ) ;
}
void QGCApplication : : _checkForNewVersion ( void )
{
# ifndef __mobile__
if ( ! _runningUnitTests ) {
if ( _parseVersionText ( applicationVersion ( ) , _majorVersion , _minorVersion , _buildVersion ) ) {
QString versionCheckFile = toolbox ( ) - > corePlugin ( ) - > stableVersionCheckFileUrl ( ) ;
if ( ! versionCheckFile . isEmpty ( ) ) {
_currentVersionDownload = new QGCFileDownload ( this ) ;
connect ( _currentVersionDownload , & QGCFileDownload : : downloadFinished , this , & QGCApplication : : _currentVersionDownloadFinished ) ;
connect ( _currentVersionDownload , & QGCFileDownload : : error , this , & QGCApplication : : _currentVersionDownloadError ) ;
_currentVersionDownload - > download ( versionCheckFile ) ;
}
}
}
# endif
}
void QGCApplication : : _currentVersionDownloadFinished ( QString remoteFile , QString localFile )
{
Q_UNUSED ( remoteFile ) ;
# ifdef __mobile__
Q_UNUSED ( localFile ) ;
# else
QFile versionFile ( localFile ) ;
if ( versionFile . open ( QIODevice : : ReadOnly ) ) {
QTextStream textStream ( & versionFile ) ;
QString version = textStream . readLine ( ) ;
qDebug ( ) < < version ;
int majorVersion , minorVersion , buildVersion ;
if ( _parseVersionText ( version , majorVersion , minorVersion , buildVersion ) ) {
if ( _majorVersion < majorVersion | |
( _majorVersion = = majorVersion & & _minorVersion < minorVersion ) | |
( _majorVersion = = majorVersion & & _minorVersion = = minorVersion & & _buildVersion < buildVersion ) ) {
QGCMessageBox : : information ( tr ( " New Version Available " ) , tr ( " There is a newer version of %1 available. You can download it from %2. " ) . arg ( applicationName ( ) ) . arg ( toolbox ( ) - > corePlugin ( ) - > stableDownloadLocation ( ) ) ) ;
}
}
}
_currentVersionDownload - > deleteLater ( ) ;
# endif
}
void QGCApplication : : _currentVersionDownloadError ( QString errorMsg )
{
Q_UNUSED ( errorMsg ) ;
_currentVersionDownload - > deleteLater ( ) ;
}
bool QGCApplication : : _parseVersionText ( const QString & versionString , int & majorVersion , int & minorVersion , int & buildVersion )
{
QRegularExpression regExp ( " v( \\ d+) \ \ . ( \ \ d + ) \ \ . ( \ \ d + ) " ) ;
QRegularExpressionMatch match = regExp . match ( versionString ) ;
if ( match . hasMatch ( ) & & match . lastCapturedIndex ( ) = = 3 ) {
majorVersion = match . captured ( 1 ) . toInt ( ) ;
minorVersion = match . captured ( 2 ) . toInt ( ) ;
buildVersion = match . captured ( 3 ) . toInt ( ) ;
return true ;
}
return false ;
}