diff --git a/qgroundcontrol.qrc b/qgroundcontrol.qrc index 8de7ae380fead56ae74a6508e900e9851b821419..3d0c0b07982c4e32ba5f051421806208b7289756 100644 --- a/qgroundcontrol.qrc +++ b/qgroundcontrol.qrc @@ -28,6 +28,7 @@ src/ui/preferences/DebugWindow.qml src/AutoPilotPlugins/Common/ESP8266Component.qml src/AutoPilotPlugins/Common/ESP8266ComponentSummary.qml + src/ui/ExitWithErrorWindow.qml src/VehicleSetup/FirmwareUpgrade.qml src/FlightDisplay/FlightDisplayViewDummy.qml src/FlightDisplay/FlightDisplayViewUVC.qml diff --git a/src/QGCApplication.cc b/src/QGCApplication.cc index 800462089497ae99b8d7de7182ce1bfa6f20aee6..f81b185c941f6b1f3145ddb3c3dadb5e707329ad 100644 --- a/src/QGCApplication.cc +++ b/src/QGCApplication.cc @@ -26,11 +26,6 @@ #include #include #include -#ifdef Q_OS_LINUX -#ifndef __mobile__ - #include -#endif -#endif #ifdef QGC_ENABLE_BLUETOOTH #include @@ -164,42 +159,33 @@ QGCApplication::QGCApplication(int &argc, char* argv[], bool unitTesting) , _runningUnitTests (unitTesting) { _app = this; - // Setup for network proxy support - QNetworkProxyFactory::setUseSystemConfiguration(true); - #ifdef Q_OS_LINUX #ifndef __mobile__ if (!_runningUnitTests) { if (getuid() == 0) { - QMessageBox msgBox; - msgBox.setInformativeText(tr("You are running %1 as root. " - "You should not do this since it will cause other issues with %1. " - "%1 will now exit. " - "If you are having serial port issues on Ubuntu, execute the following commands to fix most issues:\n" - "sudo usermod -a -G dialout $USER\n" - "sudo apt-get remove modemmanager").arg(qgcApp()->applicationName())); - msgBox.setStandardButtons(QMessageBox::Ok); - msgBox.setDefaultButton(QMessageBox::Ok); - msgBox.exec(); - _exit(0); + _exitWithError(QString( + tr("You are running %1 as root. " + "You should not do this since it will cause other issues with %1." + "%1 will now exit.

" + "If you are having serial port issues on Ubuntu, execute the following commands to fix most issues:
" + "
sudo usermod -a -G dialout $USER
" + "sudo apt-get remove modemmanager
").arg(qgcApp()->applicationName()))); + return; } - // Determine if we have the correct permissions to access USB serial devices QFile permFile("/etc/group"); if(permFile.open(QIODevice::ReadOnly)) { while(!permFile.atEnd()) { QString line = permFile.readLine(); if (line.contains("dialout") && !line.contains(getenv("USER"))) { - QMessageBox msgBox; - msgBox.setInformativeText("The current user does not have the correct permissions to access serial devices. " - "You should also remove modemmanager since it also interferes. " - "If you are using Ubuntu, execute the following commands to fix these issues:\n" - "sudo usermod -a -G dialout $USER\n" - "sudo apt-get remove modemmanager"); - msgBox.setStandardButtons(QMessageBox::Ok); - msgBox.setDefaultButton(QMessageBox::Ok); - msgBox.exec(); - break; + permFile.close(); + _exitWithError(QString( + tr("The current user does not have the correct permissions to access serial devices. " + "You should also remove modemmanager since it also interferes.

