@ -39,6 +39,7 @@
# include <QVector>
# include <QVector>
# include "base/bittorrent/downloadpriority.h"
# include "base/bittorrent/downloadpriority.h"
# include "base/bittorrent/infohash.h"
# include "base/bittorrent/magneturi.h"
# include "base/bittorrent/magneturi.h"
# include "base/bittorrent/session.h"
# include "base/bittorrent/session.h"
# include "base/bittorrent/torrenthandle.h"
# include "base/bittorrent/torrenthandle.h"
@ -276,11 +277,11 @@ bool AddNewTorrentDialog::loadTorrentFile(const QString &torrentPath)
bool AddNewTorrentDialog : : loadTorrentImpl ( )
bool AddNewTorrentDialog : : loadTorrentImpl ( )
{
{
m_hasMetadata = true ;
m_hasMetadata = true ;
m_h ash = m_torrentInfo . hash ( ) ;
const BitTorrent : : InfoHash infoH ash = m_torrentInfo . hash ( ) ;
// Prevent showing the dialog if download is already present
// Prevent showing the dialog if download is already present
if ( BitTorrent : : Session : : instance ( ) - > isKnownTorrent ( m_h ash) ) {
if ( BitTorrent : : Session : : instance ( ) - > isKnownTorrent ( infoH ash) ) {
BitTorrent : : TorrentHandle * const torrent = BitTorrent : : Session : : instance ( ) - > findTorrent ( m_h ash) ;
BitTorrent : : TorrentHandle * const torrent = BitTorrent : : Session : : instance ( ) - > findTorrent ( infoH ash) ;
if ( torrent ) {
if ( torrent ) {
if ( torrent - > isPrivate ( ) | | m_torrentInfo . isPrivate ( ) ) {
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 ) ;
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()
return false ;
return false ;
}
}
m_ui - > labelHashData - > setText ( m_h ash) ;
m_ui - > labelHashData - > setText ( infoH ash) ;
setupTreeview ( ) ;
setupTreeview ( ) ;
TMMChanged ( m_ui - > comboTTM - > currentIndex ( ) ) ;
TMMChanged ( m_ui - > comboTTM - > currentIndex ( ) ) ;
m_ui - > keepTopLevelFolderCheckBox - > setEnabled ( m_torrentInfo . hasRootFolder ( ) ) ;
m_ui - > keepTopLevelFolderCheckBox - > setEnabled ( m_torrentInfo . hasRootFolder ( ) ) ;
@ -312,10 +313,11 @@ bool AddNewTorrentDialog::loadMagnet(const BitTorrent::MagnetUri &magnetUri)
}
}
m_torrentGuard = std : : make_unique < TorrentFileGuard > ( ) ;
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
// Prevent showing the dialog if download is already present
if ( BitTorrent : : Session : : instance ( ) - > isKnownTorrent ( m_h ash) ) {
if ( BitTorrent : : Session : : instance ( ) - > isKnownTorrent ( infoH ash) ) {
BitTorrent : : TorrentHandle * const torrent = BitTorrent : : Session : : instance ( ) - > findTorrent ( m_h ash) ;
BitTorrent : : TorrentHandle * const torrent = BitTorrent : : Session : : instance ( ) - > findTorrent ( infoH ash) ;
if ( torrent ) {
if ( torrent ) {
if ( torrent - > isPrivate ( ) ) {
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 ) ;
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)
connect ( BitTorrent : : Session : : instance ( ) , & BitTorrent : : Session : : metadataLoaded , this , & AddNewTorrentDialog : : updateMetadata ) ;
connect ( BitTorrent : : Session : : instance ( ) , & BitTorrent : : Session : : metadataLoaded , this , & AddNewTorrentDialog : : updateMetadata ) ;
// Set dialog title
// Set dialog title
QString torrentName = magnetUri . name ( ) ;
const QString torrentName = magnetUri . name ( ) ;
setWindowTitle ( torrentName . isEmpty ( ) ? tr ( " Magnet link " ) : torrentName ) ;
setWindowTitle ( torrentName . isEmpty ( ) ? tr ( " Magnet link " ) : torrentName ) ;
setupTreeview ( ) ;
setupTreeview ( ) ;
@ -343,8 +345,9 @@ bool AddNewTorrentDialog::loadMagnet(const BitTorrent::MagnetUri &magnetUri)
BitTorrent : : Session : : instance ( ) - > loadMetadata ( magnetUri ) ;
BitTorrent : : Session : : instance ( ) - > loadMetadata ( magnetUri ) ;
setMetadataProgressIndicator ( true , tr ( " Retrieving metadata... " ) ) ;
setMetadataProgressIndicator ( true , tr ( " Retrieving metadata... " ) ) ;
m_ui - > labelHashData - > setText ( m_h ash) ;
m_ui - > labelHashData - > setText ( infoH ash) ;
m_magnetURI = magnetUri ;
return true ;
return true ;
}
}
@ -573,7 +576,7 @@ void AddNewTorrentDialog::accept()
// Add torrent
// Add torrent
if ( ! m_hasMetadata )
if ( ! m_hasMetadata )
BitTorrent : : Session : : instance ( ) - > addTorrent ( m_hash , m_torrentParams ) ;
BitTorrent : : Session : : instance ( ) - > addTorrent ( m_magnetURI , m_torrentParams ) ;
else
else
BitTorrent : : Session : : instance ( ) - > addTorrent ( m_torrentInfo , m_torrentParams ) ;
BitTorrent : : Session : : instance ( ) - > addTorrent ( m_torrentInfo , m_torrentParams ) ;
@ -585,7 +588,7 @@ void AddNewTorrentDialog::reject()
{
{
if ( ! m_hasMetadata ) {
if ( ! m_hasMetadata ) {
setMetadataProgressIndicator ( false ) ;
setMetadataProgressIndicator ( false ) ;
BitTorrent : : Session : : instance ( ) - > cancelLoadMetadata ( m_hash ) ;
BitTorrent : : Session : : instance ( ) - > cancelLoadMetadata ( m_magnetURI . hash ( ) ) ;
}
}
QDialog : : reject ( ) ;
QDialog : : reject ( ) ;