mirror of
https://github.com/qbittorrent/qBittorrent.git
synced 2024-11-29 13:58:51 +03:00
Fix previous commits.
This commit is contained in:
parent
c8035dff1e
commit
a6fa27467f
7 changed files with 57 additions and 65 deletions
|
@ -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));
|
||||
|
|
|
@ -1,15 +1,15 @@
|
|||
#include "alertdispatcher.h"
|
||||
|
||||
#include <boost/bind.hpp>
|
||||
#include <boost/make_shared.hpp>
|
||||
#include <QMutexLocker>
|
||||
|
||||
QAlertDispatcher::QAlertDispatcher(libtorrent::session *session, QObject* parent)
|
||||
: QObject(parent)
|
||||
, session(session)
|
||||
, m_session(session)
|
||||
, current_tag(new QAtomicPointer<QAlertDispatcher>(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<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) {
|
||||
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<libtorrent::alert*>& out) {
|
||||
assert(out.empty());
|
||||
void QAlertDispatcher::getPendingAlerts(std::deque<libtorrent::alert*>& 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<QAtomicPointer<QAlertDispatcher>
|
|||
|
||||
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())
|
||||
|
|
|
@ -8,8 +8,7 @@
|
|||
#include <QSharedPointer>
|
||||
#include <libtorrent/session.hpp>
|
||||
|
||||
class QAlertDispatcher : public QObject
|
||||
{
|
||||
class QAlertDispatcher : public QObject {
|
||||
Q_OBJECT
|
||||
Q_DISABLE_COPY(QAlertDispatcher)
|
||||
|
||||
|
@ -18,7 +17,7 @@ public:
|
|||
~QAlertDispatcher();
|
||||
|
||||
void getPendingAlertsNoWait(std::deque<libtorrent::alert*>&);
|
||||
void getPendingAlerts(std::deque<libtorrent::alert*>&);
|
||||
void getPendingAlerts(std::deque<libtorrent::alert*>&, 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<libtorrent::alert*> alerts;
|
||||
|
|
|
@ -1635,7 +1635,12 @@ void QBtSession::saveFastResumeData() {
|
|||
}
|
||||
while (num_resume_data > 0) {
|
||||
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)
|
||||
{
|
||||
|
@ -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<save_resume_data_alert const*>(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);
|
||||
|
|
|
@ -33,7 +33,6 @@
|
|||
#include <QFile>
|
||||
#include <QDir>
|
||||
#include <QByteArray>
|
||||
#include <QDateTime>
|
||||
#include <math.h>
|
||||
#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)
|
||||
|
|
|
@ -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<libtorrent::torrent_status> &statuses)
|
||||
{
|
||||
void TorrentModel::stateUpdated(const std::vector<libtorrent::torrent_status> &statuses) {
|
||||
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;
|
||||
|
||||
const int row = torrentRow(misc::toQString(status.handle.info_hash()));
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue