Skip to content

Commit 7c2b35a

Browse files
committed
feat: use dconfig2cpp for read/write the DConfig
The org.deepin.dtk.preference.json file is not in this project, so we can't generated codes by cmake.
1 parent ec6fbaf commit 7c2b35a

6 files changed

Lines changed: 771 additions & 38 deletions

File tree

.reuse/dep5

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,3 +63,6 @@ Files: toolGenerate/**/*
6363
Copyright: None
6464
License: CC0-1.0
6565

66+
Files: src/kernel/orgdeepindtkpreference.hpp
67+
Copyright: None
68+
License: CC0-1.0

src/kernel/dguiapplicationhelper.cpp

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@
55
#include "dguiapplicationhelper.h"
66
#include "private/dguiapplicationhelper_p.h"
77
#include "dplatformhandle.h"
8+
89
#include <DFontManager>
910
#include <DStandardPaths>
11+
#include <DSGApplication>
1012

1113
#include <QHash>
1214
#include <QColor>
@@ -34,7 +36,6 @@
3436
#include <QDBusConnection>
3537
#include <QDBusConnectionInterface>
3638
#include <QProcess>
37-
#include <DConfig>
3839
#endif
3940
#include <QDir>
4041
#include <QLockFile>
@@ -61,6 +62,8 @@
6162
#include <unistd.h>
6263
#endif
6364

