Merge pull request #8716 from sledgehammer999/move_progress

Move and recheck progress
This commit is contained in:
sledgehammer999
2018-05-13 13:02:03 +03:00
committed by GitHub
8 changed files with 39 additions and 14 deletions

View File

@@ -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<float>(m_nativeStatus.total_wanted_done) / m_nativeStatus.total_wanted;
Q_ASSERT((progress >= 0.f) && (progress <= 1.f));
return progress;
qreal progress = static_cast<qreal>(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
@@ -734,7 +738,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 +812,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 +1382,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();
}
}
@@ -1440,8 +1449,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()))) {
@@ -1450,9 +1459,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 +1488,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();

View File

@@ -149,6 +149,8 @@ namespace BitTorrent
PausedDownloading,
PausedUploading,
Moving,
MissingFiles,
Error
};