mirror of
https://github.com/qbittorrent/qBittorrent.git
synced 2024-11-23 17:59:44 +00:00
Fix priority up/down for multiple torrents at the same time (closes #692184)
This commit is contained in:
parent
89abde61d6
commit
c3b7aeadd7
@ -53,9 +53,12 @@
|
|||||||
#include <QRegExp>
|
#include <QRegExp>
|
||||||
#include <QFileDialog>
|
#include <QFileDialog>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include <queue>
|
||||||
|
|
||||||
#include "qinisettings.h"
|
#include "qinisettings.h"
|
||||||
|
|
||||||
|
using namespace libtorrent;
|
||||||
|
|
||||||
TransferListWidget::TransferListWidget(QWidget *parent, MainWindow *main_window, QBtSession *_BTSession):
|
TransferListWidget::TransferListWidget(QWidget *parent, MainWindow *main_window, QBtSession *_BTSession):
|
||||||
QTreeView(parent), BTSession(_BTSession), main_window(main_window) {
|
QTreeView(parent), BTSession(_BTSession), main_window(main_window) {
|
||||||
// Create and apply delegate
|
// Create and apply delegate
|
||||||
@ -312,24 +315,50 @@ void TransferListWidget::deleteVisibleTorrents() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void TransferListWidget::increasePrioSelectedTorrents() {
|
void TransferListWidget::increasePrioSelectedTorrents() {
|
||||||
|
qDebug() << Q_FUNC_INFO;
|
||||||
if(main_window->getCurrentTabWidget() != this) return;
|
if(main_window->getCurrentTabWidget() != this) return;
|
||||||
const QStringList hashes = getSelectedTorrentsHashes();
|
const QStringList hashes = getSelectedTorrentsHashes();
|
||||||
|
std::priority_queue<QPair<int, QTorrentHandle>, std::vector<QPair<int, QTorrentHandle> >, std::greater<QPair<int, QTorrentHandle> > > torrent_queue;
|
||||||
|
// Sort torrents by priority
|
||||||
foreach(const QString &hash, hashes) {
|
foreach(const QString &hash, hashes) {
|
||||||
QTorrentHandle h = BTSession->getTorrentHandle(hash);
|
try {
|
||||||
if(h.is_valid() && !h.is_seed()) {
|
QTorrentHandle h = BTSession->getTorrentHandle(hash);
|
||||||
|
if(!h.is_seed()) {
|
||||||
|
torrent_queue.push(qMakePair(h.queue_position(), h));
|
||||||
|
}
|
||||||
|
}catch(invalid_handle&){}
|
||||||
|
}
|
||||||
|
// Increase torrents priority (starting with the ones with highest priority)
|
||||||
|
while(!torrent_queue.empty()) {
|
||||||
|
QTorrentHandle h = torrent_queue.top().second;
|
||||||
|
try {
|
||||||
h.queue_position_up();
|
h.queue_position_up();
|
||||||
}
|
} catch(invalid_handle& h) {}
|
||||||
|
torrent_queue.pop();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void TransferListWidget::decreasePrioSelectedTorrents() {
|
void TransferListWidget::decreasePrioSelectedTorrents() {
|
||||||
|
qDebug() << Q_FUNC_INFO;
|
||||||
if(main_window->getCurrentTabWidget() != this) return;
|
if(main_window->getCurrentTabWidget() != this) return;
|
||||||
const QStringList hashes = getSelectedTorrentsHashes();
|
const QStringList hashes = getSelectedTorrentsHashes();
|
||||||
|
std::priority_queue<QPair<int, QTorrentHandle>, std::vector<QPair<int, QTorrentHandle> >, std::less<QPair<int, QTorrentHandle> > > torrent_queue;
|
||||||
|
// Sort torrents by priority
|
||||||
foreach(const QString &hash, hashes) {
|
foreach(const QString &hash, hashes) {
|
||||||
QTorrentHandle h = BTSession->getTorrentHandle(hash);
|
try {
|
||||||
if(h.is_valid() && !h.is_seed()) {
|
QTorrentHandle h = BTSession->getTorrentHandle(hash);
|
||||||
|
if(!h.is_seed()) {
|
||||||
|
torrent_queue.push(qMakePair(h.queue_position(), h));
|
||||||
|
}
|
||||||
|
}catch(invalid_handle&){}
|
||||||
|
}
|
||||||
|
// Decrease torrents priority (starting with the ones with lowest priority)
|
||||||
|
while(!torrent_queue.empty()) {
|
||||||
|
QTorrentHandle h = torrent_queue.top().second;
|
||||||
|
try {
|
||||||
h.queue_position_down();
|
h.queue_position_down();
|
||||||
}
|
} catch(invalid_handle& h) {}
|
||||||
|
torrent_queue.pop();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -45,6 +45,8 @@
|
|||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QRegExp>
|
#include <QRegExp>
|
||||||
#include <QTemporaryFile>
|
#include <QTemporaryFile>
|
||||||
|
#include <queue>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
using namespace libtorrent;
|
using namespace libtorrent;
|
||||||
|
|
||||||
@ -505,23 +507,25 @@ void HttpConnection::respondCommand(QString command)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if(command == "increasePrio") {
|
if(command == "increasePrio") {
|
||||||
QTorrentHandle h = QBtSession::instance()->getTorrentHandle(parser.post("hash"));
|
increaseTorrentsPriority(parser.post("hashes").split("|"));
|
||||||
if(h.is_valid()) h.queue_position_up();
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if(command == "decreasePrio") {
|
if(command == "decreasePrio") {
|
||||||
QTorrentHandle h = QBtSession::instance()->getTorrentHandle(parser.post("hash"));
|
decreaseTorrentsPriority(parser.post("hashes").split("|"));
|
||||||
if(h.is_valid()) h.queue_position_down();
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if(command == "topPrio") {
|
if(command == "topPrio") {
|
||||||
QTorrentHandle h = QBtSession::instance()->getTorrentHandle(parser.post("hash"));
|
foreach(const QString &hash, parser.post("hashes").split("|")) {
|
||||||
if(h.is_valid()) h.queue_position_top();
|
QTorrentHandle h = QBtSession::instance()->getTorrentHandle(hash);
|
||||||
|
if(h.is_valid()) h.queue_position_top();
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if(command == "bottomPrio") {
|
if(command == "bottomPrio") {
|
||||||
QTorrentHandle h = QBtSession::instance()->getTorrentHandle(parser.post("hash"));
|
foreach(const QString &hash, parser.post("hashes").split("|")) {
|
||||||
if(h.is_valid()) h.queue_position_bottom();
|
QTorrentHandle h = QBtSession::instance()->getTorrentHandle(hash);
|
||||||
|
if(h.is_valid()) h.queue_position_bottom();
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if(command == "recheck"){
|
if(command == "recheck"){
|
||||||
@ -550,3 +554,49 @@ void HttpConnection::recheckAllTorrents() {
|
|||||||
QBtSession::instance()->recheckTorrent(h.hash());
|
QBtSession::instance()->recheckTorrent(h.hash());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void HttpConnection::decreaseTorrentsPriority(const QStringList &hashes)
|
||||||
|
{
|
||||||
|
qDebug() << Q_FUNC_INFO << hashes;
|
||||||
|
std::priority_queue<QPair<int, QTorrentHandle>, std::vector<QPair<int, QTorrentHandle> >, std::less<QPair<int, QTorrentHandle> > > torrent_queue;
|
||||||
|
// Sort torrents by priority
|
||||||
|
foreach(const QString &hash, hashes) {
|
||||||
|
try {
|
||||||
|
QTorrentHandle h = QBtSession::instance()->getTorrentHandle(hash);
|
||||||
|
if(!h.is_seed()) {
|
||||||
|
torrent_queue.push(qMakePair(h.queue_position(), h));
|
||||||
|
}
|
||||||
|
}catch(invalid_handle&){}
|
||||||
|
}
|
||||||
|
// Decrease torrents priority (starting with the ones with lowest priority)
|
||||||
|
while(!torrent_queue.empty()) {
|
||||||
|
QTorrentHandle h = torrent_queue.top().second;
|
||||||
|
try {
|
||||||
|
h.queue_position_down();
|
||||||
|
} catch(invalid_handle& h) {}
|
||||||
|
torrent_queue.pop();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void HttpConnection::increaseTorrentsPriority(const QStringList &hashes)
|
||||||
|
{
|
||||||
|
qDebug() << Q_FUNC_INFO << hashes;
|
||||||
|
std::priority_queue<QPair<int, QTorrentHandle>, std::vector<QPair<int, QTorrentHandle> >, std::greater<QPair<int, QTorrentHandle> > > torrent_queue;
|
||||||
|
// Sort torrents by priority
|
||||||
|
foreach(const QString &hash, hashes) {
|
||||||
|
try {
|
||||||
|
QTorrentHandle h = QBtSession::instance()->getTorrentHandle(hash);
|
||||||
|
if(!h.is_seed()) {
|
||||||
|
torrent_queue.push(qMakePair(h.queue_position(), h));
|
||||||
|
}
|
||||||
|
}catch(invalid_handle&){}
|
||||||
|
}
|
||||||
|
// Increase torrents priority (starting with the ones with highest priority)
|
||||||
|
while(!torrent_queue.empty()) {
|
||||||
|
QTorrentHandle h = torrent_queue.top().second;
|
||||||
|
try {
|
||||||
|
h.queue_position_up();
|
||||||
|
} catch(invalid_handle& h) {}
|
||||||
|
torrent_queue.pop();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -67,6 +67,9 @@ protected slots:
|
|||||||
void handleDownloadFailure(QString, QString);
|
void handleDownloadFailure(QString, QString);
|
||||||
void recheckTorrent(QString hash);
|
void recheckTorrent(QString hash);
|
||||||
void recheckAllTorrents();
|
void recheckAllTorrents();
|
||||||
|
void decreaseTorrentsPriority(const QStringList& hashes);
|
||||||
|
void increaseTorrentsPriority(const QStringList& hashes);
|
||||||
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
HttpConnection(QTcpSocket *socket, HttpServer *httpserver);
|
HttpConnection(QTcpSocket *socket, HttpServer *httpserver);
|
||||||
|
@ -208,7 +208,7 @@ bool HttpServer::isAuthorized(QByteArray auth, QString method) const {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
QByteArray prop_nonce = regex_nonce.cap(1).toLocal8Bit();
|
QByteArray prop_nonce = regex_nonce.cap(1).toLocal8Bit();
|
||||||
qDebug("prop nonce is: %s", prop_nonce.data());
|
//qDebug("prop nonce is: %s", prop_nonce.data());
|
||||||
// get uri
|
// get uri
|
||||||
QRegExp regex_uri(".*uri=\"([^\"]+)\".*");
|
QRegExp regex_uri(".*uri=\"([^\"]+)\".*");
|
||||||
if(regex_uri.indexIn(auth) < 0) {
|
if(regex_uri.indexIn(auth) < 0) {
|
||||||
@ -216,7 +216,7 @@ bool HttpServer::isAuthorized(QByteArray auth, QString method) const {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
QByteArray prop_uri = regex_uri.cap(1).toLocal8Bit();
|
QByteArray prop_uri = regex_uri.cap(1).toLocal8Bit();
|
||||||
qDebug("prop uri is: %s", prop_uri.data());
|
//qDebug("prop uri is: %s", prop_uri.data());
|
||||||
// get response
|
// get response
|
||||||
QRegExp regex_response(".*response=[\"]?([\\w=]+)[\"]?.*");
|
QRegExp regex_response(".*response=[\"]?([\\w=]+)[\"]?.*");
|
||||||
if(regex_response.indexIn(auth) < 0) {
|
if(regex_response.indexIn(auth) < 0) {
|
||||||
@ -224,7 +224,7 @@ bool HttpServer::isAuthorized(QByteArray auth, QString method) const {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
QByteArray prop_response = regex_response.cap(1).toLocal8Bit();
|
QByteArray prop_response = regex_response.cap(1).toLocal8Bit();
|
||||||
qDebug("prop response is: %s", prop_response.data());
|
//qDebug("prop response is: %s", prop_response.data());
|
||||||
// Compute correct reponse
|
// Compute correct reponse
|
||||||
QCryptographicHash md5_ha2(QCryptographicHash::Md5);
|
QCryptographicHash md5_ha2(QCryptographicHash::Md5);
|
||||||
md5_ha2.addData(method.toLocal8Bit() + ":" + prop_uri);
|
md5_ha2.addData(method.toLocal8Bit() + ":" + prop_uri);
|
||||||
@ -239,21 +239,21 @@ bool HttpServer::isAuthorized(QByteArray auth, QString method) const {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
QByteArray prop_nc = regex_nc.cap(1).toLocal8Bit();
|
QByteArray prop_nc = regex_nc.cap(1).toLocal8Bit();
|
||||||
qDebug("prop nc is: %s", prop_nc.data());
|
//qDebug("prop nc is: %s", prop_nc.data());
|
||||||
QRegExp regex_cnonce(".*cnonce=[\"]?([\\w=]+)[\"]?.*");
|
QRegExp regex_cnonce(".*cnonce=[\"]?([\\w=]+)[\"]?.*");
|
||||||
if(regex_cnonce.indexIn(auth) < 0) {
|
if(regex_cnonce.indexIn(auth) < 0) {
|
||||||
qDebug("AUTH-PROB: qop but missing cnonce");
|
qDebug("AUTH-PROB: qop but missing cnonce");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
QByteArray prop_cnonce = regex_cnonce.cap(1).toLocal8Bit();
|
QByteArray prop_cnonce = regex_cnonce.cap(1).toLocal8Bit();
|
||||||
qDebug("prop cnonce is: %s", prop_cnonce.data());
|
//qDebug("prop cnonce is: %s", prop_cnonce.data());
|
||||||
QRegExp regex_qop(".*qop=[\"]?(\\w+)[\"]?.*");
|
QRegExp regex_qop(".*qop=[\"]?(\\w+)[\"]?.*");
|
||||||
if(regex_qop.indexIn(auth) < 0) {
|
if(regex_qop.indexIn(auth) < 0) {
|
||||||
qDebug("AUTH-PROB: missing qop");
|
qDebug("AUTH-PROB: missing qop");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
QByteArray prop_qop = regex_qop.cap(1).toLocal8Bit();
|
QByteArray prop_qop = regex_qop.cap(1).toLocal8Bit();
|
||||||
qDebug("prop qop is: %s", prop_qop.data());
|
//qDebug("prop qop is: %s", prop_qop.data());
|
||||||
md5_ha.addData(password_ha1+":"+prop_nonce+":"+prop_nc+":"+prop_cnonce+":"+prop_qop+":"+ha2);
|
md5_ha.addData(password_ha1+":"+prop_nonce+":"+prop_nc+":"+prop_cnonce+":"+prop_qop+":"+ha2);
|
||||||
response = md5_ha.result().toHex();
|
response = md5_ha.result().toHex();
|
||||||
} else {
|
} else {
|
||||||
@ -261,7 +261,7 @@ bool HttpServer::isAuthorized(QByteArray auth, QString method) const {
|
|||||||
md5_ha.addData(password_ha1+":"+prop_nonce+":"+ha2);
|
md5_ha.addData(password_ha1+":"+prop_nonce+":"+ha2);
|
||||||
response = md5_ha.result().toHex();
|
response = md5_ha.result().toHex();
|
||||||
}
|
}
|
||||||
qDebug("AUTH: comparing reponses: (%d)", static_cast<int>(prop_response == response));
|
//qDebug("AUTH: comparing reponses: (%d)", static_cast<int>(prop_response == response));
|
||||||
return prop_response == response;
|
return prop_response == response;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -203,7 +203,7 @@ initializeWindows = function(){
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
['pause','resume','decreasePrio','increasePrio', 'topPrio', 'bottomPrio', 'recheck'].each(function(item) {
|
['pause','resume', 'recheck'].each(function(item) {
|
||||||
addClickEvent(item, function(e){
|
addClickEvent(item, function(e){
|
||||||
new Event(e).stop();
|
new Event(e).stop();
|
||||||
var h = myTable.selectedIds();
|
var h = myTable.selectedIds();
|
||||||
@ -219,13 +219,18 @@ initializeWindows = function(){
|
|||||||
new Request({url: '/command/'+item+'all'}).send();
|
new Request({url: '/command/'+item+'all'}).send();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
['decreasePrio','increasePrio', 'topPrio', 'bottomPrio'].each(function(item) {
|
||||||
|
addClickEvent(item, function(e){
|
||||||
|
new Event(e).stop();
|
||||||
|
setPriorityFN(item);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
setPriorityFN = function(cmd) {
|
setPriorityFN = function(cmd) {
|
||||||
var h = myTable.selectedIds();
|
var h = myTable.selectedIds();
|
||||||
if(h.length){
|
if(h.length) {
|
||||||
h.each(function(hash, index){
|
new Request({url: '/command/'+cmd, method: 'post', data: {hashes: h.join("|")}}).send();
|
||||||
new Request({url: '/command/'+cmd, method: 'post', data: {hash: hash}}).send();
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user