diff --git a/src/core/batchrenamejob.cpp b/src/core/batchrenamejob.cpp --- a/src/core/batchrenamejob.cpp +++ b/src/core/batchrenamejob.cpp @@ -59,9 +59,8 @@ // Check for extensions. QSet extensions; - QMimeDatabase db; foreach (const QUrl &url, m_srcList) { - const QString extension = db.suffixForFileName(url.toDisplayString().toLower()); + const QString extension = fileExtension(url.fileName()); if (extensions.contains(extension)) { m_allExtensionsDifferent = false; break; @@ -102,6 +101,7 @@ Q_DECLARE_PUBLIC(BatchRenameJob) void slotStart(); + static QString fileExtension(const QString& filename); QString indexedName(const QString& name, int index, QChar placeHolder) const; @@ -157,6 +157,26 @@ return newName; } +// The function QMimeDatabase.suffixForFileName always converts the extension to lower case +// This function is a helper which avoids the conversion to lower case +QString BatchRenameJobPrivate::fileExtension(const QString& filename) +{ + QMimeDatabase db; + const size_t extensionLen = db.suffixForFileName(filename).length(); + + //extensionLen will be 0 if the extension is not in the QMimeDatabase i.e "foo.xyz" + if (extensionLen) { + return filename.right(extensionLen); + } else { + //Fallback to everything right of the last '.' + const int dotIndex = filename.lastIndexOf(QStringLiteral(".")); + if (dotIndex != -1) { + return filename.mid(dotIndex+1); + } + } + return QStringLiteral(); +} + void BatchRenameJobPrivate::slotStart() { Q_Q(BatchRenameJob); @@ -168,8 +188,7 @@ if (m_listIterator != m_srcList.constEnd()) { QString newName = indexedName(m_newName, m_index, m_placeHolder); const QUrl oldUrl = *m_listIterator; - QMimeDatabase db; - const QString extension = db.suffixForFileName(oldUrl.path().toLower()); + const QString extension = fileExtension(oldUrl.fileName()); if (!extension.isEmpty()) { newName += QLatin1Char('.') + extension; }