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. 5
      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
if (!data.resumed) { if (!data.resumed) {
setSequentialDownload(data.sequential); setSequentialDownload(data.sequential);
if (hasMetadata()) { if (hasMetadata()) {
setFirstLastPiecePriority(data.sequential);
if (m_session->isAppendExtensionEnabled()) if (m_session->isAppendExtensionEnabled())
appendExtensionsToIncompleteFiles(); 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) void TorrentHandle::move(QString path)
{ {
path = Utils::Fs::toNativePath(path); path = Utils::Fs::toNativePath(path);
@ -1130,24 +1124,22 @@ void TorrentHandle::forceRecheck()
SAFE_CALL(force_recheck); SAFE_CALL(force_recheck);
} }
void TorrentHandle::toggleSequentialDownload() void TorrentHandle::setSequentialDownload(bool b)
{ {
if (hasMetadata()) { if (b != isSequentialDownload()) {
bool was_sequential = isSequentialDownload(); SAFE_CALL(set_sequential_download, b);
SAFE_CALL(set_sequential_download, !was_sequential);
if (!was_sequential)
setFirstLastPiecePriority(true);
} }
} }
void TorrentHandle::toggleFirstLastPiecePriority() void TorrentHandle::toggleSequentialDownload()
{ {
if (hasMetadata()) setSequentialDownload(!isSequentialDownload());
setFirstLastPiecePriority(!hasFirstLastPiecePriority());
} }
void TorrentHandle::setFirstLastPiecePriority(bool b) void TorrentHandle::setFirstLastPiecePriority(bool b)
{ {
if (!hasMetadata()) return;
std::vector<int> fp; std::vector<int> fp;
SAFE_GET(fp, file_priorities); SAFE_GET(fp, file_priorities);
@ -1168,6 +1160,11 @@ void TorrentHandle::setFirstLastPiecePriority(bool b)
} }
} }
void TorrentHandle::toggleFirstLastPiecePriority()
{
setFirstLastPiecePriority(!hasFirstLastPiecePriority());
}
void TorrentHandle::pause() void TorrentHandle::pause()
{ {
if (isPaused()) return; if (isPaused()) return;
@ -1756,9 +1753,12 @@ QString TorrentHandle::toMagnetUri() const
void TorrentHandle::prioritizeFiles(const QVector<int> &priorities) void TorrentHandle::prioritizeFiles(const QVector<int> &priorities)
{ {
qDebug() << Q_FUNC_INFO; if (!hasMetadata()) return;
if (priorities.size() != filesCount()) 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 // Reset 'm_hasSeedStatus' if needed in order to react again to
// 'torrent_finished_alert' and eg show tray notifications // 'torrent_finished_alert' and eg show tray notifications
QVector<qreal> progress = filesProgress(); QVector<qreal> progress = filesProgress();
@ -1828,5 +1828,9 @@ void TorrentHandle::prioritizeFiles(const QVector<int> &priorities)
} }
} }
// Restore first/last piece first option if necessary
if (firstLastPieceFirst)
setFirstLastPiecePriority(true);
updateStatus(); updateStatus();
} }

2
src/core/bittorrent/torrenthandle.h

@ -304,8 +304,8 @@ namespace BitTorrent
void setLabel(const QString &label); void setLabel(const QString &label);
void setSequentialDownload(bool b); void setSequentialDownload(bool b);
void toggleSequentialDownload(); void toggleSequentialDownload();
void toggleFirstLastPiecePriority();
void setFirstLastPiecePriority(bool b); void setFirstLastPiecePriority(bool b);
void toggleFirstLastPiecePriority();
void pause(); void pause();
void resume(bool forced = false); void resume(bool forced = false);
void move(QString path); void move(QString path);

5
src/gui/properties/propertieswidget.cpp

@ -840,14 +840,9 @@ void PropertiesWidget::editWebSeed() {
bool PropertiesWidget::applyPriorities() { bool PropertiesWidget::applyPriorities() {
qDebug("Saving files priorities"); qDebug("Saving files priorities");
const QVector<int> priorities = PropListModel->model()->getFilePriorities(); 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 // Prioritize the files
qDebug("prioritize files: %d", priorities[0]); qDebug("prioritize files: %d", priorities[0]);
m_torrent->prioritizeFiles(priorities); m_torrent->prioritizeFiles(priorities);
// Restore first/last piece first option if necessary
if (first_last_piece_first)
m_torrent->setFirstLastPiecePriority(true);
return true; return true;
} }

2
src/gui/transferlistwidget.cpp

@ -562,7 +562,7 @@ void TransferListWidget::toggleSelectedTorrentsSequentialDownload() const
void TransferListWidget::toggleSelectedFirstLastPiecePrio() const void TransferListWidget::toggleSelectedFirstLastPiecePrio() const
{ {
foreach (BitTorrent::TorrentHandle *const torrent, getSelectedTorrents()) foreach (BitTorrent::TorrentHandle *const torrent, getSelectedTorrents())
torrent->setFirstLastPiecePriority(!torrent->hasFirstLastPiecePriority()); torrent->toggleFirstLastPiecePriority();
} }
void TransferListWidget::askNewLabelForSelection() void TransferListWidget::askNewLabelForSelection()

Loading…
Cancel
Save