diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2019-02-03 15:13:24 +0100 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2019-02-09 12:13:32 +0100 |
commit | 5d554656d7f2392a0c98a4474641f997c7b47543 (patch) | |
tree | 2dcec940f648d8c9cd20d89d6fd06f06a04840f4 | |
parent | 7dd05e0be7a1243d7f3026fadd3492eb054006fb (diff) |
options, opentrack: fix migrations with tie_setting
Migrations only ran after `tie_setting()' handlers were done, clobbering
the settings that were about to be migrated. Applying QSignalBlocker to
few comboboxes isn't enough as it affects everything touched by
`tie_setting()'.
Split reload and notify phases in the options system.
-rw-r--r-- | options/bundle.cpp | 59 | ||||
-rw-r--r-- | options/bundle.hpp | 20 | ||||
-rw-r--r-- | variant/default/main-window.cpp | 29 |
3 files changed, 77 insertions, 31 deletions
diff --git a/options/bundle.cpp b/options/bundle.cpp index dc0f0fcf..a17b04fb 100644 --- a/options/bundle.cpp +++ b/options/bundle.cpp @@ -29,17 +29,21 @@ bundle::bundle(const QString& group_name) : bundle::~bundle() = default; -void bundle::reload() +void bundle::reload_no_notify() { if (group_name.isEmpty()) return; - { - QMutexLocker l{&mtx}; + QMutexLocker l{&mtx}; - saved = group(group_name); - transient = saved; + saved = group(group_name); + transient = saved; +} +void bundle::notify() +{ + { + QMutexLocker l(&mtx); connector::notify_all_values(); } @@ -47,6 +51,17 @@ void bundle::reload() emit changed(); } +void bundle::reload() +{ + { + QMutexLocker l{&mtx}; + reload_no_notify(); + connector::notify_all_values(); + } + emit reloading(); + emit changed(); +} + void bundle::set_all_to_default() { connector::set_all_to_default_(); @@ -96,7 +111,7 @@ void bundle::save() emit saving(); } -void bundler::after_profile_changed_() +void bundler::reload_no_notify_() { QMutexLocker l(&implsgl_mtx); @@ -107,16 +122,38 @@ void bundler::after_profile_changed_() if (bundle_) { //qDebug() << "bundle: reverting" << kv.first << "due to profile change"; - bundle_->reload(); + bundle_->reload_no_notify(); } } } -void bundler::refresh_all_bundles() +void bundler::notify_() { - bundler_singleton().after_profile_changed_(); + QMutexLocker l(&implsgl_mtx); + + for (auto& kv : implsgl_data) + { + weak bundle = kv.second; + shared bundle_ = bundle.lock(); + if (bundle_) + { + //qDebug() << "bundle: reverting" << kv.first << "due to profile change"; + bundle_->notify(); + } + } +} + +void bundler::reload_() +{ + QMutexLocker l(&implsgl_mtx); + notify_(); + reload_no_notify_(); } +void bundler::notify() { singleton().notify_(); } +void bundler::reload_no_notify() { singleton().reload_no_notify_(); } +void bundler::reload() { singleton().reload_(); } + bundler::bundler() = default; bundler::~bundler() = default; @@ -153,7 +190,7 @@ std::shared_ptr<bundler::v> bundler::make_bundle_(const k& key) return shr; } -bundler& bundler::bundler_singleton() +bundler& bundler::singleton() { static bundler ret; return ret; @@ -166,7 +203,7 @@ namespace options { std::shared_ptr<bundle_> make_bundle(const QString& name) { if (!name.isEmpty()) - return detail::bundler::bundler_singleton().make_bundle_(name); + return detail::bundler::singleton().make_bundle_(name); else return std::make_shared<bundle_>(QString()); } diff --git a/options/bundle.hpp b/options/bundle.hpp index 4c2b9781..c1bb716d 100644 --- a/options/bundle.hpp +++ b/options/bundle.hpp @@ -30,6 +30,7 @@ namespace options::detail { class bundle; + struct bundler; } // ns options::detail namespace options { @@ -44,11 +45,15 @@ class OTR_OPTIONS_EXPORT bundle final : public QObject, public connector { Q_OBJECT + friend struct bundler; + mutable QMutex mtx { QMutex::Recursive }; const QString group_name; group saved; group transient; + void reload_no_notify(); + signals: void reloading(); void saving() const; @@ -68,6 +73,7 @@ public: bool contains(const QString& name) const; QVariant get_variant(const QString& name) const; + void notify(); public slots: void save(); @@ -82,19 +88,25 @@ struct OTR_OPTIONS_EXPORT bundler final using weak = std::weak_ptr<v>; using shared = std::shared_ptr<v>; - static void refresh_all_bundles(); + static void notify(); + static void reload_no_notify(); + + void reload(); private: QMutex implsgl_mtx { QMutex::Recursive }; std::unordered_map<k, weak> implsgl_data {}; - void after_profile_changed_(); + void notify_(); + void reload_no_notify_(); + + void reload_(); - friend OTR_OPTIONS_EXPORT + friend std::shared_ptr<v> options::make_bundle(const QString& name); std::shared_ptr<v> make_bundle_(const k& key); - static bundler& bundler_singleton(); + static bundler& singleton(); bundler(); ~bundler(); diff --git a/variant/default/main-window.cpp b/variant/default/main-window.cpp index 2e9461ed..53872644 100644 --- a/variant/default/main-window.cpp +++ b/variant/default/main-window.cpp @@ -650,42 +650,39 @@ void main_window::exit(int status) void main_window::set_profile(const QString& new_name_, bool migrate) { - QString new_name = new_name_; - QSignalBlocker b(ui.iconcomboProfile); + QString new_name = new_name_; + if (!profile_list.contains(new_name)) { new_name = OPENTRACK_DEFAULT_PROFILE; - refresh_profile_list(); if (!profile_list.contains(new_name)) migrate = false; } - if (new_name != ini_filename()) - { - ui.iconcomboProfile->setCurrentText(new_name); + const bool status = new_name != ini_filename(); + + if (status) set_profile_in_registry(new_name); - options::detail::bundler::refresh_all_bundles(); - } + using bundler = options::detail::bundler; - // this needs to run on app start -sh 20190203 - if (migrate) - { - // workaround migration breakage -sh 20180428 - QSignalBlocker b1(ui.iconcomboTrackerSource); - QSignalBlocker b2(ui.iconcomboProtocol); - QSignalBlocker b3(ui.iconcomboFilter); + bundler::reload_no_notify(); + if (migrate) // migrations are for config layout changes and other user-visible // incompatibilities in future versions run_migrations(); - } else mark_profile_as_not_needing_migration(); + bundler::notify(); + set_title(); + + if (status) + ui.iconcomboProfile->setCurrentText(new_name); } void main_window::ensure_tray() |