mirror of
https://github.com/qbittorrent/qBittorrent
synced 2025-08-20 05:13:30 -07:00
Don't use output parameters for error handling
This commit is contained in:
parent
4d480b8761
commit
41fc0fd084
12 changed files with 116 additions and 165 deletions
|
@ -252,13 +252,13 @@ bool AddNewTorrentDialog::loadTorrentFile(const QString &torrentPath)
|
|||
? QUrl::fromEncoded(torrentPath.toLocal8Bit()).toLocalFile()
|
||||
: torrentPath;
|
||||
|
||||
QString error;
|
||||
m_torrentInfo = BitTorrent::TorrentInfo::loadFromFile(decodedPath, &error);
|
||||
if (!m_torrentInfo.isValid())
|
||||
const nonstd::expected<BitTorrent::TorrentInfo, QString> result = BitTorrent::TorrentInfo::loadFromFile(decodedPath);
|
||||
m_torrentInfo = result.value_or(BitTorrent::TorrentInfo());
|
||||
if (!result)
|
||||
{
|
||||
RaisedMessageBox::critical(this, tr("Invalid torrent")
|
||||
, tr("Failed to load the torrent: %1.\nError: %2", "Don't remove the '\n' characters. They insert a newline.")
|
||||
.arg(Utils::Fs::toNativePath(decodedPath), error));
|
||||
.arg(Utils::Fs::toNativePath(decodedPath), result.error()));
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -746,36 +746,38 @@ void AddNewTorrentDialog::setupTreeview()
|
|||
updateDiskSpaceLabel();
|
||||
}
|
||||
|
||||
void AddNewTorrentDialog::handleDownloadFinished(const Net::DownloadResult &result)
|
||||
void AddNewTorrentDialog::handleDownloadFinished(const Net::DownloadResult &downloadResult)
|
||||
{
|
||||
QString error;
|
||||
switch (result.status)
|
||||
switch (downloadResult.status)
|
||||
{
|
||||
case Net::DownloadStatus::Success:
|
||||
m_torrentInfo = BitTorrent::TorrentInfo::load(result.data, &error);
|
||||
if (!m_torrentInfo.isValid())
|
||||
{
|
||||
RaisedMessageBox::critical(this, tr("Invalid torrent"), tr("Failed to load from URL: %1.\nError: %2")
|
||||
.arg(result.url, error));
|
||||
return;
|
||||
const nonstd::expected<BitTorrent::TorrentInfo, QString> result = BitTorrent::TorrentInfo::load(downloadResult.data);
|
||||
m_torrentInfo = result.value_or(BitTorrent::TorrentInfo());
|
||||
if (!result)
|
||||
{
|
||||
RaisedMessageBox::critical(this, tr("Invalid torrent"), tr("Failed to load from URL: %1.\nError: %2")
|
||||
.arg(downloadResult.url, result.error()));
|
||||
return;
|
||||
}
|
||||
|
||||
m_torrentGuard = std::make_unique<TorrentFileGuard>();
|
||||
|
||||
if (loadTorrentImpl())
|
||||
open();
|
||||
else
|
||||
deleteLater();
|
||||
}
|
||||
|
||||
m_torrentGuard = std::make_unique<TorrentFileGuard>();
|
||||
|
||||
if (loadTorrentImpl())
|
||||
open();
|
||||
else
|
||||
deleteLater();
|
||||
break;
|
||||
case Net::DownloadStatus::RedirectedToMagnet:
|
||||
if (loadMagnet(BitTorrent::MagnetUri(result.magnet)))
|
||||
if (loadMagnet(BitTorrent::MagnetUri(downloadResult.magnet)))
|
||||
open();
|
||||
else
|
||||
deleteLater();
|
||||
break;
|
||||
default:
|
||||
RaisedMessageBox::critical(this, tr("Download Error"),
|
||||
tr("Cannot download '%1': %2").arg(result.url, result.errorString));
|
||||
tr("Cannot download '%1': %2").arg(downloadResult.url, downloadResult.errorString));
|
||||
deleteLater();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue