### Build DtkCore from Source Source: https://github.com/linuxdeepin/dtkcore/blob/master/README.md Instructions for building the Deepin Tool Kit Core from source code. Ensure all dependencies are installed before proceeding. ```bash mkdir build cd build cmake .. make ``` ```bash sudo make install ``` -------------------------------- ### Configure dconfig2cpp Executable Build Source: https://github.com/linuxdeepin/dtkcore/blob/master/tools/dconfig2cpp/CMakeLists.txt Sets up the build for the dconfig2cpp executable, including its name, dependencies, and installation path. Ensure Qt Core is available. ```cmake set(TARGET_NAME dconfig2cpp) set(BIN_NAME ${TARGET_NAME}${DTK_NAME_SUFFIX}) set(CMAKE_EXPORT_COMPILE_COMMANDS ON) find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Core) add_executable(${BIN_NAME} main.cpp ) target_link_libraries( ${BIN_NAME} PRIVATE Qt${QT_VERSION_MAJOR}::Core ) set_target_properties( ${BIN_NAME} PROPERTIES OUTPUT_NAME ${TARGET_NAME} EXPORT_NAME DConfig2Cpp ) install( TARGETS ${BIN_NAME} EXPORT Dtk${DTK_NAME_SUFFIX}ToolsTargets DESTINATION ${TOOL_INSTALL_DIR} ) ``` -------------------------------- ### DSettings Initialization and Usage Example Source: https://github.com/linuxdeepin/dtkcore/blob/master/docs/settings/index.zh_CN.md Demonstrates initializing DSettings from a JSON resource, setting a backend, reading option values, modifying them, retrieving all keys, and accessing specific groups. Requires DtkCore and Qt. ```cpp #include #include #include #include #include #include #include DCORE_USE_NAMESPACE int main(int argc, char *argv[]) { QCoreApplication a(argc, argv); // 初始化一个存储后端 QTemporaryFile tmpFile; tmpFile.open(); QPointer backend = new QSettingBackend(tmpFile.fileName()); // 从json中初始化配置 QPointer settings = DSettings::fromJsonFile(":/data/settings.json"); settings->setBackend(backend); // 读取配置 // 该组中包含一个base的root组,两个子组: open_action/new_tab_windows,每个子组有包含若干选项。 // 对于"New Window Open:"这个配置,其完整的访问id为base.new_tab_windows.new_window_path。 QPointer opt = settings->option("base.new_tab_windows.new_window_path"); qDebug() << opt->value(); // 修改配置 opt->setValue("Test"); qDebug() << opt->value(); // 获取所有keys QStringList keys = settings->keys(); qDebug() << keys; // base.open_action对应的组 QPointer group = settings->group("base.open_action"); qDebug() << group->key(); return a.exec(); } ``` -------------------------------- ### Set Target Properties and Install Deepin OS Release Source: https://github.com/linuxdeepin/dtkcore/blob/master/tools/deepin-os-release/CMakeLists.txt Sets the output name property for the deepin-os-release target and installs the executable to the specified tool installation directory. ```cmake set_target_properties(${BIN_NAME} PROPERTIES OUTPUT_NAME ${TARGET_NAME}) install(TARGETS ${BIN_NAME} DESTINATION "${TOOL_INSTALL_DIR}") #end dci ``` -------------------------------- ### Configure textcodec Executable Build Source: https://github.com/linuxdeepin/dtkcore/blob/master/examples/textcodec-example/CMakeLists.txt This snippet defines the executable name, links against Qt Core and a library named LIB_NAME, and sets public include directories. It's used to build the textcodec example application. ```cmake set(BIN_NAME textcodec${DTK_NAME_SUFFIX}) find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Core) add_executable(${BIN_NAME} main.cpp ) target_link_libraries( ${BIN_NAME} PRIVATE Qt${QT_VERSION_MAJOR}::Core ${LIB_NAME} ) target_include_directories(${BIN_NAME} PUBLIC ../../include/util/ ../../include/ ) ``` -------------------------------- ### Configure dtk-settings Executable Build Source: https://github.com/linuxdeepin/dtkcore/blob/master/tools/settings/CMakeLists.txt Defines the target name, finds Qt Core and Xml modules, checks for PkgConfig and gsettings-qt if Qt5 is used, adds the main source file, and links necessary libraries. It also sets public include directories and configures output name and installation. ```cmake set(TARGET_NAME dtk-settings) set(BIN_NAME ${TARGET_NAME}${DTK_NAME_SUFFIX}) find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Core) find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Xml) if(${QT_VERSION_MAJOR} STREQUAL "5") find_package(PkgConfig REQUIRED) pkg_check_modules(QGSettings REQUIRED IMPORTED_TARGET gsettings-qt) endif() add_executable(${BIN_NAME} main.cpp ) target_link_libraries( ${BIN_NAME} PRIVATE Qt${QT_VERSION_MAJOR}::Core Qt${QT_VERSION_MAJOR}::Xml ${LIB_NAME} ) if(${QT_VERSION_MAJOR} STREQUAL "5") target_link_libraries( ${BIN_NAME} PRIVATE PkgConfig::QGSettings ) endif() target_include_directories( ${BIN_NAME} PUBLIC ../../include/util/ ../../include/dci/ ../../include/log/ ../../include/base/ ../../include/global/ ../../include/DtkCore/ ../../include/settings/ ../../include/filesystem/ ../../include/ ) set_target_properties(${BIN_NAME} PROPERTIES OUTPUT_NAME ${TARGET_NAME}) install(TARGETS ${BIN_NAME} DESTINATION "${TOOL_INSTALL_DIR}") ``` -------------------------------- ### Basic Log Output with Macros Source: https://github.com/linuxdeepin/dtkcore/blob/master/docs/log/index.zh_CN.md This example demonstrates basic log output using the dDebug() macro. It registers console appenders and optionally journal appenders on Linux. Use the '<<' operator to output multiple variables. The registerJournalAppender() function is Linux-specific. ```cpp #include #include DCORE_USE_NAMESPACE int main(int argc, char **argv) { QCoreApplication app(argc, argv); #ifdef Q_OS_LINUX DLogManager::registerJournalAppender(); #endif DLogManager::registerConsoleAppender(); dDebug() << "this is a debug message"; return app.exec(); } ``` -------------------------------- ### CMakeLists.txt for DtkCore Project Source: https://github.com/linuxdeepin/dtkcore/blob/master/docs/settings/index.zh_CN.md Configures a C++ project using DtkCore, specifying C++ standard, resource file support, and linking against Dtk::Core. Ensure DtkCore is installed and findable by CMake. ```cmake cmake_minimum_required(VERSION 3.1.0) # 指定cmake最低版本 project(dsetting-example VERSION 1.0.0 LANGUAGES CXX)# 指定项目名称, 版本, 语言 cxx就是c++ set(CMAKE_CXX_STANDARD 11) # 指定c++标准 set(CMAKE_CXX_STANDARD_REQUIRED ON) # 指定c++标准要求,至少为11以上 set(CMAKE_AUTORCC ON) # support qt resource file # 支持qt资源文件 set(CMAKE_EXPORT_COMPILE_COMMANDS ON) # 支持 clangd if (CMAKE_VERSION VERSION_LESS "3.7.0") # 如果cmake版本小于3.7.0 set(CMAKE_INCLUDE_CURRENT_DIR ON) # 设置包含当前目录 endif() find_package(DtkCore REQUIRED) # 寻找Dtk组件Core add_executable(${PROJECT_NAME} # 生成可执行文件 main.cpp data.qrc ) target_link_libraries(${PROJECT_NAME} PRIVATE # 添加需要链接的共享库 Dtk::Core ) ``` -------------------------------- ### Resolve XDG and DSG Paths with DStandardPaths Source: https://context7.com/linuxdeepin/dtkcore/llms.txt Use DStandardPaths to get standard user directories according to XDG Base Directory Specification and Deepin DSG. It also handles environment redirection for Snap/Flatpak and provides a test mode for unit testing. ```cpp #include #include DCORE_USE_NAMESPACE void showPaths() { // Standard Qt locations (Snap/Flatpak-aware) QString config = DStandardPaths::writableLocation(QStandardPaths::AppConfigLocation); qDebug() << "App config dir:" << config; // ~/.config/com.example.myapp // XDG Base Directories qDebug() << "XDG_DATA_HOME:" << DStandardPaths::path(DStandardPaths::XDG::DataHome); // → ~/.local/share qDebug() << "XDG_CONFIG_HOME:" << DStandardPaths::path(DStandardPaths::XDG::ConfigHome); // → ~/.config qDebug() << "XDG_CACHE_HOME:" << DStandardPaths::path(DStandardPaths::XDG::CacheHome); // → ~/.cache qDebug() << "XDG_RUNTIME_DIR:" << DStandardPaths::path(DStandardPaths::XDG::RuntimeDir); // → /run/user/1000 qDebug() << "XDG_STATE_HOME:" << DStandardPaths::path(DStandardPaths::XDG::StateHome); // → ~/.local/state // Build a full file path inside an XDG directory QString lockFile = DStandardPaths::filePath(DStandardPaths::XDG::RuntimeDir, "myapp.lock"); qDebug() << "Lock file:" << lockFile; // → /run/user/1000/myapp.lock // DSG application data directories (Deepin-specific shared data) qDebug() << "DSG AppData:" << DStandardPaths::path(DStandardPaths::DSG::AppData); qDebug() << "DSG DataDirs:" << DStandardPaths::paths(DStandardPaths::DSG::DataDir); // Per-user home by UID qDebug() << "Home of uid 1001:" << DStandardPaths::homePath(1001); // Test mode (redirects all paths to a temp directory for unit tests) DStandardPaths::setMode(DStandardPaths::Test); } ``` -------------------------------- ### Interactive Mode Notice for Terminal Programs Source: https://github.com/linuxdeepin/dtkcore/blob/master/LICENSES/LGPL-3.0-or-later.txt If your program interacts with the terminal, display this notice when it starts in interactive mode to inform users about its licensing and warranty status. ```text Copyright (C) This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. ``` -------------------------------- ### Monitor Single File/Directory Changes with DFileWatcher Source: https://context7.com/linuxdeepin/dtkcore/llms.txt Use DFileWatcher to monitor a single file or directory for events like modification, deletion, or creation. Ensure DFileWatcher is started before connecting to its signals. ```cpp #include #include #include #include DCORE_USE_NAMESPACE int main(int argc, char *argv[]) { QCoreApplication app(argc, argv); // --- Single file watcher --- DFileWatcher singleWatcher("/etc/hostname"); singleWatcher.startWatcher(); QObject::connect(&singleWatcher, &DFileWatcher::fileModified, [](const QUrl &url) { qDebug() << "Modified:" << url.toLocalFile(); }); QObject::connect(&singleWatcher, &DFileWatcher::fileDeleted, [](const QUrl &url) { qDebug() << "Deleted:" << url.toLocalFile(); }); // --- Manager for multiple files --- DFileWatcherManager manager; manager.add("/tmp/a.conf"); manager.add("/tmp/b.conf"); manager.add("/home/user/Documents"); // directory: get subfileCreated events QObject::connect(&manager, &DFileWatcherManager::fileModified, [](const QString &path) { qDebug() << "Manager: file modified:" << path; }); QObject::connect(&manager, &DFileWatcherManager::subfileCreated, [](const QString &path) { qDebug() << "Manager: new file in dir:" << path; }); QObject::connect(&manager, &DFileWatcherManager::fileMoved, [](const QString &from, const QString &to) { qDebug() << "Manager: moved" << from << "->" << to; }); qDebug() << "Watching:" << manager.watchedFiles(); // Stop watching a specific path manager.remove("/tmp/a.conf"); // Stop and clean up all watchers manager.removeAll(); // Restart a watcher after removal singleWatcher.stopWatcher(); singleWatcher.restartWatcher(); return app.exec(); } ``` -------------------------------- ### DSettings: Load, Persist, and Manage Application Settings Source: https://context7.com/linuxdeepin/dtkcore/llms.txt Load settings from a JSON schema, attach a backend for persistence (e.g., QSettingBackend), and manage settings values. Supports reading, writing, resetting, and reacting to changes. ```cpp #include #include #include #include #include #include DCORE_USE_NAMESPACE // settings.json: // { "groups": [{ "key": "general", "name": "General", // "options": [ // { "key": "language", "type": "combobox", "default": "en_US" }, // { "key": "autosave", "type": "checkbox", "default": true } // ] // }]} int main(int argc, char *argv[]) { QCoreApplication app(argc, argv); // Load schema from JSON file auto settings = DSettings::fromJsonFile(":/settings.json"); if (!settings) { qCritical() << "Failed to load settings schema"; return 1; } // Attach a QSettings-based persistence backend auto backend = new Dtk::Core::QSettingBackend("/tmp/myapp.ini", settings.data()); settings->setBackend(backend); // Read values qDebug() << "Language:" << settings->value("general.language").toString(); // "en_US" qDebug() << "Autosave:" << settings->value("general.autosave").toBool(); // true // Write a value settings->setOption("general.language", "zh_CN"); settings->sync(); // flush to backend (blocking) // Enumerate all groups and their options for (auto group : settings->groups()) { qDebug() << "Group:" << group->key(); for (auto opt : group->options()) { qDebug() << " " << opt->key() << "=" << opt->value(); } } // React to any change QObject::connect(settings.data(), &DSettings::valueChanged, [](const QString &key, const QVariant &val) { qDebug() << "Setting changed:" << key << "=" << val; }); // Reset all settings to defaults settings->reset(); return 0; } ``` -------------------------------- ### Configure Deepin OS Release Executable Source: https://github.com/linuxdeepin/dtkcore/blob/master/tools/deepin-os-release/CMakeLists.txt Sets up the target name, binary name, and essential CMake configurations like exporting compile commands and enabling automatic meta-object compilation. It also finds the required Qt Core components. ```cmake set(TARGET_NAME deepin-os-release) set(BIN_NAME ${TARGET_NAME}${DTK_NAME_SUFFIX}) set(CMAKE_EXPORT_COMPILE_COMMANDS ON) set(CMAKE_AUTOMOC ON) find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Core) if(${QT_VERSION_MAJOR} EQUAL 6) if(${Qt6Core_VERSION} VERSION_GREATER_EQUAL 6.10.0) find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS CorePrivate) endif() endif() ``` -------------------------------- ### Configure Executable and Link Libraries Source: https://github.com/linuxdeepin/dtkcore/blob/master/examples/expintf-example/CMakeLists.txt Defines the executable name, enables compile command generation, finds Qt components, adds the executable target, and links necessary libraries and include directories. ```cmake set(BIN_NAME exprintf${DTK_NAME_SUFFIX}) set(CMAKE_EXPORT_COMPILE_COMMANDS ON) find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS DBus) add_executable(${BIN_NAME} main.cpp ) target_link_libraries( ${BIN_NAME} PRIVATE Qt${QT_VERSION_MAJOR}::DBus ${LIB_NAME} ) target_include_directories(${BIN_NAME} PUBLIC ../../include/base ../../include/base/private/ ../../include/filesystem/ ../../include/ ) ``` -------------------------------- ### Manage Application Configuration with DConfig Source: https://context7.com/linuxdeepin/dtkcore/llms.txt Use DConfig to manage application settings backed by JSON files. It supports per-user and global overrides, read-only keys, and live change notifications. Ensure the `dconfig` service is available. ```cpp #include #include #include DCORE_USE_NAMESPACE int main(int argc, char *argv[]) { QCoreApplication app(argc, argv); app.setApplicationName("com.example.myapp"); // Open config file "appearance" (maps to org.deepin.dde.appearance.json or similar) DConfig cfg("appearance"); if (!cfg.isValid()) { qWarning() << "Config is invalid (dconfig service unavailable?), check backend"; return 1; } // List all available keys qDebug() << "Keys:" << cfg.keyList(); // e.g. ["theme", "fontSize", "showTray"] // Read a value with a fallback QString theme = cfg.value("theme", "deepin").toString(); qDebug() << "Current theme:" << theme; // Check whether a key still holds its default value if (cfg.isDefaultValue("fontSize")) { qDebug() << "fontSize is at its default"; } // Check if a key is read-only if (!cfg.isReadOnly("theme")) { cfg.setValue("theme", "deepin-dark"); qDebug() << "Theme set to deepin-dark"; } // Reset a key to its default cfg.reset("theme"); // React to live changes (e.g. another process writes the config) QObject::connect(&cfg, &DConfig::valueChanged, [&](const QString &key) { qDebug() << "Config changed:" << key << "→" << cfg.value(key); }); // Create a config for a different appId (cross-app config access) DConfig *otherCfg = DConfig::create("org.deepin.dde.dock", "plugin-settings", QString(), &app); if (otherCfg && otherCfg->isValid()) { qDebug() << "Dock plugin keys:" << otherCfg->keyList(); } return app.exec(); } // Build: find_package(DtkCore REQUIRED); target_link_libraries(myapp DtkCore) ``` -------------------------------- ### Configure Dlog Executable Build Source: https://github.com/linuxdeepin/dtkcore/blob/master/examples/dlog-example/CMakeLists.txt Sets the executable name, enables compile command export, finds Qt Core, and defines the build target with its dependencies and include paths. ```cmake set(BIN_NAME dlog${DTK_NAME_SUFFIX}) set(CMAKE_EXPORT_COMPILE_COMMANDS ON) find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Core) add_executable(${BIN_NAME} main.cpp ) target_link_libraries( ${BIN_NAME} PRIVATE Qt${QT_VERSION_MAJOR}::Core ${LIB_NAME} ) target_include_directories(${BIN_NAME} PUBLIC ../../include/ ) ``` -------------------------------- ### Standard Header for Free Software Source: https://github.com/linuxdeepin/dtkcore/blob/master/LICENSES/LGPL-3.0-or-later.txt Include this header at the beginning of each source file to provide copyright information and state that the program is free software distributed under the GNU GPL. ```text Copyright (C) This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . ``` -------------------------------- ### Configure DCI Executable Build Source: https://github.com/linuxdeepin/dtkcore/blob/master/tools/dci/CMakeLists.txt Defines the DCI executable, links necessary Qt Core libraries, and sets public include directories. Ensure Qt${QT_VERSION_MAJOR} is found and Core/CorePrivate components are available. ```cmake set(TARGET_NAME dci) set(BIN_NAME ${TARGET_NAME}${DTK_NAME_SUFFIX}) set(CMAKE_EXPORT_COMPILE_COMMANDS ON) find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Core) if(${QT_VERSION_MAJOR} EQUAL 6) if(${Qt6Core_VERSION} VERSION_GREATER_EQUAL 6.10.0) find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS CorePrivate) endif() endif() add_definitions(-DDTK_NO_PROJECT) # start dci include(../../src/dci/dci.cmake) add_executable(${BIN_NAME} ${dci_SRCS} main.cpp ) target_link_libraries(${BIN_NAME} PRIVATE Qt${QT_VERSION_MAJOR}::Core Qt${QT_VERSION_MAJOR}::CorePrivate ) target_include_directories(${BIN_NAME} PUBLIC ../../include/ ../../include/dci/ ../../include/DtkCore/ ../../include/base/ ../../include/global/ ) set_target_properties(${BIN_NAME} PROPERTIES OUTPUT_NAME ${TARGET_NAME}) #end dci install(TARGETS ${BIN_NAME} DESTINATION "${TOOL_INSTALL_DIR}") ``` -------------------------------- ### Link Libraries and Include Directories for Deepin OS Release Source: https://github.com/linuxdeepin/dtkcore/blob/master/tools/deepin-os-release/CMakeLists.txt Links the necessary Qt Core and CorePrivate libraries to the deepin-os-release executable. It also specifies public include directories for build-time interface, ensuring headers are accessible. ```cmake target_link_libraries(${BIN_NAME} PRIVATE Qt${QT_VERSION_MAJOR}::Core Qt${QT_VERSION_MAJOR}::CorePrivate ) target_include_directories(${BIN_NAME} PUBLIC $ $ $ $ $ $ ) ``` -------------------------------- ### Send Desktop Notifications with DNotifySender Source: https://context7.com/linuxdeepin/dtkcore/llms.txt Use DNotifySender to construct and send desktop notifications. It supports minimal and full configurations with various options like appName, appIcon, appBody, actions, and hints. The call() method sends the notification and returns a QDBusPendingCall. ```cpp #include #include DCORE_USE_NAMESPACE int main(int argc, char *argv[]) { QCoreApplication app(argc, argv); // Minimal notification DUtil::DNotifySender("Download complete").call(); // Full notification with all options QDBusPendingCall pending = DUtil::DNotifySender("Build Failed") .appName("MyIDE") .appIcon("dialog-error") // icon name or absolute path .appBody("main.cpp: undefined reference to 'foo'") .replaceId(0) // 0 = new notification; >0 = replace existing .timeOut(8000) // milliseconds; -1 = server default .actions({"_retry", "Retry", "_dismiss", "Dismiss"}) .hints({"urgency", 2}) // 0=low,1=normal,2=critical .call(); auto *w = new QDBusPendingCallWatcher(pending, &app); QObject::connect(w, &QDBusPendingCallWatcher::finished, [&app](QDBusPendingCallWatcher *watcher) { QDBusPendingReply reply = *watcher; if (!reply.isError()) qDebug() << "Notification ID:" << reply.value(); watcher->deleteLater(); app.quit(); }); return app.exec(); } ``` -------------------------------- ### Data Resource File (data.qrc) Source: https://github.com/linuxdeepin/dtkcore/blob/master/docs/settings/index.zh_CN.md A Qt Resource Collection file that includes the settings.json file, making it accessible within the application's resources. Ensure the path in the qrc file matches the actual file location. ```xml data/settings.json ``` -------------------------------- ### DLogManager: Configure and Use Structured Application Logging Source: https://context7.com/linuxdeepin/dtkcore/llms.txt Initialize DLogManager by registering appenders (console, file, journal) and optionally customizing log file paths and message formats. Supports DTK-specific logging macros and standard Qt logging. ```cpp #include // pulls in DLogManager + dDebug/dInfo/dWarning/dError macros #include DCORE_USE_NAMESPACE int main(int argc, char *argv[]) { QCoreApplication app(argc, argv); app.setApplicationName("com.example.myapp"); // Register appenders (order does not matter) #ifdef Q_OS_LINUX DLogManager::registerJournalAppender(); // systemd journal (Linux only) #endif DLogManager::registerConsoleAppender(); // stdout / stderr with color at TTY DLogManager::registerFileAppender(); // rolling file under ~/.cache// // Customise log file path (must be called before registerFileAppender if path matters) DLogManager::setlogFilePath("/var/log/myapp/app.log"); // Customise message format (%{time} %{type} [%{function}] %{message}) DLogManager::setLogFormat("%{time}{yyyy-MM-dd HH:mm:ss.zzz} [%{type:-7}] %{message}"); qDebug() << "Default Qt log goes through DLogManager too"; dDebug() << "Debug message from DtkCore macro"; dInfo() << "Application started, version 1.0"; dWarning() << "Low disk space detected"; dError() << "Failed to open config file"; // Measure a code block's wall-clock duration (prints on scope exit) { dDebugTime("Heavy initialisation"); // ... expensive setup ... } // Retrieve the current log file path qDebug() << "Log file:" << DLogManager::getlogFilePath(); // Expected output: "Log file: /var/log/myapp/app.log" return app.exec(); } ``` -------------------------------- ### Print System and Distribution Information with DSysInfo Source: https://context7.com/linuxdeepin/dtkcore/llms.txt Use DSysInfo to access details about the operating system, product type, version, edition, hardware, uptime, and distribution branding. This is useful for displaying system information in 'About' dialogs or for diagnostics. ```cpp #include #include DCORE_USE_NAMESPACE void printSystemInfo() { // Distribution identity qDebug() << "OS name:" << DSysInfo::operatingSystemName(); // "UnionTech OS Desktop 20 Pro" qDebug() << "Product type:" << DSysInfo::productTypeString(); // "Uos" qDebug() << "Product ver:" << DSysInfo::productVersion(); // "20" qDebug() << "Community ed.:" << DSysInfo::isCommunityEdition(); #ifdef Q_OS_LINUX // Deepin/UOS-specific info if (DSysInfo::isDeepin()) { qDebug() << "Deepin type:" << DSysInfo::deepinType(); // DeepinProfessional qDebug() << "Deepin ver:" << DSysInfo::deepinVersion(); // "20" qDebug() << "Major ver:" << DSysInfo::majorVersion(); qDebug() << "SP version:" << DSysInfo::spVersion(); // "SP1" qDebug() << "UOS edition:" << DSysInfo::uosEditionType(); // UosProfessional } if (DSysInfo::isDDE()) { qDebug() << "Running inside DDE (Deepin Desktop Environment)"; } #endif // Hardware qDebug() << "Computer:" << DSysInfo::computerName(); qDebug() << "CPU:" << DSysInfo::cpuModelName(); qDebug() << "RAM installed:" << DSysInfo::memoryInstalledSize() / (1024*1024*1024) << "GB"; qDebug() << "RAM available:" << DSysInfo::memoryTotalSize() / (1024*1024*1024) << "GB"; qDebug() << "Disk size:" << DSysInfo::systemDiskSize() / (1024*1024*1024) << "GB"; qDebug() << "Architecture:" << DSysInfo::arch(); // DSysInfo::X86_64 // Uptime / boot qDebug() << "Boot time:" << DSysInfo::bootTime().toString(Qt::ISODate); qDebug() << "Uptime (s):" << DSysInfo::uptime(); // Distribution branding (for About dialogs) qDebug() << "Distributor:" << DSysInfo::distributionOrgName(DSysInfo::Distributor); auto website = DSysInfo::distributionOrgWebsite(DSysInfo::Distribution); qDebug() << "Website:" << website.first << website.second; // ("Homepage", "https://www.deepin.org") qDebug() << "Logo path:" << DSysInfo::distributionOrgLogo(DSysInfo::Distribution, DSysInfo::Normal); } ``` -------------------------------- ### Chinese Pinyin Conversion with DPinyin Source: https://context7.com/linuxdeepin/dtkcore/llms.txt Use DPinyin for polyphonic-aware conversion of Chinese characters to pinyin. Supports tone marks, no tones, numeric tones, and first-letter extraction for search functionalities. Include `` and `` headers. ```cpp #include #include DCORE_USE_NAMESPACE int main() { // Simple (non-polyphonic) conversion QString simple = Chinese2Pinyin("中国"); qDebug() << "Simple pinyin:" << simple; // "zhōngguó" // Polyphonic-aware conversion bool ok = false; // Tone marks (default style) QStringList tone = pinyin("重要", TS_Tone, &ok); qDebug() << "With tone marks:" << tone << ok; // ["zhòngyào"] true // No tones QStringList noTone = pinyin("重要", TS_NoneTone, &ok); qDebug() << "Without tones:" << noTone; // ["zhongyao"] // Numeric tone style QStringList numTone = pinyin("中文", TS_ToneNum, &ok); qDebug() << "Numeric tones:" << numTone; // ["zhong1wen2"] // Extract first letters only (for search/index) QStringList initials = firstLetters("深圳市"); qDebug() << "First letters:" << initials; // ["szs"] (one per possible reading) QStringList initialsWithTone = firstLetters("深圳市", TS_ToneNum); qDebug() << "First letters (tone):" << initialsWithTone; return 0; } ``` -------------------------------- ### User Application Standard Paths Source: https://github.com/linuxdeepin/dtkcore/blob/master/docs/Specification.md Defines the standard directory paths for user-specific application data, logs, configurations, and cache files. These paths are relative to the user's home directory and follow the XDG Base Directory Specification. ```bash XGD_LOG_HOME_DEEPIN: Where deepin-user-specific log should be written. XGD_USER_HOME/.log DAPP_CONFIG_HOME: Where application-specific configurations should be written. XDG_CONFIG_HOME/{Organization-name}/{Application-name} DAPP_LOG_HOME: Where application-specific log should be written. XGD_LOG_HOME_DEEPIN/{Organization-name}/{Application-name} DAPP_CACHE_HOME: Where application-specific cache files should be written. XGD_CACHE_HOME/{Organization-name}/{Application-name} DAPP_DATA_HOME: Where application-specific data files should be written. $XDG_DATA_HOME/{Organization-name}/{Application-name} ``` ```bash DAPP_CONFIG_HOME: $HOME/.config/deepin/dde-dock DAPP_LOG_HOME: $HOME/.log/deepin/dde-dock DAPP_CACHE_HOME: $HOME/.cache/deepin/dde-dock DAPP_DATA_HOME: $HOME/.local/share/deepin/dde-dock ``` -------------------------------- ### System Application Standard Paths Source: https://github.com/linuxdeepin/dtkcore/blob/master/docs/Specification.md Defines the standard directory paths for system-wide application data, logs, and configurations. These paths are typically used for system daemons or applications running without a dedicated user home directory. ```bash DAPP_CONFIG_SYS: /etc/{Organization-name}/{Application-name} DAPP_LOG_SYS: /var/log/{Organization-name}/{Application-name} DAPP_DATA_SYS: /usr/share/{Organization-name}/{Application-name} DAPP_CACHE_SYS: /var/cache/{Organization-name}/{Application-name} ``` -------------------------------- ### Settings JSON Structure Source: https://github.com/linuxdeepin/dtkcore/blob/master/docs/settings/index.zh_CN.md Defines application settings with groups and options, including types like checkbox and combobox, and default values. This JSON file is typically loaded by DSettings. ```json { "groups": [{ "key": "base", "name": "Basic settings", "groups": [{ "key": "open_action", "name": "Open Action", "options": [{ "key": "alway_open_on_new", "type": "checkbox", "text": "Always Open On New Windows", "default": true }, { "key": "open_file_action", "name": "Open File:", "type": "combobox", "default": "" } ] }, { "key": "new_tab_windows", "name": "New Tab & Window", "options": [{ "key": "new_window_path", "name": "New Window Open:", "type": "combobox", "default": "" }, { "key": "new_tab_path", "name": "New Tab Open:", "type": "combobox", "default": "" } ] } ] }] } ``` -------------------------------- ### Define Deepin OS Release Source Files and Executable Source: https://github.com/linuxdeepin/dtkcore/blob/master/tools/deepin-os-release/CMakeLists.txt Defines the source files for the deepin-os-release executable, including header and source files for dsysinfo and ddesktopentry, along with the main entry point. It also adds a public compile definition for DSYSINFO_PREFIX. ```cmake add_definitions(-DDTK_NO_PROJECT) # start dci set(dci_SRCS ../../include/global/dsysinfo.h ../../include/global/ddesktopentry.h ../../src/dsysinfo.cpp ../../src/ddesktopentry.cpp ) add_executable(${BIN_NAME} ${dci_SRCS} main.cpp ) target_compile_definitions(${BIN_NAME} PUBLIC DSYSINFO_PREFIX="${DSYSINFO_PREFIX}") ``` -------------------------------- ### Fluent D-Bus Method Calls with DDBusSender Source: https://context7.com/linuxdeepin/dtkcore/llms.txt Utilize DDBusSender for chainable, asynchronous D-Bus method calls and property operations. Supports session and system buses. Requires ``, ``, ``, and ``. ```cpp #include #include #include #include int main(int argc, char *argv[]) { QCoreApplication app(argc, argv); // --- Call a method on the session bus --- QDBusPendingCall call = DDBusSender() .service("org.freedesktop.Notifications") .path("/org/freedesktop/Notifications") .interface("org.freedesktop.Notifications") .method("Notify") .arg(QString("myapp")) // app_name .arg(uint(0)) // replaces_id .arg(QString("dialog-info"))// app_icon .arg(QString("Hello")) // summary .arg(QString("World")) // body .arg(QStringList()) // actions .arg(QVariantMap()) // hints .arg(int(5000)) // expire_timeout .call(); auto *watcher = new QDBusPendingCallWatcher(call, &app); QObject::connect(watcher, &QDBusPendingCallWatcher::finished, [](QDBusPendingCallWatcher *w) { QDBusPendingReply reply = *w; if (reply.isError()) qWarning() << "D-Bus error:" << reply.error().message(); else qDebug() << "Notification id:" << reply.value(); w->deleteLater(); }); // --- Call a method on the system bus --- QDBusPendingCall sysBusCall = DDBusSender::system() .service("org.freedesktop.NetworkManager") .path("/org/freedesktop/NetworkManager") .interface("org.freedesktop.NetworkManager") .method("GetAllDevices") .call(); // --- Get a D-Bus property --- QDBusPendingCall getProp = DDBusSender() .service("org.freedesktop.NetworkManager") .path("/org/freedesktop/NetworkManager") .interface("org.freedesktop.NetworkManager") .property("Version") .get(); // --- Set a D-Bus property --- QDBusPendingCall setProp = DDBusSender() .service("com.example.Service") .path("/com/example/Service") .interface("com.example.Service") .property("Enabled") .set(true); return app.exec(); } ```