Browse Source

Reuse alert dispatcher

Instead of using a specific alert handler in `SessionImpl::saveResumeData()`, reuse the generic
one.
adaptive-webui-19844
Chocobo1 2 years ago
parent
commit
c94152c47c
No known key found for this signature in database
GPG Key ID: 210D9C873253A68C
  1. 18
      src/base/bittorrent/sessionimpl.cpp
  2. 1
      src/base/bittorrent/sessionimpl.h
  3. 9
      src/base/bittorrent/torrentimpl.cpp

18
src/base/bittorrent/sessionimpl.cpp

@ -2444,6 +2444,12 @@ void SessionImpl::handleTorrentSaveResumeDataRequested(const TorrentImpl *torren
++m_numResumeData; ++m_numResumeData;
} }
void SessionImpl::handleTorrentSaveResumeDataFailed(const TorrentImpl *torrent)
{
Q_UNUSED(torrent);
--m_numResumeData;
}
QVector<Torrent *> SessionImpl::torrents() const QVector<Torrent *> SessionImpl::torrents() const
{ {
QVector<Torrent *> result; QVector<Torrent *> result;
@ -2904,16 +2910,12 @@ void SessionImpl::saveResumeData()
bool hasWantedAlert = false; bool hasWantedAlert = false;
for (const lt::alert *a : alerts) for (const lt::alert *a : alerts)
{ {
switch (a->type()) if (const int alertType = a->type();
(alertType == lt::save_resume_data_alert::alert_type)
|| (alertType == lt::save_resume_data_failed_alert::alert_type))
{ {
case lt::save_resume_data_failed_alert::alert_type:
hasWantedAlert = true;
--m_numResumeData;
break;
case lt::save_resume_data_alert::alert_type:
hasWantedAlert = true; hasWantedAlert = true;
dispatchTorrentAlert(static_cast<const lt::torrent_alert *>(a)); handleAlert(a);
break;
} }
} }

1
src/base/bittorrent/sessionimpl.h

@ -410,6 +410,7 @@ namespace BitTorrent
// Torrent interface // Torrent interface
void handleTorrentNeedSaveResumeData(const TorrentImpl *torrent); void handleTorrentNeedSaveResumeData(const TorrentImpl *torrent);
void handleTorrentSaveResumeDataRequested(const TorrentImpl *torrent); void handleTorrentSaveResumeDataRequested(const TorrentImpl *torrent);
void handleTorrentSaveResumeDataFailed(const TorrentImpl *torrent);
void handleTorrentShareLimitChanged(TorrentImpl *const torrent); void handleTorrentShareLimitChanged(TorrentImpl *const torrent);
void handleTorrentNameChanged(TorrentImpl *const torrent); void handleTorrentNameChanged(TorrentImpl *const torrent);
void handleTorrentSavePathChanged(TorrentImpl *const torrent); void handleTorrentSavePathChanged(TorrentImpl *const torrent);

9
src/base/bittorrent/torrentimpl.cpp

@ -1949,8 +1949,13 @@ void TorrentImpl::prepareResumeData(const lt::add_torrent_params &params)
void TorrentImpl::handleSaveResumeDataFailedAlert(const lt::save_resume_data_failed_alert *p) void TorrentImpl::handleSaveResumeDataFailedAlert(const lt::save_resume_data_failed_alert *p)
{ {
Q_UNUSED(p); if (p->error != lt::errors::resume_data_not_modified)
Q_ASSERT_X(false, Q_FUNC_INFO, "This point should be unreachable since libtorrent 1.2.11"); {
LogMsg(tr("Generate resume data failed. Torrent: \"%1\". Reason: \"%2\"")
.arg(name(), QString::fromLocal8Bit(p->error.message().c_str())), Log::CRITICAL);
}
m_session->handleTorrentSaveResumeDataFailed(this);
} }
void TorrentImpl::handleFastResumeRejectedAlert(const lt::fastresume_rejected_alert *p) void TorrentImpl::handleFastResumeRejectedAlert(const lt::fastresume_rejected_alert *p)

Loading…
Cancel
Save