65+
#include "orgdeepindtkpreference.hpp"
66+
6467
#ifdef Q_OS_UNIX
6568
class EnvReplaceGuard
6669
{
@@ -115,10 +118,9 @@ Q_GLOBAL_STATIC(DFontManager, _globalFM)
115118

116119
#define WINDOW_THEME_KEY "_d_platform_theme"
117120

118-
#define APP_THEME_TYPE "themeType"
119-
#define DTK_ENABLE_ANIMATIONS "enableDtkAnimations"
120121
#define DTK_ANIMATIONS_ENV "D_DTK_DISABLE_ANIMATIONS"
121-
Q_GLOBAL_STATIC_WITH_ARGS(DTK_CORE_NAMESPACE::DConfig, _d_dconfig, ("org.deepin.dtk.preference"));
122+
Q_GLOBAL_STATIC(OrgDeepinDTKPreference, _d_dconfig, DTK_CORE_NAMESPACE::DConfig::globalThread(), nullptr,
123+
"org.deepin.dtk.preference", DTK_CORE_NAMESPACE::DSGApplication::id(), {}, false, nullptr)
122124

123125
/*!
124126
@private
@@ -445,7 +447,7 @@ void DGuiApplicationHelperPrivate::initPaletteType() const
445447
return;
446448

447449
auto applyThemeType = [this](bool emitSignal){
448-
int ct = _d_dconfig->value(APP_THEME_TYPE, DGuiApplicationHelper::UnknownType).toInt();
450+
int ct = _d_dconfig->themeType();
449451
if (ct > DGuiApplicationHelper::DarkType || ct < DGuiApplicationHelper::UnknownType)
450452
ct = DGuiApplicationHelper::UnknownType;
451453

@@ -454,10 +456,7 @@ void DGuiApplicationHelperPrivate::initPaletteType() const
454456

455457
applyThemeType(false);
456458

457-
QObject::connect(_d_dconfig, &DConfig::valueChanged, _d_dconfig, [applyThemeType](const QString &key){
458-
if (key != APP_THEME_TYPE)
459-
return;
460-
459+
QObject::connect(_d_dconfig.operator ()(), &OrgDeepinDTKPreference::themeTypeChanged, _d_dconfig, [applyThemeType] {
461460
applyThemeType(true);
462461
});
463462
}
@@ -1781,8 +1780,7 @@ bool DGuiApplicationHelper::testAttribute(DGuiApplicationHelper::Attribute attri
17811780
if (isDisable)
17821781
return false;
17831782

1784-
static bool shouldEnable = _d_dconfig->value(DTK_ENABLE_ANIMATIONS, false).toBool();
1785-
return shouldEnable;
1783+
return _d_dconfig->enableDtkAnimations();
17861784
}
17871785
default:
17881786
return DGuiApplicationHelperPrivate::attributes.testFlag(attribute);
@@ -1823,7 +1821,7 @@ void DGuiApplicationHelper::setPaletteType(DGuiApplicationHelper::ColorType pale
18231821

18241822
d->initPaletteType();
18251823
d->setPaletteType(paletteType, true);
1826-
_d_dconfig->setValue(APP_THEME_TYPE, paletteType);
1824+
_d_dconfig->setThemeType(static_cast<int>(paletteType));
18271825
}
18281826

18291827
/*!

src/kernel/dplatformtheme.cpp

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,15 @@
1313
#include "plugins/platform/treeland/dtreelandplatforminterface.h"
1414
#endif
1515
#include "private/dplatforminterface_p.h"
16+
#include "orgdeepindtkpreference.hpp"
1617

1718
#include <QVariant>
1819
#include <QTimer>
1920
#include <QMetaProperty>
2021
#include <QDebug>
2122
#include <DGuiApplicationHelper>
22-
#include <DConfig>
2323

2424
DGUI_BEGIN_NAMESPACE
25-
#define DTK_PREFERENCE_NAME "org.deepin.dtk.preference"
26-
#define DTK_SIZE_MODE_KEY "sizeMode"
27-
#define DTK_SCROLLBAR_POLICY_KEY "scrollBarPolicy"
2825

2926
static DPlatformInterfaceFactory::HelperCreator OutsideInterfaceCreator = nullptr;
3027

@@ -78,18 +75,6 @@ void DPlatformThemePrivate::notifyPaletteChanged()
7875
notifyPaletteChangeTimer->start(300);
7976
}
8077

81-
void DPlatformThemePrivate::onDtkPreferenceDConfigChanged(const QString &key)
82-
{
83-
D_Q(DPlatformTheme);
84-
if (key == DTK_SIZE_MODE_KEY) {
85-
sizeMode = static_cast<DGuiApplicationHelper::SizeMode>(dtkPreferenceConfig->value(key).toInt());
86-
Q_EMIT q->sizeModeChanged(sizeMode);
87-
} else if (key == DTK_SCROLLBAR_POLICY_KEY) {
88-
scrollBarPolicy = static_cast<Qt::ScrollBarPolicy>(dtkPreferenceConfig->value(key).toInt());
89-
Q_EMIT q->scrollBarPolicyChanged(scrollBarPolicy);
90-
}
91-
}
92-
9378
/*!
9479
\class Dtk::Gui::DPlatformTheme
9580
\inmodule dtkgui
@@ -125,12 +110,18 @@ DPlatformTheme::DPlatformTheme(quint32 window, QObject *parent)
125110

126111
d->theme = new DNativeSettings(window, QByteArray(), this);
127112

128-
d->dtkPreferenceConfig = DConfig::createGeneric(DTK_PREFERENCE_NAME, "", this);
129-
d->sizeMode = static_cast<DGuiApplicationHelper::SizeMode>(d->dtkPreferenceConfig->value(DTK_SIZE_MODE_KEY).toInt());
130-
d->scrollBarPolicy = static_cast<Qt::ScrollBarPolicy>(d->dtkPreferenceConfig->value(DTK_SCROLLBAR_POLICY_KEY).toInt());
131-
connect(d->dtkPreferenceConfig, &DConfig::valueChanged, this, [this](const QString &key) -> void{
113+
d->dtkPreferenceConfig = OrgDeepinDTKPreference::createGeneric("", this);
114+
d->sizeMode = static_cast<DGuiApplicationHelper::SizeMode>(d->dtkPreferenceConfig->sizeMode());
115+
d->scrollBarPolicy = static_cast<Qt::ScrollBarPolicy>(d->dtkPreferenceConfig->scrollBarPolicy());
116+
connect(d->dtkPreferenceConfig, &OrgDeepinDTKPreference::sizeModeChanged, this, [this] {
117+
D_D(DPlatformTheme);
118+
d->sizeMode = static_cast<DGuiApplicationHelper::SizeMode>(d->dtkPreferenceConfig->sizeMode());
119+
Q_EMIT sizeModeChanged(d->sizeMode);
120+
});
121+
connect(d->dtkPreferenceConfig, &OrgDeepinDTKPreference::scrollBarPolicyChanged, this, [this] {
132122
D_D(DPlatformTheme);
133-
d->onDtkPreferenceDConfigChanged(key);
123+
d->scrollBarPolicy = static_cast<Qt::ScrollBarPolicy>(d->dtkPreferenceConfig->scrollBarPolicy());
124+
Q_EMIT scrollBarPolicyChanged(d->scrollBarPolicy);
134125
});
135126

136127
#if DTK_VERSION < DTK_VERSION_CHECK(6, 0, 0, 0)

src/kernel/kernel.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@ file(GLOB KERNEL_SOURCE
77
set(kernel_SRC
88
${KERNEL_HEADER}
99
${KERNEL_SOURCE}
10+
${CMAKE_CURRENT_LIST_DIR}/orgdeepindtkpreference.hpp
1011
)

0 commit comments

Comments
 (0)