Improve coding style

This commit is contained in:
Vladimir Golovnev (Glassez)
2020-11-16 10:02:11 +03:00
parent acad35c5bc
commit c41df9ffbd
147 changed files with 4454 additions and 2227 deletions

View File

@@ -59,7 +59,8 @@ QVector<float> DownloadedPiecesBar::bitfieldToFloatVector(const QBitArray &vecin
// image.x(0) = pieces.x(0.0 >= x < 1.7)
// image.x(1) = pieces.x(1.7 >= x < 3.4)
for (int x = 0; x < reqSize; ++x) {
for (int x = 0; x < reqSize; ++x)
{
// R - real
const float fromR = x * ratio;
const float toR = (x + 1) * ratio;
@@ -80,15 +81,18 @@ QVector<float> DownloadedPiecesBar::bitfieldToFloatVector(const QBitArray &vecin
float value = 0;
// case when calculated range is (15.2 >= x < 15.7)
if (x2 == toCMinusOne) {
if (x2 == toCMinusOne)
{
if (vecin[x2])
value += ratio;
++x2;
}
// case when (15.2 >= x < 17.8)
else {
else
{
// subcase (15.2 >= x < 16)
if (x2 != fromR) {
if (x2 != fromR)
{
if (vecin[x2])
value += 1.0 - (fromR - fromC);
++x2;
@@ -100,7 +104,8 @@ QVector<float> DownloadedPiecesBar::bitfieldToFloatVector(const QBitArray &vecin
value += 1.0;
// subcase (17 >= x < 17.8)
if (x2 == toCMinusOne) {
if (x2 == toCMinusOne)
{
if (vecin[x2])
value += 1.0 - (toC - toR);
++x2;
@@ -123,12 +128,14 @@ bool DownloadedPiecesBar::updateImage(QImage &image)
{
// qDebug() << "updateImage";
QImage image2(width() - 2 * borderWidth, 1, QImage::Format_RGB888);
if (image2.isNull()) {
if (image2.isNull())
{
qDebug() << "QImage image2() allocation failed, width():" << width();
return false;
}
if (m_pieces.isEmpty()) {
if (m_pieces.isEmpty())
{
image2.fill(backgroundColor());
image = image2;
return true;
@@ -138,10 +145,12 @@ bool DownloadedPiecesBar::updateImage(QImage &image)
QVector<float> scaledPiecesDl = bitfieldToFloatVector(m_downloadedPieces, image2.width());
// filling image
for (int x = 0; x < scaledPieces.size(); ++x) {
for (int x = 0; x < scaledPieces.size(); ++x)
{
float piecesToValue = scaledPieces.at(x);
float piecesToValueDl = scaledPiecesDl.at(x);
if (piecesToValueDl != 0) {
if (piecesToValueDl != 0)
{
float fillRatio = piecesToValue + piecesToValueDl;
float ratio = piecesToValueDl / fillRatio;
@@ -150,7 +159,8 @@ bool DownloadedPiecesBar::updateImage(QImage &image)
image2.setPixel(x, 0, mixedColor);
}
else {
else
{
image2.setPixel(x, 0, pieceColors()[piecesToValue * 255]);
}
}

View File

@@ -39,9 +39,11 @@ PeerListSortModel::PeerListSortModel(QObject *parent)
bool PeerListSortModel::lessThan(const QModelIndex &left, const QModelIndex &right) const
{
switch (sortColumn()) {
switch (sortColumn())
{
case PeerListWidget::IP:
case PeerListWidget::CLIENT: {
case PeerListWidget::CLIENT:
{
const QString strL = left.data(UnderlyingDataRole).toString();
const QString strR = right.data(UnderlyingDataRole).toString();
const int result = Utils::String::naturalCompare(strL, strR, Qt::CaseInsensitive);

View File

@@ -126,8 +126,10 @@ PeerListWidget::PeerListWidget(PropertiesWidget *parent)
hideColumn(PeerListColumns::COUNTRY);
// Ensure that at least one column is visible at all times
bool atLeastOne = false;
for (int i = 0; i < PeerListColumns::IP_HIDDEN; ++i) {
if (!isColumnHidden(i)) {
for (int i = 0; i < PeerListColumns::IP_HIDDEN; ++i)
{
if (!isColumnHidden(i))
{
atLeastOne = true;
break;
}
@@ -137,7 +139,8 @@ PeerListWidget::PeerListWidget(PropertiesWidget *parent)
// To also mitigate the above issue, we have to resize each column when
// its size is 0, because explicitly 'showing' the column isn't enough
// in the above scenario.
for (int i = 0; i < PeerListColumns::IP_HIDDEN; ++i) {
for (int i = 0; i < PeerListColumns::IP_HIDDEN; ++i)
{
if ((columnWidth(i) <= 0) && !isColumnHidden(i))
resizeColumnToContents(i);
}
@@ -178,7 +181,8 @@ void PeerListWidget::displayToggleColumnsMenu(const QPoint &)
menu->setAttribute(Qt::WA_DeleteOnClose);
menu->setTitle(tr("Column visibility"));
for (int i = 0; i < PeerListColumns::IP_HIDDEN; ++i) {
for (int i = 0; i < PeerListColumns::IP_HIDDEN; ++i)
{
if ((i == PeerListColumns::COUNTRY) && !Preferences::instance()->resolvePeerCountries())
continue;
@@ -191,7 +195,8 @@ void PeerListWidget::displayToggleColumnsMenu(const QPoint &)
connect(menu, &QMenu::triggered, this, [this](const QAction *action)
{
int visibleCols = 0;
for (int i = 0; i < PeerListColumns::IP_HIDDEN; ++i) {
for (int i = 0; i < PeerListColumns::IP_HIDDEN; ++i)
{
if (!isColumnHidden(i))
++visibleCols;
@@ -217,14 +222,17 @@ void PeerListWidget::displayToggleColumnsMenu(const QPoint &)
void PeerListWidget::updatePeerHostNameResolutionState()
{
if (Preferences::instance()->resolvePeerHostNames()) {
if (!m_resolver) {
if (Preferences::instance()->resolvePeerHostNames())
{
if (!m_resolver)
{
m_resolver = new Net::ReverseResolution(this);
connect(m_resolver, &Net::ReverseResolution::ipResolved, this, &PeerListWidget::handleResolved);
loadPeers(m_properties->getCurrentTorrent());
}
}
else {
else
{
delete m_resolver;
m_resolver = nullptr;
}
@@ -237,13 +245,15 @@ void PeerListWidget::updatePeerCountryResolutionState()
return;
m_resolveCountries = resolveCountries;
if (m_resolveCountries) {
if (m_resolveCountries)
{
loadPeers(m_properties->getCurrentTorrent());
showColumn(PeerListColumns::COUNTRY);
if (columnWidth(PeerListColumns::COUNTRY) <= 0)
resizeColumnToContents(PeerListColumns::COUNTRY);
}
else {
else
{
hideColumn(PeerListColumns::COUNTRY);
}
}
@@ -258,7 +268,8 @@ void PeerListWidget::showPeerListMenu(const QPoint &)
// Add Peer Action
// Do not allow user to add peers in a private torrent
if (!torrent->isQueued() && !torrent->isChecking() && !torrent->isPrivate()) {
if (!torrent->isQueued() && !torrent->isChecking() && !torrent->isPrivate())
{
const QAction *addPeerAct = menu->addAction(UIThemeManager::instance()->getIcon("user-group-new"), tr("Add a new peer..."));
connect(addPeerAct, &QAction::triggered, this, [this, torrent]()
{
@@ -274,7 +285,8 @@ void PeerListWidget::showPeerListMenu(const QPoint &)
});
}
if (!selectionModel()->selectedRows().isEmpty()) {
if (!selectionModel()->selectedRows().isEmpty())
{
const QAction *copyPeerAct = menu->addAction(UIThemeManager::instance()->getIcon("edit-copy"), tr("Copy IP:port"));
connect(copyPeerAct, &QAction::triggered, this, &PeerListWidget::copySelectedPeers);
@@ -298,7 +310,8 @@ void PeerListWidget::banSelectedPeers()
QVector<QString> selectedIPs;
selectedIPs.reserve(selectedIndexes.size());
for (const QModelIndex &index : selectedIndexes) {
for (const QModelIndex &index : selectedIndexes)
{
const int row = m_proxyModel->mapToSource(index).row();
const QString ip = m_listModel->item(row, PeerListColumns::IP_HIDDEN)->text();
selectedIPs += ip;
@@ -309,7 +322,8 @@ void PeerListWidget::banSelectedPeers()
, tr("Are you sure you want to permanently ban the selected peers?"));
if (btn != QMessageBox::Yes) return;
for (const QString &ip : selectedIPs) {
for (const QString &ip : selectedIPs)
{
BitTorrent::Session::instance()->banIP(ip);
LogMsg(tr("Peer \"%1\" is manually banned").arg(ip));
}
@@ -322,7 +336,8 @@ void PeerListWidget::copySelectedPeers()
const QModelIndexList selectedIndexes = selectionModel()->selectedRows();
QStringList selectedPeers;
for (const QModelIndex &index : selectedIndexes) {
for (const QModelIndex &index : selectedIndexes)
{
const int row = m_proxyModel->mapToSource(index).row();
const QString ip = m_listModel->item(row, PeerListColumns::IP_HIDDEN)->text();
const QString port = m_listModel->item(row, PeerListColumns::PORT)->text();
@@ -364,19 +379,22 @@ void PeerListWidget::loadPeers(const BitTorrent::TorrentHandle *torrent)
for (auto i = m_peerItems.cbegin(); i != m_peerItems.cend(); ++i)
existingPeers << i.key();
for (const BitTorrent::PeerInfo &peer : peers) {
for (const BitTorrent::PeerInfo &peer : peers)
{
if (peer.address().ip.isNull()) continue;
bool isNewPeer = false;
updatePeer(torrent, peer, isNewPeer);
if (!isNewPeer) {
if (!isNewPeer)
{
const PeerEndpoint peerEndpoint {peer.address(), peer.connectionType()};
existingPeers.remove(peerEndpoint);
}
}
// Remove peers that are gone
for (const PeerEndpoint &peerEndpoint : asConst(existingPeers)) {
for (const PeerEndpoint &peerEndpoint : asConst(existingPeers))
{
QStandardItem *item = m_peerItems.take(peerEndpoint);
QSet<QStandardItem *> &items = m_itemsByIP[peerEndpoint.address.ip];
@@ -411,7 +429,8 @@ void PeerListWidget::updatePeer(const BitTorrent::TorrentHandle *torrent, const
auto itemIter = m_peerItems.find(peerEndpoint);
isNewPeer = (itemIter == m_peerItems.end());
if (isNewPeer) {
if (isNewPeer)
{
// new item
const int row = m_listModel->rowCount();
m_listModel->insertRow(row);
@@ -449,9 +468,11 @@ void PeerListWidget::updatePeer(const BitTorrent::TorrentHandle *torrent, const
if (m_resolver)
m_resolver->resolve(peerEndpoint.address.ip);
if (m_resolveCountries) {
if (m_resolveCountries)
{
const QIcon icon = UIThemeManager::instance()->getFlagIcon(peer.country());
if (!icon.isNull()) {
if (!icon.isNull())
{
m_listModel->setData(m_listModel->index(row, PeerListColumns::COUNTRY), icon, Qt::DecorationRole);
const QString countryName = Net::GeoIPManager::CountryName(peer.country());
m_listModel->setData(m_listModel->index(row, PeerListColumns::COUNTRY), countryName, Qt::ToolTipRole);
@@ -479,7 +500,8 @@ void PeerListWidget::handleSortColumnChanged(const int col)
void PeerListWidget::wheelEvent(QWheelEvent *event)
{
if (event->modifiers() & Qt::ShiftModifier) {
if (event->modifiers() & Qt::ShiftModifier)
{
// Shift + scroll = horizontal scroll
event->accept();

View File

@@ -57,18 +57,22 @@ QVector<BitTorrent::PeerAddress> PeersAdditionDialog::askForPeers(QWidget *paren
void PeersAdditionDialog::validateInput()
{
if (m_ui->textEditPeers->toPlainText().trimmed().isEmpty()) {
if (m_ui->textEditPeers->toPlainText().trimmed().isEmpty())
{
QMessageBox::warning(this, tr("No peer entered"),
tr("Please type at least one peer."),
QMessageBox::Ok);
return;
}
for (const QString &peer : asConst(m_ui->textEditPeers->toPlainText().trimmed().split('\n'))) {
for (const QString &peer : asConst(m_ui->textEditPeers->toPlainText().trimmed().split('\n')))
{
const BitTorrent::PeerAddress addr = BitTorrent::PeerAddress::parse(peer);
if (!addr.ip.isNull()) {
if (!addr.ip.isNull())
{
m_peersList.append(addr);
}
else {
else
{
QMessageBox::warning(this, tr("Invalid peer"),
tr("The peer '%1' is invalid.").arg(peer),
QMessageBox::Ok);

View File

@@ -58,7 +58,8 @@ QVector<float> PieceAvailabilityBar::intToFloatVector(const QVector<int> &vecin,
// image.x(0) = pieces.x(0.0 >= x < 1.7)
// image.x(1) = pieces.x(1.7 >= x < 3.4)
for (int x = 0; x < reqSize; ++x) {
for (int x = 0; x < reqSize; ++x)
{
// R - real
const float fromR = x * ratio;
const float toR = (x + 1) * ratio;
@@ -79,15 +80,18 @@ QVector<float> PieceAvailabilityBar::intToFloatVector(const QVector<int> &vecin,
float value = 0;
// case when calculated range is (15.2 >= x < 15.7)
if (x2 == toCMinusOne) {
if (x2 == toCMinusOne)
{
if (vecin[x2])
value += ratio * vecin[x2];
++x2;
}
// case when (15.2 >= x < 17.8)
else {
else
{
// subcase (15.2 >= x < 16)
if (x2 != fromR) {
if (x2 != fromR)
{
if (vecin[x2])
value += (1.0 - (fromR - fromC)) * vecin[x2];
++x2;
@@ -99,7 +103,8 @@ QVector<float> PieceAvailabilityBar::intToFloatVector(const QVector<int> &vecin,
value += vecin[x2];
// subcase (17 >= x < 17.8)
if (x2 == toCMinusOne) {
if (x2 == toCMinusOne)
{
if (vecin[x2])
value += (1.0 - (toC - toR)) * vecin[x2];
++x2;
@@ -121,12 +126,14 @@ QVector<float> PieceAvailabilityBar::intToFloatVector(const QVector<int> &vecin,
bool PieceAvailabilityBar::updateImage(QImage &image)
{
QImage image2(width() - 2 * borderWidth, 1, QImage::Format_RGB888);
if (image2.isNull()) {
if (image2.isNull())
{
qDebug() << "QImage image2() allocation failed, width():" << width();
return false;
}
if (m_pieces.empty()) {
if (m_pieces.empty())
{
image2.fill(backgroundColor());
image = image2;
return true;
@@ -135,7 +142,8 @@ bool PieceAvailabilityBar::updateImage(QImage &image)
QVector<float> scaledPieces = intToFloatVector(m_pieces, image2.width());
// filling image
for (int x = 0; x < scaledPieces.size(); ++x) {
for (int x = 0; x < scaledPieces.size(); ++x)
{
float piecesToValue = scaledPieces.at(x);
image2.setPixel(x, 0, pieceColors()[piecesToValue * 255]);
}

View File

@@ -53,7 +53,8 @@ namespace
{
public:
PieceIndexToImagePos(const BitTorrent::TorrentInfo &torrentInfo, const QImage &image)
: m_bytesPerPixel {((image.width() > 0) && (torrentInfo.totalSize() >= image.width()))
: m_bytesPerPixel
{((image.width() > 0) && (torrentInfo.totalSize() >= image.width()))
? torrentInfo.totalSize() / image.width() : -1}
, m_torrentInfo {torrentInfo}
{
@@ -133,7 +134,8 @@ void PiecesBar::clear()
bool PiecesBar::event(QEvent *e)
{
if (e->type() == QEvent::ToolTip) {
if (e->type() == QEvent::ToolTip)
{
showToolTip(static_cast<QHelpEvent *>(e));
return true;
}
@@ -167,17 +169,20 @@ void PiecesBar::paintEvent(QPaintEvent *)
{
QPainter painter(this);
QRect imageRect(borderWidth, borderWidth, width() - 2 * borderWidth, height() - 2 * borderWidth);
if (m_image.isNull()) {
if (m_image.isNull())
{
painter.setBrush(backgroundColor());
painter.drawRect(imageRect);
}
else {
else
{
if (m_image.width() != imageRect.width())
updateImage(m_image);
painter.drawImage(imageRect, m_image);
}
if (!m_highlitedRegion.isNull()) {
if (!m_highlitedRegion.isNull())
{
QColor highlightColor {this->palette().color(QPalette::Active, QPalette::Highlight)};
highlightColor.setAlphaF(0.35);
QRect targetHighlightRect {m_highlitedRegion.adjusted(borderWidth, borderWidth, borderWidth, height() - 2 * borderWidth)};
@@ -247,19 +252,23 @@ void PiecesBar::showToolTip(const QHelpEvent *e)
QString toolTipText;
QTextStream stream(&toolTipText, QIODevice::WriteOnly);
const bool showDetailedInformation = QApplication::keyboardModifiers().testFlag(Qt::ShiftModifier);
if (showDetailedInformation && m_torrent->hasMetadata()) {
if (showDetailedInformation && m_torrent->hasMetadata())
{
const int imagePos = e->pos().x() - borderWidth;
if ((imagePos >=0) && (imagePos < m_image.width())) {
if ((imagePos >=0) && (imagePos < m_image.width()))
{
stream << "<html><body>";
PieceIndexToImagePos transform {m_torrent->info(), m_image};
int pieceIndex = transform.pieceIndex(imagePos);
const QVector<int> files {m_torrent->info().fileIndicesForPiece(pieceIndex)};
QString tooltipTitle;
if (files.count() > 1) {
if (files.count() > 1)
{
tooltipTitle = tr("Files in this piece:");
}
else {
else
{
if (m_torrent->info().fileSize(files.front()) == m_torrent->info().pieceLength(pieceIndex))
tooltipTitle = tr("File in this piece");
else
@@ -268,14 +277,16 @@ void PiecesBar::showToolTip(const QHelpEvent *e)
DetailedTooltipRenderer renderer(stream, tooltipTitle);
for (int f : files) {
for (int f : files)
{
const QString filePath {m_torrent->info().filePath(f)};
renderer(Utils::Misc::friendlyUnit(m_torrent->info().fileSize(f)), filePath);
}
stream << "</body></html>";
}
}
else {
else
{
stream << simpleToolTipText();
if (showDetailedInformation) // metadata are not available at this point
stream << '\n' << tr("Wait until metadata become available to see detailed information");
@@ -297,17 +308,20 @@ void PiecesBar::highlightFile(int imagePos)
int pieceIndex = transform.pieceIndex(imagePos);
QVector<int> fileIndices {m_torrent->info().fileIndicesForPiece(pieceIndex)};
if (fileIndices.count() == 1) {
if (fileIndices.count() == 1)
{
BitTorrent::TorrentInfo::PieceRange filePieces = m_torrent->info().filePieces(fileIndices.first());
ImageRange imageRange = transform.imagePos(filePieces);
QRect newHighlitedRegion {imageRange.first(), 0, imageRange.size(), m_image.height()};
if (newHighlitedRegion != m_highlitedRegion) {
if (newHighlitedRegion != m_highlitedRegion)
{
m_highlitedRegion = newHighlitedRegion;
update();
}
}
else if (!m_highlitedRegion.isEmpty()) {
else if (!m_highlitedRegion.isEmpty())
{
m_highlitedRegion = QRect();
update();
}
@@ -316,7 +330,8 @@ void PiecesBar::highlightFile(int imagePos)
void PiecesBar::updatePieceColors()
{
m_pieceColors = QVector<QRgb>(256);
for (int i = 0; i < 256; ++i) {
for (int i = 0; i < 256; ++i)
{
float ratio = (i / 255.0);
m_pieceColors[i] = mixTwoColors(backgroundColor().rgb(), pieceColor().rgb(), ratio);
}

View File

@@ -194,7 +194,8 @@ void PropertiesWidget::showPiecesDownloaded(bool show)
void PropertiesWidget::setVisibility(const bool visible)
{
if (!visible && (m_state == VISIBLE)) {
if (!visible && (m_state == VISIBLE))
{
const int tabBarHeight = m_tabBar->geometry().height(); // take height before hiding
auto *hSplitter = static_cast<QSplitter *>(parentWidget());
m_ui->stackedProperties->setVisible(false);
@@ -210,7 +211,8 @@ void PropertiesWidget::setVisibility(const bool visible)
return;
}
if (visible && (m_state == REDUCED)) {
if (visible && (m_state == REDUCED))
{
m_ui->stackedProperties->setVisible(true);
auto *hSplitter = static_cast<QSplitter *>(parentWidget());
if (m_handleWidth != -1)
@@ -314,7 +316,8 @@ void PropertiesWidget::loadTorrentInfos(BitTorrent::TorrentHandle *const torrent
// Hash
m_ui->labelHashVal->setText(m_torrent->hash());
m_propListModel->model()->clear();
if (m_torrent->hasMetadata()) {
if (m_torrent->hasMetadata())
{
// Creation date
m_ui->labelCreatedOnVal->setText(m_torrent->creationDate().toString(Qt::DefaultLocaleShortDate));
@@ -333,7 +336,8 @@ void PropertiesWidget::loadTorrentInfos(BitTorrent::TorrentHandle *const torrent
// Expand single-item folders recursively
QModelIndex currentIndex;
while (m_propListModel->rowCount(currentIndex) == 1) {
while (m_propListModel->rowCount(currentIndex) == 1)
{
currentIndex = m_propListModel->index(0, 0, currentIndex);
m_ui->filesList->setExpanded(currentIndex, true);
}
@@ -350,7 +354,8 @@ void PropertiesWidget::readSettings()
const Preferences *const pref = Preferences::instance();
// Restore splitter sizes
QStringList sizesStr = pref->getPropSplitterSizes().split(',');
if (sizesStr.size() == 2) {
if (sizesStr.size() == 2)
{
m_slideSizes << sizesStr.first().toInt();
m_slideSizes << sizesStr.last().toInt();
auto *hSplitter = static_cast<QSplitter *>(parentWidget());
@@ -396,8 +401,10 @@ void PropertiesWidget::loadDynamicData()
if (!m_torrent || (m_state != VISIBLE)) return;
// Transfer infos
switch (m_ui->stackedProperties->currentIndex()) {
case PropTabBar::MainTab: {
switch (m_ui->stackedProperties->currentIndex())
{
case PropTabBar::MainTab:
{
m_ui->labelWastedVal->setText(Utils::Misc::friendlyUnit(m_torrent->wastedSize()));
m_ui->labelUpTotalVal->setText(tr("%1 (%2 this session)").arg(Utils::Misc::friendlyUnit(m_torrent->totalUpload())
@@ -456,16 +463,19 @@ void PropertiesWidget::loadDynamicData()
m_ui->labelAddedOnVal->setText(m_torrent->addedTime().toString(Qt::DefaultLocaleShortDate));
if (m_torrent->hasMetadata()) {
if (m_torrent->hasMetadata())
{
m_ui->labelTotalPiecesVal->setText(tr("%1 x %2 (have %3)", "(torrent pieces) eg 152 x 4MB (have 25)").arg(m_torrent->piecesCount()).arg(Utils::Misc::friendlyUnit(m_torrent->pieceLength())).arg(m_torrent->piecesHave()));
if (!m_torrent->isSeed() && !m_torrent->isPaused() && !m_torrent->isQueued() && !m_torrent->isChecking()) {
if (!m_torrent->isSeed() && !m_torrent->isPaused() && !m_torrent->isQueued() && !m_torrent->isChecking())
{
// Pieces availability
showPiecesAvailability(true);
m_piecesAvailability->setAvailability(m_torrent->pieceAvailability());
m_ui->labelAverageAvailabilityVal->setText(Utils::String::fromDouble(m_torrent->distributedCopies(), 3));
}
else {
else
{
showPiecesAvailability(false);
}
@@ -474,7 +484,8 @@ void PropertiesWidget::loadDynamicData()
m_ui->labelProgressVal->setText(Utils::String::fromDouble(progress, 1) + '%');
m_downloadedPieces->setProgress(m_torrent->pieces(), m_torrent->downloadingPieces());
}
else {
else
{
showPiecesAvailability(false);
}
}
@@ -489,7 +500,8 @@ void PropertiesWidget::loadDynamicData()
break;
case PropTabBar::FilesTab:
// Files progress
if (m_torrent->hasMetadata()) {
if (m_torrent->hasMetadata())
{
qDebug("Updating priorities in files tab");
m_ui->filesList->setUpdatesEnabled(false);
m_propListModel->model()->updateFilesProgress(m_torrent->filesProgress());
@@ -511,7 +523,8 @@ void PropertiesWidget::loadUrlSeeds()
qDebug("Loading URL seeds");
const QVector<QUrl> hcSeeds = m_torrent->urlSeeds();
// Add url seeds
for (const QUrl &hcSeed : hcSeeds) {
for (const QUrl &hcSeed : hcSeeds)
{
qDebug("Loading URL seed: %s", qUtf8Printable(hcSeed.toString()));
new QListWidgetItem(hcSeed.toString(), m_ui->listWebSeeds);
}
@@ -519,7 +532,8 @@ void PropertiesWidget::loadUrlSeeds()
QString PropertiesWidget::getFullPath(const QModelIndex &index) const
{
if (m_propListModel->itemType(index) == TorrentContentModelItem::FileType) {
if (m_propListModel->itemType(index) == TorrentContentModelItem::FileType)
{
const int fileIdx = m_propListModel->getFileIndex(index);
const QString filename {m_torrent->filePath(fileIdx)};
const QDir saveDir {m_torrent->savePath(true)};
@@ -568,7 +582,8 @@ void PropertiesWidget::displayFilesListMenu(const QPoint &)
QMenu *menu = new QMenu(this);
menu->setAttribute(Qt::WA_DeleteOnClose);
if (selectedRows.size() == 1) {
if (selectedRows.size() == 1)
{
const QModelIndex index = selectedRows[0];
const QAction *actOpen = menu->addAction(UIThemeManager::instance()->getIcon("folder-documents"), tr("Open"));
@@ -583,12 +598,14 @@ void PropertiesWidget::displayFilesListMenu(const QPoint &)
menu->addSeparator();
}
if (!m_torrent->isSeed()) {
if (!m_torrent->isSeed())
{
QMenu *subMenu = menu->addMenu(tr("Priority"));
const auto applyPriorities = [this, selectedRows](const BitTorrent::DownloadPriority prio)
{
for (const QModelIndex &index : selectedRows) {
for (const QModelIndex &index : selectedRows)
{
m_propListModel->setData(
m_propListModel->index(index.row(), PRIORITY, index.parent()), static_cast<int>(prio));
}
@@ -646,7 +663,8 @@ void PropertiesWidget::displayWebSeedListMenu(const QPoint &)
const QAction *actAdd = menu->addAction(UIThemeManager::instance()->getIcon("list-add"), tr("New Web seed"));
connect(actAdd, &QAction::triggered, this, &PropertiesWidget::askWebSeed);
if (!rows.isEmpty()) {
if (!rows.isEmpty())
{
const QAction *actDel = menu->addAction(UIThemeManager::instance()->getIcon("list-remove"), tr("Remove Web seed"));
connect(actDel, &QAction::triggered, this, &PropertiesWidget::deleteSelectedUrlSeeds);
@@ -673,16 +691,20 @@ void PropertiesWidget::openSelectedFile()
void PropertiesWidget::configure()
{
// Speed widget
if (Preferences::instance()->isSpeedWidgetEnabled()) {
if (!m_speedWidget || !qobject_cast<SpeedWidget *>(m_speedWidget)) {
if (Preferences::instance()->isSpeedWidgetEnabled())
{
if (!m_speedWidget || !qobject_cast<SpeedWidget *>(m_speedWidget))
{
m_ui->speedLayout->removeWidget(m_speedWidget);
delete m_speedWidget;
m_speedWidget = new SpeedWidget {this};
m_ui->speedLayout->addWidget(m_speedWidget);
}
}
else {
if (!m_speedWidget || !qobject_cast<QLabel *>(m_speedWidget)) {
else
{
if (!m_speedWidget || !qobject_cast<QLabel *>(m_speedWidget))
{
m_ui->speedLayout->removeWidget(m_speedWidget);
delete m_speedWidget;
auto *label = new QLabel(tr("<center><b>Speed graphs are disabled</b><p>You may change this setting in Advanced Options </center>"), this);
@@ -702,7 +724,8 @@ void PropertiesWidget::askWebSeed()
QLatin1String("http://www."), &ok);
if (!ok) return;
qDebug("Adding %s web seed", qUtf8Printable(urlSeed));
if (!m_ui->listWebSeeds->findItems(urlSeed, Qt::MatchFixedString).empty()) {
if (!m_ui->listWebSeeds->findItems(urlSeed, Qt::MatchFixedString).empty())
{
QMessageBox::warning(this, "qBittorrent",
tr("This URL seed is already in the list."),
QMessageBox::Ok);
@@ -755,7 +778,8 @@ void PropertiesWidget::editWebSeed()
oldSeed, &result);
if (!result) return;
if (!m_ui->listWebSeeds->findItems(newSeed, Qt::MatchFixedString).empty()) {
if (!m_ui->listWebSeeds->findItems(newSeed, Qt::MatchFixedString).empty())
{
QMessageBox::warning(this, tr("qBittorrent"),
tr("This URL seed is already in the list."),
QMessageBox::Ok);
@@ -781,11 +805,13 @@ void PropertiesWidget::filteredFilesChanged()
void PropertiesWidget::filterText(const QString &filter)
{
m_propListModel->setFilterRegExp(QRegExp(filter, Qt::CaseInsensitive, QRegExp::WildcardUnix));
if (filter.isEmpty()) {
if (filter.isEmpty())
{
m_ui->filesList->collapseAll();
m_ui->filesList->expand(m_propListModel->index(0, 0));
}
else {
else
{
m_ui->filesList->expandAll();
}
}

View File

@@ -72,11 +72,13 @@ void PropListDelegate::initProgressStyleOption(QStyleOptionProgressBar &option,
ProgressBarDelegate::initProgressStyleOption(option, index);
const int priority
= index.sibling(index.row(), PRIORITY).data(TorrentContentModel::UnderlyingDataRole).toInt();
if (static_cast<BitTorrent::DownloadPriority>(priority) == BitTorrent::DownloadPriority::Ignored) {
if (static_cast<BitTorrent::DownloadPriority>(priority) == BitTorrent::DownloadPriority::Ignored)
{
option.state &= ~QStyle::State_Enabled;
option.palette = progressBarDisabledPalette();
}
else {
else
{
option.state |= QStyle::State_Enabled;
}
}
@@ -86,7 +88,8 @@ void PropListDelegate::setEditorData(QWidget *editor, const QModelIndex &index)
auto *combobox = static_cast<QComboBox *>(editor);
// Set combobox index
const int priority = index.data(TorrentContentModel::UnderlyingDataRole).toInt();
switch (static_cast<BitTorrent::DownloadPriority>(priority)) {
switch (static_cast<BitTorrent::DownloadPriority>(priority))
{
case BitTorrent::DownloadPriority::Ignored:
combobox->setCurrentIndex(0);
break;
@@ -106,7 +109,8 @@ QWidget *PropListDelegate::createEditor(QWidget *parent, const QStyleOptionViewI
{
if (index.column() != PRIORITY) return nullptr;
if (m_properties) {
if (m_properties)
{
const BitTorrent::TorrentHandle *torrent = m_properties->getCurrentTorrent();
if (!torrent || !torrent->hasMetadata() || torrent->isSeed())
return nullptr;
@@ -131,7 +135,8 @@ void PropListDelegate::setModelData(QWidget *editor, QAbstractItemModel *model,
const int value = combobox->currentIndex();
BitTorrent::DownloadPriority prio = BitTorrent::DownloadPriority::Normal; // NORMAL
switch (value) {
switch (value)
{
case 0:
prio = BitTorrent::DownloadPriority::Ignored; // IGNORED
break;

View File

@@ -122,8 +122,10 @@ void PropTabBar::setCurrentIndex(int index)
if (index >= m_btnGroup->buttons().size())
index = 0;
// If asked to hide or if the currently selected tab is clicked
if ((index < 0) || (m_currentIndex == index)) {
if (m_currentIndex >= 0) {
if ((index < 0) || (m_currentIndex == index))
{
if (m_currentIndex >= 0)
{
m_btnGroup->button(m_currentIndex)->setDown(false);
m_currentIndex = -1;
emit visibilityToggled(false);
@@ -131,10 +133,12 @@ void PropTabBar::setCurrentIndex(int index)
return;
}
// Unselect previous tab
if (m_currentIndex >= 0) {
if (m_currentIndex >= 0)
{
m_btnGroup->button(m_currentIndex)->setDown(false);
}
else {
else
{
// Nothing was selected, show!
emit visibilityToggled(true);
}

View File

@@ -79,26 +79,30 @@ namespace
if (value <= 12.0) return {12, SizeUnit::Byte};
SizeUnit calculatedUnit = SizeUnit::Byte;
while (value > 1024) {
while (value > 1024)
{
value /= 1024;
calculatedUnit = static_cast<SizeUnit>(static_cast<int>(calculatedUnit) + 1);
}
if (value > 100.0) {
if (value > 100.0)
{
int roundedValue = static_cast<int>(value / 40) * 40;
while (roundedValue < value)
roundedValue += 40;
return {static_cast<double>(roundedValue), calculatedUnit};
}
if (value > 10.0) {
if (value > 10.0)
{
int roundedValue = static_cast<int>(value / 4) * 4;
while (roundedValue < value)
roundedValue += 4;
return {static_cast<double>(roundedValue), calculatedUnit};
}
for (const auto &roundedValue : roundingTable) {
for (const auto &roundedValue : roundingTable)
{
if (value <= roundedValue)
return {roundedValue, calculatedUnit};
}
@@ -215,7 +219,8 @@ void SpeedPlotView::setPeriod(const TimePeriod period)
{
m_period = period;
switch (period) {
switch (period)
{
case SpeedPlotView::MIN1:
m_viewablePointsCount = MIN1_SEC;
m_currentData = &m_data5Min;
@@ -266,7 +271,8 @@ quint64 SpeedPlotView::maxYValue()
boost::circular_buffer<PointData> &queue = getCurrentData();
quint64 maxYValue = 0;
for (int id = UP; id < NB_GRAPHS; ++id) {
for (int id = UP; id < NB_GRAPHS; ++id)
{
if (!m_properties[static_cast<GraphID>(id)].enable)
continue;
@@ -292,7 +298,8 @@ void SpeedPlotView::paintEvent(QPaintEvent *)
rect.adjust(0, fontMetrics.height(), 0, 0); // Add top padding for top speed text
// draw Y axis speed labels
const QVector<QString> speedLabels = {
const QVector<QString> speedLabels =
{
formatLabel(niceScale.arg, niceScale.unit),
formatLabel((0.75 * niceScale.arg), niceScale.unit),
formatLabel((0.50 * niceScale.arg), niceScale.unit),
@@ -311,7 +318,8 @@ void SpeedPlotView::paintEvent(QPaintEvent *)
#endif
int i = 0;
for (const QString &label : speedLabels) {
for (const QString &label : speedLabels)
{
QRectF labelRect(rect.topLeft() + QPointF(-yAxisWidth, (i++) * 0.25 * rect.height() - fontMetrics.height()),
QSizeF(2 * yAxisWidth, fontMetrics.height()));
painter.drawText(labelRect, label, Qt::AlignRight | Qt::AlignTop);
@@ -333,7 +341,8 @@ void SpeedPlotView::paintEvent(QPaintEvent *)
painter.drawLine(fullRect.left(), rect.bottom(), rect.right(), rect.bottom());
const int TIME_AXIS_DIVISIONS = 6;
for (int i = 0; i < TIME_AXIS_DIVISIONS; ++i) {
for (int i = 0; i < TIME_AXIS_DIVISIONS; ++i)
{
const int x = rect.left() + (i * rect.width()) / TIME_AXIS_DIVISIONS;
painter.drawLine(x, fullRect.top(), x, fullRect.bottom());
}
@@ -349,12 +358,14 @@ void SpeedPlotView::paintEvent(QPaintEvent *)
boost::circular_buffer<PointData> &queue = getCurrentData();
for (int id = UP; id < NB_GRAPHS; ++id) {
for (int id = UP; id < NB_GRAPHS; ++id)
{
if (!m_properties[static_cast<GraphID>(id)].enable)
continue;
QVector<QPoint> points;
for (int i = static_cast<int>(queue.size()) - 1, j = 0; (i >= 0) && (j < m_viewablePointsCount); --i, ++j) {
for (int i = static_cast<int>(queue.size()) - 1, j = 0; (i >= 0) && (j < m_viewablePointsCount); --i, ++j)
{
int newX = rect.right() - j * xTickSize;
int newY = rect.bottom() - queue[i].y[id] * yMultiplier;
@@ -371,7 +382,8 @@ void SpeedPlotView::paintEvent(QPaintEvent *)
double legendHeight = 0;
int legendWidth = 0;
for (const auto &property : asConst(m_properties)) {
for (const auto &property : asConst(m_properties))
{
if (!property.enable)
continue;
@@ -391,7 +403,8 @@ void SpeedPlotView::paintEvent(QPaintEvent *)
painter.fillRect(legendBackgroundRect, legendBackgroundColor);
i = 0;
for (const auto &property : asConst(m_properties)) {
for (const auto &property : asConst(m_properties))
{
if (!property.enable)
continue;

View File

@@ -92,7 +92,8 @@ SpeedWidget::SpeedWidget(PropertiesWidget *parent)
m_graphsMenuActions = m_graphsMenu->actions();
for (int id = SpeedPlotView::UP; id < SpeedPlotView::NB_GRAPHS; ++id) {
for (int id = SpeedPlotView::UP; id < SpeedPlotView::NB_GRAPHS; ++id)
{
QAction *action = m_graphsMenuActions.at(id);
action->setCheckable(true);
action->setChecked(true);
@@ -168,7 +169,8 @@ void SpeedWidget::loadSettings()
m_periodCombobox->setCurrentIndex(periodIndex);
onPeriodChange(static_cast<SpeedPlotView::TimePeriod>(periodIndex));
for (int id = SpeedPlotView::UP; id < SpeedPlotView::NB_GRAPHS; ++id) {
for (int id = SpeedPlotView::UP; id < SpeedPlotView::NB_GRAPHS; ++id)
{
QAction *action = m_graphsMenuActions.at(id);
bool enable = preferences->getSpeedWidgetGraphEnable(id);
@@ -183,7 +185,8 @@ void SpeedWidget::saveSettings() const
preferences->setSpeedWidgetPeriod(m_periodCombobox->currentIndex());
for (int id = SpeedPlotView::UP; id < SpeedPlotView::NB_GRAPHS; ++id) {
for (int id = SpeedPlotView::UP; id < SpeedPlotView::NB_GRAPHS; ++id)
{
QAction *action = m_graphsMenuActions.at(id);
preferences->setSpeedWidgetGraphEnable(id, action->isChecked());
}

View File

@@ -152,7 +152,8 @@ QVector<QTreeWidgetItem *> TrackerListWidget::getSelectedTrackerItems() const
QVector<QTreeWidgetItem *> selectedTrackers;
selectedTrackers.reserve(selectedTrackerItems.size());
for (QTreeWidgetItem *item : selectedTrackerItems) {
for (QTreeWidgetItem *item : selectedTrackerItems)
{
if (indexOfTopLevelItem(item) >= NB_STICKY_ITEM) // Ignore STICKY ITEMS
selectedTrackers << item;
}
@@ -171,7 +172,8 @@ void TrackerListWidget::setRowColor(const int row, const QColor &color)
void TrackerListWidget::moveSelectionUp()
{
BitTorrent::TorrentHandle *const torrent = m_properties->getCurrentTorrent();
if (!torrent) {
if (!torrent)
{
clear();
return;
}
@@ -179,9 +181,11 @@ void TrackerListWidget::moveSelectionUp()
if (selectedTrackerItems.isEmpty()) return;
bool change = false;
for (QTreeWidgetItem *item : selectedTrackerItems) {
for (QTreeWidgetItem *item : selectedTrackerItems)
{
int index = indexOfTopLevelItem(item);
if (index > NB_STICKY_ITEM) {
if (index > NB_STICKY_ITEM)
{
insertTopLevelItem(index - 1, takeTopLevelItem(index));
change = true;
}
@@ -197,7 +201,8 @@ void TrackerListWidget::moveSelectionUp()
// Update torrent trackers
QVector<BitTorrent::TrackerEntry> trackers;
trackers.reserve(topLevelItemCount());
for (int i = NB_STICKY_ITEM; i < topLevelItemCount(); ++i) {
for (int i = NB_STICKY_ITEM; i < topLevelItemCount(); ++i)
{
const QString trackerURL = topLevelItem(i)->data(COL_URL, Qt::DisplayRole).toString();
BitTorrent::TrackerEntry e(trackerURL);
e.setTier(i - NB_STICKY_ITEM);
@@ -213,7 +218,8 @@ void TrackerListWidget::moveSelectionUp()
void TrackerListWidget::moveSelectionDown()
{
BitTorrent::TorrentHandle *const torrent = m_properties->getCurrentTorrent();
if (!torrent) {
if (!torrent)
{
clear();
return;
}
@@ -221,9 +227,11 @@ void TrackerListWidget::moveSelectionDown()
if (selectedTrackerItems.isEmpty()) return;
bool change = false;
for (int i = selectedItems().size() - 1; i >= 0; --i) {
for (int i = selectedItems().size() - 1; i >= 0; --i)
{
int index = indexOfTopLevelItem(selectedTrackerItems.at(i));
if (index < (topLevelItemCount() - 1)) {
if (index < (topLevelItemCount() - 1))
{
insertTopLevelItem(index + 1, takeTopLevelItem(index));
change = true;
}
@@ -239,7 +247,8 @@ void TrackerListWidget::moveSelectionDown()
// Update torrent trackers
QVector<BitTorrent::TrackerEntry> trackers;
trackers.reserve(topLevelItemCount());
for (int i = NB_STICKY_ITEM; i < topLevelItemCount(); ++i) {
for (int i = NB_STICKY_ITEM; i < topLevelItemCount(); ++i)
{
const QString trackerURL = topLevelItem(i)->data(COL_URL, Qt::DisplayRole).toString();
BitTorrent::TrackerEntry e(trackerURL);
e.setTier(i - NB_STICKY_ITEM);
@@ -294,7 +303,8 @@ void TrackerListWidget::loadStickyItems(const BitTorrent::TorrentHandle *torrent
else
m_LSDItem->setText(COL_STATUS, disabled);
if (torrent->isPrivate()) {
if (torrent->isPrivate())
{
QString privateMsg = tr("This torrent is private");
m_DHTItem->setText(COL_MSG, privateMsg);
m_PEXItem->setText(COL_MSG, privateMsg);
@@ -304,22 +314,26 @@ void TrackerListWidget::loadStickyItems(const BitTorrent::TorrentHandle *torrent
// XXX: libtorrent should provide this info...
// Count peers from DHT, PeX, LSD
uint seedsDHT = 0, seedsPeX = 0, seedsLSD = 0, peersDHT = 0, peersPeX = 0, peersLSD = 0;
for (const BitTorrent::PeerInfo &peer : asConst(torrent->peers())) {
for (const BitTorrent::PeerInfo &peer : asConst(torrent->peers()))
{
if (peer.isConnecting()) continue;
if (peer.fromDHT()) {
if (peer.fromDHT())
{
if (peer.isSeed())
++seedsDHT;
else
++peersDHT;
}
if (peer.fromPeX()) {
if (peer.fromPeX())
{
if (peer.isSeed())
++seedsPeX;
else
++peersPeX;
}
if (peer.fromLSD()) {
if (peer.fromLSD())
{
if (peer.isSeed())
++seedsLSD;
else
@@ -347,17 +361,20 @@ void TrackerListWidget::loadTrackers()
const QHash<QString, BitTorrent::TrackerInfo> trackerData = torrent->trackerInfos();
QStringList oldTrackerURLs = m_trackerItems.keys();
for (const BitTorrent::TrackerEntry &entry : asConst(torrent->trackers())) {
for (const BitTorrent::TrackerEntry &entry : asConst(torrent->trackers()))
{
const QString trackerURL = entry.url();
QTreeWidgetItem *item = m_trackerItems.value(trackerURL, nullptr);
if (!item) {
if (!item)
{
item = new QTreeWidgetItem();
item->setText(COL_URL, trackerURL);
addTopLevelItem(item);
m_trackerItems[trackerURL] = item;
}
else {
else
{
oldTrackerURLs.removeOne(trackerURL);
}
@@ -365,7 +382,8 @@ void TrackerListWidget::loadTrackers()
const BitTorrent::TrackerInfo data = trackerData.value(trackerURL);
switch (entry.status()) {
switch (entry.status())
{
case BitTorrent::TrackerEntry::Working:
item->setText(COL_STATUS, tr("Working"));
item->setText(COL_MSG, "");
@@ -427,7 +445,8 @@ void TrackerListWidget::copyTrackerUrl()
if (selectedTrackerItems.isEmpty()) return;
QStringList urlsToCopy;
for (const QTreeWidgetItem *item : selectedTrackerItems) {
for (const QTreeWidgetItem *item : selectedTrackerItems)
{
QString trackerURL = item->data(COL_URL, Qt::DisplayRole).toString();
qDebug() << QString("Copy: ") + trackerURL;
urlsToCopy << trackerURL;
@@ -439,7 +458,8 @@ void TrackerListWidget::copyTrackerUrl()
void TrackerListWidget::deleteSelectedTrackers()
{
BitTorrent::TorrentHandle *const torrent = m_properties->getCurrentTorrent();
if (!torrent) {
if (!torrent)
{
clear();
return;
}
@@ -448,7 +468,8 @@ void TrackerListWidget::deleteSelectedTrackers()
if (selectedTrackerItems.isEmpty()) return;
QStringList urlsToRemove;
for (const QTreeWidgetItem *item : selectedTrackerItems) {
for (const QTreeWidgetItem *item : selectedTrackerItems)
{
QString trackerURL = item->data(COL_URL, Qt::DisplayRole).toString();
urlsToRemove << trackerURL;
m_trackerItems.remove(trackerURL);
@@ -460,7 +481,8 @@ void TrackerListWidget::deleteSelectedTrackers()
QVector<BitTorrent::TrackerEntry> remainingTrackers;
remainingTrackers.reserve(trackers.size());
for (const BitTorrent::TrackerEntry &entry : trackers) {
for (const BitTorrent::TrackerEntry &entry : trackers)
{
if (!urlsToRemove.contains(entry.url()))
remainingTrackers.push_back(entry);
}
@@ -487,7 +509,8 @@ void TrackerListWidget::editSelectedTracker()
QLineEdit::Normal, trackerURL.toString(), &ok).trimmed();
if (!ok) return;
if (!newTrackerURL.isValid()) {
if (!newTrackerURL.isValid())
{
QMessageBox::warning(this, tr("Tracker editing failed"), tr("The tracker URL entered is invalid."));
return;
}
@@ -495,13 +518,16 @@ void TrackerListWidget::editSelectedTracker()
QVector<BitTorrent::TrackerEntry> trackers = torrent->trackers();
bool match = false;
for (BitTorrent::TrackerEntry &entry : trackers) {
if (newTrackerURL == QUrl(entry.url())) {
for (BitTorrent::TrackerEntry &entry : trackers)
{
if (newTrackerURL == QUrl(entry.url()))
{
QMessageBox::warning(this, tr("Tracker editing failed"), tr("The tracker URL already exists."));
return;
}
if (!match && (trackerURL == QUrl(entry.url()))) {
if (!match && (trackerURL == QUrl(entry.url())))
{
match = true;
BitTorrent::TrackerEntry newEntry(newTrackerURL.toString());
newEntry.setTier(entry.tier());
@@ -525,16 +551,20 @@ void TrackerListWidget::reannounceSelected()
const QVector<BitTorrent::TrackerEntry> trackers = torrent->trackers();
for (const QTreeWidgetItem *item : selItems) {
for (const QTreeWidgetItem *item : selItems)
{
// DHT case
if (item == m_DHTItem) {
if (item == m_DHTItem)
{
torrent->forceDHTAnnounce();
continue;
}
// Trackers case
for (int i = 0; i < trackers.size(); ++i) {
if (item->text(COL_URL) == trackers[i].url()) {
for (int i = 0; i < trackers.size(); ++i)
{
if (item->text(COL_URL) == trackers[i].url())
{
torrent->forceReannounce(i);
break;
}
@@ -556,7 +586,8 @@ void TrackerListWidget::showTrackerListMenu(const QPoint &)
const QAction *addAct = menu->addAction(UIThemeManager::instance()->getIcon("list-add"), tr("Add a new tracker..."));
connect(addAct, &QAction::triggered, this, &TrackerListWidget::askForTrackers);
if (!getSelectedTrackerItems().isEmpty()) {
if (!getSelectedTrackerItems().isEmpty())
{
const QAction *editAct = menu->addAction(UIThemeManager::instance()->getIcon("edit-rename"),tr("Edit tracker URL..."));
connect(editAct, &QAction::triggered, this, &TrackerListWidget::editSelectedTracker);
@@ -567,7 +598,8 @@ void TrackerListWidget::showTrackerListMenu(const QPoint &)
connect(copyAct, &QAction::triggered, this, &TrackerListWidget::copyTrackerUrl);
}
if (!torrent->isPaused()) {
if (!torrent->isPaused())
{
const QAction *reannounceSelAct = menu->addAction(UIThemeManager::instance()->getIcon("view-refresh"), tr("Force reannounce to selected trackers"));
connect(reannounceSelAct, &QAction::triggered, this, &TrackerListWidget::reannounceSelected);
@@ -597,7 +629,8 @@ void TrackerListWidget::saveSettings() const
QStringList TrackerListWidget::headerLabels()
{
return {
return
{
tr("Tier")
, tr("URL")
, tr("Status")
@@ -612,7 +645,8 @@ QStringList TrackerListWidget::headerLabels()
int TrackerListWidget::visibleColumnsCount() const
{
int visibleCols = 0;
for (int i = 0; i < COL_COUNT; ++i) {
for (int i = 0; i < COL_COUNT; ++i)
{
if (!isColumnHidden(i))
++visibleCols;
}
@@ -626,7 +660,8 @@ void TrackerListWidget::displayToggleColumnsMenu(const QPoint &)
menu->setAttribute(Qt::WA_DeleteOnClose);
menu->setTitle(tr("Column visibility"));
for (int i = 0; i < COL_COUNT; ++i) {
for (int i = 0; i < COL_COUNT; ++i)
{
QAction *myAct = menu->addAction(headerLabels().at(i));
myAct->setCheckable(true);
myAct->setChecked(!isColumnHidden(i));

View File

@@ -59,7 +59,8 @@ QStringList TrackersAdditionDialog::newTrackers() const
const QString plainText = m_ui->textEditTrackersList->toPlainText();
QStringList cleanTrackers;
for (QStringRef url : asConst(plainText.splitRef('\n'))) {
for (QStringRef url : asConst(plainText.splitRef('\n')))
{
url = url.trimmed();
if (!url.isEmpty())
cleanTrackers << url.toString();
@@ -78,7 +79,8 @@ void TrackersAdditionDialog::on_uTorrentListButton_clicked()
void TrackersAdditionDialog::torrentListDownloadFinished(const Net::DownloadResult &result)
{
if (result.status != Net::DownloadStatus::Success) {
if (result.status != Net::DownloadStatus::Success)
{
// To restore the cursor ...
setCursor(Qt::ArrowCursor);
m_ui->uTorrentListButton->setEnabled(true);
@@ -92,7 +94,8 @@ void TrackersAdditionDialog::torrentListDownloadFinished(const Net::DownloadResu
const QStringList trackersFromUser = m_ui->textEditTrackersList->toPlainText().split('\n');
QVector<BitTorrent::TrackerEntry> existingTrackers = m_torrent->trackers();
existingTrackers.reserve(trackersFromUser.size());
for (const QString &userURL : trackersFromUser) {
for (const QString &userURL : trackersFromUser)
{
const BitTorrent::TrackerEntry userTracker(userURL);
if (!existingTrackers.contains(userTracker))
existingTrackers << userTracker;
@@ -105,12 +108,14 @@ void TrackersAdditionDialog::torrentListDownloadFinished(const Net::DownloadResu
QBuffer buffer;
buffer.setData(result.data);
buffer.open(QBuffer::ReadOnly);
while (!buffer.atEnd()) {
while (!buffer.atEnd())
{
const QString line = buffer.readLine().trimmed();
if (line.isEmpty()) continue;
BitTorrent::TrackerEntry newTracker(line);
if (!existingTrackers.contains(newTracker)) {
if (!existingTrackers.contains(newTracker))
{
m_ui->textEditTrackersList->insertPlainText(line + '\n');
++nb;
}