Browse Source

Merge pull request #4114 from glassez/fix-4105

Fix default save path for magnet. Closes #4105.
adaptive-webui-19844
sledgehammer999 9 years ago
parent
commit
340288f308
  1. 51
      src/core/bittorrent/session.cpp
  2. 2
      src/core/bittorrent/session.h
  3. 24
      src/core/bittorrent/torrenthandle.cpp
  4. 3
      src/core/bittorrent/torrenthandle.h

51
src/core/bittorrent/session.cpp

@ -711,7 +711,7 @@ void Session::handleDownloadFailed(const QString &url, const QString &reason) @@ -711,7 +711,7 @@ void Session::handleDownloadFailed(const QString &url, const QString &reason)
void Session::handleRedirectedToMagnet(const QString &url, const QString &magnetUri)
{
addTorrent_impl(m_downloadedTorrents.take(url), MagnetUri(magnetUri));
addTorrent_impl(addDataFromParams(m_downloadedTorrents.take(url)), MagnetUri(magnetUri));
}
void Session::switchToAlternativeMode(bool alternative)
@ -723,7 +723,7 @@ void Session::switchToAlternativeMode(bool alternative) @@ -723,7 +723,7 @@ void Session::switchToAlternativeMode(bool alternative)
void Session::handleDownloadFinished(const QString &url, const QString &filePath)
{
emit downloadFromUrlFinished(url);
addTorrent_impl(m_downloadedTorrents.take(url), MagnetUri(), TorrentInfo::loadFromFile(filePath));
addTorrent_impl(addDataFromParams(m_downloadedTorrents.take(url)), MagnetUri(), TorrentInfo::loadFromFile(filePath));
Utils::Fs::forceRemove(filePath); // remove temporary file
}
@ -957,7 +957,7 @@ bool Session::addTorrent(QString source, const AddTorrentParams &params) @@ -957,7 +957,7 @@ bool Session::addTorrent(QString source, const AddTorrentParams &params)
// use common 2nd step of torrent addition
libt::add_torrent_alert *alert = new libt::add_torrent_alert(handle, libt::add_torrent_params(), libt::error_code());
m_addingTorrents.insert(hash, AddTorrentData(params));
m_addingTorrents.insert(hash, addDataFromParams(params));
handleAddTorrentAlert(alert);
delete alert;
return true;
@ -978,10 +978,10 @@ bool Session::addTorrent(QString source, const AddTorrentParams &params) @@ -978,10 +978,10 @@ bool Session::addTorrent(QString source, const AddTorrentParams &params)
m_downloadedTorrents[handler->url()] = params;
}
else if (source.startsWith("magnet:", Qt::CaseInsensitive)) {
return addTorrent_impl(params, MagnetUri(source));
return addTorrent_impl(addDataFromParams(params), MagnetUri(source));
}
else {
return addTorrent_impl(params, MagnetUri(), TorrentInfo::loadFromFile(source));
return addTorrent_impl(addDataFromParams(params), MagnetUri(), TorrentInfo::loadFromFile(source));
}
return false;
@ -991,7 +991,7 @@ bool Session::addTorrent(const TorrentInfo &torrentInfo, const AddTorrentParams @@ -991,7 +991,7 @@ bool Session::addTorrent(const TorrentInfo &torrentInfo, const AddTorrentParams
{
if (!torrentInfo.isValid()) return false;
return addTorrent_impl(params, MagnetUri(), torrentInfo);
return addTorrent_impl(addDataFromParams(params), MagnetUri(), torrentInfo);
}
// Add a torrent to the BitTorrent session
@ -1067,15 +1067,6 @@ bool Session::addTorrent_impl(AddTorrentData addData, const MagnetUri &magnetUri @@ -1067,15 +1067,6 @@ bool Session::addTorrent_impl(AddTorrentData addData, const MagnetUri &magnetUri
p.max_connections = pref->getMaxConnecsPerTorrent();
p.max_uploads = pref->getMaxUploadsPerTorrent();
if (addData.savePath.isEmpty()) {
addData.savePath = m_defaultSavePath;
if (m_appendLabelToSavePath && !addData.label.isEmpty())
addData.savePath += QString("%1/").arg(addData.label);
}
else if (!addData.savePath.endsWith("/")) {
addData.savePath += "/";
}
QString savePath;
// Set actual save path (e.g. temporary folder)
if (isTempPathEnabled() && !addData.disableTempPath && !addData.hasSeedStatus)
@ -2448,3 +2439,33 @@ void torrentQueuePositionBottom(const libt::torrent_handle &handle) @@ -2448,3 +2439,33 @@ void torrentQueuePositionBottom(const libt::torrent_handle &handle)
qDebug() << Q_FUNC_INFO << " fails: " << exc.what();
}
}
AddTorrentData Session::addDataFromParams(const AddTorrentParams &params)
{
AddTorrentData data;
data.resumed = false;
data.name = params.name;
data.label = params.label;
data.savePath = params.savePath;
data.disableTempPath = params.disableTempPath;
data.sequential = params.sequential;
data.hasSeedStatus = params.skipChecking; // do not react on 'torrent_finished_alert' when skipping
data.skipChecking = params.skipChecking;
data.addForced = params.addForced;
data.addPaused = params.addPaused;
data.filePriorities = params.filePriorities;
data.ratioLimit = params.ignoreShareRatio ? TorrentHandle::NO_RATIO_LIMIT : TorrentHandle::USE_GLOBAL_RATIO;
// normalize save path
if (data.savePath.isEmpty()) {
data.savePath = m_defaultSavePath;
if (m_appendLabelToSavePath && !data.label.isEmpty())
data.savePath += QString("%1/").arg(data.label);
}
else if (!data.savePath.endsWith("/")) {
data.savePath += "/";
}
return data;
}

2
src/core/bittorrent/session.h

@ -320,6 +320,8 @@ namespace BitTorrent @@ -320,6 +320,8 @@ namespace BitTorrent
void dispatchAlerts(std::auto_ptr<libtorrent::alert> alertPtr);
void getPendingAlerts(QVector<libtorrent::alert *> &out, ulong time = 0);
AddTorrentData addDataFromParams(const AddTorrentParams &params);
// BitTorrent
libtorrent::session *m_nativeSession;

24
src/core/bittorrent/torrenthandle.cpp

@ -124,26 +124,6 @@ TorrentState::operator int() const @@ -124,26 +124,6 @@ TorrentState::operator int() const
return m_value;
}
// AddTorrentData
AddTorrentData::AddTorrentData() {}
AddTorrentData::AddTorrentData(const AddTorrentParams &in)
: resumed(false)
, name(in.name)
, label(in.label)
, savePath(in.savePath)
, disableTempPath(in.disableTempPath)
, sequential(in.sequential)
, hasSeedStatus(in.skipChecking) // do not react on 'torrent_finished_alert' when skipping
, skipChecking(in.skipChecking)
, addForced(in.addForced)
, addPaused(in.addPaused)
, filePriorities(in.filePriorities)
, ratioLimit(in.ignoreShareRatio ? TorrentHandle::NO_RATIO_LIMIT : TorrentHandle::USE_GLOBAL_RATIO)
{
}
// TorrentHandle
#define SAFE_CALL(func, ...) \
@ -901,12 +881,12 @@ int TorrentHandle::leechsCount() const @@ -901,12 +881,12 @@ int TorrentHandle::leechsCount() const
int TorrentHandle::totalSeedsCount() const
{
return m_nativeStatus.list_seeds;
return m_nativeStatus.list_seeds;
}
int TorrentHandle::totalPeersCount() const
{
return m_nativeStatus.list_peers;
return m_nativeStatus.list_peers;
}
int TorrentHandle::totalLeechersCount() const

3
src/core/bittorrent/torrenthandle.h

@ -97,9 +97,6 @@ namespace BitTorrent @@ -97,9 +97,6 @@ namespace BitTorrent
QVector<int> filePriorities;
// for resumed torrents
qreal ratioLimit;
AddTorrentData();
AddTorrentData(const AddTorrentParams &in);
};
struct TrackerInfo

Loading…
Cancel
Save