From 565ffa7d1efa009408a81d923e1751e885299386 Mon Sep 17 00:00:00 2001 From: sledgehammer999 Date: Mon, 9 Apr 2018 18:19:33 +0300 Subject: [PATCH 1/3] Add 'Moving' state for torrents being relocated/moved This is another indication to the user that something is happening behind the scenes. Uses the same icon/color as "Checking" status. Torrents in the `Moving` state are considered as "Active". This should prevent accidental program exit from the user and inhibit system sleep. --- src/base/bittorrent/torrenthandle.cpp | 14 +++++++++++--- src/base/bittorrent/torrenthandle.h | 2 ++ src/gui/torrentmodel.cpp | 2 ++ src/gui/transferlistdelegate.cpp | 3 +++ src/webui/api/serialize/serialize_torrent.cpp | 2 ++ src/webui/www/private/scripts/dynamicTable.js | 4 ++++ 6 files changed, 24 insertions(+), 3 deletions(-) diff --git a/src/base/bittorrent/torrenthandle.cpp b/src/base/bittorrent/torrenthandle.cpp index bc7cf1318..b3cefc797 100644 --- a/src/base/bittorrent/torrenthandle.cpp +++ b/src/base/bittorrent/torrenthandle.cpp @@ -734,7 +734,8 @@ bool TorrentHandle::isActive() const || m_state == TorrentState::Downloading || m_state == TorrentState::ForcedDownloading || m_state == TorrentState::Uploading - || m_state == TorrentState::ForcedUploading; + || m_state == TorrentState::ForcedUploading + || m_state == TorrentState::Moving; } bool TorrentHandle::isInactive() const @@ -807,7 +808,10 @@ TorrentState TorrentHandle::state() const void TorrentHandle::updateState() { - if (isPaused()) { + if (isMoveInProgress()) { + m_state = TorrentState::Moving; + } + else if (isPaused()) { if (hasMissingFiles()) m_state = TorrentState::MissingFiles; else if (hasError()) @@ -1374,6 +1378,7 @@ void TorrentHandle::moveStorage(const QString &newPath, bool overwrite) , (overwrite ? libt::always_replace_files : libt::dont_replace)); m_moveStorageInfo.oldPath = oldPath; m_moveStorageInfo.newPath = newPath; + updateState(); } } @@ -1450,9 +1455,10 @@ void TorrentHandle::handleStorageMovedAlert(const libtorrent::storage_moved_aler qDebug() << "Removing torrent temp folder:" << m_moveStorageInfo.oldPath; Utils::Fs::smartRemoveEmptyFolderTree(m_moveStorageInfo.oldPath); } - updateStatus(); m_moveStorageInfo.newPath.clear(); + updateStatus(); + if (!m_moveStorageInfo.queuedPath.isEmpty()) { moveStorage(m_moveStorageInfo.queuedPath, m_moveStorageInfo.queuedOverwrite); m_moveStorageInfo.queuedPath.clear(); @@ -1478,6 +1484,8 @@ void TorrentHandle::handleStorageMovedFailedAlert(const libtorrent::storage_move .arg(name(), QString::fromStdString(p->message())), Log::CRITICAL); m_moveStorageInfo.newPath.clear(); + updateStatus(); + if (!m_moveStorageInfo.queuedPath.isEmpty()) { moveStorage(m_moveStorageInfo.queuedPath, m_moveStorageInfo.queuedOverwrite); m_moveStorageInfo.queuedPath.clear(); diff --git a/src/base/bittorrent/torrenthandle.h b/src/base/bittorrent/torrenthandle.h index 32a6842fc..3d0016e8c 100644 --- a/src/base/bittorrent/torrenthandle.h +++ b/src/base/bittorrent/torrenthandle.h @@ -149,6 +149,8 @@ namespace BitTorrent PausedDownloading, PausedUploading, + Moving, + MissingFiles, Error }; diff --git a/src/gui/torrentmodel.cpp b/src/gui/torrentmodel.cpp index 9bb9490f0..585bc250d 100644 --- a/src/gui/torrentmodel.cpp +++ b/src/gui/torrentmodel.cpp @@ -349,6 +349,7 @@ QIcon getIconByState(BitTorrent::TorrentState state) case BitTorrent::TorrentState::QueuedForChecking: #endif case BitTorrent::TorrentState::CheckingResumeData: + case BitTorrent::TorrentState::Moving: return getCheckingIcon(); case BitTorrent::TorrentState::Unknown: case BitTorrent::TorrentState::MissingFiles: @@ -404,6 +405,7 @@ QColor getColorByState(BitTorrent::TorrentState state) case BitTorrent::TorrentState::QueuedForChecking: #endif case BitTorrent::TorrentState::CheckingResumeData: + case BitTorrent::TorrentState::Moving: if (!dark) return QColor(0, 128, 128); // Teal else diff --git a/src/gui/transferlistdelegate.cpp b/src/gui/transferlistdelegate.cpp index e713e52a4..4263bf098 100644 --- a/src/gui/transferlistdelegate.cpp +++ b/src/gui/transferlistdelegate.cpp @@ -272,6 +272,9 @@ QString TransferListDelegate::getStatusString(const BitTorrent::TorrentState sta case BitTorrent::TorrentState::PausedUploading: str = tr("Completed"); break; + case BitTorrent::TorrentState::Moving: + str = tr("Moving", "Torrent local data are being moved/relocated"); + break; case BitTorrent::TorrentState::MissingFiles: str = tr("Missing Files"); break; diff --git a/src/webui/api/serialize/serialize_torrent.cpp b/src/webui/api/serialize/serialize_torrent.cpp index 124d9e1f4..c78f5b405 100644 --- a/src/webui/api/serialize/serialize_torrent.cpp +++ b/src/webui/api/serialize/serialize_torrent.cpp @@ -76,6 +76,8 @@ namespace #endif case BitTorrent::TorrentState::CheckingResumeData: return QLatin1String("checkingResumeData"); + case BitTorrent::TorrentState::Moving: + return QLatin1String("moving"); default: return QLatin1String("unknown"); } diff --git a/src/webui/www/private/scripts/dynamicTable.js b/src/webui/www/private/scripts/dynamicTable.js index 00b6d1c5d..2d6027b53 100644 --- a/src/webui/www/private/scripts/dynamicTable.js +++ b/src/webui/www/private/scripts/dynamicTable.js @@ -814,6 +814,7 @@ var TorrentsTable = new Class({ case "checkingUP": case "queuedForChecking": case "checkingResumeData": + case "moving": state = "checking"; break; case "unknown": @@ -887,6 +888,9 @@ var TorrentsTable = new Class({ case "pausedUP": status = "Completed"; break; + case "moving": + status = "Moving"; + break; case "missingFiles": status = "Missing Files"; break; From e5c73cee4a27eb3237977255e8a545274a22a456 Mon Sep 17 00:00:00 2001 From: sledgehammer999 Date: Mon, 9 Apr 2018 18:26:01 +0300 Subject: [PATCH 2/3] Log successful torrent move --- src/base/bittorrent/torrenthandle.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/base/bittorrent/torrenthandle.cpp b/src/base/bittorrent/torrenthandle.cpp index b3cefc797..bc75f0e9c 100644 --- a/src/base/bittorrent/torrenthandle.cpp +++ b/src/base/bittorrent/torrenthandle.cpp @@ -1445,8 +1445,8 @@ void TorrentHandle::handleStorageMovedAlert(const libtorrent::storage_moved_aler return; } - qDebug("Torrent is successfully moved from %s to %s" - , qUtf8Printable(m_moveStorageInfo.oldPath), qUtf8Printable(m_moveStorageInfo.newPath)); + LogMsg(tr("Successfully moved torrent: %1. New path: %2").arg(name(), m_moveStorageInfo.newPath)); + const QDir oldDir {m_moveStorageInfo.oldPath}; if ((oldDir == QDir(m_session->torrentTempPath(info()))) && (oldDir != QDir(m_session->tempPath()))) { From 375b15727d8b572b7a4c749a4ab9d1a0415740c0 Mon Sep 17 00:00:00 2001 From: sledgehammer999 Date: Mon, 9 Apr 2018 16:52:37 +0300 Subject: [PATCH 3/3] Show rechecking progress When having big torrents, the rechecking might take a while to complete. Users need some sort of feedback that progress is being made. Also, I changed the float to qreal since that's the return type. --- src/base/bittorrent/torrenthandle.cpp | 18 +++++++++++------- src/webui/api/synccontroller.cpp | 2 +- src/webui/api/torrentscontroller.cpp | 2 +- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/base/bittorrent/torrenthandle.cpp b/src/base/bittorrent/torrenthandle.cpp index bc75f0e9c..cbe77267a 100644 --- a/src/base/bittorrent/torrenthandle.cpp +++ b/src/base/bittorrent/torrenthandle.cpp @@ -519,15 +519,19 @@ int TorrentHandle::piecesHave() const qreal TorrentHandle::progress() const { - if (!m_nativeStatus.total_wanted) - return 0.; + if (!isChecking()) { + if (!m_nativeStatus.total_wanted) + return 0.; - if (m_nativeStatus.total_wanted_done == m_nativeStatus.total_wanted) - return 1.; + if (m_nativeStatus.total_wanted_done == m_nativeStatus.total_wanted) + return 1.; - float progress = static_cast(m_nativeStatus.total_wanted_done) / m_nativeStatus.total_wanted; - Q_ASSERT((progress >= 0.f) && (progress <= 1.f)); - return progress; + qreal progress = static_cast(m_nativeStatus.total_wanted_done) / m_nativeStatus.total_wanted; + Q_ASSERT((progress >= 0.f) && (progress <= 1.f)); + return progress; + } + + return m_nativeStatus.progress; } QString TorrentHandle::category() const diff --git a/src/webui/api/synccontroller.cpp b/src/webui/api/synccontroller.cpp index 1c2126fd2..a90e69a93 100644 --- a/src/webui/api/synccontroller.cpp +++ b/src/webui/api/synccontroller.cpp @@ -327,7 +327,7 @@ namespace // Each value of the 'torrents' dictionary contains map. The map can contain following keys: // - "name": Torrent name // - "size": Torrent size -// - "progress: Torrent progress +// - "progress": Torrent progress // - "dlspeed": Torrent download speed // - "upspeed": Torrent upload speed // - "priority": Torrent priority (-1 if queuing is disabled) diff --git a/src/webui/api/torrentscontroller.cpp b/src/webui/api/torrentscontroller.cpp index c8afa9252..8b6b46c4f 100644 --- a/src/webui/api/torrentscontroller.cpp +++ b/src/webui/api/torrentscontroller.cpp @@ -132,7 +132,7 @@ namespace // - "hash": Torrent hash // - "name": Torrent name // - "size": Torrent size -// - "progress: Torrent progress +// - "progress": Torrent progress // - "dlspeed": Torrent download speed // - "upspeed": Torrent upload speed // - "priority": Torrent priority (-1 if queuing is disabled)