From 505220e0e7cca88dd721b7ddd35093184e01b9ed Mon Sep 17 00:00:00 2001 From: Don Gagne Date: Fri, 5 Dec 2014 11:59:45 -0800 Subject: [PATCH] Change to use QGCTemporaryFile --- qgroundcontrol.pro | 7 ++++-- src/GAudioOutput.cc | 1 - src/LogCompressor.cc | 1 - src/QGCApplication.cc | 6 ++++- src/comm/MAVLinkProtocol.cc | 4 +--- src/comm/MAVLinkProtocol.h | 8 +++---- src/qgcunittest/MavlinkLogTest.cc | 39 ++++++++++++------------------- src/qgcunittest/MavlinkLogTest.h | 2 ++ 8 files changed, 32 insertions(+), 36 deletions(-) diff --git a/qgroundcontrol.pro b/qgroundcontrol.pro index 638f3855e..7d3cab5ba 100644 --- a/qgroundcontrol.pro +++ b/qgroundcontrol.pro @@ -478,7 +478,8 @@ HEADERS += \ src/uas/QGXPX4UAS.h \ src/QGCFileDialog.h \ src/QGCMessageBox.h \ - src/QGCComboBox.h + src/QGCComboBox.h \ + src/QGCTemporaryFile.h SOURCES += \ src/main.cc \ @@ -616,7 +617,9 @@ SOURCES += \ src/CmdLineOptParser.cc \ src/uas/QGXPX4UAS.cc \ src/QGCFileDialog.cc \ - src/QGCComboBox.cc + src/QGCComboBox.cc \ + src/QGCTemporaryFile.cc + # # Unit Test specific configuration goes here diff --git a/src/GAudioOutput.cc b/src/GAudioOutput.cc index 5edd1e17a..a67d45649 100644 --- a/src/GAudioOutput.cc +++ b/src/GAudioOutput.cc @@ -32,7 +32,6 @@ This file is part of the QGROUNDCONTROL project #include #include -#include #include "GAudioOutput.h" #include "MG.h" diff --git a/src/LogCompressor.cc b/src/LogCompressor.cc index 28b73aebd..faa55eccb 100644 --- a/src/LogCompressor.cc +++ b/src/LogCompressor.cc @@ -30,7 +30,6 @@ This file is part of the QGROUNDCONTROL project #include #include #include -#include #include #include #include diff --git a/src/QGCApplication.cc b/src/QGCApplication.cc index fa8540b20..469bcee53 100644 --- a/src/QGCApplication.cc +++ b/src/QGCApplication.cc @@ -56,6 +56,7 @@ #include "LinkManager.h" #include "UASManager.h" #include "AutoPilotPluginManager.h" +#include "QGCTemporaryFile.h" #ifdef QGC_RTLAB_ENABLED #include "OpalLink.h" @@ -309,12 +310,15 @@ void QGCApplication::setSavedFilesLocation(QString& location) bool QGCApplication::validatePossibleSavedFilesLocation(QString& location) { // Make sure we can write to the directory + QString filename = QDir(location).filePath("QGCTempXXXXXXXX.tmp"); - QTemporaryFile tempFile(filename); + QGCTemporaryFile tempFile(filename); if (!tempFile.open()) { return false; } + tempFile.remove(); + return true; } diff --git a/src/comm/MAVLinkProtocol.cc b/src/comm/MAVLinkProtocol.cc index 1c5e39c9f..d6743ff71 100644 --- a/src/comm/MAVLinkProtocol.cc +++ b/src/comm/MAVLinkProtocol.cc @@ -56,15 +56,13 @@ MAVLinkProtocol::MAVLinkProtocol() : _should_exit(false), _logSuspendError(false), _logSuspendReplay(false), + _tempLogFile(QString("%2.%3").arg(_tempLogFileTemplate).arg(_logFileExtension)), _protocolStatusMessageConnected(false), _saveTempFlightDataLogConnected(false) { qRegisterMetaType("mavlink_message_t"); - _tempLogFile.setFileTemplate(QString("%1/%2.%3").arg(QStandardPaths::writableLocation(QStandardPaths::TempLocation)).arg(_tempLogFileTemplate).arg(_logFileExtension)); - _tempLogFile.setAutoRemove(false); - m_authKey = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"; loadSettings(); moveToThread(this); diff --git a/src/comm/MAVLinkProtocol.h b/src/comm/MAVLinkProtocol.h index 11b8881ee..070902b78 100644 --- a/src/comm/MAVLinkProtocol.h +++ b/src/comm/MAVLinkProtocol.h @@ -37,12 +37,12 @@ This file is part of the QGROUNDCONTROL project #include #include #include -#include #include "ProtocolInterface.h" #include "LinkInterface.h" #include "QGCMAVLink.h" #include "QGC.h" +#include "QGCTemporaryFile.h" /** * @brief MAVLink micro air vehicle protocol reference implementation. @@ -282,9 +282,9 @@ private: bool _logSuspendError; ///< true: Logging suspended due to error bool _logSuspendReplay; ///< true: Logging suspended due to replay - QTemporaryFile _tempLogFile; ///< File to log to - static const char* _tempLogFileTemplate; ///< Template for temporary log file - static const char* _logFileExtension; ///< Extension for log files + QGCTemporaryFile _tempLogFile; ///< File to log to + static const char* _tempLogFileTemplate; ///< Template for temporary log file + static const char* _logFileExtension; ///< Extension for log files bool _protocolStatusMessageConnected; ///< true: protocolStatusMessage signal has been connected bool _saveTempFlightDataLogConnected; ///< true: saveTempFlightDataLog signal has been connected diff --git a/src/qgcunittest/MavlinkLogTest.cc b/src/qgcunittest/MavlinkLogTest.cc index d04d4994f..d23fbc0b9 100644 --- a/src/qgcunittest/MavlinkLogTest.cc +++ b/src/qgcunittest/MavlinkLogTest.cc @@ -29,6 +29,7 @@ #include "MavlinkLogTest.h" #include "MainWindow.h" #include "MockLink.h" +#include "QGCTemporaryFile.h" UT_REGISTER_TEST(MavlinkLogTest) @@ -66,17 +67,21 @@ void MavlinkLogTest::cleanup(void) QCOMPARE(logFiles.count(), 0); } -void MavlinkLogTest::_bootLogDetectionCancel_test(void) +void MavlinkLogTest::_createTempLogFile(bool zeroLength) { - // Create a fake mavlink log - - QTemporaryFile tempLogFile; - tempLogFile.setFileTemplate(QString("%1/%2.%3").arg(QStandardPaths::writableLocation(QStandardPaths::TempLocation)).arg(_tempLogFileTemplate).arg(_logFileExtension)); - tempLogFile.setAutoRemove(false); + QGCTemporaryFile tempLogFile(QString("%1.%2").arg(_tempLogFileTemplate).arg(_logFileExtension)); tempLogFile.open(); - tempLogFile.write("foo"); + if (!zeroLength) { + tempLogFile.write("foo"); + } tempLogFile.close(); +} + +void MavlinkLogTest::_bootLogDetectionCancel_test(void) +{ + // Create a fake mavlink log + _createTempLogFile(false); // We should get a message box, followed by a getSaveFileName dialog. setExpectedMessageBox(QMessageBox::Ok); @@ -96,14 +101,7 @@ void MavlinkLogTest::_bootLogDetectionCancel_test(void) void MavlinkLogTest::_bootLogDetectionSave_test(void) { // Create a fake mavlink log - - QTemporaryFile tempLogFile; - tempLogFile.setFileTemplate(QString("%1/%2.%3").arg(QStandardPaths::writableLocation(QStandardPaths::TempLocation)).arg(_tempLogFileTemplate).arg(_logFileExtension)); - tempLogFile.setAutoRemove(false); - - tempLogFile.open(); - tempLogFile.write("foo"); - tempLogFile.close(); + _createTempLogFile(false); // We should get a message box, followed by a getSaveFileName dialog. setExpectedMessageBox(QMessageBox::Ok); @@ -127,15 +125,8 @@ void MavlinkLogTest::_bootLogDetectionSave_test(void) void MavlinkLogTest::_bootLogDetectionZeroLength_test(void) { - // Create a fake mavlink log - - QTemporaryFile tempLogFile; - tempLogFile.setFileTemplate(QString("%1/%2.%3").arg(QStandardPaths::writableLocation(QStandardPaths::TempLocation)).arg(_tempLogFileTemplate).arg(_logFileExtension)); - tempLogFile.setAutoRemove(false); - - // Zero length file - tempLogFile.open(); - tempLogFile.close(); + // Create a fake eempty mavlink log + _createTempLogFile(true); // Zero length log files should not generate any additional UI pop-ups. It should just be deleted silently. MainWindow* mainWindow = MainWindow::_create(NULL, MainWindow::CUSTOM_MODE_PX4); diff --git a/src/qgcunittest/MavlinkLogTest.h b/src/qgcunittest/MavlinkLogTest.h index a9f4e1953..21cde409f 100644 --- a/src/qgcunittest/MavlinkLogTest.h +++ b/src/qgcunittest/MavlinkLogTest.h @@ -49,6 +49,8 @@ private slots: void _connectLogWindowClose_test(void); private: + void _createTempLogFile(bool zeroLength); + static const char* _tempLogFileTemplate; ///< Template for temporary log file static const char* _logFileExtension; ///< Extension for log files static const char* _saveLogFilename; ///< Filename to save log files to -- 2.22.0