diff options
Diffstat (limited to 'options/bundle.cpp')
-rw-r--r-- | options/bundle.cpp | 104 |
1 files changed, 63 insertions, 41 deletions
diff --git a/options/bundle.cpp b/options/bundle.cpp index 8db4f906..a17b04fb 100644 --- a/options/bundle.cpp +++ b/options/bundle.cpp @@ -13,22 +13,14 @@ #include <cstdlib> #include <QThread> -#include <QApplication> +#include <QCoreApplication> using namespace options; using namespace options::globals; namespace options::detail { -mutex::mutex(QMutex::RecursionMode mode) : QMutex(mode) {} - -mutex::operator QMutex*() const -{ - return const_cast<QMutex*>(static_cast<const QMutex*>(this)); -} - bundle::bundle(const QString& group_name) : - mtx(QMutex::Recursive), group_name(group_name), saved(group_name), transient(saved) @@ -37,58 +29,68 @@ 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}; + + saved = group(group_name); + transient = saved; +} + +void bundle::notify() { - if (!group_name.isEmpty()) { QMutexLocker l(&mtx); + connector::notify_all_values(); + } - // XXX what do we do when values are and aren't equal? - // see QPointF -sh 20180830 - - // XXX we could probably skip assigning to `saved' -sh 20180830 - saved = group(group_name); - transient = saved; + emit reloading(); + emit changed(); +} +void bundle::reload() +{ + { + QMutexLocker l{&mtx}; + reload_no_notify(); connector::notify_all_values(); - emit reloading(); - emit changed(); } + emit reloading(); + emit changed(); } void bundle::set_all_to_default() { - QMutexLocker l(&mtx); - - forall([](value_* val) { - set_value_to_default(val); - }); + connector::set_all_to_default_(); } void bundle::store_kv(const QString& name, const QVariant& new_value) { - QMutexLocker l(&mtx); + if (group_name.isEmpty()) + return; - if (!group_name.isEmpty()) { - transient.put(name, new_value); - mark_ini_modified(); - + QMutexLocker l{&mtx}; + transient.put(name, new_value); connector::notify_values(name); - emit changed(); } + + emit changed(); } QVariant bundle::get_variant(const QString& name) const { - QMutexLocker l(mtx); + QMutexLocker l{&mtx}; return transient.get_variant(name); } bool bundle::contains(const QString &name) const { - QMutexLocker l(mtx); + QMutexLocker l{&mtx}; return transient.contains(name); } @@ -101,8 +103,7 @@ void bundle::save() return; { - QMutexLocker l(&mtx); - + QMutexLocker l{&mtx}; saved = transient; saved.save(); } @@ -110,7 +111,7 @@ void bundle::save() emit saving(); } -void bundler::after_profile_changed_() +void bundler::reload_no_notify_() { QMutexLocker l(&implsgl_mtx); @@ -121,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; @@ -139,7 +162,6 @@ std::shared_ptr<bundler::v> bundler::make_bundle_(const k& key) QMutexLocker l(&implsgl_mtx); using iter = decltype(implsgl_data.cbegin()); - const iter it = implsgl_data.find(key); if (it != implsgl_data.end()) @@ -168,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; @@ -181,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()); } |