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 @@ @@ -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

2
src/GUI.cpp

@ -380,8 +380,6 @@ void GUI::fullDiskError(QTorrentHandle& h, QString msg) const { @@ -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()));
}

2
src/TransferListDelegate.h

@ -37,6 +37,7 @@ @@ -37,6 +37,7 @@
#include <QStyleOptionViewItem>
#include <QStyleOptionViewItemV2>
#include <QApplication>
#include <QPainter>
#include "misc.h"
// Defines for download list list columns
@ -57,6 +58,7 @@ public: @@ -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;
}

20
src/TransferListWidget.cpp

@ -99,6 +99,8 @@ TransferListWidget::TransferListWidget(QWidget *parent, bittorrent *_BTSession): @@ -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) { @@ -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) { @@ -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) { @@ -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) { @@ -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() { @@ -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() { @@ -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();

3
src/TransferListWidget.h

@ -75,6 +75,8 @@ protected slots: @@ -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: @@ -86,7 +88,6 @@ public slots:
void startAllTorrents();
void pauseSelectedTorrents();
void pauseAllTorrents();
void pauseTorrent(QString hash);
void deleteSelectedTorrents();
void deletePermSelectedTorrents();
void increasePrioSelectedTorrents();

30
src/bittorrent.cpp

@ -164,19 +164,6 @@ bool bittorrent::isQueueingEnabled() const { @@ -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) { @@ -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() { @@ -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<listen_failed_alert*>(a.get())) {

4
src/bittorrent.h

@ -103,8 +103,6 @@ class bittorrent : public QObject { @@ -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 { @@ -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);

36
src/httpconnection.cpp

@ -33,6 +33,7 @@ @@ -33,6 +33,7 @@
#include "httpserver.h"
#include "eventmanager.h"
#include "json.h"
#include "bittorrent.h"
#include <QTcpSocket>
#include <QDateTime>
#include <QStringList>
@ -42,8 +43,8 @@ @@ -42,8 +43,8 @@
#include <QDebug>
#include <QTemporaryFile>
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) @@ -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<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 @@ @@ -38,6 +38,7 @@
class QTcpSocket;
class HttpServer;
class bittorrent;
class HttpConnection : public QObject
{
@ -45,6 +46,7 @@ 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 @@ -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:

4
src/httpserver.cpp

@ -69,7 +69,7 @@ void HttpServer::newHttpConnection() @@ -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() @@ -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)));
}
}

3
src/qtorrenthandle.cpp

@ -453,7 +453,8 @@ void QTorrentHandle::queue_position_down() const { @@ -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();
}

2
src/webui/index.html

@ -39,8 +39,10 @@ @@ -39,8 +39,10 @@
<ul>
<li><a id="resumeAllLink">Start 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><a id="pauseLink">Pause</a></li>
<li><a id="recheckLink">Recheck</a></li>
<li class="divider"><a id="deleteLink">Delete</a></li>
<li><a id="deletePermLink">Delete from HD</a></li>
</ul>

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

@ -54,6 +54,13 @@ initializeWindows = function(){ @@ -54,6 +54,13 @@ initializeWindows = function(){
});
});
addClickEvent('delete', function(e){
new Event(e).stop();
if($("Tab1").hasClass('active')) {
@ -68,6 +75,8 @@ initializeWindows = function(){ @@ -68,6 +75,8 @@ initializeWindows = function(){
}
});
addClickEvent('deletePerm', function(e){
new Event(e).stop();
if($("Tab1").hasClass('active')) {
@ -82,7 +91,7 @@ initializeWindows = function(){ @@ -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(){ @@ -105,6 +114,8 @@ initializeWindows = function(){
});
});
addClickEvent('bug', function(e){
new Event(e).stop();
new MochaUI.Window({

Loading…
Cancel
Save