diff --git a/gtk/Application.cc b/gtk/Application.cc index 2ea2f855f..7540ae9b0 100644 --- a/gtk/Application.cc +++ b/gtk/Application.cc @@ -1516,7 +1516,7 @@ void Application::Impl::actions_handler(Glib::ustring const& action_name) else if (action_name == "open-torrent") { auto w = std::shared_ptr(TorrentFileChooserDialog::create(*wind_, core_)); - gtr_window_on_close(*w, [w]() mutable { w.reset(); }); + w->signal_response().connect([w](int /*response*/) mutable { w.reset(); }); w->show(); } else if (action_name == "show-stats") diff --git a/gtk/MessageLogWindow.cc b/gtk/MessageLogWindow.cc index 9536b8787..5d1f4b198 100644 --- a/gtk/MessageLogWindow.cc +++ b/gtk/MessageLogWindow.cc @@ -24,7 +24,7 @@ #include #include #include -#include +#include #include #include #include @@ -71,8 +71,8 @@ private: bool onRefresh(); void onSaveRequest(); - void onSaveDialogResponse(std::shared_ptr& d, int response); - void doSave(Gtk::Window& parent, Glib::ustring const& filename); + void onSaveDialogResponse(Glib::RefPtr& d, int response); + void doSave(std::string const& filename); void onClearRequest(); void onPauseToggled(Gio::SimpleAction& action); @@ -200,13 +200,13 @@ Glib::ustring gtr_asctime(time_t t) } // namespace -void MessageLogWindow::Impl::doSave(Gtk::Window& parent, Glib::ustring const& filename) +void MessageLogWindow::Impl::doSave(std::string const& filename) { try { auto stream = std::ofstream(); stream.exceptions(std::ios_base::failbit | std::ios_base::badbit); - stream.open(Glib::locale_from_utf8(filename), std::ios_base::trunc); + stream.open(filename, std::ios_base::trunc); for (auto const& row : store_->children()) { @@ -222,10 +222,10 @@ void MessageLogWindow::Impl::doSave(Gtk::Window& parent, Glib::ustring const& fi catch (std::ios_base::failure const& e) { auto w = std::make_shared( - parent, + window_, fmt::format( _("Couldn't save '{path}': {error} ({error_code})"), - fmt::arg("path", filename), + fmt::arg("path", Glib::filename_to_utf8(filename)), fmt::arg("error", e.code().message()), fmt::arg("error_code", e.code().value())), false, @@ -237,22 +237,21 @@ void MessageLogWindow::Impl::doSave(Gtk::Window& parent, Glib::ustring const& fi } } -void MessageLogWindow::Impl::onSaveDialogResponse(std::shared_ptr& d, int response) +void MessageLogWindow::Impl::onSaveDialogResponse(Glib::RefPtr& d, int response) { - if (response == TR_GTK_RESPONSE_TYPE(ACCEPT)) - { - doSave(*d, d->get_file()->get_path()); - } + auto const filename = response == TR_GTK_RESPONSE_TYPE(ACCEPT) ? d->get_file()->get_path() : std::string(); d.reset(); + + if (!filename.empty()) + { + doSave(filename); + } } void MessageLogWindow::Impl::onSaveRequest() { - auto d = std::make_shared(window_, _("Save Log"), TR_GTK_FILE_CHOOSER_ACTION(SAVE)); - d->add_button(_("_Cancel"), TR_GTK_RESPONSE_TYPE(CANCEL)); - d->add_button(_("_Save"), TR_GTK_RESPONSE_TYPE(ACCEPT)); - + auto d = Gtk::FileChooserNative::create(_("Save Log"), window_, TR_GTK_FILE_CHOOSER_ACTION(SAVE), _("_Save"), _("_Cancel")); d->signal_response().connect([this, d](int response) mutable { onSaveDialogResponse(d, response); }); d->show(); } diff --git a/gtk/OptionsDialog.cc b/gtk/OptionsDialog.cc index 6f55bf979..31460ceaf 100644 --- a/gtk/OptionsDialog.cc +++ b/gtk/OptionsDialog.cc @@ -353,8 +353,6 @@ void TorrentFileChooserDialog::onOpenDialogResponse(int response, Glib::RefPtradd_files(files, do_start, do_prompt, do_notify); } - - close(); } std::unique_ptr TorrentFileChooserDialog::create( @@ -365,13 +363,10 @@ std::unique_ptr TorrentFileChooserDialog::create( } TorrentFileChooserDialog::TorrentFileChooserDialog(Gtk::Window& parent, Glib::RefPtr const& core) - : Gtk::FileChooserDialog(parent, _("Open a Torrent"), TR_GTK_FILE_CHOOSER_ACTION(OPEN)) + : Gtk::FileChooserNative(_("Open a Torrent"), parent, TR_GTK_FILE_CHOOSER_ACTION(OPEN), _("_Open"), _("_Cancel")) { set_modal(true); - add_button(_("_Cancel"), TR_GTK_RESPONSE_TYPE(CANCEL)); - add_button(_("_Open"), TR_GTK_RESPONSE_TYPE(ACCEPT)); - set_select_multiple(true); addTorrentFilters(this); signal_response().connect([this, core](int response) { onOpenDialogResponse(response, core); }); diff --git a/gtk/OptionsDialog.h b/gtk/OptionsDialog.h index d91bd3a7f..5682167f5 100644 --- a/gtk/OptionsDialog.h +++ b/gtk/OptionsDialog.h @@ -11,7 +11,7 @@ #include #include #include -#include +#include #include #include @@ -38,7 +38,7 @@ private: void onOpenURLResponse(int response, Gtk::Entry const& entry, Glib::RefPtr const& core); }; -class TorrentFileChooserDialog : public Gtk::FileChooserDialog +class TorrentFileChooserDialog : public Gtk::FileChooserNative { public: ~TorrentFileChooserDialog() override = default; diff --git a/gtk/PathButton.cc b/gtk/PathButton.cc index 1ab245329..ce75ab4c0 100644 --- a/gtk/PathButton.cc +++ b/gtk/PathButton.cc @@ -5,6 +5,7 @@ #include "PathButton.h" +#include "GtkCompat.h" #include "Utils.h" #include @@ -13,7 +14,8 @@ #if GTKMM_CHECK_VERSION(4, 0, 0) #include #include -#include +#include +#include #include #include #include @@ -144,10 +146,12 @@ void PathButton::Impl::show_dialog() { auto const title = title_.get_value(); - auto dialog = std::make_shared(!title.empty() ? title : _("Select a File"), action_.get_value()); + auto dialog = Gtk::FileChooserNative::create( + !title.empty() ? title : _("Select a File"), + action_.get_value(), + _("_Open"), + _("_Cancel")); dialog->set_transient_for(gtr_widget_get_window(widget_)); - dialog->add_button(_("_Cancel"), Gtk::ResponseType::CANCEL); - dialog->add_button(_("_Open"), Gtk::ResponseType::ACCEPT); dialog->set_modal(true); if (!current_file_.empty()) @@ -169,7 +173,7 @@ void PathButton::Impl::show_dialog() dialog->signal_response().connect( [this, dialog](int response) mutable { - if (response == Gtk::ResponseType::ACCEPT) + if (response == TR_GTK_RESPONSE_TYPE(ACCEPT)) { set_filename(dialog->get_file()->get_path()); selection_changed_.emit();