Browse Source

Merge pull request #4175 from glassez/seq_dl

Prevent return cached "sequential download" state. Closes #4167.
adaptive-webui-19844
sledgehammer999 9 years ago
parent
commit
0a0c8f307b
  1. 37
      src/core/bittorrent/torrenthandle.cpp
  2. 2
      src/core/bittorrent/torrenthandle.h
  3. 5
      src/gui/properties/propertieswidget.cpp
  4. 2
      src/gui/transferlistwidget.cpp

37
src/core/bittorrent/torrenthandle.cpp

@ -189,7 +189,6 @@ TorrentHandle::TorrentHandle(Session *session, const libtorrent::torrent_handle @@ -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) @@ -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,23 @@ void TorrentHandle::forceRecheck() @@ -1130,24 +1124,23 @@ 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);
m_nativeStatus.sequential_download = b; // prevent return cached value
}
}
void TorrentHandle::toggleFirstLastPiecePriority()
void TorrentHandle::toggleSequentialDownload()
{
if (hasMetadata())
setFirstLastPiecePriority(!hasFirstLastPiecePriority());
setSequentialDownload(!isSequentialDownload());
}
void TorrentHandle::setFirstLastPiecePriority(bool b)
{
if (!hasMetadata()) return;
std::vector<int> fp;
SAFE_GET(fp, file_priorities);
@ -1168,6 +1161,11 @@ void TorrentHandle::setFirstLastPiecePriority(bool b) @@ -1168,6 +1161,11 @@ void TorrentHandle::setFirstLastPiecePriority(bool b)
}
}
void TorrentHandle::toggleFirstLastPiecePriority()
{
setFirstLastPiecePriority(!hasFirstLastPiecePriority());
}
void TorrentHandle::pause()
{
if (isPaused()) return;
@ -1756,9 +1754,12 @@ QString TorrentHandle::toMagnetUri() const @@ -1756,9 +1754,12 @@ QString TorrentHandle::toMagnetUri() const
void TorrentHandle::prioritizeFiles(const QVector<int> &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<qreal> progress = filesProgress();
@ -1828,5 +1829,9 @@ void TorrentHandle::prioritizeFiles(const QVector<int> &priorities) @@ -1828,5 +1829,9 @@ void TorrentHandle::prioritizeFiles(const QVector<int> &priorities)
}
}
// Restore first/last piece first option if necessary
if (firstLastPieceFirst)
setFirstLastPiecePriority(true);
updateStatus();
}

2
src/core/bittorrent/torrenthandle.h

@ -304,8 +304,8 @@ namespace BitTorrent @@ -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);

5
src/gui/properties/propertieswidget.cpp

@ -840,14 +840,9 @@ void PropertiesWidget::editWebSeed() { @@ -840,14 +840,9 @@ void PropertiesWidget::editWebSeed() {
bool PropertiesWidget::applyPriorities() {
qDebug("Saving files priorities");
const QVector<int> 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;
}

2
src/gui/transferlistwidget.cpp

@ -562,7 +562,7 @@ void TransferListWidget::toggleSelectedTorrentsSequentialDownload() const @@ -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()

Loading…
Cancel
Save