@@ -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 606b10e..527d667 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 b3c4473..02be68a 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 0000000..4084108
--- /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
+ }
+ }
+
+}