mirror of
https://github.com/d47081/qBittorrent.git
synced 2025-03-10 04:11:16 +00:00
Improve detection of file extension string
This commit is contained in:
parent
17fa615bd3
commit
15a249eb54
@ -55,6 +55,7 @@
|
|||||||
#include <QDirIterator>
|
#include <QDirIterator>
|
||||||
#include <QFile>
|
#include <QFile>
|
||||||
#include <QFileInfo>
|
#include <QFileInfo>
|
||||||
|
#include <QMimeDatabase>
|
||||||
#include <QStorageInfo>
|
#include <QStorageInfo>
|
||||||
#include <QRegularExpression>
|
#include <QRegularExpression>
|
||||||
|
|
||||||
@ -76,9 +77,14 @@ QString Utils::Fs::toUniformPath(const QString &path)
|
|||||||
*/
|
*/
|
||||||
QString Utils::Fs::fileExtension(const QString &filename)
|
QString Utils::Fs::fileExtension(const QString &filename)
|
||||||
{
|
{
|
||||||
const QString ext = QString(filename).remove(QB_EXT);
|
const QString name = filename.endsWith(QB_EXT)
|
||||||
const int pointIndex = ext.lastIndexOf('.');
|
#if (QT_VERSION >= QT_VERSION_CHECK(5, 10, 0))
|
||||||
return (pointIndex >= 0) ? ext.mid(pointIndex + 1) : QString();
|
? filename.chopped(QB_EXT.length())
|
||||||
|
#else
|
||||||
|
? filename.left(filename.length() - QB_EXT.length())
|
||||||
|
#endif
|
||||||
|
: filename;
|
||||||
|
return QMimeDatabase().suffixForFileName(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
QString Utils::Fs::fileName(const QString &filePath)
|
QString Utils::Fs::fileName(const QString &filePath)
|
||||||
|
@ -28,6 +28,7 @@
|
|||||||
|
|
||||||
#include "autoexpandabledialog.h"
|
#include "autoexpandabledialog.h"
|
||||||
|
|
||||||
|
#include "base/utils/fs.h"
|
||||||
#include "ui_autoexpandabledialog.h"
|
#include "ui_autoexpandabledialog.h"
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
|
|
||||||
@ -57,12 +58,9 @@ QString AutoExpandableDialog::getText(QWidget *parent, const QString &title, con
|
|||||||
d.m_ui->textEdit->selectAll();
|
d.m_ui->textEdit->selectAll();
|
||||||
if (excludeExtension)
|
if (excludeExtension)
|
||||||
{
|
{
|
||||||
int lastDotIndex = text.lastIndexOf('.');
|
const QString extension = Utils::Fs::fileExtension(text);
|
||||||
if ((lastDotIndex > 3) && (text.mid(lastDotIndex - 4, 4).toLower() == ".tar"))
|
if (!extension.isEmpty())
|
||||||
lastDotIndex -= 4;
|
d.m_ui->textEdit->setSelection(0, (text.length() - extension.length() - 1));
|
||||||
// Select file name without extension, except dot files like .gitignore
|
|
||||||
if (lastDotIndex > 0)
|
|
||||||
d.m_ui->textEdit->setSelection(0, lastDotIndex);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool res = d.exec();
|
bool res = d.exec();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user