From 20ae3d997c7b486fe07954373fd81f027ca49526 Mon Sep 17 00:00:00 2001 From: Christophe Dumez Date: Mon, 14 Jul 2008 22:01:05 +0000 Subject: [PATCH] - extending Queueing system to seeding list (unfinished) --- src/FinishedListDelegate.h | 3 +- src/FinishedTorrents.cpp | 33 ++++- src/FinishedTorrents.h | 2 + src/GUI.cpp | 17 ++- src/bittorrent.cpp | 227 ++++++++++++++++++++++++++------ src/bittorrent.h | 24 +++- src/downloadingTorrents.cpp | 7 +- src/options.ui | 253 ++++++++++++++++++++---------------- src/options_imp.cpp | 11 ++ src/options_imp.h | 1 + src/seeding.ui | 5 + 11 files changed, 414 insertions(+), 169 deletions(-) diff --git a/src/FinishedListDelegate.h b/src/FinishedListDelegate.h index cdd9bc748..214633361 100644 --- a/src/FinishedListDelegate.h +++ b/src/FinishedListDelegate.h @@ -37,7 +37,8 @@ #define F_UPSPEED 2 #define F_LEECH 3 #define F_RATIO 4 -#define F_HASH 5 +#define F_PRIORITY 5 +#define F_HASH 6 class FinishedListDelegate: public QItemDelegate { Q_OBJECT diff --git a/src/FinishedTorrents.cpp b/src/FinishedTorrents.cpp index 104cf5c16..042642662 100644 --- a/src/FinishedTorrents.cpp +++ b/src/FinishedTorrents.cpp @@ -38,14 +38,17 @@ FinishedTorrents::FinishedTorrents(QObject *parent, bittorrent *BTSession) : par actionStart->setIcon(QIcon(QString::fromUtf8(":/Icons/skin/play.png"))); actionPause->setIcon(QIcon(QString::fromUtf8(":/Icons/skin/pause.png"))); connect(BTSession, SIGNAL(addedTorrent(QString, QTorrentHandle&, bool)), this, SLOT(torrentAdded(QString, QTorrentHandle&, bool))); - finishedListModel = new QStandardItemModel(0,6); + finishedListModel = new QStandardItemModel(0,7); finishedListModel->setHeaderData(F_NAME, Qt::Horizontal, tr("Name", "i.e: file name")); finishedListModel->setHeaderData(F_SIZE, Qt::Horizontal, tr("Size", "i.e: file size")); finishedListModel->setHeaderData(F_UPSPEED, Qt::Horizontal, tr("UP Speed", "i.e: Upload speed")); finishedListModel->setHeaderData(F_LEECH, Qt::Horizontal, tr("Leechers", "i.e: full/partial sources")); finishedListModel->setHeaderData(F_RATIO, Qt::Horizontal, tr("Ratio")); + finishedListModel->setHeaderData(F_PRIORITY, Qt::Horizontal, tr("Priority")); finishedList->setModel(finishedListModel); loadHiddenColumns(); + // Hide priority column + finishedList->hideColumn(F_PRIORITY); // Hide hash column finishedList->hideColumn(F_HASH); // Load last columns width for download list @@ -82,6 +85,7 @@ FinishedTorrents::FinishedTorrents(QObject *parent, bittorrent *BTSession) : par connect(actionHOSColUpSpeed, SIGNAL(triggered()), this, SLOT(hideOrShowColumnUpSpeed())); connect(actionHOSColLeechers, SIGNAL(triggered()), this, SLOT(hideOrShowColumnLeechers())); connect(actionHOSColRatio, SIGNAL(triggered()), this, SLOT(hideOrShowColumnRatio())); + connect(actionHOSColPriority, SIGNAL(triggered()), this, SLOT(hideOrShowColumnPriority())); } FinishedTorrents::~FinishedTorrents(){ @@ -97,6 +101,10 @@ void FinishedTorrents::notifyTorrentDoubleClicked(const QModelIndex& index) { emit torrentDoubleClicked(hash, true); } +void FinishedTorrents::hidePriorityColumn(bool hide) { + finishedList->setColumnHidden(F_PRIORITY, hide); +} + void FinishedTorrents::addTorrent(QString hash){ if(!BTSession->isFinished(hash)){ BTSession->setFinishedTorrent(hash); @@ -112,6 +120,8 @@ void FinishedTorrents::addTorrent(QString hash){ finishedListModel->setData(finishedListModel->index(row, F_UPSPEED), QVariant((double)0.)); finishedListModel->setData(finishedListModel->index(row, F_LEECH), QVariant("0")); finishedListModel->setData(finishedListModel->index(row, F_RATIO), QVariant(QString::fromUtf8(misc::toString(BTSession->getRealRatio(hash)).c_str()))); + if(BTSession->isQueueingEnabled()) + finishedListModel->setData(finishedListModel->index(row, F_PRIORITY), QVariant((int)BTSession->getUpTorrentPriority(hash))); finishedListModel->setData(finishedListModel->index(row, F_HASH), QVariant(hash)); if(h.is_paused()) { finishedListModel->setData(finishedListModel->index(row, F_NAME), QIcon(":/Icons/skin/paused.png"), Qt::DecorationRole); @@ -237,6 +247,14 @@ void FinishedTorrents::updateFinishedList(){ row = getRowFromHash(hash); } Q_ASSERT(row != -1); + // Update priority + if(BTSession->isQueueingEnabled()) { + finishedListModel->setData(finishedListModel->index(row, F_PRIORITY), QVariant((int)BTSession->getDlTorrentPriority(hash))); + if(h.is_paused() && BTSession->isUploadQueued(hash)) { + finishedListModel->setData(finishedListModel->index(row, F_NAME), QVariant(QIcon(QString::fromUtf8(":/Icons/skin/queued.png"))), Qt::DecorationRole); + setRowColor(row, QString::fromUtf8("grey")); + } + } if(h.is_paused()) continue; if(BTSession->getTorrentsToPauseAfterChecking().indexOf(hash) != -1) { continue; @@ -406,6 +424,12 @@ void FinishedTorrents::displayFinishedListMenu(const QPoint& pos){ void FinishedTorrents::displayFinishedHoSMenu(const QPoint& pos){ QMenu hideshowColumn(this); hideshowColumn.setTitle(tr("Hide or Show Column")); + int lastCol; + if(BTSession->isQueueingEnabled()) { + lastCol = F_PRIORITY; + } else { + lastCol = F_RATIO; + } for(int i=0; i<=F_RATIO; i++) { hideshowColumn.addAction(getActionHoSCol(i)); } @@ -464,6 +488,10 @@ void FinishedTorrents::hideOrShowColumnRatio() { hideOrShowColumn(F_RATIO); } +void FinishedTorrents::hideOrShowColumnPriority() { + hideOrShowColumn(F_PRIORITY); +} + // load the previous settings, and hide the columns bool FinishedTorrents::loadHiddenColumns() { bool loaded = false; @@ -525,6 +553,9 @@ QAction* FinishedTorrents::getActionHoSCol(int index) { case F_RATIO : return actionHOSColRatio; break; + case F_PRIORITY : + return actionHOSColPriority; + break; default : return NULL; } diff --git a/src/FinishedTorrents.h b/src/FinishedTorrents.h index 52d528b1d..31caa830a 100644 --- a/src/FinishedTorrents.h +++ b/src/FinishedTorrents.h @@ -72,6 +72,7 @@ class FinishedTorrents : public QWidget, public Ui::seeding { void hideOrShowColumnUpSpeed(); void hideOrShowColumnLeechers(); void hideOrShowColumnRatio(); + void hideOrShowColumnPriority(); public slots: void addTorrent(QString hash); @@ -81,6 +82,7 @@ class FinishedTorrents : public QWidget, public Ui::seeding { void propertiesSelection(); void deleteTorrent(QString hash); void showPropertiesFromHash(QString hash); + void hidePriorityColumn(bool hide); signals: void torrentMovedFromFinishedList(QString); diff --git a/src/GUI.cpp b/src/GUI.cpp index 75d06dff5..87c12d705 100644 --- a/src/GUI.cpp +++ b/src/GUI.cpp @@ -1112,15 +1112,22 @@ void GUI::configureSession(bool deleteOptions) { } // Queueing System if(options->isQueueingSystemEnabled()) { - if(!BTSession->isDlQueueingEnabled()) { - BTSession->setMaxActiveDlTorrents(options->getMaxActiveDownloads()); - BTSession->setDlQueueingEnabled(true); + if(!BTSession->isQueueingEnabled()) { + 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); downloadingTorrentTab->hidePriorityColumn(false); + finishedTorrentTab->hidePriorityColumn(false); } } else { - if(BTSession->isDlQueueingEnabled()) { - BTSession->setDlQueueingEnabled(false); + if(BTSession->isQueueingEnabled()) { + BTSession->setQueueingEnabled(false); downloadingTorrentTab->hidePriorityColumn(true); + finishedTorrentTab->hidePriorityColumn(true); } } // Clean up diff --git a/src/bittorrent.cpp b/src/bittorrent.cpp index d41cb3f91..954aa78f5 100644 --- a/src/bittorrent.cpp +++ b/src/bittorrent.cpp @@ -43,7 +43,7 @@ #define MAX_TRACKER_ERRORS 2 // Main constructor -bittorrent::bittorrent() : timerScan(0), DHTEnabled(false), preAllocateAll(false), addInPause(false), maxConnecsPerTorrent(500), maxUploadsPerTorrent(4), max_ratio(-1), UPnPEnabled(false), NATPMPEnabled(false), LSDEnabled(false), folderScanInterval(5), dlQueueingEnabled(false) { +bittorrent::bittorrent() : timerScan(0), DHTEnabled(false), preAllocateAll(false), addInPause(false), maxConnecsPerTorrent(500), maxUploadsPerTorrent(4), max_ratio(-1), UPnPEnabled(false), NATPMPEnabled(false), LSDEnabled(false), folderScanInterval(5), queueingEnabled(false) { // To avoid some exceptions fs::path::default_name_check(fs::no_check); // Creating bittorrent session @@ -99,11 +99,15 @@ bittorrent::~bittorrent() { if(filterParser != 0) delete filterParser; delete downloader; - if(dlQueueingEnabled) { + 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"); @@ -154,12 +158,16 @@ void bittorrent::setDownloadLimit(QString hash, long val) { saveTorrentSpeedLimits(hash); } -bool bittorrent::isDlQueueingEnabled() const { - return dlQueueingEnabled; +bool bittorrent::isQueueingEnabled() const { + return queueingEnabled; } -void bittorrent::setMaxActiveDlTorrents(int val) { - maxActiveDlTorrents = val; +void bittorrent::setMaxActiveDownloads(int val) { + maxActiveDownloads = val; +} + +void bittorrent::setMaxActiveTorrents(int val) { + maxActiveTorrents = val; } void bittorrent::increaseDlTorrentPriority(QString hash) { @@ -167,24 +175,46 @@ void bittorrent::increaseDlTorrentPriority(QString hash) { Q_ASSERT(index != -1); if(index > 0) { downloadQueue->swap(index-1, index); - saveDlTorrentPriority(hash, index-1); - saveDlTorrentPriority(downloadQueue->at(index), index); + saveTorrentPriority(hash, index-1); + saveTorrentPriority(downloadQueue->at(index), index); updateDownloadQueue(); } } +void bittorrent::increaseUpTorrentPriority(QString hash) { + 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(); + } +} + void bittorrent::decreaseDlTorrentPriority(QString hash) { int index = downloadQueue->indexOf(hash); Q_ASSERT(index != -1); if(index >= 0 && index < (downloadQueue->size()-1)) { downloadQueue->swap(index+1, index); - saveDlTorrentPriority(hash, index+1); - saveDlTorrentPriority(downloadQueue->at(index), index); + saveTorrentPriority(hash, index+1); + saveTorrentPriority(downloadQueue->at(index), index); updateDownloadQueue(); } } -void bittorrent::saveDlTorrentPriority(QString hash, int prio) { +void bittorrent::decreaseUpTorrentPriority(QString hash) { + 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); @@ -192,7 +222,7 @@ void bittorrent::saveDlTorrentPriority(QString hash, int prio) { prio_file.close(); } -int bittorrent::loadDlTorrentPriority(QString hash) { +int bittorrent::loadTorrentPriority(QString hash) { if(QFile::exists(misc::qBittorrentPath()+"BT_backup"+QDir::separator()+hash+".prio")) { // Read .queued file QFile prio_file(misc::qBittorrentPath()+"BT_backup"+QDir::separator()+hash+".prio"); @@ -212,10 +242,15 @@ int bittorrent::loadDlTorrentPriority(QString hash) { } bool bittorrent::isDownloadQueued(QString hash) const { - Q_ASSERT(dlQueueingEnabled); + Q_ASSERT(queueingEnabled); return queuedDownloads->contains(hash); } +bool bittorrent::isUploadQueued(QString hash) const { + Q_ASSERT(queueingEnabled); + return queuedUploads->contains(hash); +} + void bittorrent::setUploadLimit(QString hash, long val) { qDebug("Set upload limit rate to %ld", val); QTorrentHandle h = getTorrentHandle(hash); @@ -232,16 +267,16 @@ void bittorrent::startTorrentsInPause(bool b) { addInPause = b; } -void bittorrent::setDlQueueingEnabled(bool enable) { - if(dlQueueingEnabled != enable) { - dlQueueingEnabled = enable; +void bittorrent::setQueueingEnabled(bool enable) { + if(queueingEnabled != enable) { + queueingEnabled = enable; if(enable) { // Load priorities QList > tmp_list; QStringList noprio; - QStringList finished = getUnfinishedTorrents(); - foreach(QString hash, finished) { - int prio = loadDlTorrentPriority(hash); + QStringList unfinished = getUnfinishedTorrents(); + foreach(QString hash, unfinished) { + int prio = loadTorrentPriority(hash); if(prio != -1) { misc::insertSort2(tmp_list, QPair(prio,hash), Qt::AscendingOrder); } else { @@ -257,16 +292,45 @@ void bittorrent::setDlQueueingEnabled(bool enable) { // save priorities int i=0; foreach(QString hash, *downloadQueue) { - saveDlTorrentPriority(hash, i); + saveTorrentPriority(hash, i); ++i; } queuedDownloads = new QStringList(); updateDownloadQueue(); + QList > tmp_list2; + QStringList noprio2; + QStringList finished = getFinishedTorrents(); + foreach(QString hash, finished) { + int prio = loadTorrentPriority(hash); + if(prio != -1) { + misc::insertSort2(tmp_list2, QPair(prio,hash), Qt::AscendingOrder); + } else { + noprio2 << hash; + } + } + uploadQueue = new QStringList(); + QPair couple2; + foreach(couple2, tmp_list2) { + uploadQueue->append(couple2.second); + } + (*uploadQueue)<indexOf(hash); } +int bittorrent::getUpTorrentPriority(QString hash) const { + Q_ASSERT(uploadQueue != 0); + return uploadQueue->indexOf(hash); +} + +void bittorrent::updateUploadQueue() { + Q_ASSERT(queueingEnabled); + 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(); + 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(); + 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(uploadQueue->contains(hash)) { + QTorrentHandle h = getTorrentHandle(hash); + h.resume(); + queuedUploads->removeAll(hash); + QFile::remove(misc::qBittorrentPath()+"BT_backup"+QDir::separator()+hash+".queued"); + ++currentActiveUploads; + } + } else { + break; + } + } + } +} + void bittorrent::updateDownloadQueue() { - Q_ASSERT(dlQueueingEnabled); - int currentActiveTorrents = 0; + Q_ASSERT(queueingEnabled); + currentActiveDownloads = 0; // Check if it is necessary to queue torrents foreach(QString hash, *downloadQueue) { QTorrentHandle h = getTorrentHandle(hash); if(!h.is_paused()) { - if(currentActiveTorrents < maxActiveDlTorrents) { - ++currentActiveTorrents; + if(currentActiveDownloads < maxActiveDownloads) { + ++currentActiveDownloads; } else { // Queue it h.pause(); @@ -299,25 +419,25 @@ void bittorrent::updateDownloadQueue() { } } } else { - if(currentActiveTorrents < maxActiveDlTorrents && isDownloadQueued(hash)) { + if(currentActiveDownloads < maxActiveDownloads && isDownloadQueued(hash)) { QTorrentHandle h = getTorrentHandle(hash); h.resume(); queuedDownloads->removeAll(hash); QFile::remove(misc::qBittorrentPath()+"BT_backup"+QDir::separator()+hash+".queued"); - ++currentActiveTorrents; + ++currentActiveDownloads; } } } - if(currentActiveTorrents < maxActiveDlTorrents) { + if(currentActiveDownloads < maxActiveDownloads) { // Could not fill download slots, unqueue torrents foreach(QString hash, *downloadQueue) { - if(downloadQueue->size() != 0 && currentActiveTorrents < maxActiveDlTorrents) { + if(downloadQueue->size() != 0 && currentActiveDownloads < maxActiveDownloads) { if(downloadQueue->contains(hash)) { QTorrentHandle h = getTorrentHandle(hash); h.resume(); queuedDownloads->removeAll(hash); QFile::remove(misc::qBittorrentPath()+"BT_backup"+QDir::separator()+hash+".queued"); - ++currentActiveTorrents; + ++currentActiveDownloads; } } else { break; @@ -438,14 +558,23 @@ 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 - if(dlQueueingEnabled) { - 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"); - updateDownloadQueue(); + // 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 && files_arb != 0) { // Remove from Hard drive qDebug("Removing this on hard drive: %s", qPrintable(savePath+QDir::separator()+fileName)); @@ -484,10 +613,10 @@ void bittorrent::setUnfinishedTorrent(QString hash) { TorrentsStartTime[hash] = QDateTime::currentDateTime(); } // Add it to downloadQueue - if(dlQueueingEnabled) { + if(queueingEnabled) { if(!downloadQueue->contains(hash)) { downloadQueue->append(hash); - saveDlTorrentPriority(hash, downloadQueue->size()-1); + saveTorrentPriority(hash, downloadQueue->size()-1); updateDownloadQueue(); } } @@ -511,12 +640,16 @@ void bittorrent::setFinishedTorrent(QString hash) { TorrentsStartTime.remove(hash); TorrentsStartData.remove(hash); // Remove it from downloadQueue - if(dlQueueingEnabled) { + 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(); + uploadQueue->append(hash); + updateUploadQueue(); } // Save fast resume data saveFastResumeAndRatioData(hash); @@ -549,6 +682,13 @@ bool bittorrent::pauseTorrent(QString hash) { // Remove it from TorrentsStartTime hash table TorrentsStartTime.remove(hash); TorrentsStartData.remove(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"); return change; } @@ -744,12 +884,17 @@ void bittorrent::addTorrent(QString path, bool fromScanDir, QString from_url, bo h.resume(); if(QFile::exists(misc::qBittorrentPath()+"BT_backup"+QDir::separator()+hash+".finished")) { finishedTorrents << hash; + if(queueingEnabled) { + uploadQueue->append(hash); + saveTorrentPriority(hash, uploadQueue->size()-1); + updateUploadQueue(); + } }else{ unfinishedTorrents << hash; // Add it to downloadQueue - if(dlQueueingEnabled) { + if(queueingEnabled) { downloadQueue->append(hash); - saveDlTorrentPriority(hash, downloadQueue->size()-1); + saveTorrentPriority(hash, downloadQueue->size()-1); updateDownloadQueue(); } } diff --git a/src/bittorrent.h b/src/bittorrent.h index 9c5e75050..2b0c59d57 100644 --- a/src/bittorrent.h +++ b/src/bittorrent.h @@ -70,10 +70,14 @@ class bittorrent : public QObject{ FilterParserThread *filterParser; QString filterPath; int folderScanInterval; // in seconds - bool dlQueueingEnabled; - int maxActiveDlTorrents; + bool queueingEnabled; + int maxActiveDownloads; + int maxActiveTorrents; + int currentActiveDownloads; QStringList *downloadQueue; QStringList *queuedDownloads; + QStringList *uploadQueue; + QStringList *queuedUploads; protected: QString getSavePath(QString hash); @@ -101,10 +105,12 @@ class bittorrent : public QObject{ bool has_filtered_files(QString hash) const; unsigned int getFinishedPausedTorrentsNb() const; unsigned int getUnfinishedPausedTorrentsNb() const; - bool isDlQueueingEnabled() const; + bool isQueueingEnabled() const; int getDlTorrentPriority(QString hash) const; + int getUpTorrentPriority(QString hash) const; bool isDownloadQueued(QString hash) const; - int loadDlTorrentPriority(QString hash); + bool isUploadQueued(QString hash) const; + int loadTorrentPriority(QString hash); public slots: void addTorrent(QString path, bool fromScanDir = false, QString from_url = QString(), bool resumed = false); @@ -124,7 +130,7 @@ class bittorrent : public QObject{ void enablePeerExchange(); void enableIPFilter(QString filter); void disableIPFilter(); - void setDlQueueingEnabled(bool enable); + void setQueueingEnabled(bool enable); void resumeUnfinishedTorrents(); void saveTorrentSpeedLimits(QString hash); void loadTorrentSpeedLimits(QString hash); @@ -133,9 +139,12 @@ class bittorrent : public QObject{ void handleDownloadFailure(QString url, QString reason); void loadWebSeeds(QString fileHash); void updateDownloadQueue(); + void updateUploadQueue(); void increaseDlTorrentPriority(QString hash); void decreaseDlTorrentPriority(QString hash); - void saveDlTorrentPriority(QString hash, int prio); + void increaseUpTorrentPriority(QString hash); + void decreaseUpTorrentPriority(QString hash); + void saveTorrentPriority(QString hash, int prio); // Session configuration - Setters void setListeningPortsRange(std::pair ports); void setMaxConnections(int maxConnec); @@ -162,7 +171,8 @@ class bittorrent : public QObject{ bool enableDHT(bool b); void reloadTorrent(const QTorrentHandle &h, bool full_alloc); void setTimerScanInterval(int secs); - void setMaxActiveDlTorrents(int val); + void setMaxActiveDownloads(int val); + void setMaxActiveTorrents(int val); protected slots: void scanDirectory(); diff --git a/src/downloadingTorrents.cpp b/src/downloadingTorrents.cpp index fb2293492..e2c1afd33 100644 --- a/src/downloadingTorrents.cpp +++ b/src/downloadingTorrents.cpp @@ -335,7 +335,7 @@ void DownloadingTorrents::displayDLHoSMenu(const QPoint& pos){ QMenu hideshowColumn(this); hideshowColumn.setTitle(tr("Hide or Show Column")); int lastCol; - if(BTSession->isDlQueueingEnabled()) { + if(BTSession->isQueueingEnabled()) { lastCol = PRIORITY; } else { lastCol = ETA; @@ -552,10 +552,9 @@ void DownloadingTorrents::updateDlList() { } Q_ASSERT(row != -1); // Update Priority - if(BTSession->isDlQueueingEnabled()) { + if(BTSession->isQueueingEnabled()) { DLListModel->setData(DLListModel->index(row, PRIORITY), QVariant((int)BTSession->getDlTorrentPriority(hash))); if(h.is_paused() && BTSession->isDownloadQueued(hash)) { - qDebug("Download queued"); DLListModel->setData(DLListModel->index(row, NAME), QVariant(QIcon(QString::fromUtf8(":/Icons/skin/queued.png"))), Qt::DecorationRole); if(!downloadList->isColumnHidden(ETA)) { DLListModel->setData(DLListModel->index(row, ETA), QVariant((qlonglong)-1)); @@ -672,7 +671,7 @@ void DownloadingTorrents::addTorrent(QString hash) { DLListModel->setData(DLListModel->index(row, UPSPEED), QVariant((double)0.)); DLListModel->setData(DLListModel->index(row, SEEDSLEECH), QVariant(QString::fromUtf8("0/0"))); DLListModel->setData(DLListModel->index(row, ETA), QVariant((qlonglong)-1)); - if(BTSession->isDlQueueingEnabled()) + if(BTSession->isQueueingEnabled()) DLListModel->setData(DLListModel->index(row, PRIORITY), QVariant((int)BTSession->getDlTorrentPriority(hash))); DLListModel->setData(DLListModel->index(row, HASH), QVariant(hash)); // Pause torrent if it was paused last time diff --git a/src/options.ui b/src/options.ui index a81d38adf..7a214a9b4 100644 --- a/src/options.ui +++ b/src/options.ui @@ -22,7 +22,16 @@ 6 - + + 9 + + + 9 + + + 9 + + 9 @@ -74,20 +83,11 @@ Qt::ElideLeft - - - 0 - 0 - 641 - 457 - - General - - :/Icons/star.png:/Icons/star.png + :/Icons/star.png @@ -120,7 +120,7 @@ Qt::Horizontal - + 40 20 @@ -189,7 +189,7 @@ Qt::Horizontal - + 40 20 @@ -250,7 +250,7 @@ Qt::Horizontal - + 40 20 @@ -318,7 +318,7 @@ Qt::Vertical - + 623 20 @@ -329,22 +329,13 @@ - - - 0 - 0 - 641 - 457 - - Downloads - - :/Icons/download.png:/Icons/download.png + :/Icons/download.png - + @@ -369,7 +360,16 @@ 6 - + + 0 + + + 0 + + + 0 + + 0 @@ -377,7 +377,16 @@ 6 - + + 0 + + + 0 + + + 0 + + 0 @@ -419,9 +428,9 @@ When adding a torrent - + - + @@ -433,11 +442,11 @@ - + Qt::Horizontal - + 40 20 @@ -468,7 +477,7 @@ Folder watching - + @@ -481,7 +490,16 @@ 6 - + + 0 + + + 0 + + + 0 + + 0 @@ -504,7 +522,7 @@ - + @@ -591,7 +609,7 @@ Qt::Horizontal - + 40 20 @@ -634,7 +652,7 @@ Qt::Horizontal - + 40 20 @@ -650,20 +668,11 @@ - - - 0 - 0 - 641 - 457 - - Connection - - :/Icons/connection.png:/Icons/connection.png + :/Icons/connection.png @@ -726,7 +735,7 @@ Qt::Horizontal - + 20 20 @@ -974,7 +983,7 @@ Qt::Horizontal - + 21 29 @@ -1063,7 +1072,7 @@ Qt::Horizontal - + 40 20 @@ -1165,20 +1174,11 @@ - - - 0 - 0 - 641 - 457 - - Bittorrent - - :/Icons/bt_settings.png:/Icons/bt_settings.png + :/Icons/bt_settings.png @@ -1225,7 +1225,7 @@ Qt::Horizontal - + 40 20 @@ -1270,7 +1270,7 @@ Qt::Horizontal - + 40 20 @@ -1312,7 +1312,7 @@ Qt::Horizontal - + 40 20 @@ -1401,7 +1401,7 @@ Qt::Horizontal - + 40 20 @@ -1464,7 +1464,7 @@ Qt::Horizontal - + 40 20 @@ -1518,7 +1518,7 @@ Qt::Horizontal - + 40 20 @@ -1536,7 +1536,7 @@ Qt::Vertical - + 20 40 @@ -1547,22 +1547,13 @@ - - - 0 - 0 - 641 - 457 - - Misc - - :/Icons/configure.png:/Icons/configure.png + :/Icons/configure.png - + @@ -1571,20 +1562,19 @@ Filter Settings - + Activate IP Filtering - - :/Icons/filter.png:/Icons/filter.png + :/Icons/filter.png - + @@ -1622,7 +1612,7 @@ RSS - + @@ -1638,7 +1628,7 @@ RSS settings - + @@ -1702,7 +1692,7 @@ Qt::Horizontal - + 40 20 @@ -1736,7 +1726,7 @@ Qt::Horizontal - + 40 20 @@ -1759,9 +1749,9 @@ - Download queueing + Torrent queueing - + @@ -1770,7 +1760,7 @@ - + @@ -1798,11 +1788,11 @@ - + Qt::Horizontal - + 40 20 @@ -1812,18 +1802,61 @@ + + + + + + false + + + Maximum active torrents: + + + + + + + false + + + 1 + + + 999 + + + 5 + + + + + + + Qt::Horizontal + + + + 381 + 20 + + + + + + - + Qt::Vertical - + - 20 - 40 + 623 + 20 @@ -1831,20 +1864,11 @@ - - - 0 - 0 - 641 - 457 - - Web UI - - :/Icons/password.png:/Icons/password.png + :/Icons/password.png @@ -1897,7 +1921,7 @@ Qt::Horizontal - + 21 29 @@ -1982,7 +2006,7 @@ Qt::Horizontal - + 198 57 @@ -1998,7 +2022,7 @@ Qt::Vertical - + 623 41 @@ -2015,7 +2039,16 @@ 6 - + + 0 + + + 0 + + + 0 + + 0 @@ -2024,7 +2057,7 @@ Qt::Horizontal - QDialogButtonBox::Apply|QDialogButtonBox::Cancel|QDialogButtonBox::Ok + QDialogButtonBox::Apply|QDialogButtonBox::Cancel|QDialogButtonBox::NoButton|QDialogButtonBox::Ok true diff --git a/src/options_imp.cpp b/src/options_imp.cpp index 497f78de6..2b33c18d4 100644 --- a/src/options_imp.cpp +++ b/src/options_imp.cpp @@ -210,6 +210,7 @@ options_imp::options_imp(QWidget *parent):QDialog(parent){ connect(checkEnableRSS, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton())); connect(checkEnableQueueing, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton())); connect(spinMaxActiveDownloads, SIGNAL(valueChanged(QString)), this, SLOT(enableApplyButton())); + connect(spinMaxActiveTorrents, SIGNAL(valueChanged(QString)), this, SLOT(enableApplyButton())); // Web UI tab connect(checkWebUi, SIGNAL(toggled(bool)), this, SLOT(enableApplyButton())); connect(spinWebUiPort, SIGNAL(valueChanged(int)), this, SLOT(enableApplyButton())); @@ -354,6 +355,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("MaxActiveTorrents"), spinMaxActiveTorrents->value()); // End Queueing system preferences settings.endGroup(); // Web UI @@ -635,6 +637,7 @@ void options_imp::loadOptions(){ if(isQueueingSystemEnabled()) { enableQueueingSystem(2); // Enable spinMaxActiveDownloads->setValue(settings.value(QString::fromUtf8("MaxActiveDownloads"), 3).toInt()); + spinMaxActiveTorrents->setValue(settings.value(QString::fromUtf8("MaxActiveTorrents"), 5).toInt()); } else { enableQueueingSystem(0); // Disable } @@ -665,6 +668,10 @@ int options_imp::getMaxActiveDownloads() const { return spinMaxActiveDownloads->value(); } +int options_imp::getMaxActiveTorrents() const { + return spinMaxActiveTorrents->value(); +} + bool options_imp::minimizeToTray() const{ if(checkNoSystray->isChecked()) return false; return checkMinimizeToSysTray->isChecked(); @@ -855,10 +862,14 @@ void options_imp::enableQueueingSystem(int checkBoxValue) { //Disable spinMaxActiveDownloads->setEnabled(false); label_max_active->setEnabled(false); + maxActiveTorrents_lbl->setEnabled(false); + spinMaxActiveTorrents->setEnabled(false); }else{ //enable spinMaxActiveDownloads->setEnabled(true); label_max_active->setEnabled(true); + maxActiveTorrents_lbl->setEnabled(true); + spinMaxActiveTorrents->setEnabled(true); } } diff --git a/src/options_imp.h b/src/options_imp.h index a883e761f..bdc37f3df 100644 --- a/src/options_imp.h +++ b/src/options_imp.h @@ -110,6 +110,7 @@ class options_imp : public QDialog, private Ui::Dialog { // Queueing system bool isQueueingSystemEnabled() const; int getMaxActiveDownloads() const; + int getMaxActiveTorrents() const; bool isWebUiEnabled() const; quint16 webUiPort() const; QString webUiUsername() const; diff --git a/src/seeding.ui b/src/seeding.ui index c2c37fa63..776060e26 100644 --- a/src/seeding.ui +++ b/src/seeding.ui @@ -134,6 +134,11 @@ Buy it + + + Priority + +