Browse Source

- Torrents can now be rechecked from Web UI (patch by Stephanos Antaris)

- Torrents paused/resumed state is not reflected in GUI if the action was executed from Web UI
adaptive-webui-19844
Christophe Dumez 15 years ago
parent
commit
4e8eaafd53
  1. 1
      Changelog
  2. 2
      src/GUI.cpp
  3. 2
      src/TransferListDelegate.h
  4. 20
      src/TransferListWidget.cpp
  5. 3
      src/TransferListWidget.h
  6. 30
      src/bittorrent.cpp
  7. 4
      src/bittorrent.h
  8. 36
      src/httpconnection.cpp
  9. 6
      src/httpconnection.h
  10. 4
      src/httpserver.cpp
  11. 3
      src/qtorrenthandle.cpp
  12. 2
      src/webui/index.html
  13. 13
      src/webui/scripts/mocha-init.js

1
Changelog

@ -21,6 +21,7 @@
- FEATURE: Display per-torrent peer list - FEATURE: Display per-torrent peer list
- FEATURE: Make sure torrent files are always sorted by name - FEATURE: Make sure torrent files are always sorted by name
- FEATURE: Seeds and Peers columns are now sortable - FEATURE: Seeds and Peers columns are now sortable
- FEATURE: Torrents can be rechecked from Web UI (Stephanos Antaris)
- COSMETIC: Merged download / upload lists - COSMETIC: Merged download / upload lists
- COSMETIC: Torrents can be filtered based on their status - COSMETIC: Torrents can be filtered based on their status
- COSMETIC: Torrent properties are now displayed in main window - COSMETIC: Torrent properties are now displayed in main window

2
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 // Download will be paused by libtorrent. Updating GUI information accordingly
QString hash = h.hash(); QString hash = h.hash();
qDebug("Full disk error, pausing torrent %s", hash.toLocal8Bit().data()); 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())); BTSession->addConsoleMessage(tr("An error occured (full disk?), '%1' paused.", "e.g: An error occured (full disk?), 'xxx.avi' paused.").arg(h.name()));
} }

2
src/TransferListDelegate.h

