mirror of
https://github.com/qbittorrent/qBittorrent.git
synced 2024-11-24 18:26:11 +03:00
Add ability to prioritize selected items by shown file order
Closes #2834.
This commit is contained in:
parent
3985d58d3c
commit
28d31b9d5b
2 changed files with 75 additions and 6 deletions
|
@ -502,12 +502,12 @@ void AddNewTorrentDialog::displayContentTreeMenu(const QPoint &)
|
|||
{
|
||||
const QModelIndexList selectedRows = m_ui->contentTreeView->selectionModel()->selectedRows(0);
|
||||
|
||||
const auto applyPriorities = [this, selectedRows](const BitTorrent::DownloadPriority prio)
|
||||
const auto applyPriorities = [this](const BitTorrent::DownloadPriority prio)
|
||||
{
|
||||
const QModelIndexList selectedRows = m_ui->contentTreeView->selectionModel()->selectedRows(0);
|
||||
for (const QModelIndex &index : selectedRows)
|
||||
{
|
||||
m_contentModel->setData(
|
||||
m_contentModel->index(index.row(), PRIORITY, index.parent())
|
||||
m_contentModel->setData(index.sibling(index.row(), PRIORITY)
|
||||
, static_cast<int>(prio));
|
||||
}
|
||||
};
|
||||
|
@ -541,6 +541,40 @@ void AddNewTorrentDialog::displayContentTreeMenu(const QPoint &)
|
|||
{
|
||||
applyPriorities(BitTorrent::DownloadPriority::Maximum);
|
||||
});
|
||||
subMenu->addSeparator();
|
||||
subMenu->addAction(tr("By shown file order"), subMenu, [this]()
|
||||
{
|
||||
// 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
|
||||
// many "download priority" are available to be assigned
|
||||
|
||||
const QModelIndexList selectedRows = m_ui->contentTreeView->selectionModel()->selectedRows(0);
|
||||
|
||||
const int priorityGroups = 3;
|
||||
const int priorityGroupSize = std::max((selectedRows.length() / priorityGroups), 1);
|
||||
|
||||
for (int i = 0; i < selectedRows.length(); ++i)
|
||||
{
|
||||
auto priority = BitTorrent::DownloadPriority::Ignored;
|
||||
switch (i / priorityGroupSize)
|
||||
{
|
||||
case 0:
|
||||
priority = BitTorrent::DownloadPriority::Maximum;
|
||||
break;
|
||||
case 1:
|
||||
priority = BitTorrent::DownloadPriority::High;
|
||||
break;
|
||||
default:
|
||||
case 2:
|
||||
priority = BitTorrent::DownloadPriority::Normal;
|
||||
break;
|
||||
}
|
||||
|
||||
const QModelIndex &index = selectedRows[i];
|
||||
m_contentModel->setData(index.sibling(index.row(), PRIORITY)
|
||||
, static_cast<int>(priority));
|
||||
}
|
||||
});
|
||||
|
||||
menu->popup(QCursor::pos());
|
||||
}
|
||||
|
|
|
@ -600,12 +600,13 @@ void PropertiesWidget::displayFilesListMenu(const QPoint &)
|
|||
|
||||
if (!m_torrent->isSeed())
|
||||
{
|
||||
const auto applyPriorities = [this, selectedRows](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)
|
||||
{
|
||||
m_propListModel->setData(
|
||||
m_propListModel->index(index.row(), PRIORITY, index.parent()), static_cast<int>(prio));
|
||||
m_propListModel->setData(index.sibling(index.row(), PRIORITY)
|
||||
, static_cast<int>(prio));
|
||||
}
|
||||
|
||||
// Save changes
|
||||
|
@ -630,6 +631,40 @@ void PropertiesWidget::displayFilesListMenu(const QPoint &)
|
|||
{
|
||||
applyPriorities(BitTorrent::DownloadPriority::Maximum);
|
||||
});
|
||||
subMenu->addSeparator();
|
||||
subMenu->addAction(tr("By shown file order"), subMenu, [this]()
|
||||
{
|
||||
// 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
|
||||
// many "download priority" are available to be assigned
|
||||
|
||||
const QModelIndexList selectedRows = m_ui->filesList->selectionModel()->selectedRows(0);
|
||||
|
||||
const int priorityGroups = 3;
|
||||
const int priorityGroupSize = std::max((selectedRows.length() / priorityGroups), 1);
|
||||
|
||||
for (int i = 0; i < selectedRows.length(); ++i)
|
||||
{
|
||||
auto priority = BitTorrent::DownloadPriority::Ignored;
|
||||
switch (i / priorityGroupSize)
|
||||
{
|
||||
case 0:
|
||||
priority = BitTorrent::DownloadPriority::Maximum;
|
||||
break;
|
||||
case 1:
|
||||
priority = BitTorrent::DownloadPriority::High;
|
||||
break;
|
||||
default:
|
||||
case 2:
|
||||
priority = BitTorrent::DownloadPriority::Normal;
|
||||
break;
|
||||
}
|
||||
|
||||
const QModelIndex &index = selectedRows[i];
|
||||
m_propListModel->setData(index.sibling(index.row(), PRIORITY)
|
||||
, static_cast<int>(priority));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// The selected torrent might have disappeared during exec()
|
||||
|
|
Loading…
Reference in a new issue