-
-
Notifications
You must be signed in to change notification settings - Fork 4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Avoid using QDateTime for announce timestamps
- Loading branch information
Showing
6 changed files
with
35 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
/* | ||
* Bittorrent Client using Qt and libtorrent. | ||
* Copyright (C) 2015-2023 Vladimir Golovnev <[email protected]> | ||
* Copyright (C) 2015-2024 Vladimir Golovnev <[email protected]> | ||
* | ||
* This program is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU General Public License | ||
|
@@ -28,7 +28,6 @@ | |
|
||
#pragma once | ||
|
||
#include <QDateTime> | ||
#include <QHash> | ||
#include <QString> | ||
|
||
|
@@ -59,8 +58,8 @@ namespace BitTorrent | |
int numLeeches = -1; | ||
int numDownloaded = -1; | ||
|
||
QDateTime nextAnnounceTime {}; | ||
QDateTime minAnnounceTime {}; | ||
qint64 nextAnnounceTime = 0; | ||
qint64 minAnnounceTime = 0; | ||
}; | ||
|
||
struct TrackerEntryStatus | ||
|
@@ -76,8 +75,8 @@ namespace BitTorrent | |
int numLeeches = -1; | ||
int numDownloaded = -1; | ||
|
||
QDateTime nextAnnounceTime {}; | ||
QDateTime minAnnounceTime {}; | ||
qint64 nextAnnounceTime = 0; | ||
qint64 minAnnounceTime = 0; | ||
|
||
QHash<std::pair<QString, int>, TrackerEndpointStatus> endpoints {}; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
/* | ||
* Bittorrent Client using Qt and libtorrent. | ||
* Copyright (C) 2023 Vladimir Golovnev <[email protected]> | ||
* Copyright (C) 2023-2024 Vladimir Golovnev <[email protected]> | ||
* Copyright (C) 2006 Christophe Dumez <[email protected]> | ||
* | ||
* This program is free software; you can redistribute it and/or | ||
|
@@ -40,6 +40,7 @@ | |
#include <boost/multi_index/tag.hpp> | ||
|
||
#include <QColor> | ||
#include <QDateTime> | ||
#include <QList> | ||
#include <QPointer> | ||
#include <QScopeGuard> | ||
|
@@ -141,12 +142,12 @@ struct TrackerListModel::Item final | |
int numLeeches = -1; | ||
int numDownloaded = -1; | ||
|
||
QDateTime nextAnnounceTime {}; | ||
QDateTime minAnnounceTime {}; | ||
qint64 nextAnnounceTime = 0; | ||
qint64 minAnnounceTime = 0; | ||
|
||
qint64 secsToNextAnnounce = 0; | ||
qint64 secsToMinAnnounce = 0; | ||
QDateTime announceTimestamp; | ||
qint64 announceTimestamp = 0; | ||
|
||
std::weak_ptr<Item> parentItem {}; | ||
|
||
|
@@ -211,7 +212,7 @@ void TrackerListModel::Item::fillFrom(const BitTorrent::TrackerEntryStatus &trac | |
minAnnounceTime = trackerEntryStatus.minAnnounceTime; | ||
secsToNextAnnounce = 0; | ||
secsToMinAnnounce = 0; | ||
announceTimestamp = QDateTime(); | ||
announceTimestamp = 0; | ||
} | ||
|
||
void TrackerListModel::Item::fillFrom(const BitTorrent::TrackerEndpointStatus &endpointStatus) | ||
|
@@ -230,7 +231,7 @@ void TrackerListModel::Item::fillFrom(const BitTorrent::TrackerEndpointStatus &e | |
minAnnounceTime = endpointStatus.minAnnounceTime; | ||
secsToNextAnnounce = 0; | ||
secsToMinAnnounce = 0; | ||
announceTimestamp = QDateTime(); | ||
announceTimestamp = 0; | ||
} | ||
|
||
TrackerListModel::TrackerListModel(BitTorrent::Session *btSession, QObject *parent) | ||
|
@@ -369,7 +370,7 @@ void TrackerListModel::populate() | |
for (const BitTorrent::TrackerEntryStatus &status : trackers) | ||
addTrackerItem(status); | ||
|
||
m_announceTimestamp = QDateTime::currentDateTime(); | ||
m_announceTimestamp = QDateTime::currentSecsSinceEpoch(); | ||
m_announceRefreshTimer->start(ANNOUNCE_TIME_REFRESH_INTERVAL); | ||
} | ||
|
||
|
@@ -448,7 +449,7 @@ void TrackerListModel::refreshAnnounceTimes() | |
if (!m_torrent) | ||
return; | ||
|
||
m_announceTimestamp = QDateTime::currentDateTime(); | ||
m_announceTimestamp = QDateTime::currentSecsSinceEpoch(); | ||
emit dataChanged(index(0, COL_NEXT_ANNOUNCE), index((rowCount() - 1), COL_MIN_ANNOUNCE)); | ||
for (int i = 0; i < rowCount(); ++i) | ||
{ | ||
|
@@ -545,8 +546,8 @@ QVariant TrackerListModel::data(const QModelIndex &index, const int role) const | |
|
||
if (itemPtr->announceTimestamp != m_announceTimestamp) | ||
{ | ||
itemPtr->secsToNextAnnounce = std::max<qint64>(0, m_announceTimestamp.secsTo(itemPtr->nextAnnounceTime)); | ||
itemPtr->secsToMinAnnounce = std::max<qint64>(0, m_announceTimestamp.secsTo(itemPtr->minAnnounceTime)); | ||
itemPtr->secsToNextAnnounce = std::max<qint64>(0, (itemPtr->nextAnnounceTime - m_announceTimestamp)); | ||
itemPtr->secsToMinAnnounce = std::max<qint64>(0, (itemPtr->minAnnounceTime - m_announceTimestamp)); | ||
itemPtr->announceTimestamp = m_announceTimestamp; | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
/* | ||
* Bittorrent Client using Qt and libtorrent. | ||
* Copyright (C) 2023 Vladimir Golovnev <[email protected]> | ||
* Copyright (C) 2023-2024 Vladimir Golovnev <[email protected]> | ||
* Copyright (C) 2006 Christophe Dumez <[email protected]> | ||
* | ||
* This program is free software; you can redistribute it and/or | ||
|
@@ -33,7 +33,6 @@ | |
|
||
#include <QtContainerFwd> | ||
#include <QAbstractItemModel> | ||
#include <QDateTime> | ||
|
||
#include "base/bittorrent/trackerentrystatus.h" | ||
|
||
|
@@ -115,6 +114,6 @@ class TrackerListModel final : public QAbstractItemModel | |
class Items; | ||
std::unique_ptr<Items> m_items; | ||
|
||
QDateTime m_announceTimestamp; | ||
qint64 m_announceTimestamp = 0; | ||
QTimer *m_announceRefreshTimer = nullptr; | ||
}; |