/* Copyright (c) 2015-2016, Stanislaw Halik * Permission to use, copy, modify, and/or distribute this * software for any purpose with or without fee is hereby granted, * provided that the above copyright notice and this permission * notice appear in all copies. */ #pragma once #include "export.hpp" #include "compat/util.hpp" #include "bundle.hpp" #include "slider.hpp" #include "base-value.hpp" #include "value-traits.hpp" #include #include #include #include #include #include #include #include #include #include namespace options { namespace detail { OTR_OPTIONS_EXPORT void acct_lookup(bool is_fresh); } // ns detail template class value final : public base_value { using traits = detail::value_traits; using element_type = typename traits::element_type; static bool is_equal(const QVariant& val1, const QVariant& val2) { return val1.value() == val2.value(); } OTR_NEVER_INLINE t get() const { if (!b->contains(self_name) || b->get(self_name).type() == QVariant::Invalid) return def; const element_type x(b->get(self_name)); return traits::from_value(traits::from_storage(x), def); } public: OTR_NEVER_INLINE t operator=(const t& datum) { if (datum != get()) store(traits::to_storage(datum)); return datum; } static constexpr const Qt::ConnectionType DIRECT_CONNTYPE = Qt::DirectConnection; static constexpr const Qt::ConnectionType SAFE_CONNTYPE = Qt::QueuedConnection; OTR_NEVER_INLINE value(bundle b, const QString& name, t def) : base_value(b, name, &is_equal, std::type_index(typeid(element_type))), def(def) { QObject::connect(b.get(), SIGNAL(reloading()), this, SLOT(reload()), DIRECT_CONNTYPE); } OTR_NEVER_INLINE value(bundle b, const char* name, t def) : value(b, QString(name), def) { } OTR_NEVER_INLINE t default_value() const { return def; } OTR_NEVER_INLINE void set_to_default() override { *this = def; } OTR_NEVER_INLINE operator t() const { return std::forward(get()); } OTR_NEVER_INLINE void reload() override { *this = static_cast(*this); } OTR_NEVER_INLINE void bundle_value_changed() const override { emit valueChanged(traits::to_storage(get())); } OTR_NEVER_INLINE t operator()() const { return get(); } template OTR_NEVER_INLINE u to() const { return static_cast(std::forward(get())); } private: const t def; }; } // ns options