Browse Source

Merge pull request #17858 from Chocobo1/infohash

Show N/A when there is no hash
adaptive-webui-19844
Chocobo1 2 years ago committed by GitHub
parent
commit
f66ec4430d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      .github/workflows/coverity-scan.yml
  2. 8
      src/gui/downloadfromurldialog.cpp
  3. 15
      src/gui/transferlistmodel.cpp

2
.github/workflows/coverity-scan.yml

@ -25,7 +25,7 @@ jobs:
uses: jurplel/install-qt-action@v3 uses: jurplel/install-qt-action@v3
with: with:
version: "6.4.0" version: "6.4.0"
archives: qtbase qtsvg qttools archives: icu qtbase qtsvg qttools
- name: Install libtorrent - name: Install libtorrent
run: | run: |

8
src/gui/downloadfromurldialog.cpp

@ -38,6 +38,7 @@
#include <QStringList> #include <QStringList>
#include <QStringView> #include <QStringView>
#include "base/net/downloadmanager.h"
#include "ui_downloadfromurldialog.h" #include "ui_downloadfromurldialog.h"
#include "utils.h" #include "utils.h"
@ -47,16 +48,13 @@ namespace
{ {
bool isDownloadable(const QString &str) bool isDownloadable(const QString &str)
{ {
return (str.startsWith(u"http://", Qt::CaseInsensitive) return (Net::DownloadManager::hasSupportedScheme(str)
|| str.startsWith(u"https://", Qt::CaseInsensitive)
|| str.startsWith(u"ftp://", Qt::CaseInsensitive)
|| str.startsWith(u"magnet:", Qt::CaseInsensitive) || str.startsWith(u"magnet:", Qt::CaseInsensitive)
|| ((str.size() == 40) && !str.contains(QRegularExpression(u"[^0-9A-Fa-f]"_qs))) // v1 hex-encoded SHA-1 info-hash
#ifdef QBT_USES_LIBTORRENT2 #ifdef QBT_USES_LIBTORRENT2
|| ((str.size() == 64) && !str.contains(QRegularExpression(u"[^0-9A-Fa-f]"_qs))) // v2 hex-encoded SHA-256 info-hash || ((str.size() == 64) && !str.contains(QRegularExpression(u"[^0-9A-Fa-f]"_qs))) // v2 hex-encoded SHA-256 info-hash
#endif #endif
|| ((str.size() == 40) && !str.contains(QRegularExpression(u"[^0-9A-Fa-f]"_qs))) // v1 hex-encoded SHA-1 info-hash
|| ((str.size() == 32) && !str.contains(QRegularExpression(u"[^2-7A-Za-z]"_qs)))); // v1 Base32 encoded SHA-1 info-hash || ((str.size() == 32) && !str.contains(QRegularExpression(u"[^2-7A-Za-z]"_qs)))); // v1 Base32 encoded SHA-1 info-hash
} }
} }

15
src/gui/transferlistmodel.cpp

@ -224,7 +224,7 @@ QVariant TransferListModel::headerData(const int section, const Qt::Orientation
case TR_AMOUNT_UPLOADED_SESSION: return tr("Session Upload", "Amount of data uploaded since program open (e.g. in MB)"); case TR_AMOUNT_UPLOADED_SESSION: return tr("Session Upload", "Amount of data uploaded since program open (e.g. in MB)");
case TR_AMOUNT_LEFT: return tr("Remaining", "Amount of data left to download (e.g. in MB)"); case TR_AMOUNT_LEFT: return tr("Remaining", "Amount of data left to download (e.g. in MB)");
case TR_TIME_ELAPSED: return tr("Time Active", "Time (duration) the torrent is active (not paused)"); case TR_TIME_ELAPSED: return tr("Time Active", "Time (duration) the torrent is active (not paused)");
case TR_SAVE_PATH: return tr("Save path", "Torrent save path"); case TR_SAVE_PATH: return tr("Save Path", "Torrent save path");
case TR_DOWNLOAD_PATH: return tr("Incomplete Save Path", "Torrent incomplete save path"); case TR_DOWNLOAD_PATH: return tr("Incomplete Save Path", "Torrent incomplete save path");
case TR_COMPLETED: return tr("Completed", "Amount of data completed (e.g. in MB)"); case TR_COMPLETED: return tr("Completed", "Amount of data completed (e.g. in MB)");
case TR_RATIO_LIMIT: return tr("Ratio Limit", "Upload share ratio limit"); case TR_RATIO_LIMIT: return tr("Ratio Limit", "Upload share ratio limit");
@ -374,6 +374,13 @@ QString TransferListModel::displayValue(const BitTorrent::Torrent *torrent, cons
: m_statusStrings[state]; : m_statusStrings[state];
}; };
const auto hashString = [hideValues](const auto &hash) -> QString
{
if (hideValues && !hash.isValid())
return {};
return hash.isValid() ? hash.toString() : tr("N/A");
};
switch (column) switch (column)
{ {
case TR_NAME: case TR_NAME:
@ -441,9 +448,9 @@ QString TransferListModel::displayValue(const BitTorrent::Torrent *torrent, cons
case TR_TOTAL_SIZE: case TR_TOTAL_SIZE:
return unitString(torrent->totalSize()); return unitString(torrent->totalSize());
case TR_INFOHASH_V1: case TR_INFOHASH_V1:
return torrent->infoHash().v1().toString(); return hashString(torrent->infoHash().v1());
case TR_INFOHASH_V2: case TR_INFOHASH_V2:
return torrent->infoHash().v2().toString(); return hashString(torrent->infoHash().v2());
} }
return {}; return {};
@ -504,7 +511,7 @@ QVariant TransferListModel::internalValue(const BitTorrent::Torrent *torrent, co
case TR_DOWNLOAD_PATH: case TR_DOWNLOAD_PATH:
return torrent->downloadPath().data(); return torrent->downloadPath().data();
case TR_SAVE_PATH: case TR_SAVE_PATH:
return torrent->savePath().toString(); return torrent->savePath().data();
case TR_COMPLETED: case TR_COMPLETED:
return torrent->completedSize(); return torrent->completedSize();
case TR_RATIO_LIMIT: case TR_RATIO_LIMIT:

Loading…
Cancel
Save