Improve strip torrent root folder

Fix issue when you rename the "root item" in the "Add New Torrent" dialog
and uncheck "Create subfolder", it will create the subfolder with the
renamed name.
Fix PropertiesWidget first folder is expanded after app restart.
Strip root folder if torrent was added via magnet link.
Fix crash when you get name of torrent without metadata.
This commit is contained in:
Vladimir Golovnev (Glassez)
2016-01-04 16:00:50 +03:00
parent 4b2d8a7941
commit d413bc65ef
6 changed files with 48 additions and 35 deletions

View File

@@ -89,6 +89,7 @@ AddTorrentData::AddTorrentData(const AddTorrentParams &params)
, sequential(params.sequential)
, hasSeedStatus(params.skipChecking) // do not react on 'torrent_finished_alert' when skipping
, skipChecking(params.skipChecking)
, hasRootFolder(params.createSubfolder)
, addForced(params.addForced)
, addPaused(params.addPaused)
, filePriorities(params.filePriorities)
@@ -152,7 +153,6 @@ TorrentState::operator int() const
return m_value;
}
, createSubfolder(in.createSubfolder)
// TorrentHandle
const qreal TorrentHandle::USE_GLOBAL_RATIO = -2.;
@@ -200,6 +200,7 @@ TorrentHandle::TorrentHandle(Session *session, const libtorrent::torrent_handle
, m_ratioLimit(data.ratioLimit)
, m_tempPathDisabled(data.disableTempPath)
, m_hasMissingFiles(false)
, m_hasRootFolder(data.hasRootFolder)
, m_pauseAfterRecheck(false)
, m_needSaveResumeData(false)
{
@@ -209,8 +210,13 @@ TorrentHandle::TorrentHandle(Session *session, const libtorrent::torrent_handle
updateStatus();
m_hash = InfoHash(m_nativeStatus.info_hash);
if (!data.resumed)
if (!data.resumed) {
setSequentialDownload(data.sequential);
if (hasMetadata()) {
if (filesCount() == 1)
m_hasRootFolder = false;
}
}
}
TorrentHandle::~TorrentHandle() {}
@@ -231,8 +237,8 @@ QString TorrentHandle::name() const
if (name.isEmpty())
name = QString::fromStdString(m_nativeStatus.name);
if (name.isEmpty())
name = QString::fromStdString(m_torrentInfo.origFiles().name());
if (name.isEmpty() && hasMetadata())
name = QString::fromStdString(m_torrentInfo.nativeInfo()->orig_files().name());
if (name.isEmpty())
name = m_hash;
@@ -338,6 +344,11 @@ void TorrentHandle::setAutoTMMEnabled(bool enabled)
move_impl(m_session->categorySavePath(m_category));
}
bool TorrentHandle::hasRootFolder() const
{
return m_hasRootFolder;
}
QString TorrentHandle::nativeActualSavePath() const
{
return QString::fromStdString(m_nativeStatus.save_path);
@@ -1493,6 +1504,7 @@ void TorrentHandle::handleSaveResumeDataAlert(libtorrent::save_resume_data_alert
resumeData["qBt-seedStatus"] = m_hasSeedStatus;
resumeData["qBt-tempPathDisabled"] = m_tempPathDisabled;
resumeData["qBt-queuePosition"] = queuePosition();
resumeData["qBt-hasRootFolder"] = m_hasRootFolder;
m_session->handleTorrentResumeDataReady(this, resumeData);
}
@@ -1594,6 +1606,10 @@ void TorrentHandle::handleMetadataReceivedAlert(libt::metadata_received_alert *p
updateStatus();
if (m_session->isAppendExtensionEnabled())
manageIncompleteFiles();
if (!m_hasRootFolder)
m_torrentInfo.stripRootFolder();
if (filesCount() == 1)
m_hasRootFolder = false;
m_session->handleTorrentMetadataReceived(this);
if (isPaused()) {