Browse Source

Make setSequentialDownload/setFirstLastPiecePriority independent.

adaptive-webui-19844
Vladimir Golovnev (Glassez) 9 years ago
parent
commit
67e90d8d2a
  1. 36
      src/core/bittorrent/torrenthandle.cpp
  2. 2
      src/core/bittorrent/torrenthandle.h
  3. 7
      src/gui/properties/propertieswidget.cpp
  4. 2
      src/gui/transferlistwidget.cpp

36
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,22 @@ void TorrentHandle::forceRecheck() @@ -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<int> fp;
SAFE_GET(fp, file_priorities);
@ -1168,6 +1160,11 @@ void TorrentHandle::setFirstLastPiecePriority(bool b) @@ -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 @@ -1756,9 +1753,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 +1828,9 @@ void TorrentHandle::prioritizeFiles(const QVector<int> &priorities) @@ -1828,5 +1828,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);

7
src/gui/properties/propertieswidget.cpp

@ -450,7 +450,7 @@ void PropertiesWidget::loadDynamicData() { @@ -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() { @@ -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