Commit 505220e0 authored by Don Gagne's avatar Don Gagne

Change to use QGCTemporaryFile

parent 7127f648
...@@ -478,7 +478,8 @@ HEADERS += \ ...@@ -478,7 +478,8 @@ HEADERS += \
src/uas/QGXPX4UAS.h \ src/uas/QGXPX4UAS.h \
src/QGCFileDialog.h \ src/QGCFileDialog.h \
src/QGCMessageBox.h \ src/QGCMessageBox.h \
src/QGCComboBox.h src/QGCComboBox.h \
src/QGCTemporaryFile.h
SOURCES += \ SOURCES += \
src/main.cc \ src/main.cc \
...@@ -616,7 +617,9 @@ SOURCES += \ ...@@ -616,7 +617,9 @@ SOURCES += \
src/CmdLineOptParser.cc \ src/CmdLineOptParser.cc \
src/uas/QGXPX4UAS.cc \ src/uas/QGXPX4UAS.cc \
src/QGCFileDialog.cc \ src/QGCFileDialog.cc \
src/QGCComboBox.cc src/QGCComboBox.cc \
src/QGCTemporaryFile.cc
# #
# Unit Test specific configuration goes here # Unit Test specific configuration goes here
......
...@@ -32,7 +32,6 @@ This file is part of the QGROUNDCONTROL project ...@@ -32,7 +32,6 @@ This file is part of the QGROUNDCONTROL project
#include <QApplication> #include <QApplication>
#include <QSettings> #include <QSettings>
#include <QTemporaryFile>
#include "GAudioOutput.h" #include "GAudioOutput.h"
#include "MG.h" #include "MG.h"
......
...@@ -30,7 +30,6 @@ This file is part of the QGROUNDCONTROL project ...@@ -30,7 +30,6 @@ This file is part of the QGROUNDCONTROL project
#include <QFile> #include <QFile>
#include <QFileInfo> #include <QFileInfo>
#include <QDir> #include <QDir>
#include <QTemporaryFile>
#include <QTextStream> #include <QTextStream>
#include <QStringList> #include <QStringList>
#include <QFileInfo> #include <QFileInfo>
......
...@@ -56,6 +56,7 @@ ...@@ -56,6 +56,7 @@
#include "LinkManager.h" #include "LinkManager.h"
#include "UASManager.h" #include "UASManager.h"
#include "AutoPilotPluginManager.h" #include "AutoPilotPluginManager.h"
#include "QGCTemporaryFile.h"
#ifdef QGC_RTLAB_ENABLED #ifdef QGC_RTLAB_ENABLED
#include "OpalLink.h" #include "OpalLink.h"
...@@ -309,12 +310,15 @@ void QGCApplication::setSavedFilesLocation(QString& location) ...@@ -309,12 +310,15 @@ void QGCApplication::setSavedFilesLocation(QString& location)
bool QGCApplication::validatePossibleSavedFilesLocation(QString& location) bool QGCApplication::validatePossibleSavedFilesLocation(QString& location)
{ {
// Make sure we can write to the directory // Make sure we can write to the directory
QString filename = QDir(location).filePath("QGCTempXXXXXXXX.tmp"); QString filename = QDir(location).filePath("QGCTempXXXXXXXX.tmp");
QTemporaryFile tempFile(filename); QGCTemporaryFile tempFile(filename);
if (!tempFile.open()) { if (!tempFile.open()) {
return false; return false;
} }
tempFile.remove();
return true; return true;
} }
......
...@@ -56,15 +56,13 @@ MAVLinkProtocol::MAVLinkProtocol() : ...@@ -56,15 +56,13 @@ MAVLinkProtocol::MAVLinkProtocol() :
_should_exit(false), _should_exit(false),
_logSuspendError(false), _logSuspendError(false),
_logSuspendReplay(false), _logSuspendReplay(false),
_tempLogFile(QString("%2.%3").arg(_tempLogFileTemplate).arg(_logFileExtension)),
_protocolStatusMessageConnected(false), _protocolStatusMessageConnected(false),
_saveTempFlightDataLogConnected(false) _saveTempFlightDataLogConnected(false)
{ {
qRegisterMetaType<mavlink_message_t>("mavlink_message_t"); qRegisterMetaType<mavlink_message_t>("mavlink_message_t");
_tempLogFile.setFileTemplate(QString("%1/%2.%3").arg(QStandardPaths::writableLocation(QStandardPaths::TempLocation)).arg(_tempLogFileTemplate).arg(_logFileExtension));
_tempLogFile.setAutoRemove(false);
m_authKey = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"; m_authKey = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
loadSettings(); loadSettings();
moveToThread(this); moveToThread(this);
......
...@@ -37,12 +37,12 @@ This file is part of the QGROUNDCONTROL project ...@@ -37,12 +37,12 @@ This file is part of the QGROUNDCONTROL project
#include <QFile> #include <QFile>
#include <QMap> #include <QMap>
#include <QByteArray> #include <QByteArray>
#include <QTemporaryFile>
#include "ProtocolInterface.h" #include "ProtocolInterface.h"
#include "LinkInterface.h" #include "LinkInterface.h"
#include "QGCMAVLink.h" #include "QGCMAVLink.h"
#include "QGC.h" #include "QGC.h"
#include "QGCTemporaryFile.h"
/** /**
* @brief MAVLink micro air vehicle protocol reference implementation. * @brief MAVLink micro air vehicle protocol reference implementation.
...@@ -282,9 +282,9 @@ private: ...@@ -282,9 +282,9 @@ private:
bool _logSuspendError; ///< true: Logging suspended due to error bool _logSuspendError; ///< true: Logging suspended due to error
bool _logSuspendReplay; ///< true: Logging suspended due to replay bool _logSuspendReplay; ///< true: Logging suspended due to replay
QTemporaryFile _tempLogFile; ///< File to log to QGCTemporaryFile _tempLogFile; ///< File to log to
static const char* _tempLogFileTemplate; ///< Template for temporary log file static const char* _tempLogFileTemplate; ///< Template for temporary log file
static const char* _logFileExtension; ///< Extension for log files static const char* _logFileExtension; ///< Extension for log files
bool _protocolStatusMessageConnected; ///< true: protocolStatusMessage signal has been connected bool _protocolStatusMessageConnected; ///< true: protocolStatusMessage signal has been connected
bool _saveTempFlightDataLogConnected; ///< true: saveTempFlightDataLog signal has been connected bool _saveTempFlightDataLogConnected; ///< true: saveTempFlightDataLog signal has been connected
......
...@@ -29,6 +29,7 @@ ...@@ -29,6 +29,7 @@
#include "MavlinkLogTest.h" #include "MavlinkLogTest.h"
#include "MainWindow.h" #include "MainWindow.h"
#include "MockLink.h" #include "MockLink.h"
#include "QGCTemporaryFile.h"
UT_REGISTER_TEST(MavlinkLogTest) UT_REGISTER_TEST(MavlinkLogTest)
...@@ -66,17 +67,21 @@ void MavlinkLogTest::cleanup(void) ...@@ -66,17 +67,21 @@ void MavlinkLogTest::cleanup(void)
QCOMPARE(logFiles.count(), 0); QCOMPARE(logFiles.count(), 0);
} }
void MavlinkLogTest::_bootLogDetectionCancel_test(void) void MavlinkLogTest::_createTempLogFile(bool zeroLength)
{ {
// Create a fake mavlink log QGCTemporaryFile tempLogFile(QString("%1.%2").arg(_tempLogFileTemplate).arg(_logFileExtension));
QTemporaryFile tempLogFile;
tempLogFile.setFileTemplate(QString("%1/%2.%3").arg(QStandardPaths::writableLocation(QStandardPaths::TempLocation)).arg(_tempLogFileTemplate).arg(_logFileExtension));
tempLogFile.setAutoRemove(false);
tempLogFile.open(); tempLogFile.open();
tempLogFile.write("foo"); if (!zeroLength) {
tempLogFile.write("foo");
}
tempLogFile.close(); 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. // We should get a message box, followed by a getSaveFileName dialog.
setExpectedMessageBox(QMessageBox::Ok); setExpectedMessageBox(QMessageBox::Ok);
...@@ -96,14 +101,7 @@ void MavlinkLogTest::_bootLogDetectionCancel_test(void) ...@@ -96,14 +101,7 @@ void MavlinkLogTest::_bootLogDetectionCancel_test(void)
void MavlinkLogTest::_bootLogDetectionSave_test(void) void MavlinkLogTest::_bootLogDetectionSave_test(void)
{ {
// Create a fake mavlink log // Create a fake mavlink log
_createTempLogFile(false);
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();
// We should get a message box, followed by a getSaveFileName dialog. // We should get a message box, followed by a getSaveFileName dialog.
setExpectedMessageBox(QMessageBox::Ok); setExpectedMessageBox(QMessageBox::Ok);
...@@ -127,15 +125,8 @@ void MavlinkLogTest::_bootLogDetectionSave_test(void) ...@@ -127,15 +125,8 @@ void MavlinkLogTest::_bootLogDetectionSave_test(void)
void MavlinkLogTest::_bootLogDetectionZeroLength_test(void) void MavlinkLogTest::_bootLogDetectionZeroLength_test(void)
{ {
// Create a fake mavlink log // Create a fake eempty mavlink log
_createTempLogFile(true);
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();
// Zero length log files should not generate any additional UI pop-ups. It should just be deleted silently. // 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); MainWindow* mainWindow = MainWindow::_create(NULL, MainWindow::CUSTOM_MODE_PX4);
......
...@@ -49,6 +49,8 @@ private slots: ...@@ -49,6 +49,8 @@ private slots:
void _connectLogWindowClose_test(void); void _connectLogWindowClose_test(void);
private: private:
void _createTempLogFile(bool zeroLength);
static const char* _tempLogFileTemplate; ///< Template for temporary log file static const char* _tempLogFileTemplate; ///< Template for temporary log file
static const char* _logFileExtension; ///< Extension for log files static const char* _logFileExtension; ///< Extension for log files
static const char* _saveLogFilename; ///< Filename to save log files to static const char* _saveLogFilename; ///< Filename to save log files to
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment