mirror of
https://github.com/qbittorrent/qBittorrent
synced 2025-08-20 21:33:27 -07:00
This commit is contained in:
parent
00f9180b81
commit
8790092a81
2 changed files with 43 additions and 9 deletions
|
@ -30,6 +30,7 @@
|
||||||
|
|
||||||
#include <QMutexLocker>
|
#include <QMutexLocker>
|
||||||
#include <QList>
|
#include <QList>
|
||||||
|
#include <QDateTime>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "qbtsession.h"
|
#include "qbtsession.h"
|
||||||
|
@ -61,7 +62,8 @@ private:
|
||||||
};
|
};
|
||||||
|
|
||||||
TorrentSpeedMonitor::TorrentSpeedMonitor(QBtSession* session) :
|
TorrentSpeedMonitor::TorrentSpeedMonitor(QBtSession* session) :
|
||||||
QThread(session), m_abort(false), m_session(session)
|
QThread(session), m_abort(false), m_session(session),
|
||||||
|
sessionUL(0), sessionDL(0), lastWrite(0), dirty(false)
|
||||||
{
|
{
|
||||||
connect(m_session, SIGNAL(deletedTorrent(QString)), SLOT(removeSamples(QString)));
|
connect(m_session, SIGNAL(deletedTorrent(QString)), SLOT(removeSamples(QString)));
|
||||||
connect(m_session, SIGNAL(pausedTorrent(QTorrentHandle)), SLOT(removeSamples(QTorrentHandle)));
|
connect(m_session, SIGNAL(pausedTorrent(QTorrentHandle)), SLOT(removeSamples(QTorrentHandle)));
|
||||||
|
@ -72,6 +74,8 @@ TorrentSpeedMonitor::~TorrentSpeedMonitor() {
|
||||||
m_abort = true;
|
m_abort = true;
|
||||||
m_abortCond.wakeOne();
|
m_abortCond.wakeOne();
|
||||||
wait();
|
wait();
|
||||||
|
dirty = true;
|
||||||
|
lastWrite = 0;
|
||||||
saveStats();
|
saveStats();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -188,22 +192,50 @@ void TorrentSpeedMonitor::getSamples()
|
||||||
} catch(invalid_handle&) {}
|
} catch(invalid_handle&) {}
|
||||||
}
|
}
|
||||||
libtorrent::session_status ss = m_session->getSessionStatus();
|
libtorrent::session_status ss = m_session->getSessionStatus();
|
||||||
|
if (ss.total_download > sessionDL) {
|
||||||
sessionDL = ss.total_download;
|
sessionDL = ss.total_download;
|
||||||
|
dirty = true;
|
||||||
|
}
|
||||||
|
if (ss.total_upload > sessionUL) {
|
||||||
sessionUL = ss.total_upload;
|
sessionUL = ss.total_upload;
|
||||||
|
dirty = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void TorrentSpeedMonitor::saveStats() const {
|
void TorrentSpeedMonitor::saveStats() const {
|
||||||
QIniSettings s;
|
if (!dirty && !(QDateTime::currentMSecsSinceEpoch() - lastWrite >= 15*60*1000))
|
||||||
|
return;
|
||||||
|
QIniSettings s("qBittorrent", "qBittorrent-data");
|
||||||
QVariantHash v;
|
QVariantHash v;
|
||||||
v.insert("AlltimeDL", alltimeDL + sessionDL);
|
v.insert("AlltimeDL", alltimeDL + sessionDL);
|
||||||
v.insert("AlltimeUL", alltimeUL + sessionUL);
|
v.insert("AlltimeUL", alltimeUL + sessionUL);
|
||||||
s.setValue("Stats/AllStats", v);
|
s.setValue("Stats/AllStats", v);
|
||||||
|
dirty = false;
|
||||||
|
lastWrite = QDateTime::currentMSecsSinceEpoch();
|
||||||
}
|
}
|
||||||
|
|
||||||
void TorrentSpeedMonitor::loadStats() {
|
void TorrentSpeedMonitor::loadStats() {
|
||||||
QIniSettings s;
|
// Temp code. Versions v3.1.4 and v3.1.5 saved the data in the qbittorrent.ini file.
|
||||||
QVariantHash v(s.value("Stats/AllStats", QVariantHash()).toHash());
|
// This code reads the data from there, writes it to the new file, and removes the keys
|
||||||
|
// from the old file. This code should be removed after some time has passed.
|
||||||
|
// e.g. When we reach v3.3.0
|
||||||
|
QIniSettings s_old;
|
||||||
|
QIniSettings s("qBittorrent", "qBittorrent-data");
|
||||||
|
QVariantHash v;
|
||||||
|
|
||||||
|
// Let's test if the qbittorrent.ini holds the key
|
||||||
|
if (s_old.contains("Stats/AllStats")) {
|
||||||
|
v = s_old.value("Stats/AllStats").toHash();
|
||||||
|
dirty = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
v = s.value("Stats/AllStats").toHash();
|
||||||
|
|
||||||
alltimeDL = v["AlltimeDL"].toULongLong();
|
alltimeDL = v["AlltimeDL"].toULongLong();
|
||||||
alltimeUL = v["AlltimeUL"].toULongLong();
|
alltimeUL = v["AlltimeUL"].toULongLong();
|
||||||
sessionDL = sessionUL = 0;
|
|
||||||
|
if (dirty) {
|
||||||
|
saveStats();
|
||||||
|
s_old.remove("Stats/AllStats");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -73,8 +73,10 @@ private:
|
||||||
// Will overflow at 15.9 EiB
|
// Will overflow at 15.9 EiB
|
||||||
quint64 alltimeUL;
|
quint64 alltimeUL;
|
||||||
quint64 alltimeDL;
|
quint64 alltimeDL;
|
||||||
quint64 sessionUL;
|
qint64 sessionUL;
|
||||||
quint64 sessionDL;
|
qint64 sessionDL;
|
||||||
|
mutable qint64 lastWrite;
|
||||||
|
mutable bool dirty;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // TORRENTSPEEDMONITOR_H
|
#endif // TORRENTSPEEDMONITOR_H
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue