diff --git a/src/log/dconfig_org_deepin_dtk_preference.hpp b/src/log/dconfig_org_deepin_dtk_preference.hpp index 5a318c8a..abd3ae85 100644 --- a/src/log/dconfig_org_deepin_dtk_preference.hpp +++ b/src/log/dconfig_org_deepin_dtk_preference.hpp @@ -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. @@ -11,6 +12,21 @@ #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 #include #include @@ -119,6 +135,7 @@ class dconfig_org_deepin_dtk_preference : public QObject { // 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(Data::Status::Initializing), @@ -135,7 +152,6 @@ class dconfig_org_deepin_dtk_preference : public QObject { 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()) diff --git a/tools/dconfig2cpp/main.cpp b/tools/dconfig2cpp/main.cpp index 4c1804b1..3ca2ffc2 100644 --- a/tools/dconfig2cpp/main.cpp +++ b/tools/dconfig2cpp/main.cpp @@ -12,6 +12,12 @@ #include #include +struct Version { + quint16 major; + quint16 minor; +}; +static constexpr Version ToolVersion{1, 1}; + static QString toUnicodeEscape(const QString& input) { QString result; for (QChar ch : input) { @@ -82,9 +88,11 @@ static QString jsonValueToCppCode(const QJsonValue &value){ 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"), @@ -151,6 +159,18 @@ int main(int argc, char *argv[]) { // 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(" ")); @@ -163,20 +183,37 @@ int main(int argc, char *argv[]) { " * 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 \n"; headerStream << "#include \n"; headerStream << "#include \n";