@@ -4188,14 +4188,29 @@ bool SessionImpl::isPaused() const
4188
4188
4189
4189
void SessionImpl::pause ()
4190
4190
{
4191
- if (!m_isPaused)
4191
+ if (m_isPaused)
4192
+ return ;
4193
+
4194
+ if (isRestored ())
4192
4195
{
4193
- if (isRestored ())
4194
- m_nativeSession->pause ();
4196
+ m_nativeSession->pause ();
4195
4197
4196
- m_isPaused = true ;
4197
- emit paused ();
4198
+ for (TorrentImpl *torrent : asConst (m_torrents))
4199
+ {
4200
+ torrent->resetTrackerEntryStatuses ();
4201
+
4202
+ const QList<TrackerEntryStatus> trackers = torrent->trackers ();
4203
+ QHash<QString, TrackerEntryStatus> updatedTrackers;
4204
+ updatedTrackers.reserve (trackers.size ());
4205
+
4206
+ for (const TrackerEntryStatus &status : trackers)
4207
+ updatedTrackers.emplace (status.url , status);
4208
+ emit trackerEntryStatusesUpdated (torrent, updatedTrackers);
4209
+ }
4198
4210
}
4211
+
4212
+ m_isPaused = true ;
4213
+ emit paused ();
4199
4214
}
4200
4215
4201
4216
void SessionImpl::resume ()
@@ -5417,9 +5432,6 @@ void SessionImpl::handleMoveTorrentStorageJobFinished(const Path &newPath)
5417
5432
if (torrent)
5418
5433
{
5419
5434
torrent->handleMoveStorageJobFinished (newPath, finishedJob.context , torrentHasOutstandingJob);
5420
- // The torrent may become "finished" at the end of the move if it was moved
5421
- // from the "incomplete" location after downloading finished.
5422
- processPendingFinishedTorrents ();
5423
5435
}
5424
5436
else if (!torrentHasOutstandingJob)
5425
5437
{
@@ -5683,6 +5695,11 @@ void SessionImpl::setTorrentContentLayout(const TorrentContentLayout value)
5683
5695
// Read alerts sent by libtorrent session
5684
5696
void SessionImpl::readAlerts ()
5685
5697
{
5698
+ // cache current datetime of Qt and libtorrent clocks in order
5699
+ // to optimize conversion of time points from lt to Qt clocks
5700
+ m_ltNow = lt::clock_type::now ();
5701
+ m_qNow = QDateTime::currentDateTime ();
5702
+
5686
5703
const std::vector<lt::alert *> alerts = getPendingAlerts ();
5687
5704
5688
5705
Q_ASSERT (m_loadedTorrents.isEmpty ());
@@ -5709,6 +5726,9 @@ void SessionImpl::readAlerts()
5709
5726
}
5710
5727
}
5711
5728
5729
+ // Some torrents may become "finished" after different alerts handling.
5730
+ processPendingFinishedTorrents ();
5731
+
5712
5732
processTrackerStatuses ();
5713
5733
}
5714
5734
@@ -6348,8 +6368,6 @@ void SessionImpl::handleStateUpdateAlert(const lt::state_update_alert *alert)
6348
6368
if (!updatedTorrents.isEmpty ())
6349
6369
emit torrentsUpdated (updatedTorrents);
6350
6370
6351
- processPendingFinishedTorrents ();
6352
-
6353
6371
if (m_needSaveTorrentsQueue)
6354
6372
saveTorrentsQueue ();
6355
6373
@@ -6546,3 +6564,9 @@ void SessionImpl::handleRemovedTorrent(const TorrentID &torrentID, const QString
6546
6564
6547
6565
m_removingTorrents.erase (removingTorrentDataIter);
6548
6566
}
6567
+
6568
+ QDateTime SessionImpl::fromLTTimePoint32 (const libtorrent::time_point32 &timePoint) const
6569
+ {
6570
+ const auto secsSinceNow = lt::duration_cast<lt::seconds>(timePoint - m_ltNow + lt::milliseconds (500 )).count ();
6571
+ return m_qNow.addSecs (secsSinceNow);
6572
+ }
0 commit comments