1
0
Fork 0
mirror of https://github.com/transmission/transmission synced 2025-03-17 17:25:32 +00:00

Run GTK dialogs in non-blocking fashion (#3805)

GTK 4 drops blocking `run()` method for dialogs. Switch to non-blocking
`show()` to support both GTK 3 and 4.
This commit is contained in:
Mike Gelfand 2022-09-10 21:15:01 +03:00 committed by GitHub
parent 9f0fbb38ec
commit 3c8d8488ea
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 90 additions and 52 deletions

View file

@ -719,7 +719,7 @@ void Application::Impl::app_setup()
if (!gtr_pref_flag_get(TR_KEY_user_has_given_informed_consent)) if (!gtr_pref_flag_get(TR_KEY_user_has_given_informed_consent))
{ {
Gtk::MessageDialog w( auto w = std::make_shared<Gtk::MessageDialog>(
*wind_, *wind_,
_("Transmission is a file sharing program. When you run a torrent, its data will be " _("Transmission is a file sharing program. When you run a torrent, its data will be "
"made available to others by means of upload. Any content you share is your sole responsibility."), "made available to others by means of upload. Any content you share is your sole responsibility."),
@ -727,19 +727,24 @@ void Application::Impl::app_setup()
TR_GTK_MESSAGE_TYPE(OTHER), TR_GTK_MESSAGE_TYPE(OTHER),
TR_GTK_BUTTONS_TYPE(NONE), TR_GTK_BUTTONS_TYPE(NONE),
true); true);
w.add_button(_("_Cancel"), TR_GTK_RESPONSE_TYPE(REJECT)); w->add_button(_("_Cancel"), TR_GTK_RESPONSE_TYPE(REJECT));
w.add_button(_("I _Agree"), TR_GTK_RESPONSE_TYPE(ACCEPT)); w->add_button(_("I _Agree"), TR_GTK_RESPONSE_TYPE(ACCEPT));
w.set_default_response(TR_GTK_RESPONSE_TYPE(ACCEPT)); w->set_default_response(TR_GTK_RESPONSE_TYPE(ACCEPT));
w->signal_response().connect(
if (w.run() == TR_GTK_RESPONSE_TYPE(ACCEPT)) [w](int response) mutable
{ {
// only show it once if (response == TR_GTK_RESPONSE_TYPE(ACCEPT))
gtr_pref_flag_set(TR_KEY_user_has_given_informed_consent, true); {
} // only show it once
else gtr_pref_flag_set(TR_KEY_user_has_given_informed_consent, true);
{ w.reset();
exit(0); }
} else
{
exit(0);
}
});
w->show();
} }
} }
@ -959,9 +964,16 @@ void Application::Impl::show_torrent_errors(Glib::ustring const& primary, std::v
s << leader << ' ' << f << '\n'; s << leader << ' ' << f << '\n';
} }
Gtk::MessageDialog w(*wind_, primary, false, TR_GTK_MESSAGE_TYPE(ERROR), TR_GTK_BUTTONS_TYPE(CLOSE)); auto w = std::make_shared<Gtk::MessageDialog>(
w.set_secondary_text(s.str()); *wind_,
w.run(); primary,
false,
TR_GTK_MESSAGE_TYPE(ERROR),
TR_GTK_BUTTONS_TYPE(CLOSE),
true);
w->set_secondary_text(s.str());
w->signal_response().connect([w](int /*response*/) mutable { w.reset(); });
w->show();
files.clear(); files.clear();
} }
@ -1296,25 +1308,31 @@ void Application::Impl::show_about_dialog()
"Mike Gelfand", "Mike Gelfand",
}); });
Gtk::AboutDialog d; auto d = std::make_shared<Gtk::AboutDialog>();
d.set_authors(authors); d->set_authors(authors);
d.set_comments(_("A fast and easy BitTorrent client")); d->set_comments(_("A fast and easy BitTorrent client"));
d.set_copyright(_("Copyright © The Transmission Project")); d->set_copyright(_("Copyright © The Transmission Project"));
d.set_logo_icon_name(AppIconName); d->set_logo_icon_name(AppIconName);
d.set_name(Glib::get_application_name()); d->set_name(Glib::get_application_name());
/* Translators: translate "translator-credits" as your name /* Translators: translate "translator-credits" as your name
to have it appear in the credits in the "About" to have it appear in the credits in the "About"
dialog */ dialog */
d.set_translator_credits(_("translator-credits")); d->set_translator_credits(_("translator-credits"));
d.set_version(LONG_VERSION_STRING); d->set_version(LONG_VERSION_STRING);
d.set_website(uri); d->set_website(uri);
d.set_website_label(uri); d->set_website_label(uri);
#ifdef SHOW_LICENSE #ifdef SHOW_LICENSE
d.set_license(LICENSE); d->set_license(LICENSE);
d.set_wrap_license(true); d->set_wrap_license(true);
#endif #endif
d.set_transient_for(*wind_); d->set_transient_for(*wind_);
d.run(); d->set_modal(true);
#if GTKMM_CHECK_VERSION(4, 0, 0)
d->signal_close_request().connect_notify([d]() mutable { d.reset(); });
#else
d->signal_delete_event().connect_notify([d](void* /*event*/) mutable { d.reset(); });
#endif
d->show();
} }
bool Application::Impl::call_rpc_for_selected_torrents(std::string const& method) bool Application::Impl::call_rpc_for_selected_torrents(std::string const& method)

