diff --git a/qgroundcontrol.pro b/qgroundcontrol.pro index 638f3855ed1e87d0cb7a48c47fc48192c6b74245..7d3cab5ba6ddbb8615f5eee9ce00d940159f6209 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 5edd1e17a189759d760fe0ab3ec6efbb26e05607..a67d4564980987e748bb998a211c1cc01d1ff15c 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 28b73aebd2c05a10606dfe260914905eb6a5c198..faa55eccbbb6f20ce9e8cb9d24bd27b64b40e29b 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 fa8540b203133ea737ec71cd74af584c47fb4e58..469bcee53e95885b8a3fccfdba1a23897acedc8d 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 1c5e39c9fa200d24bf4e75f002342af006c553d0..d6743ff71ba977f73a8adfadf67606389d60b513 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 11b8881ee4fae643c5f0ad2dd2bfed83f85b67ed..070902b7866c544987a47966f25c63d3235a539c 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 d04d4994fecc79d89fafd1f2772827ee405480ee..d23fbc0b9dc7e0ad8f512a4d97e9dc854cf46fd2 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 a9f4e19535457062ae637a9d53313cdf563ad5b6..21cde409faf864484e9c65989861196f73984e27 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