diff --git a/src/QGCApplication.cc b/src/QGCApplication.cc index 03271b21f03bcda036bf2c37779570f898cbd722..c8ef3a87dc7bbe361c057f65779552d9486a2909 100644 --- a/src/QGCApplication.cc +++ b/src/QGCApplication.cc @@ -581,3 +581,26 @@ void QGCApplication::_loadCurrentStyle(void) // Finally restore the cursor before returning. restoreOverrideCursor(); } + +void QGCApplication::reconnectAfterWait(int waitSeconds) +{ + LinkManager* linkManager = LinkManager::instance(); + Q_ASSERT(linkManager); + + Q_ASSERT(linkManager->getLinks().count() == 1); + LinkInterface* link = linkManager->getLinks()[0]; + + // Save the link configuration so we can restart the link laster + _reconnectLinkConfig = linkManager->getLinks()[0]->getLinkConfiguration(); + + // Disconnect and wait + + linkManager->disconnectLink(link); + QTimer::singleShot(waitSeconds * 1000, this, &QGCApplication::_reconnect); +} + +void QGCApplication::_reconnect(void) +{ + qgcApp()->restoreOverrideCursor(); + LinkManager::instance()->createConnectedLink(_reconnectLinkConfig); +} \ No newline at end of file diff --git a/src/QGCApplication.h b/src/QGCApplication.h index 5b75acfed0cd29757c6d8a244890f1ea3d5ec3a9..8bd84b55d7eb489d3adfe58526cae174c3f760a6 100644 --- a/src/QGCApplication.h +++ b/src/QGCApplication.h @@ -34,6 +34,8 @@ #include +#include "LinkConfiguration.h" + #ifdef QGC_RTLAB_ENABLED #include "OpalLink.h" #endif @@ -93,6 +95,9 @@ public: /// Set the current UI style void setStyle(bool styleIsDark); + /// Disconnects the current link and waits for the specified number of seconds before reconnecting. + void reconnectAfterWait(int waitSeconds); + public slots: /// You can connect to this slot to show an information message box from a different thread. void informationMessageBoxOnMainThread(const QString& title, const QString& msg); @@ -132,6 +137,9 @@ public: static QGCApplication* _app; ///< Our own singleton. Should be reference directly by qgcApp +private slots: + void _reconnect(void); + private: void _createSingletons(void); void _destroySingletons(void); @@ -153,6 +161,8 @@ private: static const char* _lightStyleFile; bool _styleIsDark; ///< true: dark style, false: light style + LinkConfiguration* _reconnectLinkConfig; ///< Configuration to reconnect for reconnectAfterWai + /// Unit Test have access to creating and destroying singletons friend class UnitTest; };