mirror of
https://github.com/f4exb/sdrangel.git
synced 2025-05-29 21:42:26 -04:00
FileSink: Generate qWarning and error dialog in GUI when failing to open a file or write to a file.
This commit is contained in:
parent
9147eb6046
commit
f0e37131ed
@ -18,6 +18,7 @@
|
|||||||
#include <QLocale>
|
#include <QLocale>
|
||||||
#include <QFileDialog>
|
#include <QFileDialog>
|
||||||
#include <QTime>
|
#include <QTime>
|
||||||
|
#include <QMessageBox>
|
||||||
|
|
||||||
#include "device/deviceuiset.h"
|
#include "device/deviceuiset.h"
|
||||||
#include "device/deviceapi.h"
|
#include "device/deviceapi.h"
|
||||||
@ -141,6 +142,12 @@ bool FileSinkGUI::handleMessage(const Message& message)
|
|||||||
ui->fileNameText->setText(report.getFileName());
|
ui->fileNameText->setText(report.getFileName());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
else if (FileSinkMessages::MsgReportRecordFileError::match(message))
|
||||||
|
{
|
||||||
|
const FileSinkMessages::MsgReportRecordFileError& report = (FileSinkMessages::MsgReportRecordFileError&) message;
|
||||||
|
QMessageBox::critical(this, tr("File Error"), report.getMessage());
|
||||||
|
return true;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
|
@ -21,3 +21,4 @@ MESSAGE_CLASS_DEFINITION(FileSinkMessages::MsgConfigureSpectrum, Message)
|
|||||||
MESSAGE_CLASS_DEFINITION(FileSinkMessages::MsgReportSquelch, Message)
|
MESSAGE_CLASS_DEFINITION(FileSinkMessages::MsgReportSquelch, Message)
|
||||||
MESSAGE_CLASS_DEFINITION(FileSinkMessages::MsgReportRecording, Message)
|
MESSAGE_CLASS_DEFINITION(FileSinkMessages::MsgReportRecording, Message)
|
||||||
MESSAGE_CLASS_DEFINITION(FileSinkMessages::MsgReportRecordFileName, Message)
|
MESSAGE_CLASS_DEFINITION(FileSinkMessages::MsgReportRecordFileName, Message)
|
||||||
|
MESSAGE_CLASS_DEFINITION(FileSinkMessages::MsgReportRecordFileError, Message)
|
||||||
|
@ -103,6 +103,25 @@ public:
|
|||||||
m_fileName(fileName)
|
m_fileName(fileName)
|
||||||
{ }
|
{ }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class MsgReportRecordFileError : public Message {
|
||||||
|
MESSAGE_CLASS_DECLARATION
|
||||||
|
|
||||||
|
public:
|
||||||
|
const QString& getMessage() const { return m_message; }
|
||||||
|
|
||||||
|
static MsgReportRecordFileError* create(const QString& message) {
|
||||||
|
return new MsgReportRecordFileError(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
QString m_message;
|
||||||
|
|
||||||
|
MsgReportRecordFileError(const QString& message) :
|
||||||
|
Message(),
|
||||||
|
m_message(message)
|
||||||
|
{ }
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // INCLUDE_FILESINKMESSAGES_H_
|
#endif // INCLUDE_FILESINKMESSAGES_H_
|
||||||
|
@ -49,7 +49,17 @@ void FileSinkSink::startRecording()
|
|||||||
m_fileSink.setMsShift(-mSShift);
|
m_fileSink.setMsShift(-mSShift);
|
||||||
|
|
||||||
// notify capture start
|
// notify capture start
|
||||||
m_fileSink.startRecording();
|
if (!m_fileSink.startRecording())
|
||||||
|
{
|
||||||
|
// qWarning already output in startRecording, just need to send to GUI
|
||||||
|
if (m_msgQueueToGUI)
|
||||||
|
{
|
||||||
|
FileSinkMessages::MsgReportRecordFileError *msg
|
||||||
|
= FileSinkMessages::MsgReportRecordFileError::create(QString("Failed to open %1").arg(m_fileSink.getCurrentFileName()));
|
||||||
|
m_msgQueueToGUI->push(msg);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
m_record = true;
|
m_record = true;
|
||||||
m_nbCaptures++;
|
m_nbCaptures++;
|
||||||
|
|
||||||
@ -84,7 +94,16 @@ void FileSinkSink::stopRecording()
|
|||||||
if (m_record)
|
if (m_record)
|
||||||
{
|
{
|
||||||
m_preRecordBuffer.reset();
|
m_preRecordBuffer.reset();
|
||||||
m_fileSink.stopRecording();
|
if (!m_fileSink.stopRecording())
|
||||||
|
{
|
||||||
|
// qWarning already output stopRecording, just need to send to GUI
|
||||||
|
if (m_msgQueueToGUI)
|
||||||
|
{
|
||||||
|
FileSinkMessages::MsgReportRecordFileError *msg
|
||||||
|
= FileSinkMessages::MsgReportRecordFileError::create(QString("Error while writing to %1").arg(m_fileSink.getCurrentFileName()));
|
||||||
|
m_msgQueueToGUI->push(msg);
|
||||||
|
}
|
||||||
|
}
|
||||||
m_record = false;
|
m_record = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -103,7 +103,7 @@ void FileRecord::stop()
|
|||||||
stopRecording();
|
stopRecording();
|
||||||
}
|
}
|
||||||
|
|
||||||
void FileRecord::startRecording()
|
bool FileRecord::startRecording()
|
||||||
{
|
{
|
||||||
if (m_recordOn) {
|
if (m_recordOn) {
|
||||||
stopRecording();
|
stopRecording();
|
||||||
@ -114,13 +114,19 @@ void FileRecord::startRecording()
|
|||||||
qDebug() << "FileRecord::startRecording";
|
qDebug() << "FileRecord::startRecording";
|
||||||
m_curentFileName = QString("%1.%2.sdriq").arg(m_fileBase).arg(QDateTime::currentDateTimeUtc().toString("yyyy-MM-ddTHH_mm_ss_zzz"));
|
m_curentFileName = QString("%1.%2.sdriq").arg(m_fileBase).arg(QDateTime::currentDateTimeUtc().toString("yyyy-MM-ddTHH_mm_ss_zzz"));
|
||||||
m_sampleFile.open(m_curentFileName.toStdString().c_str(), std::ios::binary);
|
m_sampleFile.open(m_curentFileName.toStdString().c_str(), std::ios::binary);
|
||||||
|
if (!m_sampleFile.is_open())
|
||||||
|
{
|
||||||
|
qWarning() << "FileRecord::startRecording: failed to open file: " << m_curentFileName;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
m_recordOn = true;
|
m_recordOn = true;
|
||||||
m_recordStart = true;
|
m_recordStart = true;
|
||||||
m_byteCount = 0;
|
m_byteCount = 0;
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void FileRecord::stopRecording()
|
bool FileRecord::stopRecording()
|
||||||
{
|
{
|
||||||
if (m_sampleFile.is_open())
|
if (m_sampleFile.is_open())
|
||||||
{
|
{
|
||||||
@ -128,7 +134,13 @@ void FileRecord::stopRecording()
|
|||||||
m_sampleFile.close();
|
m_sampleFile.close();
|
||||||
m_recordOn = false;
|
m_recordOn = false;
|
||||||
m_recordStart = false;
|
m_recordStart = false;
|
||||||
|
if (m_sampleFile.bad())
|
||||||
|
{
|
||||||
|
qWarning() << "FileRecord::stopRecording: an error occured while writing to " << m_curentFileName;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool FileRecord::handleMessage(const Message& message)
|
bool FileRecord::handleMessage(const Message& message)
|
||||||
|
@ -60,8 +60,8 @@ public:
|
|||||||
virtual bool handleMessage(const Message& message);
|
virtual bool handleMessage(const Message& message);
|
||||||
|
|
||||||
virtual void setFileName(const QString& fileBase);
|
virtual void setFileName(const QString& fileBase);
|
||||||
virtual void startRecording();
|
virtual bool startRecording();
|
||||||
virtual void stopRecording();
|
virtual bool stopRecording();
|
||||||
virtual bool isRecording() const { return m_recordOn; }
|
virtual bool isRecording() const { return m_recordOn; }
|
||||||
|
|
||||||
static bool readHeader(std::ifstream& samplefile, Header& header); //!< returns true if CRC checksum is correct else false
|
static bool readHeader(std::ifstream& samplefile, Header& header); //!< returns true if CRC checksum is correct else false
|
||||||
|
@ -51,8 +51,8 @@ public:
|
|||||||
MessageQueue *getMessageQueueToGUI() { return m_guiMessageQueue; }
|
MessageQueue *getMessageQueueToGUI() { return m_guiMessageQueue; }
|
||||||
|
|
||||||
virtual void setFileName(const QString &filename) = 0;
|
virtual void setFileName(const QString &filename) = 0;
|
||||||
virtual void startRecording() = 0;
|
virtual bool startRecording() = 0;
|
||||||
virtual void stopRecording() = 0;
|
virtual bool stopRecording() = 0;
|
||||||
virtual bool isRecording() const = 0;
|
virtual bool isRecording() const = 0;
|
||||||
|
|
||||||
static QString genUniqueFileName(unsigned int deviceUID, int istream = -1);
|
static QString genUniqueFileName(unsigned int deviceUID, int istream = -1);
|
||||||
|
@ -107,8 +107,9 @@ unsigned int SigMFFileRecord::getNbCaptures() const
|
|||||||
return m_metaRecord->captures.size();
|
return m_metaRecord->captures.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
void SigMFFileRecord::startRecording()
|
bool SigMFFileRecord::startRecording()
|
||||||
{
|
{
|
||||||
|
bool success = true;
|
||||||
|
|
||||||
if (m_recordStart)
|
if (m_recordStart)
|
||||||
{
|
{
|
||||||
@ -118,7 +119,17 @@ void SigMFFileRecord::startRecording()
|
|||||||
m_sampleFileName = m_fileName + ".sigmf-data";
|
m_sampleFileName = m_fileName + ".sigmf-data";
|
||||||
m_metaFileName = m_fileName + ".sigmf-meta";
|
m_metaFileName = m_fileName + ".sigmf-meta";
|
||||||
m_sampleFile.open(m_sampleFileName.toStdString().c_str(), std::ios::binary);
|
m_sampleFile.open(m_sampleFileName.toStdString().c_str(), std::ios::binary);
|
||||||
|
if (!m_sampleFile.is_open())
|
||||||
|
{
|
||||||
|
qWarning() << "SigMFFileRecord::startRecording: failed to open file: " << m_sampleFileName;
|
||||||
|
success = false;
|
||||||
|
}
|
||||||
m_metaFile.open(m_metaFileName.toStdString().c_str(), std::ofstream::out);
|
m_metaFile.open(m_metaFileName.toStdString().c_str(), std::ofstream::out);
|
||||||
|
if (!m_metaFile.is_open())
|
||||||
|
{
|
||||||
|
qWarning() << "SigMFFileRecord::startRecording: failed to open file: " << m_metaFile;
|
||||||
|
success = false;
|
||||||
|
}
|
||||||
makeHeader();
|
makeHeader();
|
||||||
m_recordStart = false;
|
m_recordStart = false;
|
||||||
}
|
}
|
||||||
@ -130,16 +141,28 @@ void SigMFFileRecord::startRecording()
|
|||||||
m_captureStartDT = QDateTime::currentDateTimeUtc().addMSecs(m_msShift);
|
m_captureStartDT = QDateTime::currentDateTimeUtc().addMSecs(m_msShift);
|
||||||
m_recordOn = true;
|
m_recordOn = true;
|
||||||
m_sampleCount = 0;
|
m_sampleCount = 0;
|
||||||
|
return success;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SigMFFileRecord::stopRecording()
|
bool SigMFFileRecord::stopRecording()
|
||||||
{
|
{
|
||||||
if (m_recordOn)
|
if (m_recordOn)
|
||||||
{
|
{
|
||||||
qDebug("SigMFFileRecord::stopRecording: file previous capture");
|
qDebug("SigMFFileRecord::stopRecording: file previous capture");
|
||||||
makeCapture();
|
makeCapture();
|
||||||
m_recordOn = false;
|
m_recordOn = false;
|
||||||
|
if (m_sampleFile.bad())
|
||||||
|
{
|
||||||
|
qWarning() << "SigMFFileRecord::stopRecording: an error occured while writing to " << m_sampleFileName;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (m_metaFile.bad())
|
||||||
|
{
|
||||||
|
qWarning() << "SigMFFileRecord::stopRecording: an error occured while writing to " << m_metaFileName;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SigMFFileRecord::makeHeader()
|
void SigMFFileRecord::makeHeader()
|
||||||
|
@ -45,8 +45,8 @@ public:
|
|||||||
virtual bool handleMessage(const Message& message);
|
virtual bool handleMessage(const Message& message);
|
||||||
|
|
||||||
virtual void setFileName(const QString& filename);
|
virtual void setFileName(const QString& filename);
|
||||||
virtual void startRecording();
|
virtual bool startRecording();
|
||||||
virtual void stopRecording();
|
virtual bool stopRecording();
|
||||||
virtual bool isRecording() const { return m_recordOn; }
|
virtual bool isRecording() const { return m_recordOn; }
|
||||||
|
|
||||||
void setHardwareId(const QString& hardwareId) { m_hardwareId = hardwareId; }
|
void setHardwareId(const QString& hardwareId) { m_hardwareId = hardwareId; }
|
||||||
|
Loading…
x
Reference in New Issue
Block a user