Browse Source

Allow setting priority for partially downloaded multi-file torrent

Currently you can't directly change the priority of a partially completed multi file torrent. You'll have to start downloading those files and then change their priority.

Closes #10994.
Closes #8673.
PR #16546.
adaptive-webui-19844
An0n 3 years ago committed by GitHub
parent
commit
c2af5c6a3f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 117
      src/gui/properties/propertieswidget.cpp
  2. 2
      src/gui/properties/proplistdelegate.cpp

117
src/gui/properties/propertieswidget.cpp

@ -655,77 +655,74 @@ void PropertiesWidget::displayFilesListMenu()
menu->addSeparator(); menu->addSeparator();
} }
if (!m_torrent->isSeed()) const auto applyPriorities = [this](const BitTorrent::DownloadPriority prio)
{ {
const auto applyPriorities = [this](const BitTorrent::DownloadPriority prio) const QModelIndexList selectedRows = m_ui->filesList->selectionModel()->selectedRows(0);
for (const QModelIndex &index : selectedRows)
{ {
const QModelIndexList selectedRows = m_ui->filesList->selectionModel()->selectedRows(0); m_propListModel->setData(index.sibling(index.row(), PRIORITY)
for (const QModelIndex &index : selectedRows) , static_cast<int>(prio));
{ }
m_propListModel->setData(index.sibling(index.row(), PRIORITY)
, static_cast<int>(prio));
}
// Save changes // Save changes
this->applyPriorities(); this->applyPriorities();
}; };
QMenu *subMenu = menu->addMenu(tr("Priority")); QMenu *subMenu = menu->addMenu(tr("Priority"));
subMenu->addAction(tr("Do not download"), subMenu, [applyPriorities]() subMenu->addAction(tr("Do not download"), subMenu, [applyPriorities]()
{ {
applyPriorities(BitTorrent::DownloadPriority::Ignored); applyPriorities(BitTorrent::DownloadPriority::Ignored);
}); });
subMenu->addAction(tr("Normal"), subMenu, [applyPriorities]() subMenu->addAction(tr("Normal"), subMenu, [applyPriorities]()
{ {
applyPriorities(BitTorrent::DownloadPriority::Normal); applyPriorities(BitTorrent::DownloadPriority::Normal);
}); });
subMenu->addAction(tr("High"), subMenu, [applyPriorities]() subMenu->addAction(tr("High"), subMenu, [applyPriorities]()
{ {
applyPriorities(BitTorrent::DownloadPriority::High); applyPriorities(BitTorrent::DownloadPriority::High);
}); });
subMenu->addAction(tr("Maximum"), subMenu, [applyPriorities]() subMenu->addAction(tr("Maximum"), subMenu, [applyPriorities]()
{ {
applyPriorities(BitTorrent::DownloadPriority::Maximum); applyPriorities(BitTorrent::DownloadPriority::Maximum);
}); });
subMenu->addSeparator(); subMenu->addSeparator();
subMenu->addAction(tr("By shown file order"), subMenu, [this]() subMenu->addAction(tr("By shown file order"), subMenu, [this]()
{ {
// Equally distribute the selected items into groups and for each group assign // Equally distribute the selected items into groups and for each group assign
// a download priority that will apply to each item. The number of groups depends on how // a download priority that will apply to each item. The number of groups depends on how
// many "download priority" are available to be assigned // many "download priority" are available to be assigned
const QModelIndexList selectedRows = m_ui->filesList->selectionModel()->selectedRows(0); const QModelIndexList selectedRows = m_ui->filesList->selectionModel()->selectedRows(0);
const qsizetype priorityGroups = 3; const qsizetype priorityGroups = 3;
const auto priorityGroupSize = std::max<qsizetype>((selectedRows.length() / priorityGroups), 1); const auto priorityGroupSize = std::max<qsizetype>((selectedRows.length() / priorityGroups), 1);
for (qsizetype i = 0; i < selectedRows.length(); ++i) for (qsizetype i = 0; i < selectedRows.length(); ++i)
{
auto priority = BitTorrent::DownloadPriority::Ignored;
switch (i / priorityGroupSize)
{ {
auto priority = BitTorrent::DownloadPriority::Ignored; case 0:
switch (i / priorityGroupSize) priority = BitTorrent::DownloadPriority::Maximum;
{ break;
case 0: case 1:
priority = BitTorrent::DownloadPriority::Maximum; priority = BitTorrent::DownloadPriority::High;
break; break;
case 1: default:
priority = BitTorrent::DownloadPriority::High; case 2:
break; priority = BitTorrent::DownloadPriority::Normal;
default: break;
case 2: }
priority = BitTorrent::DownloadPriority::Normal;
break;
}
const QModelIndex &index = selectedRows[i]; const QModelIndex &index = selectedRows[i];
m_propListModel->setData(index.sibling(index.row(), PRIORITY) m_propListModel->setData(index.sibling(index.row(), PRIORITY)
, static_cast<int>(priority)); , static_cast<int>(priority));
// Save changes // Save changes
this->applyPriorities(); this->applyPriorities();
} }
}); });
}
// The selected torrent might have disappeared during exec() // The selected torrent might have disappeared during exec()
// so we just close menu when an appropriate model is reset // so we just close menu when an appropriate model is reset

2
src/gui/properties/proplistdelegate.cpp

@ -77,7 +77,7 @@ QWidget *PropListDelegate::createEditor(QWidget *parent, const QStyleOptionViewI
if (m_properties) if (m_properties)
{ {
const BitTorrent::Torrent *torrent = m_properties->getCurrentTorrent(); const BitTorrent::Torrent *torrent = m_properties->getCurrentTorrent();
if (!torrent || !torrent->hasMetadata() || torrent->isSeed()) if (!torrent || !torrent->hasMetadata())
return nullptr; return nullptr;
} }

Loading…
Cancel
Save