@ -37,6 +37,7 @@
#include <QStyleOptionViewItem> #include <QStyleOptionViewItem>
#include <QStyleOptionViewItemV2> #include <QStyleOptionViewItemV2>
#include <QApplication> #include <QApplication>
#include <QPainter>
#include "misc.h" #include "misc.h"
// Defines for download list list columns // Defines for download list list columns
@ -57,6 +58,7 @@ public:
switch(index.column()){ switch(index.column()){
case SIZE:{ case SIZE:{
QItemDelegate::drawBackground(painter, opt, index); QItemDelegate::drawBackground(painter, opt, index);
opt.displayAlignment = Qt::AlignHCenter;
QItemDelegate::drawDisplay(painter, opt, option.rect, misc::friendlyUnit(index.data().toLongLong())); QItemDelegate::drawDisplay(painter, opt, option.rect, misc::friendlyUnit(index.data().toLongLong()));
break; break;
} }

20
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(addedTorrent(QTorrentHandle&)), this, SLOT(addTorrent(QTorrentHandle&)));
connect(BTSession, SIGNAL(finishedTorrent(QTorrentHandle&)), this, SLOT(setFinished(QTorrentHandle&))); connect(BTSession, SIGNAL(finishedTorrent(QTorrentHandle&)), this, SLOT(setFinished(QTorrentHandle&)));
connect(BTSession, SIGNAL(metadataReceived(QTorrentHandle&)), this, SLOT(updateMetadata(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 // Listen for list events
connect(this, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(torrentDoubleClicked(QModelIndex))); 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, SEEDS), QVariant((double)0.0));
listModel->setData(listModel->index(row, PEERS), QVariant((double)0.0)); listModel->setData(listModel->index(row, PEERS), QVariant((double)0.0));
if(BTSession->isQueueingEnabled()) 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())); listModel->setData(listModel->index(row, HASH), QVariant(h.hash()));
// Pause torrent if it is // Pause torrent if it is
if(h.is_paused()) { if(h.is_paused()) {
@ -167,8 +169,9 @@ void TransferListWidget::deleteTorrent(int row) {
listModel->removeRow(row); listModel->removeRow(row);
} }
void TransferListWidget::pauseTorrent(QString hash) { // Wrapper slot for bittorrent signal
pauseTorrent(getRowFromHash(hash)); void TransferListWidget::pauseTorrent(QTorrentHandle &h) {
pauseTorrent(getRowFromHash(h.hash()));
} }
void TransferListWidget::pauseTorrent(int row) { void TransferListWidget::pauseTorrent(int row) {
@ -182,6 +185,11 @@ void TransferListWidget::pauseTorrent(int row) {
//setRowColor(row, QString::fromUtf8("red")); //setRowColor(row, QString::fromUtf8("red"));
} }
// Wrapper slot for bittorrent signal
void TransferListWidget::resumeTorrent(QTorrentHandle &h) {
resumeTorrent(getRowFromHash(h.hash()));
}
void TransferListWidget::resumeTorrent(int row) { void TransferListWidget::resumeTorrent(int row) {
QTorrentHandle h = BTSession->getTorrentHandle(getHashFromRow(row)); QTorrentHandle h = BTSession->getTorrentHandle(getHashFromRow(row));
if(!h.is_valid()) return; if(!h.is_valid()) return;
@ -217,7 +225,7 @@ void TransferListWidget::updateTorrent(int row) {
if(!h.is_seed()) { if(!h.is_seed()) {
// Queueing code // Queueing code
if(BTSession->isQueueingEnabled()) { 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.is_queued()) {
if(h.state() == torrent_status::checking_files || h.state() == torrent_status::queued_for_checking) { 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); 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) { foreach(const QModelIndex &index, selectedIndexes) {
QTorrentHandle h = BTSession->getTorrentHandle(getHashFromRow(proxyModel->mapToSource(index).row())); QTorrentHandle h = BTSession->getTorrentHandle(getHashFromRow(proxyModel->mapToSource(index).row()));
if(h.is_valid() && !h.is_seed()) { if(h.is_valid() && !h.is_seed()) {
BTSession->increaseDlTorrentPriority(h.hash()); h.queue_position_up();
} }
} }
refreshList(); refreshList();
@ -483,7 +491,7 @@ void TransferListWidget::decreasePrioSelectedTorrents() {
foreach(const QModelIndex &index, selectedIndexes) { foreach(const QModelIndex &index, selectedIndexes) {
QTorrentHandle h = BTSession->getTorrentHandle(getHashFromRow(proxyModel->mapToSource(index).row())); QTorrentHandle h = BTSession->getTorrentHandle(getHashFromRow(proxyModel->mapToSource(index).row()));
if(h.is_valid() && !h.is_seed()) { if(h.is_valid() && !h.is_seed()) {
BTSession->decreaseDlTorrentPriority(h.hash()); h.queue_position_down();
} }
} }
refreshList(); refreshList();

3
src/TransferListWidget.h

@ -75,6 +75,8 @@ protected slots:
void displayListMenu(const QPoint&); void displayListMenu(const QPoint&);
void updateMetadata(QTorrentHandle &h); void updateMetadata(QTorrentHandle &h);
void currentChanged(const QModelIndex& current, const QModelIndex&); void currentChanged(const QModelIndex& current, const QModelIndex&);
void pauseTorrent(QTorrentHandle &h);
void resumeTorrent(QTorrentHandle &h);
//void setRowColor(int row, QColor color); //void setRowColor(int row, QColor color);
public slots: public slots:
@ -86,7 +88,6 @@ public slots:
void startAllTorrents(); void startAllTorrents();
void pauseSelectedTorrents(); void pauseSelectedTorrents();
void pauseAllTorrents(); void pauseAllTorrents();
void pauseTorrent(QString hash);
void deleteSelectedTorrents(); void deleteSelectedTorrents();
void deletePermSelectedTorrents(); void deletePermSelectedTorrents();
void increasePrioSelectedTorrents(); void increasePrioSelectedTorrents();

30
src/bittorrent.cpp

@ -164,19 +164,6 @@ bool bittorrent::isQueueingEnabled() const {
return queueingEnabled; 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) { void bittorrent::setUploadLimit(QString hash, long val) {
qDebug("Set upload limit rate to %ld", val); qDebug("Set upload limit rate to %ld", val);
QTorrentHandle h = getTorrentHandle(hash); 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 // Set BT session configuration
void bittorrent::configureSession() { void bittorrent::configureSession() {
qDebug("Configuring session"); qDebug("Configuring session");
@ -1575,8 +1550,11 @@ void bittorrent::readAlerts() {
if(h.is_valid()) { if(h.is_valid()) {
h.auto_managed(false); h.auto_managed(false);
std::cerr << "File Error: " << p->message().c_str() << std::endl; 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())); emit fullDiskError(h, misc::toQString(p->message()));
h.pause();
emit torrentPaused(h);
}
} }
} }
else if (dynamic_cast<listen_failed_alert*>(a.get())) { else if (dynamic_cast<listen_failed_alert*>(a.get())) {

4
src/bittorrent.h

@ -103,8 +103,6 @@ class bittorrent : public QObject {
bool has_filtered_files(QString hash) const; bool has_filtered_files(QString hash) const;
bool hasActiveTorrents() const; bool hasActiveTorrents() const;
bool isQueueingEnabled() const; bool isQueueingEnabled() const;
int getDlTorrentPriority(QString hash) const;
int getUpTorrentPriority(QString hash) const;
int getMaximumActiveDownloads() const; int getMaximumActiveDownloads() const;
int getMaximumActiveTorrents() const; int getMaximumActiveTorrents() const;
int loadTorrentPriority(QString hash); int loadTorrentPriority(QString hash);
@ -142,8 +140,6 @@ class bittorrent : public QObject {
void loadTorrentSpeedLimits(QString hash); void loadTorrentSpeedLimits(QString hash);
void handleDownloadFailure(QString url, QString reason); void handleDownloadFailure(QString url, QString reason);
void loadWebSeeds(QString fileHash); void loadWebSeeds(QString fileHash);
void increaseDlTorrentPriority(QString hash);
void decreaseDlTorrentPriority(QString hash);
void downloadUrlAndSkipDialog(QString url, QString save_path=QString::null); void downloadUrlAndSkipDialog(QString url, QString save_path=QString::null);
// Session configuration - Setters // Session configuration - Setters
void setListeningPort(int port); void setListeningPort(int port);

36
src/httpconnection.cpp

@ -33,6 +33,7 @@
#include "httpserver.h" #include "httpserver.h"
#include "eventmanager.h" #include "eventmanager.h"
#include "json.h" #include "json.h"
#include "bittorrent.h"
#include <QTcpSocket> #include <QTcpSocket>
#include <QDateTime> #include <QDateTime>
#include <QStringList> #include <QStringList>
@ -42,8 +43,8 @@
#include <QDebug> #include <QDebug>
#include <QTemporaryFile> #include <QTemporaryFile>
HttpConnection::HttpConnection(QTcpSocket *socket, HttpServer *parent) HttpConnection::HttpConnection(QTcpSocket *socket, bittorrent *BTSession, HttpServer *parent)
: QObject(parent), socket(socket), parent(parent) : QObject(parent), socket(socket), parent(parent), BTSession(BTSession)
{ {
socket->setParent(this); socket->setParent(this);
connect(socket, SIGNAL(readyRead()), this, SLOT(read())); connect(socket, SIGNAL(readyRead()), this, SLOT(read()));
@ -246,11 +247,38 @@ void HttpConnection::respondCommand(QString command)
return; return;
} }
if(command == "increasePrio") { if(command == "increasePrio") {
emit increasePrioTorrent(parser.post("hash")); QTorrentHandle h = BTSession->getTorrentHandle(parser.post("hash"));
if(h.is_valid()) h.queue_position_up();
return; return;
} }
if(command == "decreasePrio") { if(command == "decreasePrio") {
emit decreasePrioTorrent(parser.post("hash")); QTorrentHandle h = BTSession->getTorrentHandle(parser.post("hash"));
if(h.is_valid()) h.queue_position_down();
return; 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<torrent_handle> torrents = BTSession->getTorrents();
std::vector<torrent_handle>::iterator torrentIT;
for(torrentIT = torrents.begin(); torrentIT != torrents.end(); torrentIT++) {
QTorrentHandle h = QTorrentHandle(*torrentIT);
if(h.is_valid() && !h.is_paused())
h.force_recheck();
}
} }

6
src/httpconnection.h

@ -38,6 +38,7 @@
class QTcpSocket; class QTcpSocket;
class HttpServer; class HttpServer;
class bittorrent;
class HttpConnection : public QObject class HttpConnection : public QObject
{ {
@ -45,6 +46,7 @@ class HttpConnection : public QObject
private: private:
QTcpSocket *socket; QTcpSocket *socket;
HttpServer *parent; HttpServer *parent;
bittorrent *BTSession;
protected: protected:
HttpRequestParser parser; HttpRequestParser parser;
@ -58,9 +60,11 @@ class HttpConnection : public QObject
void respondNotFound(); void respondNotFound();
void processDownloadedFile(QString, QString); void processDownloadedFile(QString, QString);
void handleDownloadFailure(QString, QString); void handleDownloadFailure(QString, QString);
void recheckTorrent(QString hash);
void recheckAllTorrents();
public: public:
HttpConnection(QTcpSocket *socket, HttpServer *parent); HttpConnection(QTcpSocket *socket, bittorrent* BTSession, HttpServer *parent);
~HttpConnection(); ~HttpConnection();
private slots: private slots:

4
src/httpserver.cpp

@ -69,7 +69,7 @@ void HttpServer::newHttpConnection()
QTcpSocket *socket; QTcpSocket *socket;
while((socket = nextPendingConnection())) while((socket = nextPendingConnection()))
{ {
HttpConnection *connection = new HttpConnection(socket, this); HttpConnection *connection = new HttpConnection(socket, BTSession, this);
//connect connection to BTSession //connect connection to BTSession
connect(connection, SIGNAL(UrlReadyToBeDownloaded(QString)), BTSession, SLOT(downloadUrlAndSkipDialog(QString))); connect(connection, SIGNAL(UrlReadyToBeDownloaded(QString)), BTSession, SLOT(downloadUrlAndSkipDialog(QString)));
connect(connection, SIGNAL(MagnetReadyToBeDownloaded(QString)), BTSession, SLOT(addMagnetSkipAddDlg(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(resumeTorrent(QString)), BTSession, SLOT(resumeTorrent(QString)));
connect(connection, SIGNAL(pauseAllTorrents()), BTSession, SLOT(pauseAllTorrents())); connect(connection, SIGNAL(pauseAllTorrents()), BTSession, SLOT(pauseAllTorrents()));
connect(connection, SIGNAL(resumeAllTorrents()), BTSession, SLOT(resumeAllTorrents())); 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)));
} }
} }

3
src/qtorrenthandle.cpp

@ -453,7 +453,8 @@ void QTorrentHandle::queue_position_down() const {
void QTorrentHandle::queue_position_up() const { void QTorrentHandle::queue_position_up() const {
Q_ASSERT(h.is_valid()); Q_ASSERT(h.is_valid());
h.queue_position_up(); if(h.queue_position() > 0)
h.queue_position_up();
} }

2
src/webui/index.html

@ -39,8 +39,10 @@
<ul> <ul>
<li><a id="resumeAllLink">Start All</a></li> <li><a id="resumeAllLink">Start All</a></li>
<li><a id="pauseAllLink">Pause All</a></li> <li><a id="pauseAllLink">Pause All</a></li>
<li><a id="recheckAllLink">Recheck All</a></li>
<li class="divider"><a id="resumeLink">Start</a></li> <li class="divider"><a id="resumeLink">Start</a></li>
<li><a id="pauseLink">Pause</a></li> <li><a id="pauseLink">Pause</a></li>
<li><a id="recheckLink">Recheck</a></li>
<li class="divider"><a id="deleteLink">Delete</a></li> <li class="divider"><a id="deleteLink">Delete</a></li>
<li><a id="deletePermLink">Delete from HD</a></li> <li><a id="deletePermLink">Delete from HD</a></li>
</ul> </ul>

13
src/webui/scripts/mocha-init.js

@ -53,6 +53,13 @@ initializeWindows = function(){
height: 120 height: 120
}); });
}); });
addClickEvent('delete', function(e){ addClickEvent('delete', function(e){
new Event(e).stop(); new Event(e).stop();
@ -67,6 +74,8 @@ initializeWindows = function(){
}); });
} }
}); });
addClickEvent('deletePerm', function(e){ addClickEvent('deletePerm', function(e){
new Event(e).stop(); 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){ addClickEvent(item, function(e){
new Event(e).stop(); new Event(e).stop();
if($("Tab1").hasClass('active')) { if($("Tab1").hasClass('active')) {
@ -105,6 +114,8 @@ initializeWindows = function(){
}); });
}); });
addClickEvent('bug', function(e){ addClickEvent('bug', function(e){
new Event(e).stop(); new Event(e).stop();
new MochaUI.Window({ new MochaUI.Window({

Loading…
Cancel
Save