From 74ad0fd40a2bd2c8b2d816fdb887e3c3066aaa6a Mon Sep 17 00:00:00 2001 From: Fredrik Arvidsson Date: Sat, 30 Nov 2013 13:02:52 +0100 Subject: [PATCH] OP-1119 Added cancel functionality on download. Added soem more gui update logic. --- .../src/plugins/flightlog/FlightLogDialog.qml | 10 ++++++- .../plugins/flightlog/flightlogmanager.cpp | 26 ++++++++++++++++--- .../src/plugins/flightlog/flightlogmanager.h | 19 +++++++++++++- 3 files changed, 50 insertions(+), 5 deletions(-) diff --git a/ground/openpilotgcs/src/plugins/flightlog/FlightLogDialog.qml b/ground/openpilotgcs/src/plugins/flightlog/FlightLogDialog.qml index f9c3f8dc6..18debefc0 100644 --- a/ground/openpilotgcs/src/plugins/flightlog/FlightLogDialog.qml +++ b/ground/openpilotgcs/src/plugins/flightlog/FlightLogDialog.qml @@ -146,7 +146,7 @@ Rectangle { height: 40 Button { id: exportButton - enabled: !logManager.disableControls + enabled: !logManager.disableControls && !logManager.disableExport text: qsTr("Export...") activeFocusOnPress: true onClicked: logManager.exportLogs() @@ -161,10 +161,18 @@ Rectangle { Rectangle { Layout.fillWidth: true } + Button { + id: cancelButton + enabled: logManager.disableControls + text: qsTr("Cancel") + activeFocusOnPress: true + onClicked: logManager.cancelExportLogs() + } Button { id: okButton enabled: !logManager.disableControls text: qsTr("OK") + isDefault: true activeFocusOnPress: true onClicked: dialog.close() } diff --git a/ground/openpilotgcs/src/plugins/flightlog/flightlogmanager.cpp b/ground/openpilotgcs/src/plugins/flightlog/flightlogmanager.cpp index 45b58725a..48aec397f 100644 --- a/ground/openpilotgcs/src/plugins/flightlog/flightlogmanager.cpp +++ b/ground/openpilotgcs/src/plugins/flightlog/flightlogmanager.cpp @@ -37,7 +37,7 @@ #include "utils/logfile.h" FlightLogManager::FlightLogManager(QObject *parent) : - QObject(parent), m_disableControls(false) + QObject(parent), m_disableControls(false), m_cancelDownload(false) { ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance(); @@ -121,6 +121,7 @@ void FlightLogManager::clearLogList() m_logEntries.clear(); emit logEntriesChanged(); + setDisableExport(true); while (!tmpList.isEmpty()) { delete tmpList.takeFirst(); @@ -131,7 +132,7 @@ void FlightLogManager::retrieveLogs(int flightToRetrieve) { setDisableControls(true); QApplication::setOverrideCursor(Qt::WaitCursor); - + m_cancelDownload = false; UAVObjectUpdaterHelper updateHelper; UAVObjectRequestHelper requestHelper; @@ -169,16 +170,30 @@ void FlightLogManager::retrieveLogs(int flightToRetrieve) // We failed for some reason break; } + if (m_cancelDownload) { + break; + } + } + if (m_cancelDownload) { + break; } } + + if (m_cancelDownload) { + clearLogList(); + m_cancelDownload = false; + } + emit logEntriesChanged(); + setDisableExport(m_logEntries.count() == 0); + QApplication::restoreOverrideCursor(); setDisableControls(false); } void FlightLogManager::exportLogs() { - if(m_flightEntries.isEmpty()) { + if(m_logEntries.isEmpty()) { return; } @@ -231,6 +246,11 @@ void FlightLogManager::exportLogs() setDisableControls(false); } +void FlightLogManager::cancelExportLogs() +{ + m_cancelDownload = true; +} + void FlightLogManager::updateFlightEntries(quint16 currentFlight) { Q_UNUSED(currentFlight); diff --git a/ground/openpilotgcs/src/plugins/flightlog/flightlogmanager.h b/ground/openpilotgcs/src/plugins/flightlog/flightlogmanager.h index 27412fd4b..2b53c3982 100644 --- a/ground/openpilotgcs/src/plugins/flightlog/flightlogmanager.h +++ b/ground/openpilotgcs/src/plugins/flightlog/flightlogmanager.h @@ -71,6 +71,7 @@ class FlightLogManager : public QObject { Q_PROPERTY(QQmlListProperty logEntries READ logEntries NOTIFY logEntriesChanged) Q_PROPERTY(QStringList flightEntries READ flightEntries NOTIFY flightEntriesChanged) Q_PROPERTY(bool disableControls READ disableControls WRITE setDisableControls NOTIFY disableControlsChanged) + Q_PROPERTY(bool disableExport READ disableExport WRITE setDisableExport NOTIFY disableExportChanged) public: explicit FlightLogManager(QObject *parent = 0); @@ -89,18 +90,24 @@ public: return m_disableControls; } + bool disableExport() const + { + return m_disableExport; + } + void clearLogList(); signals: void logEntriesChanged(); void flightEntriesChanged(); void disableControlsChanged(bool arg); - + void disableExportChanged(bool arg); public slots: void clearAllLogs(); void retrieveLogs(int flightToRetrieve = -1); void exportLogs(); + void cancelExportLogs(); void setDisableControls(bool arg) { @@ -110,6 +117,14 @@ public slots: } } + void setDisableExport(bool arg) + { + if (m_disableExport != arg) { + m_disableExport = arg; + emit disableExportChanged(arg); + } + } + private slots: void updateFlightEntries(quint16 currentFlight); @@ -123,6 +138,8 @@ private: static const int UAVTALK_TIMEOUT = 4000; bool m_disableControls; + bool m_disableExport; + bool m_cancelDownload; }; #endif // FLIGHTLOGMANAGER_H