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"
|
2016-01-09 02:56:56 +01:00
|
|
|
#include "./scriptdefs.h"
|
2015-10-16 22:07:04 +02:00
|
|
|
|
2015-04-22 19:33:53 +02:00
|
|
|
#include <QObject>
|
|
|
|
#include <QList>
|
|
|
|
#include <QDir>
|
2016-03-10 22:13:43 +01:00
|
|
|
#include <QMutex>
|
|
|
|
#include <QAtomicInteger>
|
2016-04-21 23:55:22 +02:00
|
|
|
#if defined(TAGEDITOR_USE_JSENGINE)
|
2016-01-09 02:56:56 +01:00
|
|
|
# include <QJSEngine>
|
|
|
|
# include <QJSValue>
|
2016-04-21 23:55:22 +02:00
|
|
|
#elif defined(TAGEDITOR_USE_SCRIPT)
|
2016-01-09 02:56:56 +01:00
|
|
|
# include <QScriptEngine>
|
|
|
|
# include <QScriptValue>
|
|
|
|
#endif
|
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;
|
2016-01-09 02:56:56 +01:00
|
|
|
class TagEditorObject;
|
2015-04-22 19:33:53 +02:00
|
|
|
|
|
|
|
class RemamingEngine : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
|
|
|
RemamingEngine(QObject *parent = nullptr);
|
|
|
|
|
|
|
|
FileSystemItem *rootItem() const;
|
2016-04-21 23:55:22 +02:00
|
|
|
#ifndef TAGEDITOR_NO_JSENGINE
|
2016-01-09 02:56:56 +01:00
|
|
|
const TAGEDITOR_JS_VALUE &scriptProgram() const;
|
|
|
|
bool setProgram(const TAGEDITOR_JS_VALUE &program);
|
2016-04-21 23:55:22 +02:00
|
|
|
#endif
|
2016-01-09 02:56:56 +01:00
|
|
|
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();
|
2016-01-09 02:56:56 +01:00
|
|
|
const QString &errorMessage() const;
|
|
|
|
int errorLineNumber() const;
|
2015-04-22 19:33:53 +02:00
|
|
|
|
|
|
|
public slots:
|
2016-01-09 02:56:56 +01:00
|
|
|
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:
|
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);
|
2016-04-21 23:55:22 +02:00
|
|
|
#ifndef TAGEDITOR_NO_JSENGINE
|
2015-10-13 20:12:00 +02:00
|
|
|
std::unique_ptr<FileSystemItem> generatePreview(const QDir &dir, FileSystemItem *parent = nullptr);
|
2016-04-21 23:55:22 +02:00
|
|
|
#endif
|
2015-04-22 19:33:53 +02:00
|
|
|
void applyChangings(FileSystemItem *parentItem);
|
|
|
|
static void setError(const QList<FileSystemItem *> items);
|
2016-04-21 23:55:22 +02:00
|
|
|
#ifndef TAGEDITOR_NO_JSENGINE
|
2015-04-22 19:33:53 +02:00
|
|
|
void executeScriptForItem(const QFileInfo &fileInfo, FileSystemItem *item);
|
2016-04-21 23:55:22 +02:00
|
|
|
#endif
|
2015-04-22 19:33:53 +02:00
|
|
|
|
2016-04-21 23:55:22 +02:00
|
|
|
#ifndef TAGEDITOR_NO_JSENGINE
|
2016-01-09 02:56:56 +01:00
|
|
|
TagEditorObject *m_tagEditorQObj;
|
|
|
|
TAGEDITOR_JS_ENGINE m_engine;
|
|
|
|
TAGEDITOR_JS_VALUE m_tagEditorJsObj;
|
2016-04-21 23:55:22 +02:00
|
|
|
#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;
|
2016-04-21 23:55:22 +02:00
|
|
|
#ifndef TAGEDITOR_NO_JSENGINE
|
2016-01-09 02:56:56 +01:00
|
|
|
TAGEDITOR_JS_VALUE m_program;
|
2016-04-21 23:55:22 +02:00
|
|
|
#endif
|
2015-04-22 19:33:53 +02:00
|
|
|
QDir m_dir;
|
|
|
|
bool m_includeSubdirs;
|
2016-03-10 22:13:43 +01:00
|
|
|
QMutex m_mutex;
|
2015-04-22 19:33:53 +02:00
|
|
|
FileSystemItemModel *m_model;
|
|
|
|
FilteredFileSystemItemModel *m_currentModel;
|
|
|
|
FilteredFileSystemItemModel *m_previewModel;
|
2016-01-09 02:56:56 +01:00
|
|
|
QString m_errorMessage;
|
|
|
|
int m_errorLineNumber;
|
2015-04-22 19:33:53 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
inline FileSystemItem *RemamingEngine::rootItem() const
|
|
|
|
{
|
|
|
|
return m_rootItem.get();
|
|
|
|
}
|
|
|
|
|
2016-04-21 23:55:22 +02:00
|
|
|
#ifndef TAGEDITOR_NO_JSENGINE
|
2016-01-09 02:56:56 +01:00
|
|
|
inline const TAGEDITOR_JS_VALUE &RemamingEngine::scriptProgram() const
|
2015-04-22 19:33:53 +02:00
|
|
|
{
|
|
|
|
return m_program;
|
|
|
|
}
|
2016-04-21 23:55:22 +02:00
|
|
|
#endif
|
2015-04-22 19:33:53 +02:00
|
|
|
|
|
|
|
inline const QDir &RemamingEngine::rootDirectory() const
|
|
|
|
{
|
|
|
|
return m_dir;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool RemamingEngine::subdirsIncluded() const
|
|
|
|
{
|
|
|
|
return m_includeSubdirs;
|
|
|
|
}
|
|
|
|
|
2016-01-09 02:56:56 +01:00
|
|
|
inline const QString &RemamingEngine::errorMessage() const
|
|
|
|
{
|
|
|
|
return m_errorMessage;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline int RemamingEngine::errorLineNumber() const
|
|
|
|
{
|
|
|
|
return m_errorLineNumber;
|
|
|
|
}
|
|
|
|
|
2015-04-22 19:33:53 +02:00
|
|
|
} // namespace RenamingUtility
|
|
|
|
|
|
|
|
#endif // RENAMINGUTILITY_RENAMINGENGINE_H
|