Improve renaming tool
* Allow to pass a note to the skip function * Add useful properties to the file info object * Extend example
This commit is contained in:
parent
39b22e70bf
commit
28860e1051
|
@ -338,7 +338,7 @@ void RenamingEngine::executeScriptForItem(const QFileInfo &fileInfo, FileSystemI
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
item->setNote(tr("skipped"));
|
item->setNote(m_tagEditorQObj->note().isEmpty() ? tr("skipped") : m_tagEditorQObj->note());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -145,6 +145,8 @@ TAGEDITOR_JS_VALUE TagEditorObject::parseFileInfo(const QString &fileName)
|
||||||
|
|
||||||
// add basic file information
|
// add basic file information
|
||||||
auto fileInfoObject = m_engine->newObject();
|
auto fileInfoObject = m_engine->newObject();
|
||||||
|
fileInfoObject.setProperty(QStringLiteral("currentPath"), QString::fromUtf8(fileInfo.path().data()));
|
||||||
|
fileInfoObject.setProperty(QStringLiteral("currentPathWithoutExtension"), QString::fromUtf8(fileInfo.pathWithoutExtension().data()));
|
||||||
fileInfoObject.setProperty(QStringLiteral("currentName"), QString::fromUtf8(fileInfo.fileName(false).data()));
|
fileInfoObject.setProperty(QStringLiteral("currentName"), QString::fromUtf8(fileInfo.fileName(false).data()));
|
||||||
fileInfoObject.setProperty(QStringLiteral("currentBaseName"), QString::fromUtf8(fileInfo.fileName(true).data()));
|
fileInfoObject.setProperty(QStringLiteral("currentBaseName"), QString::fromUtf8(fileInfo.fileName(true).data()));
|
||||||
QString suffix = fromNativeFileName(fileInfo.extension().data());
|
QString suffix = fromNativeFileName(fileInfo.extension().data());
|
||||||
|
@ -154,7 +156,7 @@ TAGEDITOR_JS_VALUE TagEditorObject::parseFileInfo(const QString &fileName)
|
||||||
fileInfoObject.setProperty(QStringLiteral("currentSuffix"), suffix TAGEDITOR_JS_READONLY);
|
fileInfoObject.setProperty(QStringLiteral("currentSuffix"), suffix TAGEDITOR_JS_READONLY);
|
||||||
|
|
||||||
// parse further file information
|
// parse further file information
|
||||||
bool criticalParseingErrorOccured = false;
|
bool criticalParseingErrorOccured = false, ioErrorOccured = false;
|
||||||
try {
|
try {
|
||||||
fileInfo.parseEverything(diag);
|
fileInfo.parseEverything(diag);
|
||||||
} catch (const Failure &) {
|
} catch (const Failure &) {
|
||||||
|
@ -163,6 +165,7 @@ TAGEDITOR_JS_VALUE TagEditorObject::parseFileInfo(const QString &fileName)
|
||||||
} catch (...) {
|
} catch (...) {
|
||||||
::IoUtilities::catchIoFailure();
|
::IoUtilities::catchIoFailure();
|
||||||
criticalParseingErrorOccured = true;
|
criticalParseingErrorOccured = true;
|
||||||
|
ioErrorOccured = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// gather notifications
|
// gather notifications
|
||||||
|
@ -170,6 +173,7 @@ TAGEDITOR_JS_VALUE TagEditorObject::parseFileInfo(const QString &fileName)
|
||||||
diagObj << diag;
|
diagObj << diag;
|
||||||
criticalParseingErrorOccured |= diag.level() >= DiagLevel::Critical;
|
criticalParseingErrorOccured |= diag.level() >= DiagLevel::Critical;
|
||||||
fileInfoObject.setProperty(QStringLiteral("hasCriticalMessages"), criticalParseingErrorOccured);
|
fileInfoObject.setProperty(QStringLiteral("hasCriticalMessages"), criticalParseingErrorOccured);
|
||||||
|
fileInfoObject.setProperty(QStringLiteral("ioErrorOccured"), ioErrorOccured);
|
||||||
fileInfoObject.setProperty(QStringLiteral("diagMessages"), diagObj);
|
fileInfoObject.setProperty(QStringLiteral("diagMessages"), diagObj);
|
||||||
|
|
||||||
// add MIME-type, suitable suffix and technical summary
|
// add MIME-type, suitable suffix and technical summary
|
||||||
|
@ -270,9 +274,10 @@ void TagEditorObject::move(const QString &newRelativeDirectory)
|
||||||
m_action = ActionType::Rename;
|
m_action = ActionType::Rename;
|
||||||
}
|
}
|
||||||
|
|
||||||
void TagEditorObject::skip()
|
void TagEditorObject::skip(const QString ¬e)
|
||||||
{
|
{
|
||||||
m_action = ActionType::Skip;
|
m_action = ActionType::Skip;
|
||||||
|
m_note = note;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace RenamingUtility
|
} // namespace RenamingUtility
|
||||||
|
|
|
@ -24,6 +24,7 @@ class TagEditorObject : public QObject {
|
||||||
Q_PROPERTY(bool isFile READ isFile)
|
Q_PROPERTY(bool isFile READ isFile)
|
||||||
Q_PROPERTY(QString newName READ newName WRITE rename)
|
Q_PROPERTY(QString newName READ newName WRITE rename)
|
||||||
Q_PROPERTY(QString newRelativeDirectory READ newRelativeDirectory WRITE move)
|
Q_PROPERTY(QString newRelativeDirectory READ newRelativeDirectory WRITE move)
|
||||||
|
Q_PROPERTY(QString note READ note)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit TagEditorObject(TAGEDITOR_JS_ENGINE *engine);
|
explicit TagEditorObject(TAGEDITOR_JS_ENGINE *engine);
|
||||||
|
@ -38,6 +39,7 @@ public:
|
||||||
bool isFile() const;
|
bool isFile() const;
|
||||||
const QString &newName() const;
|
const QString &newName() const;
|
||||||
const QString &newRelativeDirectory() const;
|
const QString &newRelativeDirectory() const;
|
||||||
|
const QString ¬e() const;
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
TAGEDITOR_JS_VALUE parseFileInfo(const QString &fileName);
|
TAGEDITOR_JS_VALUE parseFileInfo(const QString &fileName);
|
||||||
|
@ -47,7 +49,7 @@ public slots:
|
||||||
void writeLog(const QString &message);
|
void writeLog(const QString &message);
|
||||||
void rename(const QString &newName);
|
void rename(const QString &newName);
|
||||||
void move(const QString &newRelativeDirectory);
|
void move(const QString &newRelativeDirectory);
|
||||||
void skip();
|
void skip(const QString ¬e = QString());
|
||||||
|
|
||||||
private:
|
private:
|
||||||
TAGEDITOR_JS_ENGINE *m_engine;
|
TAGEDITOR_JS_ENGINE *m_engine;
|
||||||
|
@ -58,6 +60,7 @@ private:
|
||||||
ActionType m_action;
|
ActionType m_action;
|
||||||
QString m_newName;
|
QString m_newName;
|
||||||
QString m_newRelativeDirectory;
|
QString m_newRelativeDirectory;
|
||||||
|
QString m_note;
|
||||||
};
|
};
|
||||||
|
|
||||||
inline ActionType TagEditorObject::action() const
|
inline ActionType TagEditorObject::action() const
|
||||||
|
@ -65,6 +68,11 @@ inline ActionType TagEditorObject::action() const
|
||||||
return m_action;
|
return m_action;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline const QString &TagEditorObject::note() const
|
||||||
|
{
|
||||||
|
return m_note;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace RenamingUtility
|
} // namespace RenamingUtility
|
||||||
|
|
||||||
#endif // TAGEDITOR_NO_JSENGINE
|
#endif // TAGEDITOR_NO_JSENGINE
|
||||||
|
|
|
@ -78,6 +78,21 @@ if (fileInfo.currentName.indexOf(".") === 0
|
||||||
tageditor.skip()
|
tageditor.skip()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// treat *.lrc files like their corresponding *.mp3 files
|
||||||
|
var keepSuffix
|
||||||
|
if (fileInfo.currentSuffix === "lrc") {
|
||||||
|
// deduce path of corresponding *.mp3 file
|
||||||
|
var correspondingMp3File = fileInfo.currentPathWithoutExtension + ".mp3"
|
||||||
|
// keep the lrc suffix later
|
||||||
|
keepSuffix = fileInfo.currentSuffix
|
||||||
|
// use the file info from the corresponding *.mp3 file
|
||||||
|
fileInfo = tageditor.parseFileInfo(correspondingMp3File)
|
||||||
|
if (fileInfo.ioErrorOccured) {
|
||||||
|
tageditor.skip("skipped, " + correspondingMp3File + " not present")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
tag = fileInfo.tag
|
||||||
}
|
}
|
||||||
|
|
||||||
// skip files which don't contain audio or video tracks
|
// skip files which don't contain audio or video tracks
|
||||||
|
|
Loading…
Reference in New Issue