Browse Source

Change to use QGCTemporaryFile

QGC4.4
Don Gagne 11 years ago
parent
commit
505220e0e7
  1. 7
      qgroundcontrol.pro
  2. 1
      src/GAudioOutput.cc
  3. 1
      src/LogCompressor.cc
  4. 6
      src/QGCApplication.cc
  5. 4
      src/comm/MAVLinkProtocol.cc
  6. 8
      src/comm/MAVLinkProtocol.h
  7. 39
      src/qgcunittest/MavlinkLogTest.cc
  8. 2
      src/qgcunittest/MavlinkLogTest.h

7
qgroundcontrol.pro

@ -478,7 +478,8 @@ HEADERS += \ @@ -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 += \ @@ -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

1
src/GAudioOutput.cc

@ -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 <QSettings>
#include <QTemporaryFile>
#include "GAudioOutput.h"
#include "MG.h"

1
src/LogCompressor.cc

@ -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 <QFileInfo>
#include <QDir>
#include <QTemporaryFile>
#include <QTextStream>
#include <QStringList>
#include <QFileInfo>

6
src/QGCApplication.cc

@ -56,6 +56,7 @@ @@ -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) @@ -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;
}

4
src/comm/MAVLinkProtocol.cc

@ -56,15 +56,13 @@ MAVLinkProtocol::MAVLinkProtocol() : @@ -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>("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);

8
src/comm/MAVLinkProtocol.h

@ -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 <QMap>
#include <QByteArray>
#include <QTemporaryFile>
#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: @@ -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

39
src/qgcunittest/MavlinkLogTest.cc

@ -29,6 +29,7 @@ @@ -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) @@ -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) @@ -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) @@ -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);

2
src/qgcunittest/MavlinkLogTest.h

@ -49,6 +49,8 @@ private slots: @@ -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

Loading…
Cancel
Save