diff --git a/Changelog b/Changelog index a662e5ef5..26dd3bc21 100644 --- a/Changelog +++ b/Changelog @@ -21,6 +21,7 @@ - FEATURE: Display per-torrent peer list - FEATURE: Make sure torrent files are always sorted by name - FEATURE: Seeds and Peers columns are now sortable + - FEATURE: Torrents can be rechecked from Web UI (Stephanos Antaris) - COSMETIC: Merged download / upload lists - COSMETIC: Torrents can be filtered based on their status - COSMETIC: Torrent properties are now displayed in main window diff --git a/src/GUI.cpp b/src/GUI.cpp index 112fb2228..e26a19937 100644 --- a/src/GUI.cpp +++ b/src/GUI.cpp @@ -380,8 +380,6 @@ void GUI::fullDiskError(QTorrentHandle& h, QString msg) const { // Download will be paused by libtorrent. Updating GUI information accordingly QString hash = h.hash(); qDebug("Full disk error, pausing torrent %s", hash.toLocal8Bit().data()); - h.pause(); - transferList->pauseTorrent(h.hash()); BTSession->addConsoleMessage(tr("An error occured (full disk?), '%1' paused.", "e.g: An error occured (full disk?), 'xxx.avi' paused.").arg(h.name())); } diff --git a/src/TransferListDelegate.h b/src/TransferListDelegate.h index edbda7b28..20660c724 100644 --- a/src/TransferListDelegate.h +++ b/src/TransferListDelegate.h @@ -37,6 +37,7 @@ #include #include #include +#include #include "misc.h" // Defines for download list list columns @@ -57,6 +58,7 @@ public: switch(index.column()){ case SIZE:{ QItemDelegate::drawBackground(painter, opt, index); + opt.displayAlignment = Qt::AlignHCenter; QItemDelegate::drawDisplay(painter, opt, option.rect, misc::friendlyUnit(index.data().toLongLong())); break; } diff --git a/src/TransferListWidget.cpp b/src/TransferListWidget.cpp index 082775f59..d54517992 100644 --- a/src/TransferListWidget.cpp +++ b/src/TransferListWidget.cpp @@ -99,6 +99,8 @@ TransferListWidget::TransferListWidget(QWidget *parent, bittorrent *_BTSession): connect(BTSession, SIGNAL(addedTorrent(QTorrentHandle&)), this, SLOT(addTorrent(QTorrentHandle&))); connect(BTSession, SIGNAL(finishedTorrent(QTorrentHandle&)), this, SLOT(setFinished(QTorrentHandle&))); connect(BTSession, SIGNAL(metadataReceived(QTorrentHandle&)), this, SLOT(updateMetadata(QTorrentHandle&))); + connect(BTSession, SIGNAL(pausedTorrent(QTorrentHandle&)), this, SLOT(pauseTorrent(QTorrentHandle&))); + connect(BTSession, SIGNAL(resumedTorrent(QTorrentHandle&)), this, SLOT(resumeTorrent(QTorrentHandle&))); // Listen for list events connect(this, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(torrentDoubleClicked(QModelIndex))); @@ -135,7 +137,7 @@ void TransferListWidget::addTorrent(QTorrentHandle& h) { listModel->setData(listModel->index(row, SEEDS), QVariant((double)0.0)); listModel->setData(listModel->index(row, PEERS), QVariant((double)0.0)); if(BTSession->isQueueingEnabled()) - listModel->setData(listModel->index(row, PRIORITY), QVariant((int)BTSession->getDlTorrentPriority(h.hash()))); + listModel->setData(listModel->index(row, PRIORITY), QVariant((int)h.queue_position())); listModel->setData(listModel->index(row, HASH), QVariant(h.hash())); // Pause torrent if it is if(h.is_paused()) { @@ -167,8 +169,9 @@ void TransferListWidget::deleteTorrent(int row) { listModel->removeRow(row); } -void TransferListWidget::pauseTorrent(QString hash) { - pauseTorrent(getRowFromHash(hash)); +// Wrapper slot for bittorrent signal +void TransferListWidget::pauseTorrent(QTorrentHandle &h) { + pauseTorrent(getRowFromHash(h.hash())); } void TransferListWidget::pauseTorrent(int row) { @@ -182,6 +185,11 @@ void TransferListWidget::pauseTorrent(int row) { //setRowColor(row, QString::fromUtf8("red")); } +// Wrapper slot for bittorrent signal +void TransferListWidget::resumeTorrent(QTorrentHandle &h) { + resumeTorrent(getRowFromHash(h.hash())); +} + void TransferListWidget::resumeTorrent(int row) { QTorrentHandle h = BTSession->getTorrentHandle(getHashFromRow(row)); if(!h.is_valid()) return; @@ -217,7 +225,7 @@ void TransferListWidget::updateTorrent(int row) { if(!h.is_seed()) { // Queueing code if(BTSession->isQueueingEnabled()) { - listModel->setData(listModel->index(row, PRIORITY), QVariant((int)BTSession->getDlTorrentPriority(hash))); + listModel->setData(listModel->index(row, PRIORITY), QVariant((int)h.queue_position())); if(h.is_queued()) { if(h.state() == torrent_status::checking_files || h.state() == torrent_status::queued_for_checking) { listModel->setData(listModel->index(row, NAME), QVariant(QIcon(QString::fromUtf8(":/Icons/oxygen/run-build.png"))), Qt::DecorationRole); @@ -471,7 +479,7 @@ void TransferListWidget::increasePrioSelectedTorrents() { foreach(const QModelIndex &index, selectedIndexes) { QTorrentHandle h = BTSession->getTorrentHandle(getHashFromRow(proxyModel->mapToSource(index).row())); if(h.is_valid() && !h.is_seed()) { - BTSession->increaseDlTorrentPriority(h.hash()); + h.queue_position_up(); } } refreshList(); @@ -483,7 +491,7 @@ void TransferListWidget::decreasePrioSelectedTorrents() { foreach(const QModelIndex &index, selectedIndexes) { QTorrentHandle h = BTSession->getTorrentHandle(getHashFromRow(proxyModel->mapToSource(index).row())); if(h.is_valid() && !h.is_seed()) { - BTSession->decreaseDlTorrentPriority(h.hash()); + h.queue_position_down(); } } refreshList(); diff --git a/src/TransferListWidget.h b/src/TransferListWidget.h index 207283354..774dc5df2 100644 --- a/src/TransferListWidget.h +++ b/src/TransferListWidget.h @@ -75,6 +75,8 @@ protected slots: void displayListMenu(const QPoint&); void updateMetadata(QTorrentHandle &h); void currentChanged(const QModelIndex& current, const QModelIndex&); + void pauseTorrent(QTorrentHandle &h); + void resumeTorrent(QTorrentHandle &h); //void setRowColor(int row, QColor color); public slots: @@ -86,7 +88,6 @@ public slots: void startAllTorrents(); void pauseSelectedTorrents(); void pauseAllTorrents(); - void pauseTorrent(QString hash); void deleteSelectedTorrents(); void deletePermSelectedTorrents(); void increasePrioSelectedTorrents(); diff --git a/src/bittorrent.cpp b/src/bittorrent.cpp index fe0da1aee..e1f54a3b6 100644 --- a/src/bittorrent.cpp +++ b/src/bittorrent.cpp @@ -164,19 +164,6 @@ bool bittorrent::isQueueingEnabled() const { return queueingEnabled; } -void bittorrent::increaseDlTorrentPriority(QString hash) { - Q_ASSERT(queueingEnabled); - QTorrentHandle h = getTorrentHandle(hash); - if(h.queue_position() > 0) - h.queue_position_up(); -} - -void bittorrent::decreaseDlTorrentPriority(QString hash) { - Q_ASSERT(queueingEnabled); - QTorrentHandle h = getTorrentHandle(hash); - h.queue_position_down(); -} - void bittorrent::setUploadLimit(QString hash, long val) { qDebug("Set upload limit rate to %ld", val); QTorrentHandle h = getTorrentHandle(hash); @@ -207,18 +194,6 @@ void bittorrent::setQueueingEnabled(bool enable) { } } -int bittorrent::getDlTorrentPriority(QString hash) const { - Q_ASSERT(queueingEnabled); - QTorrentHandle h = getTorrentHandle(hash); - return h.queue_position(); -} - -int bittorrent::getUpTorrentPriority(QString hash) const { - Q_ASSERT(queueingEnabled); - QTorrentHandle h = getTorrentHandle(hash); - return h.queue_position(); -} - // Set BT session configuration void bittorrent::configureSession() { qDebug("Configuring session"); @@ -1575,8 +1550,11 @@ void bittorrent::readAlerts() { if(h.is_valid()) { h.auto_managed(false); std::cerr << "File Error: " << p->message().c_str() << std::endl; - if(h.is_valid()) + if(h.is_valid()) { emit fullDiskError(h, misc::toQString(p->message())); + h.pause(); + emit torrentPaused(h); + } } } else if (dynamic_cast(a.get())) { diff --git a/src/bittorrent.h b/src/bittorrent.h index 509d0c1d6..e33b9ccd7 100644 --- a/src/bittorrent.h +++ b/src/bittorrent.h @@ -103,8 +103,6 @@ class bittorrent : public QObject { bool has_filtered_files(QString hash) const; bool hasActiveTorrents() const; bool isQueueingEnabled() const; - int getDlTorrentPriority(QString hash) const; - int getUpTorrentPriority(QString hash) const; int getMaximumActiveDownloads() const; int getMaximumActiveTorrents() const; int loadTorrentPriority(QString hash); @@ -142,8 +140,6 @@ class bittorrent : public QObject { void loadTorrentSpeedLimits(QString hash); void handleDownloadFailure(QString url, QString reason); void loadWebSeeds(QString fileHash); - void increaseDlTorrentPriority(QString hash); - void decreaseDlTorrentPriority(QString hash); void downloadUrlAndSkipDialog(QString url, QString save_path=QString::null); // Session configuration - Setters void setListeningPort(int port); diff --git a/src/httpconnection.cpp b/src/httpconnection.cpp index b86ca8206..912e86208 100644 --- a/src/httpconnection.cpp +++ b/src/httpconnection.cpp @@ -33,6 +33,7 @@ #include "httpserver.h" #include "eventmanager.h" #include "json.h" +#include "bittorrent.h" #include #include #include @@ -42,8 +43,8 @@ #include #include -HttpConnection::HttpConnection(QTcpSocket *socket, HttpServer *parent) - : QObject(parent), socket(socket), parent(parent) +HttpConnection::HttpConnection(QTcpSocket *socket, bittorrent *BTSession, HttpServer *parent) + : QObject(parent), socket(socket), parent(parent), BTSession(BTSession) { socket->setParent(this); connect(socket, SIGNAL(readyRead()), this, SLOT(read())); @@ -246,11 +247,38 @@ void HttpConnection::respondCommand(QString command) return; } if(command == "increasePrio") { - emit increasePrioTorrent(parser.post("hash")); + QTorrentHandle h = BTSession->getTorrentHandle(parser.post("hash")); + if(h.is_valid()) h.queue_position_up(); return; } if(command == "decreasePrio") { - emit decreasePrioTorrent(parser.post("hash")); + QTorrentHandle h = BTSession->getTorrentHandle(parser.post("hash")); + if(h.is_valid()) h.queue_position_down(); + return; + } + if(command == "recheck"){ + recheckTorrent(parser.post("hash")); + return; + } + if(command == "recheckall"){ + recheckAllTorrents(); return; } } + +void HttpConnection::recheckTorrent(QString hash) { + QTorrentHandle h = BTSession->getTorrentHandle(hash); + if(h.is_valid() && !h.is_paused()){ + h.force_recheck(); + } +} + +void HttpConnection::recheckAllTorrents() { + std::vector torrents = BTSession->getTorrents(); + std::vector::iterator torrentIT; + for(torrentIT = torrents.begin(); torrentIT != torrents.end(); torrentIT++) { + QTorrentHandle h = QTorrentHandle(*torrentIT); + if(h.is_valid() && !h.is_paused()) + h.force_recheck(); + } +} diff --git a/src/httpconnection.h b/src/httpconnection.h index 848581f22..d14122591 100644 --- a/src/httpconnection.h +++ b/src/httpconnection.h @@ -38,6 +38,7 @@ class QTcpSocket; class HttpServer; +class bittorrent; class HttpConnection : public QObject { @@ -45,6 +46,7 @@ class HttpConnection : public QObject private: QTcpSocket *socket; HttpServer *parent; + bittorrent *BTSession; protected: HttpRequestParser parser; @@ -58,9 +60,11 @@ class HttpConnection : public QObject void respondNotFound(); void processDownloadedFile(QString, QString); void handleDownloadFailure(QString, QString); + void recheckTorrent(QString hash); + void recheckAllTorrents(); public: - HttpConnection(QTcpSocket *socket, HttpServer *parent); + HttpConnection(QTcpSocket *socket, bittorrent* BTSession, HttpServer *parent); ~HttpConnection(); private slots: diff --git a/src/httpserver.cpp b/src/httpserver.cpp index 4470f3fa0..54e7bfa15 100644 --- a/src/httpserver.cpp +++ b/src/httpserver.cpp @@ -69,7 +69,7 @@ void HttpServer::newHttpConnection() QTcpSocket *socket; while((socket = nextPendingConnection())) { - HttpConnection *connection = new HttpConnection(socket, this); + HttpConnection *connection = new HttpConnection(socket, BTSession, this); //connect connection to BTSession connect(connection, SIGNAL(UrlReadyToBeDownloaded(QString)), BTSession, SLOT(downloadUrlAndSkipDialog(QString))); connect(connection, SIGNAL(MagnetReadyToBeDownloaded(QString)), BTSession, SLOT(addMagnetSkipAddDlg(QString))); @@ -79,8 +79,6 @@ void HttpServer::newHttpConnection() connect(connection, SIGNAL(resumeTorrent(QString)), BTSession, SLOT(resumeTorrent(QString))); connect(connection, SIGNAL(pauseAllTorrents()), BTSession, SLOT(pauseAllTorrents())); connect(connection, SIGNAL(resumeAllTorrents()), BTSession, SLOT(resumeAllTorrents())); - connect(connection, SIGNAL(increasePrioTorrent(QString)), BTSession, SLOT(increaseDlTorrentPriority(QString))); - connect(connection, SIGNAL(decreasePrioTorrent(QString)), BTSession, SLOT(decreaseDlTorrentPriority(QString))); } } diff --git a/src/qtorrenthandle.cpp b/src/qtorrenthandle.cpp index 984796377..93fd5876a 100644 --- a/src/qtorrenthandle.cpp +++ b/src/qtorrenthandle.cpp @@ -453,7 +453,8 @@ void QTorrentHandle::queue_position_down() const { void QTorrentHandle::queue_position_up() const { Q_ASSERT(h.is_valid()); - h.queue_position_up(); + if(h.queue_position() > 0) + h.queue_position_up(); } diff --git a/src/webui/index.html b/src/webui/index.html index dab60ae30..425730cb7 100644 --- a/src/webui/index.html +++ b/src/webui/index.html @@ -39,8 +39,10 @@ diff --git a/src/webui/scripts/mocha-init.js b/src/webui/scripts/mocha-init.js index cfa58bb78..aded5bf83 100644 --- a/src/webui/scripts/mocha-init.js +++ b/src/webui/scripts/mocha-init.js @@ -53,6 +53,13 @@ initializeWindows = function(){ height: 120 }); }); + + + + + + + addClickEvent('delete', function(e){ new Event(e).stop(); @@ -67,6 +74,8 @@ initializeWindows = function(){ }); } }); + + addClickEvent('deletePerm', function(e){ new Event(e).stop(); @@ -82,7 +91,7 @@ initializeWindows = function(){ } }); - ['pause','resume','decreasePrio','increasePrio'].each(function(item) { + ['pause','resume','decreasePrio','increasePrio','recheck'].each(function(item) { addClickEvent(item, function(e){ new Event(e).stop(); if($("Tab1").hasClass('active')) { @@ -105,6 +114,8 @@ initializeWindows = function(){ }); }); + + addClickEvent('bug', function(e){ new Event(e).stop(); new MochaUI.Window({