mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-03 15:45:46 +08:00
refs #144 Util class, deleting temp files when application shuts down. First used with soundgenerator's temp. wav-files
This commit is contained in:
14
src/blackmisc/filedeleter.cpp
Normal file
14
src/blackmisc/filedeleter.cpp
Normal file
@@ -0,0 +1,14 @@
|
||||
#include <QFile>
|
||||
#include "filedeleter.h"
|
||||
|
||||
namespace BlackMisc
|
||||
{
|
||||
CFileDeleter::~CFileDeleter()
|
||||
{
|
||||
foreach(const QString fn, this->m_fileNames)
|
||||
{
|
||||
QFile f(fn);
|
||||
f.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
38
src/blackmisc/filedeleter.h
Normal file
38
src/blackmisc/filedeleter.h
Normal file
@@ -0,0 +1,38 @@
|
||||
#ifndef BLACKMISC_CFILEDELETER_H
|
||||
#define BLACKMISC_CFILEDELETER_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QDebug>
|
||||
|
||||
namespace BlackMisc
|
||||
{
|
||||
|
||||
/*!
|
||||
* \brief Utility class, deleting files when it is destroyed
|
||||
*/
|
||||
class CFileDeleter : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
private:
|
||||
QStringList m_fileNames;
|
||||
|
||||
public:
|
||||
/*!
|
||||
* \brief File deleter
|
||||
* \param parent
|
||||
*/
|
||||
explicit CFileDeleter(QObject *parent = nullptr) : QObject(parent) {}
|
||||
|
||||
//! \brief add given file for deletion
|
||||
void addFileForDeletion(const QString &file)
|
||||
{
|
||||
if (!this->m_fileNames.contains(file)) this->m_fileNames.append(file);
|
||||
}
|
||||
|
||||
//! \brief Destructor
|
||||
~CFileDeleter();
|
||||
};
|
||||
}
|
||||
|
||||
#endif // guard
|
||||
Reference in New Issue
Block a user