2015-09-06 20:20:00 +02:00
|
|
|
#include "./renamingengine.h"
|
|
|
|
#include "./filesystemitemmodel.h"
|
|
|
|
#include "./filteredfilesystemitemmodel.h"
|
2016-01-09 02:56:56 +01:00
|
|
|
#include "./tageditorobject.h"
|
2015-04-22 19:33:53 +02:00
|
|
|
|
|
|
|
#include <QDir>
|
2016-01-09 02:56:56 +01:00
|
|
|
#include <QStringBuilder>
|
2015-04-22 19:33:53 +02:00
|
|
|
|
2017-02-05 21:04:27 +01:00
|
|
|
#include <memory>
|
|
|
|
|
2015-04-22 19:33:53 +02:00
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
namespace RenamingUtility {
|
|
|
|
|
2018-03-07 01:18:01 +01:00
|
|
|
RenamingEngine::RenamingEngine(QObject *parent)
|
|
|
|
: QObject(parent)
|
|
|
|
,
|
2016-04-21 23:55:22 +02:00
|
|
|
#ifndef TAGEDITOR_NO_JSENGINE
|
2018-03-07 01:18:01 +01:00
|
|
|
m_tagEditorQObj(new TagEditorObject(&m_engine))
|
|
|
|
, m_tagEditorJsObj(TAGEDITOR_JS_QOBJECT(m_engine, m_tagEditorQObj))
|
|
|
|
,
|
2016-04-21 23:55:22 +02:00
|
|
|
#endif
|
2018-03-07 01:18:01 +01:00
|
|
|
m_itemsProcessed(0)
|
|
|
|
, m_errorsOccured(0)
|
|
|
|
, m_aborted(false)
|
|
|
|
, m_includeSubdirs(false)
|
|
|
|
, m_isBusy(false)
|
|
|
|
, m_model(nullptr)
|
|
|
|
, m_currentModel(nullptr)
|
|
|
|
, m_previewModel(nullptr)
|
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
|
|
|
m_engine.globalObject().setProperty(QStringLiteral("tageditor"), m_tagEditorJsObj);
|
2016-04-21 23:55:22 +02:00
|
|
|
#endif
|
2017-01-06 21:29:43 +01:00
|
|
|
connect(this, &RenamingEngine::previewGenerated, this, &RenamingEngine::processPreviewGenerated);
|
|
|
|
connect(this, &RenamingEngine::changingsApplied, this, &RenamingEngine::processChangingsApplied);
|
2015-04-22 19:33:53 +02:00
|
|
|
}
|
|
|
|
|
2020-11-27 00:40:45 +01:00
|
|
|
RenamingEngine::~RenamingEngine()
|
|
|
|
{
|
|
|
|
#ifndef TAGEDITOR_NO_JSENGINE
|
|
|
|
for (auto *const child : children()) {
|
|
|
|
if (auto *const childThread = qobject_cast<QThread *>(child)) {
|
|
|
|
childThread->wait();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2016-04-21 23:55:22 +02:00
|
|
|
#ifndef TAGEDITOR_NO_JSENGINE
|
2017-01-06 21:29:43 +01:00
|
|
|
bool RenamingEngine::setProgram(const TAGEDITOR_JS_VALUE &program)
|
2016-01-09 02:56:56 +01:00
|
|
|
{
|
2018-04-29 19:01:55 +02:00
|
|
|
if (program.isError()) {
|
2016-01-09 02:56:56 +01:00
|
|
|
m_errorMessage = program.property(QStringLiteral("message")).toString();
|
|
|
|
m_errorLineNumber = TAGEDITOR_JS_INT(program.property(QStringLiteral("lineNumber")));
|
2018-04-29 19:01:55 +02:00
|
|
|
return false;
|
|
|
|
} else if (!TAGEDITOR_JS_IS_VALID_PROG(program)) {
|
|
|
|
m_errorMessage = tr("Program is not callable. Please don't close a function you didn't open.");
|
2016-01-09 02:56:56 +01:00
|
|
|
m_errorLineNumber = 0;
|
2018-04-29 19:01:55 +02:00
|
|
|
return false;
|
2016-01-09 02:56:56 +01:00
|
|
|
}
|
2018-04-29 19:01:55 +02:00
|
|
|
|
|
|
|
m_errorMessage.clear();
|
|
|
|
m_errorLineNumber = 0;
|
|
|
|
m_program = program;
|
|
|
|
return true;
|
2016-01-09 02:56:56 +01:00
|
|
|
}
|
2016-04-21 23:55:22 +02:00
|
|
|
#endif
|
2015-04-22 19:33:53 +02:00
|
|
|
|
2017-01-06 21:29:43 +01:00
|
|
|
bool RenamingEngine::setProgram(const QString &program)
|
2016-01-09 02:56:56 +01:00
|
|
|
{
|
2016-04-21 23:55:22 +02:00
|
|
|
#ifndef TAGEDITOR_NO_JSENGINE
|
2016-01-09 02:56:56 +01:00
|
|
|
return setProgram(m_engine.evaluate(QStringLiteral("(function(){") % program % QStringLiteral("})")));
|
2016-04-21 23:55:22 +02:00
|
|
|
#else
|
2020-09-08 19:09:12 +02:00
|
|
|
Q_UNUSED(program)
|
2016-04-21 23:55:22 +02:00
|
|
|
m_errorLineNumber = 0;
|
|
|
|
m_errorMessage = tr("Not compiled with ECMA support.");
|
|
|
|
return false;
|
|
|
|
#endif
|
2016-01-09 02:56:56 +01:00
|
|
|
}
|
|
|
|
|
2017-01-06 21:29:43 +01:00
|
|
|
bool RenamingEngine::generatePreview(const QDir &rootDirectory, bool includeSubdirs)
|
2015-04-22 19:33:53 +02:00
|
|
|
{
|
2016-04-21 23:55:22 +02:00
|
|
|
#ifndef TAGEDITOR_NO_JSENGINE
|
2018-03-07 01:18:01 +01:00
|
|
|
if (m_isBusy) {
|
2015-04-22 19:33:53 +02:00
|
|
|
return false;
|
|
|
|
}
|
2017-01-06 21:43:59 +01:00
|
|
|
setRootItem();
|
|
|
|
m_includeSubdirs = includeSubdirs;
|
|
|
|
m_dir = rootDirectory;
|
2019-10-11 19:47:30 +02:00
|
|
|
|
|
|
|
(new PreviewGenerator(this))->start();
|
2017-01-06 21:43:59 +01:00
|
|
|
return m_isBusy = true;
|
2016-04-21 23:55:22 +02:00
|
|
|
#else
|
2020-09-08 19:09:12 +02:00
|
|
|
Q_UNUSED(rootDirectory)
|
|
|
|
Q_UNUSED(includeSubdirs)
|
2016-04-21 23:55:22 +02:00
|
|
|
return false;
|
|
|
|
#endif
|
2015-04-22 19:33:53 +02:00
|
|
|
}
|
|
|
|
|
2017-01-06 21:29:43 +01:00
|
|
|
bool RenamingEngine::applyChangings()
|
2015-04-22 19:33:53 +02:00
|
|
|
{
|
2018-03-07 01:18:01 +01:00
|
|
|
if (!m_rootItem || m_isBusy) {
|
2015-04-22 19:33:53 +02:00
|
|
|
return false;
|
|
|
|
}
|
2020-09-08 19:09:12 +02:00
|
|
|
#ifndef TAGEDITOR_NO_JSENGINE
|
2019-10-11 19:47:30 +02:00
|
|
|
(new RenamingThing(this))->start();
|
2020-09-08 19:09:12 +02:00
|
|
|
#endif
|
2017-01-06 21:43:59 +01:00
|
|
|
return m_isBusy = true;
|
2015-04-22 19:33:53 +02:00
|
|
|
}
|
|
|
|
|
2017-01-06 21:29:43 +01:00
|
|
|
bool RenamingEngine::clearPreview()
|
2015-04-22 19:33:53 +02:00
|
|
|
{
|
2018-03-07 01:18:01 +01:00
|
|
|
if (m_isBusy) {
|
2015-04-22 19:33:53 +02:00
|
|
|
return false;
|
|
|
|
}
|
2017-01-06 21:43:59 +01:00
|
|
|
|
|
|
|
updateModel(nullptr);
|
|
|
|
m_rootItem.reset();
|
|
|
|
return true;
|
2015-04-22 19:33:53 +02:00
|
|
|
}
|
|
|
|
|
2017-01-06 21:29:43 +01:00
|
|
|
FileSystemItemModel *RenamingEngine::model()
|
2015-04-22 19:33:53 +02:00
|
|
|
{
|
2018-03-07 01:18:01 +01:00
|
|
|
if (!m_model) {
|
2015-04-22 19:33:53 +02:00
|
|
|
m_model = new FileSystemItemModel(m_rootItem.get(), this);
|
|
|
|
}
|
|
|
|
return m_model;
|
|
|
|
}
|
|
|
|
|
2017-01-06 21:29:43 +01:00
|
|
|
FilteredFileSystemItemModel *RenamingEngine::currentModel()
|
2015-04-22 19:33:53 +02:00
|
|
|
{
|
2018-03-07 01:18:01 +01:00
|
|
|
if (!m_currentModel) {
|
2015-04-22 19:33:53 +02:00
|
|
|
m_currentModel = new FilteredFileSystemItemModel(ItemStatus::Current, this);
|
|
|
|
m_currentModel->setSourceModel(model());
|
|
|
|
}
|
|
|
|
return m_currentModel;
|
|
|
|
}
|
|
|
|
|
2017-01-06 21:29:43 +01:00
|
|
|
FilteredFileSystemItemModel *RenamingEngine::previewModel()
|
2015-04-22 19:33:53 +02:00
|
|
|
{
|
2018-03-07 01:18:01 +01:00
|
|
|
if (!m_previewModel) {
|
2015-04-22 19:33:53 +02:00
|
|
|
m_previewModel = new FilteredFileSystemItemModel(ItemStatus::New, this);
|
|
|
|
m_previewModel->setSourceModel(model());
|
|
|
|
}
|
|
|
|
return m_previewModel;
|
|
|
|
}
|
|
|
|
|
2017-01-06 21:29:43 +01:00
|
|
|
void RenamingEngine::processPreviewGenerated()
|
2015-04-22 19:33:53 +02:00
|
|
|
{
|
2019-10-11 19:47:30 +02:00
|
|
|
finalizeTaskCompletion();
|
2015-10-13 20:12:00 +02:00
|
|
|
setRootItem(move(m_newlyGeneratedRootItem));
|
2015-04-22 19:33:53 +02:00
|
|
|
}
|
|
|
|
|
2017-01-06 21:29:43 +01:00
|
|
|
void RenamingEngine::processChangingsApplied()
|
2015-04-22 19:33:53 +02:00
|
|
|
{
|
2019-10-11 19:47:30 +02:00
|
|
|
finalizeTaskCompletion();
|
2015-04-22 19:33:53 +02:00
|
|
|
updateModel(nullptr);
|
|
|
|
updateModel(m_rootItem.get());
|
|
|
|
}
|
|
|
|
|
2019-10-11 19:47:30 +02:00
|
|
|
void RenamingEngine::resetStatus()
|
|
|
|
{
|
2019-12-15 19:31:34 +01:00
|
|
|
#if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0))
|
|
|
|
m_aborted.storeRelaxed(false);
|
|
|
|
#else
|
2019-10-11 19:47:30 +02:00
|
|
|
m_aborted.store(false);
|
2019-12-15 19:31:34 +01:00
|
|
|
#endif
|
2019-10-11 19:47:30 +02:00
|
|
|
m_itemsProcessed = 0;
|
|
|
|
m_errorsOccured = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void RenamingEngine::finalizeTaskCompletion()
|
|
|
|
{
|
2020-09-08 19:09:12 +02:00
|
|
|
#ifndef TAGEDITOR_NO_JSENGINE
|
2019-10-11 19:47:30 +02:00
|
|
|
m_engine.moveToThread(thread());
|
2020-09-08 19:09:12 +02:00
|
|
|
#endif
|
2019-10-11 19:47:30 +02:00
|
|
|
m_isBusy = false;
|
|
|
|
}
|
|
|
|
|
2017-01-06 21:29:43 +01:00
|
|
|
inline void RenamingEngine::setRootItem(unique_ptr<FileSystemItem> &&rootItem)
|
2015-04-22 19:33:53 +02:00
|
|
|
{
|
2015-10-13 20:12:00 +02:00
|
|
|
updateModel(rootItem.get());
|
|
|
|
m_rootItem = move(rootItem);
|
2015-04-22 19:33:53 +02:00
|
|
|
}
|
|
|
|
|
2017-01-06 21:29:43 +01:00
|
|
|
void RenamingEngine::updateModel(FileSystemItem *rootItem)
|
2015-04-22 19:33:53 +02:00
|
|
|
{
|
2018-03-07 01:18:01 +01:00
|
|
|
if (m_model) {
|
2015-04-22 19:33:53 +02:00
|
|
|
m_model->setRootItem(rootItem);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-21 23:55:22 +02:00
|
|
|
#ifndef TAGEDITOR_NO_JSENGINE
|
2017-01-06 21:29:43 +01:00
|
|
|
unique_ptr<FileSystemItem> RenamingEngine::generatePreview(const QDir &dir, FileSystemItem *parent)
|
2015-04-22 19:33:53 +02:00
|
|
|
{
|
2015-10-13 20:12:00 +02:00
|
|
|
auto item = make_unique<FileSystemItem>(ItemStatus::Current, ItemType::Dir, dir.dirName(), parent);
|
2015-04-22 19:33:53 +02:00
|
|
|
item->setApplied(false);
|
2018-03-07 01:18:01 +01:00
|
|
|
for (const QFileInfo &entry : dir.entryInfoList()) {
|
|
|
|
if (entry.fileName() == QLatin1String("..") || entry.fileName() == QLatin1String(".")) {
|
2015-04-22 19:33:53 +02:00
|
|
|
continue;
|
|
|
|
}
|
2015-10-13 20:12:00 +02:00
|
|
|
FileSystemItem *subItem; // will be deleted by parent
|
2018-03-07 01:18:01 +01:00
|
|
|
if (entry.isDir() && m_includeSubdirs) {
|
2015-10-13 20:12:00 +02:00
|
|
|
subItem = generatePreview(QDir(entry.absoluteFilePath()), item.get()).release();
|
2018-03-07 01:18:01 +01:00
|
|
|
} else if (entry.isFile()) {
|
2015-10-13 20:12:00 +02:00
|
|
|
subItem = new FileSystemItem(ItemStatus::Current, ItemType::File, entry.fileName(), item.get());
|
2015-04-22 19:33:53 +02:00
|
|
|
subItem->setApplied(false);
|
|
|
|
} else {
|
|
|
|
subItem = nullptr;
|
|
|
|
}
|
2018-03-07 01:18:01 +01:00
|
|
|
if (subItem) {
|
2015-04-22 19:33:53 +02:00
|
|
|
executeScriptForItem(entry, subItem);
|
2018-03-07 01:18:01 +01:00
|
|
|
if (subItem->errorOccured()) {
|
2015-04-22 19:33:53 +02:00
|
|
|
++m_errorsOccured;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
++m_itemsProcessed;
|
2018-03-07 01:18:01 +01:00
|
|
|
if (isAborted()) {
|
2015-04-22 19:33:53 +02:00
|
|
|
return item;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
emit progress(m_itemsProcessed, m_errorsOccured);
|
|
|
|
return item;
|
|
|
|
}
|
2016-04-21 23:55:22 +02:00
|
|
|
#endif
|
2015-04-22 19:33:53 +02:00
|
|
|
|
2017-01-06 21:29:43 +01:00
|
|
|
void RenamingEngine::applyChangings(FileSystemItem *parentItem)
|
2015-04-22 19:33:53 +02:00
|
|
|
{
|
2018-08-15 21:49:06 +02:00
|
|
|
for (auto *const item : parentItem->children()) {
|
2018-03-07 01:18:01 +01:00
|
|
|
if (!item->applied() && !item->errorOccured()) {
|
|
|
|
switch (item->status()) {
|
2015-04-22 19:33:53 +02:00
|
|
|
case ItemStatus::New: {
|
2017-01-06 21:43:59 +01:00
|
|
|
const FileSystemItem *counterpartItem = item->counterpart(); // holds current name
|
|
|
|
const QString currentPath = counterpartItem ? counterpartItem->relativePath() : QString();
|
|
|
|
const QString newPath = item->relativePath();
|
2018-03-07 01:18:01 +01:00
|
|
|
if (item->name().isEmpty()) {
|
2015-04-22 19:33:53 +02:00
|
|
|
// new item name mustn't be empty
|
|
|
|
item->setNote(tr("generated name is empty"));
|
|
|
|
item->setErrorOccured(true);
|
2018-03-07 01:18:01 +01:00
|
|
|
} else if (counterpartItem && !counterpartItem->name().isEmpty()) {
|
2015-04-22 19:33:53 +02:00
|
|
|
// rename current item
|
2018-03-07 01:18:01 +01:00
|
|
|
if (item->parent() != counterpartItem->parent() || item->name() != counterpartItem->name()) {
|
|
|
|
if (m_dir.exists(newPath)) {
|
|
|
|
if (item->parent() == counterpartItem->parent()) {
|
2015-04-22 19:33:53 +02:00
|
|
|
item->setNote(tr("unable to rename, there is already an entry with the same name"));
|
|
|
|
} else {
|
|
|
|
item->setNote(tr("unable to move, there is already an entry with the same name"));
|
|
|
|
}
|
|
|
|
item->setErrorOccured(true);
|
2018-03-07 01:18:01 +01:00
|
|
|
} else if (m_dir.rename(currentPath, newPath)) {
|
|
|
|
if (item->parent() == counterpartItem->parent()) {
|
2015-04-22 19:33:53 +02:00
|
|
|
item->setNote(tr("renamed"));
|
|
|
|
} else {
|
|
|
|
item->setNote(tr("moved"));
|
|
|
|
}
|
|
|
|
item->setApplied(true);
|
|
|
|
} else {
|
|
|
|
item->setNote(tr("unable to rename"));
|
|
|
|
item->setErrorOccured(true);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
item->setNote(tr("nothing to be changed"));
|
|
|
|
item->setApplied(true);
|
|
|
|
}
|
2018-03-07 01:18:01 +01:00
|
|
|
} else if (item->type() == ItemType::Dir) {
|
2015-04-22 19:33:53 +02:00
|
|
|
// create new item, but only if its a dir
|
2018-03-07 01:18:01 +01:00
|
|
|
if (m_dir.exists(newPath)) {
|
2015-04-22 19:33:53 +02:00
|
|
|
item->setNote(tr("directory already existed"));
|
|
|
|
item->setApplied(true);
|
2018-03-07 01:18:01 +01:00
|
|
|
} else if (m_dir.mkpath(newPath)) {
|
2015-04-22 19:33:53 +02:00
|
|
|
item->setNote(tr("directory created"));
|
|
|
|
item->setApplied(true);
|
|
|
|
} else {
|
|
|
|
item->setNote(tr("unable to create directory"));
|
|
|
|
item->setErrorOccured(true);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// can not create new file
|
|
|
|
item->setNote(tr("unable to create file"));
|
|
|
|
item->setErrorOccured(true);
|
|
|
|
}
|
|
|
|
break;
|
2018-03-07 01:18:01 +01:00
|
|
|
}
|
|
|
|
case ItemStatus::Current:
|
2015-04-22 19:33:53 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2018-03-07 01:18:01 +01:00
|
|
|
if (item->errorOccured()) {
|
2015-04-22 19:33:53 +02:00
|
|
|
++m_errorsOccured;
|
|
|
|
}
|
|
|
|
// apply changings for child items as well
|
2018-03-07 01:18:01 +01:00
|
|
|
if (item->type() == ItemType::Dir) {
|
2015-04-22 19:33:53 +02:00
|
|
|
applyChangings(item);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
m_itemsProcessed += parentItem->children().size();
|
|
|
|
emit progress(m_itemsProcessed, m_errorsOccured);
|
|
|
|
}
|
|
|
|
|
2017-01-06 21:29:43 +01:00
|
|
|
void RenamingEngine::setError(const QList<FileSystemItem *> items)
|
2015-04-22 19:33:53 +02:00
|
|
|
{
|
2018-08-15 21:49:06 +02:00
|
|
|
for (auto *const item : items) {
|
2015-04-22 19:33:53 +02:00
|
|
|
item->setErrorOccured(true);
|
|
|
|
item->setNote(tr("skipped due to error of superior item"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-21 23:55:22 +02:00
|
|
|
#ifndef TAGEDITOR_NO_JSENGINE
|
2017-01-06 21:29:43 +01:00
|
|
|
void RenamingEngine::executeScriptForItem(const QFileInfo &fileInfo, FileSystemItem *item)
|
2015-04-22 19:33:53 +02:00
|
|
|
{
|
2016-01-09 02:56:56 +01:00
|
|
|
// make file info for the specified item available in the script
|
|
|
|
m_tagEditorQObj->setFileInfo(fileInfo, item);
|
2019-10-11 19:47:30 +02:00
|
|
|
|
2015-10-13 20:12:00 +02:00
|
|
|
// execute script
|
2018-04-29 19:01:55 +02:00
|
|
|
const auto scriptResult(m_program.call());
|
2018-03-07 01:18:01 +01:00
|
|
|
if (scriptResult.isError()) {
|
2015-10-13 20:12:00 +02:00
|
|
|
// handle error
|
2015-04-22 19:33:53 +02:00
|
|
|
item->setErrorOccured(true);
|
2016-01-09 02:56:56 +01:00
|
|
|
item->setNote(scriptResult.toString());
|
2018-04-29 19:01:55 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// create preview for action
|
|
|
|
const QString &newName = m_tagEditorQObj->newName();
|
|
|
|
const QString &newRelativeDirectory = m_tagEditorQObj->newRelativeDirectory();
|
|
|
|
switch (m_tagEditorQObj->action()) {
|
|
|
|
case ActionType::None:
|
|
|
|
item->setNote(tr("no action specified"));
|
|
|
|
break;
|
|
|
|
case ActionType::Rename:
|
|
|
|
if (!newRelativeDirectory.isEmpty()) {
|
2018-11-15 21:32:49 +01:00
|
|
|
FileSystemItem *const counterpartParent = item->root()->makeChildAvailable(newRelativeDirectory);
|
2018-04-29 19:01:55 +02:00
|
|
|
const QString &counterpartName = newName.isEmpty() ? item->name() : newName;
|
2019-02-13 21:42:29 +01:00
|
|
|
if (const auto *const conflictingItem = counterpartParent->findChild(counterpartName, item)) {
|
|
|
|
QString conflictingName;
|
|
|
|
if (const auto *const conflictingCounterpart = conflictingItem->counterpart()) {
|
|
|
|
conflictingCounterpart->relativePath(conflictingName);
|
|
|
|
} else {
|
|
|
|
conflictingName = conflictingItem->currentName();
|
|
|
|
}
|
|
|
|
item->setNote(tr("name is already used at new location by '%1'").arg(conflictingName));
|
2018-04-29 19:01:55 +02:00
|
|
|
item->setErrorOccured(true);
|
|
|
|
} else {
|
2018-11-15 21:32:49 +01:00
|
|
|
auto *const counterpart = new FileSystemItem(ItemStatus::New, item->type(), counterpartName, counterpartParent);
|
2018-04-29 19:01:55 +02:00
|
|
|
item->setCounterpart(counterpart);
|
|
|
|
counterpart->setCheckable(true);
|
|
|
|
counterpart->setChecked(true);
|
2015-04-22 19:33:53 +02:00
|
|
|
}
|
2018-04-29 19:01:55 +02:00
|
|
|
} else if (!newName.isEmpty()) {
|
|
|
|
item->setNewName(newName);
|
|
|
|
}
|
2018-11-15 21:32:49 +01:00
|
|
|
if (FileSystemItem *const newItem = item->counterpart()) {
|
2018-04-29 19:01:55 +02:00
|
|
|
if ((newItem->name().isEmpty() || newItem->name() == item->name()) && (newItem->parent() == item->parent())) {
|
|
|
|
item->setNote(tr("name doesn't change"));
|
|
|
|
} else if (newItem->parent() && newItem->parent()->findChild(newItem->name(), newItem)) {
|
|
|
|
item->setNote(tr("generated name is already used"));
|
|
|
|
item->setErrorOccured(true);
|
|
|
|
} else if (newItem->parent() == item->parent()) {
|
|
|
|
item->setNote(tr("will be renamed"));
|
|
|
|
newItem->setCheckable(true);
|
|
|
|
newItem->setChecked(true);
|
2015-04-22 19:33:53 +02:00
|
|
|
} else {
|
2018-04-29 19:01:55 +02:00
|
|
|
item->setNote(tr("will be moved"));
|
2015-04-22 19:33:53 +02:00
|
|
|
}
|
2019-02-13 21:42:29 +01:00
|
|
|
} else if (item->note().isEmpty()) {
|
2018-04-29 19:01:55 +02:00
|
|
|
item->setNote(tr("can not be renamed"));
|
2015-04-22 19:33:53 +02:00
|
|
|
}
|
2018-04-29 19:01:55 +02:00
|
|
|
break;
|
|
|
|
default:
|
2018-11-15 21:36:12 +01:00
|
|
|
item->setNote(m_tagEditorQObj->note().isEmpty() ? tr("skipped") : m_tagEditorQObj->note());
|
2015-04-22 19:33:53 +02:00
|
|
|
}
|
|
|
|
}
|
2019-10-11 19:47:30 +02:00
|
|
|
|
|
|
|
PreviewGenerator::PreviewGenerator(RenamingEngine *engine)
|
|
|
|
: QThread(engine)
|
|
|
|
, m_engine(engine)
|
|
|
|
{
|
|
|
|
m_engine->m_engine.moveToThread(this);
|
|
|
|
connect(this, &PreviewGenerator::finished, m_engine, &RenamingEngine::previewGenerated, Qt::QueuedConnection);
|
|
|
|
connect(this, &PreviewGenerator::finished, this, &PreviewGenerator::deleteLater);
|
|
|
|
}
|
|
|
|
|
|
|
|
void PreviewGenerator::run()
|
|
|
|
{
|
|
|
|
m_engine->resetStatus();
|
|
|
|
m_engine->m_newlyGeneratedRootItem = m_engine->generatePreview(m_engine->m_dir);
|
|
|
|
}
|
|
|
|
|
|
|
|
RenamingThing::RenamingThing(RenamingEngine *engine)
|
|
|
|
: QThread(engine)
|
|
|
|
, m_engine(engine)
|
|
|
|
{
|
|
|
|
m_engine->m_engine.moveToThread(this);
|
|
|
|
connect(this, &RenamingThing::finished, m_engine, &RenamingEngine::changingsApplied, Qt::QueuedConnection);
|
|
|
|
connect(this, &RenamingThing::finished, this, &RenamingThing::deleteLater);
|
|
|
|
}
|
|
|
|
|
|
|
|
void RenamingThing::run()
|
|
|
|
{
|
|
|
|
m_engine->resetStatus();
|
|
|
|
m_engine->applyChangings(m_engine->m_rootItem.get());
|
|
|
|
}
|
|
|
|
|
2016-04-21 23:55:22 +02:00
|
|
|
#endif
|
2015-04-22 19:33:53 +02:00
|
|
|
|
|
|
|
} // namespace RenamingUtility
|