Commit a1de93c1 authored by Gus Grubba's avatar Gus Grubba

Replace usage of QMessageBox with a QML window.

parent d2ab2510
...@@ -28,6 +28,7 @@ ...@@ -28,6 +28,7 @@
<file alias="DebugWindow.qml">src/ui/preferences/DebugWindow.qml</file> <file alias="DebugWindow.qml">src/ui/preferences/DebugWindow.qml</file>
<file alias="ESP8266Component.qml">src/AutoPilotPlugins/Common/ESP8266Component.qml</file> <file alias="ESP8266Component.qml">src/AutoPilotPlugins/Common/ESP8266Component.qml</file>
<file alias="ESP8266ComponentSummary.qml">src/AutoPilotPlugins/Common/ESP8266ComponentSummary.qml</file> <file alias="ESP8266ComponentSummary.qml">src/AutoPilotPlugins/Common/ESP8266ComponentSummary.qml</file>
<file alias="ExitWithErrorWindow.qml">src/ui/ExitWithErrorWindow.qml</file>
<file alias="FirmwareUpgrade.qml">src/VehicleSetup/FirmwareUpgrade.qml</file> <file alias="FirmwareUpgrade.qml">src/VehicleSetup/FirmwareUpgrade.qml</file>
<file alias="FlightDisplayViewDummy.qml">src/FlightDisplay/FlightDisplayViewDummy.qml</file> <file alias="FlightDisplayViewDummy.qml">src/FlightDisplay/FlightDisplayViewDummy.qml</file>
<file alias="FlightDisplayViewUVC.qml">src/FlightDisplay/FlightDisplayViewUVC.qml</file> <file alias="FlightDisplayViewUVC.qml">src/FlightDisplay/FlightDisplayViewUVC.qml</file>
......
...@@ -26,11 +26,6 @@ ...@@ -26,11 +26,6 @@
#include <QStringListModel> #include <QStringListModel>
#include <QRegularExpression> #include <QRegularExpression>
#include <QFontDatabase> #include <QFontDatabase>
#ifdef Q_OS_LINUX
#ifndef __mobile__
#include <QMessageBox>
#endif
#endif
#ifdef QGC_ENABLE_BLUETOOTH #ifdef QGC_ENABLE_BLUETOOTH
#include <QBluetoothLocalDevice> #include <QBluetoothLocalDevice>
...@@ -164,42 +159,33 @@ QGCApplication::QGCApplication(int &argc, char* argv[], bool unitTesting) ...@@ -164,42 +159,33 @@ QGCApplication::QGCApplication(int &argc, char* argv[], bool unitTesting)
, _runningUnitTests (unitTesting) , _runningUnitTests (unitTesting)
{ {
_app = this; _app = this;
// Setup for network proxy support
QNetworkProxyFactory::setUseSystemConfiguration(true);
#ifdef Q_OS_LINUX #ifdef Q_OS_LINUX
#ifndef __mobile__ #ifndef __mobile__
if (!_runningUnitTests) { if (!_runningUnitTests) {
if (getuid() == 0) { if (getuid() == 0) {
QMessageBox msgBox; _exitWithError(QString(
msgBox.setInformativeText(tr("You are running %1 as root. " tr("You are running %1 as root. "
"You should not do this since it will cause other issues with %1. " "You should not do this since it will cause other issues with %1."
"%1 will now exit. " "%1 will now exit.<br/><br/>"
"If you are having serial port issues on Ubuntu, execute the following commands to fix most issues:\n" "If you are having serial port issues on Ubuntu, execute the following commands to fix most issues:<br/>"
"sudo usermod -a -G dialout $USER\n" "<pre>sudo usermod -a -G dialout $USER<br/>"
"sudo apt-get remove modemmanager").arg(qgcApp()->applicationName())); "sudo apt-get remove modemmanager</pre>").arg(qgcApp()->applicationName())));
msgBox.setStandardButtons(QMessageBox::Ok); return;
msgBox.setDefaultButton(QMessageBox::Ok);
msgBox.exec();
_exit(0);
} }
// Determine if we have the correct permissions to access USB serial devices // Determine if we have the correct permissions to access USB serial devices
QFile permFile("/etc/group"); QFile permFile("/etc/group");
if(permFile.open(QIODevice::ReadOnly)) { if(permFile.open(QIODevice::ReadOnly)) {
while(!permFile.atEnd()) { while(!permFile.atEnd()) {
QString line = permFile.readLine(); QString line = permFile.readLine();
if (line.contains("dialout") && !line.contains(getenv("USER"))) { if (line.contains("dialout") && !line.contains(getenv("USER"))) {
QMessageBox msgBox; permFile.close();
msgBox.setInformativeText("The current user does not have the correct permissions to access serial devices. " _exitWithError(QString(
"You should also remove modemmanager since it also interferes. " tr("The current user does not have the correct permissions to access serial devices. "
"If you are using Ubuntu, execute the following commands to fix these issues:\n" "You should also remove modemmanager since it also interferes.<br/><br/>"
"sudo usermod -a -G dialout $USER\n" "If you are using Ubuntu, execute the following commands to fix these issues:<br/>"
"sudo apt-get remove modemmanager"); "<pre>sudo usermod -a -G dialout $USER<br/>"
msgBox.setStandardButtons(QMessageBox::Ok); "sudo apt-get remove modemmanager</pre>")));
msgBox.setDefaultButton(QMessageBox::Ok); return;
msgBox.exec();
break;
} }
} }
permFile.close(); permFile.close();
...@@ -208,6 +194,9 @@ QGCApplication::QGCApplication(int &argc, char* argv[], bool unitTesting) ...@@ -208,6 +194,9 @@ QGCApplication::QGCApplication(int &argc, char* argv[], bool unitTesting)
#endif #endif
#endif #endif
// Setup for network proxy support
QNetworkProxyFactory::setUseSystemConfiguration(true);
// Parse command line options // Parse command line options
bool fClearSettingsOptions = false; // Clear stored settings bool fClearSettingsOptions = false; // Clear stored settings
...@@ -348,6 +337,17 @@ QGCApplication::QGCApplication(int &argc, char* argv[], bool unitTesting) ...@@ -348,6 +337,17 @@ QGCApplication::QGCApplication(int &argc, char* argv[], bool unitTesting)
_checkForNewVersion(); _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() void QGCApplication::setLanguage()
{ {
_locale = QLocale::system(); _locale = QLocale::system();
......
...@@ -145,6 +145,8 @@ public: ...@@ -145,6 +145,8 @@ public:
static QGCApplication* _app; ///< Our own singleton. Should be reference directly by qgcApp static QGCApplication* _app; ///< Our own singleton. Should be reference directly by qgcApp
bool isErrorState() { return _error; }
public: public:
// Although public, these methods are internal and should only be called by UnitTest code // Although public, these methods are internal and should only be called by UnitTest code
...@@ -166,6 +168,7 @@ private slots: ...@@ -166,6 +168,7 @@ private slots:
private: private:
QObject* _rootQmlObject (); QObject* _rootQmlObject ();
void _checkForNewVersion (); void _checkForNewVersion ();
void _exitWithError (QString errorMessage);
bool _runningUnitTests; ///< true: running unit tests, false: normal app bool _runningUnitTests; ///< true: running unit tests, false: normal app
...@@ -190,6 +193,7 @@ private: ...@@ -190,6 +193,7 @@ private:
QTranslator _QGCTranslator; QTranslator _QGCTranslator;
QTranslator _QGCTranslatorQt; QTranslator _QGCTranslatorQt;
QLocale _locale; QLocale _locale;
bool _error = false;
static const char* _settingsVersionKey; ///< Settings key which hold settings version 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 static const char* _deleteAllSettingsKey; ///< If this settings key is set on boot, all settings will be deleted
......
...@@ -328,6 +328,10 @@ int main(int argc, char *argv[]) ...@@ -328,6 +328,10 @@ int main(int argc, char *argv[])
QCoreApplication::setAttribute(Qt::AA_UseHighDpiPixmaps); QCoreApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);
QGCApplication* app = new QGCApplication(argc, argv, runUnitTests); QGCApplication* app = new QGCApplication(argc, argv, runUnitTests);
Q_CHECK_PTR(app); Q_CHECK_PTR(app);
if(app->isErrorState()) {
app->exec();
return -1;
}
#ifdef Q_OS_LINUX #ifdef Q_OS_LINUX
QApplication::setWindowIcon(QIcon(":/res/resources/icons/qgroundcontrol.ico")); QApplication::setWindowIcon(QIcon(":/res/resources/icons/qgroundcontrol.ico"));
......
/****************************************************************************
*
* (c) 2009-2016 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
*
* 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
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment