qBittorrent
Statistics Class Reference

#include <statistics.h>

Inheritance diagram for Statistics:
Collaboration diagram for Statistics:

Public Member Functions

 Statistics (BitTorrent::Session *session)
 
 ~Statistics ()
 
quint64 getAlltimeDL () const
 
quint64 getAlltimeUL () const
 

Private Slots

void gather ()
 

Private Member Functions

void save () const
 
void load ()
 

Private Attributes

BitTorrent::Sessionm_session
 
quint64 m_alltimeUL
 
quint64 m_alltimeDL
 
quint64 m_sessionUL
 
quint64 m_sessionDL
 
qint64 m_lastWrite
 
bool m_dirty
 
QTimer m_timer
 

Detailed Description

Definition at line 39 of file statistics.h.

Constructor & Destructor Documentation

◆ Statistics()

Statistics::Statistics ( BitTorrent::Session session)
explicit

Definition at line 41 of file statistics.cpp.

42  : QObject(session)
43  , m_session(session)
44  , m_sessionUL(0)
45  , m_sessionDL(0)
46  , m_lastWrite(0)
47  , m_dirty(false)
48 {
49  load();
50  connect(&m_timer, &QTimer::timeout, this, &Statistics::gather);
51  m_timer.start(60 * 1000);
52 }
quint64 m_sessionDL
Definition: statistics.h:63
bool m_dirty
Definition: statistics.h:65
quint64 m_sessionUL
Definition: statistics.h:62
BitTorrent::Session * m_session
Definition: statistics.h:58
void load()
Definition: statistics.cpp:104
QTimer m_timer
Definition: statistics.h:67
void gather()
Definition: statistics.cpp:71
qint64 m_lastWrite
Definition: statistics.h:64

References gather(), load(), and m_timer.

Here is the call graph for this function:

◆ ~Statistics()

Statistics::~Statistics ( )

Definition at line 54 of file statistics.cpp.

55 {
56  if (m_dirty)
57  m_lastWrite = 0;
58  save();
59 }
void save() const
Definition: statistics.cpp:88

References m_dirty, m_lastWrite, and save().

Here is the call graph for this function:

Member Function Documentation

◆ gather

void Statistics::gather ( )
privateslot

Definition at line 71 of file statistics.cpp.

72 {
73  const SessionStatus &ss = m_session->status();
74  if (ss.totalDownload > m_sessionDL)
75  {
77  m_dirty = true;
78  }
79  if (ss.totalUpload > m_sessionUL)
80  {
82  m_dirty = true;
83  }
84 
85  save();
86 }
const SessionStatus & status() const
Definition: session.cpp:4301

References m_dirty, m_session, m_sessionDL, m_sessionUL, save(), BitTorrent::Session::status(), BitTorrent::SessionStatus::totalDownload, and BitTorrent::SessionStatus::totalUpload.

Referenced by Statistics().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getAlltimeDL()

quint64 Statistics::getAlltimeDL ( ) const

Definition at line 61 of file statistics.cpp.

62 {
63  return m_alltimeDL + m_sessionDL;
64 }
quint64 m_alltimeDL
Definition: statistics.h:61

References m_alltimeDL, and m_sessionDL.

Referenced by BitTorrent::Session::getAlltimeDL().

Here is the caller graph for this function:

◆ getAlltimeUL()

quint64 Statistics::getAlltimeUL ( ) const

Definition at line 66 of file statistics.cpp.

67 {
68  return m_alltimeUL + m_sessionUL;
69 }
quint64 m_alltimeUL
Definition: statistics.h:60

References m_alltimeUL, and m_sessionUL.

Referenced by BitTorrent::Session::getAlltimeUL().

Here is the caller graph for this function:

◆ load()

void Statistics::load ( )
private

Definition at line 104 of file statistics.cpp.

105 {
106  const SettingsPtr s = Profile::instance()->applicationSettings(QLatin1String("qBittorrent-data"));
107  const QVariantHash v = s->value("Stats/AllStats").toHash();
108 
109  m_alltimeDL = v["AlltimeDL"].toULongLong();
110  m_alltimeUL = v["AlltimeUL"].toULongLong();
111 }
SettingsPtr applicationSettings(const QString &name) const
Definition: profile.cpp:109
static const Profile * instance()
Definition: profile.cpp:67
std::unique_ptr< QSettings > SettingsPtr
Definition: profile.h:44

References Profile::applicationSettings(), Profile::instance(), m_alltimeDL, and m_alltimeUL.

Referenced by Statistics().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ save()

void Statistics::save ( ) const
private

Definition at line 88 of file statistics.cpp.

89 {
90  const qint64 now = QDateTime::currentMSecsSinceEpoch();
91 
92  if (!m_dirty || ((now - m_lastWrite) < SAVE_INTERVAL))
93  return;
94 
95  SettingsPtr s = Profile::instance()->applicationSettings(QLatin1String("qBittorrent-data"));
96  QVariantHash v;
97  v.insert("AlltimeDL", m_alltimeDL + m_sessionDL);
98  v.insert("AlltimeUL", m_alltimeUL + m_sessionUL);
99  s->setValue("Stats/AllStats", v);
100  m_dirty = false;
101  m_lastWrite = now;
102 }
static const qint64 SAVE_INTERVAL
Definition: statistics.cpp:37

References Profile::applicationSettings(), Profile::instance(), m_alltimeDL, m_alltimeUL, m_dirty, m_lastWrite, m_sessionDL, m_sessionUL, and SAVE_INTERVAL.

Referenced by gather(), and ~Statistics().

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ m_alltimeDL

quint64 Statistics::m_alltimeDL
private

Definition at line 61 of file statistics.h.

Referenced by getAlltimeDL(), load(), and save().

◆ m_alltimeUL

quint64 Statistics::m_alltimeUL
private

Definition at line 60 of file statistics.h.

Referenced by getAlltimeUL(), load(), and save().

◆ m_dirty

bool Statistics::m_dirty
mutableprivate

Definition at line 65 of file statistics.h.

Referenced by gather(), save(), and ~Statistics().

◆ m_lastWrite

qint64 Statistics::m_lastWrite
mutableprivate

Definition at line 64 of file statistics.h.

Referenced by save(), and ~Statistics().

◆ m_session

BitTorrent::Session* Statistics::m_session
private

Definition at line 58 of file statistics.h.

Referenced by gather().

◆ m_sessionDL

quint64 Statistics::m_sessionDL
private

Definition at line 63 of file statistics.h.

Referenced by gather(), getAlltimeDL(), and save().

◆ m_sessionUL

quint64 Statistics::m_sessionUL
private

Definition at line 62 of file statistics.h.

Referenced by gather(), getAlltimeUL(), and save().

◆ m_timer

QTimer Statistics::m_timer
private

Definition at line 67 of file statistics.h.

Referenced by Statistics().


The documentation for this class was generated from the following files: