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;
|
||||
default:
|
||||
item->setNote(tr("skipped"));
|
||||
item->setNote(m_tagEditorQObj->note().isEmpty() ? tr("skipped") : m_tagEditorQObj->note());
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -145,6 +145,8 @@ TAGEDITOR_JS_VALUE TagEditorObject::parseFileInfo(const QString &fileName)
|
|||
|
||||
// add basic file information
|
||||
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("currentBaseName"), QString::fromUtf8(fileInfo.fileName(true).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);
|
||||
|
||||
// parse further file information
|
||||
bool criticalParseingErrorOccured = false;
|
||||
bool criticalParseingErrorOccured = false, ioErrorOccured = false;
|
||||
try {
|
||||
fileInfo.parseEverything(diag);
|
||||
} catch (const Failure &) {
|
||||
|
@ -163,6 +165,7 @@ TAGEDITOR_JS_VALUE TagEditorObject::parseFileInfo(const QString &fileName)
|
|||
} catch (...) {
|
||||
::IoUtilities::catchIoFailure();
|
||||
criticalParseingErrorOccured = true;
|
||||
ioErrorOccured = true;
|
||||
}
|
||||
|
||||
// gather notifications
|
||||
|
@ -170,6 +173,7 @@ TAGEDITOR_JS_VALUE TagEditorObject::parseFileInfo(const QString &fileName)
|
|||
diagObj << diag;
|
||||
criticalParseingErrorOccured |= diag.level() >= DiagLevel::Critical;
|
||||
fileInfoObject.setProperty(QStringLiteral("hasCriticalMessages"), criticalParseingErrorOccured);
|
||||
fileInfoObject.setProperty(QStringLiteral("ioErrorOccured"), ioErrorOccured);
|
||||
fileInfoObject.setProperty(QStringLiteral("diagMessages"), diagObj);
|
||||
|
||||
// add MIME-type, suitable suffix and technical summary
|
||||
|
@ -270,9 +274,10 @@ void TagEditorObject::move(const QString &newRelativeDirectory)
|
|||
m_action = ActionType::Rename;
|
||||
}
|
||||
|
||||
void TagEditorObject::skip()
|
||||
void TagEditorObject::skip(const QString ¬e)
|
||||
{
|
||||
m_action = ActionType::Skip;
|
||||
m_note = note;
|
||||
}
|
||||
|
||||
} // namespace RenamingUtility
|
||||
|
|
|
@ -24,6 +24,7 @@ class TagEditorObject : public QObject {
|
|||
Q_PROPERTY(bool isFile READ isFile)
|
||||
Q_PROPERTY(QString newName READ newName WRITE rename)
|
||||
Q_PROPERTY(QString newRelativeDirectory READ newRelativeDirectory WRITE move)
|
||||
Q_PROPERTY(QString note READ note)
|
||||
|
||||
public:
|
||||
explicit TagEditorObject(TAGEDITOR_JS_ENGINE *engine);
|
||||
|
@ -38,6 +39,7 @@ public:
|
|||
bool isFile() const;
|
||||
const QString &newName() const;
|
||||
const QString &newRelativeDirectory() const;
|
||||
const QString ¬e() const;
|
||||
|
||||
public slots:
|
||||
TAGEDITOR_JS_VALUE parseFileInfo(const QString &fileName);
|
||||
|
@ -47,7 +49,7 @@ public slots:
|
|||
void writeLog(const QString &message);
|
||||
void rename(const QString &newName);
|
||||
void move(const QString &newRelativeDirectory);
|
||||
void skip();
|
||||
void skip(const QString ¬e = QString());
|
||||
|
||||
private:
|
||||
TAGEDITOR_JS_ENGINE *m_engine;
|
||||
|
@ -58,6 +60,7 @@ private:
|
|||
ActionType m_action;
|
||||
QString m_newName;
|
||||
QString m_newRelativeDirectory;
|
||||
QString m_note;
|
||||
};
|
||||
|
||||
inline ActionType TagEditorObject::action() const
|
||||
|
@ -65,6 +68,11 @@ inline ActionType TagEditorObject::action() const
|
|||
return m_action;
|
||||
}
|
||||
|
||||
inline const QString &TagEditorObject::note() const
|
||||
{
|
||||
return m_note;
|
||||
}
|
||||
|
||||
} // namespace RenamingUtility
|
||||
|
||||
#endif // TAGEDITOR_NO_JSENGINE
|
||||
|
|
|
@ -78,6 +78,21 @@ if (fileInfo.currentName.indexOf(".") === 0
|
|||
tageditor.skip()
|
||||
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
|
||||
|
|
Loading…
Reference in New Issue