diff --git a/src/properties/propertieswidget.cpp b/src/properties/propertieswidget.cpp index 3552d52c1..a92199fe6 100644 --- a/src/properties/propertieswidget.cpp +++ b/src/properties/propertieswidget.cpp @@ -317,8 +317,8 @@ void PropertiesWidget::loadDynamicData() { if (!h.is_valid() || main_window->getCurrentTabWidget() != transferList || state != VISIBLE) return; try { libtorrent::torrent_status status = h.status(torrent_handle::query_accurate_download_counters - | torrent_handle::query_distributed_copies - | torrent_handle::query_pieces); + | torrent_handle::query_distributed_copies + | torrent_handle::query_pieces); // Transfer infos if (stackedProperties->currentIndex() == PropTabBar::MAIN_TAB) { wasted->setText(misc::friendlyUnit(status.total_failed_bytes+status.total_redundant_bytes)); diff --git a/src/qtlibtorrent/alertdispatcher.cpp b/src/qtlibtorrent/alertdispatcher.cpp index 345d4e163..5bd20aed9 100644 --- a/src/qtlibtorrent/alertdispatcher.cpp +++ b/src/qtlibtorrent/alertdispatcher.cpp @@ -1,15 +1,15 @@ #include "alertdispatcher.h" #include -#include #include QAlertDispatcher::QAlertDispatcher(libtorrent::session *session, QObject* parent) : QObject(parent) - , session(session) + , m_session(session) , current_tag(new QAtomicPointer(this)) - , event_posted(false) { - session->set_alert_dispatch(boost::bind(&QAlertDispatcher::dispatch, current_tag, _1)); + , event_posted(false) +{ + m_session->set_alert_dispatch(boost::bind(&QAlertDispatcher::dispatch, current_tag, _1)); } QAlertDispatcher::~QAlertDispatcher() { @@ -21,32 +21,32 @@ QAlertDispatcher::~QAlertDispatcher() { // with invalid tag it simply discard an alert. { - QMutexLocker lock(&(alerts_mutex)); + QMutexLocker lock(&alerts_mutex); *current_tag = 0; current_tag.clear(); } typedef boost::function)> dispatch_function_t; - session->set_alert_dispatch(dispatch_function_t()); + m_session->set_alert_dispatch(dispatch_function_t()); } void QAlertDispatcher::getPendingAlertsNoWait(std::deque& out) { Q_ASSERT(out.empty()); - QMutexLocker lock(&(alerts_mutex)); - std::swap(alerts, out); + QMutexLocker lock(&alerts_mutex); + alerts.swap(out); event_posted = false; } -void QAlertDispatcher::getPendingAlerts(std::deque& out) { - assert(out.empty()); +void QAlertDispatcher::getPendingAlerts(std::deque& out, unsigned long time) { + Q_ASSERT(out.empty()); - QMutexLocker lock(&(alerts_mutex)); + QMutexLocker lock(&alerts_mutex); while (alerts.empty()) - alerts_condvar.wait(&(alerts_mutex)); + alerts_condvar.wait(&alerts_mutex, time); - std::swap(alerts, out); + alerts.swap(out); event_posted = false; } @@ -58,8 +58,7 @@ void QAlertDispatcher::dispatch(QSharedPointer QMutexLocker lock(&(that->alerts_mutex)); - that = *tag; - if (!that) + if (!*tag) return; bool was_empty = that->alerts.empty(); @@ -85,7 +84,7 @@ void QAlertDispatcher::enqueueToMainThread() { void QAlertDispatcher::deliverSignal() { emit alertsReceived(); - QMutexLocker lock(&(alerts_mutex)); + QMutexLocker lock(&alerts_mutex); event_posted = false; if (!alerts.empty()) diff --git a/src/qtlibtorrent/alertdispatcher.h b/src/qtlibtorrent/alertdispatcher.h index 55e937621..a2ce981ff 100644 --- a/src/qtlibtorrent/alertdispatcher.h +++ b/src/qtlibtorrent/alertdispatcher.h @@ -8,8 +8,7 @@ #include #include -class QAlertDispatcher : public QObject -{ +class QAlertDispatcher : public QObject { Q_OBJECT Q_DISABLE_COPY(QAlertDispatcher) @@ -18,7 +17,7 @@ public: ~QAlertDispatcher(); void getPendingAlertsNoWait(std::deque&); - void getPendingAlerts(std::deque&); + void getPendingAlerts(std::deque&, unsigned long time = ULONG_MAX); signals: void alertsReceived(); @@ -32,7 +31,7 @@ private slots: void deliverSignal(); private: - libtorrent::session *session; + libtorrent::session *m_session; QMutex alerts_mutex; QWaitCondition alerts_condvar; std::deque alerts; diff --git a/src/qtlibtorrent/qbtsession.cpp b/src/qtlibtorrent/qbtsession.cpp index 29d736c82..df6303524 100755 --- a/src/qtlibtorrent/qbtsession.cpp +++ b/src/qtlibtorrent/qbtsession.cpp @@ -1635,7 +1635,12 @@ void QBtSession::saveFastResumeData() { } while (num_resume_data > 0) { std::deque 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::const_iterator i = alerts.begin(), end = alerts.end(); i != end; ++i) { @@ -1649,18 +1654,26 @@ void QBtSession::saveFastResumeData() { if (rda->handle.is_valid()) s->remove_torrent(rda->handle); }catch(libtorrent::libtorrent_exception) {} + delete a; continue; } save_resume_data_alert const* rd = dynamic_cast(a); if (!rd) { + delete a; continue; } // Saving fast resume data was successful --num_resume_data; - if (!rd->resume_data) continue; + if (!rd->resume_data) { + delete a; + continue; + } QDir torrentBackup(fsutils::BTBackupLocation()); const QTorrentHandle h(rd->handle); - if (!h.is_valid()) continue; + if (!h.is_valid()) { + delete a; + continue; + } try { // Remove old fastresume file if it exists backupPersistentData(h.hash(), rd->resume_data); diff --git a/src/qtlibtorrent/qtorrenthandle.cpp b/src/qtlibtorrent/qtorrenthandle.cpp index a44eae05e..43c887681 100644 --- a/src/qtlibtorrent/qtorrenthandle.cpp +++ b/src/qtlibtorrent/qtorrenthandle.cpp @@ -33,7 +33,6 @@ #include #include #include -#include #include #include "fs_utils.h" #include "misc.h" @@ -616,35 +615,29 @@ bool QTorrentHandle::operator ==(const QTorrentHandle& new_h) const { 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; } -bool QTorrentHandle::is_queued(const libtorrent::torrent_status &status) -{ +bool QTorrentHandle::is_queued(const libtorrent::torrent_status &status) { 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 || 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 || 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(); } -float QTorrentHandle::progress(const libtorrent::torrent_status &status) -{ +float QTorrentHandle::progress(const libtorrent::torrent_status &status) { if (!status.total_wanted) return 0.; if (status.total_wanted_done == status.total_wanted) diff --git a/src/qtlibtorrent/torrentmodel.cpp b/src/qtlibtorrent/torrentmodel.cpp index cbb303908..dd001711a 100644 --- a/src/qtlibtorrent/torrentmodel.cpp +++ b/src/qtlibtorrent/torrentmodel.cpp @@ -37,52 +37,43 @@ using namespace libtorrent; -namespace -{ - QIcon get_paused_icon() - { +namespace { +QIcon get_paused_icon() { static QIcon cached = QIcon(":/Icons/skin/paused.png"); return cached; } - QIcon get_queued_icon() - { +QIcon get_queued_icon() { static QIcon cached = QIcon(":/Icons/skin/queued.png"); return cached; } - QIcon get_downloading_icon() - { +QIcon get_downloading_icon() { static QIcon cached = QIcon(":/Icons/skin/downloading.png"); return cached; } - QIcon get_stalled_downloading_icon() - { +QIcon get_stalled_downloading_icon() { static QIcon cached = QIcon(":/Icons/skin/stalledDL.png"); return cached; } - QIcon get_uploading_icon() - { +QIcon get_uploading_icon() { static QIcon cached = QIcon(":/Icons/skin/uploading.png"); return cached; } - QIcon get_stalled_uploading_icon() - { +QIcon get_stalled_uploading_icon() { static QIcon cached = QIcon(":/Icons/skin/stalledUP.png"); return cached; } - QIcon get_checking_icon() - { +QIcon get_checking_icon() { static QIcon cached = QIcon(":/Icons/skin/checking.png"); return cached; } - QIcon get_error_icon() - { +QIcon get_error_icon() { static QIcon cached = QIcon(":/Icons/skin/error.png"); return cached; } @@ -101,13 +92,11 @@ TorrentModelItem::TorrentModelItem(const QTorrentHandle &h) m_name = h.name(); } -void TorrentModelItem::refreshStatus(libtorrent::torrent_status const& status) -{ +void TorrentModelItem::refreshStatus(libtorrent::torrent_status const& status) { m_lastStatus = status; } -TorrentModelItem::State TorrentModelItem::state() const -{ +TorrentModelItem::State TorrentModelItem::state() const { try { // Pause or Queued if (m_torrent.is_paused(m_lastStatus)) { @@ -549,12 +538,10 @@ void TorrentModel::handleTorrentAboutToBeRemoved(const QTorrentHandle &h) } } -void TorrentModel::stateUpdated(const std::vector &statuses) -{ +void TorrentModel::stateUpdated(const std::vector &statuses) { typedef std::vector 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; const int row = torrentRow(misc::toQString(status.handle.info_hash())); diff --git a/src/qtlibtorrent/torrentstatistics.cpp b/src/qtlibtorrent/torrentstatistics.cpp index b0229887d..13b4cea2f 100644 --- a/src/qtlibtorrent/torrentstatistics.cpp +++ b/src/qtlibtorrent/torrentstatistics.cpp @@ -13,7 +13,8 @@ TorrentStatistics::TorrentStatistics(QBtSession* session, QObject* parent) , m_sessionUL(0) , m_sessionDL(0) , m_lastWrite(0) - , m_dirty(false) { + , m_dirty(false) +{ loadStats(); connect(&m_timer, SIGNAL(timeout()), this, SLOT(gatherStats())); m_timer.start(60 * 1000);