View file

@ -2187,15 +2187,16 @@ void EditTrackersDialog::on_response(int response)
} }
else else
{ {
Gtk::MessageDialog w( auto w = std::make_shared<Gtk::MessageDialog>(
*this, *this,
_("List contains invalid URLs"), _("List contains invalid URLs"),
false, false,
TR_GTK_MESSAGE_TYPE(ERROR), TR_GTK_MESSAGE_TYPE(ERROR),
TR_GTK_BUTTONS_TYPE(CLOSE), TR_GTK_BUTTONS_TYPE(CLOSE),
true); true);
w.set_secondary_text(_("Please correct the errors and try again.")); w->set_secondary_text(_("Please correct the errors and try again."));
w.run(); w->signal_response().connect([w](int /*response*/) mutable { w.reset(); });
w->show();
do_destroy = false; do_destroy = false;
} }

View file

@ -771,7 +771,7 @@ bool FileList::Impl::on_rename_done_idle(Glib::ustring const& path_string, Glib:
} }
else else
{ {
Gtk::MessageDialog w( auto w = std::make_shared<Gtk::MessageDialog>(
*static_cast<Gtk::Window*>(widget_.get_toplevel()), *static_cast<Gtk::Window*>(widget_.get_toplevel()),
fmt::format( fmt::format(
_("Couldn't rename '{old_path}' as '{path}': {error} ({error_code})"), _("Couldn't rename '{old_path}' as '{path}': {error} ({error_code})"),
@ -783,8 +783,9 @@ bool FileList::Impl::on_rename_done_idle(Glib::ustring const& path_string, Glib:
TR_GTK_MESSAGE_TYPE(ERROR), TR_GTK_MESSAGE_TYPE(ERROR),
TR_GTK_BUTTONS_TYPE(CLOSE), TR_GTK_BUTTONS_TYPE(CLOSE),
true); true);
w.set_secondary_text(_("Please correct the errors and try again.")); w->set_secondary_text(_("Please correct the errors and try again."));
w.run(); w->signal_response().connect([w](int /*response*/) mutable { w.reset(); });
w->show();
} }
return false; return false;

View file

@ -87,15 +87,23 @@ bool RelocateDialog::Impl::onTimer()
{ {
if (done_ == TR_LOC_ERROR) if (done_ == TR_LOC_ERROR)
{ {
Gtk::MessageDialog( auto d = std::make_shared<Gtk::MessageDialog>(
*message_dialog_, *message_dialog_,
_("Couldn't move torrent"), _("Couldn't move torrent"),
false, false,
TR_GTK_MESSAGE_TYPE(ERROR), TR_GTK_MESSAGE_TYPE(ERROR),
TR_GTK_BUTTONS_TYPE(CLOSE), TR_GTK_BUTTONS_TYPE(CLOSE),
true) true);
.run();
message_dialog_.reset(); timer_.block();
d->signal_response().connect(
[this, d](int /*response*/) mutable
{
timer_.unblock();
d.reset();
});
d->show();
} }
else if (done_ == TR_LOC_DONE) else if (done_ == TR_LOC_DONE)
{ {

View file

@ -95,19 +95,29 @@ void StatsDialog::Impl::dialogResponse(int response)
{ {
if (response == TR_RESPONSE_RESET) if (response == TR_RESPONSE_RESET)
{ {
Gtk::MessageDialog auto w = std::make_shared<Gtk::MessageDialog>(
w(dialog_, _("Reset your statistics?"), false, TR_GTK_MESSAGE_TYPE(QUESTION), TR_GTK_BUTTONS_TYPE(NONE), true); dialog_,
w.add_button(_("_Cancel"), TR_GTK_RESPONSE_TYPE(CANCEL)); _("Reset your statistics?"),
w.add_button(_("_Reset"), TR_RESPONSE_RESET); false,
w.set_secondary_text( TR_GTK_MESSAGE_TYPE(QUESTION),
TR_GTK_BUTTONS_TYPE(NONE),
true);
w->add_button(_("_Cancel"), TR_GTK_RESPONSE_TYPE(CANCEL));
w->add_button(_("_Reset"), TR_RESPONSE_RESET);
w->set_secondary_text(
_("These statistics are for your information only. " _("These statistics are for your information only. "
"Resetting them doesn't affect the statistics logged by your BitTorrent trackers.")); "Resetting them doesn't affect the statistics logged by your BitTorrent trackers."));
w->signal_response().connect(
if (w.run() == TR_RESPONSE_RESET) [this, w](int inner_response) mutable
{ {
tr_sessionClearStats(core_->get_session()); if (inner_response == TR_RESPONSE_RESET)
updateStats(); {
} tr_sessionClearStats(core_->get_session());
updateStats();
}
w.reset();
});
w->show();
} }
if (response == TR_GTK_RESPONSE_TYPE(CLOSE)) if (response == TR_GTK_RESPONSE_TYPE(CLOSE))