diff --git a/dtkgui.cmake b/dtkgui.cmake index 81a88e57..6ee46db6 100644 --- a/dtkgui.cmake +++ b/dtkgui.cmake @@ -111,7 +111,7 @@ install(FILES DtkGuis DESTINATION "${INCLUDE_INSTALL_DIR}") # Find common dependencies find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Gui DBus Network) find_package(PkgConfig REQUIRED) -find_package(Dtk${DTK_NAME_SUFFIX} REQUIRED Core) +find_package(Dtk${DTK_NAME_SUFFIX} REQUIRED Core Tools) find_package(DtkBuildHelper REQUIRED) pkg_check_modules(librsvg REQUIRED IMPORTED_TARGET librsvg-2.0) diff --git a/src/kernel/kernel.cmake b/src/kernel/kernel.cmake index 5cb4cc32..bbccd2fd 100644 --- a/src/kernel/kernel.cmake +++ b/src/kernel/kernel.cmake @@ -7,5 +7,9 @@ file(GLOB KERNEL_SOURCE set(kernel_SRC ${KERNEL_HEADER} ${KERNEL_SOURCE} - ${CMAKE_CURRENT_LIST_DIR}/orgdeepindtkpreference.hpp +) + +dtk_add_config_to_cpp(kernel_SRC /usr/share/dsg/configs/org.deepin.dtk.preference.json + OUTPUT_FILE_NAME orgdeepindtkpreference.hpp + CLASS_NAME OrgDeepinDTKPreference ) diff --git a/src/kernel/orgdeepindtkpreference.hpp b/src/kernel/orgdeepindtkpreference.hpp deleted file mode 100644 index 6c465fcc..00000000 --- a/src/kernel/orgdeepindtkpreference.hpp +++ /dev/null @@ -1,751 +0,0 @@ -/** - * This file is generated by dconfig2cpp. - * Command line arguments: ./build5/tools/dconfig2cpp/dconfig2cpp -c OrgDeepinDTKPreference /usr/share/dsg/configs/org.deepin.dtk.preference.json - * Generation time: 2025-05-08T17:31:56 - * JSON file version: 1.0 - * - * WARNING: DO NOT MODIFY THIS FILE MANUALLY. - * If you need to change the content, please modify the dconfig2cpp tool. - */ - -#ifndef ORGDEEPINDTKPREFERENCE_H -#define ORGDEEPINDTKPREFERENCE_H - -#include -#include -#include -#include -#include -#include -#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) -#include -#endif -#include -#include - -class OrgDeepinDTKPreference : public QObject { - Q_OBJECT - - Q_PROPERTY(bool autoDisplayFeature READ autoDisplayFeature WRITE setAutoDisplayFeature NOTIFY autoDisplayFeatureChanged RESET resetAutoDisplayFeature) - Q_PROPERTY(bool enableDtkAnimations READ enableDtkAnimations WRITE setEnableDtkAnimations NOTIFY enableDtkAnimationsChanged RESET resetEnableDtkAnimations) - Q_PROPERTY(bool featureUpdated READ featureUpdated WRITE setFeatureUpdated NOTIFY featureUpdatedChanged RESET resetFeatureUpdated) - Q_PROPERTY(bool keyboardsearchDisabled READ keyboardsearchDisabled WRITE setKeyboardsearchDisabled NOTIFY keyboardsearchDisabledChanged RESET resetKeyboardsearchDisabled) - Q_PROPERTY(QString rules READ rules WRITE setRules NOTIFY rulesChanged RESET resetRules) - Q_PROPERTY(qlonglong scrollBarPolicy READ scrollBarPolicy WRITE setScrollBarPolicy NOTIFY scrollBarPolicyChanged RESET resetScrollBarPolicy) - Q_PROPERTY(qlonglong sizeMode READ sizeMode WRITE setSizeMode NOTIFY sizeModeChanged RESET resetSizeMode) - Q_PROPERTY(qlonglong themeType READ themeType WRITE setThemeType NOTIFY themeTypeChanged RESET resetThemeType) - Q_PROPERTY(qlonglong titlebarHeight READ titlebarHeight WRITE setTitlebarHeight NOTIFY titlebarHeightChanged RESET resetTitlebarHeight) - Q_PROPERTY(bool underlineShortcut READ underlineShortcut WRITE setUnderlineShortcut NOTIFY underlineShortcutChanged RESET resetUnderlineShortcut) - Q_CLASSINFO("DConfigKeyList", "autoDisplayFeature;enableDtkAnimations;featureUpdated;keyboardsearchDisabled;rules;scrollBarPolicy;sizeMode;themeType;titlebarHeight;underlineShortcut") - Q_CLASSINFO("DConfigFileName", "org.deepin.dtk.preference") - Q_CLASSINFO("DConfigFileVersion", "1.0") - -public: - explicit OrgDeepinDTKPreference(QThread *thread, DTK_CORE_NAMESPACE::DConfigBackend *backend, - const QString &name, const QString &appId, const QString &subpath, - bool isGeneric, QObject *parent) - : QObject(nullptr) { - if (!thread->isRunning()) { - qWarning() << QLatin1String("Warning: The provided thread is not running."); - } - Q_ASSERT(QThread::currentThread() != thread); - auto worker = new QObject(); - worker->moveToThread(thread); - QPointer watcher(parent); - QMetaObject::invokeMethod(worker, [=, this]() { - DTK_CORE_NAMESPACE::DConfig *config = nullptr; - if (isGeneric) { - if (backend) { - config = DTK_CORE_NAMESPACE::DConfig::createGeneric(backend, name, subpath, nullptr); - } else { - config = DTK_CORE_NAMESPACE::DConfig::createGeneric(name, subpath, nullptr); - } - } else { - if (backend) { - if (appId.isNull()) { - config = DTK_CORE_NAMESPACE::DConfig::create(backend, DTK_CORE_NAMESPACE::DSGApplication::id(), - name, subpath, nullptr); - } else { - config = DTK_CORE_NAMESPACE::DConfig::create(backend, appId, name, subpath, nullptr); - } - } else { - if (appId.isNull()) { - config = DTK_CORE_NAMESPACE::DConfig::create(DTK_CORE_NAMESPACE::DSGApplication::id(), - name, subpath, nullptr); - } else { - config = DTK_CORE_NAMESPACE::DConfig::create(appId, name, subpath, nullptr); - } - } - } - if (!config) { - qWarning() << QLatin1String("Failed to create DConfig instance."); - worker->deleteLater(); - return; - } - config->moveToThread(QThread::currentThread()); - initializeInConfigThread(config); - if (watcher != parent) { - // delete this if watcher is changed to nullptr. - deleteLater(); - } else if (!this->parent() && parent) { - // !parent() means that parent is not changed. - this->setParent(watcher); - } - worker->deleteLater(); - }); - } - static OrgDeepinDTKPreference* create(const QString &appId = {}, const QString &subpath = {}, QObject *parent = nullptr, QThread *thread = DTK_CORE_NAMESPACE::DConfig::globalThread()) - { return new OrgDeepinDTKPreference(thread, nullptr, QStringLiteral(u"\u006f\u0072\u0067\u002e\u0064\u0065\u0065\u0070\u0069\u006e\u002e\u0064\u0074\u006b\u002e\u0070\u0072\u0065\u0066\u0065\u0072\u0065\u006e\u0063\u0065"), appId, subpath, false, parent); } - static OrgDeepinDTKPreference* create(DTK_CORE_NAMESPACE::DConfigBackend *backend, const QString &appId = {}, const QString &subpath = {}, QObject *parent = nullptr, QThread *thread = DTK_CORE_NAMESPACE::DConfig::globalThread()) - { return new OrgDeepinDTKPreference(thread, backend, QStringLiteral(u"\u006f\u0072\u0067\u002e\u0064\u0065\u0065\u0070\u0069\u006e\u002e\u0064\u0074\u006b\u002e\u0070\u0072\u0065\u0066\u0065\u0072\u0065\u006e\u0063\u0065"), appId, subpath, false, parent); } - static OrgDeepinDTKPreference* createByName(const QString &name, const QString &appId = {}, const QString &subpath = {}, QObject *parent = nullptr, QThread *thread = DTK_CORE_NAMESPACE::DConfig::globalThread()) - { return new OrgDeepinDTKPreference(thread, nullptr, name, appId, subpath, false, parent); } - static OrgDeepinDTKPreference* createByName(DTK_CORE_NAMESPACE::DConfigBackend *backend, const QString &name, const QString &appId = {}, const QString &subpath = {}, QObject *parent = nullptr, QThread *thread = DTK_CORE_NAMESPACE::DConfig::globalThread()) - { return new OrgDeepinDTKPreference(thread, backend, name, appId, subpath, false, parent); } - static OrgDeepinDTKPreference* createGeneric(const QString &subpath = {}, QObject *parent = nullptr, QThread *thread = DTK_CORE_NAMESPACE::DConfig::globalThread()) - { return new OrgDeepinDTKPreference(thread, nullptr, QStringLiteral(u"\u006f\u0072\u0067\u002e\u0064\u0065\u0065\u0070\u0069\u006e\u002e\u0064\u0074\u006b\u002e\u0070\u0072\u0065\u0066\u0065\u0072\u0065\u006e\u0063\u0065"), {}, subpath, true, parent); } - static OrgDeepinDTKPreference* create(DTK_CORE_NAMESPACE::DConfigBackend *backend, const QString &subpath = {}, QObject *parent = nullptr, QThread *thread = DTK_CORE_NAMESPACE::DConfig::globalThread()) - { return new OrgDeepinDTKPreference(thread, backend, QStringLiteral(u"\u006f\u0072\u0067\u002e\u0064\u0065\u0065\u0070\u0069\u006e\u002e\u0064\u0074\u006b\u002e\u0070\u0072\u0065\u0066\u0065\u0072\u0065\u006e\u0063\u0065"), {}, subpath, true, parent); } - static OrgDeepinDTKPreference* createGenericByName(const QString &name, const QString &subpath = {}, QObject *parent = nullptr, QThread *thread = DTK_CORE_NAMESPACE::DConfig::globalThread()) - { return new OrgDeepinDTKPreference(thread, nullptr, name, {}, subpath, true, parent); } - static OrgDeepinDTKPreference* createGenericByName(DTK_CORE_NAMESPACE::DConfigBackend *backend, const QString &name, const QString &subpath = {}, QObject *parent = nullptr, QThread *thread = DTK_CORE_NAMESPACE::DConfig::globalThread()) - { return new OrgDeepinDTKPreference(thread, backend, name, {}, subpath, true, parent); } - ~OrgDeepinDTKPreference() { - if (m_config.loadRelaxed()) { - m_config.loadRelaxed()->deleteLater(); - } - } - - Q_INVOKABLE DTK_CORE_NAMESPACE::DConfig *config() const { - return m_config.loadRelaxed(); - } - - Q_INVOKABLE bool isInitializeSucceed() const { - return m_status.loadRelaxed() == static_cast(Status::Succeed); - } - - Q_INVOKABLE bool isInitializeFailed() const { - return m_status.loadRelaxed() == static_cast(Status::Failed); - } - - Q_INVOKABLE bool isInitializing() const { - return m_status.loadRelaxed() == static_cast(Status::Invalid); - } - - Q_INVOKABLE QStringList keyList() const { - return { QStringLiteral("autoDisplayFeature"), - QStringLiteral("enableDtkAnimations"), - QStringLiteral("featureUpdated"), - QStringLiteral("keyboardsearchDisabled"), - QStringLiteral("rules"), - QStringLiteral("scrollBarPolicy"), - QStringLiteral("sizeMode"), - QStringLiteral("themeType"), - QStringLiteral("titlebarHeight"), - QStringLiteral("underlineShortcut")}; - } - - Q_INVOKABLE bool isDefaultValue(const QString &key) const { - if (key == QStringLiteral("autoDisplayFeature")) - return autoDisplayFeatureIsDefaultValue(); - if (key == QStringLiteral("enableDtkAnimations")) - return enableDtkAnimationsIsDefaultValue(); - if (key == QStringLiteral("featureUpdated")) - return featureUpdatedIsDefaultValue(); - if (key == QStringLiteral("keyboardsearchDisabled")) - return keyboardsearchDisabledIsDefaultValue(); - if (key == QStringLiteral("rules")) - return rulesIsDefaultValue(); - if (key == QStringLiteral("scrollBarPolicy")) - return scrollBarPolicyIsDefaultValue(); - if (key == QStringLiteral("sizeMode")) - return sizeModeIsDefaultValue(); - if (key == QStringLiteral("themeType")) - return themeTypeIsDefaultValue(); - if (key == QStringLiteral("titlebarHeight")) - return titlebarHeightIsDefaultValue(); - if (key == QStringLiteral("underlineShortcut")) - return underlineShortcutIsDefaultValue(); - return false; - } - - bool autoDisplayFeature() const { - return p_autoDisplayFeature; - } - void setAutoDisplayFeature(const bool &value) { - auto oldValue = p_autoDisplayFeature; - p_autoDisplayFeature = value; - markPropertySet(0); - if (auto config = m_config.loadRelaxed()) { - QMetaObject::invokeMethod(config, [this, value]() { - m_config.loadRelaxed()->setValue(QStringLiteral("autoDisplayFeature"), value); - }); - } - if (p_autoDisplayFeature != oldValue) { - Q_EMIT autoDisplayFeatureChanged(); - Q_EMIT valueChanged(QStringLiteral("autoDisplayFeature"), value); - } - } - void resetAutoDisplayFeature() { - if (auto config = m_config.loadRelaxed()) { - QMetaObject::invokeMethod(config, [this]() { - m_config.loadRelaxed()->reset(QStringLiteral("autoDisplayFeature")); - }); - } - } -#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) - QBindable bindableAutoDisplayFeature() { - return QBindable(this, "autoDisplayFeature"); - } -#endif - Q_INVOKABLE bool autoDisplayFeatureIsDefaultValue() const { - return !testPropertySet(0); - } - bool enableDtkAnimations() const { - return p_enableDtkAnimations; - } - void setEnableDtkAnimations(const bool &value) { - auto oldValue = p_enableDtkAnimations; - p_enableDtkAnimations = value; - markPropertySet(1); - if (auto config = m_config.loadRelaxed()) { - QMetaObject::invokeMethod(config, [this, value]() { - m_config.loadRelaxed()->setValue(QStringLiteral("enableDtkAnimations"), value); - }); - } - if (p_enableDtkAnimations != oldValue) { - Q_EMIT enableDtkAnimationsChanged(); - Q_EMIT valueChanged(QStringLiteral("enableDtkAnimations"), value); - } - } - void resetEnableDtkAnimations() { - if (auto config = m_config.loadRelaxed()) { - QMetaObject::invokeMethod(config, [this]() { - m_config.loadRelaxed()->reset(QStringLiteral("enableDtkAnimations")); - }); - } - } -#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) - QBindable bindableEnableDtkAnimations() { - return QBindable(this, "enableDtkAnimations"); - } -#endif - Q_INVOKABLE bool enableDtkAnimationsIsDefaultValue() const { - return !testPropertySet(1); - } - bool featureUpdated() const { - return p_featureUpdated; - } - void setFeatureUpdated(const bool &value) { - auto oldValue = p_featureUpdated; - p_featureUpdated = value; - markPropertySet(2); - if (auto config = m_config.loadRelaxed()) { - QMetaObject::invokeMethod(config, [this, value]() { - m_config.loadRelaxed()->setValue(QStringLiteral("featureUpdated"), value); - }); - } - if (p_featureUpdated != oldValue) { - Q_EMIT featureUpdatedChanged(); - Q_EMIT valueChanged(QStringLiteral("featureUpdated"), value); - } - } - void resetFeatureUpdated() { - if (auto config = m_config.loadRelaxed()) { - QMetaObject::invokeMethod(config, [this]() { - m_config.loadRelaxed()->reset(QStringLiteral("featureUpdated")); - }); - } - } -#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) - QBindable bindableFeatureUpdated() { - return QBindable(this, "featureUpdated"); - } -#endif - Q_INVOKABLE bool featureUpdatedIsDefaultValue() const { - return !testPropertySet(2); - } - bool keyboardsearchDisabled() const { - return p_keyboardsearchDisabled; - } - void setKeyboardsearchDisabled(const bool &value) { - auto oldValue = p_keyboardsearchDisabled; - p_keyboardsearchDisabled = value; - markPropertySet(3); - if (auto config = m_config.loadRelaxed()) { - QMetaObject::invokeMethod(config, [this, value]() { - m_config.loadRelaxed()->setValue(QStringLiteral("keyboardsearchDisabled"), value); - }); - } - if (p_keyboardsearchDisabled != oldValue) { - Q_EMIT keyboardsearchDisabledChanged(); - Q_EMIT valueChanged(QStringLiteral("keyboardsearchDisabled"), value); - } - } - void resetKeyboardsearchDisabled() { - if (auto config = m_config.loadRelaxed()) { - QMetaObject::invokeMethod(config, [this]() { - m_config.loadRelaxed()->reset(QStringLiteral("keyboardsearchDisabled")); - }); - } - } -#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) - QBindable bindableKeyboardsearchDisabled() { - return QBindable(this, "keyboardsearchDisabled"); - } -#endif - Q_INVOKABLE bool keyboardsearchDisabledIsDefaultValue() const { - return !testPropertySet(3); - } - QString rules() const { - return p_rules; - } - void setRules(const QString &value) { - auto oldValue = p_rules; - p_rules = value; - markPropertySet(4); - if (auto config = m_config.loadRelaxed()) { - QMetaObject::invokeMethod(config, [this, value]() { - m_config.loadRelaxed()->setValue(QStringLiteral("rules"), value); - }); - } - if (p_rules != oldValue) { - Q_EMIT rulesChanged(); - Q_EMIT valueChanged(QStringLiteral("rules"), value); - } - } - void resetRules() { - if (auto config = m_config.loadRelaxed()) { - QMetaObject::invokeMethod(config, [this]() { - m_config.loadRelaxed()->reset(QStringLiteral("rules")); - }); - } - } -#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) - QBindable bindableRules() { - return QBindable(this, "rules"); - } -#endif - Q_INVOKABLE bool rulesIsDefaultValue() const { - return !testPropertySet(4); - } - qlonglong scrollBarPolicy() const { - return p_scrollBarPolicy; - } - void setScrollBarPolicy(const qlonglong &value) { - auto oldValue = p_scrollBarPolicy; - p_scrollBarPolicy = value; - markPropertySet(5); - if (auto config = m_config.loadRelaxed()) { - QMetaObject::invokeMethod(config, [this, value]() { - m_config.loadRelaxed()->setValue(QStringLiteral("scrollBarPolicy"), value); - }); - } - if (p_scrollBarPolicy != oldValue) { - Q_EMIT scrollBarPolicyChanged(); - Q_EMIT valueChanged(QStringLiteral("scrollBarPolicy"), value); - } - } - void resetScrollBarPolicy() { - if (auto config = m_config.loadRelaxed()) { - QMetaObject::invokeMethod(config, [this]() { - m_config.loadRelaxed()->reset(QStringLiteral("scrollBarPolicy")); - }); - } - } -#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) - QBindable bindableScrollBarPolicy() { - return QBindable(this, "scrollBarPolicy"); - } -#endif - Q_INVOKABLE bool scrollBarPolicyIsDefaultValue() const { - return !testPropertySet(5); - } - qlonglong sizeMode() const { - return p_sizeMode; - } - void setSizeMode(const qlonglong &value) { - auto oldValue = p_sizeMode; - p_sizeMode = value; - markPropertySet(6); - if (auto config = m_config.loadRelaxed()) { - QMetaObject::invokeMethod(config, [this, value]() { - m_config.loadRelaxed()->setValue(QStringLiteral("sizeMode"), value); - }); - } - if (p_sizeMode != oldValue) { - Q_EMIT sizeModeChanged(); - Q_EMIT valueChanged(QStringLiteral("sizeMode"), value); - } - } - void resetSizeMode() { - if (auto config = m_config.loadRelaxed()) { - QMetaObject::invokeMethod(config, [this]() { - m_config.loadRelaxed()->reset(QStringLiteral("sizeMode")); - }); - } - } -#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) - QBindable bindableSizeMode() { - return QBindable(this, "sizeMode"); - } -#endif - Q_INVOKABLE bool sizeModeIsDefaultValue() const { - return !testPropertySet(6); - } - qlonglong themeType() const { - return p_themeType; - } - void setThemeType(const qlonglong &value) { - auto oldValue = p_themeType; - p_themeType = value; - markPropertySet(7); - if (auto config = m_config.loadRelaxed()) { - QMetaObject::invokeMethod(config, [this, value]() { - m_config.loadRelaxed()->setValue(QStringLiteral("themeType"), value); - }); - } - if (p_themeType != oldValue) { - Q_EMIT themeTypeChanged(); - Q_EMIT valueChanged(QStringLiteral("themeType"), value); - } - } - void resetThemeType() { - if (auto config = m_config.loadRelaxed()) { - QMetaObject::invokeMethod(config, [this]() { - m_config.loadRelaxed()->reset(QStringLiteral("themeType")); - }); - } - } -#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) - QBindable bindableThemeType() { - return QBindable(this, "themeType"); - } -#endif - Q_INVOKABLE bool themeTypeIsDefaultValue() const { - return !testPropertySet(7); - } - qlonglong titlebarHeight() const { - return p_titlebarHeight; - } - void setTitlebarHeight(const qlonglong &value) { - auto oldValue = p_titlebarHeight; - p_titlebarHeight = value; - markPropertySet(8); - if (auto config = m_config.loadRelaxed()) { - QMetaObject::invokeMethod(config, [this, value]() { - m_config.loadRelaxed()->setValue(QStringLiteral("titlebarHeight"), value); - }); - } - if (p_titlebarHeight != oldValue) { - Q_EMIT titlebarHeightChanged(); - Q_EMIT valueChanged(QStringLiteral("titlebarHeight"), value); - } - } - void resetTitlebarHeight() { - if (auto config = m_config.loadRelaxed()) { - QMetaObject::invokeMethod(config, [this]() { - m_config.loadRelaxed()->reset(QStringLiteral("titlebarHeight")); - }); - } - } -#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) - QBindable bindableTitlebarHeight() { - return QBindable(this, "titlebarHeight"); - } -#endif - Q_INVOKABLE bool titlebarHeightIsDefaultValue() const { - return !testPropertySet(8); - } - bool underlineShortcut() const { - return p_underlineShortcut; - } - void setUnderlineShortcut(const bool &value) { - auto oldValue = p_underlineShortcut; - p_underlineShortcut = value; - markPropertySet(9); - if (auto config = m_config.loadRelaxed()) { - QMetaObject::invokeMethod(config, [this, value]() { - m_config.loadRelaxed()->setValue(QStringLiteral("underlineShortcut"), value); - }); - } - if (p_underlineShortcut != oldValue) { - Q_EMIT underlineShortcutChanged(); - Q_EMIT valueChanged(QStringLiteral("underlineShortcut"), value); - } - } - void resetUnderlineShortcut() { - if (auto config = m_config.loadRelaxed()) { - QMetaObject::invokeMethod(config, [this]() { - m_config.loadRelaxed()->reset(QStringLiteral("underlineShortcut")); - }); - } - } -#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) - QBindable bindableUnderlineShortcut() { - return QBindable(this, "underlineShortcut"); - } -#endif - Q_INVOKABLE bool underlineShortcutIsDefaultValue() const { - return !testPropertySet(9); - } -Q_SIGNALS: - void configInitializeFailed(DTK_CORE_NAMESPACE::DConfig *config); - void configInitializeSucceed(DTK_CORE_NAMESPACE::DConfig *config); - void valueChanged(const QString &key, const QVariant &value); - - void autoDisplayFeatureChanged(); - void enableDtkAnimationsChanged(); - void featureUpdatedChanged(); - void keyboardsearchDisabledChanged(); - void rulesChanged(); - void scrollBarPolicyChanged(); - void sizeModeChanged(); - void themeTypeChanged(); - void titlebarHeightChanged(); - void underlineShortcutChanged(); -private: - void initializeInConfigThread(DTK_CORE_NAMESPACE::DConfig *config) { - Q_ASSERT(!m_config.loadRelaxed()); - m_config.storeRelaxed(config); - if (!config->isValid()) { - m_status.storeRelaxed(static_cast(Status::Failed)); - Q_EMIT configInitializeFailed(config); - return; - } - - if (testPropertySet(0)) { - config->setValue(QStringLiteral("autoDisplayFeature"), QVariant::fromValue(p_autoDisplayFeature)); - } else { - updateValue(QStringLiteral("autoDisplayFeature"), QVariant::fromValue(p_autoDisplayFeature)); - } - if (testPropertySet(1)) { - config->setValue(QStringLiteral("enableDtkAnimations"), QVariant::fromValue(p_enableDtkAnimations)); - } else { - updateValue(QStringLiteral("enableDtkAnimations"), QVariant::fromValue(p_enableDtkAnimations)); - } - if (testPropertySet(2)) { - config->setValue(QStringLiteral("featureUpdated"), QVariant::fromValue(p_featureUpdated)); - } else { - updateValue(QStringLiteral("featureUpdated"), QVariant::fromValue(p_featureUpdated)); - } - if (testPropertySet(3)) { - config->setValue(QStringLiteral("keyboardsearchDisabled"), QVariant::fromValue(p_keyboardsearchDisabled)); - } else { - updateValue(QStringLiteral("keyboardsearchDisabled"), QVariant::fromValue(p_keyboardsearchDisabled)); - } - if (testPropertySet(4)) { - config->setValue(QStringLiteral("rules"), QVariant::fromValue(p_rules)); - } else { - updateValue(QStringLiteral("rules"), QVariant::fromValue(p_rules)); - } - if (testPropertySet(5)) { - config->setValue(QStringLiteral("scrollBarPolicy"), QVariant::fromValue(p_scrollBarPolicy)); - } else { - updateValue(QStringLiteral("scrollBarPolicy"), QVariant::fromValue(p_scrollBarPolicy)); - } - if (testPropertySet(6)) { - config->setValue(QStringLiteral("sizeMode"), QVariant::fromValue(p_sizeMode)); - } else { - updateValue(QStringLiteral("sizeMode"), QVariant::fromValue(p_sizeMode)); - } - if (testPropertySet(7)) { - config->setValue(QStringLiteral("themeType"), QVariant::fromValue(p_themeType)); - } else { - updateValue(QStringLiteral("themeType"), QVariant::fromValue(p_themeType)); - } - if (testPropertySet(8)) { - config->setValue(QStringLiteral("titlebarHeight"), QVariant::fromValue(p_titlebarHeight)); - } else { - updateValue(QStringLiteral("titlebarHeight"), QVariant::fromValue(p_titlebarHeight)); - } - if (testPropertySet(9)) { - config->setValue(QStringLiteral("underlineShortcut"), QVariant::fromValue(p_underlineShortcut)); - } else { - updateValue(QStringLiteral("underlineShortcut"), QVariant::fromValue(p_underlineShortcut)); - } - - connect(config, &DTK_CORE_NAMESPACE::DConfig::valueChanged, this, [this](const QString &key) { - updateValue(key); - }, Qt::DirectConnection); - - m_status.storeRelaxed(static_cast(Status::Succeed)); - Q_EMIT configInitializeSucceed(config); - } - void updateValue(const QString &key, const QVariant &fallback = QVariant()) { - Q_ASSERT(QThread::currentThread() == m_config.loadRelaxed()->thread()); - const QVariant &value = m_config.loadRelaxed()->value(key, fallback); - if (key == QStringLiteral("autoDisplayFeature")) { - markPropertySet(0, !m_config.loadRelaxed()->isDefaultValue(key)); - auto newValue = qvariant_cast(value); - QMetaObject::invokeMethod(this, [this, newValue, key, value]() { - Q_ASSERT(QThread::currentThread() == this->thread()); - if (p_autoDisplayFeature != newValue) { - p_autoDisplayFeature = newValue; - Q_EMIT autoDisplayFeatureChanged(); - Q_EMIT valueChanged(key, value); - } - }); - return; - } - if (key == QStringLiteral("enableDtkAnimations")) { - markPropertySet(1, !m_config.loadRelaxed()->isDefaultValue(key)); - auto newValue = qvariant_cast(value); - QMetaObject::invokeMethod(this, [this, newValue, key, value]() { - Q_ASSERT(QThread::currentThread() == this->thread()); - if (p_enableDtkAnimations != newValue) { - p_enableDtkAnimations = newValue; - Q_EMIT enableDtkAnimationsChanged(); - Q_EMIT valueChanged(key, value); - } - }); - return; - } - if (key == QStringLiteral("featureUpdated")) { - markPropertySet(2, !m_config.loadRelaxed()->isDefaultValue(key)); - auto newValue = qvariant_cast(value); - QMetaObject::invokeMethod(this, [this, newValue, key, value]() { - Q_ASSERT(QThread::currentThread() == this->thread()); - if (p_featureUpdated != newValue) { - p_featureUpdated = newValue; - Q_EMIT featureUpdatedChanged(); - Q_EMIT valueChanged(key, value); - } - }); - return; - } - if (key == QStringLiteral("keyboardsearchDisabled")) { - markPropertySet(3, !m_config.loadRelaxed()->isDefaultValue(key)); - auto newValue = qvariant_cast(value); - QMetaObject::invokeMethod(this, [this, newValue, key, value]() { - Q_ASSERT(QThread::currentThread() == this->thread()); - if (p_keyboardsearchDisabled != newValue) { - p_keyboardsearchDisabled = newValue; - Q_EMIT keyboardsearchDisabledChanged(); - Q_EMIT valueChanged(key, value); - } - }); - return; - } - if (key == QStringLiteral("rules")) { - markPropertySet(4, !m_config.loadRelaxed()->isDefaultValue(key)); - auto newValue = qvariant_cast(value); - QMetaObject::invokeMethod(this, [this, newValue, key, value]() { - Q_ASSERT(QThread::currentThread() == this->thread()); - if (p_rules != newValue) { - p_rules = newValue; - Q_EMIT rulesChanged(); - Q_EMIT valueChanged(key, value); - } - }); - return; - } - if (key == QStringLiteral("scrollBarPolicy")) { - markPropertySet(5, !m_config.loadRelaxed()->isDefaultValue(key)); - auto newValue = qvariant_cast(value); - QMetaObject::invokeMethod(this, [this, newValue, key, value]() { - Q_ASSERT(QThread::currentThread() == this->thread()); - if (p_scrollBarPolicy != newValue) { - p_scrollBarPolicy = newValue; - Q_EMIT scrollBarPolicyChanged(); - Q_EMIT valueChanged(key, value); - } - }); - return; - } - if (key == QStringLiteral("sizeMode")) { - markPropertySet(6, !m_config.loadRelaxed()->isDefaultValue(key)); - auto newValue = qvariant_cast(value); - QMetaObject::invokeMethod(this, [this, newValue, key, value]() { - Q_ASSERT(QThread::currentThread() == this->thread()); - if (p_sizeMode != newValue) { - p_sizeMode = newValue; - Q_EMIT sizeModeChanged(); - Q_EMIT valueChanged(key, value); - } - }); - return; - } - if (key == QStringLiteral("themeType")) { - markPropertySet(7, !m_config.loadRelaxed()->isDefaultValue(key)); - auto newValue = qvariant_cast(value); - QMetaObject::invokeMethod(this, [this, newValue, key, value]() { - Q_ASSERT(QThread::currentThread() == this->thread()); - if (p_themeType != newValue) { - p_themeType = newValue; - Q_EMIT themeTypeChanged(); - Q_EMIT valueChanged(key, value); - } - }); - return; - } - if (key == QStringLiteral("titlebarHeight")) { - markPropertySet(8, !m_config.loadRelaxed()->isDefaultValue(key)); - auto newValue = qvariant_cast(value); - QMetaObject::invokeMethod(this, [this, newValue, key, value]() { - Q_ASSERT(QThread::currentThread() == this->thread()); - if (p_titlebarHeight != newValue) { - p_titlebarHeight = newValue; - Q_EMIT titlebarHeightChanged(); - Q_EMIT valueChanged(key, value); - } - }); - return; - } - if (key == QStringLiteral("underlineShortcut")) { - markPropertySet(9, !m_config.loadRelaxed()->isDefaultValue(key)); - auto newValue = qvariant_cast(value); - QMetaObject::invokeMethod(this, [this, newValue, key, value]() { - Q_ASSERT(QThread::currentThread() == this->thread()); - if (p_underlineShortcut != newValue) { - p_underlineShortcut = newValue; - Q_EMIT underlineShortcutChanged(); - Q_EMIT valueChanged(key, value); - } - }); - return; - } - } - inline void markPropertySet(const int index, bool on = true) { - if (index < 32) { - if (on) - m_propertySetStatus0.fetchAndOrOrdered(1 << (index - 0)); - else - m_propertySetStatus0.fetchAndAndOrdered(~(1 << (index - 0))); - return; - } - Q_UNREACHABLE(); - } - inline bool testPropertySet(const int index) const { - if (index < 32) { - return (m_propertySetStatus0.loadRelaxed() & (1 << (index - 0))); - } - Q_UNREACHABLE(); - } - - QAtomicPointer m_config = nullptr; - -public: - enum class Status { - Invalid = 0, - Succeed = 1, - Failed = 2 - }; -private: - QAtomicInteger m_status = static_cast(Status::Invalid); - - bool p_autoDisplayFeature { false }; - bool p_enableDtkAnimations { false }; - bool p_featureUpdated { false }; - bool p_keyboardsearchDisabled { false }; - // Default value: "" - QString p_rules { QLatin1String("") }; - qlonglong p_scrollBarPolicy { 0 }; - qlonglong p_sizeMode { 0 }; - qlonglong p_themeType { 0 }; - qlonglong p_titlebarHeight { -1 }; - bool p_underlineShortcut { false }; - QAtomicInteger m_propertySetStatus0 = 0; -}; - -#endif // ORGDEEPINDTKPREFERENCE_H