Skip to content

Commit

Permalink
Merge pull request qbittorrent#2191 from glassez/webui
Browse files Browse the repository at this point in the history
WebUI: Implement server-side filtering, sorting and limit/offset.
  • Loading branch information
sledgehammer999 committed Dec 7, 2014
2 parents 14d27d9 + 0e87b96 commit 3672363
Show file tree
Hide file tree
Showing 12 changed files with 1,146 additions and 831 deletions.
89 changes: 88 additions & 1 deletion src/qtlibtorrent/qtorrenthandle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
#include "preferences.h"
#include "qtorrenthandle.h"
#include "torrentpersistentdata.h"
#include "qbtsession.h"
#include <libtorrent/version.hpp>
#include <libtorrent/magnet_uri.hpp>
#include <libtorrent/torrent_info.hpp>
Expand Down Expand Up @@ -403,7 +404,52 @@ bool QTorrentHandle::has_metadata() const {
}

void QTorrentHandle::file_progress(std::vector<size_type>& fp) const {
torrent_handle::file_progress(fp, torrent_handle::piece_granularity);
torrent_handle::file_progress(fp, torrent_handle::piece_granularity);
}

QTorrentState QTorrentHandle::torrentState() const {
QTorrentState state = QTorrentState::Unknown;
libtorrent::torrent_status s = status(torrent_handle::query_accurate_download_counters);

if (is_paused(s)) {
if (has_error(s))
state = QTorrentState::Error;
else
state = is_seed(s) ? QTorrentState::PausedUploading : QTorrentState::PausedDownloading;
}
else {
if (QBtSession::instance()->isQueueingEnabled() && is_queued(s)) {
state = is_seed(s) ? QTorrentState::QueuedUploading : QTorrentState::QueuedDownloading;
}
else {
switch (s.state) {
case torrent_status::finished:
case torrent_status::seeding:
state = s.upload_payload_rate > 0 ? QTorrentState::Uploading : QTorrentState::StalledUploading;
break;
case torrent_status::allocating:
case torrent_status::checking_files:
case torrent_status::queued_for_checking:
case torrent_status::checking_resume_data:
state = is_seed(s) ? QTorrentState::CheckingUploading : QTorrentState::CheckingDownloading;
break;
case torrent_status::downloading:
case torrent_status::downloading_metadata:
state = s.download_payload_rate > 0 ? QTorrentState::Downloading : QTorrentState::StalledDownloading;
break;
default:
qWarning("Unrecognized torrent status, should not happen!!! status was %d", this->state());
}
}
}

return state;
}

qulonglong QTorrentHandle::eta() const
{
libtorrent::torrent_status s = status(torrent_handle::query_accurate_download_counters);
return QBtSession::instance()->getETA(hash(), s);
}

//
Expand Down Expand Up @@ -681,3 +727,44 @@ QString QTorrentHandle::filepath_at(const libtorrent::torrent_info &info, unsign
return fsutils::fromNativePath(misc::toQStringU(info.files().file_path(index)));

}


QTorrentState::QTorrentState(int value)
: m_value(value)
{
}

QString QTorrentState::toString() const
{
switch (m_value) {
case Error:
return "error";
case Uploading:
return "uploading";
case PausedUploading:
return "pausedUP";
case QueuedUploading:
return "queuedUP";
case StalledUploading:
return "stalledUP";
case CheckingUploading:
return "checkingUP";
case Downloading:
return "downloading";
case PausedDownloading:
return "pausedDL";
case QueuedDownloading:
return "queuedDL";
case StalledDownloading:
return "stalledDL";
case CheckingDownloading:
return "checkingDL";
default:
return "unknown";
}
}

QTorrentState::operator int() const
{
return m_value;
}
32 changes: 32 additions & 0 deletions src/qtlibtorrent/qtorrenthandle.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,36 @@ QT_BEGIN_NAMESPACE
class QStringList;
QT_END_NAMESPACE

class QTorrentState
{
public:
enum {
Unknown = -1,

Error,

Uploading,
PausedUploading,
QueuedUploading,
StalledUploading,
CheckingUploading,

Downloading,
PausedDownloading,
QueuedDownloading,
StalledDownloading,
CheckingDownloading
};

QTorrentState(int value);

operator int() const;
QString toString() const;

private:
int m_value;
};

// A wrapper for torrent_handle in libtorrent
// to interact well with Qt types
class QTorrentHandle : public libtorrent::torrent_handle {
Expand Down Expand Up @@ -94,6 +124,8 @@ class QTorrentHandle : public libtorrent::torrent_handle {
void downloading_pieces(libtorrent::bitfield& bf) const;
bool has_metadata() const;
void file_progress(std::vector<libtorrent::size_type>& fp) const;
QTorrentState torrentState() const;
qulonglong eta() const;

//
// Setters
Expand Down
Loading

0 comments on commit 3672363

Please sign in to comment.