Browse Source

Merge pull request #14138 from glassez/add-torrent

Use single parameter to accept torrent source
adaptive-webui-19844
Vladimir Golovnev 4 years ago committed by GitHub
parent
commit
8771e1a339
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      macxconf.pri
  2. 10
      src/base/bittorrent/session.cpp
  3. 3
      src/base/bittorrent/session.h

2
macxconf.pri

@ -7,6 +7,8 @@ else { @@ -7,6 +7,8 @@ else {
include(conf.pri)
}
QMAKE_MACOSX_DEPLOYMENT_TARGET = 10.14
LIBS += -framework Carbon -framework IOKit -framework AppKit
QT_LANG_PATH = ../dist/qt-translations

10
src/base/bittorrent/session.cpp

@ -2038,14 +2038,14 @@ bool Session::addTorrent(const MagnetUri &magnetUri, const AddTorrentParams &par @@ -2038,14 +2038,14 @@ bool Session::addTorrent(const MagnetUri &magnetUri, const AddTorrentParams &par
{
if (!magnetUri.isValid()) return false;
return addTorrent_impl(params, magnetUri);
return addTorrent_impl(magnetUri, params);
}
bool Session::addTorrent(const TorrentInfo &torrentInfo, const AddTorrentParams &params)
{
if (!torrentInfo.isValid()) return false;
return addTorrent_impl(params, MagnetUri(), torrentInfo);
return addTorrent_impl(torrentInfo, params);
}
LoadTorrentParams Session::initLoadTorrentParams(const AddTorrentParams &addTorrentParams)
@ -2080,9 +2080,11 @@ LoadTorrentParams Session::initLoadTorrentParams(const AddTorrentParams &addTorr @@ -2080,9 +2080,11 @@ LoadTorrentParams Session::initLoadTorrentParams(const AddTorrentParams &addTorr
}
// Add a torrent to the BitTorrent session
bool Session::addTorrent_impl(const AddTorrentParams &addTorrentParams, const MagnetUri &magnetUri, TorrentInfo metadata)
bool Session::addTorrent_impl(const std::variant<MagnetUri, TorrentInfo> &source, const AddTorrentParams &addTorrentParams)
{
const bool hasMetadata = metadata.isValid();
const bool hasMetadata = std::holds_alternative<TorrentInfo>(source);
TorrentInfo metadata = (hasMetadata ? std::get<TorrentInfo>(source) : TorrentInfo {});
const MagnetUri &magnetUri = (hasMetadata ? MagnetUri {} : std::get<MagnetUri>(source));
const InfoHash hash = (hasMetadata ? metadata.hash() : magnetUri.hash());
// It looks illogical that we don't just use an existing handle,

3
src/base/bittorrent/session.h

@ -30,6 +30,7 @@ @@ -30,6 +30,7 @@
#pragma once
#include <memory>
#include <variant>
#include <vector>
#include <libtorrent/add_torrent_params.hpp>
@ -600,7 +601,7 @@ namespace BitTorrent @@ -600,7 +601,7 @@ namespace BitTorrent
bool loadTorrentResumeData(const QByteArray &data, const TorrentInfo &metadata, LoadTorrentParams &torrentParams);
bool loadTorrent(LoadTorrentParams params);
LoadTorrentParams initLoadTorrentParams(const AddTorrentParams &addTorrentParams);
bool addTorrent_impl(const AddTorrentParams &addTorrentParams, const MagnetUri &magnetUri, TorrentInfo torrentInfo = TorrentInfo());
bool addTorrent_impl(const std::variant<MagnetUri, TorrentInfo> &source, const AddTorrentParams &addTorrentParams);
void updateSeedingLimitTimer();
void exportTorrentFile(const TorrentHandle *torrent, TorrentExportFolder folder = TorrentExportFolder::Regular);

Loading…
Cancel
Save