Browse Source

Fix previous commits.

adaptive-webui-19844
sledgehammer999 11 years ago
parent
commit
a6fa27467f
  1. 4
      src/properties/propertieswidget.cpp
  2. 31
      src/qtlibtorrent/alertdispatcher.cpp
  3. 7
      src/qtlibtorrent/alertdispatcher.h
  4. 19
      src/qtlibtorrent/qbtsession.cpp
  5. 19
      src/qtlibtorrent/qtorrenthandle.cpp
  6. 39
      src/qtlibtorrent/torrentmodel.cpp
  7. 3
      src/qtlibtorrent/torrentstatistics.cpp

4
src/properties/propertieswidget.cpp

@ -317,8 +317,8 @@ void PropertiesWidget::loadDynamicData() {
if (!h.is_valid() || main_window->getCurrentTabWidget() != transferList || state != VISIBLE) return; if (!h.is_valid() || main_window->getCurrentTabWidget() != transferList || state != VISIBLE) return;
try { try {
libtorrent::torrent_status status = h.status(torrent_handle::query_accurate_download_counters libtorrent::torrent_status status = h.status(torrent_handle::query_accurate_download_counters
| torrent_handle::query_distributed_copies | torrent_handle::query_distributed_copies
| torrent_handle::query_pieces); | torrent_handle::query_pieces);
// Transfer infos // Transfer infos
if (stackedProperties->currentIndex() == PropTabBar::MAIN_TAB) { if (stackedProperties->currentIndex() == PropTabBar::MAIN_TAB) {
wasted->setText(misc::friendlyUnit(status.total_failed_bytes+status.total_redundant_bytes)); wasted->setText(misc::friendlyUnit(status.total_failed_bytes+status.total_redundant_bytes));

31
src/qtlibtorrent/alertdispatcher.cpp

@ -1,15 +1,15 @@
#include "alertdispatcher.h" #include "alertdispatcher.h"
#include <boost/bind.hpp> #include <boost/bind.hpp>
#include <boost/make_shared.hpp>
#include <QMutexLocker> #include <QMutexLocker>
QAlertDispatcher::QAlertDispatcher(libtorrent::session *session, QObject* parent) QAlertDispatcher::QAlertDispatcher(libtorrent::session *session, QObject* parent)
: QObject(parent) : QObject(parent)
, session(session) , m_session(session)
, current_tag(new QAtomicPointer<QAlertDispatcher>(this)) , current_tag(new QAtomicPointer<QAlertDispatcher>(this))
, event_posted(false) { , event_posted(false)
session->set_alert_dispatch(boost::bind(&QAlertDispatcher::dispatch, current_tag, _1)); {
m_session->set_alert_dispatch(boost::bind(&QAlertDispatcher::dispatch, current_tag, _1));
} }
QAlertDispatcher::~QAlertDispatcher() { QAlertDispatcher::~QAlertDispatcher() {
@ -21,32 +21,32 @@ QAlertDispatcher::~QAlertDispatcher() {
// with invalid tag it simply discard an alert. // with invalid tag it simply discard an alert.
{ {
QMutexLocker lock(&(alerts_mutex)); QMutexLocker lock(&alerts_mutex);
*current_tag = 0; *current_tag = 0;
current_tag.clear(); current_tag.clear();
} }
typedef boost::function<void (std::auto_ptr<libtorrent::alert>)> dispatch_function_t; typedef boost::function<void (std::auto_ptr<libtorrent::alert>)> dispatch_function_t;
session->set_alert_dispatch(dispatch_function_t()); m_session->set_alert_dispatch(dispatch_function_t());
} }
void QAlertDispatcher::getPendingAlertsNoWait(std::deque<libtorrent::alert*>& out) { void QAlertDispatcher::getPendingAlertsNoWait(std::deque<libtorrent::alert*>& out) {
Q_ASSERT(out.empty()); Q_ASSERT(out.empty());
QMutexLocker lock(&(alerts_mutex)); QMutexLocker lock(&alerts_mutex);
std::swap(alerts, out); alerts.swap(out);
event_posted = false; event_posted = false;
} }
void QAlertDispatcher::getPendingAlerts(std::deque<libtorrent::alert*>& out) { void QAlertDispatcher::getPendingAlerts(std::deque<libtorrent::alert*>& out, unsigned long time) {
assert(out.empty()); Q_ASSERT(out.empty());
QMutexLocker lock(&(alerts_mutex)); QMutexLocker lock(&alerts_mutex);
while (alerts.empty()) while (alerts.empty())
alerts_condvar.wait(&(alerts_mutex)); alerts_condvar.wait(&alerts_mutex, time);
std::swap(alerts, out); alerts.swap(out);
event_posted = false; event_posted = false;
} }
@ -58,8 +58,7 @@ void QAlertDispatcher::dispatch(QSharedPointer<QAtomicPointer<QAlertDispatcher>
QMutexLocker lock(&(that->alerts_mutex)); QMutexLocker lock(&(that->alerts_mutex));
that = *tag; if (!*tag)
if (!that)
return; return;
bool was_empty = that->alerts.empty(); bool was_empty = that->alerts.empty();
@ -85,7 +84,7 @@ void QAlertDispatcher::enqueueToMainThread() {
void QAlertDispatcher::deliverSignal() { void QAlertDispatcher::deliverSignal() {
emit alertsReceived(); emit alertsReceived();
QMutexLocker lock(&(alerts_mutex)); QMutexLocker lock(&alerts_mutex);
event_posted = false; event_posted = false;
if (!alerts.empty()) if (!alerts.empty())

7
src/qtlibtorrent/alertdispatcher.h

@ -8,8 +8,7 @@
#include <QSharedPointer> #include <QSharedPointer>
#include <libtorrent/session.hpp> #include <libtorrent/session.hpp>
class QAlertDispatcher : public QObject class QAlertDispatcher : public QObject {
{
Q_OBJECT Q_OBJECT
Q_DISABLE_COPY(QAlertDispatcher) Q_DISABLE_COPY(QAlertDispatcher)
@ -18,7 +17,7 @@ public:
~QAlertDispatcher(); ~QAlertDispatcher();
void getPendingAlertsNoWait(std::deque<libtorrent::alert*>&); void getPendingAlertsNoWait(std::deque<libtorrent::alert*>&);
void getPendingAlerts(std::deque<libtorrent::alert*>&); void getPendingAlerts(std::deque<libtorrent::alert*>&, unsigned long time = ULONG_MAX);
signals: signals:
void alertsReceived(); void alertsReceived();
@ -32,7 +31,7 @@ private slots:
void deliverSignal(); void deliverSignal();
private: private:
libtorrent::session *session; libtorrent::session *m_session;
QMutex alerts_mutex; QMutex alerts_mutex;
QWaitCondition alerts_condvar; QWaitCondition alerts_condvar;
std::deque<libtorrent::alert*> alerts; std::deque<libtorrent::alert*> alerts;

19
src/qtlibtorrent/qbtsession.cpp

@ -1635,7 +1635,12 @@ void QBtSession::saveFastResumeData() {
} }
while (num_resume_data > 0) { while (num_resume_data > 0) {
std::deque<alert*> alerts; std::deque<alert*> alerts;
m_alertDispatcher->getPendingAlerts(alerts); m_alertDispatcher->getPendingAlerts(alerts, 30*1000);
if (alerts.empty()) {
std::cerr << " aborting with " << num_resume_data << " outstanding "
"torrents to save resume data for" << std::endl;
break;
}
for (std::deque<alert*>::const_iterator i = alerts.begin(), end = alerts.end(); i != end; ++i) for (std::deque<alert*>::const_iterator i = alerts.begin(), end = alerts.end(); i != end; ++i)
{ {
@ -1649,18 +1654,26 @@ void QBtSession::saveFastResumeData() {
if (rda->handle.is_valid()) if (rda->handle.is_valid())
s->remove_torrent(rda->handle); s->remove_torrent(rda->handle);
}catch(libtorrent::libtorrent_exception) {} }catch(libtorrent::libtorrent_exception) {}
delete a;
continue; continue;
} }
save_resume_data_alert const* rd = dynamic_cast<save_resume_data_alert const*>(a); save_resume_data_alert const* rd = dynamic_cast<save_resume_data_alert const*>(a);
if (!rd) { if (!rd) {
delete a;
continue; continue;
} }
// Saving fast resume data was successful // Saving fast resume data was successful
--num_resume_data; --num_resume_data;
if (!rd->resume_data) continue; if (!rd->resume_data) {
delete a;
continue;
}
QDir torrentBackup(fsutils::BTBackupLocation()); QDir torrentBackup(fsutils::BTBackupLocation());
const QTorrentHandle h(rd->handle); const QTorrentHandle h(rd->handle);
if (!h.is_valid()) continue; if (!h.is_valid()) {
delete a;
continue;
}
try { try {
// Remove old fastresume file if it exists // Remove old fastresume file if it exists
backupPersistentData(h.hash(), rd->resume_data); backupPersistentData(h.hash(), rd->resume_data);

19
src/qtlibtorrent/qtorrenthandle.cpp

@ -33,7 +33,6 @@
#include <QFile> #include <QFile>
#include <QDir> #include <QDir>
#include <QByteArray> #include <QByteArray>
#include <QDateTime>
#include <math.h> #include <math.h>
#include "fs_utils.h" #include "fs_utils.h"
#include "misc.h" #include "misc.h"
@ -616,35 +615,29 @@ bool QTorrentHandle::operator ==(const QTorrentHandle& new_h) const {
return info_hash() == new_h.info_hash(); return info_hash() == new_h.info_hash();
} }
bool QTorrentHandle::is_paused(const libtorrent::torrent_status &status) bool QTorrentHandle::is_paused(const libtorrent::torrent_status &status) {
{
return status.paused && !status.auto_managed; return status.paused && !status.auto_managed;
} }
bool QTorrentHandle::is_queued(const libtorrent::torrent_status &status) bool QTorrentHandle::is_queued(const libtorrent::torrent_status &status) {
{
return status.paused && status.auto_managed; return status.paused && status.auto_managed;
} }
bool QTorrentHandle::is_seed(const libtorrent::torrent_status &status) bool QTorrentHandle::is_seed(const libtorrent::torrent_status &status) {
{
return status.state == torrent_status::finished return status.state == torrent_status::finished
|| status.state == torrent_status::seeding; || status.state == torrent_status::seeding;
} }
bool QTorrentHandle::is_checking(const libtorrent::torrent_status &status) bool QTorrentHandle::is_checking(const libtorrent::torrent_status &status) {
{
return status.state == torrent_status::checking_files return status.state == torrent_status::checking_files
|| status.state == torrent_status::checking_resume_data; || status.state == torrent_status::checking_resume_data;
} }
bool QTorrentHandle::has_error(const libtorrent::torrent_status &status) bool QTorrentHandle::has_error(const libtorrent::torrent_status &status) {
{
return status.paused && !status.error.empty(); return status.paused && !status.error.empty();
} }
float QTorrentHandle::progress(const libtorrent::torrent_status &status) float QTorrentHandle::progress(const libtorrent::torrent_status &status) {
{
if (!status.total_wanted) if (!status.total_wanted)
return 0.; return 0.;
if (status.total_wanted_done == status.total_wanted) if (status.total_wanted_done == status.total_wanted)

39
src/qtlibtorrent/torrentmodel.cpp

@ -37,52 +37,43 @@
using namespace libtorrent; using namespace libtorrent;
namespace namespace {
{ QIcon get_paused_icon() {
QIcon get_paused_icon()
{
static QIcon cached = QIcon(":/Icons/skin/paused.png"); static QIcon cached = QIcon(":/Icons/skin/paused.png");
return cached; return cached;
} }
QIcon get_queued_icon() QIcon get_queued_icon() {
{
static QIcon cached = QIcon(":/Icons/skin/queued.png"); static QIcon cached = QIcon(":/Icons/skin/queued.png");
return cached; return cached;
} }
QIcon get_downloading_icon() QIcon get_downloading_icon() {
{
static QIcon cached = QIcon(":/Icons/skin/downloading.png"); static QIcon cached = QIcon(":/Icons/skin/downloading.png");
return cached; return cached;
} }
QIcon get_stalled_downloading_icon() QIcon get_stalled_downloading_icon() {
{
static QIcon cached = QIcon(":/Icons/skin/stalledDL.png"); static QIcon cached = QIcon(":/Icons/skin/stalledDL.png");
return cached; return cached;
} }
QIcon get_uploading_icon() QIcon get_uploading_icon() {
{
static QIcon cached = QIcon(":/Icons/skin/uploading.png"); static QIcon cached = QIcon(":/Icons/skin/uploading.png");
return cached; return cached;
} }
QIcon get_stalled_uploading_icon() QIcon get_stalled_uploading_icon() {
{
static QIcon cached = QIcon(":/Icons/skin/stalledUP.png"); static QIcon cached = QIcon(":/Icons/skin/stalledUP.png");
return cached; return cached;
} }
QIcon get_checking_icon() QIcon get_checking_icon() {
{
static QIcon cached = QIcon(":/Icons/skin/checking.png"); static QIcon cached = QIcon(":/Icons/skin/checking.png");
return cached; return cached;
} }
QIcon get_error_icon() QIcon get_error_icon() {
{
static QIcon cached = QIcon(":/Icons/skin/error.png"); static QIcon cached = QIcon(":/Icons/skin/error.png");
return cached; return cached;
} }
@ -101,13 +92,11 @@ TorrentModelItem::TorrentModelItem(const QTorrentHandle &h)
m_name = h.name(); m_name = h.name();
} }
void TorrentModelItem::refreshStatus(libtorrent::torrent_status const& status) void TorrentModelItem::refreshStatus(libtorrent::torrent_status const& status) {
{
m_lastStatus = status; m_lastStatus = status;
} }
TorrentModelItem::State TorrentModelItem::state() const TorrentModelItem::State TorrentModelItem::state() const {
{
try { try {
// Pause or Queued // Pause or Queued
if (m_torrent.is_paused(m_lastStatus)) { if (m_torrent.is_paused(m_lastStatus)) {
@ -549,12 +538,10 @@ void TorrentModel::handleTorrentAboutToBeRemoved(const QTorrentHandle &h)
} }
} }
void TorrentModel::stateUpdated(const std::vector<libtorrent::torrent_status> &statuses) void TorrentModel::stateUpdated(const std::vector<libtorrent::torrent_status> &statuses) {
{
typedef std::vector<libtorrent::torrent_status> statuses_t; typedef std::vector<libtorrent::torrent_status> statuses_t;
for (statuses_t::const_iterator i = statuses.begin(), end = statuses.end(); i != end; ++i) for (statuses_t::const_iterator i = statuses.begin(), end = statuses.end(); i != end; ++i) {
{
libtorrent::torrent_status const& status = *i; libtorrent::torrent_status const& status = *i;
const int row = torrentRow(misc::toQString(status.handle.info_hash())); const int row = torrentRow(misc::toQString(status.handle.info_hash()));

3
src/qtlibtorrent/torrentstatistics.cpp

@ -13,7 +13,8 @@ TorrentStatistics::TorrentStatistics(QBtSession* session, QObject* parent)
, m_sessionUL(0) , m_sessionUL(0)
, m_sessionDL(0) , m_sessionDL(0)
, m_lastWrite(0) , m_lastWrite(0)
, m_dirty(false) { , m_dirty(false)
{
loadStats(); loadStats();
connect(&m_timer, SIGNAL(timeout()), this, SLOT(gatherStats())); connect(&m_timer, SIGNAL(timeout()), this, SLOT(gatherStats()));
m_timer.start(60 * 1000); m_timer.start(60 * 1000);

Loading…
Cancel
Save