From 19ef27d7f3d3b4df0e4c45a4e88d1a63186ffb76 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Sun, 26 Feb 2017 14:25:43 +0100 Subject: {api/base,gui/options}-dialog: prevent closing without signal Use hide() to avoid emitting idempotent events. There's isVisible() but no isClosed() or equivalent. Worse yet, close() can return true twice in a row, despite what docs for `bool QWidget::close()' say. --- api/plugin-api.cpp | 10 +++++++++- api/plugin-api.hpp | 2 ++ gui/options-dialog.cpp | 14 ++++++++++++-- 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/api/plugin-api.cpp b/api/plugin-api.cpp index 1bf56200..100902eb 100644 --- a/api/plugin-api.cpp +++ b/api/plugin-api.cpp @@ -11,7 +11,13 @@ ITracker::~ITracker() {} ITrackerDialog::~ITrackerDialog() {} plugin_api::detail::BaseDialog::BaseDialog() {} -void plugin_api::detail::BaseDialog::closeEvent(QCloseEvent*) { emit closing(); } + +void plugin_api::detail::BaseDialog::closeEvent(QCloseEvent*) +{ + if (isVisible()) + emit closing(); +} + Metadata::Metadata() {} IFilter::IFilter() {} IFilterDialog::IFilterDialog() {} @@ -19,3 +25,5 @@ IProtocol::IProtocol() {} IProtocolDialog::IProtocolDialog() {} ITracker::ITracker() {} ITrackerDialog::ITrackerDialog() {} + +void plugin_api::detail::BaseDialog::done(int) { close(); hide(); } diff --git a/api/plugin-api.hpp b/api/plugin-api.hpp index e9de9dad..4c9dee2f 100644 --- a/api/plugin-api.hpp +++ b/api/plugin-api.hpp @@ -48,6 +48,8 @@ public: void closeEvent(QCloseEvent *) override; signals: void closing(); +private slots: + void done(int) override; }; } // ns diff --git a/gui/options-dialog.cpp b/gui/options-dialog.cpp index 356d7cef..8e420a83 100644 --- a/gui/options-dialog.cpp +++ b/gui/options-dialog.cpp @@ -199,18 +199,28 @@ void OptionsDialog::bind_key(key_opts& kopts, QLabel* label) void OptionsDialog::doOK() { + if (!close()) // dialog was closed already + return; + if (isHidden()) // close() can return true twice in a row it seems + return; + hide(); + main.b->save(); ui.game_detector->save(); set_disable_translation_state(ui.disable_translation->isChecked()); - close(); emit closing(); } void OptionsDialog::doCancel() { + if (!close()) // dialog was closed already + return; + if (isHidden()) // close() can return true twice in a row it seems + return; + hide(); + main.b->reload(); ui.game_detector->revert(); - close(); emit closing(); } -- cgit v1.2.3