mirror of
https://github.com/qbittorrent/qBittorrent.git
synced 2025-12-19 23:17:21 -06:00
Extract alert handling to separate functions.
This commit is contained in:
@@ -2145,6 +2145,83 @@ void QBtSession::readAlerts() {
|
||||
void QBtSession::handleAlert(libtorrent::alert* a) {
|
||||
try {
|
||||
if (torrent_finished_alert* p = dynamic_cast<torrent_finished_alert*>(a)) {
|
||||
handleTorrentFinishedAlert(p);
|
||||
}
|
||||
else if (save_resume_data_alert* p = dynamic_cast<save_resume_data_alert*>(a)) {
|
||||
handleSaveResumeDataAlert(p);
|
||||
}
|
||||
else if (file_renamed_alert* p = dynamic_cast<file_renamed_alert*>(a)) {
|
||||
handleFileRenamedAlert(p);
|
||||
}
|
||||
else if (torrent_deleted_alert* p = dynamic_cast<torrent_deleted_alert*>(a)) {
|
||||
handleTorrentDeletedAlert(p);
|
||||
}
|
||||
else if (storage_moved_alert* p = dynamic_cast<storage_moved_alert*>(a)) {
|
||||
handleStorageMovedAlert(p);
|
||||
}
|
||||
else if (metadata_received_alert* p = dynamic_cast<metadata_received_alert*>(a)) {
|
||||
handleMetadataReceivedAlert(p);
|
||||
}
|
||||
else if (file_error_alert* p = dynamic_cast<file_error_alert*>(a)) {
|
||||
handleFileErrorAlert(p);
|
||||
}
|
||||
else if (file_completed_alert* p = dynamic_cast<file_completed_alert*>(a)) {
|
||||
handleFileCompletedAlert(p);
|
||||
}
|
||||
else if (torrent_paused_alert* p = dynamic_cast<torrent_paused_alert*>(a)) {
|
||||
handleTorrentPausedAlert(p);
|
||||
}
|
||||
else if (tracker_error_alert* p = dynamic_cast<tracker_error_alert*>(a)) {
|
||||
handleTrackerErrorAlert(p);
|
||||
}
|
||||
else if (tracker_reply_alert* p = dynamic_cast<tracker_reply_alert*>(a)) {
|
||||
handleTrackerReplyAlert(p);
|
||||
}
|
||||
else if (tracker_warning_alert* p = dynamic_cast<tracker_warning_alert*>(a)) {
|
||||
handleTrackerWarningAlert(p);
|
||||
}
|
||||
else if (portmap_error_alert* p = dynamic_cast<portmap_error_alert*>(a)) {
|
||||
handlePortmapWarningAlert(p);
|
||||
}
|
||||
else if (portmap_alert* p = dynamic_cast<portmap_alert*>(a)) {
|
||||
handlePortmapAlert(p);
|
||||
}
|
||||
else if (peer_blocked_alert* p = dynamic_cast<peer_blocked_alert*>(a)) {
|
||||
handlePeerBlockedAlert(p);
|
||||
}
|
||||
else if (peer_ban_alert* p = dynamic_cast<peer_ban_alert*>(a)) {
|
||||
handlePeerBanAlert(p);
|
||||
}
|
||||
else if (fastresume_rejected_alert* p = dynamic_cast<fastresume_rejected_alert*>(a)) {
|
||||
handleFastResumeRejectedAlert(p);
|
||||
}
|
||||
else if (url_seed_alert* p = dynamic_cast<url_seed_alert*>(a)) {
|
||||
handleUrlSeedAlert(p);
|
||||
}
|
||||
else if (listen_succeeded_alert *p = dynamic_cast<listen_succeeded_alert*>(a)) {
|
||||
handleListenSucceededAlert(p);
|
||||
}
|
||||
else if (listen_failed_alert *p = dynamic_cast<listen_failed_alert*>(a)) {
|
||||
handleListenFailedAlert(p);
|
||||
}
|
||||
else if (torrent_checked_alert* p = dynamic_cast<torrent_checked_alert*>(a)) {
|
||||
handleTorrentCheckedAlert(p);
|
||||
}
|
||||
else if (external_ip_alert *p = dynamic_cast<external_ip_alert*>(a)) {
|
||||
handleExternalIPAlert(p);
|
||||
}
|
||||
else if (state_update_alert *p = dynamic_cast<state_update_alert *>(a)) {
|
||||
handleStateUpdateAlert(p);
|
||||
}
|
||||
else if (stats_alert *p = dynamic_cast<stats_alert *>(a)) {
|
||||
handleStatsAlert(p);
|
||||
}
|
||||
} catch (const std::exception& e) {
|
||||
qWarning() << "Caught exception in readAlerts(): " << e.what();
|
||||
}
|
||||
}
|
||||
|
||||
void QBtSession::handleTorrentFinishedAlert(libtorrent::torrent_finished_alert* p) {
|
||||
QTorrentHandle h(p->handle);
|
||||
if (h.is_valid()) {
|
||||
const QString hash = h.hash();
|
||||
@@ -2252,8 +2329,9 @@ void QBtSession::handleAlert(libtorrent::alert* a) {
|
||||
#endif // DISABLE_GUI
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (save_resume_data_alert* p = dynamic_cast<save_resume_data_alert*>(a)) {
|
||||
}
|
||||
|
||||
void QBtSession::handleSaveResumeDataAlert(libtorrent::save_resume_data_alert* p) {
|
||||
const QDir torrentBackup(fsutils::BTBackupLocation());
|
||||
const QTorrentHandle h(p->handle);
|
||||
if (h.is_valid() && p->resume_data) {
|
||||
@@ -2270,8 +2348,9 @@ void QBtSession::handleAlert(libtorrent::alert* a) {
|
||||
resume_file.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (file_renamed_alert* p = dynamic_cast<file_renamed_alert*>(a)) {
|
||||
}
|
||||
|
||||
void QBtSession::handleFileRenamedAlert(libtorrent::file_renamed_alert* p) {
|
||||
QTorrentHandle h(p->handle);
|
||||
if (h.is_valid()) {
|
||||
if (h.num_files() > 1) {
|
||||
@@ -2293,8 +2372,9 @@ void QBtSession::handleAlert(libtorrent::alert* a) {
|
||||
emit savePathChanged(h);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (torrent_deleted_alert* p = dynamic_cast<torrent_deleted_alert*>(a)) {
|
||||
}
|
||||
|
||||
void QBtSession::handleTorrentDeletedAlert(libtorrent::torrent_deleted_alert* p) {
|
||||
qDebug("A torrent was deleted from the hard disk, attempting to remove the root folder too...");
|
||||
QString hash = misc::toQString(p->info_hash);
|
||||
if (!hash.isEmpty()) {
|
||||
@@ -2315,8 +2395,9 @@ void QBtSession::handleAlert(libtorrent::alert* a) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (storage_moved_alert* p = dynamic_cast<storage_moved_alert*>(a)) {
|
||||
}
|
||||
|
||||
void QBtSession::handleStorageMovedAlert(libtorrent::storage_moved_alert* p) {
|
||||
QTorrentHandle h(p->handle);
|
||||
if (h.is_valid()) {
|
||||
// Attempt to remove old folder if empty
|
||||
@@ -2335,8 +2416,9 @@ void QBtSession::handleAlert(libtorrent::alert* a) {
|
||||
emit savePathChanged(h);
|
||||
//h.force_recheck();
|
||||
}
|
||||
}
|
||||
else if (metadata_received_alert* p = dynamic_cast<metadata_received_alert*>(a)) {
|
||||
}
|
||||
|
||||
void QBtSession::handleMetadataReceivedAlert(libtorrent::metadata_received_alert* p) {
|
||||
QTorrentHandle h(p->handle);
|
||||
Preferences pref;
|
||||
if (h.is_valid()) {
|
||||
@@ -2382,10 +2464,10 @@ void QBtSession::handleAlert(libtorrent::alert* a) {
|
||||
// and the torrent can be paused when metadata is received
|
||||
emit pausedTorrent(h);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
else if (file_error_alert* p = dynamic_cast<file_error_alert*>(a)) {
|
||||
void QBtSession::handleFileErrorAlert(libtorrent::file_error_alert* p) {
|
||||
QTorrentHandle h(p->handle);
|
||||
if (h.is_valid()) {
|
||||
h.pause();
|
||||
@@ -2398,8 +2480,9 @@ void QBtSession::handleAlert(libtorrent::alert* a) {
|
||||
emit pausedTorrent(h);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (file_completed_alert* p = dynamic_cast<file_completed_alert*>(a)) {
|
||||
}
|
||||
|
||||
void QBtSession::handleFileCompletedAlert(libtorrent::file_completed_alert* p) {
|
||||
QTorrentHandle h(p->handle);
|
||||
qDebug("A file completed download in torrent %s", qPrintable(h.name()));
|
||||
if (appendqBExtension) {
|
||||
@@ -2412,8 +2495,9 @@ void QBtSession::handleAlert(libtorrent::alert* a) {
|
||||
h.rename_file(p->index, name);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (torrent_paused_alert* p = dynamic_cast<torrent_paused_alert*>(a)) {
|
||||
}
|
||||
|
||||
void QBtSession::handleTorrentPausedAlert(libtorrent::torrent_paused_alert* p) {
|
||||
if (p->handle.is_valid()) {
|
||||
QTorrentHandle h(p->handle);
|
||||
if (!HiddenData::hasData(h.hash())) {
|
||||
@@ -2422,8 +2506,9 @@ void QBtSession::handleAlert(libtorrent::alert* a) {
|
||||
emit pausedTorrent(h);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (tracker_error_alert* p = dynamic_cast<tracker_error_alert*>(a)) {
|
||||
}
|
||||
|
||||
void QBtSession::handleTrackerErrorAlert(libtorrent::tracker_error_alert* p) {
|
||||
// Level: fatal
|
||||
QTorrentHandle h(p->handle);
|
||||
if (h.is_valid()) {
|
||||
@@ -2440,8 +2525,9 @@ void QBtSession::handleAlert(libtorrent::alert* a) {
|
||||
emit trackerAuthenticationRequired(h);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (tracker_reply_alert* p = dynamic_cast<tracker_reply_alert*>(a)) {
|
||||
}
|
||||
|
||||
void QBtSession::handleTrackerReplyAlert(libtorrent::tracker_reply_alert* p) {
|
||||
const QTorrentHandle h(p->handle);
|
||||
if (h.is_valid()) {
|
||||
qDebug("Received a tracker reply from %s (Num_peers=%d)", p->url.c_str(), p->num_peers);
|
||||
@@ -2454,8 +2540,9 @@ void QBtSession::handleAlert(libtorrent::alert* a) {
|
||||
trackers_data.insert(tracker_url, data);
|
||||
trackersInfos[h.hash()] = trackers_data;
|
||||
}
|
||||
}
|
||||
else if (tracker_warning_alert* p = dynamic_cast<tracker_warning_alert*>(a)) {
|
||||
}
|
||||
|
||||
void QBtSession::handleTrackerWarningAlert(libtorrent::tracker_warning_alert* p) {
|
||||
const QTorrentHandle h(p->handle);
|
||||
if (h.is_valid()) {
|
||||
// Connection was successful now but there is a warning message
|
||||
@@ -2467,33 +2554,38 @@ void QBtSession::handleAlert(libtorrent::alert* a) {
|
||||
trackersInfos[h.hash()] = trackers_data;
|
||||
qDebug("Received a tracker warning from %s: %s", p->url.c_str(), p->msg.c_str());
|
||||
}
|
||||
}
|
||||
else if (portmap_error_alert* p = dynamic_cast<portmap_error_alert*>(a)) {
|
||||
}
|
||||
|
||||
void QBtSession::handlePortmapWarningAlert(libtorrent::portmap_error_alert* p) {
|
||||
addConsoleMessage(tr("UPnP/NAT-PMP: Port mapping failure, message: %1").arg(misc::toQStringU(p->message())), "red");
|
||||
//emit UPnPError(QString(p->msg().c_str()));
|
||||
}
|
||||
else if (portmap_alert* p = dynamic_cast<portmap_alert*>(a)) {
|
||||
}
|
||||
|
||||
void QBtSession::handlePortmapAlert(libtorrent::portmap_alert* p) {
|
||||
qDebug("UPnP Success, msg: %s", p->message().c_str());
|
||||
addConsoleMessage(tr("UPnP/NAT-PMP: Port mapping successful, message: %1").arg(misc::toQStringU(p->message())), "blue");
|
||||
//emit UPnPSuccess(QString(p->msg().c_str()));
|
||||
}
|
||||
else if (peer_blocked_alert* p = dynamic_cast<peer_blocked_alert*>(a)) {
|
||||
}
|
||||
|
||||
void QBtSession::handlePeerBlockedAlert(libtorrent::peer_blocked_alert* p) {
|
||||
boost::system::error_code ec;
|
||||
string ip = p->ip.to_string(ec);
|
||||
if (!ec) {
|
||||
addPeerBanMessage(QString::fromLatin1(ip.c_str()), true);
|
||||
//emit peerBlocked(QString::fromLatin1(ip.c_str()));
|
||||
}
|
||||
}
|
||||
else if (peer_ban_alert* p = dynamic_cast<peer_ban_alert*>(a)) {
|
||||
}
|
||||
|
||||
void QBtSession::handlePeerBanAlert(libtorrent::peer_ban_alert* p) {
|
||||
boost::system::error_code ec;
|
||||
string ip = p->ip.address().to_string(ec);
|
||||
if (!ec) {
|
||||
addPeerBanMessage(QString::fromLatin1(ip.c_str()), false);
|
||||
//emit peerBlocked(QString::fromLatin1(ip.c_str()));
|
||||
}
|
||||
}
|
||||
else if (fastresume_rejected_alert* p = dynamic_cast<fastresume_rejected_alert*>(a)) {
|
||||
}
|
||||
|
||||
void QBtSession::handleFastResumeRejectedAlert(libtorrent::fastresume_rejected_alert* p) {
|
||||
QTorrentHandle h(p->handle);
|
||||
if (h.is_valid()) {
|
||||
qDebug("/!\\ Fast resume failed for %s, reason: %s", qPrintable(h.name()), p->message().c_str());
|
||||
@@ -2508,12 +2600,14 @@ void QBtSession::handleAlert(libtorrent::alert* a) {
|
||||
addConsoleMessage(tr("Reason: %1").arg(misc::toQStringU(p->message())));
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (url_seed_alert* p = dynamic_cast<url_seed_alert*>(a)) {
|
||||
}
|
||||
|
||||
void QBtSession::handleUrlSeedAlert(libtorrent::url_seed_alert* p) {
|
||||
addConsoleMessage(tr("Url seed lookup failed for url: %1, message: %2").arg(misc::toQString(p->url)).arg(misc::toQStringU(p->message())), QString::fromUtf8("red"));
|
||||
//emit urlSeedProblem(QString::fromUtf8(p->url.c_str()), QString::fromUtf8(p->msg().c_str()));
|
||||
}
|
||||
else if (listen_succeeded_alert *p = dynamic_cast<listen_succeeded_alert*>(a)) {
|
||||
}
|
||||
|
||||
void QBtSession::handleListenSucceededAlert(libtorrent::listen_succeeded_alert *p) {
|
||||
boost::system::error_code ec;
|
||||
QString proto = "TCP";
|
||||
#if LIBTORRENT_VERSION_NUM >= 10000
|
||||
@@ -2534,8 +2628,9 @@ void QBtSession::handleAlert(libtorrent::alert* a) {
|
||||
for ( ; it != itend; ++it) {
|
||||
it->force_reannounce();
|
||||
}
|
||||
}
|
||||
else if (listen_failed_alert *p = dynamic_cast<listen_failed_alert*>(a)) {
|
||||
}
|
||||
|
||||
void QBtSession::handleListenFailedAlert(libtorrent::listen_failed_alert *p) {
|
||||
boost::system::error_code ec;
|
||||
QString proto = "TCP";
|
||||
#if LIBTORRENT_VERSION_NUM >= 10000
|
||||
@@ -2552,8 +2647,10 @@ void QBtSession::handleAlert(libtorrent::alert* a) {
|
||||
#endif
|
||||
qDebug() << "Failed listening on " << proto << p->endpoint.address().to_string(ec).c_str() << "/" << p->endpoint.port();
|
||||
addConsoleMessage(tr("qBittorrent failed listening on interface %1 port: %2/%3. Reason: %4", "e.g: qBittorrent failed listening on interface 192.168.0.1 port: TCP/6881. Reason: already in use").arg(p->endpoint.address().to_string(ec).c_str()).arg(proto).arg(QString::number(p->endpoint.port())).arg(misc::toQStringU(p->error.message())), "red");
|
||||
}
|
||||
else if (torrent_checked_alert* p = dynamic_cast<torrent_checked_alert*>(a)) {
|
||||
|
||||
}
|
||||
|
||||
void QBtSession::handleTorrentCheckedAlert(libtorrent::torrent_checked_alert* p) {
|
||||
QTorrentHandle h(p->handle);
|
||||
if (h.is_valid()) {
|
||||
const QString hash = h.hash();
|
||||
@@ -2578,20 +2675,19 @@ void QBtSession::handleAlert(libtorrent::alert* a) {
|
||||
emit pausedTorrent(h);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (external_ip_alert *p = dynamic_cast<external_ip_alert*>(a)) {
|
||||
}
|
||||
|
||||
void QBtSession::handleExternalIPAlert(libtorrent::external_ip_alert *p) {
|
||||
boost::system::error_code ec;
|
||||
addConsoleMessage(tr("External IP: %1", "e.g. External IP: 192.168.0.1").arg(p->external_address.to_string(ec).c_str()), "blue");
|
||||
}
|
||||
else if (state_update_alert *p = dynamic_cast<state_update_alert *>(a)) {
|
||||
}
|
||||
|
||||
void QBtSession::handleStateUpdateAlert(libtorrent::state_update_alert *p) {
|
||||
emit stateUpdate(p->status);
|
||||
}
|
||||
else if (stats_alert *p = dynamic_cast<stats_alert *>(a)) {
|
||||
}
|
||||
|
||||
void QBtSession::handleStatsAlert(libtorrent::stats_alert *p) {
|
||||
emit statsReceived(*p);
|
||||
}
|
||||
} catch (const std::exception& e) {
|
||||
qWarning() << "Caught exception in readAlerts(): " << e.what();
|
||||
}
|
||||
}
|
||||
|
||||
void QBtSession::recheckTorrent(const QString &hash) {
|
||||
|
||||
@@ -195,6 +195,30 @@ private:
|
||||
void recoverPersistentData(const QString &hash, const std::vector<char> &buf);
|
||||
void backupPersistentData(const QString &hash, boost::shared_ptr<libtorrent::entry> data);
|
||||
void handleAlert(libtorrent::alert* a);
|
||||
void handleTorrentFinishedAlert(libtorrent::torrent_finished_alert* p);
|
||||
void handleSaveResumeDataAlert(libtorrent::save_resume_data_alert* p);
|
||||
void handleFileRenamedAlert(libtorrent::file_renamed_alert* p);
|
||||
void handleTorrentDeletedAlert(libtorrent::torrent_deleted_alert* p);
|
||||
void handleStorageMovedAlert(libtorrent::storage_moved_alert* p);
|
||||
void handleMetadataReceivedAlert(libtorrent::metadata_received_alert* p);
|
||||
void handleFileErrorAlert(libtorrent::file_error_alert* p);
|
||||
void handleFileCompletedAlert(libtorrent::file_completed_alert* p);
|
||||
void handleTorrentPausedAlert(libtorrent::torrent_paused_alert* p);
|
||||
void handleTrackerErrorAlert(libtorrent::tracker_error_alert* p);
|
||||
void handleTrackerReplyAlert(libtorrent::tracker_reply_alert* p);
|
||||
void handleTrackerWarningAlert(libtorrent::tracker_warning_alert* p);
|
||||
void handlePortmapWarningAlert(libtorrent::portmap_error_alert* p);
|
||||
void handlePortmapAlert(libtorrent::portmap_alert* p);
|
||||
void handlePeerBlockedAlert(libtorrent::peer_blocked_alert* p);
|
||||
void handlePeerBanAlert(libtorrent::peer_ban_alert* p);
|
||||
void handleFastResumeRejectedAlert(libtorrent::fastresume_rejected_alert* p);
|
||||
void handleUrlSeedAlert(libtorrent::url_seed_alert* p);
|
||||
void handleListenSucceededAlert(libtorrent::listen_succeeded_alert *p);
|
||||
void handleListenFailedAlert(libtorrent::listen_failed_alert *p);
|
||||
void handleTorrentCheckedAlert(libtorrent::torrent_checked_alert* p);
|
||||
void handleExternalIPAlert(libtorrent::external_ip_alert *p);
|
||||
void handleStateUpdateAlert(libtorrent::state_update_alert *p);
|
||||
void handleStatsAlert(libtorrent::stats_alert *p);
|
||||
|
||||
private slots:
|
||||
void addTorrentsFromScanFolder(QStringList&);
|
||||
|
||||
Reference in New Issue
Block a user