tageditor/renamingutility/renamingengine.h

176 lines
4.0 KiB
C
Raw Normal View History

2015-04-22 19:33:53 +02:00
#ifndef RENAMINGUTILITY_RENAMINGENGINE_H
#define RENAMINGUTILITY_RENAMINGENGINE_H
2015-10-16 22:07:04 +02:00
#include "./filesystemitem.h"
#include "./jsdefs.h"
#include "./jsincludes.h"
2015-10-16 22:07:04 +02:00
2016-03-10 22:13:43 +01:00
#include <QAtomicInteger>
2018-03-07 01:18:01 +01:00
#include <QDir>
#include <QList>
#include <QObject>
#include <QThread>
2015-04-22 19:33:53 +02:00
#include <memory>
2015-10-16 22:07:04 +02:00
QT_FORWARD_DECLARE_CLASS(QFileInfo)
2015-04-22 19:33:53 +02:00
namespace RenamingUtility {
class FileSystemItemModel;
class FilteredFileSystemItemModel;
class TagEditorObject;
class RenamingEngine;
class PreviewGenerator final : public QThread {
Q_OBJECT
public:
explicit PreviewGenerator(RenamingEngine *engine);
protected:
void run() final;
private:
RenamingEngine *m_engine;
};
class RenamingThing final : public QThread {
Q_OBJECT
public:
explicit RenamingThing(RenamingEngine *engine);
protected:
void run() final;
private:
RenamingEngine *m_engine;
};
2015-04-22 19:33:53 +02:00
2018-03-07 01:18:01 +01:00
class RenamingEngine : public QObject {
2015-04-22 19:33:53 +02:00
Q_OBJECT
friend class PreviewGenerator;
friend class RenamingThing;
2015-04-22 19:33:53 +02:00
public:
2017-01-06 21:29:43 +01:00
explicit RenamingEngine(QObject *parent = nullptr);
2015-04-22 19:33:53 +02:00
FileSystemItem *rootItem() const;
#ifndef TAGEDITOR_NO_JSENGINE
const TAGEDITOR_JS_VALUE &scriptProgram() const;
bool setProgram(const TAGEDITOR_JS_VALUE &program);
#endif
bool setProgram(const QString &program);
2015-04-22 19:33:53 +02:00
const QDir &rootDirectory() const;
bool subdirsIncluded() const;
bool isBusy();
bool isAborted();
bool clearPreview();
FileSystemItemModel *model();
FilteredFileSystemItemModel *currentModel();
FilteredFileSystemItemModel *previewModel();
const QString &errorMessage() const;
int errorLineNumber() const;
2015-04-22 19:33:53 +02:00
public slots:
bool generatePreview(const QDir &rootDirectory, bool includeSubdirs);
2015-04-22 19:33:53 +02:00
bool applyChangings();
void abort();
signals:
void previewGenerated();
void changingsApplied();
void progress(int itemsProcessed, int errorsOccured);
private slots:
void processPreviewGenerated();
void processChangingsApplied();
private:
void resetStatus();
void finalizeTaskCompletion();
2015-10-13 20:12:00 +02:00
void setRootItem(std::unique_ptr<FileSystemItem> &&rootItem = std::unique_ptr<FileSystemItem>());
2015-04-22 19:33:53 +02:00
void updateModel(FileSystemItem *rootItem);
#ifndef TAGEDITOR_NO_JSENGINE
2015-10-13 20:12:00 +02:00
std::unique_ptr<FileSystemItem> generatePreview(const QDir &dir, FileSystemItem *parent = nullptr);
#endif
2015-04-22 19:33:53 +02:00
void applyChangings(FileSystemItem *parentItem);
static void setError(const QList<FileSystemItem *> items);
#ifndef TAGEDITOR_NO_JSENGINE
2015-04-22 19:33:53 +02:00
void executeScriptForItem(const QFileInfo &fileInfo, FileSystemItem *item);
#endif
2015-04-22 19:33:53 +02:00
#ifndef TAGEDITOR_NO_JSENGINE
TagEditorObject *m_tagEditorQObj;
TAGEDITOR_JS_ENGINE m_engine;
TAGEDITOR_JS_VALUE m_tagEditorJsObj;
#endif
2015-04-22 19:33:53 +02:00
std::unique_ptr<FileSystemItem> m_rootItem;
std::unique_ptr<FileSystemItem> m_newlyGeneratedRootItem;
int m_itemsProcessed;
int m_errorsOccured;
2016-03-10 22:13:43 +01:00
QAtomicInteger<unsigned char> m_aborted;
#ifndef TAGEDITOR_NO_JSENGINE
TAGEDITOR_JS_VALUE m_program;
#endif
2015-04-22 19:33:53 +02:00
QDir m_dir;
bool m_includeSubdirs;
bool m_isBusy;
2015-04-22 19:33:53 +02:00
FileSystemItemModel *m_model;
FilteredFileSystemItemModel *m_currentModel;
FilteredFileSystemItemModel *m_previewModel;
QString m_errorMessage;
int m_errorLineNumber;
2015-04-22 19:33:53 +02:00
};
2017-01-06 21:29:43 +01:00
inline FileSystemItem *RenamingEngine::rootItem() const
2015-04-22 19:33:53 +02:00
{
return m_rootItem.get();
}
#ifndef TAGEDITOR_NO_JSENGINE
2017-01-06 21:29:43 +01:00
inline const TAGEDITOR_JS_VALUE &RenamingEngine::scriptProgram() const
2015-04-22 19:33:53 +02:00
{
return m_program;
}
#endif
2015-04-22 19:33:53 +02:00
2017-01-06 21:29:43 +01:00
inline const QDir &RenamingEngine::rootDirectory() const
2015-04-22 19:33:53 +02:00
{
return m_dir;
}
2017-01-06 21:29:43 +01:00
inline bool RenamingEngine::subdirsIncluded() const
2015-04-22 19:33:53 +02:00
{
return m_includeSubdirs;
}
2017-01-06 21:29:43 +01:00
inline const QString &RenamingEngine::errorMessage() const
{
return m_errorMessage;
}
2017-01-06 21:29:43 +01:00
inline int RenamingEngine::errorLineNumber() const
{
return m_errorLineNumber;
}
inline bool RenamingEngine::isBusy()
{
return m_isBusy;
}
inline void RenamingEngine::abort()
{
m_aborted.store(1);
}
inline bool RenamingEngine::isAborted()
{
return m_aborted.load();
}
2015-04-22 19:33:53 +02:00
} // namespace RenamingUtility
#endif // RENAMINGUTILITY_RENAMINGENGINE_H