qBittorrent
BitTorrent::MagnetUri Class Reference

#include <magneturi.h>

Collaboration diagram for BitTorrent::MagnetUri:

Public Member Functions

 MagnetUri (const QString &source={})
 
bool isValid () const
 
InfoHash infoHash () const
 
QString name () const
 
QVector< TrackerEntrytrackers () const
 
QVector< QUrl > urlSeeds () const
 
QString url () const
 
lt::add_torrent_params addTorrentParams () const
 

Private Attributes

bool m_valid
 
QString m_url
 
InfoHash m_infoHash
 
QString m_name
 
QVector< TrackerEntrym_trackers
 
QVector< QUrl > m_urlSeeds
 
lt::add_torrent_params m_addTorrentParams
 

Detailed Description

Definition at line 42 of file magneturi.h.

Constructor & Destructor Documentation

◆ MagnetUri()

MagnetUri::MagnetUri ( const QString &  source = {})
explicit

Definition at line 76 of file magneturi.cpp.

77  : m_valid(false)
78  , m_url(source)
79 {
80  if (source.isEmpty()) return;
81 
82  if (isV2Hash(source))
83  m_url = QString::fromLatin1("magnet:?xt=urn:btmh:1220") + source; // 0x12 0x20 is the "multihash format" tag for the SHA-256 hashing scheme.
84  else if (isV1Hash(source))
85  m_url = QString::fromLatin1("magnet:?xt=urn:btih:") + source;
86 
87  lt::error_code ec;
88  lt::parse_magnet_uri(m_url.toStdString(), m_addTorrentParams, ec);
89  if (ec) return;
90 
91  m_valid = true;
92 
93 #ifdef QBT_USES_LIBTORRENT2
94  m_infoHash = m_addTorrentParams.info_hashes;
95 #else
96  m_infoHash = m_addTorrentParams.info_hash;
97 #endif
98 
99  m_name = QString::fromStdString(m_addTorrentParams.name);
100 
101  m_trackers.reserve(static_cast<decltype(m_trackers)::size_type>(m_addTorrentParams.trackers.size()));
102  for (const std::string &tracker : m_addTorrentParams.trackers)
103  m_trackers.append({QString::fromStdString(tracker)});
104 
105  m_urlSeeds.reserve(static_cast<decltype(m_urlSeeds)::size_type>(m_addTorrentParams.url_seeds.size()));
106  for (const std::string &urlSeed : m_addTorrentParams.url_seeds)
107  m_urlSeeds.append(QString::fromStdString(urlSeed));
108 }
QVector< QUrl > m_urlSeeds
Definition: magneturi.h:62
lt::add_torrent_params m_addTorrentParams
Definition: magneturi.h:63
QVector< TrackerEntry > m_trackers
Definition: magneturi.h:61
bool isV1Hash(const QString &string)
Definition: magneturi.cpp:44
bool isV2Hash(const QString &string)
Definition: magneturi.cpp:60

References anonymous_namespace{magneturi.cpp}::isV1Hash(), anonymous_namespace{magneturi.cpp}::isV2Hash(), m_addTorrentParams, m_infoHash, m_name, m_trackers, m_url, m_urlSeeds, m_valid, and anonymous_namespace{misc.cpp}::source.

Here is the call graph for this function:

Member Function Documentation

◆ addTorrentParams()

lt::add_torrent_params MagnetUri::addTorrentParams ( ) const

Definition at line 140 of file magneturi.cpp.

141 {
142  return m_addTorrentParams;
143 }

References m_addTorrentParams.

Referenced by BitTorrent::Session::addTorrent_impl(), and BitTorrent::Session::downloadMetadata().

Here is the caller graph for this function:

◆ infoHash()

InfoHash MagnetUri::infoHash ( ) const

Definition at line 115 of file magneturi.cpp.

116 {
117  return m_infoHash;
118 }

References m_infoHash.

Referenced by BitTorrent::Session::downloadMetadata(), AddNewTorrentDialog::loadMagnet(), AddNewTorrentDialog::reject(), and AddNewTorrentDialog::updateMetadata().

Here is the caller graph for this function:

◆ isValid()

bool MagnetUri::isValid ( ) const

Definition at line 110 of file magneturi.cpp.

111 {
112  return m_valid;
113 }

References m_valid.

Referenced by BitTorrent::Session::addTorrent(), BitTorrent::Session::downloadMetadata(), AddNewTorrentDialog::loadMagnet(), and AddNewTorrentDialog::show().

Here is the caller graph for this function:

◆ name()

QString MagnetUri::name ( ) const

Definition at line 120 of file magneturi.cpp.

121 {
122  return m_name;
123 }

References m_name.

Referenced by BitTorrent::Session::downloadMetadata(), and AddNewTorrentDialog::loadMagnet().

Here is the caller graph for this function:

◆ trackers()

QVector< TrackerEntry > MagnetUri::trackers ( ) const

Definition at line 125 of file magneturi.cpp.

126 {
127  return m_trackers;
128 }

References m_trackers.

Referenced by BitTorrent::Session::addTorrent_impl(), and AddNewTorrentDialog::loadMagnet().

Here is the caller graph for this function:

◆ url()

QString MagnetUri::url ( ) const

Definition at line 135 of file magneturi.cpp.

136 {
137  return m_url;
138 }

References m_url.

◆ urlSeeds()

QVector< QUrl > MagnetUri::urlSeeds ( ) const

Definition at line 130 of file magneturi.cpp.

131 {
132  return m_urlSeeds;
133 }

References m_urlSeeds.

Referenced by BitTorrent::Session::addTorrent_impl(), and AddNewTorrentDialog::loadMagnet().

Here is the caller graph for this function:

Member Data Documentation

◆ m_addTorrentParams

lt::add_torrent_params BitTorrent::MagnetUri::m_addTorrentParams
private

Definition at line 63 of file magneturi.h.

Referenced by addTorrentParams(), and MagnetUri().

◆ m_infoHash

InfoHash BitTorrent::MagnetUri::m_infoHash
private

Definition at line 59 of file magneturi.h.

Referenced by infoHash(), and MagnetUri().

◆ m_name

QString BitTorrent::MagnetUri::m_name
private

Definition at line 60 of file magneturi.h.

Referenced by MagnetUri(), and name().

◆ m_trackers

QVector<TrackerEntry> BitTorrent::MagnetUri::m_trackers
private

Definition at line 61 of file magneturi.h.

Referenced by MagnetUri(), and trackers().

◆ m_url

QString BitTorrent::MagnetUri::m_url
private

Definition at line 58 of file magneturi.h.

Referenced by MagnetUri(), and url().

◆ m_urlSeeds

QVector<QUrl> BitTorrent::MagnetUri::m_urlSeeds
private

Definition at line 62 of file magneturi.h.

Referenced by MagnetUri(), and urlSeeds().

◆ m_valid

bool BitTorrent::MagnetUri::m_valid
private

Definition at line 57 of file magneturi.h.

Referenced by isValid(), and MagnetUri().


The documentation for this class was generated from the following files: