From f3729fbae67f1460a214567d2985b20aaf1b6ee3 Mon Sep 17 00:00:00 2001 From: Christophe Dumez Date: Sun, 2 Nov 2008 10:47:59 +0000 Subject: [PATCH] - Use libtorrent queueing system (probably buggy and queueing currently does not work for seeds) --- src/GUI.cpp | 63 ++++--- src/bittorrent.cpp | 419 ++--------------------------------------- src/bittorrent.h | 13 -- src/options.ui | 188 +++++++++--------- src/options_imp.cpp | 14 +- src/options_imp.h | 1 + src/qtorrenthandle.cpp | 16 ++ src/qtorrenthandle.h | 3 + 8 files changed, 182 insertions(+), 535 deletions(-) diff --git a/src/GUI.cpp b/src/GUI.cpp index 9da24adc6..8031e3de8 100644 --- a/src/GUI.cpp +++ b/src/GUI.cpp @@ -1031,6 +1031,39 @@ void GUI::configureSession(bool deleteOptions) { } sessionSettings.upnp_ignore_nonrouters = true; sessionSettings.use_dht_as_fallback = false; + // Queueing System + if(options->isQueueingSystemEnabled()) { + if(!BTSession->isQueueingEnabled()) { + downloadingTorrentTab->hidePriorityColumn(false); + finishedTorrentTab->hidePriorityColumn(false); + actionDecreasePriority->setVisible(true); + actionIncreasePriority->setVisible(true); + prioSeparator->setVisible(true); + prioSeparator2->setVisible(true); + toolBar->layout()->setSpacing(7); + } + int max_torrents = options->getMaxActiveTorrents(); + int max_downloads = options->getMaxActiveDownloads(); + int max_seeds = options->getMaxActiveUploads(); + sessionSettings.active_limit = max_torrents; + sessionSettings.active_downloads = max_downloads; + sessionSettings.active_seeds = max_seeds; + BTSession->setQueueingEnabled(true); + } else { + if(BTSession->isQueueingEnabled()) { + sessionSettings.active_limit = -1; + sessionSettings.active_downloads = -1; + sessionSettings.active_seeds = -1; + BTSession->setQueueingEnabled(false); + downloadingTorrentTab->hidePriorityColumn(true); + finishedTorrentTab->hidePriorityColumn(true); + actionDecreasePriority->setVisible(false); + actionIncreasePriority->setVisible(false); + prioSeparator->setVisible(false); + prioSeparator2->setVisible(false); + toolBar->layout()->setSpacing(7); + } + } BTSession->setSessionSettings(sessionSettings); // Bittorrent // * Max connections limit @@ -1107,36 +1140,6 @@ void GUI::configureSession(bool deleteOptions) { } else { displayRSSTab(false); } - // Queueing System - if(options->isQueueingSystemEnabled()) { - if(!BTSession->isQueueingEnabled()) { - downloadingTorrentTab->hidePriorityColumn(false); - finishedTorrentTab->hidePriorityColumn(false); - actionDecreasePriority->setVisible(true); - actionIncreasePriority->setVisible(true); - prioSeparator->setVisible(true); - prioSeparator2->setVisible(true); - toolBar->layout()->setSpacing(7); - } - int max_torrents = options->getMaxActiveTorrents(); - int max_downloads = options->getMaxActiveDownloads(); - if(max_torrents < max_downloads) - max_torrents = max_downloads; - BTSession->setMaxActiveTorrents(max_torrents); - BTSession->setMaxActiveDownloads(max_downloads); - BTSession->setQueueingEnabled(true); - } else { - if(BTSession->isQueueingEnabled()) { - BTSession->setQueueingEnabled(false); - downloadingTorrentTab->hidePriorityColumn(true); - finishedTorrentTab->hidePriorityColumn(true); - actionDecreasePriority->setVisible(false); - actionIncreasePriority->setVisible(false); - prioSeparator->setVisible(false); - prioSeparator2->setVisible(false); - toolBar->layout()->setSpacing(7); - } - } // Clean up if(deleteOptions) { delete options; diff --git a/src/bittorrent.cpp b/src/bittorrent.cpp index b3436acf5..dc514136d 100644 --- a/src/bittorrent.cpp +++ b/src/bittorrent.cpp @@ -70,10 +70,6 @@ bittorrent::bittorrent() : timerScan(0), DHTEnabled(false), preAllocateAll(false connect(downloader, SIGNAL(downloadFailure(QString, QString)), this, SLOT(handleDownloadFailure(QString, QString))); BigRatioTimer = 0; filterParser = 0; - downloadQueue = 0; - queuedDownloads = 0; - uploadQueue = 0; - queuedUploads = 0; qDebug("* BTSession constructed"); } @@ -99,16 +95,6 @@ bittorrent::~bittorrent() { if(filterParser) delete filterParser; delete downloader; - if(queueingEnabled) { - Q_ASSERT(downloadQueue); - delete downloadQueue; - Q_ASSERT(queuedDownloads); - delete queuedDownloads; - Q_ASSERT(uploadQueue); - delete uploadQueue; - Q_ASSERT(queuedUploads); - delete queuedUploads; - } // Delete BT session qDebug("Deleting session"); delete s; @@ -171,161 +157,41 @@ bool bittorrent::isQueueingEnabled() const { return queueingEnabled; } -void bittorrent::setMaxActiveDownloads(int val) { - if(val != maxActiveDownloads) { - maxActiveDownloads = val; - if(queueingEnabled) { - updateDownloadQueue(); - updateUploadQueue(); - } - } -} - -void bittorrent::setMaxActiveTorrents(int val) { - if(val != maxActiveTorrents) { - maxActiveTorrents = val; - if(queueingEnabled) { - updateDownloadQueue(); - updateUploadQueue(); - } - } -} - void bittorrent::increaseDlTorrentPriority(QString hash) { Q_ASSERT(queueingEnabled); - int index = downloadQueue->indexOf(hash); - Q_ASSERT(index != -1); - if(index > 0) { - downloadQueue->swap(index-1, index); - saveTorrentPriority(hash, index-1); - saveTorrentPriority(downloadQueue->at(index), index); - updateDownloadQueue(); - } + QTorrentHandle h = getTorrentHandle(hash); + h.queue_position_up(); } void bittorrent::increaseUpTorrentPriority(QString hash) { Q_ASSERT(queueingEnabled); - int index = uploadQueue->indexOf(hash); - Q_ASSERT(index != -1); - if(index > 0) { - uploadQueue->swap(index-1, index); - saveTorrentPriority(hash, index-1); - saveTorrentPriority(uploadQueue->at(index), index); - updateUploadQueue(); - } + QTorrentHandle h = getTorrentHandle(hash); + h.queue_position_up(); } void bittorrent::decreaseDlTorrentPriority(QString hash) { Q_ASSERT(queueingEnabled); - int index = downloadQueue->indexOf(hash); - Q_ASSERT(index != -1); - if(index >= 0 && index < (downloadQueue->size()-1)) { - downloadQueue->swap(index+1, index); - saveTorrentPriority(hash, index+1); - saveTorrentPriority(downloadQueue->at(index), index); - updateDownloadQueue(); - } + QTorrentHandle h = getTorrentHandle(hash); + h.queue_position_down(); } void bittorrent::decreaseUpTorrentPriority(QString hash) { Q_ASSERT(queueingEnabled); - int index = uploadQueue->indexOf(hash); - Q_ASSERT(index != -1); - if(index >= 0 && index < (uploadQueue->size()-1)) { - uploadQueue->swap(index+1, index); - saveTorrentPriority(hash, index+1); - saveTorrentPriority(uploadQueue->at(index), index); - updateUploadQueue(); - } -} - -void bittorrent::saveTorrentPriority(QString hash, int prio) { - // Write .queued file - QFile prio_file(misc::qBittorrentPath()+"BT_backup"+QDir::separator()+hash+".prio"); - prio_file.open(QIODevice::WriteOnly | QIODevice::Text); - prio_file.write(QByteArray::number(prio)); - prio_file.close(); -} - -void bittorrent::fixTorrentPriorities() { - Q_ASSERT(queueingEnabled); - // Load priorities - QList > tmp_list; - QStringList noprio; - foreach(QString hash, unfinishedTorrents) { - int prio = loadTorrentPriority(hash); - if(prio != -1) { - misc::insertSort2(tmp_list, QPair(prio,hash), Qt::AscendingOrder); - } else { - noprio << hash; - } - } - downloadQueue->clear(); - QPair couple; - foreach(couple, tmp_list) { - downloadQueue->append(couple.second); - } - (*downloadQueue)<clear(); - updateDownloadQueue(); - foreach(QString hash, finishedTorrents) { - int prio = loadTorrentPriority(hash); - if(prio != -1) { - misc::insertSort2(tmp_list, QPair(prio,hash), Qt::AscendingOrder); - } else { - noprio << hash; - } - } - uploadQueue->clear(); - foreach(couple, tmp_list) { - uploadQueue->append(couple.second); - } - (*uploadQueue)<clear(); - updateUploadQueue(); -} - -int bittorrent::loadTorrentPriority(QString hash) { - // Read .prio file - QFile prio_file(misc::qBittorrentPath()+"BT_backup"+QDir::separator()+hash+".prio"); - if(prio_file.open(QIODevice::ReadOnly | QIODevice::Text)) { - bool ok = false; - int prio = prio_file.readAll().toInt(&ok); - prio_file.close(); - if(!ok) { - qDebug("Could not convert prio to integer !!!!!!!"); - return -1; - } - qDebug("Prio is %d", prio); - return prio; - } - qDebug(".prio file does not exist !!!!!"); - return -1; + QTorrentHandle h = getTorrentHandle(hash); + h.queue_position_down(); } bool bittorrent::isDownloadQueued(QString hash) const { Q_ASSERT(queueingEnabled); - return queuedDownloads->contains(hash); + QTorrentHandle h = getTorrentHandle(hash); + return h.queue_position() >= 0; } bool bittorrent::isUploadQueued(QString hash) const { + // FIXME: libtorrent does not support this. Q_ASSERT(queueingEnabled); - return queuedUploads->contains(hash); + QTorrentHandle h = getTorrentHandle(hash); + return h.queue_position() >= 0; } void bittorrent::setUploadLimit(QString hash, long val) { @@ -336,14 +202,6 @@ void bittorrent::setUploadLimit(QString hash, long val) { saveTorrentSpeedLimits(hash); } -int bittorrent::getMaximumActiveDownloads() const { - return maxActiveDownloads; -} - -int bittorrent::getMaximumActiveTorrents() const { - return maxActiveTorrents; -} - void bittorrent::handleDownloadFailure(QString url, QString reason) { emit downloadFromUrlFailure(url, reason); } @@ -356,171 +214,19 @@ void bittorrent::setQueueingEnabled(bool enable) { if(queueingEnabled != enable) { qDebug("Queueing system is changing state..."); queueingEnabled = enable; - if(enable) { - downloadQueue = new QStringList(); - uploadQueue = new QStringList(); - queuedUploads = new QStringList(); - queuedDownloads = new QStringList(); - fixTorrentPriorities(); - } else { - // Unqueue torrents - foreach(QString hash, *queuedDownloads) { - QTorrentHandle h = getTorrentHandle(hash); - h.resume(); - if(QFile::exists(misc::qBittorrentPath()+"BT_backup"+QDir::separator()+hash+".queued")) { - QFile::remove(misc::qBittorrentPath()+"BT_backup"+QDir::separator()+hash+".queued"); - } - if(QFile::exists(misc::qBittorrentPath()+"BT_backup"+QDir::separator()+hash+".prio")) { - QFile::remove(misc::qBittorrentPath()+"BT_backup"+QDir::separator()+hash+".prio"); - } - } - foreach(QString hash, *queuedUploads) { - QTorrentHandle h = getTorrentHandle(hash); - h.resume(); - if(QFile::exists(misc::qBittorrentPath()+"BT_backup"+QDir::separator()+hash+".queued")) { - QFile::remove(misc::qBittorrentPath()+"BT_backup"+QDir::separator()+hash+".queued"); - } - if(QFile::exists(misc::qBittorrentPath()+"BT_backup"+QDir::separator()+hash+".prio")) { - QFile::remove(misc::qBittorrentPath()+"BT_backup"+QDir::separator()+hash+".prio"); - } - } - delete downloadQueue; - downloadQueue = 0; - delete queuedDownloads; - queuedDownloads = 0; - delete uploadQueue; - uploadQueue = 0; - delete queuedUploads; - queuedUploads = 0; - } } } int bittorrent::getDlTorrentPriority(QString hash) const { - Q_ASSERT(downloadQueue != 0); - return downloadQueue->indexOf(hash); -} - -int bittorrent::getUpTorrentPriority(QString hash) const { - Q_ASSERT(uploadQueue != 0); - return uploadQueue->indexOf(hash); -} - -void bittorrent::updateUploadQueue() { Q_ASSERT(queueingEnabled); - bool change = false; - int maxActiveUploads = maxActiveTorrents - currentActiveDownloads; - int currentActiveUploads = 0; - // Check if it is necessary to queue uploads - foreach(QString hash, *uploadQueue) { - QTorrentHandle h = getTorrentHandle(hash); - if(!h.is_paused()) { - if(currentActiveUploads < maxActiveUploads) { - ++currentActiveUploads; - } else { - // Queue it - h.pause(); - change = true; - if(!queuedUploads->contains(hash)) { - queuedUploads->append(hash); - // Create .queued file - if(!QFile::exists(misc::qBittorrentPath()+"BT_backup"+QDir::separator()+hash+".queued")) { - QFile queued_file(misc::qBittorrentPath()+"BT_backup"+QDir::separator()+hash+".queued"); - queued_file.open(QIODevice::WriteOnly | QIODevice::Text); - queued_file.close(); - } - } - } - } else { - if(currentActiveUploads < maxActiveUploads && isUploadQueued(hash)) { - QTorrentHandle h = getTorrentHandle(hash); - h.resume(); - change = true; - queuedUploads->removeAll(hash); - QFile::remove(misc::qBittorrentPath()+"BT_backup"+QDir::separator()+hash+".queued"); - ++currentActiveUploads; - } - } - } - if(currentActiveUploads < maxActiveUploads) { - // Could not fill download slots, unqueue torrents - foreach(QString hash, *uploadQueue) { - if(uploadQueue->size() != 0 && currentActiveUploads < maxActiveUploads) { - if(queuedUploads->contains(hash)) { - QTorrentHandle h = getTorrentHandle(hash); - h.resume(); - change = true; - queuedUploads->removeAll(hash); - QFile::remove(misc::qBittorrentPath()+"BT_backup"+QDir::separator()+hash+".queued"); - ++currentActiveUploads; - } - } else { - break; - } - } - } - if(change) { - emit updateFinishedTorrentNumber(); - emit forceFinishedListUpdate(); - } + QTorrentHandle h = getTorrentHandle(hash); + return h.queue_position(); } -void bittorrent::updateDownloadQueue() { +int bittorrent::getUpTorrentPriority(QString hash) const { Q_ASSERT(queueingEnabled); - bool change = false; - currentActiveDownloads = 0; - // Check if it is necessary to queue torrents - foreach(QString hash, *downloadQueue) { - QTorrentHandle h = getTorrentHandle(hash); - if(!h.is_paused()) { - if(currentActiveDownloads < maxActiveDownloads) { - ++currentActiveDownloads; - } else { - // Queue it - h.pause(); - change = true; - if(!queuedDownloads->contains(hash)) { - queuedDownloads->append(hash); - // Create .queued file - if(!QFile::exists(misc::qBittorrentPath()+"BT_backup"+QDir::separator()+hash+".queued")) { - QFile queued_file(misc::qBittorrentPath()+"BT_backup"+QDir::separator()+hash+".queued"); - queued_file.open(QIODevice::WriteOnly | QIODevice::Text); - queued_file.close(); - } - } - } - } else { - if(currentActiveDownloads < maxActiveDownloads && isDownloadQueued(hash)) { - QTorrentHandle h = getTorrentHandle(hash); - h.resume(); - change = true; - queuedDownloads->removeAll(hash); - QFile::remove(misc::qBittorrentPath()+"BT_backup"+QDir::separator()+hash+".queued"); - ++currentActiveDownloads; - } - } - } - if(currentActiveDownloads < maxActiveDownloads) { - // Could not fill download slots, unqueue torrents - foreach(QString hash, *downloadQueue) { - if(downloadQueue->size() != 0 && currentActiveDownloads < maxActiveDownloads) { - if(queuedDownloads->contains(hash)) { - QTorrentHandle h = getTorrentHandle(hash); - h.resume(); - change = true; - queuedDownloads->removeAll(hash); - QFile::remove(misc::qBittorrentPath()+"BT_backup"+QDir::separator()+hash+".queued"); - ++currentActiveDownloads; - } - } else { - break; - } - } - } - if(change) { - emit updateUnfinishedTorrentNumber(); - emit forceUnfinishedListUpdate(); - } + QTorrentHandle h = getTorrentHandle(hash); + return h.queue_position(); } // Calculate the ETA using GASA @@ -632,23 +338,6 @@ void bittorrent::deleteTorrent(QString hash, bool permanent) { std::cerr << "Error: Torrent " << hash.toStdString() << " is neither in finished or unfinished list\n"; } } - // Remove it from downloadQueue or UploadQueue - if(queueingEnabled) { - if(downloadQueue->contains(hash)) { - downloadQueue->removeAll(hash); - queuedDownloads->removeAll(hash); - updateDownloadQueue(); - } - if(uploadQueue->contains(hash)) { - uploadQueue->removeAll(hash); - queuedUploads->removeAll(hash); - updateUploadQueue(); - } - } - if(QFile::exists(misc::qBittorrentPath()+"BT_backup"+QDir::separator()+hash+".prio")) - QFile::remove(misc::qBittorrentPath()+"BT_backup"+QDir::separator()+hash+".prio"); - if(QFile::exists(misc::qBittorrentPath()+"BT_backup"+QDir::separator()+hash+".queued")) - QFile::remove(misc::qBittorrentPath()+"BT_backup"+QDir::separator()+hash+".queued"); if(permanent) addConsoleMessage(tr("'%1' was removed permanently.", "'xxx.avi' was removed permanently.").arg(fileName)); else @@ -686,24 +375,6 @@ void bittorrent::setUnfinishedTorrent(QString hash) { TorrentsStartTime[hash] = QDateTime::currentDateTime(); } } - if(queueingEnabled) { - // Remove it from uploadQueue - if(uploadQueue->contains(hash)) { - uploadQueue->removeAll(hash); - queuedUploads->removeAll(hash); - /*if(QFile::exists(misc::qBittorrentPath()+"BT_backup"+QDir::separator()+hash+".prio")) - QFile::remove(misc::qBittorrentPath()+"BT_backup"+QDir::separator()+hash+".prio"); - if(QFile::exists(misc::qBittorrentPath()+"BT_backup"+QDir::separator()+hash+".queued")) - QFile::remove(misc::qBittorrentPath()+"BT_backup"+QDir::separator()+hash+".queued");*/ - updateUploadQueue(); - } - // Add it to downloadQueue - if(!downloadQueue->contains(hash)) { - downloadQueue->append(hash); - saveTorrentPriority(hash, downloadQueue->size()-1); - updateDownloadQueue(); - } - } //emit torrentSwitchedtoUnfinished(hash); } @@ -726,20 +397,6 @@ void bittorrent::setFinishedTorrent(QString hash) { TorrentsStartTime.remove(hash); TorrentsStartData.remove(hash); } - // Remove it from - if(queueingEnabled) { - downloadQueue->removeAll(hash); - queuedDownloads->removeAll(hash); - /*if(QFile::exists(misc::qBittorrentPath()+"BT_backup"+QDir::separator()+hash+".prio")) - QFile::remove(misc::qBittorrentPath()+"BT_backup"+QDir::separator()+hash+".prio"); - if(QFile::exists(misc::qBittorrentPath()+"BT_backup"+QDir::separator()+hash+".queued")) - QFile::remove(misc::qBittorrentPath()+"BT_backup"+QDir::separator()+hash+".queued");*/ - updateDownloadQueue(); - if(!uploadQueue->contains(hash)) { - uploadQueue->append(hash); - updateUploadQueue(); - } - } //emit torrentSwitchedtoFinished(hash); } @@ -752,30 +409,13 @@ bool bittorrent::pauseTorrent(QString hash) { change = true; // Save fast resume data saveFastResumeData(hash); - if(queueingEnabled) { - updateDownloadQueue(); - updateUploadQueue(); - } qDebug("Torrent paused successfully"); emit pausedTorrent(hash); }else{ if(!h.is_valid()) { qDebug("Could not pause torrent %s, reason: invalid", hash.toUtf8().data()); }else{ - if(queueingEnabled && (isDownloadQueued(hash)||isUploadQueued(hash))) { - // Remove it from queued list if present - if(queuedDownloads->contains(hash)) - queuedDownloads->removeAll(hash); - if(queuedUploads->contains(hash)) - queuedUploads->removeAll(hash); - if(QFile::exists(misc::qBittorrentPath()+"BT_backup"+QDir::separator()+hash+".queued")) - QFile::remove(misc::qBittorrentPath()+"BT_backup"+QDir::separator()+hash+".queued"); - updateDownloadQueue(); - updateUploadQueue(); - change = true; - } else { qDebug("Could not pause torrent %s, reason: already paused", hash.toUtf8().data()); - } } } // Create .paused file if necessary @@ -799,24 +439,18 @@ bool bittorrent::resumeTorrent(QString hash) { bool change = false; QTorrentHandle h = getTorrentHandle(hash); if(h.is_valid() && h.is_paused()) { - if(!(queueingEnabled && (isDownloadQueued(hash)||isUploadQueued(hash)))) { // Save Addition DateTime if(calculateETA) { - TorrentsStartData[hash] = h.total_payload_download(); - TorrentsStartTime[hash] = QDateTime::currentDateTime(); + TorrentsStartData[hash] = h.total_payload_download(); + TorrentsStartTime[hash] = QDateTime::currentDateTime(); } h.resume(); change = true; emit resumedTorrent(hash); - } } // Delete .paused file if(QFile::exists(misc::qBittorrentPath()+"BT_backup"+QDir::separator()+hash+".paused")) QFile::remove(misc::qBittorrentPath()+"BT_backup"+QDir::separator()+hash+".paused"); - if(queueingEnabled) { - updateDownloadQueue(); - updateUploadQueue(); - } if(change) { addConsoleMessage(tr("'%1' resumed.", "e.g: xxx.avi resumed.").arg(h.name())); } @@ -1013,18 +647,8 @@ void bittorrent::addTorrent(QString path, bool fromScanDir, QString from_url, bo } if(QFile::exists(misc::qBittorrentPath()+"BT_backup"+QDir::separator()+hash+".finished")) { finishedTorrents << hash; - if(!resumed && queueingEnabled) { - uploadQueue->append(hash); - saveTorrentPriority(hash, uploadQueue->size()-1); - updateUploadQueue(); - } }else{ unfinishedTorrents << hash; - if(!resumed && queueingEnabled) { - downloadQueue->append(hash); - saveTorrentPriority(hash, downloadQueue->size()-1); - updateDownloadQueue(); - } } // If download from url, remove temp file if(!from_url.isNull()) QFile::remove(file); @@ -1864,8 +1488,5 @@ void bittorrent::resumeUnfinishedTorrents() { foreach(fileName, filePaths) { addTorrent(fileName, false, QString(), true); } - if(queueingEnabled) { - fixTorrentPriorities(); - } qDebug("Unfinished torrents resumed"); } diff --git a/src/bittorrent.h b/src/bittorrent.h index 558dd8c21..d89f2990e 100644 --- a/src/bittorrent.h +++ b/src/bittorrent.h @@ -74,13 +74,6 @@ class bittorrent : public QObject { QString filterPath; int folderScanInterval; // in seconds bool queueingEnabled; - int maxActiveDownloads; - int maxActiveTorrents; - int currentActiveDownloads; - QStringList *downloadQueue; - QStringList *queuedDownloads; - QStringList *uploadQueue; - QStringList *queuedUploads; bool calculateETA; QStringList url_skippingDlg; @@ -145,13 +138,10 @@ class bittorrent : public QObject { void loadTorrentSpeedLimits(QString hash); void handleDownloadFailure(QString url, QString reason); void loadWebSeeds(QString fileHash); - void updateDownloadQueue(); - void updateUploadQueue(); void increaseDlTorrentPriority(QString hash); void decreaseDlTorrentPriority(QString hash); void increaseUpTorrentPriority(QString hash); void decreaseUpTorrentPriority(QString hash); - void saveTorrentPriority(QString hash, int prio); void downloadUrlAndSkipDialog(QString); // Session configuration - Setters void setListeningPortsRange(std::pair ports); @@ -178,12 +168,9 @@ class bittorrent : public QObject { void enableLSD(bool b); bool enableDHT(bool b); void setTimerScanInterval(int secs); - void setMaxActiveDownloads(int val); - void setMaxActiveTorrents(int val); void setETACalculation(bool enable); void addConsoleMessage(QString msg, QColor color=QApplication::palette().color(QPalette::WindowText)); void addPeerBanMessage(QString msg, bool from_ipfilter); - void fixTorrentPriorities(); protected slots: void scanDirectory(); diff --git a/src/options.ui b/src/options.ui index d6bc02f30..7c0a646e1 100644 --- a/src/options.ui +++ b/src/options.ui @@ -22,16 +22,7 @@ 6 - - 9 - - - 9 - - - 9 - - + 9 @@ -87,7 +78,8 @@ General - :/Icons/star.png + + :/Icons/star.png:/Icons/star.png @@ -120,7 +112,7 @@ Qt::Horizontal - + 40 20 @@ -189,7 +181,7 @@ Qt::Horizontal - + 40 20 @@ -260,7 +252,7 @@ Qt::Horizontal - + 40 20 @@ -328,7 +320,7 @@ Qt::Vertical - + 623 20 @@ -343,7 +335,8 @@ Downloads - :/Icons/download.png + + :/Icons/download.png:/Icons/download.png @@ -370,16 +363,7 @@ 6 - - 0 - - - 0 - - - 0 - - + 0 @@ -387,16 +371,7 @@ 6 - - 0 - - - 0 - - - 0 - - + 0 @@ -456,7 +431,7 @@ Qt::Horizontal - + 40 20 @@ -500,16 +475,7 @@ 6 - - 0 - - - 0 - - - 0 - - + 0 @@ -619,7 +585,7 @@ Qt::Horizontal - + 40 20 @@ -662,7 +628,7 @@ Qt::Horizontal - + 40 20 @@ -682,7 +648,8 @@ Connection - :/Icons/connection.png + + :/Icons/connection.png:/Icons/connection.png @@ -745,7 +712,7 @@ Qt::Horizontal - + 20 20 @@ -904,7 +871,7 @@ Qt::Horizontal - + 40 20 @@ -922,7 +889,7 @@ Qt::Vertical - + 623 121 @@ -937,7 +904,8 @@ Bittorrent - :/Icons/bt_settings.png + + :/Icons/bt_settings.png:/Icons/bt_settings.png @@ -984,7 +952,7 @@ Qt::Horizontal - + 40 20 @@ -1029,7 +997,7 @@ Qt::Horizontal - + 40 20 @@ -1071,7 +1039,7 @@ Qt::Horizontal - + 40 20 @@ -1160,7 +1128,7 @@ Qt::Horizontal - + 40 20 @@ -1223,7 +1191,7 @@ Qt::Horizontal - + 40 20 @@ -1277,7 +1245,7 @@ Qt::Horizontal - + 40 20 @@ -1295,7 +1263,7 @@ Qt::Vertical - + 20 40 @@ -1310,7 +1278,8 @@ Proxy - :/Icons/proxy.png + + :/Icons/proxy.png:/Icons/proxy.png @@ -1396,7 +1365,7 @@ Qt::Horizontal - + 21 29 @@ -1485,7 +1454,7 @@ Qt::Horizontal - + 40 20 @@ -1591,7 +1560,7 @@ Qt::Horizontal - + 21 29 @@ -1680,7 +1649,7 @@ Qt::Horizontal - + 40 20 @@ -1784,9 +1753,10 @@ Misc - :/Icons/configure.png + + :/Icons/configure.png:/Icons/configure.png - + @@ -1802,7 +1772,8 @@ Activate IP Filtering - :/Icons/filter.png + + :/Icons/filter.png:/Icons/filter.png @@ -1925,7 +1896,7 @@ Qt::Horizontal - + 40 20 @@ -1959,7 +1930,7 @@ Qt::Horizontal - + 40 20 @@ -1984,7 +1955,7 @@ Torrent queueing - + @@ -1995,7 +1966,7 @@ - + false @@ -2025,7 +1996,50 @@ Qt::Horizontal - + + + 40 + 20 + + + + + + + + + + + + false + + + Maximum active uploads: + + + + + + + false + + + 1 + + + 999 + + + 3 + + + + + + + Qt::Horizontal + + 40 20 @@ -2068,7 +2082,7 @@ Qt::Horizontal - + 381 20 @@ -2086,7 +2100,7 @@ Qt::Vertical - + 623 20 @@ -2101,7 +2115,8 @@ Web UI - :/Icons/password.png + + :/Icons/password.png:/Icons/password.png @@ -2154,7 +2169,7 @@ Qt::Horizontal - + 21 29 @@ -2239,7 +2254,7 @@ Qt::Horizontal - + 198 57 @@ -2255,7 +2270,7 @@ Qt::Vertical - + 623 41 @@ -2272,16 +2287,7 @@ 6 - - 0 - - - 0 - - - 0 - - + 0 @@ -2290,7 +2296,7 @@ Qt::Horizontal - QDialogButtonBox::Apply|QDialogButtonBox::Cancel|QDialogButtonBox::NoButton|QDialogButtonBox::Ok + QDialogButtonBox::Apply|QDialogButtonBox::Cancel|QDialogButtonBox::Ok true diff --git a/src/options_imp.cpp b/src/options_imp.cpp index 9d6223dc9..1520130e7 100644 --- a/src/options_imp.cpp +++ b/src/options_imp.cpp @@ -385,6 +385,7 @@ void options_imp::saveOptions(){ settings.beginGroup("Queueing"); settings.setValue(QString::fromUtf8("QueueingEnabled"), isQueueingSystemEnabled()); settings.setValue(QString::fromUtf8("MaxActiveDownloads"), spinMaxActiveDownloads->value()); + settings.setValue(QString::fromUtf8("MaxActiveUploads"), spinMaxActiveUploads->value()); settings.setValue(QString::fromUtf8("MaxActiveTorrents"), spinMaxActiveTorrents->value()); // End Queueing system preferences settings.endGroup(); @@ -703,6 +704,7 @@ void options_imp::loadOptions(){ if(isQueueingSystemEnabled()) { enableQueueingSystem(2); // Enable spinMaxActiveDownloads->setValue(settings.value(QString::fromUtf8("MaxActiveDownloads"), 3).toInt()); + spinMaxActiveUploads->setValue(settings.value(QString::fromUtf8("MaxActiveUploads"), 3).toInt()); spinMaxActiveTorrents->setValue(settings.value(QString::fromUtf8("MaxActiveTorrents"), 5).toInt()); } else { enableQueueingSystem(0); // Disable @@ -734,6 +736,10 @@ int options_imp::getMaxActiveDownloads() const { return spinMaxActiveDownloads->value(); } +int options_imp::getMaxActiveUploads() const { + return spinMaxActiveUploads->value(); +} + int options_imp::getMaxActiveTorrents() const { return spinMaxActiveTorrents->value(); } @@ -927,13 +933,17 @@ void options_imp::enableQueueingSystem(int checkBoxValue) { if(checkBoxValue != 2) { //Disable spinMaxActiveDownloads->setEnabled(false); - label_max_active->setEnabled(false); + spinMaxActiveUploads->setEnabled(false); + label_max_active_dl->setEnabled(false); + label_max_active_up->setEnabled(false); maxActiveTorrents_lbl->setEnabled(false); spinMaxActiveTorrents->setEnabled(false); }else{ //enable spinMaxActiveDownloads->setEnabled(true); - label_max_active->setEnabled(true); + spinMaxActiveUploads->setEnabled(true); + label_max_active_dl->setEnabled(true); + label_max_active_up->setEnabled(true); maxActiveTorrents_lbl->setEnabled(true); spinMaxActiveTorrents->setEnabled(true); } diff --git a/src/options_imp.h b/src/options_imp.h index 1449e1d49..39859d302 100644 --- a/src/options_imp.h +++ b/src/options_imp.h @@ -119,6 +119,7 @@ class options_imp : public QDialog, private Ui::Dialog { // Queueing system bool isQueueingSystemEnabled() const; int getMaxActiveDownloads() const; + int getMaxActiveUploads() const; int getMaxActiveTorrents() const; bool isWebUiEnabled() const; quint16 webUiPort() const; diff --git a/src/qtorrenthandle.cpp b/src/qtorrenthandle.cpp index 2be8cb768..9ec652a7a 100644 --- a/src/qtorrenthandle.cpp +++ b/src/qtorrenthandle.cpp @@ -266,6 +266,11 @@ QStringList QTorrentHandle::files_path() const { return res; } +int QTorrentHandle::queue_position() const { + Q_ASSERT(h.is_valid()); + return h.queue_position(); +} + int QTorrentHandle::num_uploads() const { Q_ASSERT(h.is_valid()); return h.status().num_uploads; @@ -335,6 +340,17 @@ void QTorrentHandle::replace_trackers(std::vector const& v) cons h.replace_trackers(v); } +void QTorrentHandle::queue_position_down() const { + Q_ASSERT(h.is_valid()); + h.queue_position_down(); +} + +void QTorrentHandle::queue_position_up() const { + Q_ASSERT(h.is_valid()); + h.queue_position_up(); + +} + void QTorrentHandle::force_reannounce() { Q_ASSERT(h.is_valid()); h.force_reannounce(); diff --git a/src/qtorrenthandle.h b/src/qtorrenthandle.h index fdfae791e..7191c7038 100644 --- a/src/qtorrenthandle.h +++ b/src/qtorrenthandle.h @@ -77,6 +77,7 @@ class QTorrentHandle { int num_files() const; bool has_metadata() const; void save_resume_data() const; + int queue_position() const; QString file_at(unsigned int index) const; size_type filesize_at(unsigned int index) const; std::vector const& trackers() const; @@ -111,6 +112,8 @@ class QTorrentHandle { void force_reannounce(); void set_sequential_download(bool); void set_tracker_login(QString username, QString password); + void queue_position_down() const; + void queue_position_up() const; // // Operators