mirror of
https://github.com/qbittorrent/qBittorrent.git
synced 2024-11-22 17:26:21 +03:00
Clean up code
* Use compiler generated comparison function * Use designated initializers * Convert to proper type * Use reference * Remove redundant text The `msg` already contain the text `Reason:` so it isn't needed. PR #20312.
This commit is contained in:
parent
bab9c15913
commit
94e80d01a8
7 changed files with 42 additions and 58 deletions
|
@ -34,7 +34,6 @@
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <csignal>
|
#include <csignal>
|
||||||
#include <tuple>
|
|
||||||
|
|
||||||
#ifdef Q_OS_UNIX
|
#ifdef Q_OS_UNIX
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
|
@ -28,8 +28,6 @@
|
||||||
|
|
||||||
#include "addtorrentparams.h"
|
#include "addtorrentparams.h"
|
||||||
|
|
||||||
#include <tuple>
|
|
||||||
|
|
||||||
#include <QJsonArray>
|
#include <QJsonArray>
|
||||||
#include <QJsonObject>
|
#include <QJsonObject>
|
||||||
#include <QJsonValue>
|
#include <QJsonValue>
|
||||||
|
@ -101,51 +99,38 @@ namespace
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool BitTorrent::operator==(const AddTorrentParams &lhs, const AddTorrentParams &rhs)
|
|
||||||
{
|
|
||||||
return std::tie(lhs.name, lhs.category, lhs.tags,
|
|
||||||
lhs.savePath, lhs.useDownloadPath, lhs.downloadPath,
|
|
||||||
lhs.sequential, lhs.firstLastPiecePriority, lhs.addForced,
|
|
||||||
lhs.addToQueueTop, lhs.addPaused, lhs.stopCondition,
|
|
||||||
lhs.filePaths, lhs.filePriorities, lhs.skipChecking,
|
|
||||||
lhs.contentLayout, lhs.useAutoTMM, lhs.uploadLimit,
|
|
||||||
lhs.downloadLimit, lhs.seedingTimeLimit, lhs.inactiveSeedingTimeLimit, lhs.ratioLimit)
|
|
||||||
== std::tie(rhs.name, rhs.category, rhs.tags,
|
|
||||||
rhs.savePath, rhs.useDownloadPath, rhs.downloadPath,
|
|
||||||
rhs.sequential, rhs.firstLastPiecePriority, rhs.addForced,
|
|
||||||
rhs.addToQueueTop, rhs.addPaused, rhs.stopCondition,
|
|
||||||
rhs.filePaths, rhs.filePriorities, rhs.skipChecking,
|
|
||||||
rhs.contentLayout, rhs.useAutoTMM, rhs.uploadLimit,
|
|
||||||
rhs.downloadLimit, rhs.seedingTimeLimit, rhs.inactiveSeedingTimeLimit, rhs.ratioLimit);
|
|
||||||
}
|
|
||||||
|
|
||||||
BitTorrent::AddTorrentParams BitTorrent::parseAddTorrentParams(const QJsonObject &jsonObj)
|
BitTorrent::AddTorrentParams BitTorrent::parseAddTorrentParams(const QJsonObject &jsonObj)
|
||||||
{
|
{
|
||||||
AddTorrentParams params;
|
const AddTorrentParams params
|
||||||
params.category = jsonObj.value(PARAM_CATEGORY).toString();
|
{
|
||||||
params.tags = parseTagSet(jsonObj.value(PARAM_TAGS).toArray());
|
.name = {},
|
||||||
params.savePath = Path(jsonObj.value(PARAM_SAVEPATH).toString());
|
.category = jsonObj.value(PARAM_CATEGORY).toString(),
|
||||||
params.useDownloadPath = getOptionalBool(jsonObj, PARAM_USEDOWNLOADPATH);
|
.tags = parseTagSet(jsonObj.value(PARAM_TAGS).toArray()),
|
||||||
params.downloadPath = Path(jsonObj.value(PARAM_DOWNLOADPATH).toString());
|
.savePath = Path(jsonObj.value(PARAM_SAVEPATH).toString()),
|
||||||
params.addForced = (getEnum<TorrentOperatingMode>(jsonObj, PARAM_OPERATINGMODE) == TorrentOperatingMode::Forced);
|
.useDownloadPath = getOptionalBool(jsonObj, PARAM_USEDOWNLOADPATH),
|
||||||
params.addToQueueTop = getOptionalBool(jsonObj, PARAM_QUEUETOP);
|
.downloadPath = Path(jsonObj.value(PARAM_DOWNLOADPATH).toString()),
|
||||||
params.addPaused = getOptionalBool(jsonObj, PARAM_STOPPED);
|
.addForced = (getEnum<TorrentOperatingMode>(jsonObj, PARAM_OPERATINGMODE) == TorrentOperatingMode::Forced),
|
||||||
params.stopCondition = getOptionalEnum<Torrent::StopCondition>(jsonObj, PARAM_STOPCONDITION);
|
.addToQueueTop = getOptionalBool(jsonObj, PARAM_QUEUETOP),
|
||||||
params.skipChecking = jsonObj.value(PARAM_SKIPCHECKING).toBool();
|
.addPaused = getOptionalBool(jsonObj, PARAM_STOPPED),
|
||||||
params.contentLayout = getOptionalEnum<TorrentContentLayout>(jsonObj, PARAM_CONTENTLAYOUT);
|
.stopCondition = getOptionalEnum<Torrent::StopCondition>(jsonObj, PARAM_STOPCONDITION),
|
||||||
params.useAutoTMM = getOptionalBool(jsonObj, PARAM_AUTOTMM);
|
.filePaths = {},
|
||||||
params.uploadLimit = jsonObj.value(PARAM_UPLOADLIMIT).toInt(-1);
|
.filePriorities = {},
|
||||||
params.downloadLimit = jsonObj.value(PARAM_DOWNLOADLIMIT).toInt(-1);
|
.skipChecking = jsonObj.value(PARAM_SKIPCHECKING).toBool(),
|
||||||
params.seedingTimeLimit = jsonObj.value(PARAM_SEEDINGTIMELIMIT).toInt(Torrent::USE_GLOBAL_SEEDING_TIME);
|
.contentLayout = getOptionalEnum<TorrentContentLayout>(jsonObj, PARAM_CONTENTLAYOUT),
|
||||||
params.inactiveSeedingTimeLimit = jsonObj.value(PARAM_INACTIVESEEDINGTIMELIMIT).toInt(Torrent::USE_GLOBAL_INACTIVE_SEEDING_TIME);
|
.useAutoTMM = getOptionalBool(jsonObj, PARAM_AUTOTMM),
|
||||||
params.ratioLimit = jsonObj.value(PARAM_RATIOLIMIT).toDouble(Torrent::USE_GLOBAL_RATIO);
|
.uploadLimit = jsonObj.value(PARAM_UPLOADLIMIT).toInt(-1),
|
||||||
|
.downloadLimit = jsonObj.value(PARAM_DOWNLOADLIMIT).toInt(-1),
|
||||||
|
.seedingTimeLimit = jsonObj.value(PARAM_SEEDINGTIMELIMIT).toInt(Torrent::USE_GLOBAL_SEEDING_TIME),
|
||||||
|
.inactiveSeedingTimeLimit = jsonObj.value(PARAM_INACTIVESEEDINGTIMELIMIT).toInt(Torrent::USE_GLOBAL_INACTIVE_SEEDING_TIME),
|
||||||
|
.ratioLimit = jsonObj.value(PARAM_RATIOLIMIT).toDouble(Torrent::USE_GLOBAL_RATIO)
|
||||||
|
};
|
||||||
return params;
|
return params;
|
||||||
}
|
}
|
||||||
|
|
||||||
QJsonObject BitTorrent::serializeAddTorrentParams(const AddTorrentParams ¶ms)
|
QJsonObject BitTorrent::serializeAddTorrentParams(const AddTorrentParams ¶ms)
|
||||||
{
|
{
|
||||||
QJsonObject jsonObj {
|
QJsonObject jsonObj
|
||||||
|
{
|
||||||
{PARAM_CATEGORY, params.category},
|
{PARAM_CATEGORY, params.category},
|
||||||
{PARAM_TAGS, serializeTagSet(params.tags)},
|
{PARAM_TAGS, serializeTagSet(params.tags)},
|
||||||
{PARAM_SAVEPATH, params.savePath.data()},
|
{PARAM_SAVEPATH, params.savePath.data()},
|
||||||
|
|
|
@ -69,9 +69,9 @@ namespace BitTorrent
|
||||||
int seedingTimeLimit = Torrent::USE_GLOBAL_SEEDING_TIME;
|
int seedingTimeLimit = Torrent::USE_GLOBAL_SEEDING_TIME;
|
||||||
int inactiveSeedingTimeLimit = Torrent::USE_GLOBAL_INACTIVE_SEEDING_TIME;
|
int inactiveSeedingTimeLimit = Torrent::USE_GLOBAL_INACTIVE_SEEDING_TIME;
|
||||||
qreal ratioLimit = Torrent::USE_GLOBAL_RATIO;
|
qreal ratioLimit = Torrent::USE_GLOBAL_RATIO;
|
||||||
};
|
|
||||||
|
|
||||||
bool operator==(const AddTorrentParams &lhs, const AddTorrentParams &rhs);
|
friend bool operator==(const AddTorrentParams &lhs, const AddTorrentParams &rhs) = default;
|
||||||
|
};
|
||||||
|
|
||||||
AddTorrentParams parseAddTorrentParams(const QJsonObject &jsonObj);
|
AddTorrentParams parseAddTorrentParams(const QJsonObject &jsonObj);
|
||||||
QJsonObject serializeAddTorrentParams(const AddTorrentParams ¶ms);
|
QJsonObject serializeAddTorrentParams(const AddTorrentParams ¶ms);
|
||||||
|
|
|
@ -76,7 +76,7 @@ namespace
|
||||||
template <typename LTStr>
|
template <typename LTStr>
|
||||||
QString fromLTString(const LTStr &str)
|
QString fromLTString(const LTStr &str)
|
||||||
{
|
{
|
||||||
return QString::fromUtf8(str.data(), static_cast<int>(str.size()));
|
return QString::fromUtf8(str.data(), static_cast<qsizetype>(str.size()));
|
||||||
}
|
}
|
||||||
|
|
||||||
using ListType = lt::entry::list_type;
|
using ListType = lt::entry::list_type;
|
||||||
|
|
|
@ -148,7 +148,7 @@ namespace
|
||||||
template <typename LTStr>
|
template <typename LTStr>
|
||||||
QString fromLTString(const LTStr &str)
|
QString fromLTString(const LTStr &str)
|
||||||
{
|
{
|
||||||
return QString::fromUtf8(str.data(), static_cast<int>(str.size()));
|
return QString::fromUtf8(str.data(), static_cast<qsizetype>(str.size()));
|
||||||
}
|
}
|
||||||
|
|
||||||
QString quoted(const QString &name)
|
QString quoted(const QString &name)
|
||||||
|
|
|
@ -227,20 +227,20 @@ void TorrentCreatorDialog::onCreateButtonClicked()
|
||||||
.replace(QRegularExpression(u"\n\n[\n]+"_s), u"\n\n"_s).split(u'\n');
|
.replace(QRegularExpression(u"\n\n[\n]+"_s), u"\n\n"_s).split(u'\n');
|
||||||
const BitTorrent::TorrentCreatorParams params
|
const BitTorrent::TorrentCreatorParams params
|
||||||
{
|
{
|
||||||
m_ui->checkPrivate->isChecked()
|
.isPrivate = m_ui->checkPrivate->isChecked(),
|
||||||
#ifdef QBT_USES_LIBTORRENT2
|
#ifdef QBT_USES_LIBTORRENT2
|
||||||
, getTorrentFormat()
|
.torrentFormat = getTorrentFormat(),
|
||||||
#else
|
#else
|
||||||
, m_ui->checkOptimizeAlignment->isChecked()
|
.isAlignmentOptimized = m_ui->checkOptimizeAlignment->isChecked(),
|
||||||
, getPaddedFileSizeLimit()
|
.paddedFileSizeLimit = getPaddedFileSizeLimit(),
|
||||||
#endif
|
#endif
|
||||||
, getPieceSize()
|
.pieceSize = getPieceSize(),
|
||||||
, inputPath
|
.inputPath = inputPath,
|
||||||
, destPath
|
.savePath = destPath,
|
||||||
, m_ui->txtComment->toPlainText()
|
.comment = m_ui->txtComment->toPlainText(),
|
||||||
, m_ui->lineEditSource->text()
|
.source = m_ui->lineEditSource->text(),
|
||||||
, trackers
|
.trackers = trackers,
|
||||||
, m_ui->URLSeedsList->toPlainText().split(u'\n', Qt::SkipEmptyParts)
|
.urlSeeds = m_ui->URLSeedsList->toPlainText().split(u'\n', Qt::SkipEmptyParts)
|
||||||
};
|
};
|
||||||
|
|
||||||
auto *torrentCreator = new BitTorrent::TorrentCreator(params);
|
auto *torrentCreator = new BitTorrent::TorrentCreator(params);
|
||||||
|
@ -257,7 +257,7 @@ void TorrentCreatorDialog::handleCreationFailure(const QString &msg)
|
||||||
{
|
{
|
||||||
// Remove busy cursor
|
// Remove busy cursor
|
||||||
setCursor(QCursor(Qt::ArrowCursor));
|
setCursor(QCursor(Qt::ArrowCursor));
|
||||||
QMessageBox::information(this, tr("Torrent creation failed"), tr("Reason: %1").arg(msg));
|
QMessageBox::information(this, tr("Torrent creation failed"), msg);
|
||||||
setInteractionEnabled(true);
|
setInteractionEnabled(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -754,7 +754,7 @@ void TorrentsController::addAction()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const DataMap torrents = data();
|
const DataMap &torrents = data();
|
||||||
for (auto it = torrents.constBegin(); it != torrents.constEnd(); ++it)
|
for (auto it = torrents.constBegin(); it != torrents.constEnd(); ++it)
|
||||||
{
|
{
|
||||||
if (const auto loadResult = BitTorrent::TorrentDescriptor::load(it.value()))
|
if (const auto loadResult = BitTorrent::TorrentDescriptor::load(it.value()))
|
||||||
|
|
Loading…
Reference in a new issue