Commit a1de93c1 authored by Gus Grubba's avatar Gus Grubba

Replace usage of QMessageBox with a QML window.

parent d2ab2510
......@@ -28,6 +28,7 @@
<file alias="DebugWindow.qml">src/ui/preferences/DebugWindow.qml</file>
<file alias="ESP8266Component.qml">src/AutoPilotPlugins/Common/ESP8266Component.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="FlightDisplayViewDummy.qml">src/FlightDisplay/FlightDisplayViewDummy.qml</file>
<file alias="FlightDisplayViewUVC.qml">src/FlightDisplay/FlightDisplayViewUVC.qml</file>
......
......@@ -26,11 +26,6 @@
#include <QStringListModel>
#include <QRegularExpression>
#include <QFontDatabase>
#ifdef Q_OS_LINUX
#ifndef __mobile__
#include <QMessageBox>
#endif
#endif
#ifdef QGC_ENABLE_BLUETOOTH
#include <QBluetoothLocalDevice>
......@@ -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.<br/><br/>"
"If you are having serial port issues on Ubuntu, execute the following commands to fix most issues:<br/>"
"<pre>sudo usermod -a -G dialout $USER<br/>"
"sudo apt-get remove modemmanager</pre>").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.<br/><br/>"
"If you are using Ubuntu, execute the following commands to fix these issues:<br/>"
"<pre>sudo usermod -a -G dialout $USER<br/>"
"sudo apt-get remove modemmanager</pre>")));
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();
......
......@@ -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
......
......@@ -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"));
......
/****************************************************************************
*
* (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