fix: qt open magnet dialog munges magnet url (#3787)
This commit is contained in:
parent
050ee1cbbd
commit
c000311b80
11
qt/AddData.h
11
qt/AddData.h
|
@ -5,6 +5,8 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <optional>
|
||||||
|
|
||||||
#include <QByteArray>
|
#include <QByteArray>
|
||||||
#include <QString>
|
#include <QString>
|
||||||
#include <QUrl>
|
#include <QUrl>
|
||||||
|
@ -34,9 +36,14 @@ public:
|
||||||
QString readableName() const;
|
QString readableName() const;
|
||||||
QString readableShortName() const;
|
QString readableShortName() const;
|
||||||
|
|
||||||
static bool isSupported(QString const& str)
|
static std::optional<AddData> create(QString const& str)
|
||||||
{
|
{
|
||||||
return AddData(str).type != NONE;
|
if (auto ret = AddData{ str }; ret.type != NONE)
|
||||||
|
{
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
int type = NONE;
|
int type = NONE;
|
||||||
|
|
|
@ -1273,19 +1273,19 @@ void MainWindow::openTorrent()
|
||||||
|
|
||||||
void MainWindow::openURL()
|
void MainWindow::openURL()
|
||||||
{
|
{
|
||||||
QString str = QApplication::clipboard()->text(QClipboard::Selection);
|
auto add = AddData::create(QApplication::clipboard()->text(QClipboard::Selection));
|
||||||
|
|
||||||
if (!AddData::isSupported(str))
|
if (!add)
|
||||||
{
|
{
|
||||||
str = QApplication::clipboard()->text(QClipboard::Clipboard);
|
add = AddData::create(QApplication::clipboard()->text(QClipboard::Clipboard));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!AddData::isSupported(str))
|
if (!add)
|
||||||
{
|
{
|
||||||
str.clear();
|
add = AddData{};
|
||||||
}
|
}
|
||||||
|
|
||||||
addTorrent(AddData(str), true);
|
addTorrent(std::move(*add), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::addTorrents(QStringList const& filenames)
|
void MainWindow::addTorrents(QStringList const& filenames)
|
||||||
|
@ -1308,17 +1308,17 @@ void MainWindow::addTorrents(QStringList const& filenames)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::addTorrent(AddData const& addMe, bool show_options)
|
void MainWindow::addTorrent(AddData add_me, bool show_options)
|
||||||
{
|
{
|
||||||
if (show_options)
|
if (show_options)
|
||||||
{
|
{
|
||||||
auto* o = new OptionsDialog(session_, prefs_, addMe, this);
|
auto* o = new OptionsDialog(session_, prefs_, std::move(add_me), this);
|
||||||
o->show();
|
o->show();
|
||||||
QApplication::alert(o);
|
QApplication::alert(o);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
session_.addTorrent(addMe);
|
session_.addTorrent(std::move(add_me));
|
||||||
QApplication::alert(this);
|
QApplication::alert(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -133,7 +133,7 @@ private:
|
||||||
void initStatusBar();
|
void initStatusBar();
|
||||||
|
|
||||||
void clearSelection();
|
void clearSelection();
|
||||||
void addTorrent(AddData const& add_me, bool show_options);
|
void addTorrent(AddData add_me, bool show_options);
|
||||||
|
|
||||||
// QWidget
|
// QWidget
|
||||||
void hideEvent(QHideEvent* event) override;
|
void hideEvent(QHideEvent* event) override;
|
||||||
|
|
|
@ -39,18 +39,7 @@ OptionsDialog::OptionsDialog(Session& session, Prefs const& prefs, AddData addme
|
||||||
{
|
{
|
||||||
ui_.setupUi(this);
|
ui_.setupUi(this);
|
||||||
|
|
||||||
QString title;
|
setWindowTitle(add_.type == AddData::FILENAME ? tr("Open Torrent from File") : tr("Open Torrent from URL or Magnet Link"));
|
||||||
|
|
||||||
if (add_.type == AddData::FILENAME)
|
|
||||||
{
|
|
||||||
title = tr("Open Torrent from File");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
title = tr("Open Torrent from URL or Magnet Link");
|
|
||||||
}
|
|
||||||
|
|
||||||
setWindowTitle(title);
|
|
||||||
|
|
||||||
edit_timer_.setInterval(2000);
|
edit_timer_.setInterval(2000);
|
||||||
edit_timer_.setSingleShot(true);
|
edit_timer_.setSingleShot(true);
|
||||||
|
@ -319,9 +308,9 @@ void OptionsDialog::onSourceChanged()
|
||||||
{
|
{
|
||||||
add_.set(ui_.sourceButton->path());
|
add_.set(ui_.sourceButton->path());
|
||||||
}
|
}
|
||||||
else
|
else if (auto const text = ui_.sourceEdit->text(); text != add_.readableName())
|
||||||
{
|
{
|
||||||
add_.set(ui_.sourceEdit->text());
|
add_.set(text);
|
||||||
}
|
}
|
||||||
|
|
||||||
reload();
|
reload();
|
||||||
|
|
|
@ -986,7 +986,7 @@ void Session::setBlocklistSize(int64_t i)
|
||||||
emit blocklistUpdated(i);
|
emit blocklistUpdated(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Session::addTorrent(AddData const& add_me, tr_variant* args, bool trash_original)
|
void Session::addTorrent(AddData add_me, tr_variant* args, bool trash_original)
|
||||||
{
|
{
|
||||||
assert(tr_variantDictFind(args, TR_KEY_filename) == nullptr);
|
assert(tr_variantDictFind(args, TR_KEY_filename) == nullptr);
|
||||||
assert(tr_variantDictFind(args, TR_KEY_metainfo) == nullptr);
|
assert(tr_variantDictFind(args, TR_KEY_metainfo) == nullptr);
|
||||||
|
@ -1105,12 +1105,12 @@ void Session::onDuplicatesTimer()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Session::addTorrent(AddData const& add_me)
|
void Session::addTorrent(AddData add_me)
|
||||||
{
|
{
|
||||||
tr_variant args;
|
tr_variant args;
|
||||||
tr_variantInitDict(&args, 3);
|
tr_variantInitDict(&args, 3);
|
||||||
|
|
||||||
addTorrent(add_me, &args, prefs_.getBool(Prefs::TRASH_ORIGINAL));
|
addTorrent(std::move(add_me), &args, prefs_.getBool(Prefs::TRASH_ORIGINAL));
|
||||||
}
|
}
|
||||||
|
|
||||||
void Session::addNewlyCreatedTorrent(QString const& filename, QString const& local_path)
|
void Session::addNewlyCreatedTorrent(QString const& filename, QString const& local_path)
|
||||||
|
|
|
@ -93,7 +93,7 @@ public:
|
||||||
|
|
||||||
void torrentSetLocation(torrent_ids_t const& ids, QString const& path, bool do_move);
|
void torrentSetLocation(torrent_ids_t const& ids, QString const& path, bool do_move);
|
||||||
void torrentRenamePath(torrent_ids_t const& ids, QString const& oldpath, QString const& newname);
|
void torrentRenamePath(torrent_ids_t const& ids, QString const& oldpath, QString const& newname);
|
||||||
void addTorrent(AddData const& addme, tr_variant* top, bool trash_original);
|
void addTorrent(AddData addme, tr_variant* top, bool trash_original);
|
||||||
void initTorrents(torrent_ids_t const& ids = {});
|
void initTorrents(torrent_ids_t const& ids = {});
|
||||||
void pauseTorrents(torrent_ids_t const& torrentIds = {});
|
void pauseTorrents(torrent_ids_t const& torrentIds = {});
|
||||||
void startTorrents(torrent_ids_t const& torrentIds = {});
|
void startTorrents(torrent_ids_t const& torrentIds = {});
|
||||||
|
@ -117,7 +117,7 @@ public:
|
||||||
};
|
};
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void addTorrent(AddData const& addme);
|
void addTorrent(AddData addme);
|
||||||
void launchWebInterface() const;
|
void launchWebInterface() const;
|
||||||
void queueMoveBottom(torrent_ids_t const& torrentIds = {});
|
void queueMoveBottom(torrent_ids_t const& torrentIds = {});
|
||||||
void queueMoveDown(torrent_ids_t const& torrentIds = {});
|
void queueMoveDown(torrent_ids_t const& torrentIds = {});
|
||||||
|
|
Loading…
Reference in New Issue