fix: cannot add magnet links in GTK client (#8277)

This commit is contained in:
Charles Kerr
2026-01-29 16:13:09 -06:00
committed by GitHub
parent fa3d3c7727
commit d7cf7dffe4

View File

@@ -144,7 +144,7 @@ private:
void inc_busy();
void dec_busy();
bool add_file(Glib::RefPtr<Gio::File> const& file, bool do_start, bool do_prompt, bool do_notify);
bool add(Glib::ustring const& name, bool do_start, bool do_prompt, bool do_notify);
void add_file_async_callback(
Glib::RefPtr<Gio::File> const& file,
Glib::RefPtr<Gio::AsyncResult>& result,
@@ -823,7 +823,8 @@ void Session::Impl::add_file_async_callback(
dec_busy();
}
bool Session::Impl::add_file(Glib::RefPtr<Gio::File> const& file, bool do_start, bool do_prompt, bool do_notify)
// Add `name,` which might be a local filename, a magnet link, or a URI.
bool Session::Impl::add(Glib::ustring const& name, bool const do_start, bool const do_prompt, bool const do_notify)
{
auto* const session = get_session();
if (session == nullptr)
@@ -837,6 +838,7 @@ bool Session::Impl::add_file(Glib::RefPtr<Gio::File> const& file, bool do_start,
tr_ctorSetPaused(ctor, TR_FORCE, !do_start);
bool loaded = false;
auto file = Gio::File::create_for_parse_name(name);
if (auto const path = file->get_path(); !std::empty(path))
{
// try to treat it as a file...
@@ -846,7 +848,7 @@ bool Session::Impl::add_file(Glib::RefPtr<Gio::File> const& file, bool do_start,
if (!loaded)
{
// try to treat it as a magnet link...
loaded = tr_ctorSetMetainfoFromMagnetLink(ctor, file->get_uri().c_str(), nullptr);
loaded = tr_ctorSetMetainfoFromMagnetLink(ctor, name.raw().c_str(), nullptr);
}
// if we could make sense of it, add it
@@ -881,12 +883,11 @@ bool Session::add_from_url(Glib::ustring const& url)
bool Session::Impl::add_from_url(Glib::ustring const& url)
{
auto const file = Gio::File::create_for_uri(url);
auto const do_start = gtr_pref_flag_get(TR_KEY_start_added_torrents);
auto const do_prompt = gtr_pref_flag_get(TR_KEY_show_options_window);
auto const do_notify = false;
auto const handled = add_file(file, do_start, do_prompt, do_notify);
auto const handled = add(url, do_start, do_prompt, do_notify);
torrents_added();
return handled;
}
@@ -900,7 +901,7 @@ void Session::Impl::add_files(std::vector<Glib::RefPtr<Gio::File>> const& files,
{
for (auto const& file : files)
{
add_file(file, do_start, do_prompt, do_notify);
add(file->get_parse_name(), do_start, do_prompt, do_notify);
}
torrents_added();