Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions src/log/dconfig_org_deepin_dtk_preference.hpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
/**
* This file is generated by dconfig2cpp.
* Command line arguments: ./build/tools/dconfig2cpp/dconfig2cpp /usr/share/dsg/configs/org.deepin.dtk.preference.json -o ./src/log/dconfig_org_deepin_dtk_preference.hpp
* Generation time: 2026-01-21T14:01:24
* Generation time: 2026-01-22T14:49:01
* JSON file version: 1.0
* Tool version: 1.1
*
* WARNING: DO NOT MODIFY THIS FILE MANUALLY.
* If you need to change the content, please modify the dconfig2cpp tool.
Expand All @@ -11,9 +12,24 @@
#ifndef DCONFIG_ORG_DEEPIN_DTK_PREFERENCE_H
#define DCONFIG_ORG_DEEPIN_DTK_PREFERENCE_H

#define DCONFIG_ORG_DEEPIN_DTK_PREFERENCE_DCONFIG_FILE_VERSION_MAJOR 1
#define DCONFIG_ORG_DEEPIN_DTK_PREFERENCE_DCONFIG_FILE_VERSION_MINOR 1
#define DCONFIG_ORG_DEEPIN_DTK_PREFERENCE_DCONFIG_FILE_autoDisplayFeature
#define DCONFIG_ORG_DEEPIN_DTK_PREFERENCE_DCONFIG_FILE_colorMode
#define DCONFIG_ORG_DEEPIN_DTK_PREFERENCE_DCONFIG_FILE_defaultColorMode
#define DCONFIG_ORG_DEEPIN_DTK_PREFERENCE_DCONFIG_FILE_enableDtkAnimations
#define DCONFIG_ORG_DEEPIN_DTK_PREFERENCE_DCONFIG_FILE_featureUpdated
#define DCONFIG_ORG_DEEPIN_DTK_PREFERENCE_DCONFIG_FILE_keyboardsearchDisabled
#define DCONFIG_ORG_DEEPIN_DTK_PREFERENCE_DCONFIG_FILE_rules
#define DCONFIG_ORG_DEEPIN_DTK_PREFERENCE_DCONFIG_FILE_scrollBarPolicy
#define DCONFIG_ORG_DEEPIN_DTK_PREFERENCE_DCONFIG_FILE_sizeMode
#define DCONFIG_ORG_DEEPIN_DTK_PREFERENCE_DCONFIG_FILE_themeType
#define DCONFIG_ORG_DEEPIN_DTK_PREFERENCE_DCONFIG_FILE_titlebarHeight
#define DCONFIG_ORG_DEEPIN_DTK_PREFERENCE_DCONFIG_FILE_underlineShortcut

#include <QThread>

Check warning on line 30 in src/log/dconfig_org_deepin_dtk_preference.hpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QThread> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QVariant>

Check warning on line 31 in src/log/dconfig_org_deepin_dtk_preference.hpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QVariant> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QPointer>

Check warning on line 32 in src/log/dconfig_org_deepin_dtk_preference.hpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QPointer> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QDebug>
#include <QAtomicPointer>
#include <QAtomicInteger>
Expand Down Expand Up @@ -119,6 +135,7 @@
// Initialize through Data class
safeData->initializeInConfigThread(config);

// Queue state transition to main thread, to ensure config values are fully initialized.
QMetaObject::invokeMethod(safeData, [safeData, config]() {
// Try to transition from Initializing to Succeeded
if (safeData->m_status.testAndSetOrdered(static_cast<int>(Data::Status::Initializing),
Expand All @@ -135,7 +152,6 @@
safeData->deleteLater();
}
}, Qt::QueuedConnection);

});
}
static dconfig_org_deepin_dtk_preference* create(const QString &appId = {}, const QString &subpath = {}, QObject *parent = nullptr, QThread *thread = DTK_CORE_NAMESPACE::DConfig::globalThread())
Expand Down
39 changes: 38 additions & 1 deletion tools/dconfig2cpp/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,15 @@
#include <QJsonArray>
#include <QFile>
#include <QDebug>
#include <QCommandLineParser>

Check warning on line 12 in tools/dconfig2cpp/main.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QCommandLineParser> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QFileInfo>

Check warning on line 13 in tools/dconfig2cpp/main.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QFileInfo> not found. Please note: Cppcheck does not need standard library headers to get proper results.

struct Version {
quint16 major;
quint16 minor;
};
static constexpr Version ToolVersion{1, 1};

static QString toUnicodeEscape(const QString& input) {
QString result;
for (QChar ch : input) {
Expand Down Expand Up @@ -82,9 +88,11 @@

int main(int argc, char *argv[]) {
QCoreApplication app(argc, argv);
app.setApplicationVersion(QString("%1.%2").arg(ToolVersion.major).arg(ToolVersion.minor));
QCommandLineParser parser;
parser.setApplicationDescription(QLatin1String("DConfig to C++ class generator"));
parser.addHelpOption();
parser.addVersionOption();

// Define command line options
QCommandLineOption classNameOption(QStringList() << QLatin1String("c") << QLatin1String("class-name"),
Expand Down Expand Up @@ -151,6 +159,18 @@

// Extract version and add it as a comment in the generated code
QString version = root[QLatin1String("version")].toString();

// Parse version to get major
QString fileMajorVersion;
const auto versionParts = version.split('.');
if (versionParts.size() == 2) {
fileMajorVersion = versionParts[0];
}

if (fileMajorVersion != "1") {
qWarning() << QLatin1String("Warning: The JSON file version isn't supported.");
return -1;
}

// Generate header and source file comments
QString commandLineArgs = QCoreApplication::arguments().join(QLatin1String(" "));
Expand All @@ -163,20 +183,37 @@
" * Command line arguments: %1\n"
" * Generation time: %2\n"
" * JSON file version: %3\n"
" * Tool version: %4\n"
" *\n"
" * WARNING: DO NOT MODIFY THIS FILE MANUALLY.\n"
" * If you need to change the content, please modify the dconfig2cpp tool.\n"
" */\n\n"
).arg(commandLineArgs, generationTime, version);
).arg(commandLineArgs, generationTime, version, QString("%1.%2").arg(ToolVersion.major).arg(ToolVersion.minor));

headerStream << headerComment;
}

QJsonObject contents = root[QLatin1String("contents")].toObject();

// First pass: collect all property names for macro definitions
QStringList allPropertyNames;
for (auto it = contents.begin(); it != contents.end(); ++it) {
allPropertyNames << it.key();
}

// Write header file content
headerStream << "#ifndef " << className.toUpper() << "_H\n";
headerStream << "#define " << className.toUpper() << "_H\n\n";

// Add version macros
headerStream << "#define " << className.toUpper() << "_DCONFIG_FILE_VERSION_MAJOR " << ToolVersion.major << "\n";
headerStream << "#define " << className.toUpper() << "_DCONFIG_FILE_VERSION_MINOR " << ToolVersion.minor << "\n";

// Add property macros
for (const QString &propName : allPropertyNames) {
headerStream << "#define " << className.toUpper() << "_DCONFIG_FILE_" << propName << "\n";
}
headerStream << "\n";
headerStream << "#include <QThread>\n";
headerStream << "#include <QVariant>\n";
headerStream << "#include <QPointer>\n";
Expand Down