feat: better dialog when adding duplicate magnet (#2709)

Instead of giving the entire magnet link, which can be too long to be
readable, give the magnet's display name (if available) or the info hash
as a fallback.

Fixes #1217.
This commit is contained in:
Charles Kerr 2022-02-25 01:19:28 -06:00 committed by GitHub
parent 4450973d94
commit 8c598c463c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 18 additions and 1 deletions

View File

@ -29,6 +29,23 @@ QString getNameFromMetainfo(QByteArray const& benc)
return QString::fromStdString(metainfo.name());
}
QString getNameFromMagnet(QString const& magnet)
{
auto tmp = tr_magnet_metainfo{};
if (!tmp.parseMagnet(magnet.toStdString()))
{
return magnet;
}
if (!std::empty(tmp.name()))
{
return QString::fromStdString(tmp.name());
}
return QString::fromStdString(tmp.infoHashString());
}
} // namespace
int AddData::set(QString const& key)
@ -79,7 +96,7 @@ QString AddData::readableName() const
return filename;
case MAGNET:
return magnet;
return getNameFromMagnet(magnet);
case URL:
return url.toString();