Merge pull request #14801 from Chocobo1/backport

Backport PRs to v4_3_x
This commit is contained in:
Chocobo1 2021-04-18 12:42:15 +08:00 committed by GitHub
commit 2c8f322af5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 40 additions and 12 deletions

View file

@ -300,7 +300,7 @@ QUrl DNSUpdater::getRegistrationUrl(const int service)
switch (service)
{
case DNS::DYNDNS:
return {"https://www.dyndns.com/account/services/hosts/add.html"};
return {"https://account.dyn.com/entrance/"};
case DNS::NOIP:
return {"https://www.noip.com/remote-access"};
default:

View file

@ -1663,8 +1663,7 @@ void MainWindow::showNotificationBaloon(const QString &title, const QString &msg
// some inactivity shuts it down. Other DEs, like GNOME, choose
// to start their daemons at the session startup and have it sit
// idling for the whole session.
QVariantMap hints;
hints["desktop-entry"] = "qBittorrent";
const QVariantMap hints {{QLatin1String("desktop-entry"), QLatin1String("org.qbittorrent.qBittorrent")}};
QDBusPendingReply<uint> reply = notifications.Notify("qBittorrent", 0, "qbittorrent", title,
msg, QStringList(), hints, -1);
reply.waitForFinished();

View file

@ -106,6 +106,7 @@ const char KEY_PROP_SAVE_PATH[] = "save_path";
const char KEY_PROP_COMMENT[] = "comment";
// File keys
const char KEY_FILE_INDEX[] = "index";
const char KEY_FILE_NAME[] = "name";
const char KEY_FILE_SIZE[] = "size";
const char KEY_FILE_PROGRESS[] = "progress";
@ -501,6 +502,7 @@ void TorrentsController::webseedsAction()
// Returns the files in a torrent in JSON format.
// The return value is a JSON-formatted list of dictionaries.
// The dictionary keys are:
// - "index": File index
// - "name": File name
// - "size": File size
// - "progress": File progress
@ -517,6 +519,32 @@ void TorrentsController::filesAction()
if (!torrent)
throw APIError(APIErrorType::NotFound);
const int filesCount = torrent->filesCount();
QVector<int> fileIndexes;
const auto idxIt = params().constFind(QLatin1String("indexes"));
if (idxIt != params().cend())
{
const QStringList indexStrings = idxIt.value().split('|');
fileIndexes.reserve(indexStrings.size());
std::transform(indexStrings.cbegin(), indexStrings.cend(), std::back_inserter(fileIndexes)
, [&filesCount](const QString &indexString) -> int
{
bool ok = false;
const int index = indexString.toInt(&ok);
if (!ok || (index < 0))
throw APIError(APIErrorType::Conflict, tr("\"%1\" is not a valid file index.").arg(indexString));
if (index >= filesCount)
throw APIError(APIErrorType::Conflict, tr("Index %1 is out of bounds.").arg(indexString));
return index;
});
}
else
{
fileIndexes.reserve(filesCount);
for (int i = 0; i < filesCount; ++i)
fileIndexes.append(i);
}
QJsonArray fileList;
if (torrent->hasMetadata())
{
@ -524,25 +552,26 @@ void TorrentsController::filesAction()
const QVector<qreal> fp = torrent->filesProgress();
const QVector<qreal> fileAvailability = torrent->availableFileFractions();
const BitTorrent::TorrentInfo info = torrent->info();
for (int i = 0; i < torrent->filesCount(); ++i)
for (const int index : asConst(fileIndexes))
{
QJsonObject fileDict =
{
{KEY_FILE_PROGRESS, fp[i]},
{KEY_FILE_PRIORITY, static_cast<int>(priorities[i])},
{KEY_FILE_SIZE, torrent->fileSize(i)},
{KEY_FILE_AVAILABILITY, fileAvailability[i]}
{KEY_FILE_INDEX, index},
{KEY_FILE_PROGRESS, fp[index]},
{KEY_FILE_PRIORITY, static_cast<int>(priorities[index])},
{KEY_FILE_SIZE, torrent->fileSize(index)},
{KEY_FILE_AVAILABILITY, fileAvailability[index]}
};
QString fileName = torrent->filePath(i);
QString fileName = torrent->filePath(index);
if (fileName.endsWith(QB_EXT, Qt::CaseInsensitive))
fileName.chop(QB_EXT.size());
fileDict[KEY_FILE_NAME] = Utils::Fs::toUniformPath(fileName);
const BitTorrent::TorrentInfo::PieceRange idx = info.filePieces(i);
const BitTorrent::TorrentInfo::PieceRange idx = info.filePieces(index);
fileDict[KEY_FILE_PIECE_RANGE] = QJsonArray {idx.first(), idx.last()};
if (i == 0)
if (index == 0)
fileDict[KEY_FILE_IS_SEED] = torrent->isSeed();
fileList.append(fileDict);

View file

@ -43,7 +43,7 @@
#include "base/utils/net.h"
#include "base/utils/version.h"
constexpr Utils::Version<int, 3, 2> API_VERSION {2, 8, 1};
constexpr Utils::Version<int, 3, 2> API_VERSION {2, 8, 2};
class APIController;
class WebApplication;