" + "If you are using Ubuntu, execute the following commands to fix these issues:
" + "
sudo usermod -a -G dialout $USER
" + "sudo apt-get remove modemmanager
"))); + return; } } permFile.close(); @@ -208,6 +194,9 @@ QGCApplication::QGCApplication(int &argc, char* argv[], bool unitTesting) #endif #endif + // Setup for network proxy support + QNetworkProxyFactory::setUseSystemConfiguration(true); + // Parse command line options bool fClearSettingsOptions = false; // Clear stored settings @@ -348,6 +337,17 @@ QGCApplication::QGCApplication(int &argc, char* argv[], bool unitTesting) _checkForNewVersion(); } +void QGCApplication::_exitWithError(QString errorMessage) +{ + _error = true; + QQmlApplicationEngine* pEngine = new QQmlApplicationEngine(this); + pEngine->addImportPath("qrc:/qml"); + pEngine->rootContext()->setContextProperty("errorMessage", errorMessage); + pEngine->load(QUrl(QStringLiteral("qrc:/qml/ExitWithErrorWindow.qml"))); + // Exit main application when last window is closed + connect(this, &QGCApplication::lastWindowClosed, this, QGCApplication::quit); +} + void QGCApplication::setLanguage() { _locale = QLocale::system(); diff --git a/src/QGCApplication.h b/src/QGCApplication.h index 606b10eb1811bd7c0322de14e089eb744b1fd0fe..527d66754f933dfdd09ae8ec436b2a90bd857125 100644 --- a/src/QGCApplication.h +++ b/src/QGCApplication.h @@ -145,6 +145,8 @@ public: static QGCApplication* _app; ///< Our own singleton. Should be reference directly by qgcApp + bool isErrorState() { return _error; } + public: // Although public, these methods are internal and should only be called by UnitTest code @@ -166,6 +168,7 @@ private slots: private: QObject* _rootQmlObject (); void _checkForNewVersion (); + void _exitWithError (QString errorMessage); bool _runningUnitTests; ///< true: running unit tests, false: normal app @@ -190,6 +193,7 @@ private: QTranslator _QGCTranslator; QTranslator _QGCTranslatorQt; QLocale _locale; + bool _error = false; static const char* _settingsVersionKey; ///< Settings key which hold settings version static const char* _deleteAllSettingsKey; ///< If this settings key is set on boot, all settings will be deleted diff --git a/src/main.cc b/src/main.cc index b3c4473e7e0a9141f44fe54f02d79ffb6049f723..02be68a9c4c615af8bd37c26f29d164cadd5c3db 100644 --- a/src/main.cc +++ b/src/main.cc @@ -328,6 +328,10 @@ int main(int argc, char *argv[]) QCoreApplication::setAttribute(Qt::AA_UseHighDpiPixmaps); QGCApplication* app = new QGCApplication(argc, argv, runUnitTests); Q_CHECK_PTR(app); + if(app->isErrorState()) { + app->exec(); + return -1; + } #ifdef Q_OS_LINUX QApplication::setWindowIcon(QIcon(":/res/resources/icons/qgroundcontrol.ico")); diff --git a/src/ui/ExitWithErrorWindow.qml b/src/ui/ExitWithErrorWindow.qml new file mode 100644 index 0000000000000000000000000000000000000000..4084108631973ca04ddcd630cb2808118b5a5066 --- /dev/null +++ b/src/ui/ExitWithErrorWindow.qml @@ -0,0 +1,54 @@ +/**************************************************************************** + * + * (c) 2009-2016 QGROUNDCONTROL PROJECT + * + * QGroundControl is licensed according to the terms in the file + * COPYING.md in the root of the source code directory. + * + ****************************************************************************/ + +import QtQuick 2.11 +import QtQuick.Controls 2.4 +import QtQuick.Dialogs 1.3 +import QtQuick.Layouts 1.11 +import QtQuick.Window 2.11 + +ApplicationWindow { + id: errorWindow + minimumWidth: messageArea.width + 60 + minimumHeight: messageArea.height + 60 + width: messageArea.width + 60 + height: messageArea.height + 60 + visible: true + + //------------------------------------------------------------------------- + //-- Main, full window background (Fly View) + background: Item { + id: rootBackground + anchors.fill: parent + Rectangle { + anchors.fill: parent + color: "#000000" + } + } + + Column { + id: messageArea + spacing: 20 + anchors.centerIn: parent + Label { + width: 600 + text: errorMessage + color: "#eecc44" + wrapMode: Text.WordWrap + anchors.horizontalCenter: parent.horizontalCenter + } + Button { + text: qsTr("Close") + highlighted: true + onClicked: errorWindow.close() + anchors.horizontalCenter: parent.horizontalCenter + } + } + +}