Skip to content

Commit

Permalink
Rename priority to queue in the context of torrents
Browse files Browse the repository at this point in the history
  • Loading branch information
thalieht committed Jul 13, 2019
1 parent afa73d4 commit 7b31868
Show file tree
Hide file tree
Showing 20 changed files with 171 additions and 160 deletions.
30 changes: 15 additions & 15 deletions src/base/bittorrent/session.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ namespace
#endif

bool readFile(const QString &path, QByteArray &buf);
bool loadTorrentResumeData(const QByteArray &data, CreateTorrentParams &torrentParams, int &prio, MagnetUri &magnetUri);
bool loadTorrentResumeData(const QByteArray &data, CreateTorrentParams &torrentParams, int &queuePos, MagnetUri &magnetUri);

void torrentQueuePositionUp(const lt::torrent_handle &handle);
void torrentQueuePositionDown(const lt::torrent_handle &handle);
Expand Down Expand Up @@ -1698,20 +1698,20 @@ bool Session::cancelLoadMetadata(const InfoHash &hash)
return true;
}

void Session::increaseTorrentsPriority(const QStringList &hashes)
void Session::increaseTorrentsQueuePos(const QStringList &hashes)
{
std::priority_queue<QPair<int, TorrentHandle *>,
std::vector<QPair<int, TorrentHandle *>>,
std::greater<QPair<int, TorrentHandle *>>> torrentQueue;

// Sort torrents by priority
// Sort torrents by queue position
for (const InfoHash infoHash : hashes) {
TorrentHandle *const torrent = m_torrents.value(infoHash);
if (torrent && !torrent->isSeed())
torrentQueue.push(qMakePair(torrent->queuePosition(), torrent));
}

// Increase torrents priority (starting with the ones with highest priority)
// Increase torrents queue position (starting with the one in the highest queue position)
while (!torrentQueue.empty()) {
TorrentHandle *const torrent = torrentQueue.top().second;
torrentQueuePositionUp(torrent->nativeHandle());
Expand All @@ -1721,20 +1721,20 @@ void Session::increaseTorrentsPriority(const QStringList &hashes)
saveTorrentsQueue();
}

void Session::decreaseTorrentsPriority(const QStringList &hashes)
void Session::decreaseTorrentsQueuePos(const QStringList &hashes)
{
std::priority_queue<QPair<int, TorrentHandle *>,
std::vector<QPair<int, TorrentHandle *>>,
std::less<QPair<int, TorrentHandle *>>> torrentQueue;

// Sort torrents by priority
// Sort torrents by queue position
for (const InfoHash infoHash : hashes) {
TorrentHandle *const torrent = m_torrents.value(infoHash);
if (torrent && !torrent->isSeed())
torrentQueue.push(qMakePair(torrent->queuePosition(), torrent));
}

// Decrease torrents priority (starting with the ones with lowest priority)
// Decrease torrents queue position (starting with the one in the lowest queue position)
while (!torrentQueue.empty()) {
TorrentHandle *const torrent = torrentQueue.top().second;
torrentQueuePositionDown(torrent->nativeHandle());
Expand All @@ -1747,20 +1747,20 @@ void Session::decreaseTorrentsPriority(const QStringList &hashes)
saveTorrentsQueue();
}

void Session::topTorrentsPriority(const QStringList &hashes)
void Session::topTorrentsQueuePos(const QStringList &hashes)
{
std::priority_queue<QPair<int, TorrentHandle *>,
std::vector<QPair<int, TorrentHandle *>>,
std::greater<QPair<int, TorrentHandle *>>> torrentQueue;

// Sort torrents by priority
// Sort torrents by queue position
for (const InfoHash infoHash : hashes) {
TorrentHandle *const torrent = m_torrents.value(infoHash);
if (torrent && !torrent->isSeed())
torrentQueue.push(qMakePair(torrent->queuePosition(), torrent));
}

// Top torrents priority (starting with the ones with highest priority)
// Top torrents queue position (starting with the one in the highest queue position)
while (!torrentQueue.empty()) {
TorrentHandle *const torrent = torrentQueue.top().second;
torrentQueuePositionTop(torrent->nativeHandle());
Expand All @@ -1770,20 +1770,20 @@ void Session::topTorrentsPriority(const QStringList &hashes)
saveTorrentsQueue();
}

void Session::bottomTorrentsPriority(const QStringList &hashes)
void Session::bottomTorrentsQueuePos(const QStringList &hashes)
{
std::priority_queue<QPair<int, TorrentHandle *>,
std::vector<QPair<int, TorrentHandle *>>,
std::less<QPair<int, TorrentHandle *>>> torrentQueue;

// Sort torrents by priority
// Sort torrents by queue position
for (const InfoHash infoHash : hashes) {
TorrentHandle *const torrent = m_torrents.value(infoHash);
if (torrent && !torrent->isSeed())
torrentQueue.push(qMakePair(torrent->queuePosition(), torrent));
}

// Bottom torrents priority (starting with the ones with lowest priority)
// Bottom torrents queue position (starting with the one in the lowest queue position)
while (!torrentQueue.empty()) {
TorrentHandle *const torrent = torrentQueue.top().second;
torrentQueuePositionBottom(torrent->nativeHandle());
Expand Down Expand Up @@ -4432,7 +4432,7 @@ namespace
return true;
}

bool loadTorrentResumeData(const QByteArray &data, CreateTorrentParams &torrentParams, int &prio, MagnetUri &magnetUri)
bool loadTorrentResumeData(const QByteArray &data, CreateTorrentParams &torrentParams, int &queuePos, MagnetUri &magnetUri)
{
torrentParams = CreateTorrentParams();
torrentParams.restored = true;
Expand Down Expand Up @@ -4476,7 +4476,7 @@ namespace
torrentParams.firstLastPiecePriority = fast.dict_find_int_value("qBt-firstLastPiecePriority");
torrentParams.sequential = fast.dict_find_int_value("qBt-sequential");

prio = fast.dict_find_int_value("qBt-queuePosition");
queuePos = fast.dict_find_int_value("qBt-queuePosition");

return true;
}
Expand Down
8 changes: 4 additions & 4 deletions src/base/bittorrent/session.h
Original file line number Diff line number Diff line change
Expand Up @@ -421,10 +421,10 @@ namespace BitTorrent
bool cancelLoadMetadata(const InfoHash &hash);

void recursiveTorrentDownload(const InfoHash &hash);
void increaseTorrentsPriority(const QStringList &hashes);
void decreaseTorrentsPriority(const QStringList &hashes);
void topTorrentsPriority(const QStringList &hashes);
void bottomTorrentsPriority(const QStringList &hashes);
void increaseTorrentsQueuePos(const QStringList &hashes);
void decreaseTorrentsQueuePos(const QStringList &hashes);
void topTorrentsQueuePos(const QStringList &hashes);
void bottomTorrentsQueuePos(const QStringList &hashes);

// TorrentHandle interface
void handleTorrentShareLimitChanged(TorrentHandle *const torrent);
Expand Down
60 changes: 30 additions & 30 deletions src/gui/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,14 +171,14 @@ MainWindow::MainWindow(QWidget *parent)
m_ui->actionCreateTorrent->setIcon(GuiIconProvider::instance()->getIcon("document-edit"));
m_ui->actionAbout->setIcon(GuiIconProvider::instance()->getIcon("help-about"));
m_ui->actionStatistics->setIcon(GuiIconProvider::instance()->getIcon("view-statistics"));
m_ui->actionDecreasePriority->setIcon(GuiIconProvider::instance()->getIcon("go-down"));
m_ui->actionBottomPriority->setIcon(GuiIconProvider::instance()->getIcon("go-bottom"));
m_ui->actionTopQueuePos->setIcon(GuiIconProvider::instance()->getIcon("go-top"));
m_ui->actionIncreaseQueuePos->setIcon(GuiIconProvider::instance()->getIcon("go-up"));
m_ui->actionDecreaseQueuePos->setIcon(GuiIconProvider::instance()->getIcon("go-down"));
m_ui->actionBottomQueuePos->setIcon(GuiIconProvider::instance()->getIcon("go-bottom"));
m_ui->actionDelete->setIcon(GuiIconProvider::instance()->getIcon("list-remove"));
m_ui->actionDocumentation->setIcon(GuiIconProvider::instance()->getIcon("help-contents"));
m_ui->actionDonateMoney->setIcon(GuiIconProvider::instance()->getIcon("wallet-open"));
m_ui->actionExit->setIcon(GuiIconProvider::instance()->getIcon("application-exit"));
m_ui->actionIncreasePriority->setIcon(GuiIconProvider::instance()->getIcon("go-up"));
m_ui->actionTopPriority->setIcon(GuiIconProvider::instance()->getIcon("go-top"));
m_ui->actionLock->setIcon(GuiIconProvider::instance()->getIcon("object-locked"));
m_ui->actionOptions->setIcon(GuiIconProvider::instance()->getIcon("configure", "preferences-system"));
m_ui->actionPause->setIcon(GuiIconProvider::instance()->getIcon("media-playback-pause"));
Expand Down Expand Up @@ -265,8 +265,8 @@ MainWindow::MainWindow(QWidget *parent)

m_ui->centralWidgetLayout->addWidget(m_tabs);

m_prioSeparator = m_ui->toolBar->insertSeparator(m_ui->actionTopPriority);
m_prioSeparatorMenu = m_ui->menuEdit->insertSeparator(m_ui->actionTopPriority);
m_queueSeparator = m_ui->toolBar->insertSeparator(m_ui->actionTopQueuePos);
m_queueSeparatorMenu = m_ui->menuEdit->insertSeparator(m_ui->actionTopQueuePos);

#ifdef Q_OS_MAC
for (QAction *action : asConst(m_ui->toolBar->actions())) {
Expand Down Expand Up @@ -298,10 +298,10 @@ MainWindow::MainWindow(QWidget *parent)
connect(m_ui->actionPause, &QAction::triggered, m_transferListWidget, &TransferListWidget::pauseSelectedTorrents);
connect(m_ui->actionPauseAll, &QAction::triggered, m_transferListWidget, &TransferListWidget::pauseAllTorrents);
connect(m_ui->actionDelete, &QAction::triggered, m_transferListWidget, &TransferListWidget::softDeleteSelectedTorrents);
connect(m_ui->actionTopPriority, &QAction::triggered, m_transferListWidget, &TransferListWidget::topPrioSelectedTorrents);
connect(m_ui->actionIncreasePriority, &QAction::triggered, m_transferListWidget, &TransferListWidget::increasePrioSelectedTorrents);
connect(m_ui->actionDecreasePriority, &QAction::triggered, m_transferListWidget, &TransferListWidget::decreasePrioSelectedTorrents);
connect(m_ui->actionBottomPriority, &QAction::triggered, m_transferListWidget, &TransferListWidget::bottomPrioSelectedTorrents);
connect(m_ui->actionTopQueuePos, &QAction::triggered, m_transferListWidget, &TransferListWidget::topQueuePosSelectedTorrents);
connect(m_ui->actionIncreaseQueuePos, &QAction::triggered, m_transferListWidget, &TransferListWidget::increaseQueuePosSelectedTorrents);
connect(m_ui->actionDecreaseQueuePos, &QAction::triggered, m_transferListWidget, &TransferListWidget::decreaseQueuePosSelectedTorrents);
connect(m_ui->actionBottomQueuePos, &QAction::triggered, m_transferListWidget, &TransferListWidget::bottomQueuePosSelectedTorrents);
#ifndef Q_OS_MAC
connect(m_ui->actionToggleVisibility, &QAction::triggered, this, [this]() { toggleVisibility(); });
#endif
Expand Down Expand Up @@ -875,10 +875,10 @@ void MainWindow::createKeyboardShortcuts()
m_ui->actionStartAll->setShortcut(Qt::CTRL + Qt::SHIFT + Qt::Key_S);
m_ui->actionPause->setShortcut(Qt::CTRL + Qt::Key_P);
m_ui->actionPauseAll->setShortcut(Qt::CTRL + Qt::SHIFT + Qt::Key_P);
m_ui->actionBottomPriority->setShortcut(Qt::CTRL + Qt::SHIFT + Qt::Key_Minus);
m_ui->actionDecreasePriority->setShortcut(Qt::CTRL + Qt::Key_Minus);
m_ui->actionIncreasePriority->setShortcut(Qt::CTRL + Qt::Key_Plus);
m_ui->actionTopPriority->setShortcut(Qt::CTRL + Qt::SHIFT + Qt::Key_Plus);
m_ui->actionBottomQueuePos->setShortcut(Qt::CTRL + Qt::SHIFT + Qt::Key_Minus);
m_ui->actionDecreaseQueuePos->setShortcut(Qt::CTRL + Qt::Key_Minus);
m_ui->actionIncreaseQueuePos->setShortcut(Qt::CTRL + Qt::Key_Plus);
m_ui->actionTopQueuePos->setShortcut(Qt::CTRL + Qt::SHIFT + Qt::Key_Plus);
#ifdef Q_OS_MAC
m_ui->actionMinimize->setShortcut(Qt::CTRL + Qt::Key_M);
addAction(m_ui->actionMinimize);
Expand Down Expand Up @@ -1466,29 +1466,29 @@ void MainWindow::loadPreferences(bool configureSession)

// Queueing System
if (BitTorrent::Session::instance()->isQueueingSystemEnabled()) {
if (!m_ui->actionDecreasePriority->isVisible()) {
m_transferListWidget->hidePriorityColumn(false);
m_ui->actionDecreasePriority->setVisible(true);
m_ui->actionIncreasePriority->setVisible(true);
m_ui->actionTopPriority->setVisible(true);
m_ui->actionBottomPriority->setVisible(true);
if (!m_ui->actionDecreaseQueuePos->isVisible()) {
m_transferListWidget->hideQueuePosColumn(false);
m_ui->actionDecreaseQueuePos->setVisible(true);
m_ui->actionIncreaseQueuePos->setVisible(true);
m_ui->actionTopQueuePos->setVisible(true);
m_ui->actionBottomQueuePos->setVisible(true);
#ifndef Q_OS_MAC
m_prioSeparator->setVisible(true);
m_queueSeparator->setVisible(true);
#endif
m_prioSeparatorMenu->setVisible(true);
m_queueSeparatorMenu->setVisible(true);
}
}
else {
if (m_ui->actionDecreasePriority->isVisible()) {
m_transferListWidget->hidePriorityColumn(true);
m_ui->actionDecreasePriority->setVisible(false);
m_ui->actionIncreasePriority->setVisible(false);
m_ui->actionTopPriority->setVisible(false);
m_ui->actionBottomPriority->setVisible(false);
if (m_ui->actionDecreaseQueuePos->isVisible()) {
m_transferListWidget->hideQueuePosColumn(true);
m_ui->actionDecreaseQueuePos->setVisible(false);
m_ui->actionIncreaseQueuePos->setVisible(false);
m_ui->actionTopQueuePos->setVisible(false);
m_ui->actionBottomQueuePos->setVisible(false);
#ifndef Q_OS_MAC
m_prioSeparator->setVisible(false);
m_queueSeparator->setVisible(false);
#endif
m_prioSeparatorMenu->setVisible(false);
m_queueSeparatorMenu->setVisible(false);
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/gui/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -243,8 +243,8 @@ private slots:
LineEdit *m_searchFilter;
QAction *m_searchFilterAction;
// Widgets
QAction *m_prioSeparator;
QAction *m_prioSeparatorMenu;
QAction *m_queueSeparator;
QAction *m_queueSeparatorMenu;
QSplitter *m_splitter;
QPointer<SearchWidget> m_searchWidget;
QPointer<RSSWidget> m_rssWidget;
Expand Down
44 changes: 28 additions & 16 deletions src/gui/mainwindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@
<addaction name="actionPauseAll"/>
<addaction name="separator"/>
<addaction name="actionDelete"/>
<addaction name="actionTopPriority"/>
<addaction name="actionIncreasePriority"/>
<addaction name="actionDecreasePriority"/>
<addaction name="actionBottomPriority"/>
<addaction name="actionTopQueuePos"/>
<addaction name="actionIncreaseQueuePos"/>
<addaction name="actionDecreaseQueuePos"/>
<addaction name="actionBottomQueuePos"/>
</widget>
<widget class="QMenu" name="menuHelp">
<property name="title">
Expand Down Expand Up @@ -153,10 +153,10 @@
<addaction name="separator"/>
<addaction name="actionStart"/>
<addaction name="actionPause"/>
<addaction name="actionTopPriority"/>
<addaction name="actionIncreasePriority"/>
<addaction name="actionDecreasePriority"/>
<addaction name="actionBottomPriority"/>
<addaction name="actionTopQueuePos"/>
<addaction name="actionIncreaseQueuePos"/>
<addaction name="actionDecreaseQueuePos"/>
<addaction name="actionBottomQueuePos"/>
<addaction name="separator"/>
<addaction name="actionOptions"/>
<addaction name="actionLock"/>
Expand Down Expand Up @@ -248,33 +248,45 @@
<string>Set Global Upload Limit...</string>
</property>
</action>
<action name="actionBottomPriority">
<action name="actionBottomQueuePos">
<property name="text">
<string>Minimum Priority</string>
<string>Bottom of Queue</string>
</property>
<property name="toolTip">
<string>Move to the bottom of the queue</string>
</property>
<property name="visible">
<bool>true</bool>
</property>
</action>
<action name="actionTopPriority">
<action name="actionTopQueuePos">
<property name="text">
<string>Top Priority</string>
<string>Top of Queue</string>
</property>
<property name="toolTip">
<string>Move to the top of the queue</string>
</property>
<property name="visible">
<bool>true</bool>
</property>
</action>
<action name="actionDecreasePriority">
<action name="actionDecreaseQueuePos">
<property name="text">
<string>Decrease Priority</string>
<string>Move Down Queue</string>
</property>
<property name="toolTip">
<string>Move down in the queue</string>
</property>
<property name="visible">
<bool>true</bool>
</property>
</action>
<action name="actionIncreasePriority">
<action name="actionIncreaseQueuePos">
<property name="text">
<string>Increase Priority</string>
<string>Move Up Queue</string>
</property>
<property name="toolTip">
<string>Move up in the queue</string>
</property>
<property name="visible">
<bool>true</bool>
Expand Down
6 changes: 3 additions & 3 deletions src/gui/transferlistdelegate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,10 @@ void TransferListDelegate::paint(QPainter *painter, const QStyleOptionViewItem &
QItemDelegate::drawDisplay(painter, opt, opt.rect, str);
}
break;
case TransferListModel::TR_PRIORITY: {
const int priority = index.data().toInt();
case TransferListModel::TR_QUEUE_POSITION: {
const int queuePos = index.data().toInt();
opt.displayAlignment = Qt::AlignRight | Qt::AlignVCenter;
if (priority > 0) {
if (queuePos > 0) {
QItemDelegate::paint(painter, opt, index);
}
else {
Expand Down
6 changes: 3 additions & 3 deletions src/gui/transferlistmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ QVariant TransferListModel::headerData(int section, Qt::Orientation orientation,
if (orientation == Qt::Horizontal) {
if (role == Qt::DisplayRole) {
switch (section) {
case TR_PRIORITY: return QChar('#');
case TR_QUEUE_POSITION: return QChar('#');
case TR_NAME: return tr("Name", "i.e: torrent name");
case TR_SIZE: return tr("Size", "i.e: torrent size");
case TR_PROGRESS: return tr("Done", "% Done");
Expand Down Expand Up @@ -147,7 +147,7 @@ QVariant TransferListModel::headerData(int section, Qt::Orientation orientation,
case TR_DLLIMIT:
case TR_RATIO_LIMIT:
case TR_RATIO:
case TR_PRIORITY:
case TR_QUEUE_POSITION:
case TR_LAST_ACTIVITY:
return QVariant(Qt::AlignRight | Qt::AlignVCenter);
default:
Expand Down Expand Up @@ -178,7 +178,7 @@ QVariant TransferListModel::data(const QModelIndex &index, int role) const
switch (index.column()) {
case TR_NAME:
return torrent->name();
case TR_PRIORITY:
case TR_QUEUE_POSITION:
return torrent->queuePosition();
case TR_SIZE:
return torrent->wantedSize();
Expand Down
2 changes: 1 addition & 1 deletion src/gui/transferlistmodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class TransferListModel : public QAbstractListModel
public:
enum Column
{
TR_PRIORITY,
TR_QUEUE_POSITION,
TR_NAME,
TR_SIZE,
TR_TOTAL_SIZE,
Expand Down
Loading

0 comments on commit 7b31868

Please sign in to comment.