Browse Source

Store and use full magnet URI instead of hash

adaptive-webui-19844
Vladimir Golovnev (Glassez) 4 years ago
parent
commit
5727fcb001
No known key found for this signature in database
GPG Key ID: 52A2C7DEE2DFA6F7
  1. 25
      src/gui/addnewtorrentdialog.cpp
  2. 6
      src/gui/addnewtorrentdialog.h

25
src/gui/addnewtorrentdialog.cpp

@ -39,6 +39,7 @@ @@ -39,6 +39,7 @@
#include <QVector>
#include "base/bittorrent/downloadpriority.h"
#include "base/bittorrent/infohash.h"
#include "base/bittorrent/magneturi.h"
#include "base/bittorrent/session.h"
#include "base/bittorrent/torrenthandle.h"
@ -276,11 +277,11 @@ bool AddNewTorrentDialog::loadTorrentFile(const QString &torrentPath) @@ -276,11 +277,11 @@ bool AddNewTorrentDialog::loadTorrentFile(const QString &torrentPath)
bool AddNewTorrentDialog::loadTorrentImpl()
{
m_hasMetadata = true;
m_hash = m_torrentInfo.hash();
const BitTorrent::InfoHash infoHash = m_torrentInfo.hash();
// Prevent showing the dialog if download is already present
if (BitTorrent::Session::instance()->isKnownTorrent(m_hash)) {
BitTorrent::TorrentHandle *const torrent = BitTorrent::Session::instance()->findTorrent(m_hash);
if (BitTorrent::Session::instance()->isKnownTorrent(infoHash)) {
BitTorrent::TorrentHandle *const torrent = BitTorrent::Session::instance()->findTorrent(infoHash);
if (torrent) {
if (torrent->isPrivate() || m_torrentInfo.isPrivate()) {
RaisedMessageBox::warning(this, tr("Torrent is already present"), tr("Torrent '%1' is already in the transfer list. Trackers haven't been merged because it is a private torrent.").arg(torrent->name()), QMessageBox::Ok);
@ -297,7 +298,7 @@ bool AddNewTorrentDialog::loadTorrentImpl() @@ -297,7 +298,7 @@ bool AddNewTorrentDialog::loadTorrentImpl()
return false;
}
m_ui->labelHashData->setText(m_hash);
m_ui->labelHashData->setText(infoHash);
setupTreeview();
TMMChanged(m_ui->comboTTM->currentIndex());
m_ui->keepTopLevelFolderCheckBox->setEnabled(m_torrentInfo.hasRootFolder());
@ -312,10 +313,11 @@ bool AddNewTorrentDialog::loadMagnet(const BitTorrent::MagnetUri &magnetUri) @@ -312,10 +313,11 @@ bool AddNewTorrentDialog::loadMagnet(const BitTorrent::MagnetUri &magnetUri)
}
m_torrentGuard = std::make_unique<TorrentFileGuard>();
m_hash = magnetUri.hash();
const BitTorrent::InfoHash infoHash = magnetUri.hash();
// Prevent showing the dialog if download is already present
if (BitTorrent::Session::instance()->isKnownTorrent(m_hash)) {
BitTorrent::TorrentHandle *const torrent = BitTorrent::Session::instance()->findTorrent(m_hash);
if (BitTorrent::Session::instance()->isKnownTorrent(infoHash)) {
BitTorrent::TorrentHandle *const torrent = BitTorrent::Session::instance()->findTorrent(infoHash);
if (torrent) {
if (torrent->isPrivate()) {
RaisedMessageBox::warning(this, tr("Torrent is already present"), tr("Torrent '%1' is already in the transfer list. Trackers haven't been merged because it is a private torrent.").arg(torrent->name()), QMessageBox::Ok);
@ -335,7 +337,7 @@ bool AddNewTorrentDialog::loadMagnet(const BitTorrent::MagnetUri &magnetUri) @@ -335,7 +337,7 @@ bool AddNewTorrentDialog::loadMagnet(const BitTorrent::MagnetUri &magnetUri)
connect(BitTorrent::Session::instance(), &BitTorrent::Session::metadataLoaded, this, &AddNewTorrentDialog::updateMetadata);
// Set dialog title
QString torrentName = magnetUri.name();
const QString torrentName = magnetUri.name();
setWindowTitle(torrentName.isEmpty() ? tr("Magnet link") : torrentName);
setupTreeview();
@ -343,8 +345,9 @@ bool AddNewTorrentDialog::loadMagnet(const BitTorrent::MagnetUri &magnetUri) @@ -343,8 +345,9 @@ bool AddNewTorrentDialog::loadMagnet(const BitTorrent::MagnetUri &magnetUri)
BitTorrent::Session::instance()->loadMetadata(magnetUri);
setMetadataProgressIndicator(true, tr("Retrieving metadata..."));
m_ui->labelHashData->setText(m_hash);
m_ui->labelHashData->setText(infoHash);
m_magnetURI = magnetUri;
return true;
}
@ -573,7 +576,7 @@ void AddNewTorrentDialog::accept() @@ -573,7 +576,7 @@ void AddNewTorrentDialog::accept()
// Add torrent
if (!m_hasMetadata)
BitTorrent::Session::instance()->addTorrent(m_hash, m_torrentParams);
BitTorrent::Session::instance()->addTorrent(m_magnetURI, m_torrentParams);
else
BitTorrent::Session::instance()->addTorrent(m_torrentInfo, m_torrentParams);
@ -585,7 +588,7 @@ void AddNewTorrentDialog::reject() @@ -585,7 +588,7 @@ void AddNewTorrentDialog::reject()
{
if (!m_hasMetadata) {
setMetadataProgressIndicator(false);
BitTorrent::Session::instance()->cancelLoadMetadata(m_hash);
BitTorrent::Session::instance()->cancelLoadMetadata(m_magnetURI.hash());
}
QDialog::reject();

6
src/gui/addnewtorrentdialog.h

@ -34,13 +34,13 @@ @@ -34,13 +34,13 @@
#include <QDialog>
#include "base/bittorrent/addtorrentparams.h"
#include "base/bittorrent/infohash.h"
#include "base/bittorrent/magneturi.h"
#include "base/bittorrent/torrentinfo.h"
#include "base/settingvalue.h"
namespace BitTorrent
{
class MagnetUri;
class InfoHash;
}
namespace Net
@ -112,7 +112,7 @@ private: @@ -112,7 +112,7 @@ private:
TorrentContentFilterModel *m_contentModel;
PropListDelegate *m_contentDelegate;
bool m_hasMetadata;
BitTorrent::InfoHash m_hash;
BitTorrent::MagnetUri m_magnetURI;
BitTorrent::TorrentInfo m_torrentInfo;
QByteArray m_headerState;
int m_oldIndex;

Loading…
Cancel
Save