From 67e90d8d2adbf253f12f6cf8409a652f051bfb48 Mon Sep 17 00:00:00 2001 From: "Vladimir Golovnev (Glassez)" Date: Thu, 26 Nov 2015 15:08:01 +0300 Subject: [PATCH] Make setSequentialDownload/setFirstLastPiecePriority independent. --- src/core/bittorrent/torrenthandle.cpp | 36 ++++++++++++++----------- src/core/bittorrent/torrenthandle.h | 2 +- src/gui/properties/propertieswidget.cpp | 7 +---- src/gui/transferlistwidget.cpp | 2 +- 4 files changed, 23 insertions(+), 24 deletions(-) diff --git a/src/core/bittorrent/torrenthandle.cpp b/src/core/bittorrent/torrenthandle.cpp index 6b79277ad..b6f80ab60 100644 --- a/src/core/bittorrent/torrenthandle.cpp +++ b/src/core/bittorrent/torrenthandle.cpp @@ -189,7 +189,6 @@ TorrentHandle::TorrentHandle(Session *session, const libtorrent::torrent_handle if (!data.resumed) { setSequentialDownload(data.sequential); if (hasMetadata()) { - setFirstLastPiecePriority(data.sequential); if (m_session->isAppendExtensionEnabled()) appendExtensionsToIncompleteFiles(); } @@ -1088,11 +1087,6 @@ void TorrentHandle::setLabel(const QString &label) } } -void TorrentHandle::setSequentialDownload(bool b) -{ - SAFE_CALL(set_sequential_download, b); -} - void TorrentHandle::move(QString path) { path = Utils::Fs::toNativePath(path); @@ -1130,24 +1124,22 @@ void TorrentHandle::forceRecheck() SAFE_CALL(force_recheck); } -void TorrentHandle::toggleSequentialDownload() +void TorrentHandle::setSequentialDownload(bool b) { - if (hasMetadata()) { - bool was_sequential = isSequentialDownload(); - SAFE_CALL(set_sequential_download, !was_sequential); - if (!was_sequential) - setFirstLastPiecePriority(true); + if (b != isSequentialDownload()) { + SAFE_CALL(set_sequential_download, b); } } -void TorrentHandle::toggleFirstLastPiecePriority() +void TorrentHandle::toggleSequentialDownload() { - if (hasMetadata()) - setFirstLastPiecePriority(!hasFirstLastPiecePriority()); + setSequentialDownload(!isSequentialDownload()); } void TorrentHandle::setFirstLastPiecePriority(bool b) { + if (!hasMetadata()) return; + std::vector fp; SAFE_GET(fp, file_priorities); @@ -1168,6 +1160,11 @@ void TorrentHandle::setFirstLastPiecePriority(bool b) } } +void TorrentHandle::toggleFirstLastPiecePriority() +{ + setFirstLastPiecePriority(!hasFirstLastPiecePriority()); +} + void TorrentHandle::pause() { if (isPaused()) return; @@ -1756,9 +1753,12 @@ QString TorrentHandle::toMagnetUri() const void TorrentHandle::prioritizeFiles(const QVector &priorities) { - qDebug() << Q_FUNC_INFO; + if (!hasMetadata()) return; if (priorities.size() != filesCount()) return; + // Save first/last piece first option state + bool firstLastPieceFirst = hasFirstLastPiecePriority(); + // Reset 'm_hasSeedStatus' if needed in order to react again to // 'torrent_finished_alert' and eg show tray notifications QVector progress = filesProgress(); @@ -1828,5 +1828,9 @@ void TorrentHandle::prioritizeFiles(const QVector &priorities) } } + // Restore first/last piece first option if necessary + if (firstLastPieceFirst) + setFirstLastPiecePriority(true); + updateStatus(); } diff --git a/src/core/bittorrent/torrenthandle.h b/src/core/bittorrent/torrenthandle.h index 631620634..e46951def 100644 --- a/src/core/bittorrent/torrenthandle.h +++ b/src/core/bittorrent/torrenthandle.h @@ -304,8 +304,8 @@ namespace BitTorrent void setLabel(const QString &label); void setSequentialDownload(bool b); void toggleSequentialDownload(); - void toggleFirstLastPiecePriority(); void setFirstLastPiecePriority(bool b); + void toggleFirstLastPiecePriority(); void pause(); void resume(bool forced = false); void move(QString path); diff --git a/src/gui/properties/propertieswidget.cpp b/src/gui/properties/propertieswidget.cpp index 49ff7e1d4..539c6a595 100644 --- a/src/gui/properties/propertieswidget.cpp +++ b/src/gui/properties/propertieswidget.cpp @@ -450,7 +450,7 @@ void PropertiesWidget::loadDynamicData() { downloaded_pieces->setProgress(m_torrent->pieces(), m_torrent->downloadingPieces()); } else { - showPiecesAvailability(false); + showPiecesAvailability(false); } break; @@ -840,14 +840,9 @@ void PropertiesWidget::editWebSeed() { bool PropertiesWidget::applyPriorities() { qDebug("Saving files priorities"); const QVector priorities = PropListModel->model()->getFilePriorities(); - // Save first/last piece first option state - bool first_last_piece_first = m_torrent->hasFirstLastPiecePriority(); // Prioritize the files qDebug("prioritize files: %d", priorities[0]); m_torrent->prioritizeFiles(priorities); - // Restore first/last piece first option if necessary - if (first_last_piece_first) - m_torrent->setFirstLastPiecePriority(true); return true; } diff --git a/src/gui/transferlistwidget.cpp b/src/gui/transferlistwidget.cpp index d8f2eb73d..cf8a9d68f 100644 --- a/src/gui/transferlistwidget.cpp +++ b/src/gui/transferlistwidget.cpp @@ -562,7 +562,7 @@ void TransferListWidget::toggleSelectedTorrentsSequentialDownload() const void TransferListWidget::toggleSelectedFirstLastPiecePrio() const { foreach (BitTorrent::TorrentHandle *const torrent, getSelectedTorrents()) - torrent->setFirstLastPiecePriority(!torrent->hasFirstLastPiecePriority()); + torrent->toggleFirstLastPiecePriority(); } void TransferListWidget::askNewLabelForSelection()