Browse Source

Merge pull request #3649 from glassez/savepathlabel

Fix 'Append label to save path'. Closes #3495.
adaptive-webui-19844
sledgehammer999 9 years ago
parent
commit
4291a08d47
  1. 1
      src/core/bittorrent/private/torrenthandleprivate.h
  2. 40
      src/core/bittorrent/session.cpp
  3. 42
      src/core/bittorrent/torrenthandle.cpp
  4. 3
      src/core/bittorrent/torrenthandle.h

1
src/core/bittorrent/private/torrenthandleprivate.h

@ -39,7 +39,6 @@ struct TorrentHandlePrivate @@ -39,7 +39,6 @@ struct TorrentHandlePrivate
{
virtual void handleAlert(libtorrent::alert *) = 0;
virtual void handleStateUpdate(const libtorrent::torrent_status &) = 0;
virtual void handleDefaultSavePathChanged() = 0;
virtual void handleTempPathChanged() = 0;
virtual void handleAppendExtensionToggled() = 0;

40
src/core/bittorrent/session.cpp

@ -1412,14 +1412,9 @@ void Session::setDefaultSavePath(const QString &path) @@ -1412,14 +1412,9 @@ void Session::setDefaultSavePath(const QString &path)
{
if (path.isEmpty()) return;
QString defaultSavePath = Utils::Fs::fromNativePath(path);
if (!defaultSavePath.endsWith("/"))
defaultSavePath += "/";
if (m_defaultSavePath != defaultSavePath) {
m_defaultSavePath = defaultSavePath;
foreach (TorrentHandlePrivate *const torrent, m_torrents)
torrent->handleDefaultSavePathChanged();
}
m_defaultSavePath = Utils::Fs::fromNativePath(path);
if (!m_defaultSavePath.endsWith("/"))
m_defaultSavePath += "/";
}
void Session::setDefaultTempPath(const QString &path)
@ -1443,8 +1438,20 @@ void Session::setAppendLabelToSavePath(bool append) @@ -1443,8 +1438,20 @@ void Session::setAppendLabelToSavePath(bool append)
{
if (m_appendLabelToSavePath != append) {
m_appendLabelToSavePath = append;
foreach (TorrentHandlePrivate *const torrent, m_torrents)
torrent->handleDefaultSavePathChanged();
foreach (TorrentHandle *const torrent, m_torrents) {
QString label = torrent->label();
if (label.isEmpty()) continue;
QString testedOldSavePath = m_defaultSavePath;
QString newSavePath = m_defaultSavePath;
if (!m_appendLabelToSavePath)
testedOldSavePath += QString("%1/").arg(label);
else
newSavePath += QString("%1/").arg(label);
if (torrent->savePath() == testedOldSavePath)
torrent->move(newSavePath);
}
}
}
@ -1618,6 +1625,19 @@ void Session::handleTorrentSavePathChanged(TorrentHandle *const torrent) @@ -1618,6 +1625,19 @@ void Session::handleTorrentSavePathChanged(TorrentHandle *const torrent)
void Session::handleTorrentLabelChanged(TorrentHandle *const torrent, const QString &oldLabel)
{
if (m_appendLabelToSavePath) {
QString testedOldSavePath = m_defaultSavePath;
if (!oldLabel.isEmpty())
testedOldSavePath += QString("%1/").arg(oldLabel);
QString newLabel = torrent->label();
if (torrent->savePath() == testedOldSavePath) {
QString newSavePath = m_defaultSavePath;
if (!newLabel.isEmpty())
newSavePath += QString("%1/").arg(newLabel);
torrent->move(newSavePath);
}
}
emit torrentLabelChanged(torrent, oldLabel);
}

42
src/core/bittorrent/torrenthandle.cpp

@ -199,7 +199,6 @@ TorrentHandle::TorrentHandle(Session *session, const libtorrent::torrent_handle @@ -199,7 +199,6 @@ TorrentHandle::TorrentHandle(Session *session, const libtorrent::torrent_handle
, m_ratioLimit(data.ratioLimit)
, m_tempPathDisabled(data.disableTempPath)
, m_hasMissingFiles(false)
, m_useDefaultSavePath(false)
, m_pauseAfterRecheck(false)
, m_needSaveResumeData(false)
{
@ -1119,7 +1118,6 @@ void TorrentHandle::setLabel(const QString &label) @@ -1119,7 +1118,6 @@ void TorrentHandle::setLabel(const QString &label)
QString oldLabel = m_label;
m_label = label;
m_needSaveResumeData = true;
adjustSavePath();
m_session->handleTorrentLabelChanged(this, oldLabel);
}
}
@ -1131,10 +1129,6 @@ void TorrentHandle::setSequentialDownload(bool b) @@ -1131,10 +1129,6 @@ void TorrentHandle::setSequentialDownload(bool b)
void TorrentHandle::move(QString path)
{
// now we use non-default save path
// even if new path same as default.
m_useDefaultSavePath = false;
path = Utils::Fs::toNativePath(path);
if (path == savePath()) return;
@ -1463,7 +1457,7 @@ void TorrentHandle::handleSaveResumeDataAlert(libtorrent::save_resume_data_alert @@ -1463,7 +1457,7 @@ void TorrentHandle::handleSaveResumeDataAlert(libtorrent::save_resume_data_alert
resumeData["qBt-forced"] = isForced();
}
resumeData["qBt-addedTime"] = m_addedTime.toTime_t();
resumeData["qBt-savePath"] = m_useDefaultSavePath ? "" : Utils::String::toStdString(m_savePath);
resumeData["qBt-savePath"] = Utils::String::toStdString(m_savePath);
resumeData["qBt-ratioLimit"] = Utils::String::toStdString(QString::number(m_ratioLimit));
resumeData["qBt-label"] = Utils::String::toStdString(m_label);
resumeData["qBt-name"] = Utils::String::toStdString(m_name);
@ -1586,32 +1580,6 @@ void TorrentHandle::handleMetadataReceivedAlert(libt::metadata_received_alert *p @@ -1586,32 +1580,6 @@ void TorrentHandle::handleMetadataReceivedAlert(libt::metadata_received_alert *p
}
}
void TorrentHandle::handleDefaultSavePathChanged()
{
adjustSavePath();
}
void TorrentHandle::adjustSavePath()
{
// If we use default save path...
if (m_useDefaultSavePath) {
QString defaultSavePath = m_session->defaultSavePath();
if (m_session->useAppendLabelToSavePath() && !m_label.isEmpty())
defaultSavePath += QString("%1/").arg(m_label);
defaultSavePath = Utils::Fs::toNativePath(defaultSavePath);
if (m_savePath != defaultSavePath) {
if (!useTempPath()) {
moveStorage(defaultSavePath);
}
else {
m_savePath = defaultSavePath;
m_needSaveResumeData = true;
m_session->handleTorrentSavePathChanged(this);
}
}
}
}
void TorrentHandle::handleTempPathChanged()
{
adjustActualSavePath();
@ -1749,15 +1717,7 @@ void TorrentHandle::updateTorrentInfo() @@ -1749,15 +1717,7 @@ void TorrentHandle::updateTorrentInfo()
void TorrentHandle::initialize()
{
updateStatus();
m_hash = InfoHash(m_nativeStatus.info_hash);
if (m_savePath.isEmpty()) {
// we use default save path
m_savePath = nativeActualSavePath();
m_useDefaultSavePath = true;
}
adjustSavePath();
adjustActualSavePath();
}

3
src/core/bittorrent/torrenthandle.h

@ -310,7 +310,6 @@ namespace BitTorrent @@ -310,7 +310,6 @@ namespace BitTorrent
void handleAlert(libtorrent::alert *a);
void handleStateUpdate(const libtorrent::torrent_status &nativeStatus);
void handleDefaultSavePathChanged();
void handleTempPathChanged();
void handleAppendExtensionToggled();
@ -336,7 +335,6 @@ namespace BitTorrent @@ -336,7 +335,6 @@ namespace BitTorrent
bool useTempPath() const;
QString nativeActualSavePath() const;
void adjustSavePath();
void adjustActualSavePath();
void adjustActualSavePath_impl();
void moveStorage(const QString &newPath);
@ -375,7 +373,6 @@ namespace BitTorrent @@ -375,7 +373,6 @@ namespace BitTorrent
bool m_tempPathDisabled;
bool m_hasMissingFiles;
bool m_useDefaultSavePath;
bool m_pauseAfterRecheck;
bool m_needSaveResumeData;
QHash<QString, TrackerInfo> m_trackerInfos;

Loading…
Cancel
Save