Browse Source

Merge pull request #14437 from Chocobo1/mime

Improve detection of filename extension of audio/video files
adaptive-webui-19844
Mike Tzou 4 years ago committed by GitHub
parent
commit
7400284cff
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 16
      src/base/utils/misc.cpp
  2. 2
      src/base/utils/misc.h
  3. 5
      src/gui/previewselectdialog.cpp
  4. 6
      src/gui/transferlistwidget.cpp

16
src/base/utils/misc.cpp

@ -51,6 +51,7 @@ @@ -51,6 +51,7 @@
#include <zlib.h>
#include <QCoreApplication>
#include <QMimeDatabase>
#include <QRegularExpression>
#include <QSet>
#include <QSysInfo>
@ -62,6 +63,7 @@ @@ -62,6 +63,7 @@
#include "base/types.h"
#include "base/unicodestrings.h"
#include "base/utils/fs.h"
#include "base/utils/string.h"
namespace
@ -290,9 +292,17 @@ qlonglong Utils::Misc::sizeInBytes(qreal size, const Utils::Misc::SizeUnit unit) @@ -290,9 +292,17 @@ qlonglong Utils::Misc::sizeInBytes(qreal size, const Utils::Misc::SizeUnit unit)
return size;
}
bool Utils::Misc::isPreviewable(const QString &extension)
bool Utils::Misc::isPreviewable(const QString &filename)
{
static const QSet<QString> multimediaExtensions =
const QString mime = QMimeDatabase().mimeTypeForFile(filename, QMimeDatabase::MatchExtension).name();
if (mime.startsWith(QLatin1String("audio"), Qt::CaseInsensitive)
|| mime.startsWith(QLatin1String("video"), Qt::CaseInsensitive))
{
return true;
}
const QSet<QString> multimediaExtensions =
{
"3GP",
"AAC",
@ -337,7 +347,7 @@ bool Utils::Misc::isPreviewable(const QString &extension) @@ -337,7 +347,7 @@ bool Utils::Misc::isPreviewable(const QString &extension)
"WMA",
"WMV"
};
return multimediaExtensions.contains(extension.toUpper());
return multimediaExtensions.contains(Utils::Fs::fileExtension(filename).toUpper());
}
QString Utils::Misc::userFriendlyDuration(const qlonglong seconds, const qlonglong maxCap)

2
src/base/utils/misc.h

@ -77,7 +77,7 @@ namespace Utils::Misc @@ -77,7 +77,7 @@ namespace Utils::Misc
int friendlyUnitPrecision(SizeUnit unit);
qint64 sizeInBytes(qreal size, SizeUnit unit);
bool isPreviewable(const QString &extension);
bool isPreviewable(const QString &filename);
// Take a number of seconds and return a user-friendly
// time duration like "1d 2h 10m".

5
src/gui/previewselectdialog.cpp

@ -90,9 +90,8 @@ PreviewSelectDialog::PreviewSelectDialog(QWidget *parent, const BitTorrent::Torr @@ -90,9 +90,8 @@ PreviewSelectDialog::PreviewSelectDialog(QWidget *parent, const BitTorrent::Torr
{
QString fileName = torrent->fileName(i);
if (fileName.endsWith(QB_EXT))
fileName.chop(4);
QString extension = Utils::Fs::fileExtension(fileName).toUpper();
if (Utils::Misc::isPreviewable(extension))
fileName.chop(QB_EXT.length());
if (Utils::Misc::isPreviewable(fileName))
{
int row = m_previewListModel->rowCount();
m_previewListModel->insertRow(row);

6
src/gui/transferlistwidget.cpp

@ -44,6 +44,7 @@ @@ -44,6 +44,7 @@
#include <QVector>
#include <QWheelEvent>
#include "base/bittorrent/common.h"
#include "base/bittorrent/infohash.h"
#include "base/bittorrent/session.h"
#include "base/bittorrent/torrent.h"
@ -93,7 +94,10 @@ namespace @@ -93,7 +94,10 @@ namespace
for (int i = 0; i < torrent->filesCount(); ++i)
{
if (Utils::Misc::isPreviewable(Utils::Fs::fileExtension(torrent->fileName(i))))
QString fileName = torrent->fileName(i);
if (fileName.endsWith(QB_EXT))
fileName.chop(QB_EXT.length());
if (Utils::Misc::isPreviewable(fileName))
return true;
}

Loading…
Cancel
Save