diff -Nru dtkcore-5.5.33/archlinux/PKGBUILD dtkcore-5.6.2/archlinux/PKGBUILD --- dtkcore-5.5.33/archlinux/PKGBUILD 2022-07-19 09:10:28.000000000 +0000 +++ dtkcore-5.6.2/archlinux/PKGBUILD 2022-09-21 05:21:07.000000000 +0000 @@ -7,24 +7,27 @@ url="https://github.com/linuxdeepin/dtkcore" license=('LGPL3') depends=('dconf' 'deepin-desktop-base-git' 'python' 'gsettings-qt' 'lshw') -makedepends=('git' 'qt5-tools' 'gtest' 'dtkcommon-git') +makedepends=('git' 'qt5-tools' 'dtkcommon-git' 'ninja' 'cmake' 'doxygen') conflicts=('dtkcore') provides=('dtkcore') groups=('deepin-git') source=('source.tar.gz') sha512sums=('SKIP') -prepare() { - cd $deepin_source_name -} - build() { cd $deepin_source_name - qmake-qt5 PREFIX=/usr DTK_VERSION=$pkgver LIB_INSTALL_DIR=/usr/lib - make + cmake -GNinja \ + -DMKSPECS_INSTALL_DIR=/usr/lib/qt/mkspecs/modules/\ + -DBUILD_DOCS=ON \ + -DBUILD_EXAMPLES=OFF \ + -DQCH_INSTALL_DESTINATION=/usr/share/doc/qt \ + -DCMAKE_INSTALL_LIBDIR=/usr/lib \ + -DCMAKE_INSTALL_PREFIX=/usr \ + -DCMAKE_BUILD_TYPE=Release + ninja } package() { cd $deepin_source_name - make INSTALL_ROOT="$pkgdir" install + DESTDIR="$pkgdir" ninja install } diff -Nru dtkcore-5.5.33/cmake/DtkCMake/DtkCMakeConfig.cmake dtkcore-5.6.2/cmake/DtkCMake/DtkCMakeConfig.cmake --- dtkcore-5.5.33/cmake/DtkCMake/DtkCMakeConfig.cmake 2022-07-19 09:10:28.000000000 +0000 +++ dtkcore-5.6.2/cmake/DtkCMake/DtkCMakeConfig.cmake 2022-09-21 05:21:07.000000000 +0000 @@ -8,7 +8,7 @@ find_package(DtkCore REQUIRED) -set(DEEPIN_OS_RELEASE_TOOL_PATH ${DTKCORE_TOOL_DIR}) +set(DEEPIN_OS_RELEASE_TOOL_PATH ${DtkCore_TOOL_DIR}) set(DEEPIN_OS_RELEASE_TOOL ${DEEPIN_OS_RELEASE_TOOL_PATH}/deepin-os-release) if(NOT EXISTS "${DEEPIN_OS_RELEASE_TOOL}") diff -Nru dtkcore-5.5.33/cmake/DtkTools/DtkToolsConfig.cmake dtkcore-5.6.2/cmake/DtkTools/DtkToolsConfig.cmake --- dtkcore-5.5.33/cmake/DtkTools/DtkToolsConfig.cmake 2022-07-19 09:10:28.000000000 +0000 +++ dtkcore-5.6.2/cmake/DtkTools/DtkToolsConfig.cmake 2022-09-21 05:21:07.000000000 +0000 @@ -1,6 +1,6 @@ find_package(DtkCore REQUIRED) -set (DTK_SETTINGS_TOOLS_EXECUTABLE ${DTKCORE_TOOL_DIR}/dtk-settings) +set (DTK_SETTINGS_TOOLS_EXECUTABLE ${DtkCore_TOOL_DIR}/dtk-settings) if (EXISTS ${DTK_SETTINGS_TOOLS_EXECUTABLE}) set(DTK_SETTINGS_TOOLS_FOUND TRUE) diff -Nru dtkcore-5.5.33/CMakeLists.txt dtkcore-5.6.2/CMakeLists.txt --- dtkcore-5.5.33/CMakeLists.txt 2022-07-19 09:10:28.000000000 +0000 +++ dtkcore-5.6.2/CMakeLists.txt 2022-09-21 05:21:07.000000000 +0000 @@ -1,16 +1,99 @@ cmake_minimum_required (VERSION 3.10) +set (DVERSION "5.6.0.2" CACHE STRING "define project version") + project (DtkCore - VERSION "${DTK_REPO_MODULE_VERSION}" - DESCRIPTION "DTK Core module" - HOMEPAGE_URL "" - LANGUAGES CXX C + VERSION ${DVERSION} + DESCRIPTION "DTK Core module" + HOMEPAGE_URL "https://github.com/linuxdeepin/dtkcore" + LANGUAGES CXX C ) +message(STATUS ${PROJECT_VERSION}) + +include(GNUInstallDirs) +include(CMakePackageConfigHelpers) + +if (CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) + set(CMAKE_INSTALL_PREFIX /usr) +endif () +set (INCLUDE_INSTALL_DIR "${CMAKE_INSTALL_FULL_INCLUDEDIR}/libdtk-${CMAKE_PROJECT_VERSION}/DCore") +set (TOOL_INSTALL_DIR "${CMAKE_INSTALL_FULL_LIBDIR}/libdtk-${PROJECT_VERSION}/DCore/bin") +set (MKSPECS_INSTALL_DIR "${CMAKE_INSTALL_FULL_LIBDIR}/qt5/mkspecs/modules" CACHE STRING "INSTALL DIR FOR qt pri files") -find_package (Qt5 CONFIG REQUIRED COMPONENTS DBus Xml) +set (BUILD_EXAMPLES ON CACHE BOOL "Build examples") +option(BUILD_VERSION "buildversion" "0") +if(NOT BUILD_VERSION) + set(BUILD_VERSION "0") +endif() +if(UNIX AND NOT APPLE) + set(LINUX TRUE) +endif() set (BUILD_DOCS ON CACHE BOOL "Generate doxygen-based documentation") +# CXX FILAGS +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC -Wall -Wextra") +set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--as-needed") +if (CMAKE_BUILD_TYPE STREQUAL "Debug") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O0 -g -fsanitize=address -fno-omit-frame-pointer") + set(BUILD_TESTING ON) +else () + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Ofast") +endif () + if (BUILD_DOCS) - add_subdirectory(doc) + add_subdirectory(docs) endif () + +add_subdirectory(src) +if(BUILD_TESTING) + message("==================================") + message(" Now Testing is enabled ") + message("==================================") + enable_testing() + add_subdirectory(tests) +endif() +if(BUILD_EXAMPLES) + message("===================================") + message("You can build and run examples now ") + message("===================================") + add_subdirectory(examples) +endif() +add_subdirectory(tools) +install(FILES cmake/DtkCMake/DtkCMakeConfig.cmake DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/DtkCMake/") +install(FILES cmake/DtkTools/DtkToolsConfig.cmake DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/DtkTools") +install(FILES cmake/DtkTools/DtkSettingsToolsMacros.cmake DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/DtkTools") + +configure_package_config_file(misc/DtkConfig.cmake.in + ${CMAKE_CURRENT_BINARY_DIR}/DtkCoreConfig.cmake + INSTALL_DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/DtkCore" + PATH_VARS INCLUDE_INSTALL_DIR TOOL_INSTALL_DIR) +write_basic_package_version_file( + "${CMAKE_CURRENT_BINARY_DIR}/DtkCoreConfigVersion.cmake" + VERSION ${DVERSION} + COMPATIBILITY SameMajorVersion +) +install(FILES ${CMAKE_CURRENT_BINARY_DIR}/DtkCoreConfig.cmake DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/DtkCore") +install(FILES ${CMAKE_CURRENT_BINARY_DIR}/DtkCoreConfigVersion.cmake DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/DtkCore") + +configure_file(misc/dtkcore.pc.in dtkcore.pc @ONLY) +install(FILES ${CMAKE_CURRENT_BINARY_DIR}/dtkcore.pc DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig") + +configure_file(misc/qt_lib_dtkcore.pri.in qt_lib_dtkcore.pri @ONLY) +install(FILES ${CMAKE_CURRENT_BINARY_DIR}/qt_lib_dtkcore.pri DESTINATION "${MKSPECS_INSTALL_DIR}") +set(CONFIGNAME include/global/dtkcore_config.h) +file(WRITE ${CONFIGNAME} + "// it is auto make config\n" + "#define DTK_VERSION_MAJOR ${PROJECT_VERSION_MAJOR}\n" + "#define DTK_VERSION_MINOR ${PROJECT_VERSION_MINOR}\n" + "#define DTK_VERSION_PATCH ${PROJECT_VERSION_PATCH}\n" + "#define DTK_VERSION_BUILD ${BUILD_VERSION}\n" + "#define DTK_VERSION_STR \"${PROJECT_VERSION}\"\n" + "\n" +) +file(GLOB CONFIGSOURCE include/DtkCore/*) + +foreach(FILENAME ${CONFIGSOURCE}) + get_filename_component(thefile ${FILENAME} NAME) + file(APPEND ${CONFIGNAME} "#define DTKCORE_CLASS_${thefile}\n") +endforeach() diff -Nru dtkcore-5.5.33/conanfile.py dtkcore-5.6.2/conanfile.py --- dtkcore-5.5.33/conanfile.py 2022-07-19 09:10:28.000000000 +0000 +++ dtkcore-5.6.2/conanfile.py 2022-09-21 05:21:07.000000000 +0000 @@ -1,3 +1,7 @@ +# SPDX-FileCopyrightText: 2022 UnionTech Software Technology Co., Ltd. +# +# SPDX-License-Identifier: LGPL-3.0-or-later + from conans import ConanFile, tools diff -Nru dtkcore-5.5.33/debian/changelog dtkcore-5.6.2/debian/changelog --- dtkcore-5.5.33/debian/changelog 2022-09-17 06:59:38.000000000 +0000 +++ dtkcore-5.6.2/debian/changelog 2022-10-04 18:47:54.000000000 +0000 @@ -1,14 +1,8 @@ -dtkcore (5.5.33-1ubuntu2) kinetic; urgency=medium +dtkcore (5.6.2-1) kinetic; urgency=medium - * No-change rebuild against Qt 5.15.6. + * Upload to kinetic. - -- Dmitry Shachnev Sat, 17 Sep 2022 09:59:38 +0300 - -dtkcore (5.5.33-1ubuntu1) kinetic; urgency=medium - - * Again make new build time tests non fatal. - - -- Rik Mills Wed, 10 Aug 2022 05:29:48 +0100 + -- Arun Kumar Pariyar Wed, 05 Oct 2022 00:32:54 +0545 dtkcore (5.5.33-1) unstable; urgency=medium diff -Nru dtkcore-5.5.33/debian/control dtkcore-5.6.2/debian/control --- dtkcore-5.5.33/debian/control 2022-08-02 05:14:06.000000000 +0000 +++ dtkcore-5.6.2/debian/control 2022-10-04 18:47:54.000000000 +0000 @@ -10,14 +10,16 @@ Clay Stan , Hu Feng , Build-Depends: + cmake, debhelper-compat (= 13), + doxygen, + libdtkcommon-dev, libgsettings-qt-dev, + libgtest-dev, pkg-config, pkg-kde-tools, qtbase5-private-dev, qttools5-dev-tools, - libgtest-dev, - libdtkcommon-dev, Rules-Requires-Root: no Standards-Version: 4.6.1 Homepage: https://github.com/linuxdeepin/dtkcore @@ -29,8 +31,8 @@ Section: libdevel Multi-Arch: same Depends: - libdtkcore5 (= ${binary:Version}), libdtkcommon-dev, + libdtkcore5 (= ${binary:Version}), ${misc:Depends}, Breaks: libdtkwidget-dev (<< 5.2.2.10-1), diff -Nru dtkcore-5.5.33/debian/libdtkcore5-bin.install dtkcore-5.6.2/debian/libdtkcore5-bin.install --- dtkcore-5.5.33/debian/libdtkcore5-bin.install 2022-08-02 05:10:50.000000000 +0000 +++ dtkcore-5.6.2/debian/libdtkcore5-bin.install 2022-10-04 18:47:54.000000000 +0000 @@ -1,2 +1,2 @@ -usr/lib/*/*/DCore/bin/* usr/bin/* +usr/lib/*/*/DCore/bin/* diff -Nru dtkcore-5.5.33/debian/libdtkcore-dev.docs dtkcore-5.6.2/debian/libdtkcore-dev.docs --- dtkcore-5.5.33/debian/libdtkcore-dev.docs 2022-08-02 05:10:50.000000000 +0000 +++ dtkcore-5.6.2/debian/libdtkcore-dev.docs 2022-10-04 18:47:54.000000000 +0000 @@ -1,2 +1 @@ README.md -doc/Specification.md diff -Nru dtkcore-5.5.33/debian/libdtkcore-dev.install dtkcore-5.6.2/debian/libdtkcore-dev.install --- dtkcore-5.5.33/debian/libdtkcore-dev.install 2022-08-02 05:10:50.000000000 +0000 +++ dtkcore-5.6.2/debian/libdtkcore-dev.install 2022-10-04 18:47:54.000000000 +0000 @@ -1,5 +1,5 @@ -usr/lib/*/lib*.so usr/include -usr/lib/*/pkgconfig/*.pc usr/lib/*/cmake/*/*.cmake +usr/lib/*/lib*.so +usr/lib/*/pkgconfig/*.pc usr/lib/*/qt5/* diff -Nru dtkcore-5.5.33/debian/rules dtkcore-5.6.2/debian/rules --- dtkcore-5.5.33/debian/rules 2022-08-10 04:29:14.000000000 +0000 +++ dtkcore-5.6.2/debian/rules 2022-10-04 18:47:54.000000000 +0000 @@ -18,13 +18,10 @@ include /usr/share/dpkg/default.mk %: - dh $@ --buildsystem=qmake --with pkgkde_symbolshelper + dh $@ --with pkgkde_symbolshelper override_dh_auto_configure: - dh_auto_configure -- LIB_INSTALL_DIR=/usr/lib/$(DEB_HOST_MULTIARCH) VERSION=$(DEB_VERSION_UPSTREAM) - -override_dh_auto_test: - -dh_auto_test + dh_auto_configure -- -DBUILD_EXAMPLES=OFF -DBUILD_DOCS=OFF -DLIB_INSTALL_DIR=/usr/lib/$(DEB_HOST_MULTIARCH) -DVERSION=$(DEB_VERSION_UPSTREAM) override_dh_installchangelogs: dh_installchangelogs -k CHANGELOG.md diff -Nru dtkcore-5.5.33/doc/CMakeLists.txt dtkcore-5.6.2/doc/CMakeLists.txt --- dtkcore-5.5.33/doc/CMakeLists.txt 2022-07-19 09:10:28.000000000 +0000 +++ dtkcore-5.6.2/doc/CMakeLists.txt 1970-01-01 00:00:00.000000000 +0000 @@ -1,38 +0,0 @@ -cmake_minimum_required (VERSION 3.10) - -find_package (Doxygen REQUIRED) - -set (QCH_INSTALL_DESTINATION ${CMAKE_INSTALLL_PREFIX}/share/DDE/dtk CACHE STRING "QCH install location") - -set (DOXYGEN_GENERATE_HTML "NO" CACHE STRING "Doxygen HTML output") -set (DOXYGEN_GENERATE_XML "NO" CACHE STRING "Doxygen XML output") -set (DOXYGEN_GENERATE_QHP "YES" CACHE STRING "Doxygen QHP output") -set (DOXYGEN_FILE_PATTERNS *.cpp *.h *.md *.zh_CN.dox CACHE STRING "Doxygen File Patterns") -set (DOXYGEN_PROJECT_NUMBER ${CMAKE_PROJECT_VERSION} CACHE STRING "") # Should be the same as this project is using. -set (DOXYGEN_EXTRACT_STATIC YES) -set (DOXYGEN_OUTPUT_LANGUAGE "Chinese") -set (DOXYGEN_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/docs/) -set (DOXYGEN_QHG_LOCATION "qhelpgenerator") -set (DOXYGEN_QHP_NAMESPACE "org.deepin.dtk.core") -set (DOXYGEN_QCH_FILE "dtkcore.qch") -set (DOXYGEN_QHP_VIRTUAL_FOLDER "dtkcore") -set (DOXYGEN_HTML_EXTRA_STYLESHEET "" CACHE STRING "Doxygen custom stylesheet for HTML output") -set (DOXYGEN_TAGFILES "qtcore.tags=qthelp://org.qt-project.qtcore/qtcore/" CACHE STRING "Doxygen tag files") - -set (DOXYGEN_PREDEFINED - "\"DCORE_BEGIN_NAMESPACE=namespace Dtk { namespace Core {\"" - "\"DCORE_END_NAMESPACE=}}\"" - "\"DCORE_USE_NAMESPACE=using Dtk::Core\"" -) -set (DOXYGEN_MACRO_EXPANSION "YES") -set (DOXYGEN_EXPAND_ONLY_PREDEF "YES") - -doxygen_add_docs (doxygen - ${PROJECT_SOURCE_DIR}/src - ${PROJECT_SOURCE_DIR}/doc - ALL - WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} - COMMENT "Generate documentation via Doxygen" -) - -install (FILES ${PROJECT_BINARY_DIR}/docs/html/dtkcore.qch DESTINATION ${QCH_INSTALL_DESTINATION}) diff -Nru dtkcore-5.5.33/doc/Specification.md dtkcore-5.6.2/doc/Specification.md --- dtkcore-5.5.33/doc/Specification.md 2022-07-19 09:10:28.000000000 +0000 +++ dtkcore-5.6.2/doc/Specification.md 1970-01-01 00:00:00.000000000 +0000 @@ -1,81 +0,0 @@ -# Deepin Application Specification {#Specification} - -Every application should keep the rule in this document. - -## 1. Application Information - -Application should set the property Organization-name and Application-name. - -Organization/Application name can contains alphabet, number and other visible ASCII code, BUT space MUST NOT appear in the name. And we do not approve -of no-ASCII code character in the Organization/Application name - -Application can stay Organization-name empty, but it should always set an Application-name. - -## 2. Standard Path - -The log, configure and runtime cache of Application should store in specific path. - -**If Organization-name is empty, "{Organization-name}/" would not appear in path.** - -### 2.1 User Application Standard Path - -As an application run for user session, the Standard path should be: - -````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} - -```` - -Simple example: - -The dde-dock is offcial application of deepin and the standard path will be: - -````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 -```` - -### 2.2 System Application Standard Path - -Application run as system daemon, or with user with no home directory should place it's file in this standard path: - -````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} -```` - - -Refs: - -[XDG Base Directory Specification](https://specifications.freedesktop.org/basedir-spec/basedir-spec-0.8.html) - -[XDG Base Directory support](https://wiki.archlinux.org/index.php/XDG_Base_Directory_support) diff -Nru dtkcore-5.5.33/doc/src/dtkcore-index.qdoc dtkcore-5.6.2/doc/src/dtkcore-index.qdoc --- dtkcore-5.5.33/doc/src/dtkcore-index.qdoc 2022-07-19 09:10:28.000000000 +0000 +++ dtkcore-5.6.2/doc/src/dtkcore-index.qdoc 1970-01-01 00:00:00.000000000 +0000 @@ -1,37 +0,0 @@ -/* - * Copyright (C) 2021 ~ 2021 Deepin Technology Co., Ltd. - * - * Author: Chen Bin - * - * Maintainer: Chen Bin - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * 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 Lesser General Public License - * along with this program. If not, see . - */ - -/*! -\page dtkcore-index.html - -\keyword DTK Core Reference Documentation -\title DTK Core Docs - -Deepint Tool Kit (Dtk) is the base development tool of all C++/Qt Developer work on Deepin. - -\list -\li \l {DTK Gui Docs} -\li \l {DTK Gui 模块} -\li \l {DTK Core 模块} -\li \l {DTK Widget Docs} -\li \l {DTK Widget 模块} -\endlist -*/ diff -Nru dtkcore-5.5.33/doc/src/dtkcore.qdoc dtkcore-5.6.2/doc/src/dtkcore.qdoc --- dtkcore-5.5.33/doc/src/dtkcore.qdoc 2022-07-19 09:10:28.000000000 +0000 +++ dtkcore-5.6.2/doc/src/dtkcore.qdoc 1970-01-01 00:00:00.000000000 +0000 @@ -1,29 +0,0 @@ -/* - * Copyright (C) 2021 ~ 2021 Deepin Technology Co., Ltd. - * - * Author: Chen Bin - * - * Maintainer: Chen Bin - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * 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 Lesser General Public License - * along with this program. If not, see . - */ - -/*! - \module dtkcore - \title DTK Core 模块 - - \brief Deepin Tool Kit Core Devel library. - - DtkCore is base devel library of Deepin Qt/C++ applications. -*/ diff -Nru dtkcore-5.5.33/docs/CMakeLists.txt dtkcore-5.6.2/docs/CMakeLists.txt --- dtkcore-5.5.33/docs/CMakeLists.txt 1970-01-01 00:00:00.000000000 +0000 +++ dtkcore-5.6.2/docs/CMakeLists.txt 2022-09-21 05:21:07.000000000 +0000 @@ -0,0 +1,38 @@ +cmake_minimum_required (VERSION 3.10) + +find_package (Doxygen REQUIRED) + +set (QCH_INSTALL_DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/qt5/doc CACHE STRING "QCH install location") + +set (DOXYGEN_GENERATE_HTML YES CACHE STRING "Doxygen HTML output") +set (DOXYGEN_GENERATE_XML YES CACHE STRING "Doxygen XML output") +set (DOXYGEN_GENERATE_QHP YES CACHE STRING "Doxygen QHP output") +set (DOXYGEN_FILE_PATTERNS *.cpp *.h *.zh_CN.md *.zh_CN.dox CACHE STRING "Doxygen File Patterns") +set (DOXYGEN_PROJECT_NUMBER ${CMAKE_PROJECT_VERSION} CACHE STRING "") # Should be the same as this project is using. +set (DOXYGEN_EXTRACT_STATIC YES) +set (DOXYGEN_OUTPUT_LANGUAGE "Chinese") +set (DOXYGEN_QHG_LOCATION "qhelpgenerator") +set (DOXYGEN_QHP_NAMESPACE "org.deepin.dtk.core") +set (DOXYGEN_QCH_FILE "dtkcore.qch") +set (DOXYGEN_QHP_VIRTUAL_FOLDER "dtkcore") +set (DOXYGEN_HTML_EXTRA_STYLESHEET "" CACHE STRING "Doxygen custom stylesheet for HTML output") +set (DOXYGEN_TAGFILES "qtcore.tags=qthelp://org.qt-project.qtcore/qtcore/" CACHE STRING "Doxygen tag files") + +set (DOXYGEN_PREDEFINED + "\"DCORE_BEGIN_NAMESPACE=namespace Dtk { namespace Core {\"" + "\"DCORE_END_NAMESPACE=}}\"" + "\"DCORE_USE_NAMESPACE=using namespace Dtk::Core\;\"" +) +set (DOXYGEN_MACRO_EXPANSION "YES") +set (DOXYGEN_EXPAND_ONLY_PREDEF "YES") + +doxygen_add_docs (doxygen + ${PROJECT_SOURCE_DIR}/src + ${PROJECT_SOURCE_DIR}/include + ${PROJECT_SOURCE_DIR}/docs + ALL + WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} + COMMENT "Generate documentation via Doxygen" +) + +install (FILES ${PROJECT_BINARY_DIR}/docs/html/dtkcore.qch DESTINATION ${QCH_INSTALL_DESTINATION}) diff -Nru dtkcore-5.5.33/docs/Specification.md dtkcore-5.6.2/docs/Specification.md --- dtkcore-5.5.33/docs/Specification.md 1970-01-01 00:00:00.000000000 +0000 +++ dtkcore-5.6.2/docs/Specification.md 2022-09-21 05:21:07.000000000 +0000 @@ -0,0 +1,81 @@ +# Deepin Application Specification {#Specification} + +Every application should keep the rule in this document. + +## 1. Application Information + +Application should set the property Organization-name and Application-name. + +Organization/Application name can contains alphabet, number and other visible ASCII code, BUT space MUST NOT appear in the name. And we do not approve +of no-ASCII code character in the Organization/Application name + +Application can stay Organization-name empty, but it should always set an Application-name. + +## 2. Standard Path + +The log, configure and runtime cache of Application should store in specific path. + +**If Organization-name is empty, "{Organization-name}/" would not appear in path.** + +### 2.1 User Application Standard Path + +As an application run for user session, the Standard path should be: + +````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} + +```` + +Simple example: + +The dde-dock is offcial application of deepin and the standard path will be: + +````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 +```` + +### 2.2 System Application Standard Path + +Application run as system daemon, or with user with no home directory should place it's file in this standard path: + +````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} +```` + + +Refs: + +[XDG Base Directory Specification](https://specifications.freedesktop.org/basedir-spec/basedir-spec-0.8.html) + +[XDG Base Directory support](https://wiki.archlinux.org/index.php/XDG_Base_Directory_support) diff -Nru dtkcore-5.5.33/docs/src/dtkcore-index.qdoc dtkcore-5.6.2/docs/src/dtkcore-index.qdoc --- dtkcore-5.5.33/docs/src/dtkcore-index.qdoc 1970-01-01 00:00:00.000000000 +0000 +++ dtkcore-5.6.2/docs/src/dtkcore-index.qdoc 2022-09-21 05:21:07.000000000 +0000 @@ -0,0 +1,20 @@ +// SPDX-FileCopyrightText: 2021 - 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later + +/*! +\page dtkcore-index.html + +\keyword DTK Core Reference Documentation +\title DTK Core Docs + +Deepint Tool Kit (Dtk) is the base development tool of all C++/Qt Developer work on Deepin. + +\list +\li \l {DTK Gui Docs} +\li \l {DTK Gui 模块} +\li \l {DTK Core 模块} +\li \l {DTK Widget Docs} +\li \l {DTK Widget 模块} +\endlist +*/ diff -Nru dtkcore-5.5.33/docs/src/dtkcore.qdoc dtkcore-5.6.2/docs/src/dtkcore.qdoc --- dtkcore-5.5.33/docs/src/dtkcore.qdoc 1970-01-01 00:00:00.000000000 +0000 +++ dtkcore-5.6.2/docs/src/dtkcore.qdoc 2022-09-21 05:21:07.000000000 +0000 @@ -0,0 +1,12 @@ +// SPDX-FileCopyrightText: 2021 - 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later + +/*! + \module dtkcore + \title DTK Core 模块 + + \brief Deepin Tool Kit Core Devel library. + + DtkCore is base devel library of Deepin Qt/C++ applications. +*/ diff -Nru dtkcore-5.5.33/dtkcore.pro dtkcore-5.6.2/dtkcore.pro --- dtkcore-5.5.33/dtkcore.pro 2022-07-19 09:10:28.000000000 +0000 +++ dtkcore-5.6.2/dtkcore.pro 1970-01-01 00:00:00.000000000 +0000 @@ -1 +0,0 @@ -load(dtk_lib) diff -Nru dtkcore-5.5.33/examples/CMakeLists.txt dtkcore-5.6.2/examples/CMakeLists.txt --- dtkcore-5.5.33/examples/CMakeLists.txt 1970-01-01 00:00:00.000000000 +0000 +++ dtkcore-5.6.2/examples/CMakeLists.txt 2022-09-21 05:21:07.000000000 +0000 @@ -0,0 +1,2 @@ +add_subdirectory(dasync-example) +add_subdirectory(expintf-example) diff -Nru dtkcore-5.5.33/examples/dasync-example/CMakeLists.txt dtkcore-5.6.2/examples/dasync-example/CMakeLists.txt --- dtkcore-5.5.33/examples/dasync-example/CMakeLists.txt 1970-01-01 00:00:00.000000000 +0000 +++ dtkcore-5.6.2/examples/dasync-example/CMakeLists.txt 2022-09-21 05:21:07.000000000 +0000 @@ -0,0 +1,21 @@ +set(BINNAME dasync) +set(CMAKE_EXPORT_COMPILE_COMMANDS ON) +find_package(Qt5 REQUIRED COMPONENTS Widgets) +find_package(Qt5 REQUIRED COMPONENTS Core) + +add_executable(${BINNAME} + main.cpp +) + +target_link_libraries( + ${BINNAME} PRIVATE + Qt5::Core + Qt5::Widgets + dtkcore + -lpthread +) +target_include_directories(${BINNAME} PUBLIC + ../../include/global/ + ../../include/util/ + ../../include/ +) diff -Nru dtkcore-5.5.33/examples/dasync-example/dasync-example.pro dtkcore-5.6.2/examples/dasync-example/dasync-example.pro --- dtkcore-5.5.33/examples/dasync-example/dasync-example.pro 2022-07-19 09:10:28.000000000 +0000 +++ dtkcore-5.6.2/examples/dasync-example/dasync-example.pro 1970-01-01 00:00:00.000000000 +0000 @@ -1,48 +0,0 @@ -###################################################################### -# Automatically generated by qmake (3.1) Thu Aug 19 09:48:31 2021 -###################################################################### - -TEMPLATE = app -TARGET = thread_util -INCLUDEPATH += . -QT+= core widgets testlib - -CONFIG += c++11 -# The following define makes your compiler warn you if you use any -# feature of Qt which has been marked as deprecated (the exact warnings -# depend on your compiler). Please consult the documentation of the -# deprecated API in order to know how to port your code away from it. -DEFINES += QT_DEPRECATED_WARNINGS - -CONFIG(debug, debug|release) { - LIBS += -lgtest -lgmock - QMAKE_CXXFLAGS += -g -Wall -fprofile-arcs -ftest-coverage -fsanitize=address -fsanitize-recover=address -O2 - QMAKE_LFLAGS += -g -Wall -fprofile-arcs -ftest-coverage -fsanitize=address -fsanitize-recover=address -O2 - QMAKE_CXX += -g -fprofile-arcs -ftest-coverage -fsanitize=address -fsanitize-recover=address -O2 -} - -LIBS += -pthread -QMAKE_CXXFLAGS += -pthread - -#QMAKE_CXXFLAGS_RELEASE += -fvisibility=hidden -#DEFINES += LIBDTKCORE_LIBRARY - -# You can also make your code fail to compile if you use deprecated APIs. -# In order to do so, uncomment the following line. -# You can also select to disable deprecated APIs only up to a certain version of Qt. -#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 - -INCLUDEPATH += $$PWD/../../src -INCLUDEPATH += $$PWD/../../src/base -INCLUDEPATH += $$PWD/../../src/util - -# Input -HEADERS += \ - $${PWD}/../../src/dtkcore_global.h \ - $${PWD}/../../src/util/dasync.h \ - $${PWD}/../../src/util/dthreadutils.h - -SOURCES += \ - $${PWD}/../../src/util/dthreadutils.cpp \ - main.cpp - diff -Nru dtkcore-5.5.33/examples/dasync-example/main.cpp dtkcore-5.6.2/examples/dasync-example/main.cpp --- dtkcore-5.5.33/examples/dasync-example/main.cpp 2022-07-19 09:10:28.000000000 +0000 +++ dtkcore-5.6.2/examples/dasync-example/main.cpp 2022-09-21 05:21:07.000000000 +0000 @@ -1,23 +1,7 @@ -/* - * Copyright (C) 2021 ~ 2021 UnionTech Technology Co., Ltd. - * - * Author: Wang Peng <993381@qq.com> - * - * Maintainer: Wang Peng - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * 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 Lesser General Public License - * along with this program. If not, see . - */ +// SPDX-FileCopyrightText: 2021 - 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later + #include #include #include diff -Nru dtkcore-5.5.33/examples/examples.pro dtkcore-5.6.2/examples/examples.pro --- dtkcore-5.5.33/examples/examples.pro 2022-07-19 09:10:28.000000000 +0000 +++ dtkcore-5.6.2/examples/examples.pro 1970-01-01 00:00:00.000000000 +0000 @@ -1,4 +0,0 @@ -TEMPLATE = subdirs -SUBDIRS += expintf-example -SUBDIRS += dasync-example - diff -Nru dtkcore-5.5.33/examples/expintf-example/CMakeLists.txt dtkcore-5.6.2/examples/expintf-example/CMakeLists.txt --- dtkcore-5.5.33/examples/expintf-example/CMakeLists.txt 1970-01-01 00:00:00.000000000 +0000 +++ dtkcore-5.6.2/examples/expintf-example/CMakeLists.txt 2022-09-21 05:21:07.000000000 +0000 @@ -0,0 +1,19 @@ +set(BINNAME exprintf) +set(CMAKE_EXPORT_COMPILE_COMMANDS ON) +find_package(Qt5 REQUIRED COMPONENTS DBus) + +add_executable(${BINNAME} + main.cpp +) + +target_link_libraries( + ${BINNAME} PRIVATE + Qt5::DBus + dtkcore +) +target_include_directories(${BINNAME} PUBLIC + ../../include/base + ../../include/base/private/ + ../../include/filesystem/ + ../../include/ +) diff -Nru dtkcore-5.5.33/examples/expintf-example/expintf-example.pro dtkcore-5.6.2/examples/expintf-example/expintf-example.pro --- dtkcore-5.5.33/examples/expintf-example/expintf-example.pro 2022-07-19 09:10:28.000000000 +0000 +++ dtkcore-5.6.2/examples/expintf-example/expintf-example.pro 1970-01-01 00:00:00.000000000 +0000 @@ -1,16 +0,0 @@ -TEMPLATE = app -QT += dbus - -SOURCES += \ - $$PWD/main.cpp - -win32:CONFIG(release, debug|release): LIBS += -L$$OUT_PWD/../../src/release -ldtkcore -else:win32:CONFIG(debug, debug|release): LIBS += -L$$OUT_PWD/../../src/debug -ldtkcore -else:unix: LIBS += -L$$OUT_PWD/../../src -ldtkcore - -INCLUDEPATH += $$PWD/../../src -INCLUDEPATH += $$PWD/../../src/base - -CONFIG(debug, debug|release) { - unix:QMAKE_RPATHDIR += $$OUT_PWD/../../src -} diff -Nru dtkcore-5.5.33/examples/expintf-example/main.cpp dtkcore-5.6.2/examples/expintf-example/main.cpp --- dtkcore-5.5.33/examples/expintf-example/main.cpp 2022-07-19 09:10:28.000000000 +0000 +++ dtkcore-5.6.2/examples/expintf-example/main.cpp 2022-09-21 05:21:07.000000000 +0000 @@ -1,23 +1,6 @@ -/* - * Copyright (C) 2017 ~ 2019 Deepin Technology Co., Ltd. - * - * Author: Chris Xiong - * - * Maintainer: Chris Xiong - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * 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 Lesser General Public License - * along with this program. If not, see . - */ +// SPDX-FileCopyrightText: 2017 - 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later #include "util/dexportedinterface.h" diff -Nru dtkcore-5.5.33/.github/workflows/backup-to-gitlab.yml dtkcore-5.6.2/.github/workflows/backup-to-gitlab.yml --- dtkcore-5.5.33/.github/workflows/backup-to-gitlab.yml 2022-07-19 09:10:28.000000000 +0000 +++ dtkcore-5.6.2/.github/workflows/backup-to-gitlab.yml 2022-09-21 05:21:07.000000000 +0000 @@ -6,47 +6,12 @@ cancel-in-progress: true jobs: - backup-to-gitlab: - if: github.repository_owner == 'linuxdeepin' - name: backup-to-gitlab - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - with: - repository: "linuxdeepin/jenkins-bridge-client" - path: jenkins-bridge-client - - - name: Install Client - run: | - cd $GITHUB_WORKSPACE/jenkins-bridge-client - go build . - sudo install -Dvm755 jenkins-bridge-client -t /usr/bin/ - - name: Trigger sync - id: generate-runid - run: | - echo "::set-output name=RUN_ID::$(jenkins-bridge-client -triggerSync -token '${{ secrets.BRIDGETOKEN }}')" - - name: Print log - run: | - jenkins-bridge-client -printlog -token "${{ secrets.BRIDGETOKEN }}" -runid "${{ steps.generate-runid.outputs.RUN_ID }}" + backup-to-gitlabwh: + uses: linuxdeepin/.github/.github/workflows/backup-to-gitlabwh.yml@master + secrets: + BRIDGETOKEN: ${{ secrets.BRIDGETOKEN }} backup-to-gitee: - if: github.repository_owner == 'linuxdeepin' - runs-on: ubuntu-latest - steps: - - name: create-repo - run: | - repo=${{ github.event.repository.name }} - homepage="https://github.com/linuxdeepin/${repo}" - description="mirror of ${homepage}" - # remove '.' prefix - repo=${repo#"."} - curl -X POST --header 'Content-Type: application/json;charset=UTF-8' 'https://gitee.com/api/v5/enterprises/linuxdeepin/repos' -d '{"private": 1,"access_token":"${{ secrets.GITEE_SYNC_TOKEN }}","name":"'"$repo"'","description":"'"$description"'","homepage":"'"$homepage"'","has_issues":"false","has_wiki":"false","can_comment":"false"}' || true - - name: push - run: | - git clone --bare https://github.com/linuxdeepin/${{ github.event.repository.name }}.git .git - repo=${{ github.event.repository.name }} - # remove '.' prefix - repo=${repo#"."} - git remote set-url origin https://myml:${{ secrets.GITEE_SYNC_TOKEN }}@gitee.com/linuxdeepin/${repo}.git - git push -f --all --prune origin - git push --tags origin + uses: linuxdeepin/.github/.github/workflows/backup-to-gitee.yml@master + secrets: + GITEE_SYNC_TOKEN: ${{ secrets.GITEE_SYNC_TOKEN }} diff -Nru dtkcore-5.5.33/.github/workflows/call-build-deb.yml dtkcore-5.6.2/.github/workflows/call-build-deb.yml --- dtkcore-5.5.33/.github/workflows/call-build-deb.yml 2022-07-19 09:10:28.000000000 +0000 +++ dtkcore-5.6.2/.github/workflows/call-build-deb.yml 2022-09-21 05:21:07.000000000 +0000 @@ -3,6 +3,7 @@ pull_request_target: paths-ignore: - ".github/workflows/**" + types: [ opened, closed, synchronize ] concurrency: group: ${{ github.workflow }}-pull/${{ github.event.number }} @@ -10,6 +11,7 @@ jobs: check_job: + if: github.event.action != 'closed' || github.event.pull_request.merged uses: linuxdeepin/.github/.github/workflows/build-deb.yml@master secrets: BridgeToken: ${{ secrets.BridgeToken }} diff -Nru dtkcore-5.5.33/.github/workflows/call-doc-check.yml dtkcore-5.6.2/.github/workflows/call-doc-check.yml --- dtkcore-5.5.33/.github/workflows/call-doc-check.yml 1970-01-01 00:00:00.000000000 +0000 +++ dtkcore-5.6.2/.github/workflows/call-doc-check.yml 2022-09-21 05:21:07.000000000 +0000 @@ -0,0 +1,15 @@ +name: doxygen-check +on: + pull_request_target: + paths-ignore: + - ".github/workflows/**" + +concurrency: + group: ${{ github.workflow }}-pull/${{ github.event.number }} + cancel-in-progress: true + +jobs: + check_job: + uses: linuxdeepin/.github/.github/workflows/doc-check.yml@master + secrets: + APP_PRIVATE_KEY: ${{ secrets.APP_PRIVATE_KEY }} diff -Nru dtkcore-5.5.33/.github/workflows/call-license-check.yml dtkcore-5.6.2/.github/workflows/call-license-check.yml --- dtkcore-5.5.33/.github/workflows/call-license-check.yml 1970-01-01 00:00:00.000000000 +0000 +++ dtkcore-5.6.2/.github/workflows/call-license-check.yml 2022-09-21 05:21:07.000000000 +0000 @@ -0,0 +1,16 @@ +name: Call License and README Check +on: + pull_request_target: + types: [opened, synchronize, reopened] + +permissions: + pull-requests: write + contents: read + +concurrency: + group: ${{ github.workflow }}-pull/${{ github.event.number }} + cancel-in-progress: true + +jobs: + license-check: + uses: linuxdeepin/.github/.github/workflows/license-check.yml@master diff -Nru dtkcore-5.5.33/.gitignore dtkcore-5.6.2/.gitignore --- dtkcore-5.5.33/.gitignore 2022-07-19 09:10:28.000000000 +0000 +++ dtkcore-5.6.2/.gitignore 2022-09-21 05:21:07.000000000 +0000 @@ -3,6 +3,7 @@ *.lo *.o + # Compiled Dynamic libraries *.so *.dylib @@ -29,3 +30,9 @@ Makefile cmake/DtkCore* +.cache +DtkCoreConfig.cmake +dtkcore.pc +qt_lib_dtkcore.pri +dtkcore_config.h +CMakeLists.txt.user diff -Nru dtkcore-5.5.33/include/base/dobject.h dtkcore-5.6.2/include/base/dobject.h --- dtkcore-5.5.33/include/base/dobject.h 1970-01-01 00:00:00.000000000 +0000 +++ dtkcore-5.6.2/include/base/dobject.h 2022-09-21 05:21:07.000000000 +0000 @@ -0,0 +1,41 @@ +// SPDX-FileCopyrightText: 2015 - 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later + +#ifndef DOBJECT_H +#define DOBJECT_H + +#include + +#include "dtkcore_global.h" + +DCORE_BEGIN_NAMESPACE + +#define D_DECLARE_PRIVATE(Class) Q_DECLARE_PRIVATE_D(qGetPtrHelper(d_d_ptr),Class) +#define D_DECLARE_PUBLIC(Class) Q_DECLARE_PUBLIC(Class) +#define D_D(Class) Q_D(Class) +#define D_Q(Class) Q_Q(Class) +#define D_DC(Class) Q_D(const Class) +#define D_QC(Class) Q_Q(const Class) +#define D_PRIVATE_SLOT(Func) Q_PRIVATE_SLOT(d_func(), Func) + +class DObjectPrivate; + +class LIBDTKCORESHARED_EXPORT DObject +{ +protected: + DObject(DObject *parent = nullptr); + + DObject(DObjectPrivate &dd, DObject *parent = nullptr); + + virtual ~DObject(); + + QScopedPointer d_d_ptr; + + Q_DISABLE_COPY(DObject) + D_DECLARE_PRIVATE(DObject) +}; + +DCORE_END_NAMESPACE + +#endif // DOBJECT_H diff -Nru dtkcore-5.5.33/include/base/dsingleton.h dtkcore-5.6.2/include/base/dsingleton.h --- dtkcore-5.5.33/include/base/dsingleton.h 1970-01-01 00:00:00.000000000 +0000 +++ dtkcore-5.6.2/include/base/dsingleton.h 2022-09-21 05:21:07.000000000 +0000 @@ -0,0 +1,72 @@ +// SPDX-FileCopyrightText: 2016 - 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later + +#ifndef DSINGLETON_H +#define DSINGLETON_H + +#include "dtkcore_global.h" + +DCORE_BEGIN_NAMESPACE + +/*! + a simple singleton template for std c++ 11 or later. + + example: + + \code + class ExampleSingleton : public QObject, public Dtk::DSingleton + { + Q_OBJECT + friend class DSingleton; + }; + \endcode + + \note: for Qt, "public DSingleton" must be after QObject. + */ + +/*! + 通过c++11的特性实现的单例模板 + + 使用示例: + +``` + class ExampleSingleton : public QObject, public Dtk::DSingleton + { + Q_OBJECT + friend class DSingleton; + }; +``` + + \note 对于Qt程序 public DSingleton" 必须在卸载QObject后面出现。 + */ + +template +class LIBDTKCORESHARED_EXPORT DSingleton +{ +public: + QT_DEPRECATED_X("Use ref") + static inline T *instance() + { + static T *_instance = new T; + return _instance; + } + + static T& ref() + { + static T instance; + return instance; + } + + DSingleton(T&&) = delete; + DSingleton(const T&) = delete; + void operator= (const T&) = delete; + +protected: + DSingleton() = default; + virtual ~DSingleton() = default; +}; + +DCORE_END_NAMESPACE + +#endif // DSINGLETON_H diff -Nru dtkcore-5.5.33/include/base/private/dobject_p.h dtkcore-5.6.2/include/base/private/dobject_p.h --- dtkcore-5.5.33/include/base/private/dobject_p.h 1970-01-01 00:00:00.000000000 +0000 +++ dtkcore-5.6.2/include/base/private/dobject_p.h 2022-09-21 05:21:07.000000000 +0000 @@ -0,0 +1,29 @@ +// SPDX-FileCopyrightText: 2015 - 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later + +#ifndef DOBJECT_P_H +#define DOBJECT_P_H + +#include "dtkcore_global.h" + +DCORE_BEGIN_NAMESPACE + +class DObject; +class LIBDTKCORESHARED_EXPORT DObjectPrivate +{ +public: + virtual ~DObjectPrivate(); + +protected: + DObjectPrivate(DObject *qq); + + DObject *q_ptr; + + Q_DECLARE_PUBLIC(DObject) +}; + +DCORE_END_NAMESPACE + +#endif // DOBJECT_P_H + diff -Nru dtkcore-5.5.33/include/dci/ddcifile.h dtkcore-5.6.2/include/dci/ddcifile.h --- dtkcore-5.5.33/include/dci/ddcifile.h 1970-01-01 00:00:00.000000000 +0000 +++ dtkcore-5.6.2/include/dci/ddcifile.h 2022-09-21 05:21:07.000000000 +0000 @@ -0,0 +1,73 @@ +// SPDX-FileCopyrightText: 2021 - 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later + +#pragma once + +#ifndef DTK_NO_PROJECT +#include +#include +#else +#define DCORE_BEGIN_NAMESPACE +#define DCORE_END_NAMESPACE +#define LIBDTKCORESHARED_EXPORT +#define D_DECLARE_PRIVATE(Class) Class##Private *d; +#endif + +#include + +QT_BEGIN_HEADER +class QIODevice; +QT_END_NAMESPACE + +DCORE_BEGIN_NAMESPACE + +class DDciFilePrivate; +class LIBDTKCORESHARED_EXPORT DDciFile +#ifndef DTK_NO_PROJECT + : public DObject +#endif +{ + D_DECLARE_PRIVATE(DDciFile) +public: + enum FileType { + UnknowFile, + File = 1, + Directory = 2, + Symlink = 3 + }; + + static void registerFileEngine(); + + DDciFile(); + explicit DDciFile(const QString &fileName); + explicit DDciFile(const QByteArray &data); + + bool isValid() const; + QString lastErrorString() const; + + bool writeToFile(const QString &fileName) const; + bool writeToDevice(QIODevice *device) const; + QByteArray toData() const; + + static constexpr int metadataSizeV1(); + + // for reader + QStringList list(const QString &dir, bool onlyFileName = false) const; + int childrenCount(const QString &dir) const; + bool exists(const QString &filePath) const; + FileType type(const QString &filePath) const; + QByteArray dataRef(const QString &filePath) const; + QString name(const QString &filePath) const; + QString symlinkTarget(const QString &filePath, bool originData = false) const; + + // for writer + bool mkdir(const QString &filePath); + bool writeFile(const QString &filePath, const QByteArray &data, bool override = false); + bool remove(const QString &filePath); + bool rename(const QString &filePath, const QString &newFilePath, bool override = false); + bool copy(const QString &from, const QString &to); + bool link(const QString &source, const QString &to); +}; + +DCORE_END_NAMESPACE diff -Nru dtkcore-5.5.33/include/DtkCore/DAbstractUnitFormatter dtkcore-5.6.2/include/DtkCore/DAbstractUnitFormatter --- dtkcore-5.5.33/include/DtkCore/DAbstractUnitFormatter 1970-01-01 00:00:00.000000000 +0000 +++ dtkcore-5.6.2/include/DtkCore/DAbstractUnitFormatter 2022-09-21 05:21:07.000000000 +0000 @@ -0,0 +1 @@ +#include "dabstractunitformatter.h" diff -Nru dtkcore-5.5.33/include/DtkCore/DBaseFileWatcher dtkcore-5.6.2/include/DtkCore/DBaseFileWatcher --- dtkcore-5.5.33/include/DtkCore/DBaseFileWatcher 1970-01-01 00:00:00.000000000 +0000 +++ dtkcore-5.6.2/include/DtkCore/DBaseFileWatcher 2022-09-21 05:21:07.000000000 +0000 @@ -0,0 +1 @@ +#include "dbasefilewatcher.h" diff -Nru dtkcore-5.5.33/include/DtkCore/DCapDir dtkcore-5.6.2/include/DtkCore/DCapDir --- dtkcore-5.5.33/include/DtkCore/DCapDir 1970-01-01 00:00:00.000000000 +0000 +++ dtkcore-5.6.2/include/DtkCore/DCapDir 2022-09-21 05:21:07.000000000 +0000 @@ -0,0 +1 @@ +#include "dcapfile.h" diff -Nru dtkcore-5.5.33/include/DtkCore/DCapFile dtkcore-5.6.2/include/DtkCore/DCapFile --- dtkcore-5.5.33/include/DtkCore/DCapFile 1970-01-01 00:00:00.000000000 +0000 +++ dtkcore-5.6.2/include/DtkCore/DCapFile 2022-09-21 05:21:07.000000000 +0000 @@ -0,0 +1 @@ +#include "dcapfile.h" diff -Nru dtkcore-5.5.33/include/DtkCore/DCapManager dtkcore-5.6.2/include/DtkCore/DCapManager --- dtkcore-5.5.33/include/DtkCore/DCapManager 1970-01-01 00:00:00.000000000 +0000 +++ dtkcore-5.6.2/include/DtkCore/DCapManager 2022-09-21 05:21:07.000000000 +0000 @@ -0,0 +1 @@ +#include "dcapmanager.h" diff -Nru dtkcore-5.5.33/include/DtkCore/DConfig dtkcore-5.6.2/include/DtkCore/DConfig --- dtkcore-5.5.33/include/DtkCore/DConfig 1970-01-01 00:00:00.000000000 +0000 +++ dtkcore-5.6.2/include/DtkCore/DConfig 2022-09-21 05:21:07.000000000 +0000 @@ -0,0 +1 @@ +#include "dconfig.h" diff -Nru dtkcore-5.5.33/include/DtkCore/DConfigFile dtkcore-5.6.2/include/DtkCore/DConfigFile --- dtkcore-5.5.33/include/DtkCore/DConfigFile 1970-01-01 00:00:00.000000000 +0000 +++ dtkcore-5.6.2/include/DtkCore/DConfigFile 2022-09-21 05:21:07.000000000 +0000 @@ -0,0 +1 @@ +#include "dconfigfile.h" diff -Nru dtkcore-5.5.33/include/DtkCore/DDBusInterface dtkcore-5.6.2/include/DtkCore/DDBusInterface --- dtkcore-5.5.33/include/DtkCore/DDBusInterface 1970-01-01 00:00:00.000000000 +0000 +++ dtkcore-5.6.2/include/DtkCore/DDBusInterface 2022-09-21 05:21:07.000000000 +0000 @@ -0,0 +1 @@ +#include "ddbusinterface.h" diff -Nru dtkcore-5.5.33/include/DtkCore/DDBusSender dtkcore-5.6.2/include/DtkCore/DDBusSender --- dtkcore-5.5.33/include/DtkCore/DDBusSender 1970-01-01 00:00:00.000000000 +0000 +++ dtkcore-5.6.2/include/DtkCore/DDBusSender 2022-09-21 05:21:07.000000000 +0000 @@ -0,0 +1 @@ +#include "ddbussender.h" diff -Nru dtkcore-5.5.33/include/DtkCore/DDciFile dtkcore-5.6.2/include/DtkCore/DDciFile --- dtkcore-5.5.33/include/DtkCore/DDciFile 1970-01-01 00:00:00.000000000 +0000 +++ dtkcore-5.6.2/include/DtkCore/DDciFile 2022-09-21 05:21:07.000000000 +0000 @@ -0,0 +1 @@ +#include "ddcifile.h" diff -Nru dtkcore-5.5.33/include/DtkCore/DDesktopEntry dtkcore-5.6.2/include/DtkCore/DDesktopEntry --- dtkcore-5.5.33/include/DtkCore/DDesktopEntry 1970-01-01 00:00:00.000000000 +0000 +++ dtkcore-5.6.2/include/DtkCore/DDesktopEntry 2022-09-21 05:21:07.000000000 +0000 @@ -0,0 +1 @@ +#include "ddesktopentry.h" diff -Nru dtkcore-5.5.33/include/DtkCore/DDiskSizeFormatter dtkcore-5.6.2/include/DtkCore/DDiskSizeFormatter --- dtkcore-5.5.33/include/DtkCore/DDiskSizeFormatter 1970-01-01 00:00:00.000000000 +0000 +++ dtkcore-5.6.2/include/DtkCore/DDiskSizeFormatter 2022-09-21 05:21:07.000000000 +0000 @@ -0,0 +1 @@ +#include "ddisksizeformatter.h" diff -Nru dtkcore-5.5.33/include/DtkCore/DExportedInterface dtkcore-5.6.2/include/DtkCore/DExportedInterface --- dtkcore-5.5.33/include/DtkCore/DExportedInterface 1970-01-01 00:00:00.000000000 +0000 +++ dtkcore-5.6.2/include/DtkCore/DExportedInterface 2022-09-21 05:21:07.000000000 +0000 @@ -0,0 +1 @@ +#include "dexportedinterface.h" diff -Nru dtkcore-5.5.33/include/DtkCore/DFileServices dtkcore-5.6.2/include/DtkCore/DFileServices --- dtkcore-5.5.33/include/DtkCore/DFileServices 1970-01-01 00:00:00.000000000 +0000 +++ dtkcore-5.6.2/include/DtkCore/DFileServices 2022-09-21 05:21:07.000000000 +0000 @@ -0,0 +1 @@ +#include "dfileservices.h" diff -Nru dtkcore-5.5.33/include/DtkCore/DFileSystemWatcher dtkcore-5.6.2/include/DtkCore/DFileSystemWatcher --- dtkcore-5.5.33/include/DtkCore/DFileSystemWatcher 1970-01-01 00:00:00.000000000 +0000 +++ dtkcore-5.6.2/include/DtkCore/DFileSystemWatcher 2022-09-21 05:21:07.000000000 +0000 @@ -0,0 +1 @@ +#include "dfilesystemwatcher.h" diff -Nru dtkcore-5.5.33/include/DtkCore/DFileWatcher dtkcore-5.6.2/include/DtkCore/DFileWatcher --- dtkcore-5.5.33/include/DtkCore/DFileWatcher 1970-01-01 00:00:00.000000000 +0000 +++ dtkcore-5.6.2/include/DtkCore/DFileWatcher 2022-09-21 05:21:07.000000000 +0000 @@ -0,0 +1 @@ +#include "dfilewatcher.h" diff -Nru dtkcore-5.5.33/include/DtkCore/DFileWatcherManager dtkcore-5.6.2/include/DtkCore/DFileWatcherManager --- dtkcore-5.5.33/include/DtkCore/DFileWatcherManager 1970-01-01 00:00:00.000000000 +0000 +++ dtkcore-5.6.2/include/DtkCore/DFileWatcherManager 2022-09-21 05:21:07.000000000 +0000 @@ -0,0 +1 @@ +#include "dfilewatchermanager.h" diff -Nru dtkcore-5.5.33/include/DtkCore/DLog dtkcore-5.6.2/include/DtkCore/DLog --- dtkcore-5.5.33/include/DtkCore/DLog 1970-01-01 00:00:00.000000000 +0000 +++ dtkcore-5.6.2/include/DtkCore/DLog 2022-09-21 05:21:07.000000000 +0000 @@ -0,0 +1,8 @@ +#include "CuteLogger_global.h" +#include "RollingFileAppender.h" +#include "Logger.h" +#include "LogManager.h" +#include "FileAppender.h" +#include "ConsoleAppender.h" +#include "AbstractStringAppender.h" +#include "AbstractAppender.h" diff -Nru dtkcore-5.5.33/include/DtkCore/DNotifySender dtkcore-5.6.2/include/DtkCore/DNotifySender --- dtkcore-5.5.33/include/DtkCore/DNotifySender 1970-01-01 00:00:00.000000000 +0000 +++ dtkcore-5.6.2/include/DtkCore/DNotifySender 2022-09-21 05:21:07.000000000 +0000 @@ -0,0 +1 @@ +#include "dnotifysender.h" diff -Nru dtkcore-5.5.33/include/DtkCore/DObject dtkcore-5.6.2/include/DtkCore/DObject --- dtkcore-5.5.33/include/DtkCore/DObject 1970-01-01 00:00:00.000000000 +0000 +++ dtkcore-5.6.2/include/DtkCore/DObject 2022-09-21 05:21:07.000000000 +0000 @@ -0,0 +1 @@ +#include "dobject.h" diff -Nru dtkcore-5.5.33/include/DtkCore/DObjectPrivate dtkcore-5.6.2/include/DtkCore/DObjectPrivate --- dtkcore-5.5.33/include/DtkCore/DObjectPrivate 1970-01-01 00:00:00.000000000 +0000 +++ dtkcore-5.6.2/include/DtkCore/DObjectPrivate 2022-09-21 05:21:07.000000000 +0000 @@ -0,0 +1 @@ +#include "dobject_p.h" diff -Nru dtkcore-5.5.33/include/DtkCore/DPathBuf dtkcore-5.6.2/include/DtkCore/DPathBuf --- dtkcore-5.5.33/include/DtkCore/DPathBuf 1970-01-01 00:00:00.000000000 +0000 +++ dtkcore-5.6.2/include/DtkCore/DPathBuf 2022-09-21 05:21:07.000000000 +0000 @@ -0,0 +1 @@ +#include "dpathbuf.h" diff -Nru dtkcore-5.5.33/include/DtkCore/DPinyin dtkcore-5.6.2/include/DtkCore/DPinyin --- dtkcore-5.5.33/include/DtkCore/DPinyin 1970-01-01 00:00:00.000000000 +0000 +++ dtkcore-5.6.2/include/DtkCore/DPinyin 2022-09-21 05:21:07.000000000 +0000 @@ -0,0 +1 @@ +#include "dpinyin.h" diff -Nru dtkcore-5.5.33/include/DtkCore/DRecentManager dtkcore-5.6.2/include/DtkCore/DRecentManager --- dtkcore-5.5.33/include/DtkCore/DRecentManager 1970-01-01 00:00:00.000000000 +0000 +++ dtkcore-5.6.2/include/DtkCore/DRecentManager 2022-09-21 05:21:07.000000000 +0000 @@ -0,0 +1 @@ +#include "drecentmanager.h" diff -Nru dtkcore-5.5.33/include/DtkCore/DSecureString dtkcore-5.6.2/include/DtkCore/DSecureString --- dtkcore-5.5.33/include/DtkCore/DSecureString 1970-01-01 00:00:00.000000000 +0000 +++ dtkcore-5.6.2/include/DtkCore/DSecureString 2022-09-21 05:21:07.000000000 +0000 @@ -0,0 +1 @@ +#include "dsecurestring.h" diff -Nru dtkcore-5.5.33/include/DtkCore/DSettings dtkcore-5.6.2/include/DtkCore/DSettings --- dtkcore-5.5.33/include/DtkCore/DSettings 1970-01-01 00:00:00.000000000 +0000 +++ dtkcore-5.6.2/include/DtkCore/DSettings 2022-09-21 05:21:07.000000000 +0000 @@ -0,0 +1 @@ +#include "dsettings.h" diff -Nru dtkcore-5.5.33/include/DtkCore/DSettingsGroup dtkcore-5.6.2/include/DtkCore/DSettingsGroup --- dtkcore-5.5.33/include/DtkCore/DSettingsGroup 1970-01-01 00:00:00.000000000 +0000 +++ dtkcore-5.6.2/include/DtkCore/DSettingsGroup 2022-09-21 05:21:07.000000000 +0000 @@ -0,0 +1 @@ +#include "dsettingsgroup.h" diff -Nru dtkcore-5.5.33/include/DtkCore/DSettingsOption dtkcore-5.6.2/include/DtkCore/DSettingsOption --- dtkcore-5.5.33/include/DtkCore/DSettingsOption 1970-01-01 00:00:00.000000000 +0000 +++ dtkcore-5.6.2/include/DtkCore/DSettingsOption 2022-09-21 05:21:07.000000000 +0000 @@ -0,0 +1 @@ +#include "dsettingsoption.h" diff -Nru dtkcore-5.5.33/include/DtkCore/DSGApplication dtkcore-5.6.2/include/DtkCore/DSGApplication --- dtkcore-5.5.33/include/DtkCore/DSGApplication 1970-01-01 00:00:00.000000000 +0000 +++ dtkcore-5.6.2/include/DtkCore/DSGApplication 2022-09-21 05:21:07.000000000 +0000 @@ -0,0 +1 @@ +#include "dsgapplication.h" diff -Nru dtkcore-5.5.33/include/DtkCore/DSingleton dtkcore-5.6.2/include/DtkCore/DSingleton --- dtkcore-5.5.33/include/DtkCore/DSingleton 1970-01-01 00:00:00.000000000 +0000 +++ dtkcore-5.6.2/include/DtkCore/DSingleton 2022-09-21 05:21:07.000000000 +0000 @@ -0,0 +1 @@ +#include "dsingleton.h" diff -Nru dtkcore-5.5.33/include/DtkCore/DStandardPaths dtkcore-5.6.2/include/DtkCore/DStandardPaths --- dtkcore-5.5.33/include/DtkCore/DStandardPaths 1970-01-01 00:00:00.000000000 +0000 +++ dtkcore-5.6.2/include/DtkCore/DStandardPaths 2022-09-21 05:21:07.000000000 +0000 @@ -0,0 +1 @@ +#include "dstandardpaths.h" diff -Nru dtkcore-5.5.33/include/DtkCore/DSysInfo dtkcore-5.6.2/include/DtkCore/DSysInfo --- dtkcore-5.5.33/include/DtkCore/DSysInfo 1970-01-01 00:00:00.000000000 +0000 +++ dtkcore-5.6.2/include/DtkCore/DSysInfo 2022-09-21 05:21:07.000000000 +0000 @@ -0,0 +1 @@ +#include "dsysinfo.h" diff -Nru dtkcore-5.5.33/include/DtkCore/DThreadUtils dtkcore-5.6.2/include/DtkCore/DThreadUtils --- dtkcore-5.5.33/include/DtkCore/DThreadUtils 1970-01-01 00:00:00.000000000 +0000 +++ dtkcore-5.6.2/include/DtkCore/DThreadUtils 2022-09-21 05:21:07.000000000 +0000 @@ -0,0 +1 @@ +#include "dthreadutils.h" diff -Nru dtkcore-5.5.33/include/DtkCore/DTimeUnitFormatter dtkcore-5.6.2/include/DtkCore/DTimeUnitFormatter --- dtkcore-5.5.33/include/DtkCore/DTimeUnitFormatter 1970-01-01 00:00:00.000000000 +0000 +++ dtkcore-5.6.2/include/DtkCore/DTimeUnitFormatter 2022-09-21 05:21:07.000000000 +0000 @@ -0,0 +1 @@ +#include "dtimeunitformatter.h" diff -Nru dtkcore-5.5.33/include/DtkCore/DtkCores dtkcore-5.6.2/include/DtkCore/DtkCores --- dtkcore-5.5.33/include/DtkCore/DtkCores 1970-01-01 00:00:00.000000000 +0000 +++ dtkcore-5.6.2/include/DtkCore/DtkCores 2022-09-21 05:21:07.000000000 +0000 @@ -0,0 +1,44 @@ +#ifndef DTK_CORE_MODULE_H +#define DTK_CORE_MODULE_H +#include "dtkcore_global.h" +#include "dconfigfile.h" +#include "dobject.h" +#include "dsingleton.h" +#include "dutil.h" +#include "dpinyin.h" +#include "dtimeunitformatter.h" +#include "dabstractunitformatter.h" +#include "ddisksizeformatter.h" +#include "ddbussender.h" +#include "drecentmanager.h" +#include "dnotifysender.h" +#include "dexportedinterface.h" +#include "dvtablehook.h" +#include "dfileservices.h" +#include "dthreadutils.h" +#include "dasync.h" +#include "dtimedloop.h" +#include "RollingFileAppender.h" +#include "Logger.h" +#include "FileAppender.h" +#include "CuteLogger_global.h" +#include "ConsoleAppender.h" +#include "AbstractStringAppender.h" +#include "AbstractAppender.h" +#include "LogManager.h" +#include "dbasefilewatcher.h" +#include "dfilesystemwatcher.h" +#include "dfilewatcher.h" +#include "dfilewatchermanager.h" +#include "dpathbuf.h" +#include "dstandardpaths.h" +#include "dtrashmanager.h" +#include "gsettingsbackend.h" +#include "qsettingbackend.h" +#include "dsettings.h" +#include "dsettingsoption.h" +#include "dsettingsgroup.h" +#include "dsettingsbackend.h" +#include "dsettingsdconfigbackend.h" +#include "ddcifile.h" +#endif diff -Nru dtkcore-5.5.33/include/DtkCore/DTrashManager dtkcore-5.6.2/include/DtkCore/DTrashManager --- dtkcore-5.5.33/include/DtkCore/DTrashManager 1970-01-01 00:00:00.000000000 +0000 +++ dtkcore-5.6.2/include/DtkCore/DTrashManager 2022-09-21 05:21:07.000000000 +0000 @@ -0,0 +1 @@ +#include "dtrashmanager.h" diff -Nru dtkcore-5.5.33/include/DtkCore/DUtil dtkcore-5.6.2/include/DtkCore/DUtil --- dtkcore-5.5.33/include/DtkCore/DUtil 1970-01-01 00:00:00.000000000 +0000 +++ dtkcore-5.6.2/include/DtkCore/DUtil 2022-09-21 05:21:07.000000000 +0000 @@ -0,0 +1 @@ +#include "dutil.h" diff -Nru dtkcore-5.5.33/include/DtkCore/DVtableHook dtkcore-5.6.2/include/DtkCore/DVtableHook --- dtkcore-5.5.33/include/DtkCore/DVtableHook 1970-01-01 00:00:00.000000000 +0000 +++ dtkcore-5.6.2/include/DtkCore/DVtableHook 2022-09-21 05:21:07.000000000 +0000 @@ -0,0 +1 @@ +#include "dvtablehook.h" diff -Nru dtkcore-5.5.33/include/filesystem/dbasefilewatcher.h dtkcore-5.6.2/include/filesystem/dbasefilewatcher.h --- dtkcore-5.5.33/include/filesystem/dbasefilewatcher.h 1970-01-01 00:00:00.000000000 +0000 +++ dtkcore-5.6.2/include/filesystem/dbasefilewatcher.h 2022-09-21 05:21:07.000000000 +0000 @@ -0,0 +1,54 @@ +// SPDX-FileCopyrightText: 2017 - 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later + +#ifndef DBASEFILEWATCHER_H +#define DBASEFILEWATCHER_H + +#include "dtkcore_global.h" +#include "dobject.h" + +#include + +DCORE_BEGIN_NAMESPACE + +class DBaseFileWatcherPrivate; +class LIBDTKCORESHARED_EXPORT DBaseFileWatcher : public QObject, public DObject +{ + Q_OBJECT + +public: + ~DBaseFileWatcher(); + + QUrl fileUrl() const; + + bool startWatcher(); + bool stopWatcher(); + bool restartWatcher(); + + virtual void setEnabledSubfileWatcher(const QUrl &subfileUrl, bool enabled = true); + + using SignalType1 = void(DBaseFileWatcher::*)(const QUrl &); + using SignalType2 = void(DBaseFileWatcher::*)(const QUrl &, const QUrl &); + static bool ghostSignal(const QUrl &targetUrl, SignalType1 signal, const QUrl &arg1); + static bool ghostSignal(const QUrl &targetUrl, SignalType2 signal, const QUrl &arg1, const QUrl &arg2); + +Q_SIGNALS: + void fileDeleted(const QUrl &url); + void fileAttributeChanged(const QUrl &url); + void fileMoved(const QUrl &fromUrl, const QUrl &toUrl); + void subfileCreated(const QUrl &url); + void fileModified(const QUrl &url); + void fileClosed(const QUrl &url); + +protected: + explicit DBaseFileWatcher(DBaseFileWatcherPrivate &dd, const QUrl &url, QObject *parent = 0); + +private: + Q_DISABLE_COPY(DBaseFileWatcher) + D_DECLARE_PRIVATE(DBaseFileWatcher) +}; + +DCORE_END_NAMESPACE + +#endif // DBASEFILEWATCHER_H diff -Nru dtkcore-5.5.33/include/filesystem/dcapfile.h dtkcore-5.6.2/include/filesystem/dcapfile.h --- dtkcore-5.5.33/include/filesystem/dcapfile.h 1970-01-01 00:00:00.000000000 +0000 +++ dtkcore-5.6.2/include/filesystem/dcapfile.h 2022-09-21 05:21:07.000000000 +0000 @@ -0,0 +1,105 @@ +// SPDX-FileCopyrightText: 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later + +#ifndef DCAPFILE_H +#define DCAPFILE_H + +#include + +#include +#include +#include + +DCORE_BEGIN_NAMESPACE + +class DCapFilePrivate; +class DCapFile : public QFile, public DObject +{ + Q_OBJECT + D_DECLARE_PRIVATE(DCapFile) + Q_DISABLE_COPY(DCapFile) + +public: + explicit DCapFile(QObject *parent = nullptr); + DCapFile(const QString &name, QObject *parent = nullptr); + + ~DCapFile() override; + + void setFileName(const QString &name); + + bool exists() const; + static bool exists(const QString &fileName); + +#if QT_DEPRECATED_SINCE(5, 13) + D_DECL_DEPRECATED_X("Use QFile::symLinkTarget() instead") + QString readLink() const; +#endif +#if QT_VERSION >= QT_VERSION_CHECK(5, 13, 0) + QString symLinkTarget() const; +#endif + bool remove(); + static bool remove(const QString &fileName); + +#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0) + bool moveToTrash(); + static bool moveToTrash(const QString &fileName, QString *pathInTrash = nullptr); +#endif + + bool rename(const QString &newName); + static bool rename(const QString &oldName, const QString &newName); + + bool link(const QString &newName); + static bool link(const QString &oldname, const QString &newName); + + bool copy(const QString &newName); + static bool copy(const QString &fileName, const QString &newName); + + bool open(OpenMode flags) override; + + bool resize(qint64 sz) override; + static bool resize(const QString &filename, qint64 sz); + +private: + bool open(FILE *f, OpenMode ioFlags, FileHandleFlags handleFlags=DontCloseHandle); + bool open(int fd, OpenMode ioFlags, FileHandleFlags handleFlags=DontCloseHandle); +}; + +class DCapDirPrivate; +class DCapDir : public QDir +{ +public: + DCapDir(const DCapDir &); + DCapDir(const QString &path = QString()); + DCapDir(const QString &path, const QString &nameFilter, + SortFlags sort = SortFlags(Name | IgnoreCase), Filters filter = AllEntries); + ~DCapDir(); + + void setPath(const QString &path); + + bool cd(const QString &dirName); + + QStringList entryList(Filters filters = NoFilter, SortFlags sort = NoSort) const; + QStringList entryList(const QStringList &nameFilters, Filters filters = NoFilter, + SortFlags sort = NoSort) const; + + QFileInfoList entryInfoList(Filters filters = NoFilter, SortFlags sort = NoSort) const; + QFileInfoList entryInfoList(const QStringList &nameFilters, Filters filters = NoFilter, + SortFlags sort = NoSort) const; + + bool mkdir(const QString &dirName) const; + bool rmdir(const QString &dirName) const; + bool mkpath(const QString &dirPath) const; + bool rmpath(const QString &dirPath) const; + bool exists() const; + bool remove(const QString &fileName); + bool rename(const QString &oldName, const QString &newName); + bool exists(const QString &name) const; + +private: + QSharedDataPointer dd_ptr; +}; + +DCORE_END_NAMESPACE +Q_DECLARE_SHARED(DTK_CORE_NAMESPACE::DCapDir) +#endif // DCAPFILE_H diff -Nru dtkcore-5.5.33/include/filesystem/dcapmanager.h dtkcore-5.6.2/include/filesystem/dcapmanager.h --- dtkcore-5.5.33/include/filesystem/dcapmanager.h 1970-01-01 00:00:00.000000000 +0000 +++ dtkcore-5.6.2/include/filesystem/dcapmanager.h 2022-09-21 05:21:07.000000000 +0000 @@ -0,0 +1,37 @@ +// SPDX-FileCopyrightText: 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later + +#ifndef DCAPMANAGER_H +#define DCAPMANAGER_H + +#include + +#include + +DCORE_BEGIN_NAMESPACE +class DCapManagerPrivate; +class DCapManager : public QObject, public DObject +{ + Q_OBJECT + Q_DISABLE_COPY(DCapManager) + D_DECLARE_PRIVATE(DCapManager) +public: + static DCapManager *instance(); + static void registerFileEngine(); + static void unregisterFileEngine(); + + void appendPath(const QString &path); + void appendPaths(const QStringList &pathList); + + void removePath(const QString &path); + void removePaths(const QStringList &paths); + + QStringList paths() const; + +protected: + explicit DCapManager(); +}; + +DCORE_END_NAMESPACE +#endif // DCAPMANAGER_H diff -Nru dtkcore-5.5.33/include/filesystem/dfilesystemwatcher.h dtkcore-5.6.2/include/filesystem/dfilesystemwatcher.h --- dtkcore-5.5.33/include/filesystem/dfilesystemwatcher.h 1970-01-01 00:00:00.000000000 +0000 +++ dtkcore-5.6.2/include/filesystem/dfilesystemwatcher.h 2022-09-21 05:21:07.000000000 +0000 @@ -0,0 +1,49 @@ +// SPDX-FileCopyrightText: 2017 - 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later + +#ifndef DFILESYSTEMWATCHER_H +#define DFILESYSTEMWATCHER_H + +#include "dtkcore_global.h" +#include "dobject.h" + +#include + +DCORE_BEGIN_NAMESPACE + +class DFileSystemWatcherPrivate; +class LIBDTKCORESHARED_EXPORT DFileSystemWatcher : public QObject, public DObject +{ + Q_OBJECT + D_DECLARE_PRIVATE(DFileSystemWatcher) + +public: + DFileSystemWatcher(QObject *parent = Q_NULLPTR); + DFileSystemWatcher(const QStringList &paths, QObject *parent = Q_NULLPTR); + ~DFileSystemWatcher(); + + bool addPath(const QString &file); + QStringList addPaths(const QStringList &files); + bool removePath(const QString &file); + QStringList removePaths(const QStringList &files); + + QStringList files() const; + QStringList directories() const; + +Q_SIGNALS: + void fileDeleted(const QString &path, const QString &name, QPrivateSignal); + void fileAttributeChanged(const QString &path, const QString &name, QPrivateSignal); + void fileClosed(const QString &path, const QString &name, QPrivateSignal); + void fileMoved(const QString &fromPath, const QString &fromName, + const QString &toPath, const QString &toName, QPrivateSignal); + void fileCreated(const QString &path, const QString &name, QPrivateSignal); + void fileModified(const QString &path, const QString &name, QPrivateSignal); + +private: + Q_PRIVATE_SLOT(d_func(), void _q_readFromInotify()) +}; + +DCORE_END_NAMESPACE + +#endif // DFILESYSTEMWATCHER_H diff -Nru dtkcore-5.5.33/include/filesystem/dfilewatcher.h dtkcore-5.6.2/include/filesystem/dfilewatcher.h --- dtkcore-5.5.33/include/filesystem/dfilewatcher.h 1970-01-01 00:00:00.000000000 +0000 +++ dtkcore-5.6.2/include/filesystem/dfilewatcher.h 2022-09-21 05:21:07.000000000 +0000 @@ -0,0 +1,35 @@ +// SPDX-FileCopyrightText: 2017 - 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later + +#ifndef DFILEWATCHER_H +#define DFILEWATCHER_H + +#include "dbasefilewatcher.h" + +DCORE_BEGIN_NAMESPACE + +class DFileWatcherPrivate; +class LIBDTKCORESHARED_EXPORT DFileWatcher : public DBaseFileWatcher +{ + Q_OBJECT + +public: + explicit DFileWatcher(const QString &filePath, QObject *parent = 0); + +private Q_SLOTS: + void onFileDeleted(const QString &path, const QString &name); + void onFileAttributeChanged(const QString &path, const QString &name); + void onFileMoved(const QString &fromPath, const QString &fromName, + const QString &toPath, const QString &toName); + void onFileCreated(const QString &path, const QString &name); + void onFileModified(const QString &path, const QString &name); + void onFileClosed(const QString &path, const QString &name); + +private: + D_DECLARE_PRIVATE(DFileWatcher) +}; + +DCORE_END_NAMESPACE + +#endif // DFILEWATCHER_H diff -Nru dtkcore-5.5.33/include/filesystem/dfilewatchermanager.h dtkcore-5.6.2/include/filesystem/dfilewatchermanager.h --- dtkcore-5.5.33/include/filesystem/dfilewatchermanager.h 1970-01-01 00:00:00.000000000 +0000 +++ dtkcore-5.6.2/include/filesystem/dfilewatchermanager.h 2022-09-21 05:21:07.000000000 +0000 @@ -0,0 +1,46 @@ +// SPDX-FileCopyrightText: 2017 - 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later + +#ifndef DFILEWATCHERMANAGER_H +#define DFILEWATCHERMANAGER_H + +#include "dtkcore_global.h" +#include "dobject.h" + +#include + +DCORE_BEGIN_NAMESPACE + +class DFileWatcher; + +class DFileWatcherManagerPrivate; +class LIBDTKCORESHARED_EXPORT DFileWatcherManager : public QObject, public DObject +{ + Q_OBJECT + +public: + explicit DFileWatcherManager(QObject *parent = 0); + ~DFileWatcherManager(); + + DFileWatcher *add(const QString &filePath); + void remove(const QString &filePath); + +Q_SIGNALS: + void fileDeleted(const QString &filePath); + void fileAttributeChanged(const QString &filePath); + void fileMoved(const QString &fromFilePath, const QString &toFilePath); + void subfileCreated(const QString &filePath); + void fileModified(const QString &filePath); + void fileClosed(const QString &filePath); + +private: + QScopedPointer d_ptr; + + D_DECLARE_PRIVATE(DFileWatcherManager) + Q_DISABLE_COPY(DFileWatcherManager) +}; + +DCORE_END_NAMESPACE + +#endif // DFILEWATCHERMANAGER_H diff -Nru dtkcore-5.5.33/include/filesystem/dpathbuf.h dtkcore-5.6.2/include/filesystem/dpathbuf.h --- dtkcore-5.5.33/include/filesystem/dpathbuf.h 1970-01-01 00:00:00.000000000 +0000 +++ dtkcore-5.6.2/include/filesystem/dpathbuf.h 2022-09-21 05:21:07.000000000 +0000 @@ -0,0 +1,55 @@ +// SPDX-FileCopyrightText: 2017 - 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later + +#pragma once + +#include + +#include "dtkcore_global.h" + +DCORE_BEGIN_NAMESPACE + +class LIBDTKCORESHARED_EXPORT DPathBuf +{ +public: + DPathBuf(); + DPathBuf(const QString &path); + + DPathBuf operator/(const QString &p) const + { + return DPathBuf(m_path + "/" + p); + } + + DPathBuf &operator/=(const QString &p) + { + return join(p); + } + + DPathBuf operator/(const char *p) const + { + return operator /(QString(p)); + } + + DPathBuf &operator/=(const char *p) + { + return operator /=(QString(p)); + } + + DPathBuf &join(const QString &p) + { + m_path += "/" + p; + m_path = QDir(m_path).absolutePath(); + return *this; + } + + QString toString() const + { + return QDir::toNativeSeparators(m_path); + } + +private: + QString m_path; +}; + +DCORE_END_NAMESPACE diff -Nru dtkcore-5.5.33/include/filesystem/dstandardpaths.h dtkcore-5.6.2/include/filesystem/dstandardpaths.h --- dtkcore-5.5.33/include/filesystem/dstandardpaths.h 1970-01-01 00:00:00.000000000 +0000 +++ dtkcore-5.6.2/include/filesystem/dstandardpaths.h 2022-09-21 05:21:07.000000000 +0000 @@ -0,0 +1,60 @@ +// SPDX-FileCopyrightText: 2017 - 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later + +#ifndef DTK_CORE_FILESYSTEM_DSTANDARDPATHS_H +#define DTK_CORE_FILESYSTEM_DSTANDARDPATHS_H + +#include + +#include "dtkcore_global.h" + +DCORE_BEGIN_NAMESPACE + +class DStandardPathsPrivate; +class LIBDTKCORESHARED_EXPORT DStandardPaths +{ +public: + enum Mode { + Auto, + Snap, + Test, + }; + + static QString writableLocation(QStandardPaths::StandardLocation type); + static QStringList standardLocations(QStandardPaths::StandardLocation type); + + static QString locate(QStandardPaths::StandardLocation type, const QString &fileName, QStandardPaths::LocateOptions options = QStandardPaths::LocateFile); + static QStringList locateAll(QStandardPaths::StandardLocation type, const QString &fileName, QStandardPaths::LocateOptions options = QStandardPaths::LocateFile); + static QString findExecutable(const QString &executableName, const QStringList &paths = QStringList()); + static void setMode(Mode mode); + + enum class XDG { + DataHome, + ConfigHome, + CacheHome, + RuntimeTime + }; + + enum class DSG { + AppData, + DataDir + }; + + static QString homePath(); + static QString homePath(const uint uid); + static QString path(XDG type); + static QString path(DSG type); + static QStringList paths(DSG type); + static QString filePath(XDG type, QString fileName); + static QString filePath(DSG type, QString fileName); + +private: + DStandardPaths(); + ~DStandardPaths(); + Q_DISABLE_COPY(DStandardPaths) +}; + +DCORE_END_NAMESPACE + +#endif // DTK_CORE_FILESYSTEM_DSTANDARDPATHS_H diff -Nru dtkcore-5.5.33/include/filesystem/dtrashmanager.h dtkcore-5.6.2/include/filesystem/dtrashmanager.h --- dtkcore-5.5.33/include/filesystem/dtrashmanager.h 1970-01-01 00:00:00.000000000 +0000 +++ dtkcore-5.6.2/include/filesystem/dtrashmanager.h 2022-09-21 05:21:07.000000000 +0000 @@ -0,0 +1,34 @@ +// SPDX-FileCopyrightText: 2017 - 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later + +#ifndef DTRASHMANAGER_H +#define DTRASHMANAGER_H + +#include +#include + +#include + +DCORE_BEGIN_NAMESPACE + +class DTrashManagerPrivate; +class LIBDTKCORESHARED_EXPORT DTrashManager : public QObject, public DObject +{ +public: + static DTrashManager *instance(); + + bool trashIsEmpty() const; + bool cleanTrash(); + bool moveToTrash(const QString &filePath, bool followSymlink = false); + +protected: + DTrashManager(); + +private: + D_DECLARE_PRIVATE(DTrashManager) +}; + +DCORE_END_NAMESPACE + +#endif // DTRASHMANAGER_H diff -Nru dtkcore-5.5.33/include/global/dconfigfile.h dtkcore-5.6.2/include/global/dconfigfile.h --- dtkcore-5.5.33/include/global/dconfigfile.h 1970-01-01 00:00:00.000000000 +0000 +++ dtkcore-5.6.2/include/global/dconfigfile.h 2022-09-21 05:21:07.000000000 +0000 @@ -0,0 +1,127 @@ +// SPDX-FileCopyrightText: 2021 - 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later + +#ifndef DCONFIGFILE_H +#define DCONFIGFILE_H + +#include +#include +#include +#include +#include +#include +#include +#include + +QT_BEGIN_NAMESPACE +class QIODevice; +QT_END_NAMESPACE + +DCORE_BEGIN_NAMESPACE + +class DConfigMeta; +class DConfigCache; +class DConfigFilePrivate; +class LIBDTKCORESHARED_EXPORT DConfigFile : public DObject{ + D_DECLARE_PRIVATE(DConfigFile) +public: + enum Flag { + NoOverride = 1 << 0, + Global = 1 << 1 + }; + Q_DECLARE_FLAGS(Flags, Flag) + + enum Permissions { + ReadOnly, + ReadWrite + }; + + enum Visibility { + Private, + Public + }; + + struct Version { + quint16 major; + quint16 minor; + }; + + static constexpr Version supportedVersion(); + + explicit DConfigFile(const QString &appId, const QString &name, + const QString &subpath = QString()); + explicit DConfigFile(const DConfigFile &other); + + bool load(const QString &localPrefix = QString()); + bool load(QIODevice *meta, const QList &overrides); + + bool save(const QString &localPrefix = QString(), QJsonDocument::JsonFormat format = QJsonDocument::Indented, + bool sync = false) const; + + bool isValid() const; + QVariant value(const QString &key, DConfigCache *userCache = nullptr) const; + bool setValue(const QString &key, const QVariant &value, const QString &callerAppid, + DConfigCache *userCache = nullptr); + + DConfigCache *createUserCache(const uint uid); + DConfigCache *globalCache() const; + + DConfigMeta *meta(); + +protected: + friend QDebug operator<<(QDebug, const DConfigFile &); +}; + +class LIBDTKCORESHARED_EXPORT DConfigMeta { +public: + virtual ~DConfigMeta(); + virtual DConfigFile::Version version() const = 0; + virtual void setVersion(quint16 major, quint16 minor) = 0; + + virtual bool load(const QString &localPrefix = QString()) = 0; + + virtual bool load(QIODevice *meta, const QList &overrides) = 0; + + virtual QStringList keyList() const = 0; + virtual DConfigFile::Flags flags(const QString &key) const = 0; + virtual DConfigFile::Permissions permissions(const QString &key) const = 0; + virtual DConfigFile::Visibility visibility(const QString &key) const = 0; + virtual int serial(const QString &key) const = 0; + + virtual QString displayName(const QString &key, const QLocale &locale) = 0; + virtual QString description(const QString &key, const QLocale &locale) = 0; + + virtual QString metaPath(const QString &localPrefix = QString(), bool *useAppId = nullptr) const = 0; + virtual QStringList allOverrideDirs(const bool useAppId, const QString &prefix = QString()) const = 0; + + virtual QVariant value(const QString &key) const = 0; +}; + +class LIBDTKCORESHARED_EXPORT DConfigCache { +public: + virtual ~DConfigCache(); + + virtual bool load(const QString &localPrefix = QString()) = 0; + virtual bool save(const QString &localPrefix = QString(), + QJsonDocument::JsonFormat format = QJsonDocument::Indented, bool sync = false) = 0; + virtual bool isGlobal() const = 0; + + virtual void remove(const QString &key) = 0; + virtual QStringList keyList() const = 0; + virtual bool setValue(const QString &key, const QVariant &value, const int serial, + const uint uid, const QString &callerAppid) = 0; + virtual QVariant value(const QString &key) const = 0; + virtual int serial(const QString &key) const = 0; + virtual uint uid() const = 0; +}; + +#ifndef QT_NO_DEBUG_STREAM +Q_CORE_EXPORT QDebug operator<<(QDebug, const DConfigFile &); +#endif + +Q_DECLARE_OPERATORS_FOR_FLAGS(DConfigFile::Flags) + +DCORE_END_NAMESPACE + +#endif // DCONFIGFILE_H diff -Nru dtkcore-5.5.33/include/global/dconfig.h dtkcore-5.6.2/include/global/dconfig.h --- dtkcore-5.5.33/include/global/dconfig.h 1970-01-01 00:00:00.000000000 +0000 +++ dtkcore-5.6.2/include/global/dconfig.h 2022-09-21 05:21:07.000000000 +0000 @@ -0,0 +1,69 @@ +// SPDX-FileCopyrightText: 2021 - 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later + +#ifndef DCONFIG_H +#define DCONFIG_H + +#include +#include + +#include +#include + +DCORE_BEGIN_NAMESPACE +class DConfigBackend { +public: + virtual ~DConfigBackend(); + virtual bool isValid() const = 0; + virtual bool load(const QString &/*appId*/) = 0; + virtual QStringList keyList() const = 0; + virtual QVariant value(const QString &/*key*/, const QVariant &/*fallback*/) const = 0; + virtual void setValue(const QString &/*key*/, const QVariant &/*value*/) = 0; + virtual void reset(const QString &key) { setValue(key, QVariant());} + virtual QString name() const {return QString("");} +}; + +class DConfigPrivate; +class LIBDTKCORESHARED_EXPORT DConfig : public QObject, public DObject +{ + Q_OBJECT + D_DECLARE_PRIVATE(DConfig) + + Q_PROPERTY(QStringList keyList READ keyList FINAL) + +public: + explicit DConfig(const QString &name, const QString &subpath = QString(), + QObject *parent = nullptr); + + explicit DConfig(DConfigBackend *backend, const QString &name, const QString &subpath = QString(), + QObject *parent = nullptr); + + static DConfig *create(const QString &appId, const QString &name, const QString &subpath = QString(), + QObject *parent = nullptr); + static DConfig *create(DConfigBackend *backend, const QString &appId, const QString &name, const QString &subpath = QString(), + QObject *parent = nullptr); + + QString backendName() const; + + QStringList keyList() const; + + bool isValid() const; + QVariant value(const QString &key, const QVariant &fallback = QVariant()) const; + void setValue(const QString &key, const QVariant &value); + void reset(const QString &key); + + QString name() const; + QString subpath() const; + +Q_SIGNALS: + void valueChanged(const QString &key); + +private: + explicit DConfig(DConfigBackend *backend, const QString &appId, const QString &name, const QString &subpath, + QObject *parent = nullptr); +}; + +DCORE_END_NAMESPACE + +#endif // DCONFIG_H diff -Nru dtkcore-5.5.33/include/global/ddesktopentry.h dtkcore-5.6.2/include/global/ddesktopentry.h --- dtkcore-5.5.33/include/global/ddesktopentry.h 1970-01-01 00:00:00.000000000 +0000 +++ dtkcore-5.6.2/include/global/ddesktopentry.h 2022-09-21 05:21:07.000000000 +0000 @@ -0,0 +1,95 @@ +// SPDX-FileCopyrightText: 2019 - 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later + +#pragma once + +#include "dtkcore_global.h" + +#include +#include +#include + +DCORE_BEGIN_NAMESPACE + +class DDesktopEntryPrivate; +class LIBDTKCORESHARED_EXPORT DDesktopEntry +{ + Q_GADGET +public: + enum EntryType { + Unknown = 0, //!< Unknown desktop file type. Maybe is invalid. + Application, //!< The file describes application. + Link, //!< The file describes URL. + Directory, //!< The file describes directory settings. + ServiceType, //!< KDE specific type. mentioned in the spec, so listed here too. + Service, //!< KDE specific type. mentioned in the spec, so listed here too. + FSDevice //!< KDE specific type. mentioned in the spec, so listed here too. + }; + Q_ENUM(EntryType) + + enum ValueType { + Unparsed = 0, // Maybe useless, consider remove it? + String, + Strings, + Boolean, + Numeric, + NotExisted = 99 + }; + Q_ENUM(ValueType) + + enum Status { + NoError = 0, //!< No error occurred. + AccessError, //!< An access error occurred (e.g. trying to write to a read-only file). + FormatError //!< A format error occurred (e.g. loading a malformed desktop entry file). + }; + Q_ENUM(Status) + + explicit DDesktopEntry(const QString &filePath) noexcept; + ~DDesktopEntry(); + + bool save() const; + + Status status() const; + QStringList keys(const QString §ion = "Desktop Entry") const; + QStringList allGroups(bool sorted = false) const; + + bool contains(const QString &key, const QString §ion = "Desktop Entry") const; + + QString name() const; + QString genericName() const; + QString ddeDisplayName() const; + QString comment() const; + + QString rawValue(const QString &key, const QString §ion = "Desktop Entry", + const QString &defaultValue = QString()) const; + QString stringValue(const QString &key, const QString §ion = "Desktop Entry", + const QString &defaultValue = QString()) const; + QString localizedValue(const QString &key, const QString &localeKey = "default", + const QString §ion = "Desktop Entry", const QString& defaultValue = QString()) const; + QString localizedValue(const QString &key, const QLocale &locale, + const QString §ion = "Desktop Entry", const QString& defaultValue = QString()) const; + QStringList stringListValue(const QString &key, const QString §ion = "Desktop Entry") const; + + bool setRawValue(const QString &value, const QString &key, const QString& section = "Desktop Entry"); + bool setStringValue(const QString &value, const QString &key, const QString& section = "Desktop Entry"); + bool setLocalizedValue(const QString &value, const QString& localeKey, + const QString &key, const QString& section = "Desktop Entry"); + + bool removeEntry(const QString &key, const QString §ion = "Desktop Entry"); + + static QString &escape(QString &str); + static QString &escapeExec(QString &str); + static QString &unescape(QString &str, bool unescapeSemicolons = false); + static QString &unescapeExec(QString &str); + +protected: + bool setStatus(const Status &status); + +private: + QScopedPointer d_ptr; + + Q_DECLARE_PRIVATE(DDesktopEntry) +}; + +DCORE_END_NAMESPACE diff -Nru dtkcore-5.5.33/include/global/dsecurestring.h dtkcore-5.6.2/include/global/dsecurestring.h --- dtkcore-5.5.33/include/global/dsecurestring.h 1970-01-01 00:00:00.000000000 +0000 +++ dtkcore-5.6.2/include/global/dsecurestring.h 2022-09-21 05:21:07.000000000 +0000 @@ -0,0 +1,20 @@ +// SPDX-FileCopyrightText: 2019 - 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later + +#pragma once + +#include "dtkcore_global.h" +#include + +DCORE_BEGIN_NAMESPACE + +class LIBDTKCORESHARED_EXPORT DSecureString : public QString +{ +public: + using QString::QString; + DSecureString(const QString &other) noexcept; + ~DSecureString(); +}; + +DCORE_END_NAMESPACE diff -Nru dtkcore-5.5.33/include/global/dsgapplication.h dtkcore-5.6.2/include/global/dsgapplication.h --- dtkcore-5.5.33/include/global/dsgapplication.h 1970-01-01 00:00:00.000000000 +0000 +++ dtkcore-5.6.2/include/global/dsgapplication.h 2022-09-21 05:21:07.000000000 +0000 @@ -0,0 +1,21 @@ +// SPDX-FileCopyrightText: 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later + +#ifndef DSGAPPLICATION_H +#define DSGAPPLICATION_H + +#include "dtkcore_global.h" + +DCORE_BEGIN_NAMESPACE + +class LIBDTKCORESHARED_EXPORT DSGApplication +{ +public: + static QByteArray id(); + static QByteArray getId(qint64 pid); +}; + +DCORE_END_NAMESPACE + +#endif // DSGAPPLICATION_H diff -Nru dtkcore-5.5.33/include/global/dsysinfo.h dtkcore-5.6.2/include/global/dsysinfo.h --- dtkcore-5.5.33/include/global/dsysinfo.h 1970-01-01 00:00:00.000000000 +0000 +++ dtkcore-5.6.2/include/global/dsysinfo.h 2022-09-21 05:21:07.000000000 +0000 @@ -0,0 +1,140 @@ +// SPDX-FileCopyrightText: 2017 - 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later + +#ifndef DSYSINFO_H +#define DSYSINFO_H + +#include + +#include + +DCORE_BEGIN_NAMESPACE + +class DSysInfoPrivate; +class LIBDTKCORESHARED_EXPORT DSysInfo +{ +public: + enum ProductType { + UnknownType = 0, + Deepin, + ArchLinux, + CentOS, + Debian, + Fedora, + LinuxMint, + Manjaro, + openSUSE, + SailfishOS, + Ubuntu, + Uos, + Gentoo, + NixOS + }; + + enum DeepinType { + UnknownDeepin = 0, + DeepinDesktop, + DeepinProfessional, + DeepinServer, + DeepinPersonal + }; + + enum LogoType { + Normal = 0, + Light, + Symbolic, + Transparent + }; + + enum OrgType { + Distribution, //!< distribution itself + Distributor, //!< distributer of the current distribution + Manufacturer //!< manufacturer of the current distribution or device + }; + + enum UosType { + UosTypeUnknown, + UosDesktop, + UosServer, + UosDevice, + + UosTypeCount // must at last + }; + + enum UosEdition { + UosEditionUnknown, + UosProfessional, + UosHome, + UosCommunity, + UosMilitary, + UosEnterprise, + UosEnterpriseC, + UosEuler, + UosMilitaryS, // for Server + UosDeviceEdition, + UosEducation, + + UosEditionCount // must at last + }; + + // 注意:此处架构是从OsBuild获取的系统版本的Arch信息,并不是指硬件的Arch信息 + enum UosArch { + UosArchUnknown, + UosAMD64 = 1 << 0, + UosARM64 = 1 << 1, + UosMIPS64 = 1 << 2, + UosSW64 = 1 << 3 + }; + +#ifdef Q_OS_LINUX + static bool isDeepin(); + static bool isDDE(); + static DeepinType deepinType(); + static QString deepinTypeDisplayName(const QLocale &locale = QLocale::system()); + static QString deepinVersion(); + static QString deepinEdition(); + static QString deepinCopyright(); + + // uos version interface + static UosType uosType(); + static UosEdition uosEditionType(); + static UosArch uosArch(); + static QString uosProductTypeName(const QLocale &locale = QLocale::system()); + static QString uosSystemName(const QLocale &locale = QLocale::system()); + static QString uosEditionName(const QLocale &locale = QLocale::system()); + + static QString spVersion(); // SP1...SP99 + static QString udpateVersion(); // update1...update9 + static QString majorVersion(); + static QString minorVersion(); + static QString buildVersion(); // xyzs +#endif + + Q_DECL_DEPRECATED_X("Use distributionInfoPath() instead") static QString deepinDistributionInfoPath(); + static QString distributionInfoPath(); + static QString distributionInfoSectionName(OrgType type); + + static QString distributionOrgName(OrgType type = Distribution, const QLocale &locale = QLocale::system()); + Q_DECL_DEPRECATED_X("Use deepinDistributionOrgName() instead") static QString deepinDistributorName(); + static QPair distributionOrgWebsite(OrgType type = Distribution); + Q_DECL_DEPRECATED_X("Use deepinDistributionOrgWebsite() instead") static QPair deepinDistributorWebsite(); + static QString distributionOrgLogo(OrgType orgType = Distribution, LogoType type = Normal, const QString & fallback = QString()); + Q_DECL_DEPRECATED_X("Use deepinDistributionOrgLogo() instead") static QString deepinDistributorLogo(LogoType type = Normal, const QString & fallback = QString()); + + static QString operatingSystemName(); + static ProductType productType(); + static QString productTypeString(); + static QString productVersion(); + static bool isCommunityEdition(); + + static QString computerName(); + static QString cpuModelName(); + static qint64 memoryInstalledSize(); + static qint64 memoryTotalSize(); + static qint64 systemDiskSize(); +}; + +DCORE_END_NAMESPACE + +#endif // DSYSINFO_H diff -Nru dtkcore-5.5.33/include/global/dtkcore_global.h dtkcore-5.6.2/include/global/dtkcore_global.h --- dtkcore-5.5.33/include/global/dtkcore_global.h 1970-01-01 00:00:00.000000000 +0000 +++ dtkcore-5.6.2/include/global/dtkcore_global.h 2022-09-21 05:21:07.000000000 +0000 @@ -0,0 +1,60 @@ +// SPDX-FileCopyrightText: 2017 - 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later + +#pragma once + +#include +#include + +#define DTK_NAMESPACE Dtk + +#if !defined(DTK_NAMESPACE) +# define DTK_BEGIN_NAMESPACE +# define DTK_END_NAMESPACE +# define DTK_USE_NAMESPACE +#else +# define DTK_BEGIN_NAMESPACE namespace DTK_NAMESPACE { +# define DTK_END_NAMESPACE } +# define DTK_USE_NAMESPACE using namespace DTK_NAMESPACE; +#endif + +#define DCORE_NAMESPACE Core +#define DTK_CORE_NAMESPACE DTK_NAMESPACE::DCORE_NAMESPACE + +#if !defined(DCORE_NAMESPACE) +# define DCORE_BEGIN_NAMESPACE +# define DCORE_END_NAMESPACE +# define DCORE_USE_NAMESPACE +#else +# define DCORE_BEGIN_NAMESPACE namespace DTK_NAMESPACE { namespace DCORE_NAMESPACE { +# define DCORE_END_NAMESPACE }} +# define DCORE_USE_NAMESPACE using namespace DTK_CORE_NAMESPACE; +#endif + + +#if defined(DTK_STATIC_LIB) +# define LIBDTKCORESHARED_EXPORT +#else +#if defined(LIBDTKCORE_LIBRARY) +# define LIBDTKCORESHARED_EXPORT Q_DECL_EXPORT +#else +# define LIBDTKCORESHARED_EXPORT Q_DECL_IMPORT +#endif +#endif + +#ifdef D_DEPRECATED_CHECK +#define D_DECL_DEPRECATED_X(text) Q_DECL_HIDDEN +#define D_DECL_DEPRECATED Q_DECL_HIDDEN +#else +#define D_DECL_DEPRECATED Q_DECL_DEPRECATED +#define D_DECL_DEPRECATED_X Q_DECL_DEPRECATED_X +#endif + +#define DTK_VERSION_CHECK(major, minor, patch, build) ((major<<24)|(minor<<16)|(patch<<8)|build) +#define DTK_VERSION DTK_VERSION_CHECK(DTK_VERSION_MAJOR, DTK_VERSION_MINOR, DTK_VERSION_PATCH, DTK_VERSION_BUILD) + +extern "C" { +int LIBDTKCORESHARED_EXPORT dtkVersion(); +const LIBDTKCORESHARED_EXPORT char *dtkVersionString(); +} diff -Nru dtkcore-5.5.33/include/log/AbstractAppender.h dtkcore-5.6.2/include/log/AbstractAppender.h --- dtkcore-5.5.33/include/log/AbstractAppender.h 1970-01-01 00:00:00.000000000 +0000 +++ dtkcore-5.6.2/include/log/AbstractAppender.h 2022-09-21 05:21:07.000000000 +0000 @@ -0,0 +1,44 @@ +// SPDX-FileCopyrightText: 2010 Boris Moiseev (cyberbobs at gmail dot com) +// SPDX-FileCopyrightText: 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later + +#ifndef ABSTRACTAPPENDER_H +#define ABSTRACTAPPENDER_H + +// Local +#include "CuteLogger_global.h" +#include + +// Qt +#include + +DCORE_BEGIN_NAMESPACE + +class CUTELOGGERSHARED_EXPORT AbstractAppender +{ +public: + AbstractAppender(); + virtual ~AbstractAppender(); + + Logger::LogLevel detailsLevel() const; + void setDetailsLevel(Logger::LogLevel level); + void setDetailsLevel(const QString &level); + + void write(const QDateTime &timeStamp, Logger::LogLevel logLevel, const char *file, int line, const char *function, + const QString &category, const QString &message); + +protected: + virtual void append(const QDateTime &timeStamp, Logger::LogLevel logLevel, const char *file, int line, + const char *function, const QString &category, const QString &message) = 0; + +private: + QMutex m_writeMutex; + + Logger::LogLevel m_detailsLevel; + mutable QMutex m_detailsLevelMutex; +}; + +DCORE_END_NAMESPACE + +#endif // ABSTRACTAPPENDER_H diff -Nru dtkcore-5.5.33/include/log/AbstractStringAppender.h dtkcore-5.6.2/include/log/AbstractStringAppender.h --- dtkcore-5.5.33/include/log/AbstractStringAppender.h 1970-01-01 00:00:00.000000000 +0000 +++ dtkcore-5.6.2/include/log/AbstractStringAppender.h 2022-09-21 05:21:07.000000000 +0000 @@ -0,0 +1,41 @@ +// SPDX-FileCopyrightText: 2010 Boris Moiseev (cyberbobs at gmail dot com) +// SPDX-FileCopyrightText: 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later + +#ifndef ABSTRACTSTRINGAPPENDER_H +#define ABSTRACTSTRINGAPPENDER_H + +// Local +#include "CuteLogger_global.h" +#include + +// Qt +#include + +DCORE_BEGIN_NAMESPACE + +class CUTELOGGERSHARED_EXPORT AbstractStringAppender : public AbstractAppender +{ + public: + AbstractStringAppender(); + + virtual QString format() const; + void setFormat(const QString&); + + static QString stripFunctionName(const char*); + + protected: + QString formattedString(const QDateTime& timeStamp, Logger::LogLevel logLevel, const char* file, int line, + const char* function, const QString& category, const QString& message) const; + + private: + static QByteArray qCleanupFuncinfo(const char*); + + QString m_format; + mutable QReadWriteLock m_formatLock; +}; + +DCORE_END_NAMESPACE + +#endif // ABSTRACTSTRINGAPPENDER_H diff -Nru dtkcore-5.5.33/include/log/ConsoleAppender.h dtkcore-5.6.2/include/log/ConsoleAppender.h --- dtkcore-5.5.33/include/log/ConsoleAppender.h 1970-01-01 00:00:00.000000000 +0000 +++ dtkcore-5.6.2/include/log/ConsoleAppender.h 2022-09-21 05:21:07.000000000 +0000 @@ -0,0 +1,31 @@ +// SPDX-FileCopyrightText: 2010 Boris Moiseev (cyberbobs at gmail dot com) +// SPDX-FileCopyrightText: 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later + +#ifndef CONSOLEAPPENDER_H +#define CONSOLEAPPENDER_H + +#include "CuteLogger_global.h" +#include + +DCORE_BEGIN_NAMESPACE + +class CUTELOGGERSHARED_EXPORT ConsoleAppender : public AbstractStringAppender +{ + public: + ConsoleAppender(); + virtual QString format() const; + void ignoreEnvironmentPattern(bool ignore); + + protected: + virtual void append(const QDateTime& timeStamp, Logger::LogLevel logLevel, const char* file, int line, + const char* function, const QString& category, const QString& message); + + private: + bool m_ignoreEnvPattern; +}; + +DCORE_END_NAMESPACE + +#endif // CONSOLEAPPENDER_H diff -Nru dtkcore-5.5.33/include/log/CuteLogger_global.h dtkcore-5.6.2/include/log/CuteLogger_global.h --- dtkcore-5.5.33/include/log/CuteLogger_global.h 1970-01-01 00:00:00.000000000 +0000 +++ dtkcore-5.6.2/include/log/CuteLogger_global.h 2022-09-21 05:21:07.000000000 +0000 @@ -0,0 +1,21 @@ +// Copyright (C) 2017 ~ 2017 Deepin Technology Co., Ltd. +// SPDX-FileCopyrightText: 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later + +#ifndef CUTELOGGER_GLOBAL_H +#define CUTELOGGER_GLOBAL_H + +#include "dtkcore_global.h" + +#if defined(CUTELOGGER_LIBRARY) +# define CUTELOGGERSHARED_EXPORT Q_DECL_EXPORT +#else +#if defined(Q_OS_WIN32) +# define CUTELOGGERSHARED_EXPORT +#else +# define CUTELOGGERSHARED_EXPORT Q_DECL_IMPORT +#endif +#endif + +#endif // CUTELOGGER_GLOBAL_H diff -Nru dtkcore-5.5.33/include/log/FileAppender.h dtkcore-5.6.2/include/log/FileAppender.h --- dtkcore-5.5.33/include/log/FileAppender.h 1970-01-01 00:00:00.000000000 +0000 +++ dtkcore-5.6.2/include/log/FileAppender.h 2022-09-21 05:21:07.000000000 +0000 @@ -0,0 +1,44 @@ +// SPDX-FileCopyrightText: 2010 Boris Moiseev (cyberbobs at gmail dot com) +// SPDX-FileCopyrightText: 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later + +#ifndef FILEAPPENDER_H +#define FILEAPPENDER_H + +// Logger +#include "CuteLogger_global.h" +#include + +// Qt +#include +#include + +DCORE_BEGIN_NAMESPACE + +class CUTELOGGERSHARED_EXPORT FileAppender : public AbstractStringAppender +{ + public: + FileAppender(const QString& fileName = QString()); + ~FileAppender(); + + QString fileName() const; + void setFileName(const QString&); + + qint64 size() const; + + protected: + virtual void append(const QDateTime& timeStamp, Logger::LogLevel logLevel, const char* file, int line, + const char* function, const QString& category, const QString& message); + bool openFile(); + void closeFile(); + + private: + QFile m_logFile; + QTextStream m_logStream; + mutable QMutex m_logFileMutex; +}; + +DCORE_END_NAMESPACE + +#endif // FILEAPPENDER_H diff -Nru dtkcore-5.5.33/include/log/Logger.h dtkcore-5.6.2/include/log/Logger.h --- dtkcore-5.5.33/include/log/Logger.h 1970-01-01 00:00:00.000000000 +0000 +++ dtkcore-5.6.2/include/log/Logger.h 2022-09-21 05:21:07.000000000 +0000 @@ -0,0 +1,199 @@ +// SPDX-FileCopyrightText: 2012 Boris Moiseev (cyberbobs at gmail dot com) +// SPDX-FileCopyrightText: 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later + +#ifndef LOGGER_H +#define LOGGER_H + +// Qt +#include +#include +#include + +// Local +#include "CuteLogger_global.h" + +DCORE_BEGIN_NAMESPACE + +class AbstractAppender; +class Logger; +CUTELOGGERSHARED_EXPORT Logger *loggerInstance(); +#define logger loggerInstance() + + +#define dTrace CuteMessageLogger(loggerInstance(), Logger::Trace, __FILE__, __LINE__, Q_FUNC_INFO).write +#define dDebug CuteMessageLogger(loggerInstance(), Logger::Debug, __FILE__, __LINE__, Q_FUNC_INFO).write +#define dInfo CuteMessageLogger(loggerInstance(), Logger::Info, __FILE__, __LINE__, Q_FUNC_INFO).write +#define dWarning CuteMessageLogger(loggerInstance(), Logger::Warning, __FILE__, __LINE__, Q_FUNC_INFO).write +#define dError CuteMessageLogger(loggerInstance(), Logger::Error, __FILE__, __LINE__, Q_FUNC_INFO).write +#define dFatal CuteMessageLogger(loggerInstance(), Logger::Fatal, __FILE__, __LINE__, Q_FUNC_INFO).write + +#define dCTrace(category) CuteMessageLogger(loggerInstance(), Logger::Trace, __FILE__, __LINE__, Q_FUNC_INFO, category).write() +#define dCDebug(category) CuteMessageLogger(loggerInstance(), Logger::Debug, __FILE__, __LINE__, Q_FUNC_INFO, category).write() +#define dCInfo(category) CuteMessageLogger(loggerInstance(), Logger::Info, __FILE__, __LINE__, Q_FUNC_INFO, category).write() +#define dCWarning(category) CuteMessageLogger(loggerInstance(), Logger::Warning, __FILE__, __LINE__, Q_FUNC_INFO, category).write() +#define dCError(category) CuteMessageLogger(loggerInstance(), Logger::Error, __FILE__, __LINE__, Q_FUNC_INFO, category).write() +#define dCFatal(category) CuteMessageLogger(loggerInstance(), Logger::Fatal, __FILE__, __LINE__, Q_FUNC_INFO, category).write() + +#define dTraceTime LoggerTimingHelper loggerTimingHelper(loggerInstance(), Logger::Trace, __FILE__, __LINE__, Q_FUNC_INFO); loggerTimingHelper.start +#define dDebugTime LoggerTimingHelper loggerTimingHelper(loggerInstance(), Logger::Debug, __FILE__, __LINE__, Q_FUNC_INFO); loggerTimingHelper.start +#define dInfoTime LoggerTimingHelper loggerTimingHelper(loggerInstance(), Logger::Info, __FILE__, __LINE__, Q_FUNC_INFO); loggerTimingHelper.start + +#define dAssert(cond) ((!(cond)) ? loggerInstance()->writeAssert(__FILE__, __LINE__, Q_FUNC_INFO, #cond) : qt_noop()) +#define dAssertX(cond, msg) ((!(cond)) ? loggerInstance()->writeAssert(__FILE__, __LINE__, Q_FUNC_INFO, msg) : qt_noop()) + +#define dCategory(category) \ + private:\ + Logger* loggerInstance()\ + {\ + static Logger customLoggerInstance(category);\ + return &customLoggerInstance;\ + }\ + +#define dGlobalCategory(category) \ + private:\ + Logger* loggerInstance()\ + {\ + static Logger customLoggerInstance(category);\ + customLoggerInstance.logToGlobalInstance(category, true);\ + return &customLoggerInstance;\ + }\ + + + class LoggerPrivate; + class CUTELOGGERSHARED_EXPORT Logger + { + Q_DISABLE_COPY(Logger) + + public: + Logger(); + Logger(const QString &defaultCategory); + ~Logger(); + + //! Describes the possible severity levels of the log records + enum LogLevel { + Trace, //!< Trace level. Can be used for mostly unneeded records used for internal code tracing. + Debug, //!< Debug level. Useful for non-necessary records used for the debugging of the software. + Info, //!< Info level. Can be used for informational records, which may be interesting for not only developers. + Warning, //!< Warning. May be used to log some non-fatal warnings detected by your application. + Error, //!< Error. May be used for a big problems making your application work wrong but not crashing. + Fatal //!< Fatal. Used for unrecoverable errors, crashes the application right after the log record is written. + }; + + static QString levelToString(LogLevel logLevel); + static LogLevel levelFromString(const QString &s); + + static Logger *globalInstance(); + + void registerAppender(AbstractAppender *appender); + void registerCategoryAppender(const QString &category, AbstractAppender *appender); + + void logToGlobalInstance(const QString &category, bool logToGlobal = false); + + void setDefaultCategory(const QString &category); + QString defaultCategory() const; + + void write(const QDateTime &timeStamp, LogLevel logLevel, const char *file, int line, const char *function, const char *category, + const QString &message); + void write(LogLevel logLevel, const char *file, int line, const char *function, const char *category, const QString &message); + QDebug write(LogLevel logLevel, const char *file, int line, const char *function, const char *category); + + void writeAssert(const char *file, int line, const char *function, const char *condition); + + private: + void write(const QDateTime &timeStamp, LogLevel logLevel, const char *file, int line, const char *function, const char *category, + const QString &message, bool fromLocalInstance); + Q_DECLARE_PRIVATE(Logger) + LoggerPrivate *d_ptr; + }; + + + class CUTELOGGERSHARED_EXPORT CuteMessageLogger + { + Q_DISABLE_COPY(CuteMessageLogger) + + public: + Q_DECL_CONSTEXPR CuteMessageLogger(Logger *l, Logger::LogLevel level, const char *file, int line, const char *function) + : m_l(l), + m_level(level), + m_file(file), + m_line(line), + m_function(function), + m_category(0) + {} + + Q_DECL_CONSTEXPR CuteMessageLogger(Logger *l, Logger::LogLevel level, const char *file, int line, const char *function, const char *category) + : m_l(l), + m_level(level), + m_file(file), + m_line(line), + m_function(function), + m_category(category) + {} + + void write(const char *msg, ...) const +#if defined(Q_CC_GNU) && !defined(__INSURE__) +# if defined(Q_CC_MINGW) && !defined(Q_CC_CLANG) + __attribute__((format(gnu_printf, 2, 3))) +# else + __attribute__((format(printf, 2, 3))) +# endif +#endif + ; + + void write(const QString &msg) const; + + QDebug write() const; + + private: + Logger *m_l; + Logger::LogLevel m_level; + const char *m_file; + int m_line; + const char *m_function; + const char *m_category; + }; + + + class CUTELOGGERSHARED_EXPORT LoggerTimingHelper + { + Q_DISABLE_COPY(LoggerTimingHelper) + + public: + inline explicit LoggerTimingHelper(Logger *l, Logger::LogLevel logLevel, const char *file, int line, + const char *function) + : m_logger(l), + m_logLevel(logLevel), + m_file(file), + m_line(line), + m_function(function) + {} + + void start(const char *msg, ...) +#if defined(Q_CC_GNU) && !defined(__INSURE__) +# if defined(Q_CC_MINGW) && !defined(Q_CC_CLANG) + __attribute__((format(gnu_printf, 2, 3))) +# else + __attribute__((format(printf, 2, 3))) +# endif +#endif + ; + + void start(const QString &msg = QString()); + + ~LoggerTimingHelper(); + + private: + Logger *m_logger; + QTime m_time; + Logger::LogLevel m_logLevel; + const char *m_file; + int m_line; + const char *m_function; + QString m_block; + }; + + DCORE_END_NAMESPACE + +#endif // LOGGER_H diff -Nru dtkcore-5.5.33/include/log/LogManager.h dtkcore-5.6.2/include/log/LogManager.h --- dtkcore-5.5.33/include/log/LogManager.h 1970-01-01 00:00:00.000000000 +0000 +++ dtkcore-5.6.2/include/log/LogManager.h 2022-09-21 05:21:07.000000000 +0000 @@ -0,0 +1,56 @@ +// Copyright (C) 2017 ~ 2017 Deepin Technology Co., Ltd. +// SPDX-FileCopyrightText: 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later + +#ifndef LOGMANAGER_H +#define LOGMANAGER_H + +#include + +#include "CuteLogger_global.h" + +DCORE_BEGIN_NAMESPACE + +class ConsoleAppender; +class RollingFileAppender; + +class LIBDTKCORESHARED_EXPORT DLogManager +{ +public: + static void registerConsoleAppender(); + static void registerFileAppender(); + + static QString getlogFilePath(); + + /*! + * \brief setlogFilePath will change log file path of registerFileAppender + * \a logFilePath is the full path of file appender log + */ + static void setlogFilePath(const QString& logFilePath); + + static void setLogFormat(const QString& format); + +private: + QString m_format; + QString m_logPath; + ConsoleAppender* m_consoleAppender; + RollingFileAppender* m_rollingFileAppender; + + void initConsoleAppender(); + void initRollingFileAppender(); + QString joinPath(const QString& path, const QString& fileName); + + inline static DLogManager* instance(){ + static DLogManager instance; + return &instance; + } + explicit DLogManager(); + ~DLogManager(); + DLogManager(const DLogManager &); + DLogManager & operator = (const DLogManager &); +}; + +DCORE_END_NAMESPACE + +#endif // LOGMANAGER_H diff -Nru dtkcore-5.5.33/include/log/RollingFileAppender.h dtkcore-5.6.2/include/log/RollingFileAppender.h --- dtkcore-5.5.33/include/log/RollingFileAppender.h 1970-01-01 00:00:00.000000000 +0000 +++ dtkcore-5.6.2/include/log/RollingFileAppender.h 2022-09-21 05:21:07.000000000 +0000 @@ -0,0 +1,75 @@ +// Copyright (C) 2017 ~ 2017 Deepin Technology Co., Ltd. +// SPDX-FileCopyrightText: 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later + +#ifndef ROLLINGFILEAPPENDER_H +#define ROLLINGFILEAPPENDER_H + +#include + +#include + +DCORE_BEGIN_NAMESPACE + +class CUTELOGGERSHARED_EXPORT RollingFileAppender : public FileAppender +{ + public: + /*! + The enum DatePattern defines constants for date patterns. + \sa setDatePattern(DatePattern) + */ + enum DatePattern + { + /*! The minutely date pattern string is "'.'yyyy-MM-dd-hh-mm". */ + MinutelyRollover = 0, + /*! The hourly date pattern string is "'.'yyyy-MM-dd-hh". */ + HourlyRollover, + /*! The half-daily date pattern string is "'.'yyyy-MM-dd-a". */ + HalfDailyRollover, + /*! The daily date pattern string is "'.'yyyy-MM-dd". */ + DailyRollover, + /*! The weekly date pattern string is "'.'yyyy-ww". */ + WeeklyRollover, + /*! The monthly date pattern string is "'.'yyyy-MM". */ + MonthlyRollover + }; + + RollingFileAppender(const QString& fileName = QString()); + + DatePattern datePattern() const; + void setDatePattern(DatePattern datePattern); + void setDatePattern(const QString& datePattern); + + QString datePatternString() const; + + void setLogFilesLimit(int limit); + int logFilesLimit() const; + + void setLogSizeLimit(int qint64); + qint64 logSizeLimit() const; + + protected: + virtual void append(const QDateTime& timeStamp, Logger::LogLevel logLevel, const char* file, int line, + const char* function, const QString& category, const QString& message); + + private: + void rollOver(); + void computeRollOverTime(); + void computeFrequency(); + void removeOldFiles(); + void setDatePatternString(const QString& datePatternString); + + QString m_datePatternString; + DatePattern m_frequency; + + QDateTime m_rollOverTime; + QString m_rollOverSuffix; + int m_logFilesLimit; + qint64 m_logSizeLimit; + mutable QMutex m_rollingMutex; +}; + +DCORE_END_NAMESPACE + +#endif // ROLLINGFILEAPPENDER_H diff -Nru dtkcore-5.5.33/include/log/win32/OutputDebugAppender.h dtkcore-5.6.2/include/log/win32/OutputDebugAppender.h --- dtkcore-5.5.33/include/log/win32/OutputDebugAppender.h 1970-01-01 00:00:00.000000000 +0000 +++ dtkcore-5.6.2/include/log/win32/OutputDebugAppender.h 2022-09-21 05:21:07.000000000 +0000 @@ -0,0 +1,23 @@ +// SPDX-FileCopyrightText: 2010 Karl-Heinz Reichel (khreichel at googlemail dot com) +// SPDX-FileCopyrightText: 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later + +#ifndef OUTPUTDEBUGAPPENDER_H +#define OUTPUTDEBUGAPPENDER_H + +#include "CuteLogger_global.h" +#include + +DCORE_BEGIN_NAMESPACE + +class CUTELOGGERSHARED_EXPORT OutputDebugAppender : public AbstractStringAppender +{ + protected: + virtual void append(const QDateTime& timeStamp, Logger::LogLevel logLevel, const char* file, int line, + const char* function, const QString& category, const QString& message); +}; + +DCORE_END_NAMESPACE + +#endif // OUTPUTDEBUGAPPENDER_H diff -Nru dtkcore-5.5.33/include/settings/backend/dsettingsdconfigbackend.h dtkcore-5.6.2/include/settings/backend/dsettingsdconfigbackend.h --- dtkcore-5.5.33/include/settings/backend/dsettingsdconfigbackend.h 1970-01-01 00:00:00.000000000 +0000 +++ dtkcore-5.6.2/include/settings/backend/dsettingsdconfigbackend.h 2022-09-21 05:21:07.000000000 +0000 @@ -0,0 +1,34 @@ +// SPDX-FileCopyrightText: 2021 - 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later + +#pragma once + +#include +#include + +#include "dsettingsbackend.h" + +DCORE_BEGIN_NAMESPACE + +class DSettingsDConfigBackendPrivate; +class LIBDTKCORESHARED_EXPORT DSettingsDConfigBackend : public Dtk::Core::DSettingsBackend +{ + Q_OBJECT +public: + explicit DSettingsDConfigBackend(const QString &name, const QString &subpath = QString(), QObject *parent = nullptr); + ~DSettingsDConfigBackend() Q_DECL_OVERRIDE; + + virtual QStringList keys() const Q_DECL_OVERRIDE; + virtual QVariant getOption(const QString &key) const Q_DECL_OVERRIDE; + +protected Q_SLOTS: + virtual void doSetOption(const QString &key, const QVariant &value) Q_DECL_OVERRIDE; + virtual void doSync() Q_DECL_OVERRIDE; + +private: + QScopedPointer d_ptr; + Q_DECLARE_PRIVATE_D(qGetPtrHelper(d_ptr), DSettingsDConfigBackend) +}; + +DCORE_END_NAMESPACE diff -Nru dtkcore-5.5.33/include/settings/backend/gsettingsbackend.h dtkcore-5.6.2/include/settings/backend/gsettingsbackend.h --- dtkcore-5.5.33/include/settings/backend/gsettingsbackend.h 1970-01-01 00:00:00.000000000 +0000 +++ dtkcore-5.6.2/include/settings/backend/gsettingsbackend.h 2022-09-21 05:21:07.000000000 +0000 @@ -0,0 +1,34 @@ +// SPDX-FileCopyrightText: 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later + +#pragma once + +#include +#include + +#include "dsettingsbackend.h" + +DCORE_BEGIN_NAMESPACE + +class GSettingsBackendPrivate; +class LIBDTKCORESHARED_EXPORT GSettingsBackend: public DSettingsBackend +{ + Q_OBJECT +public: + explicit GSettingsBackend(DSettings *settings, QObject *parent = nullptr); + ~GSettingsBackend(); + + virtual QStringList keys() const Q_DECL_OVERRIDE; + virtual QVariant getOption(const QString &key) const Q_DECL_OVERRIDE; + +protected Q_SLOTS: + virtual void doSetOption(const QString &key, const QVariant &value) Q_DECL_OVERRIDE; + virtual void doSync() Q_DECL_OVERRIDE; + +private: + QScopedPointer d_ptr; + Q_DECLARE_PRIVATE_D(qGetPtrHelper(d_ptr), GSettingsBackend) +}; + +DCORE_END_NAMESPACE diff -Nru dtkcore-5.5.33/include/settings/backend/qsettingbackend.h dtkcore-5.6.2/include/settings/backend/qsettingbackend.h --- dtkcore-5.5.33/include/settings/backend/qsettingbackend.h 1970-01-01 00:00:00.000000000 +0000 +++ dtkcore-5.6.2/include/settings/backend/qsettingbackend.h 2022-09-21 05:21:07.000000000 +0000 @@ -0,0 +1,34 @@ +// SPDX-FileCopyrightText: 2016 - 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later + +#pragma once + +#include +#include + +#include "dsettingsbackend.h" + +DCORE_BEGIN_NAMESPACE + +class QSettingBackendPrivate; +class LIBDTKCORESHARED_EXPORT QSettingBackend : public Dtk::Core::DSettingsBackend +{ + Q_OBJECT +public: + explicit QSettingBackend(const QString &filepath, QObject *parent = 0); + ~QSettingBackend(); + + virtual QStringList keys() const Q_DECL_OVERRIDE; + virtual QVariant getOption(const QString &key) const Q_DECL_OVERRIDE; + +protected Q_SLOTS: + virtual void doSetOption(const QString &key, const QVariant &value) Q_DECL_OVERRIDE; + virtual void doSync() Q_DECL_OVERRIDE; + +private: + QScopedPointer d_ptr; + Q_DECLARE_PRIVATE_D(qGetPtrHelper(d_ptr), QSettingBackend) +}; + +DCORE_END_NAMESPACE diff -Nru dtkcore-5.5.33/include/settings/dsettingsbackend.h dtkcore-5.6.2/include/settings/dsettingsbackend.h --- dtkcore-5.5.33/include/settings/dsettingsbackend.h 1970-01-01 00:00:00.000000000 +0000 +++ dtkcore-5.6.2/include/settings/dsettingsbackend.h 2022-09-21 05:21:07.000000000 +0000 @@ -0,0 +1,43 @@ +// SPDX-FileCopyrightText: 2016 - 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later + +#pragma once + +#include +#include + +#include "dtkcore_global.h" + +DCORE_BEGIN_NAMESPACE + +class DSettings; +class LIBDTKCORESHARED_EXPORT DSettingsBackend : public QObject +{ + Q_OBJECT +public: + explicit DSettingsBackend(QObject *parent = Q_NULLPTR): QObject(parent) + { + connect(this, &DSettingsBackend::sync, this, &DSettingsBackend::doSync, Qt::QueuedConnection); + connect(this, &DSettingsBackend::setOption, this, &DSettingsBackend::doSetOption, Qt::QueuedConnection); + } + virtual ~DSettingsBackend() {} + + virtual QStringList keys() const = 0; + virtual QVariant getOption(const QString &key) const = 0; + + virtual void doSync() = 0; + +protected: + virtual void doSetOption(const QString &key, const QVariant &value) = 0; + +Q_SIGNALS: + void optionChanged(const QString &key, const QVariant &value); + + // private signals; +Q_SIGNALS: + void sync(); + void setOption(const QString &key, const QVariant &value); +}; + +DCORE_END_NAMESPACE diff -Nru dtkcore-5.5.33/include/settings/dsettingsgroup.h dtkcore-5.6.2/include/settings/dsettingsgroup.h --- dtkcore-5.5.33/include/settings/dsettingsgroup.h 1970-01-01 00:00:00.000000000 +0000 +++ dtkcore-5.6.2/include/settings/dsettingsgroup.h 2022-09-21 05:21:07.000000000 +0000 @@ -0,0 +1,49 @@ +// SPDX-FileCopyrightText: 2016 - 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later + +#pragma once + +#include +#include + +#include "dsettingsoption.h" + +#include "dtkcore_global.h" + +DCORE_BEGIN_NAMESPACE + +class DSettingsGroupPrivate; +class LIBDTKCORESHARED_EXPORT DSettingsGroup : public QObject +{ + Q_OBJECT +public: + explicit DSettingsGroup(QObject *parent = Q_NULLPTR); + ~DSettingsGroup(); + + QPointer parentGroup() const; + void setParentGroup(QPointer parentGroup); + + QString key() const; + QString name() const; + bool isHidden() const; + + QPointer childGroup(const QString &groupKey) const; + QPointer option(const QString &key) const; + + QList > childGroups() const; + QList > childOptions() const; + QList > options() const; + + static QPointer fromJson(const QString &prefixKey, const QJsonObject &group); + +private: + void parseJson(const QString &prefixKey, const QJsonObject &group); + + QScopedPointer dd_ptr; + Q_DECLARE_PRIVATE_D(qGetPtrHelper(dd_ptr), DSettingsGroup) +}; + +typedef QPointer GroupPtr; + +DCORE_END_NAMESPACE diff -Nru dtkcore-5.5.33/include/settings/dsettings.h dtkcore-5.6.2/include/settings/dsettings.h --- dtkcore-5.5.33/include/settings/dsettings.h 1970-01-01 00:00:00.000000000 +0000 +++ dtkcore-5.6.2/include/settings/dsettings.h 2022-09-21 05:21:07.000000000 +0000 @@ -0,0 +1,63 @@ +// SPDX-FileCopyrightText: 2016 - 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later + +#pragma once + +#include +#include +#include + +#include "dtkcore_global.h" + +DCORE_BEGIN_NAMESPACE + +class DSettingsBackend; +class DSettingsOption; +class DSettingsGroup; +class DSettingsPrivate; +class LIBDTKCORESHARED_EXPORT DSettings : public QObject +{ + Q_OBJECT +public: + explicit DSettings(QObject *parent = Q_NULLPTR); + ~DSettings(); + + void setBackend(DSettingsBackend *backend = nullptr); + + static QPointer fromJson(const QByteArray &json); + static QPointer fromJsonFile(const QString &filepath); + QJsonObject meta() const; + + QStringList keys() const; + QList> options() const; + QPointer option(const QString &key) const; + QVariant value(const QString &key) const; + + QStringList groupKeys() const; + QList> groups() const; + QPointer group(const QString &key) const; + + QVariant getOption(const QString &key) const; + +Q_SIGNALS: + void valueChanged(const QString &key, const QVariant &value); + +public Q_SLOTS: + //! + //! \brief sync + //! WARNING: sync will block + void sync() ; + + void setOption(const QString &key, const QVariant &value); + void reset() ; + +private: + void parseJson(const QByteArray &json); + void loadValue(); + + QScopedPointer dd_ptr; + Q_DECLARE_PRIVATE_D(qGetPtrHelper(dd_ptr), DSettings) +}; + +DCORE_END_NAMESPACE diff -Nru dtkcore-5.5.33/include/settings/dsettingsoption.h dtkcore-5.6.2/include/settings/dsettingsoption.h --- dtkcore-5.5.33/include/settings/dsettingsoption.h 1970-01-01 00:00:00.000000000 +0000 +++ dtkcore-5.6.2/include/settings/dsettingsoption.h 2022-09-21 05:21:07.000000000 +0000 @@ -0,0 +1,57 @@ +// SPDX-FileCopyrightText: 2016 - 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later + +#pragma once + +#include +#include +#include + +#include "dtkcore_global.h" + +DCORE_BEGIN_NAMESPACE + +class DSettingsGroup; +class DSettingsOptionPrivate; +class LIBDTKCORESHARED_EXPORT DSettingsOption : public QObject +{ + Q_OBJECT + Q_PROPERTY(QVariant value READ value WRITE setValue NOTIFY valueChanged) + +public: + explicit DSettingsOption(QObject *parent = Q_NULLPTR); + ~DSettingsOption(); + + QPointer parentGroup() const; + void setParentGroup(QPointer parentGroup); + + QString key() const; + QString name() const; + bool canReset() const; + QVariant defaultValue() const; + QVariant value() const; + QVariant data(const QString &dataType) const; + + QString viewType() const; + bool isHidden() const; + + static QPointer fromJson(const QString &prefixKey, const QJsonObject &json); +Q_SIGNALS: + void valueChanged(QVariant value); + void dataChanged(const QString &dataType, QVariant value); + +public Q_SLOTS: + void setValue(QVariant value); + void setData(const QString &dataType, QVariant value); + +private: + void parseJson(const QString &prefixKey, const QJsonObject &option); + + QScopedPointer dd_ptr; + Q_DECLARE_PRIVATE_D(qGetPtrHelper(dd_ptr), DSettingsOption) +}; + +typedef QPointer OptionPtr; + +DCORE_END_NAMESPACE diff -Nru dtkcore-5.5.33/include/util/dabstractunitformatter.h dtkcore-5.6.2/include/util/dabstractunitformatter.h --- dtkcore-5.5.33/include/util/dabstractunitformatter.h 1970-01-01 00:00:00.000000000 +0000 +++ dtkcore-5.6.2/include/util/dabstractunitformatter.h 2022-09-21 05:21:07.000000000 +0000 @@ -0,0 +1,37 @@ +// SPDX-FileCopyrightText: 2017 - 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later + +#ifndef DABSTRACTUNITFORMATTER_H +#define DABSTRACTUNITFORMATTER_H + +#include "dtkcore_global.h" + +#include +#include + +DCORE_BEGIN_NAMESPACE + +class LIBDTKCORESHARED_EXPORT DAbstractUnitFormatter +{ +public: + DAbstractUnitFormatter(); + ~DAbstractUnitFormatter(); + +protected: + virtual int unitMax() const = 0; + virtual int unitMin() const = 0; + virtual uint unitConvertRate(int unitId) const = 0; + virtual qreal unitValueMax(int unitId) const { return unitConvertRate(unitId) - 1; } + virtual qreal unitValueMin(int unitId) const { Q_UNUSED(unitId); return 1; } + virtual QString unitStr(int unitId) const = 0; + +public: + qreal formatAs(qreal value, int currentUnit, const int targetUnit) const; + QPair format(const qreal value, const int unit) const; + QList> formatAsUnitList(const qreal value, int unit) const; +}; + +DCORE_END_NAMESPACE + +#endif // DABSTRACTUNITFORMATTER_H diff -Nru dtkcore-5.5.33/include/util/dasync.h dtkcore-5.6.2/include/util/dasync.h --- dtkcore-5.5.33/include/util/dasync.h 1970-01-01 00:00:00.000000000 +0000 +++ dtkcore-5.6.2/include/util/dasync.h 2022-09-21 05:21:07.000000000 +0000 @@ -0,0 +1,489 @@ +// SPDX-FileCopyrightText: 2021 - 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later + +#ifndef DASYNC_H +#define DASYNC_H +#include + +#include +#include +#include +#include +#include + +#include +#include + +DCORE_BEGIN_NAMESPACE + +#define GUARDED_BY(...) +#define D_THREAD_IN_MAIN() (qApp->instance() && qApp->instance()->thread() == QThread::currentThread()) + +// TODO: 添加 DtkCorePrivate 到 dtkcore_global.h +namespace DtkCorePrivate +{ + // 本类是继承实现的,只有子类方法是安全的,暂不对外提供接口 + template + class DSafeQueue : public QQueue { + public: + inline void enqueue(const T &t) { + QMutexLocker lkc(&m_mtx); + QQueue::enqueue(t); + } + inline T dequeue() { + QMutexLocker lkc(&m_mtx); + return QQueue::dequeue(); + } + inline int size() { + QMutexLocker lkc(&m_mtx); + return QQueue::size(); + } + inline T &head() { + QMutexLocker lkc(&m_mtx); + return QQueue::head(); + } + inline const T &head() const { + QMutexLocker lkc(&m_mtx); + return QQueue::head(); + } + private: + mutable QMutex m_mtx; + }; + + // 内部使用,不对外提供接口 + class MainWorker : public QObject { + Q_OBJECT + std::function m_handle; + std::function m_handleProxy; + + std::function m_handleV; + std::function m_handleVProxy; + + bool m_dasyncDestroyed = false; + char __padding[7]; + public: + void setDAsyncDestroyed() { + m_dasyncDestroyed = true; + } + bool dasyncDestroyed() { + return m_dasyncDestroyed; + } + public: + MainWorker(QObject *parent = nullptr) + : QObject (parent) + { + // Ensure that QApplication is initialized + Q_ASSERT(qApp->instance() && qApp->instance()->thread()); + moveToThread(qApp->instance()->thread()); + + bool isStartInMain = D_THREAD_IN_MAIN(); + + QObject::connect(this, &MainWorker::sigRunInMain, + this, &MainWorker::slotRunInMain, + isStartInMain ? Qt::AutoConnection : Qt::BlockingQueuedConnection); + + QObject::connect(this, &MainWorker::sigRunInMainVoid, + this, &MainWorker::slotRunInMainVoid, + isStartInMain ? Qt::AutoConnection : Qt::BlockingQueuedConnection); + } + + // 1. handle arg is non void + template + typename std::enable_if::value>::type + setHandle(FUNC &&func) { + m_handle = [&] (void *arg) { + DSafeQueue *q = static_cast*>(arg); + while (q && q->size()) { + // 这里是 then 回调真正执行到的地方 + func(q->dequeue()); + } + }; + + m_handleProxy = [this] (void *arg) { + if (m_handle) { + m_handle(arg); + } + }; + } + + // 2. handle arg is void + template + typename std::enable_if::value>::type + setHandle(FUNC &&func) { + m_handleV = [&] (void) { + // 这里是 then 回调真正执行到的地方 + func(); + }; + + m_handleVProxy = [this] (void) { + if (m_handleV) { + m_handleV(); + } + }; + } + Q_SIGNALS: + void sigRunInMain(void *arg); + void sigRunInMainVoid(); + public Q_SLOTS: + void slotRunInMain(void *arg) { + Q_ASSERT(D_THREAD_IN_MAIN()); + if (m_handleProxy && !m_dasyncDestroyed) { + m_handleProxy(arg); + } + } + void slotRunInMainVoid(void) { + Q_ASSERT(D_THREAD_IN_MAIN()); + if (m_handleVProxy && !m_dasyncDestroyed) { + m_handleVProxy(); + } + } + }; +} + +class DAsyncState : public QObject { + Q_OBJECT +public: + explicit DAsyncState(QObject *parent = nullptr) noexcept + : QObject (parent) + { + } + enum AsyncTaskState { + NotReady = 0x00, // initial state + Ready = 0x02, // deffered = false + Running = 0x04, // thread started + Pending = Ready | Running, // condition wait + Cancel = 0x08, // set thread canceled + WaitFinished = 0x10, // wiaitForFinished + Finished = 0x20, // thread exit + Forever = 0x30, // TODO: DAsync::post execute forever + }; + Q_DECLARE_FLAGS(AsyncTaskStatus, AsyncTaskState) +}; + +// Template classes not supported by Q_OBJECT, so class MainWorker is independent +template +class DAsync : public QObject { + + class Helper; + + std::mutex m_mtxIn; + std::condition_variable m_cvIn; + + std::mutex m_mtxForWaitTask; + std::condition_variable m_cvForWaitTask; + + class Guard { + DAsync *m_as; + // 如果 DAsync 已经析构了,工作线程还没结束 + // DAsync 中的有些数据就不能在 guard 的析构里面访问了 + bool m_dasDestructed = false; + public: + bool destructed() { + return m_dasDestructed; + } + void setDestructed() { + m_dasDestructed = true; + } + public: + explicit Guard(DAsync *as) noexcept : m_as (as) + { + m_as->m_status.setFlag(DAsyncState::Ready); + m_as->m_status.setFlag(DAsyncState::Finished, false); // 防止重入 + } + ~Guard() { + if (destructed()) { + return; + } + m_as->m_threadGuard = nullptr; + m_as->m_status.setFlag(DAsyncState::Finished); + m_as->m_status.setFlag(DAsyncState::Ready, false); // 防止重入 + if (m_as->m_status.testFlag(DAsyncState::WaitFinished)) { + m_as->m_cvForWaitTask.notify_one(); + } + setPending(false); + } + void setPending(bool isPending) { + if (!destructed()) { + m_as->m_status.setFlag(DAsyncState::Pending, isPending); + } + } + }; + Guard *m_threadGuard = nullptr; + + /* + * m_QueueIn 的作用是存储 PostData 传进来的数据 + * m_QueueOut 的作用是将 post 处理完的结果暂存起来然后传入到 then 中 + * 在 emitHelper 中调用 post 进来的任务,然后将结果传到主线程中处理 + * 数据传递使用 void * 做转换,对于复合类型避免了使用 qRegisterMetaType + */ + template + struct DataQueueType { DtkCorePrivate::DSafeQueue m_queue; }; + template + struct DataQueueType::value>::type> { }; + using DataInQueue = DataQueueType; + using DataOutQueue = DataQueueType; + // Queue 中处理完的结果经由 m_QueueIn 变量暂存,然后经由 signal、slot 传给 then 中的回调函数做参数 + DataInQueue m_QueueIn; + DataOutQueue m_QueueOut; + + // 存储不同类型的输入函数 + template + struct FuncType { + }; + template + struct FuncType::value>::type, + typename std::enable_if::value>::type> { + std::function cbp; + }; + template + struct FuncType::value>::type, + typename std::enable_if::value>::type> { + std::function cbp; + }; + template + struct FuncType::value>::type, + typename std::enable_if::value>::type> { + std::function cbp; + }; + template + struct FuncType::value>::type, + typename std::enable_if::value>::type> { + std::function cbp; + }; + + std::mutex m_mtxFunc; + FuncType m_func GUARDED_BY(m_mtxFunc); + DAsyncState::AsyncTaskStatus m_status; + +public: + explicit DAsync(QObject *parent = nullptr) noexcept + : QObject (parent) + , m_func ({nullptr}) + , m_status (DAsyncState::NotReady) + { + m_mainWorker = new DtkCorePrivate::MainWorker(); + m_helper = new Helper(this, this); + } + ~DAsync() { + if (m_threadGuard) { + m_threadGuard->setDestructed(); + } + m_status.setFlag(DAsyncState::Cancel); + if (m_status.testFlag(DAsyncState::Pending)) { + m_cvIn.notify_one(); + } + if (m_mainWorker) { + m_mainWorker->setDAsyncDestroyed(); + m_mainWorker->deleteLater(); + m_mainWorker = nullptr; + } + } + +private: + // 1. input void & emit void + template + typename std::enable_if::value && std::is_void::value>::type + emitHelper() { + m_func.cbp(); + Q_EMIT m_mainWorker->sigRunInMainVoid(); + } + // 2. input non void & emit non void + template + typename std::enable_if::value && !std::is_void::value>::type + emitHelper() { + m_QueueOut.m_queue.enqueue(m_func.cbp(m_QueueIn.m_queue.dequeue())); + Q_EMIT m_mainWorker->sigRunInMain(static_cast(&(m_QueueOut.m_queue))); + } + // 3. input non void & emit void + template + typename std::enable_if::value && std::is_void::value>::type + emitHelper() { + m_func.cbp(m_QueueIn.m_queue.dequeue()); + Q_EMIT m_mainWorker->sigRunInMainVoid(); + } + // 4. input void & emit non void + template + typename std::enable_if::value && !std::is_void::value>::type + emitHelper() { + m_QueueOut.m_queue.enqueue(m_func.cbp()); + Q_EMIT m_mainWorker->sigRunInMain(static_cast(&(m_QueueOut.m_queue))); + } + +public: + void startUp() { + if (m_status.testFlag(DAsyncState::Cancel)) { + return; + } + m_helper->start(); + } + void cancelAll() { + m_status.setFlag(DAsyncState::Cancel); + if (m_status.testFlag(DAsyncState::Pending)) { + m_cvIn.notify_one(); + } + } + bool isFinished() { + return m_status.testFlag(DAsyncState::Finished); + } + /* + * 不能在 QTimer 中使用 waitForFinished,防止阻塞主线程 + * 也不能在主线程执行前使用 waitForFinished() + * 它的默认参数为 true,等同于 waitForFinished(false) + + * cancelAll, 如果调用了后者, 会一直阻塞等待任务,直到 + * cancelAll 被调用之后 waitForFinished 才会在任务完成完 + * 成后退出,此时就可以删除DAsync了。最好的管理方式还是采用 + * QObject 的内存托管。主线程中使用,可以采用托管的方式, + * 任务结束只要调用 cancelAll + isFinished 轮询判断就行了, + * DAsync 的工作线程就会在完成后自动退出。 + */ + void waitForFinished(bool cancelAllWorks = true) { + Q_ASSERT(!D_THREAD_IN_MAIN()); + if (cancelAllWorks) { + cancelAll(); + } + if (!m_status.testFlag(DAsyncState::Finished)) { + if (m_status.testFlag(DAsyncState::Pending)) { + m_cvIn.notify_one(); + } + m_status.setFlag(DAsyncState::WaitFinished); + std::unique_lock lck(m_mtxForWaitTask); + m_cvForWaitTask.wait(lck); + } + } + // 输入数据不是 void 类型则依赖于 m_QueueIn + template + typename std::enable_if::value, Helper *>::type + post(FUNC &&func) { + m_func.cbp = std::forward(func); + if (m_postProxy) { + return m_helper; + } + m_postProxy = [this] () { + std::thread thread([this] { + if (m_status.testFlag(DAsyncState::Cancel)) { + return; + } + Guard guard(this); + m_threadGuard = &guard; + + std::unique_lock lck(m_mtxIn); + while (true) { + while (!m_status.testFlag(DAsyncState::Ready) || !m_QueueIn.m_queue.size()) { + guard.setPending(true); + // 定时查询 flag,防止睡死的情况发生 + m_cvIn.wait_for(lck, std::chrono::milliseconds(200)); + if (guard.destructed() || m_status.testFlag(DAsyncState::Cancel)) { + return; + } + } + guard.setPending(false); + + while (m_func.cbp && m_QueueIn.m_queue.size()) { + emitHelper(); + } + } + }); + thread.detach(); + }; + + return m_helper; + } + + template + typename std::enable_if::value, Helper *>::type + post(FUNC &&func) { + { + std::lock_guard lckFunc(m_mtxFunc); + m_func.cbp = std::forward(func); + } + if (m_postProxy) { + return m_helper; + } + m_postProxy = [this] () { + std::thread thread([this] { + if (m_status.testFlag(DAsyncState::Cancel)) { + return; + } + Guard guard(this); + m_threadGuard = &guard; + + std::unique_lock lck(m_mtxIn); + while (true) { + if (!m_status.testFlag(DAsyncState::Ready)) { + guard.setPending(true); + // 定时查询 flag,防止睡死的情况发生 + m_cvIn.wait_for(lck, std::chrono::milliseconds(200)); + if (guard.destructed() || m_status.testFlag(DAsyncState::Cancel)){ + return; + } + } + guard.setPending(false); + + if (m_func.cbp) { + std::lock_guard lckFunc(m_mtxFunc); + emitHelper(); + m_func.cbp = nullptr; // reset + } + } + }); + thread.detach(); + }; + + return m_helper; + } + + // only support DAsync + template + typename std::enable_if::value>::type + postData(const InputType &data) { + if (Q_UNLIKELY(!m_status.testFlag(DAsyncState::Cancel))) { + m_QueueIn.m_queue.enqueue(data); + if (m_status.testFlag(DAsyncState::Pending)) { + m_cvIn.notify_one(); + } + } + } + +private: + std::function m_postProxy; + class Helper : public QObject { + DAsync *m_async; + public: + explicit Helper(DAsync *async, QObject *parent = nullptr) noexcept + : QObject (parent) + , m_async (async) + { + } + + template + Helper *then(FUNC &&func) { + m_async->m_mainWorker->template setHandle(std::forward(func)); + return this; + } + // 仅启动,非阻塞 + void start(bool immediately = true) { + if (m_async->m_postProxy) { + m_async->m_postProxy(); + } + if (!immediately) { + m_async->m_status.setFlag(DAsyncState::Ready, false); + } else { + m_async->m_status.setFlag(DAsyncState::Ready); + if (m_async->m_status.testFlag(DAsyncState::Pending)) { + m_async->m_cvIn.notify_one(); + } + } + } + }; + + Helper *m_helper = nullptr; + DtkCorePrivate::MainWorker *m_mainWorker = nullptr; +}; + +DCORE_END_NAMESPACE +#endif //DASYNC_H diff -Nru dtkcore-5.5.33/include/util/ddbusinterface.h dtkcore-5.6.2/include/util/ddbusinterface.h --- dtkcore-5.5.33/include/util/ddbusinterface.h 1970-01-01 00:00:00.000000000 +0000 +++ dtkcore-5.6.2/include/util/ddbusinterface.h 2022-09-21 05:21:07.000000000 +0000 @@ -0,0 +1,36 @@ +// SPDX-FileCopyrightText: 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later + +#pragma once +#include "dtkcore_global.h" +#include + +DCORE_BEGIN_NAMESPACE + +class DDBusInterfacePrivate; +class DDBusInterface : public QDBusAbstractInterface +{ + Q_OBJECT + +public: + explicit DDBusInterface(const QString &service, const QString &path, const QString &interface = QString(), + const QDBusConnection &connection = QDBusConnection::sessionBus(), QObject *parent = nullptr); + virtual ~DDBusInterface() override; + + bool serviceValid() const; + QString suffix() const; + void setSuffix(const QString &suffix); + + QVariant property(const char *propname); + void setProperty(const char *propname, const QVariant &value); + +Q_SIGNALS: + void serviceValidChanged(const bool valid) const; + +private: + QScopedPointer d_ptr; + Q_DECLARE_PRIVATE(DDBusInterface) + Q_DISABLE_COPY(DDBusInterface) +}; +DCORE_END_NAMESPACE diff -Nru dtkcore-5.5.33/include/util/ddbussender.h dtkcore-5.6.2/include/util/ddbussender.h --- dtkcore-5.5.33/include/util/ddbussender.h 1970-01-01 00:00:00.000000000 +0000 +++ dtkcore-5.6.2/include/util/ddbussender.h 2022-09-21 05:21:07.000000000 +0000 @@ -0,0 +1,101 @@ +// SPDX-FileCopyrightText: 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later + +#ifndef DDBUSSENDER_H +#define DDBUSSENDER_H + +#include "dtkcore_global.h" + +#include +#include +#include +#include + +#include + +class LIBDTKCORESHARED_EXPORT DDBusData +{ +public: + DDBusData(); + + QString service; + QString path; + QString interface; + QString queryName; + QDBusConnection connection; +}; + +class LIBDTKCORESHARED_EXPORT DDBusCaller +{ + friend class DDBusSender; + +public: + QDBusPendingCall call(); + + template + DDBusCaller arg(const T &argument); + +private: + explicit DDBusCaller(const QString &method, std::shared_ptr data); + +private: + std::shared_ptr m_dbusData; + QString m_methodName; + QVariantList m_arguments; +}; + +template +DDBusCaller DDBusCaller::arg(const T &argument) +{ + m_arguments << QVariant::fromValue(argument); + + return *this; +} + +class LIBDTKCORESHARED_EXPORT DDBusProperty +{ + friend class DDBusSender; + +public: + QDBusPendingCall get(); + template + QDBusPendingCall set(const T &value); + +private: + explicit DDBusProperty(const QString &property, std::shared_ptr data); + +private: + std::shared_ptr m_dbusData; + QString m_propertyName; +}; + +template +QDBusPendingCall DDBusProperty::set(const T &value) +{ + QDBusInterface iface(m_dbusData->service, m_dbusData->path, QStringLiteral("org.freedesktop.DBus.Properties"), m_dbusData->connection); + + const QVariantList args = { QVariant::fromValue(m_dbusData->interface), QVariant::fromValue(m_propertyName), QVariant::fromValue(QDBusVariant(value)) }; + + return iface.asyncCallWithArgumentList(QStringLiteral("Set"), args); +} + +class LIBDTKCORESHARED_EXPORT DDBusSender +{ +public: + explicit DDBusSender(); + + DDBusSender service(const QString &service); + DDBusSender interface(const QString &interface); + DDBusSender path(const QString &path); + DDBusCaller method(const QString &method); + DDBusProperty property(const QString &property); + +private: + DDBusSender type(const QDBusConnection::BusType busType); + +private: + std::shared_ptr m_dbusData; +}; + +#endif // DDBUSSENDER_H diff -Nru dtkcore-5.5.33/include/util/ddisksizeformatter.h dtkcore-5.6.2/include/util/ddisksizeformatter.h --- dtkcore-5.5.33/include/util/ddisksizeformatter.h 1970-01-01 00:00:00.000000000 +0000 +++ dtkcore-5.6.2/include/util/ddisksizeformatter.h 2022-09-21 05:21:07.000000000 +0000 @@ -0,0 +1,41 @@ +// SPDX-FileCopyrightText: 2017 - 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later + +#ifndef DISKSIZEFORMATTER_H +#define DISKSIZEFORMATTER_H + +#include "dabstractunitformatter.h" + +DCORE_BEGIN_NAMESPACE + +class LIBDTKCORESHARED_EXPORT DDiskSizeFormatter : public DAbstractUnitFormatter +{ +public: + DDiskSizeFormatter(); + + enum DiskUnits + { + B, + K, + M, + G, + T, + }; + + QString unitStr(int unitId) const override; + + DDiskSizeFormatter rate(int rate); + +protected: + int unitMin() const override { return B; } + int unitMax() const override { return T; } + uint unitConvertRate(int unitId) const override { Q_UNUSED(unitId); return m_rate; } + +private: + int m_rate = 1000; +}; + +DCORE_END_NAMESPACE + +#endif // DISKSIZEFORMATTER_H diff -Nru dtkcore-5.5.33/include/util/dexportedinterface.h dtkcore-5.6.2/include/util/dexportedinterface.h --- dtkcore-5.5.33/include/util/dexportedinterface.h 1970-01-01 00:00:00.000000000 +0000 +++ dtkcore-5.6.2/include/util/dexportedinterface.h 2022-09-21 05:21:07.000000000 +0000 @@ -0,0 +1,35 @@ +// SPDX-FileCopyrightText: 2017 - 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later + +#ifndef DEXPORTEDINTERFACE_H +#define DEXPORTEDINTERFACE_H + +#include +#include + +#include + +#include + +DCORE_BEGIN_NAMESPACE + +namespace DUtil { +class DExportedInterfacePrivate; +class LIBDTKCORESHARED_EXPORT DExportedInterface : public QObject, public DObject +{ + Q_OBJECT +public: + explicit DExportedInterface(QObject *parent = nullptr); + ~DExportedInterface(); + + void registerAction(const QString &action, const QString &description, const std::function handler = nullptr); + virtual QVariant invoke(const QString &action, const QString ¶meters) const; +private: + D_DECLARE_PRIVATE(DExportedInterface) +}; +} + +DCORE_END_NAMESPACE + +#endif diff -Nru dtkcore-5.5.33/include/util/dfileservices.h dtkcore-5.6.2/include/util/dfileservices.h --- dtkcore-5.5.33/include/util/dfileservices.h 1970-01-01 00:00:00.000000000 +0000 +++ dtkcore-5.6.2/include/util/dfileservices.h 2022-09-21 05:21:07.000000000 +0000 @@ -0,0 +1,42 @@ +// SPDX-FileCopyrightText: 2017 - 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later + +#ifndef DFILESERVICES_H +#define DFILESERVICES_H + +#include + +#include + +DCORE_BEGIN_NAMESPACE + +class LIBDTKCORESHARED_EXPORT DFileServices +{ +public: + static bool showFolder(QString localFilePath, const QString &startupId = QString()); + static bool showFolders(const QList localFilePaths, const QString &startupId = QString()); + static bool showFolder(QUrl url, const QString &startupId = QString()); + static bool showFolders(const QList urls, const QString &startupId = QString()); + + static bool showFileItemPropertie(QString localFilePath, const QString &startupId = QString()); + static bool showFileItemProperties(const QList localFilePaths, const QString &startupId = QString()); + static bool showFileItemPropertie(QUrl url, const QString &startupId = QString()); + static bool showFileItemProperties(const QList urls, const QString &startupId = QString()); + + static bool showFileItem(QString localFilePath, const QString &startupId = QString()); + static bool showFileItems(const QList localFilePaths, const QString &startupId = QString()); + static bool showFileItem(QUrl url, const QString &startupId = QString()); + static bool showFileItems(const QList urls, const QString &startupId = QString()); + + static bool trash(QString localFilePath); + static bool trash(const QList localFilePaths); + static bool trash(QUrl urlstartupId); + static bool trash(const QList urls); + + static QString errorMessage(); +}; + +DCORE_END_NAMESPACE + +#endif // DFILESERVICES_H diff -Nru dtkcore-5.5.33/include/util/dnotifysender.h dtkcore-5.6.2/include/util/dnotifysender.h --- dtkcore-5.5.33/include/util/dnotifysender.h 1970-01-01 00:00:00.000000000 +0000 +++ dtkcore-5.6.2/include/util/dnotifysender.h 2022-09-21 05:21:07.000000000 +0000 @@ -0,0 +1,36 @@ +// SPDX-FileCopyrightText: 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later + +#ifndef DNOTIFYSENDER_H +#define DNOTIFYSENDER_H + +#include "dtkcore_global.h" + +#include +#include + +DCORE_BEGIN_NAMESPACE + +namespace DUtil { +struct DNotifyData; +class LIBDTKCORESHARED_EXPORT DNotifySender { +public: + DNotifySender(const QString &summary); + DNotifySender appName(const QString &appName = QString()); + DNotifySender appIcon(const QString &appIcon = QString()); + DNotifySender appBody(const QString &appBody = QString()); + DNotifySender replaceId(const uint replaceId = 0); + DNotifySender timeOut(const int timeOut = -1); + DNotifySender actions(const QStringList &actions = QStringList()); + DNotifySender hints(const QVariantMap &hints = QVariantMap()); + QDBusPendingCall call(); + +private: + std::shared_ptr m_dbusData; +}; +} // namespace DUtil + +DCORE_END_NAMESPACE + +#endif // DNOTIFYSENDER_H diff -Nru dtkcore-5.5.33/include/util/dpinyin.h dtkcore-5.6.2/include/util/dpinyin.h --- dtkcore-5.5.33/include/util/dpinyin.h 1970-01-01 00:00:00.000000000 +0000 +++ dtkcore-5.6.2/include/util/dpinyin.h 2022-09-21 05:21:07.000000000 +0000 @@ -0,0 +1,18 @@ +// SPDX-FileCopyrightText: 2017 - 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later + +#ifndef DPINYIN_H +#define DPINYIN_H + +#include + +#include + +DCORE_BEGIN_NAMESPACE + +QString LIBDTKCORESHARED_EXPORT Chinese2Pinyin(const QString& words); + +DCORE_END_NAMESPACE + +#endif // DPINYIN_H diff -Nru dtkcore-5.5.33/include/util/drecentmanager.h dtkcore-5.6.2/include/util/drecentmanager.h --- dtkcore-5.5.33/include/util/drecentmanager.h 1970-01-01 00:00:00.000000000 +0000 +++ dtkcore-5.6.2/include/util/drecentmanager.h 2022-09-21 05:21:07.000000000 +0000 @@ -0,0 +1,30 @@ +// SPDX-FileCopyrightText: 2017 - 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later + +#ifndef DRECENTMANAGER_H +#define DRECENTMANAGER_H + +#include "dtkcore_global.h" +#include + +DCORE_BEGIN_NAMESPACE + +struct LIBDTKCORESHARED_EXPORT DRecentData +{ + QString appName; + QString appExec; + QString mimeType; +}; + +class LIBDTKCORESHARED_EXPORT DRecentManager +{ +public: + static bool addItem(const QString &uri, DRecentData &data); + static void removeItem(const QString &target); + static void removeItems(const QStringList &list); +}; + +DCORE_END_NAMESPACE + +#endif // DRECENTMANAGER_H diff -Nru dtkcore-5.5.33/include/util/dthreadutils.h dtkcore-5.6.2/include/util/dthreadutils.h --- dtkcore-5.5.33/include/util/dthreadutils.h 1970-01-01 00:00:00.000000000 +0000 +++ dtkcore-5.6.2/include/util/dthreadutils.h 2022-09-21 05:21:07.000000000 +0000 @@ -0,0 +1,158 @@ +// SPDX-FileCopyrightText: 2020 - 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later + +#ifndef DTHREADUTILS_H +#define DTHREADUTILS_H + +#include +#include +#include +#include +#include +#include +#include + +DCORE_BEGIN_NAMESPACE + +namespace DThreadUtil { +typedef std::function FunctionType; + +class LIBDTKCORESHARED_EXPORT FunctionCallProxy : public QObject +{ + Q_OBJECT +public: + explicit FunctionCallProxy(QThread *thread); + + static void proxyCall(QSemaphore *s, QThread *thread, QObject *target, FunctionType fun); + +Q_SIGNALS: + void callInLiveThread(QSemaphore *s, QPointer target, FunctionType *func); +}; + +template +class LIBDTKCORESHARED_EXPORT _TMP +{ +public: + inline static ReturnType runInThread(QSemaphore *s, QThread *thread, QObject *target, std::function fun) + { + ReturnType result; + FunctionType proxyFun = [&result, &fun] () { + result = fun(); + }; + + FunctionCallProxy::proxyCall(s, thread, target, proxyFun); + return result; + } + + template + inline static typename std::enable_if::value, ReturnType>::type + runInThread(QSemaphore *s, QThread *thread, T *, std::function fun) + { + return runInThread(s, thread, static_cast(nullptr), fun); + } +}; +template <> +class LIBDTKCORESHARED_EXPORT _TMP +{ +public: + inline static void runInThread(QSemaphore *s, QThread *thread, QObject *target, std::function fun) + { + FunctionCallProxy::proxyCall(s, thread, target, fun); + } + + template + inline static typename std::enable_if::value, void>::type + runInThread(QSemaphore *s, QThread *thread, T *, std::function fun) + { + return runInThread(s, thread, static_cast(nullptr), fun); + } +}; + +template +inline auto runInThread(QSemaphore *s, QThread *thread, QObject *target, Fun fun, Args&&... args) -> decltype(fun(args...)) +{ + return _TMP::runInThread(s, thread, target, std::bind(fun, std::forward(args)...)); +} +template +inline auto runInThread(QSemaphore *s, QThread *thread, Fun fun, Args&&... args) -> decltype(fun(args...)) +{ + return runInThread(s, thread, nullptr, fun, std::forward(args)...); +} +template +inline typename QtPrivate::FunctionPointer::ReturnType + runInThread(QSemaphore *s, QThread *thread, QObject *target, typename QtPrivate::FunctionPointer::Object *obj, Fun fun, Args&&... args) +{ + return _TMP::ReturnType>::runInThread(s, thread, target, std::bind(fun, obj, std::forward(args)...)); +} +template +inline typename QtPrivate::FunctionPointer::ReturnType + runInThread(QSemaphore *s, QThread *thread, typename QtPrivate::FunctionPointer::Object *obj, Fun fun, Args&&... args) +{ + return _TMP::ReturnType>::runInThread(s, thread, obj, std::bind(fun, obj, std::forward(args)...)); +} + +template +inline auto runInThread(QThread *thread, QObject *target, Fun fun, Args&&... args) -> decltype(fun(args...)) +{ + QSemaphore s; + + return runInThread(&s, thread, target, fun, std::forward(args)...); +} +template +inline auto runInThread(QThread *thread, Fun fun, Args&&... args) -> decltype(fun(args...)) +{ + return runInThread(thread, nullptr, fun, std::forward(args)...); +} +template +inline typename QtPrivate::FunctionPointer::ReturnType + runInThread(QThread *thread, T *target, typename QtPrivate::FunctionPointer::Object *obj, Fun fun, Args&&... args) +{ + QSemaphore s; + + return runInThread(&s, thread, target, obj, fun, std::forward(args)...); +} + +template +inline typename QtPrivate::FunctionPointer::ReturnType + runInThread(QThread *thread, typename QtPrivate::FunctionPointer::Object *obj, Fun fun, Args&&... args) +{ + return runInThread(thread, obj, obj, fun, std::forward(args)...); +} + +template +inline auto runInMainThread(QObject *target, Fun fun, Args&&... args) -> decltype(fun(args...)) +{ + if (!QCoreApplication::instance()) { + return fun(std::forward(args)...); + } + + return runInThread(QCoreApplication::instance()->thread(), target, fun, std::forward(args)...); +} +template +inline auto runInMainThread(Fun fun, Args&&... args) -> decltype(fun(args...)) +{ + return runInMainThread(nullptr, fun, std::forward(args)...); +} + +template +inline typename QtPrivate::FunctionPointer::ReturnType + runInMainThread(T *target, typename QtPrivate::FunctionPointer::Object *obj, Fun fun, Args&&... args) +{ + if (!QCoreApplication::instance()) { + return (obj->*fun)(std::forward(args)...); + } + + return runInThread(QCoreApplication::instance()->thread(), target, obj, fun, std::forward(args)...); +} +template +inline typename QtPrivate::FunctionPointer::ReturnType + runInMainThread(typename QtPrivate::FunctionPointer::Object *obj, Fun fun, Args&&... args) +{ + return runInMainThread(obj, obj, fun, std::forward(args)...); +} +} + +DCORE_END_NAMESPACE + +#endif // DTHREADUTILS_H diff -Nru dtkcore-5.5.33/include/util/dtimedloop.h dtkcore-5.6.2/include/util/dtimedloop.h --- dtkcore-5.5.33/include/util/dtimedloop.h 1970-01-01 00:00:00.000000000 +0000 +++ dtkcore-5.6.2/include/util/dtimedloop.h 2022-09-21 05:21:07.000000000 +0000 @@ -0,0 +1,46 @@ +// SPDX-FileCopyrightText: 2021 - 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later + +#ifndef DTIMEDLOOP_H +#define DTIMEDLOOP_H +#include +#include + +#include + +DCORE_BEGIN_NAMESPACE + +class DObject; +class DTimedLoopPrivate; +class DTimedLoop : public QEventLoop, public DObject { + Q_OBJECT +public: + explicit DTimedLoop() noexcept; + explicit DTimedLoop(QObject *parent) noexcept; + + ~DTimedLoop(); + + // 如果是 isRunning 则返回从开始到现在的 exec 执行时间,否则返回上次运行的时间 + int runningTime(); + void setTimeDump(bool flag = true); + + void exit(int returnCode = 0); + + // 方式1:不传定时时间,如果不退出就一直执行,配合 exit 使用 + // 方式2:传入durationMs 参数的是定时执行的,也能调用 exit 提前退出 + // 如果传入了 executionName 就会为本次执行设置一个名字,会输出到 log + // 在执行结束将会打印 exec 的执行时间,可以用 setTimeDump 控制其是否打印 + int exec(QEventLoop::ProcessEventsFlags flags = QEventLoop::AllEvents); + int exec(int durationMs, QEventLoop::ProcessEventsFlags flags = QEventLoop::AllEvents); + int exec(const QString &executionName, QEventLoop::ProcessEventsFlags flags = QEventLoop::AllEvents); + int exec(int durationMs, const QString &executionName, QEventLoop::ProcessEventsFlags flags = QEventLoop::AllEvents); + +private: + Q_DISABLE_COPY(DTimedLoop) + D_DECLARE_PRIVATE(DTimedLoop) +}; + +DCORE_END_NAMESPACE + +#endif // DTIMEDLOOP_H diff -Nru dtkcore-5.5.33/include/util/dtimeunitformatter.h dtkcore-5.6.2/include/util/dtimeunitformatter.h --- dtkcore-5.5.33/include/util/dtimeunitformatter.h 1970-01-01 00:00:00.000000000 +0000 +++ dtkcore-5.6.2/include/util/dtimeunitformatter.h 2022-09-21 05:21:07.000000000 +0000 @@ -0,0 +1,36 @@ +// SPDX-FileCopyrightText: 2017 - 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later + +#ifndef DTIMEUNITFORMATTER_H +#define DTIMEUNITFORMATTER_H + +#include "dtkcore_global.h" +#include "dabstractunitformatter.h" + +DCORE_BEGIN_NAMESPACE + +class LIBDTKCORESHARED_EXPORT DTimeUnitFormatter : public DAbstractUnitFormatter +{ +public: + DTimeUnitFormatter(); + + enum TimeUnits + { + Seconds, + Minute, + Hour, + Day, + }; + + QString unitStr(int unitId) const override; + +protected: + int unitMax() const override { return Day; } + int unitMin() const override { return Seconds; } + uint unitConvertRate(int unitId) const override; +}; + +DCORE_END_NAMESPACE + +#endif // DTIMEUNITFORMATTER_H diff -Nru dtkcore-5.5.33/include/util/dutil.h dtkcore-5.6.2/include/util/dutil.h --- dtkcore-5.5.33/include/util/dutil.h 1970-01-01 00:00:00.000000000 +0000 +++ dtkcore-5.6.2/include/util/dutil.h 2022-09-21 05:21:07.000000000 +0000 @@ -0,0 +1,47 @@ +// SPDX-FileCopyrightText: 2016 - 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later + +#pragma once + +#include +#include +#include +#include + +namespace DUtil +{ + +template +inline void TimerSingleShot(int msec, Func1 slot) +{ +#if QT_VERSION >= 0x050500 + QTimer::singleShot(msec, slot); +#else + QTimer *timer = new QTimer; + timer->setSingleShot(true); + timer->setInterval(msec); + timer->moveToThread(qApp->thread()); + QObject::connect(timer, &QTimer::timeout, slot); + QObject::connect(timer, &QTimer::timeout, timer, &QTimer::deleteLater); + if (QThread::currentThread() == qApp->thread()) { timer->start(); } + else { QMetaObject::invokeMethod(timer, "start", Qt::QueuedConnection); } +#endif +} + +template +void SecureErase(T *p, size_t size) +{ + memset(p, 0, size); +} + +template +void SecureErase(T &obj) +{ + for (typename T::iterator i = obj.begin(); i != obj.end(); ++i) { + *i = 0; + } + obj.clear(); +} + +} diff -Nru dtkcore-5.5.33/include/util/dvtablehook.h dtkcore-5.6.2/include/util/dvtablehook.h --- dtkcore-5.5.33/include/util/dvtablehook.h 1970-01-01 00:00:00.000000000 +0000 +++ dtkcore-5.6.2/include/util/dvtablehook.h 2022-09-21 05:21:07.000000000 +0000 @@ -0,0 +1,338 @@ +// SPDX-FileCopyrightText: 2019 - 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later + +#ifndef DVTABLEHOOK_H +#define DVTABLEHOOK_H + +#include + +#include +#include +#include + +#include +#include + +DCORE_BEGIN_NAMESPACE + +class LIBDTKCORESHARED_EXPORT DVtableHook +{ +public: + static inline quintptr toQuintptr(const void *ptr) + { + return *(quintptr*)ptr; + } + + static inline int getVtableSize(quintptr **obj) + { + quintptr *begin = *obj; + while(*begin) ++begin; + return begin - *obj; + } + + static inline quintptr *getVtableOfObject(const void *obj) + { + return *(quintptr**)obj; + } + + template + static quintptr *getVtableOfClass() + { + QByteArray vtable_symbol(typeid(T).name()); + vtable_symbol.prepend("_ZTV"); + + quintptr *vfptr_t1 = reinterpret_cast(resolve(vtable_symbol.constData())); + + if (!vfptr_t1) + return nullptr; + + // symbol address + 2 * sizeof(quintptr) = virtal table start address + return vfptr_t1 + 2; + } + + static int getDestructFunIndex(quintptr **obj, std::function destoryObjFun); + static constexpr const QObject *getQObject(...) { return nullptr;} + static constexpr const QObject *getQObject(const QObject *obj) { return obj;} + static void autoCleanVtable(const void *obj); + static bool ensureVtable(const void *obj, std::function destoryObjFun); + static bool hasVtable(const void *obj); + static void resetVtable(const void *obj); + static quintptr resetVfptrFun(const void *obj, quintptr functionOffset); + static quintptr originalFun(const void *obj, quintptr functionOffset); + static bool forceWriteMemory(void *adr, const void *data, size_t length); + static QFunctionPointer resolve(const char *symbol); + + template class OverrideDestruct : public T { ~OverrideDestruct() override;}; + template struct CheckCompatibleArguments { enum { value = false }; }; + template struct CheckCompatibleArguments { enum { value = true }; }; + + template + static bool overrideVfptrFun(quintptr *vfptr_t1, Fun1 fun1, quintptr *vfptr_t2, Fun2 fun2, bool forceWrite) + { + typedef QtPrivate::FunctionPointer FunInfo1; + typedef QtPrivate::FunctionPointer FunInfo2; + + //compilation error if the arguments does not match. + Q_STATIC_ASSERT_X((CheckCompatibleArguments::value), + "Function1 and Function2 arguments are not compatible."); + Q_STATIC_ASSERT_X((CheckCompatibleArguments, QtPrivate::List>::value), + "Function1 and Function2 return type are not compatible.."); + + //! ({code}) in the form of a code is to eliminate - Wstrict - aliasing build warnings + quintptr fun1_offset = toQuintptr(&fun1); + quintptr fun2_offset = toQuintptr(&fun2); + + if (fun1_offset < 0 || fun1_offset > UINT_LEAST16_MAX) + return false; + + quintptr *vfun = vfptr_t1 + fun1_offset / sizeof(quintptr); + + // if the fun2 is not virtual function + if (fun2_offset <= UINT_LEAST16_MAX) { + fun2_offset = *(vfptr_t2 + fun2_offset / sizeof(quintptr)); + } + + if (forceWrite) + return forceWriteMemory(vfun, &fun2_offset, sizeof(fun2_offset)); + + *vfun = fun2_offset; + + return true; + } + + template + static bool overrideVfptrFun(const typename QtPrivate::FunctionPointer::Object *t1, Fun1 fun1, + const typename QtPrivate::FunctionPointer::Object *t2, Fun2 fun2) + { + typedef QtPrivate::FunctionPointer FunInfo1; + // 检查析构函数是否为虚 + class OverrideDestruct : public FunInfo1::Object { ~OverrideDestruct() override;}; + + if (!ensureVtable((void*)t1, std::bind(&_destory_helper, t1))) { + return false; + } + + quintptr *vfptr_t1 = getVtableOfObject(t1); + quintptr *vfptr_t2 = getVtableOfObject(t2); + + bool ok = overrideVfptrFun(vfptr_t1, fun1, vfptr_t2, fun2, false); + + if (!ok) { + // 恢复旧环境 + resetVtable(t1); + } + + return ok; + } + + template + static bool overrideVfptrFun(Fun1 fun1, const typename QtPrivate::FunctionPointer::Object *t2, Fun2 fun2) + { + quintptr *vfptr_t1 = getVtableOfClass(); + + if (!vfptr_t1) { + abort(); + } + + quintptr *vfptr_t2 = getVtableOfObject(t2); + + return overrideVfptrFun(vfptr_t1, fun1, vfptr_t2, fun2, true); + } + + template + static bool overrideVfptrFun(Fun1 fun1, const typename QtPrivate::FunctionPointer::Object *t2, Fun2 fun2) + { + typedef QtPrivate::FunctionPointer FunInfo1; + return overrideVfptrFun(fun1, t2, fun2); + } + + template struct FunctionPointer { }; + template struct FunctionPointer + { + typedef QtPrivate::List Arguments; + }; + template struct FunctionPointer + { + typedef QtPrivate::List Arguments; + }; + template + static typename std::enable_if::ArgumentCount >= 0, bool>::type + overrideVfptrFun(quintptr *vfptr_t1, Fun1 fun1, Fun2 fun2, bool forceWrite) + { + typedef QtPrivate::FunctionPointer FunInfo1; + typedef QtPrivate::FunctionPointer FunInfo2; + + Q_STATIC_ASSERT(!FunInfo2::IsPointerToMemberFunction); + //compilation error if the arguments does not match. + Q_STATIC_ASSERT_X((CheckCompatibleArguments::Arguments, typename FunInfo2::Arguments>::value), + "Function1 and Function2 arguments are not compatible."); + Q_STATIC_ASSERT_X((CheckCompatibleArguments, QtPrivate::List>::value), + "Function1 and Function2 return type are not compatible.."); + + //! ({code}) in the form of a code is to eliminate - Wstrict - aliasing build warnings + quintptr fun1_offset = toQuintptr(&fun1); + quintptr fun2_offset = toQuintptr(&fun2); + + if (fun1_offset < 0 || fun1_offset > UINT_LEAST16_MAX) + return false; + + quintptr *vfun = vfptr_t1 + fun1_offset / sizeof(quintptr); + + if (forceWrite) + return forceWriteMemory(vfun, &fun2_offset, sizeof(fun2_offset)); + + *vfun = fun2_offset; + + return true; + } + + template struct StdFunWrap {}; + template + struct StdFunWrap { + typedef std::function StdFunType; + static inline StdFunType fun(StdFunType f, bool check = true) { + static StdFunType fun = f; + static bool initialized = false; + if (initialized && check) { + qWarning("The StdFunWrap is dirty! Don't use std::bind(use lambda functions)."); + } + initialized = true; + return fun; + } + static Ret call(Obj *o, Args... args) { + return fun(call, false)(o, std::forward(args)...); + } + }; + template + struct StdFunWrap : StdFunWrap{}; + + template + static inline typename std::enable_if::ArgumentCount == -1, bool>::type + overrideVfptrFun(quintptr *vfptr_t1, Fun1 fun1, Fun2 fun2, bool forceWrite) + { + typedef QtPrivate::FunctionPointer FunInfo1; + const int FunctorArgumentCount = QtPrivate::ComputeFunctorArgumentCount::Arguments>::Value; + + Q_STATIC_ASSERT_X((FunctorArgumentCount >= 0), + "Function1 and Function2 arguments are not compatible."); + const int Fun2ArgumentCount = (FunctorArgumentCount >= 0) ? FunctorArgumentCount : 0; + typedef typename QtPrivate::FunctorReturnType::Arguments, Fun2ArgumentCount>::Value>::Value Fun2ReturnType; + + Q_STATIC_ASSERT_X((QtPrivate::AreArgumentsCompatible::value), + "Function1 and Function2 return type are not compatible."); + + StdFunWrap::fun(fun2); + return overrideVfptrFun(vfptr_t1, fun1, StdFunWrap::call, forceWrite); + } + + /*! + * \fn template static bool overrideVfptrFun(const typename QtPrivate::FunctionPointer::Object *t1, Fun1 fun1, Fun2 fun2) + * + * \note 重载多继承类中的多个虚函数时,fun1务必标记成一个类名的函数。否则可能出现内存泄露的情况 + * \note 例如 class A 继承于 B,C,D,当需要重载B中的foo1,C中的foo2时,以下函数的fun1需要统一标记为&A::foo1和&A::foo2 + * \note 因为如果分开写为&B::foo1和&C::foo2的话,指针转换内部会记录多张虚表,重载多份析构函数,可能导致最开始的部分无法正常析构! + */ + template + static bool overrideVfptrFun(const typename QtPrivate::FunctionPointer::Object *t1, Fun1 fun1, Fun2 fun2) + { + typedef QtPrivate::FunctionPointer FunInfo1; + // 检查析构函数是否为虚 + class OverrideDestruct : public FunInfo1::Object { ~OverrideDestruct() override;}; + + if (!ensureVtable((void*)t1, std::bind(&_destory_helper, t1))) { + return false; + } + + bool ok = overrideVfptrFun(getVtableOfObject(t1), fun1, fun2, false); + + if (!ok) { + // 恢复旧环境 + resetVtable(t1); + } + + return true; + } + + template + static bool overrideVfptrFun(Fun1 fun1, Fun2 fun2) + { + quintptr *vfptr_t1 = getVtableOfClass(); + + if (!vfptr_t1) { + abort(); + } + + return overrideVfptrFun(vfptr_t1, fun1, fun2, true); + } + + template + static bool overrideVfptrFun(Fun1 fun1, Fun2 fun2) + { + typedef QtPrivate::FunctionPointer FunInfo1; + return overrideVfptrFun(fun1, fun2); + } + + template + static bool resetVfptrFun(const typename QtPrivate::FunctionPointer::Object *obj, Fun1 fun) + { + return resetVfptrFun((void*)obj, toQuintptr(&fun)) > 0; + } + + template + static Fun originalFun(const typename QtPrivate::FunctionPointer::Object *obj, Fun fun) + { + quintptr o_fun = originalFun((void*)obj, toQuintptr(&fun)); + + return *reinterpret_cast(o_fun); + } + + template + static typename QtPrivate::FunctionPointer::ReturnType + callOriginalFun(typename QtPrivate::FunctionPointer::Object *obj, Fun fun, Args&&... args) + { + quintptr fun_offset = toQuintptr(&fun); + + class _ResetVFun + { + public: + ~_ResetVFun() { + *(vfptr + offset / sizeof(quintptr)) = oldFun; + } + quintptr *vfptr = nullptr; + quint16 offset = 0; + quintptr oldFun = 0; + }; + + _ResetVFun rvf; + + rvf.vfptr = *(quintptr**)(obj); + rvf.offset = fun_offset; + rvf.oldFun = DVtableHook::resetVfptrFun((void*)obj, fun_offset); + + if (!rvf.oldFun) { + qWarning() << "Reset the function failed, object:" << obj; + abort(); + } + + // call + return (obj->*fun)(std::forward(args)...); + } + +private: + static bool copyVtable(quintptr **obj); + static bool clearGhostVtable(const void *obj); + + template + static void _destory_helper(const T *obj) { + delete obj; + } + + static QMap objToOriginalVfptr; + static QMap objToGhostVfptr; + static QMap objDestructFun; +}; + +DCORE_END_NAMESPACE + +#endif // DVTABLEHOOK_H diff -Nru dtkcore-5.5.33/LICENSES/CC0-1.0.txt dtkcore-5.6.2/LICENSES/CC0-1.0.txt --- dtkcore-5.5.33/LICENSES/CC0-1.0.txt 1970-01-01 00:00:00.000000000 +0000 +++ dtkcore-5.6.2/LICENSES/CC0-1.0.txt 2022-09-21 05:21:07.000000000 +0000 @@ -0,0 +1,121 @@ +Creative Commons Legal Code + +CC0 1.0 Universal + + CREATIVE COMMONS CORPORATION IS NOT A LAW FIRM AND DOES NOT PROVIDE + LEGAL SERVICES. DISTRIBUTION OF THIS DOCUMENT DOES NOT CREATE AN + ATTORNEY-CLIENT RELATIONSHIP. CREATIVE COMMONS PROVIDES THIS + INFORMATION ON AN "AS-IS" BASIS. CREATIVE COMMONS MAKES NO WARRANTIES + REGARDING THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS + PROVIDED HEREUNDER, AND DISCLAIMS LIABILITY FOR DAMAGES RESULTING FROM + THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS PROVIDED + HEREUNDER. + +Statement of Purpose + +The laws of most jurisdictions throughout the world automatically confer +exclusive Copyright and Related Rights (defined below) upon the creator +and subsequent owner(s) (each and all, an "owner") of an original work of +authorship and/or a database (each, a "Work"). + +Certain owners wish to permanently relinquish those rights to a Work for +the purpose of contributing to a commons of creative, cultural and +scientific works ("Commons") that the public can reliably and without fear +of later claims of infringement build upon, modify, incorporate in other +works, reuse and redistribute as freely as possible in any form whatsoever +and for any purposes, including without limitation commercial purposes. +These owners may contribute to the Commons to promote the ideal of a free +culture and the further production of creative, cultural and scientific +works, or to gain reputation or greater distribution for their Work in +part through the use and efforts of others. + +For these and/or other purposes and motivations, and without any +expectation of additional consideration or compensation, the person +associating CC0 with a Work (the "Affirmer"), to the extent that he or she +is an owner of Copyright and Related Rights in the Work, voluntarily +elects to apply CC0 to the Work and publicly distribute the Work under its +terms, with knowledge of his or her Copyright and Related Rights in the +Work and the meaning and intended legal effect of CC0 on those rights. + +1. Copyright and Related Rights. A Work made available under CC0 may be +protected by copyright and related or neighboring rights ("Copyright and +Related Rights"). Copyright and Related Rights include, but are not +limited to, the following: + + i. the right to reproduce, adapt, distribute, perform, display, + communicate, and translate a Work; + ii. moral rights retained by the original author(s) and/or performer(s); +iii. publicity and privacy rights pertaining to a person's image or + likeness depicted in a Work; + iv. rights protecting against unfair competition in regards to a Work, + subject to the limitations in paragraph 4(a), below; + v. rights protecting the extraction, dissemination, use and reuse of data + in a Work; + vi. database rights (such as those arising under Directive 96/9/EC of the + European Parliament and of the Council of 11 March 1996 on the legal + protection of databases, and under any national implementation + thereof, including any amended or successor version of such + directive); and +vii. other similar, equivalent or corresponding rights throughout the + world based on applicable law or treaty, and any national + implementations thereof. + +2. Waiver. To the greatest extent permitted by, but not in contravention +of, applicable law, Affirmer hereby overtly, fully, permanently, +irrevocably and unconditionally waives, abandons, and surrenders all of +Affirmer's Copyright and Related Rights and associated claims and causes +of action, whether now known or unknown (including existing as well as +future claims and causes of action), in the Work (i) in all territories +worldwide, (ii) for the maximum duration provided by applicable law or +treaty (including future time extensions), (iii) in any current or future +medium and for any number of copies, and (iv) for any purpose whatsoever, +including without limitation commercial, advertising or promotional +purposes (the "Waiver"). Affirmer makes the Waiver for the benefit of each +member of the public at large and to the detriment of Affirmer's heirs and +successors, fully intending that such Waiver shall not be subject to +revocation, rescission, cancellation, termination, or any other legal or +equitable action to disrupt the quiet enjoyment of the Work by the public +as contemplated by Affirmer's express Statement of Purpose. + +3. Public License Fallback. Should any part of the Waiver for any reason +be judged legally invalid or ineffective under applicable law, then the +Waiver shall be preserved to the maximum extent permitted taking into +account Affirmer's express Statement of Purpose. In addition, to the +extent the Waiver is so judged Affirmer hereby grants to each affected +person a royalty-free, non transferable, non sublicensable, non exclusive, +irrevocable and unconditional license to exercise Affirmer's Copyright and +Related Rights in the Work (i) in all territories worldwide, (ii) for the +maximum duration provided by applicable law or treaty (including future +time extensions), (iii) in any current or future medium and for any number +of copies, and (iv) for any purpose whatsoever, including without +limitation commercial, advertising or promotional purposes (the +"License"). The License shall be deemed effective as of the date CC0 was +applied by Affirmer to the Work. Should any part of the License for any +reason be judged legally invalid or ineffective under applicable law, such +partial invalidity or ineffectiveness shall not invalidate the remainder +of the License, and in such case Affirmer hereby affirms that he or she +will not (i) exercise any of his or her remaining Copyright and Related +Rights in the Work or (ii) assert any associated claims and causes of +action with respect to the Work, in either case contrary to Affirmer's +express Statement of Purpose. + +4. Limitations and Disclaimers. + + a. No trademark or patent rights held by Affirmer are waived, abandoned, + surrendered, licensed or otherwise affected by this document. + b. Affirmer offers the Work as-is and makes no representations or + warranties of any kind concerning the Work, express, implied, + statutory or otherwise, including without limitation warranties of + title, merchantability, fitness for a particular purpose, non + infringement, or the absence of latent or other defects, accuracy, or + the present or absence of errors, whether or not discoverable, all to + the greatest extent permissible under applicable law. + c. Affirmer disclaims responsibility for clearing rights of other persons + that may apply to the Work or any use thereof, including without + limitation any person's Copyright and Related Rights in the Work. + Further, Affirmer disclaims responsibility for obtaining any necessary + consents, permissions or other rights required for any use of the + Work. + d. Affirmer understands and acknowledges that Creative Commons is not a + party to this document and has no duty or obligation with respect to + this CC0 or use of the Work. diff -Nru dtkcore-5.5.33/LICENSES/LGPL-3.0-or-later.txt dtkcore-5.6.2/LICENSES/LGPL-3.0-or-later.txt --- dtkcore-5.5.33/LICENSES/LGPL-3.0-or-later.txt 1970-01-01 00:00:00.000000000 +0000 +++ dtkcore-5.6.2/LICENSES/LGPL-3.0-or-later.txt 2022-09-21 05:21:07.000000000 +0000 @@ -0,0 +1,304 @@ +GNU LESSER GENERAL PUBLIC LICENSE +Version 3, 29 June 2007 + +Copyright (C) 2007 Free Software Foundation, Inc. + +Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. + +This version of the GNU Lesser General Public License incorporates the terms and conditions of version 3 of the GNU General Public License, supplemented by the additional permissions listed below. + +0. Additional Definitions. + +As used herein, "this License" refers to version 3 of the GNU Lesser General Public License, and the "GNU GPL" refers to version 3 of the GNU General Public License. + +"The Library" refers to a covered work governed by this License, other than an Application or a Combined Work as defined below. + +An "Application" is any work that makes use of an interface provided by the Library, but which is not otherwise based on the Library. Defining a subclass of a class defined by the Library is deemed a mode of using an interface provided by the Library. + +A "Combined Work" is a work produced by combining or linking an Application with the Library. The particular version of the Library with which the Combined Work was made is also called the "Linked Version". + +The "Minimal Corresponding Source" for a Combined Work means the Corresponding Source for the Combined Work, excluding any source code for portions of the Combined Work that, considered in isolation, are based on the Application, and not on the Linked Version. + +The "Corresponding Application Code" for a Combined Work means the object code and/or source code for the Application, including any data and utility programs needed for reproducing the Combined Work from the Application, but excluding the System Libraries of the Combined Work. + +1. Exception to Section 3 of the GNU GPL. +You may convey a covered work under sections 3 and 4 of this License without being bound by section 3 of the GNU GPL. + +2. Conveying Modified Versions. +If you modify a copy of the Library, and, in your modifications, a facility refers to a function or data to be supplied by an Application that uses the facility (other than as an argument passed when the facility is invoked), then you may convey a copy of the modified version: + + a) under this License, provided that you make a good faith effort to ensure that, in the event an Application does not supply the function or data, the facility still operates, and performs whatever part of its purpose remains meaningful, or + + b) under the GNU GPL, with none of the additional permissions of this License applicable to that copy. + +3. Object Code Incorporating Material from Library Header Files. +The object code form of an Application may incorporate material from a header file that is part of the Library. You may convey such object code under terms of your choice, provided that, if the incorporated material is not limited to numerical parameters, data structure layouts and accessors, or small macros, inline functions and templates (ten or fewer lines in length), you do both of the following: + + a) Give prominent notice with each copy of the object code that the Library is used in it and that the Library and its use are covered by this License. + + b) Accompany the object code with a copy of the GNU GPL and this license document. + +4. Combined Works. +You may convey a Combined Work under terms of your choice that, taken together, effectively do not restrict modification of the portions of the Library contained in the Combined Work and reverse engineering for debugging such modifications, if you also do each of the following: + + a) Give prominent notice with each copy of the Combined Work that the Library is used in it and that the Library and its use are covered by this License. + + b) Accompany the Combined Work with a copy of the GNU GPL and this license document. + + c) For a Combined Work that displays copyright notices during execution, include the copyright notice for the Library among these notices, as well as a reference directing the user to the copies of the GNU GPL and this license document. + + d) Do one of the following: + + 0) Convey the Minimal Corresponding Source under the terms of this License, and the Corresponding Application Code in a form suitable for, and under terms that permit, the user to recombine or relink the Application with a modified version of the Linked Version to produce a modified Combined Work, in the manner specified by section 6 of the GNU GPL for conveying Corresponding Source. + + 1) Use a suitable shared library mechanism for linking with the Library. A suitable mechanism is one that (a) uses at run time a copy of the Library already present on the user's computer system, and (b) will operate properly with a modified version of the Library that is interface-compatible with the Linked Version. + + e) Provide Installation Information, but only if you would otherwise be required to provide such information under section 6 of the GNU GPL, and only to the extent that such information is necessary to install and execute a modified version of the Combined Work produced by recombining or relinking the Application with a modified version of the Linked Version. (If you use option 4d0, the Installation Information must accompany the Minimal Corresponding Source and Corresponding Application Code. If you use option 4d1, you must provide the Installation Information in the manner specified by section 6 of the GNU GPL for conveying Corresponding Source.) + +5. Combined Libraries. +You may place library facilities that are a work based on the Library side by side in a single library together with other library facilities that are not Applications and are not covered by this License, and convey such a combined library under terms of your choice, if you do both of the following: + + a) Accompany the combined library with a copy of the same work based on the Library, uncombined with any other library facilities, conveyed under the terms of this License. + + b) Give prominent notice with the combined library that part of it is a work based on the Library, and explaining where to find the accompanying uncombined form of the same work. + +6. Revised Versions of the GNU Lesser General Public License. +The Free Software Foundation may publish revised and/or new versions of the GNU Lesser General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. + +Each version is given a distinguishing version number. If the Library as you received it specifies that a certain numbered version of the GNU Lesser General Public License "or any later version" applies to it, you have the option of following the terms and conditions either of that published version or of any later version published by the Free Software Foundation. If the Library as you received it does not specify a version number of the GNU Lesser General Public License, you may choose any version of the GNU Lesser General Public License ever published by the Free Software Foundation. + +If the Library as you received it specifies that a proxy can decide whether future versions of the GNU Lesser General Public License shall +apply, that proxy's public statement of acceptance of any version is permanent authorization for you to choose that version for the Library. + +GNU GENERAL PUBLIC LICENSE +Version 3, 29 June 2007 + +Copyright © 2007 Free Software Foundation, Inc. + +Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. + +Preamble + +The GNU General Public License is a free, copyleft license for software and other kinds of works. + +The licenses for most software and other practical works are designed to take away your freedom to share and change the works. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change all versions of a program--to make sure it remains free software for all its users. We, the Free Software Foundation, use the GNU General Public License for most of our software; it applies also to any other work released this way by its authors. You can apply it to your programs, too. + +When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for them if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs, and that you know you can do these things. + +To protect your rights, we need to prevent others from denying you these rights or asking you to surrender the rights. Therefore, you have certain responsibilities if you distribute copies of the software, or if you modify it: responsibilities to respect the freedom of others. + +For example, if you distribute copies of such a program, whether gratis or for a fee, you must pass on to the recipients the same freedoms that you received. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. + +Developers that use the GNU GPL protect your rights with two steps: (1) assert copyright on the software, and (2) offer you this License giving you legal permission to copy, distribute and/or modify it. + +For the developers' and authors' protection, the GPL clearly explains that there is no warranty for this free software. For both users' and authors' sake, the GPL requires that modified versions be marked as changed, so that their problems will not be attributed erroneously to authors of previous versions. + +Some devices are designed to deny users access to install or run modified versions of the software inside them, although the manufacturer can do so. This is fundamentally incompatible with the aim of protecting users' freedom to change the software. The systematic pattern of such abuse occurs in the area of products for individuals to use, which is precisely where it is most unacceptable. Therefore, we have designed this version of the GPL to prohibit the practice for those products. If such problems arise substantially in other domains, we stand ready to extend this provision to those domains in future versions of the GPL, as needed to protect the freedom of users. + +Finally, every program is threatened constantly by software patents. States should not allow patents to restrict development and use of software on general-purpose computers, but in those that do, we wish to avoid the special danger that patents applied to a free program could make it effectively proprietary. To prevent this, the GPL assures that patents cannot be used to render the program non-free. + +The precise terms and conditions for copying, distribution and modification follow. + +TERMS AND CONDITIONS + +0. Definitions. + +“This License” refers to version 3 of the GNU General Public License. + +“Copyright” also means copyright-like laws that apply to other kinds of works, such as semiconductor masks. + +“The Program” refers to any copyrightable work licensed under this License. Each licensee is addressed as “you”. “Licensees” and “recipients” may be individuals or organizations. + +To “modify” a work means to copy from or adapt all or part of the work in a fashion requiring copyright permission, other than the making of an exact copy. The resulting work is called a “modified version” of the earlier work or a work “based on” the earlier work. + +A “covered work” means either the unmodified Program or a work based on the Program. + +To “propagate” a work means to do anything with it that, without permission, would make you directly or secondarily liable for infringement under applicable copyright law, except executing it on a computer or modifying a private copy. Propagation includes copying, distribution (with or without modification), making available to the public, and in some countries other activities as well. + +To “convey” a work means any kind of propagation that enables other parties to make or receive copies. Mere interaction with a user through a computer network, with no transfer of a copy, is not conveying. + +An interactive user interface displays “Appropriate Legal Notices” to the extent that it includes a convenient and prominently visible feature that (1) displays an appropriate copyright notice, and (2) tells the user that there is no warranty for the work (except to the extent that warranties are provided), that licensees may convey the work under this License, and how to view a copy of this License. If the interface presents a list of user commands or options, such as a menu, a prominent item in the list meets this criterion. + +1. Source Code. +The “source code” for a work means the preferred form of the work for making modifications to it. “Object code” means any non-source form of a work. + +A “Standard Interface” means an interface that either is an official standard defined by a recognized standards body, or, in the case of interfaces specified for a particular programming language, one that is widely used among developers working in that language. + +The “System Libraries” of an executable work include anything, other than the work as a whole, that (a) is included in the normal form of packaging a Major Component, but which is not part of that Major Component, and (b) serves only to enable use of the work with that Major Component, or to implement a Standard Interface for which an implementation is available to the public in source code form. A “Major Component”, in this context, means a major essential component (kernel, window system, and so on) of the specific operating system (if any) on which the executable work runs, or a compiler used to produce the work, or an object code interpreter used to run it. + +The “Corresponding Source” for a work in object code form means all the source code needed to generate, install, and (for an executable work) run the object code and to modify the work, including scripts to control those activities. However, it does not include the work's System Libraries, or general-purpose tools or generally available free programs which are used unmodified in performing those activities but which are not part of the work. For example, Corresponding Source includes interface definition files associated with source files for the work, and the source code for shared libraries and dynamically linked subprograms that the work is specifically designed to require, such as by intimate data communication or control flow between those subprograms and other parts of the work. + +The Corresponding Source need not include anything that users can regenerate automatically from other parts of the Corresponding Source. + +The Corresponding Source for a work in source code form is that same work. + +2. Basic Permissions. +All rights granted under this License are granted for the term of copyright on the Program, and are irrevocable provided the stated conditions are met. This License explicitly affirms your unlimited permission to run the unmodified Program. The output from running a covered work is covered by this License only if the output, given its content, constitutes a covered work. This License acknowledges your rights of fair use or other equivalent, as provided by copyright law. + +You may make, run and propagate covered works that you do not convey, without conditions so long as your license otherwise remains in force. You may convey covered works to others for the sole purpose of having them make modifications exclusively for you, or provide you with facilities for running those works, provided that you comply with the terms of this License in conveying all material for which you do not control copyright. Those thus making or running the covered works for you must do so exclusively on your behalf, under your direction and control, on terms that prohibit them from making any copies of your copyrighted material outside their relationship with you. + +Conveying under any other circumstances is permitted solely under the conditions stated below. Sublicensing is not allowed; section 10 makes it unnecessary. + +3. Protecting Users' Legal Rights From Anti-Circumvention Law. +No covered work shall be deemed part of an effective technological measure under any applicable law fulfilling obligations under article 11 of the WIPO copyright treaty adopted on 20 December 1996, or similar laws prohibiting or restricting circumvention of such measures. + +When you convey a covered work, you waive any legal power to forbid circumvention of technological measures to the extent such circumvention is effected by exercising rights under this License with respect to the covered work, and you disclaim any intention to limit operation or modification of the work as a means of enforcing, against the work's users, your or third parties' legal rights to forbid circumvention of technological measures. + +4. Conveying Verbatim Copies. +You may convey verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice; keep intact all notices stating that this License and any non-permissive terms added in accord with section 7 apply to the code; keep intact all notices of the absence of any warranty; and give all recipients a copy of this License along with the Program. + +You may charge any price or no price for each copy that you convey, and you may offer support or warranty protection for a fee. + +5. Conveying Modified Source Versions. +You may convey a work based on the Program, or the modifications to produce it from the Program, in the form of source code under the terms of section 4, provided that you also meet all of these conditions: + + a) The work must carry prominent notices stating that you modified it, and giving a relevant date. + + b) The work must carry prominent notices stating that it is released under this License and any conditions added under section 7. This requirement modifies the requirement in section 4 to “keep intact all notices”. + + c) You must license the entire work, as a whole, under this License to anyone who comes into possession of a copy. This License will therefore apply, along with any applicable section 7 additional terms, to the whole of the work, and all its parts, regardless of how they are packaged. This License gives no permission to license the work in any other way, but it does not invalidate such permission if you have separately received it. + + d) If the work has interactive user interfaces, each must display Appropriate Legal Notices; however, if the Program has interactive interfaces that do not display Appropriate Legal Notices, your work need not make them do so. + +A compilation of a covered work with other separate and independent works, which are not by their nature extensions of the covered work, and which are not combined with it such as to form a larger program, in or on a volume of a storage or distribution medium, is called an “aggregate” if the compilation and its resulting copyright are not used to limit the access or legal rights of the compilation's users beyond what the individual works permit. Inclusion of a covered work in an aggregate does not cause this License to apply to the other parts of the aggregate. + +6. Conveying Non-Source Forms. +You may convey a covered work in object code form under the terms of sections 4 and 5, provided that you also convey the machine-readable Corresponding Source under the terms of this License, in one of these ways: + + a) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by the Corresponding Source fixed on a durable physical medium customarily used for software interchange. + + b) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by a written offer, valid for at least three years and valid for as long as you offer spare parts or customer support for that product model, to give anyone who possesses the object code either (1) a copy of the Corresponding Source for all the software in the product that is covered by this License, on a durable physical medium customarily used for software interchange, for a price no more than your reasonable cost of physically performing this conveying of source, or (2) access to copy the Corresponding Source from a network server at no charge. + + c) Convey individual copies of the object code with a copy of the written offer to provide the Corresponding Source. This alternative is allowed only occasionally and noncommercially, and only if you received the object code with such an offer, in accord with subsection 6b. + + d) Convey the object code by offering access from a designated place (gratis or for a charge), and offer equivalent access to the Corresponding Source in the same way through the same place at no further charge. You need not require recipients to copy the Corresponding Source along with the object code. If the place to copy the object code is a network server, the Corresponding Source may be on a different server (operated by you or a third party) that supports equivalent copying facilities, provided you maintain clear directions next to the object code saying where to find the Corresponding Source. Regardless of what server hosts the Corresponding Source, you remain obligated to ensure that it is available for as long as needed to satisfy these requirements. + + e) Convey the object code using peer-to-peer transmission, provided you inform other peers where the object code and Corresponding Source of the work are being offered to the general public at no charge under subsection 6d. + +A separable portion of the object code, whose source code is excluded from the Corresponding Source as a System Library, need not be included in conveying the object code work. + +A “User Product” is either (1) a “consumer product”, which means any tangible personal property which is normally used for personal, family, or household purposes, or (2) anything designed or sold for incorporation into a dwelling. In determining whether a product is a consumer product, doubtful cases shall be resolved in favor of coverage. For a particular product received by a particular user, “normally used” refers to a typical or common use of that class of product, regardless of the status of the particular user or of the way in which the particular user actually uses, or expects or is expected to use, the product. A product is a consumer product regardless of whether the product has substantial commercial, industrial or non-consumer uses, unless such uses represent the only significant mode of use of the product. + +“Installation Information” for a User Product means any methods, procedures, authorization keys, or other information required to install and execute modified versions of a covered work in that User Product from a modified version of its Corresponding Source. The information must suffice to ensure that the continued functioning of the modified object code is in no case prevented or interfered with solely because modification has been made. + +If you convey an object code work under this section in, or with, or specifically for use in, a User Product, and the conveying occurs as part of a transaction in which the right of possession and use of the User Product is transferred to the recipient in perpetuity or for a fixed term (regardless of how the transaction is characterized), the Corresponding Source conveyed under this section must be accompanied by the Installation Information. But this requirement does not apply if neither you nor any third party retains the ability to install modified object code on the User Product (for example, the work has been installed in ROM). + +The requirement to provide Installation Information does not include a requirement to continue to provide support service, warranty, or updates for a work that has been modified or installed by the recipient, or for the User Product in which it has been modified or installed. Access to a network may be denied when the modification itself materially and adversely affects the operation of the network or violates the rules and protocols for communication across the network. + +Corresponding Source conveyed, and Installation Information provided, in accord with this section must be in a format that is publicly documented (and with an implementation available to the public in source code form), and must require no special password or key for unpacking, reading or copying. + +7. Additional Terms. +“Additional permissions” are terms that supplement the terms of this License by making exceptions from one or more of its conditions. Additional permissions that are applicable to the entire Program shall be treated as though they were included in this License, to the extent that they are valid under applicable law. If additional permissions apply only to part of the Program, that part may be used separately under those permissions, but the entire Program remains governed by this License without regard to the additional permissions. + +When you convey a copy of a covered work, you may at your option remove any additional permissions from that copy, or from any part of it. (Additional permissions may be written to require their own removal in certain cases when you modify the work.) You may place additional permissions on material, added by you to a covered work, for which you have or can give appropriate copyright permission. + +Notwithstanding any other provision of this License, for material you add to a covered work, you may (if authorized by the copyright holders of that material) supplement the terms of this License with terms: + + a) Disclaiming warranty or limiting liability differently from the terms of sections 15 and 16 of this License; or + + b) Requiring preservation of specified reasonable legal notices or author attributions in that material or in the Appropriate Legal Notices displayed by works containing it; or + + c) Prohibiting misrepresentation of the origin of that material, or requiring that modified versions of such material be marked in reasonable ways as different from the original version; or + + d) Limiting the use for publicity purposes of names of licensors or authors of the material; or + + e) Declining to grant rights under trademark law for use of some trade names, trademarks, or service marks; or + + f) Requiring indemnification of licensors and authors of that material by anyone who conveys the material (or modified versions of it) with contractual assumptions of liability to the recipient, for any liability that these contractual assumptions directly impose on those licensors and authors. + +All other non-permissive additional terms are considered “further restrictions” within the meaning of section 10. If the Program as you received it, or any part of it, contains a notice stating that it is governed by this License along with a term that is a further restriction, you may remove that term. If a license document contains a further restriction but permits relicensing or conveying under this License, you may add to a covered work material governed by the terms of that license document, provided that the further restriction does not survive such relicensing or conveying. + +If you add terms to a covered work in accord with this section, you must place, in the relevant source files, a statement of the additional terms that apply to those files, or a notice indicating where to find the applicable terms. + +Additional terms, permissive or non-permissive, may be stated in the form of a separately written license, or stated as exceptions; the above requirements apply either way. + +8. Termination. +You may not propagate or modify a covered work except as expressly provided under this License. Any attempt otherwise to propagate or modify it is void, and will automatically terminate your rights under this License (including any patent licenses granted under the third paragraph of section 11). + +However, if you cease all violation of this License, then your license from a particular copyright holder is reinstated (a) provisionally, unless and until the copyright holder explicitly and finally terminates your license, and (b) permanently, if the copyright holder fails to notify you of the violation by some reasonable means prior to 60 days after the cessation. + +Moreover, your license from a particular copyright holder is reinstated permanently if the copyright holder notifies you of the violation by some reasonable means, this is the first time you have received notice of violation of this License (for any work) from that copyright holder, and you cure the violation prior to 30 days after your receipt of the notice. + +Termination of your rights under this section does not terminate the licenses of parties who have received copies or rights from you under this License. If your rights have been terminated and not permanently reinstated, you do not qualify to receive new licenses for the same material under section 10. + +9. Acceptance Not Required for Having Copies. +You are not required to accept this License in order to receive or run a copy of the Program. Ancillary propagation of a covered work occurring solely as a consequence of using peer-to-peer transmission to receive a copy likewise does not require acceptance. However, nothing other than this License grants you permission to propagate or modify any covered work. These actions infringe copyright if you do not accept this License. Therefore, by modifying or propagating a covered work, you indicate your acceptance of this License to do so. + +10. Automatic Licensing of Downstream Recipients. +Each time you convey a covered work, the recipient automatically receives a license from the original licensors, to run, modify and propagate that work, subject to this License. You are not responsible for enforcing compliance by third parties with this License. + +An “entity transaction” is a transaction transferring control of an organization, or substantially all assets of one, or subdividing an organization, or merging organizations. If propagation of a covered work results from an entity transaction, each party to that transaction who receives a copy of the work also receives whatever licenses to the work the party's predecessor in interest had or could give under the previous paragraph, plus a right to possession of the Corresponding Source of the work from the predecessor in interest, if the predecessor has it or can get it with reasonable efforts. + +You may not impose any further restrictions on the exercise of the rights granted or affirmed under this License. For example, you may not impose a license fee, royalty, or other charge for exercise of rights granted under this License, and you may not initiate litigation (including a cross-claim or counterclaim in a lawsuit) alleging that any patent claim is infringed by making, using, selling, offering for sale, or importing the Program or any portion of it. + +11. Patents. +A “contributor” is a copyright holder who authorizes use under this License of the Program or a work on which the Program is based. The work thus licensed is called the contributor's “contributor version”. + +A contributor's “essential patent claims” are all patent claims owned or controlled by the contributor, whether already acquired or hereafter acquired, that would be infringed by some manner, permitted by this License, of making, using, or selling its contributor version, but do not include claims that would be infringed only as a consequence of further modification of the contributor version. For purposes of this definition, “control” includes the right to grant patent sublicenses in a manner consistent with the requirements of this License. + +Each contributor grants you a non-exclusive, worldwide, royalty-free patent license under the contributor's essential patent claims, to make, use, sell, offer for sale, import and otherwise run, modify and propagate the contents of its contributor version. + +In the following three paragraphs, a “patent license” is any express agreement or commitment, however denominated, not to enforce a patent (such as an express permission to practice a patent or covenant not to sue for patent infringement). To “grant” such a patent license to a party means to make such an agreement or commitment not to enforce a patent against the party. + +If you convey a covered work, knowingly relying on a patent license, and the Corresponding Source of the work is not available for anyone to copy, free of charge and under the terms of this License, through a publicly available network server or other readily accessible means, then you must either (1) cause the Corresponding Source to be so available, or (2) arrange to deprive yourself of the benefit of the patent license for this particular work, or (3) arrange, in a manner consistent with the requirements of this License, to extend the patent license to downstream recipients. “Knowingly relying” means you have actual knowledge that, but for the patent license, your conveying the covered work in a country, or your recipient's use of the covered work in a country, would infringe one or more identifiable patents in that country that you have reason to believe are valid. + +If, pursuant to or in connection with a single transaction or arrangement, you convey, or propagate by procuring conveyance of, a covered work, and grant a patent license to some of the parties receiving the covered work authorizing them to use, propagate, modify or convey a specific copy of the covered work, then the patent license you grant is automatically extended to all recipients of the covered work and works based on it. + +A patent license is “discriminatory” if it does not include within the scope of its coverage, prohibits the exercise of, or is conditioned on the non-exercise of one or more of the rights that are specifically granted under this License. You may not convey a covered work if you are a party to an arrangement with a third party that is in the business of distributing software, under which you make payment to the third party based on the extent of your activity of conveying the work, and under which the third party grants, to any of the parties who would receive the covered work from you, a discriminatory patent license (a) in connection with copies of the covered work conveyed by you (or copies made from those copies), or (b) primarily for and in connection with specific products or compilations that contain the covered work, unless you entered into that arrangement, or that patent license was granted, prior to 28 March 2007. + +Nothing in this License shall be construed as excluding or limiting any implied license or other defenses to infringement that may otherwise be available to you under applicable patent law. + +12. No Surrender of Others' Freedom. +If conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot convey a covered work so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not convey it at all. For example, if you agree to terms that obligate you to collect a royalty for further conveying from those to whom you convey the Program, the only way you could satisfy both those terms and this License would be to refrain entirely from conveying the Program. + +13. Use with the GNU Affero General Public License. +Notwithstanding any other provision of this License, you have permission to link or combine any covered work with a work licensed under version 3 of the GNU Affero General Public License into a single combined work, and to convey the resulting work. The terms of this License will continue to apply to the part which is the covered work, but the special requirements of the GNU Affero General Public License, section 13, concerning interaction through a network will apply to the combination as such. + +14. Revised Versions of this License. +The Free Software Foundation may publish revised and/or new versions of the GNU General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. + +Each version is given a distinguishing version number. If the Program specifies that a certain numbered version of the GNU General Public License “or any later version” applies to it, you have the option of following the terms and conditions either of that numbered version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the GNU General Public License, you may choose any version ever published by the Free Software Foundation. + +If the Program specifies that a proxy can decide which future versions of the GNU General Public License can be used, that proxy's public statement of acceptance of a version permanently authorizes you to choose that version for the Program. + +Later license versions may give you additional or different permissions. However, no additional obligations are imposed on any author or copyright holder as a result of your choosing to follow a later version. + +15. Disclaimer of Warranty. +THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM “AS IS” WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + +16. Limitation of Liability. +IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + +17. Interpretation of Sections 15 and 16. +If the disclaimer of warranty and limitation of liability provided above cannot be given local legal effect according to their terms, reviewing courts shall apply local law that most closely approximates an absolute waiver of all civil liability in connection with the Program, unless a warranty or assumption of liability accompanies a copy of the Program in return for a fee. + +END OF TERMS AND CONDITIONS + +How to Apply These Terms to Your New Programs + +If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. + +To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively state the exclusion of warranty; and each file should have at least the “copyright” line and a pointer to where the full notice is found. + + + 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 . + +Also add information on how to contact you by electronic and paper mail. + +If the program does terminal interaction, make it output a short notice like this when it starts in an interactive mode: + + 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. + +The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, your program's commands might be different; for a GUI interface, you would use an “about box”. + +You should also get your employer (if you work as a programmer) or school, if any, to sign a “copyright disclaimer” for the program, if necessary. For more information on this, and how to apply and follow the GNU GPL, see . + +The GNU General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Lesser General Public License instead of this License. But first, please read . diff -Nru dtkcore-5.5.33/misc/DtkConfig.cmake.in dtkcore-5.6.2/misc/DtkConfig.cmake.in --- dtkcore-5.5.33/misc/DtkConfig.cmake.in 1970-01-01 00:00:00.000000000 +0000 +++ dtkcore-5.6.2/misc/DtkConfig.cmake.in 2022-09-21 05:21:07.000000000 +0000 @@ -0,0 +1,12 @@ +@PACKAGE_INIT@ + +set_and_check(DtkCore_INCLUDE_DIR "@PACKAGE_INCLUDE_INSTALL_DIR@") +set(DtkCore_TOOL_DIR "@PACKAGE_TOOL_INSTALL_DIR@") +set(DtkCore_LIBRARIES dtkcore) +include_directories("${DtkCore_INCLUDE_DIR}") + +check_required_components(DtkCore) + +# Keep deprecated variables for compatibility +set(DTKCORE_INCLUDE_DIR ${DtkCore_INCLUDE_DIR}) +set(DTKCORE_TOOL_DIR ${DtkCore_TOOL_DIR}) diff -Nru dtkcore-5.5.33/misc/dtkcore.pc.in dtkcore-5.6.2/misc/dtkcore.pc.in --- dtkcore-5.5.33/misc/dtkcore.pc.in 1970-01-01 00:00:00.000000000 +0000 +++ dtkcore-5.6.2/misc/dtkcore.pc.in 2022-09-21 05:21:07.000000000 +0000 @@ -0,0 +1,10 @@ +prefix=@CMAKE_INSTALL_PREFIX@ +exec_prefix=${prefix} +libdir=@CMAKE_INSTALL_FULL_LIBDIR@ +includedir=@INCLUDE_INSTALL_DIR@ + +Name: dtkcore +Description: Deepin Tool Kit dtkcore header files +Version: @CMAKE_PROJECT_VERSION@ +Libs: -L${libdir} -ldtkcore +Cflags: -I${includedir} diff -Nru dtkcore-5.5.33/misc/qt_lib_dtkcore.pri.in dtkcore-5.6.2/misc/qt_lib_dtkcore.pri.in --- dtkcore-5.5.33/misc/qt_lib_dtkcore.pri.in 1970-01-01 00:00:00.000000000 +0000 +++ dtkcore-5.6.2/misc/qt_lib_dtkcore.pri.in 2022-09-21 05:21:07.000000000 +0000 @@ -0,0 +1,14 @@ +QT.dtkcore.VERSION = @CMAKE_PROJECT_VERSION@ +QT.dtkcore.MAJOR_VERSION = @PROJECT_VERSION_MAJOR@ +QT.dtkcore.MINOR_VERSION = @PROJECT_VERSION_MINOR@ +QT.dtkcore.PATCH_VERSION = @PROJECT_VERSION_PATCH@ +QT.dtkcore.name = dtkcore +QT.dtkcore.module = dtkcore +QT.dtkcore.tools = @TOOL_INSTALL_DIR@ +QT.dtkcore.libs = @CMAKE_INSTALL_FULL_LIBDIR@ +QT.dtkcore.includes = @INCLUDE_INSTALL_DIR@ +QT.dtkcore.frameworks = +QT.dtkcore.depends = core dbus xml +QT.dtkcore.module_config = v2 ltcg +QT.dtkcore.DEFINES = +QT_MODULES += diff -Nru dtkcore-5.5.33/.qmake.conf dtkcore-5.6.2/.qmake.conf --- dtkcore-5.5.33/.qmake.conf 2022-07-19 09:10:28.000000000 +0000 +++ dtkcore-5.6.2/.qmake.conf 1970-01-01 00:00:00.000000000 +0000 @@ -1 +0,0 @@ -DTK_VERSION= diff -Nru dtkcore-5.5.33/README.md dtkcore-5.6.2/README.md --- dtkcore-5.5.33/README.md 2022-07-19 09:10:28.000000000 +0000 +++ dtkcore-5.6.2/README.md 2022-09-21 05:21:07.000000000 +0000 @@ -1,8 +1,8 @@ -## Deepin Tool Kit Core {#mainpage} +## Deepin Tool Kit Core -Deepint Tool Kit (Dtk) is the base development tool of all C++/Qt Developer work on Deepin. +Deepin Tool Kit (DtkCore) is the base development tool of all C++/Qt Developer work on Deepin. -You should read the [Deepin Application Specification](\ref doc/Specification) firstly. +You should read the Deepin Application Specification firstly. ## Dependencies @@ -18,25 +18,26 @@ 2. Build: -```` -$ mkdir build -$ cd build -$ qmake .. -$ make -```` +```bash +mkdir build +cd build +cmake .. +make +``` 3. Install: -```` -$ sudo make install -```` +```bash +sudo make install +``` ## Getting help Any usage issues can ask for help via -* [Gitter](https://gitter.im/orgs/linuxdeepin/rooms) -* [IRC channel](https://webchat.freenode.net/?channels=deepin) +* [Telegram group](https://t.me/deepin) +* [Matrix](https://matrix.to/#/#deepin-community:matrix.org) +* [IRC (libera.chat)](https://web.libera.chat/#deepin-community) * [Forum](https://bbs.deepin.org) * [WiKi](https://wiki.deepin.org/) @@ -44,9 +45,8 @@ We encourage you to report issues and contribute changes -* [Contribution guide for developers](https://github.com/linuxdeepin/developer-center/wiki/Contribution-Guidelines-for-Developers-en). (English) -* [开发者代码贡献指南](https://github.com/linuxdeepin/developer-center/wiki/Contribution-Guidelines-for-Developers) (中文) +* [Contribution guide for developers](https://github.com/linuxdeepin/developer-center/wiki/Contribution-Guidelines-for-Developers-en). ## License -deepin-tool-kit is licensed under [GPLv3](LICENSE). +deepin-tool-kit is licensed under [LGPLv3](LICENSE). diff -Nru dtkcore-5.5.33/README.zh_CN.md dtkcore-5.6.2/README.zh_CN.md --- dtkcore-5.5.33/README.zh_CN.md 1970-01-01 00:00:00.000000000 +0000 +++ dtkcore-5.6.2/README.zh_CN.md 2022-09-21 05:21:07.000000000 +0000 @@ -0,0 +1,52 @@ +## Deepin Tool Kit Core + +Deepin Tool Kit Core(DtkCore) 是所有C++/Qt开发人员在Deepin上工作的基础开发工具. + +您应该首先阅读 Deepin应用程序规范. + +## 依赖 + +### 编译依赖 + +* Qt >= 5.10 + +## 安装 + +### 从源代码构建 + +1. 确保已经安装了所有的编译依赖. + +2. 构建: + +```bash +mkdir build +cd build +cmake .. +make +``` + +3. 安装: + +```bash +sudo make install +``` + +## 帮助 + +任何使用问题都可以通过以下方式寻求帮助: + +* [Telegram 群组](https://t.me/deepin) +* [Matrix](https://matrix.to/#/#deepin-community:matrix.org) +* [IRC (libera.chat)](https://web.libera.chat/#deepin-community) +* [Forum](https://bbs.deepin.org) +* [WiKi](https://wiki.deepin.org/) + +## 参与贡献 + +我们鼓励您报告问题并作出更改 + +* [开发者代码贡献指南](https://github.com/linuxdeepin/developer-center/wiki/Contribution-Guidelines-for-Developers) + +## 协议 + +DTK工具包遵循协议 [LGPLv3](LICENSE). diff -Nru dtkcore-5.5.33/.reuse/dep5 dtkcore-5.6.2/.reuse/dep5 --- dtkcore-5.5.33/.reuse/dep5 1970-01-01 00:00:00.000000000 +0000 +++ dtkcore-5.6.2/.reuse/dep5 2022-09-21 05:21:07.000000000 +0000 @@ -0,0 +1,70 @@ +Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/ +Upstream-Name: dtkcore +Upstream-Contact: UnionTech Software Technology Co., Ltd. <> +Source: https://github.com/linuxdeepin/dtkcore + +# Sample paragraph, commented out: +# +# Files: src/* +# Copyright: $YEAR $NAME <$CONTACT> +# License: ... + +# ci +Files: .github/* *.yml *.yaml +Copyright: None +License: CC0-1.0 + +# git +Files: .gitignore +Copyright: None +License: CC0-1.0 + +# config +Files: *.toml *.conf *.json +Copyright: None +License: CC0-1.0 + +# qt +Files: *.pro *.pri *.qrc +Copyright: None +License: CC0-1.0 + +# cmake +Files: *.cmake *CMakeLists.txt *.pc.in +Copyright: None +License: CC0-1.0 + +# debian +Files: debian/* +Copyright: None +License: CC0-1.0 + +# Arch +Files: archlinux/* +Copyright: None +License: CC0-1.0 + +# rpm +Files: rpm/* +Copyright: None +License: CC0-1.0 + +# docs +Files: *.md *README* +Copyright: None +License: CC0-1.0 + +# interface +Files: include/DtkCore/D* +Copyright: None +License: CC0-1.0 + +# others +Files: src/util/resources/dpinyin.dict +Copyright: None +License: CC0-1.0 + + +Files: src/log/* +Copyright: UnionTech Software Technology Co., Ltd. +License: LGPL-3.0-or-later diff -Nru dtkcore-5.5.33/src/base/base.cmake dtkcore-5.6.2/src/base/base.cmake --- dtkcore-5.5.33/src/base/base.cmake 1970-01-01 00:00:00.000000000 +0000 +++ dtkcore-5.6.2/src/base/base.cmake 2022-09-21 05:21:07.000000000 +0000 @@ -0,0 +1,6 @@ +set(base_SRCS + ${CMAKE_CURRENT_LIST_DIR}/../../include/base/dobject.h + ${CMAKE_CURRENT_LIST_DIR}/../../include/base/private/dobject_p.h + ${CMAKE_CURRENT_LIST_DIR}/../../include/base/dsingleton.h + ${CMAKE_CURRENT_LIST_DIR}/dobject.cpp +) diff -Nru dtkcore-5.5.33/src/base/base.pri dtkcore-5.6.2/src/base/base.pri --- dtkcore-5.5.33/src/base/base.pri 2022-07-19 09:10:28.000000000 +0000 +++ dtkcore-5.6.2/src/base/base.pri 1970-01-01 00:00:00.000000000 +0000 @@ -1,18 +0,0 @@ -include($$PWD/private/private.pri) - -INCLUDEPATH += $$PWD/base -INCLUDEPATH += $$PWD/private - -HEADERS += \ - $$PWD/dobject.h \ - $$PWD/dsingleton.h - -SOURCES += \ - $$PWD/dobject.cpp - -includes.files += $$PWD/*.h -includes.files += $$PWD/private/*.h -includes.files += \ - $$PWD/DObject \ - $$PWD/DObjectPrivate \ - $$PWD/DSingleton diff -Nru dtkcore-5.5.33/src/base/DObject dtkcore-5.6.2/src/base/DObject --- dtkcore-5.5.33/src/base/DObject 2022-07-19 09:10:28.000000000 +0000 +++ dtkcore-5.6.2/src/base/DObject 1970-01-01 00:00:00.000000000 +0000 @@ -1 +0,0 @@ -#include "dobject.h" diff -Nru dtkcore-5.5.33/src/base/dobject.cpp dtkcore-5.6.2/src/base/dobject.cpp --- dtkcore-5.5.33/src/base/dobject.cpp 2022-07-19 09:10:28.000000000 +0000 +++ dtkcore-5.6.2/src/base/dobject.cpp 2022-09-21 05:21:07.000000000 +0000 @@ -1,22 +1,9 @@ -/* - * Copyright (C) 2015 ~ 2017 Deepin Technology Co., Ltd. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * 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 Lesser General Public License - * along with this program. If not, see . - */ +// SPDX-FileCopyrightText: 2015 - 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later #include "dobject.h" -#include "private/dobject_p.h" +#include "base/private/dobject_p.h" DCORE_BEGIN_NAMESPACE @@ -247,7 +234,7 @@ } - #include "moc_a.cpp" + \#include "moc_a.cpp" \endcode \a Func 槽函数的完整签名 \note 添加或更新私有槽之后需要重新手动调用 qmake diff -Nru dtkcore-5.5.33/src/base/dobject.h dtkcore-5.6.2/src/base/dobject.h --- dtkcore-5.5.33/src/base/dobject.h 2022-07-19 09:10:28.000000000 +0000 +++ dtkcore-5.6.2/src/base/dobject.h 1970-01-01 00:00:00.000000000 +0000 @@ -1,54 +0,0 @@ -/* - * Copyright (C) 2015 ~ 2017 Deepin Technology Co., Ltd. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * 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 Lesser General Public License - * along with this program. If not, see . - */ - -#ifndef DOBJECT_H -#define DOBJECT_H - -#include - -#include "dtkcore_global.h" - -DCORE_BEGIN_NAMESPACE - -#define D_DECLARE_PRIVATE(Class) Q_DECLARE_PRIVATE_D(qGetPtrHelper(d_d_ptr),Class) -#define D_DECLARE_PUBLIC(Class) Q_DECLARE_PUBLIC(Class) -#define D_D(Class) Q_D(Class) -#define D_Q(Class) Q_Q(Class) -#define D_DC(Class) Q_D(const Class) -#define D_QC(Class) Q_Q(const Class) -#define D_PRIVATE_SLOT(Func) Q_PRIVATE_SLOT(d_func(), Func) - -class DObjectPrivate; - -class LIBDTKCORESHARED_EXPORT DObject -{ -protected: - DObject(DObject *parent = nullptr); - - DObject(DObjectPrivate &dd, DObject *parent = nullptr); - - virtual ~DObject(); - - QScopedPointer d_d_ptr; - - Q_DISABLE_COPY(DObject) - D_DECLARE_PRIVATE(DObject) -}; - -DCORE_END_NAMESPACE - -#endif // DOBJECT_H diff -Nru dtkcore-5.5.33/src/base/DObjectPrivate dtkcore-5.6.2/src/base/DObjectPrivate --- dtkcore-5.5.33/src/base/DObjectPrivate 2022-07-19 09:10:28.000000000 +0000 +++ dtkcore-5.6.2/src/base/DObjectPrivate 1970-01-01 00:00:00.000000000 +0000 @@ -1 +0,0 @@ -#include "dobject_p.h" diff -Nru dtkcore-5.5.33/src/base/DSingleton dtkcore-5.6.2/src/base/DSingleton --- dtkcore-5.5.33/src/base/DSingleton 2022-07-19 09:10:28.000000000 +0000 +++ dtkcore-5.6.2/src/base/DSingleton 1970-01-01 00:00:00.000000000 +0000 @@ -1 +0,0 @@ -#include "dsingleton.h" diff -Nru dtkcore-5.5.33/src/base/dsingleton.h dtkcore-5.6.2/src/base/dsingleton.h --- dtkcore-5.5.33/src/base/dsingleton.h 2022-07-19 09:10:28.000000000 +0000 +++ dtkcore-5.6.2/src/base/dsingleton.h 1970-01-01 00:00:00.000000000 +0000 @@ -1,85 +0,0 @@ -/* - * Copyright (C) 2016 ~ 2017 Deepin Technology Co., Ltd. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * 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 Lesser General Public License - * along with this program. If not, see . - */ - -#ifndef DSINGLETON_H -#define DSINGLETON_H - -#include "dtkcore_global.h" - -DCORE_BEGIN_NAMESPACE - -/*! - a simple singleton template for std c++ 11 or later. - - example: - - \code - class ExampleSingleton : public QObject, public Dtk::DSingleton - { - Q_OBJECT - friend class DSingleton; - }; - \endcode - - \note: for Qt, "public DSingleton" must be after QObject. - */ - -/*! - 通过c++11的特性实现的单例模板 - - 使用示例: - -``` - class ExampleSingleton : public QObject, public Dtk::DSingleton - { - Q_OBJECT - friend class DSingleton; - }; -``` - - \note 对于Qt程序 public DSingleton" 必须在卸载QObject后面出现。 - */ - -template -class LIBDTKCORESHARED_EXPORT DSingleton -{ -public: - QT_DEPRECATED_X("Use ref") - static inline T *instance() - { - static T *_instance = new T; - return _instance; - } - - static T& ref() - { - static T instance; - return instance; - } - - DSingleton(T&&) = delete; - DSingleton(const T&) = delete; - void operator= (const T&) = delete; - -protected: - DSingleton() = default; - virtual ~DSingleton() = default; -}; - -DCORE_END_NAMESPACE - -#endif // DSINGLETON_H diff -Nru dtkcore-5.5.33/src/base/private/dobject_p.h dtkcore-5.6.2/src/base/private/dobject_p.h --- dtkcore-5.5.33/src/base/private/dobject_p.h 2022-07-19 09:10:28.000000000 +0000 +++ dtkcore-5.6.2/src/base/private/dobject_p.h 1970-01-01 00:00:00.000000000 +0000 @@ -1,42 +0,0 @@ -/* - * Copyright (C) 2015 ~ 2017 Deepin Technology Co., Ltd. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * 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 Lesser General Public License - * along with this program. If not, see . - */ - -#ifndef DOBJECT_P_H -#define DOBJECT_P_H - -#include "dtkcore_global.h" - -DCORE_BEGIN_NAMESPACE - -class DObject; -class LIBDTKCORESHARED_EXPORT DObjectPrivate -{ -public: - virtual ~DObjectPrivate(); - -protected: - DObjectPrivate(DObject *qq); - - DObject *q_ptr; - - Q_DECLARE_PUBLIC(DObject) -}; - -DCORE_END_NAMESPACE - -#endif // DOBJECT_P_H - diff -Nru dtkcore-5.5.33/src/base/private/private.pri dtkcore-5.6.2/src/base/private/private.pri --- dtkcore-5.5.33/src/base/private/private.pri 2022-07-19 09:10:28.000000000 +0000 +++ dtkcore-5.6.2/src/base/private/private.pri 1970-01-01 00:00:00.000000000 +0000 @@ -1,2 +0,0 @@ -HEADERS += \ - $$PWD/dobject_p.h diff -Nru dtkcore-5.5.33/src/CMakeLists.txt dtkcore-5.6.2/src/CMakeLists.txt --- dtkcore-5.5.33/src/CMakeLists.txt 1970-01-01 00:00:00.000000000 +0000 +++ dtkcore-5.6.2/src/CMakeLists.txt 2022-09-21 05:21:07.000000000 +0000 @@ -0,0 +1,123 @@ +#cmake_minimum_required(VERSION 3.5) +set(LIBNAME dtkcore) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) +set(CMAKE_EXPORT_COMPILE_COMMANDS ON) + +set(CMAKE_AUTOMOC ON) +set(CMAKE_AUTOUIC ON) +set(CMAKE_AUTORCC ON) + +set (DSG_PREFIX_PATH "${CMAKE_INSTALL_PREFIX}" CACHE STRING "PREFIX of DSG_DATA_DIRS") +add_definitions(-DPREFIX="${DSG_PREFIX_PATH}") +find_package(Qt5 REQUIRED COMPONENTS Core) +if(LINUX) +find_package(PkgConfig REQUIRED) +pkg_check_modules(QGSettings REQUIRED gsettings-qt) +find_package(Qt5 REQUIRED COMPONENTS DBus) +endif() +find_package(Qt5 REQUIRED COMPONENTS Xml) + +# start base +include(base/base.cmake) +# end base +if(LINUX) + include(dbus/dbus.cmake) +endif() +#message(${dbus_SRCS}) +# end dbus + +# start dci +include(dci/dci.cmake) +#end dci + +#start filesystem +include(filesystem/filesystem.cmake) +#end filesystem +# start log +include(log/log.cmake) +#end log +# start settings +include(settings/settings.cmake) +#end settings + +#start utils +include(util/util.cmake) +#end utils + +#GLOB +include(glob.cmake) +#endGLOG +if(LINUX) + add_library(${LIBNAME} SHARED + ${dbus_SRCS} + ${base_SRCS} + ${dci_SRCS} + ${filesystem_SRCS} + ${log_SRCS} + ${settings_SRC} + ${utils_SRC} + ${glob_SRC} + ) + target_link_libraries( + ${LIBNAME} PRIVATE + Qt5::Core + Qt5::DBus + Qt5::Xml + ${QGSettings_LIBRARIES} + ) +else() + add_library(${LIBNAME} SHARED + ${base_SRCS} + ${dci_SRCS} + ${filesystem_SRCS} + ${log_SRCS} + ${settings_SRC} + ${utils_SRC} + ${glob_SRC} + ) + target_link_libraries( + ${LIBNAME} PRIVATE + Qt5::Core + Qt5::Xml + ) +endif() +set_target_properties(${LIBNAME} PROPERTIES + VERSION ${CMAKE_PROJECT_VERSION} + SOVERSION ${CMAKE_PROJECT_VERSION_MAJOR} +) +target_include_directories( ${LIBNAME} PUBLIC + ${QGSettings_INCLUDE_DIRS} + ${Qt5Core_PRIVATE_INCLUDE_DIRS} + ../include/util/ + ../include/dci/ + ../include/log/ + ../include/base/ + ../include/base/private + ../include/global/ + ../include/DtkCore/ + ../include/settings/ + ../include/filesystem/ + ../include/ +) +set(TOINSTALLBASE + ../include/base/dobject.h + ../include/base/dsingleton.h + ../include/base/private/dobject_p.h +) +install(FILES ${TOINSTALLBASE} DESTINATION "${INCLUDE_INSTALL_DIR}") +install(DIRECTORY ../include/dci/ DESTINATION "${INCLUDE_INSTALL_DIR}" FILES_MATCHING PATTERN "*.h") +install(DIRECTORY ../include/DtkCore/ DESTINATION "${INCLUDE_INSTALL_DIR}" FILES_MATCHING PATTERN "*") +install(DIRECTORY ../include/filesystem/ DESTINATION "${INCLUDE_INSTALL_DIR}" FILES_MATCHING PATTERN "*.h") +install(DIRECTORY ../include/global/ DESTINATION "${INCLUDE_INSTALL_DIR}" FILES_MATCHING PATTERN "*.h") +file(GLOB TOINSTALLLOG + ../include/log/*.h +) +install(FILES ${TOINSTALLLOG} DESTINATION "${INCLUDE_INSTALL_DIR}") +file(GLOB TOINSTALLSETTINGS + ../include/settings/*.h + ../include/settings/backend/*.h +) +install(FILES ${TOINSTALLSETTINGS} DESTINATION "${INCLUDE_INSTALL_DIR}") +install(DIRECTORY ../include/util/ DESTINATION "${INCLUDE_INSTALL_DIR}" FILES_MATCHING PATTERN "*.h") +install(TARGETS ${LIBNAME} DESTINATION ${CMAKE_INSTALL_LIBDIR}) diff -Nru dtkcore-5.5.33/src/dbus/dbus.cmake dtkcore-5.6.2/src/dbus/dbus.cmake --- dtkcore-5.5.33/src/dbus/dbus.cmake 1970-01-01 00:00:00.000000000 +0000 +++ dtkcore-5.6.2/src/dbus/dbus.cmake 2022-09-21 05:21:07.000000000 +0000 @@ -0,0 +1,21 @@ +set(dbus_SRCS) +set_source_files_properties( + ${CMAKE_CURRENT_LIST_DIR}/org.desktopspec.ConfigManager.xml + PROPERTIES + NO_NAMESPACE ON + CLASSNAME DSGConfig +) +qt5_add_dbus_interface(dbus_SRCS + ${CMAKE_CURRENT_LIST_DIR}/org.desktopspec.ConfigManager.xml + configmanager_interface +) +set_source_files_properties( + ${CMAKE_CURRENT_LIST_DIR}/org.desktopspec.ConfigManager.Manager.xml + PROPERTIES + NO_NAMESPACE ON + CLASSNAME DSGConfigManager +) +qt5_add_dbus_interface(dbus_SRCS + ${CMAKE_CURRENT_LIST_DIR}/org.desktopspec.ConfigManager.Manager.xml + manager_interface +) diff -Nru dtkcore-5.5.33/src/dbus/org.desktopspec.ConfigManager.Manager.xml dtkcore-5.6.2/src/dbus/org.desktopspec.ConfigManager.Manager.xml --- dtkcore-5.5.33/src/dbus/org.desktopspec.ConfigManager.Manager.xml 2022-07-19 09:10:28.000000000 +0000 +++ dtkcore-5.6.2/src/dbus/org.desktopspec.ConfigManager.Manager.xml 2022-09-21 05:21:07.000000000 +0000 @@ -1,3 +1,11 @@ + + + + diff -Nru dtkcore-5.5.33/src/dbus/org.desktopspec.ConfigManager.xml dtkcore-5.6.2/src/dbus/org.desktopspec.ConfigManager.xml --- dtkcore-5.5.33/src/dbus/org.desktopspec.ConfigManager.xml 2022-07-19 09:10:28.000000000 +0000 +++ dtkcore-5.6.2/src/dbus/org.desktopspec.ConfigManager.xml 2022-09-21 05:21:07.000000000 +0000 @@ -1,3 +1,11 @@ + + + + diff -Nru dtkcore-5.5.33/src/dci/dci.cmake dtkcore-5.6.2/src/dci/dci.cmake --- dtkcore-5.5.33/src/dci/dci.cmake 1970-01-01 00:00:00.000000000 +0000 +++ dtkcore-5.6.2/src/dci/dci.cmake 2022-09-21 05:21:07.000000000 +0000 @@ -0,0 +1,6 @@ +set(dci_SRCS + ${CMAKE_CURRENT_LIST_DIR}/../../include/dci/ddcifile.h + ${CMAKE_CURRENT_LIST_DIR}/ddcifile.cpp + ${CMAKE_CURRENT_LIST_DIR}/private/ddcifileengine_p.h + ${CMAKE_CURRENT_LIST_DIR}/private/ddcifileengine.cpp +) diff -Nru dtkcore-5.5.33/src/dci/ddcifile.cpp dtkcore-5.6.2/src/dci/ddcifile.cpp --- dtkcore-5.5.33/src/dci/ddcifile.cpp 1970-01-01 00:00:00.000000000 +0000 +++ dtkcore-5.6.2/src/dci/ddcifile.cpp 2022-09-21 05:21:07.000000000 +0000 @@ -0,0 +1,829 @@ +// SPDX-FileCopyrightText: 2021 - 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later + +#include "ddcifile.h" +#include "private/ddcifileengine_p.h" + +#ifndef DTK_NO_PROJECT +#include +#else +#define D_D(class) +#define D_DC(class) +#endif +#include +#include +#include +#include +#include +#include +#include +#include + +DCORE_BEGIN_NAMESPACE + +#define MAGIC "DCI" + +#define MAGIC_SIZE 4 +#define VERSION_SIZE 1 +#define FILE_COUNT_SIZE 3 +#define FILE_META_SIZE 72 + +#define FILE_TYPE_SIZE 1 +#define FILE_NAME_SIZE 63 +#define FILE_DATA_SIZE 8 + +#define FILE_TYPE_FILE DDciFile::FileType::File +#define FILE_TYPE_DIR DDciFile::FileType::Directory +#define FILE_TYPE_SYMLINK DDciFile::FileType::Symlink + +#ifdef QT_DEBUG +Q_LOGGING_CATEGORY(logDF, "dtk.dci.file") +#else +Q_LOGGING_CATEGORY(logDF, "dtk.dci.file", QtInfoMsg) +#endif + +class DDciFilePrivate +#ifndef DTK_NO_PROJECT + : public DObjectPrivate +#endif +{ +public: + DDciFilePrivate(DDciFile *qq) +#ifndef DTK_NO_PROJECT + : DObjectPrivate(qq) + { +#else + { + Q_UNUSED(qq) +#endif + + } + ~DDciFilePrivate(); + + void setErrorString(const QString &message); + + void load(const QString &fileName); + void load(const QByteArray &data); + + QString errorMessage; + struct Node { + qint8 type = DDciFile::UnknowFile; + QString name; + + Node *parent = nullptr; + QVector children; // for directory + QByteArray data; // for file + + ~Node() { + qDeleteAll(children); + } + + QString path() const { + QString p = name; + Node *current = parent; + while (current) { + p.prepend(current->name + "/"); + current = current->parent; + } + + return p; + } + + QString linkPath() const { + const QString &path = QString::fromUtf8(data); + if (path.startsWith('/')) + return path; + // 转为绝对路径 + auto pNode = parent; + int pathStart = 0; + while (pathStart < path.size()) { + if (path.midRef(pathStart, 3) == QLatin1String("../")) { + pathStart += 3; + pNode = pNode->parent; + if (!pNode) + return QString(); + } else if (path.midRef(pathStart, 2) == QLatin1String("./")) { + pathStart += 2; + } else { + break; + } + } + Q_ASSERT(pNode); + return pNode->path() + QLatin1Char('/') + path.midRef(pathStart); + } + }; + + qint64 writeMetaDataForNode(QIODevice *device, Node *node, qint64 dataSize) const; + qint64 writeDataForNode(QIODevice *device, Node *node) const; + qint64 writeNode(QIODevice *device, Node *node) const; + + Node *mkNode(const QString &filePath); + void removeNode(Node *node); + void copyNode(const Node *from, Node *to); + + bool loadDirectory(Node *directory, + const QByteArray &data, qint64 &begin, qint64 end, + QHash &pathToNode); + + // 按标准中规定的文件排序计算此 name 在这个列表中的位置 + static int getOrderedIndexOfNodeName(const decltype(Node::children) &list, const QString &name); + + qint8 version = 0; + QScopedPointer root; + QHash pathToNode; + QByteArray rawData; +}; + +DDciFilePrivate::~DDciFilePrivate() +{ + +} + +void DDciFilePrivate::setErrorString(const QString &message) +{ + qCDebug(logDF, "%s", qPrintable(message)); + errorMessage = message; +} + +void DDciFilePrivate::load(const QString &fileName) +{ + QFile file(fileName); + + if (!file.open(QIODevice::ReadOnly)) { + setErrorString(file.errorString()); + return; + } + + return load(file.readAll()); +} + +void DDciFilePrivate::load(const QByteArray &data) +{ + // check magic + if (!data.startsWith("DCI")) { + setErrorString(QString("Expect value is \"DCI\", " + "but actually value is \"%1\"") + .arg(QString::fromLatin1(data.left(3)))); + return; + } + + qint8 version = data.at(MAGIC_SIZE); + if (version != 1) { + setErrorString(QString("Not supported version: %1").arg(version)); + return; + } + + char fileCountData[4]; + int fileCountOffset = MAGIC_SIZE + VERSION_SIZE; + memcpy(fileCountData, data.constData() + fileCountOffset, FILE_COUNT_SIZE); + fileCountData[3] = 0; + int fileCount = qFromLittleEndian(fileCountData); + + if (fileCount < 0) { + setErrorString(QString("Invalid file count: %1").arg(fileCount)); + return; + } + + qint64 offset = MAGIC_SIZE + VERSION_SIZE + FILE_COUNT_SIZE; + Node *root = new Node; + root->type = FILE_TYPE_DIR; + root->parent = nullptr; + + QHash pathToNode; + + if (!loadDirectory(root, data, offset, data.size() - 1, pathToNode) + || fileCount != root->children.count()) { + delete root; + return; + } + + this->version = version; + this->root.reset(root); + this->pathToNode = pathToNode; + this->pathToNode["/"] = root; + // Node 中保存的文件数据仅是此数据的引用,因此要确保此数据一直存在 + this->rawData = data; +} + +qint64 DDciFilePrivate::writeMetaDataForNode(QIODevice *device, DDciFilePrivate::Node *node, qint64 dataSize) const +{ + qint64 size = 0; + device->putChar(static_cast(node->type)); + size += FILE_TYPE_SIZE; + + const QByteArray rawName = node->name.toUtf8().left(FILE_NAME_SIZE - 1); + size += device->write(rawName); + // 填充未使用的部分 + size += device->write(QByteArray(FILE_NAME_SIZE - rawName.size(), '\0')); + + char int64[FILE_DATA_SIZE]; + qToLittleEndian(dataSize, int64); + size += device->write(int64, FILE_DATA_SIZE); + Q_ASSERT(size == FILE_META_SIZE); + + return size; +} + +qint64 DDciFilePrivate::writeDataForNode(QIODevice *device, DDciFilePrivate::Node *node) const +{ + if (node->type == FILE_TYPE_FILE + || node->type == FILE_TYPE_SYMLINK) { + return device->write(node->data); + } else if (node->type == FILE_TYPE_DIR) { + qint64 dataSize = 0; + for (Node *child : node->children) { + dataSize += writeNode(device, child); + } + return dataSize; + } + + return 0; +} + +qint64 DDciFilePrivate::writeNode(QIODevice *device, DDciFilePrivate::Node *node) const +{ + const qint64 metaDataPos = device->pos(); + device->seek(metaDataPos + FILE_META_SIZE); + const qint64 dataSize = writeDataForNode(device, node); + device->seek(metaDataPos); + const qint64 metaDataSize = writeMetaDataForNode(device, node, dataSize); + device->seek(device->pos() + dataSize); + return metaDataSize + dataSize; +} + +DDciFilePrivate::Node *DDciFilePrivate::mkNode(const QString &filePath) +{ + qCDebug(logDF, "Request create a node"); + + if (pathToNode.contains(filePath)) { + setErrorString(QString("The \"%1\" is existed").arg(filePath)); + return nullptr; + } + + const QFileInfo info(filePath); + qCDebug(logDF, "The parent directory is \"%s\"", qPrintable(info.path())); + + if (Node *parentNode = pathToNode.value(info.path())) { + if (parentNode->type != FILE_TYPE_DIR) { + setErrorString(QString("The \"%1\" is not a directory").arg(info.path())); + return nullptr; + } + + // 检查文件名长度,避免溢出 + if (info.fileName().toUtf8().size() > FILE_NAME_SIZE - 1) { + setErrorString(QString("The file name size must less then %1 bytes").arg(FILE_NAME_SIZE)); + return nullptr; + } + + Node *newNode = new Node; + newNode->name = info.fileName(); + newNode->parent = parentNode; + + const int index = getOrderedIndexOfNodeName(parentNode->children, newNode->name); + parentNode->children.insert(index, newNode); + pathToNode[newNode->path()] = newNode; + + return newNode; + } else { + setErrorString("The parent directory is not exists"); + return nullptr; + } +} + +void DDciFilePrivate::removeNode(DDciFilePrivate::Node *node) +{ + Q_ASSERT(node != root.data()); + + node->parent->children.removeOne(node); + auto removedNode = pathToNode.take(node->path()); + Q_ASSERT(removedNode == node); + + for (Node *child : node->children) { + Q_ASSERT(child->parent == node); + auto removedNode = pathToNode.take(child->path()); + Q_ASSERT(removedNode == child); + } + + delete node; +} + +void DDciFilePrivate::copyNode(const DDciFilePrivate::Node *from, DDciFilePrivate::Node *to) +{ + QList> copyPendingList; + copyPendingList << qMakePair(from, to); + + for (int i = 0; i < copyPendingList.size(); ++i) { + auto f = copyPendingList.at(i).first; + auto t = copyPendingList.at(i).second; + + t->type = f->type; + t->data = f->data; + + for (const auto child : f->children) { + if (child == to) + continue; + + Node *newChild = new Node; + newChild->parent = t; + newChild->name = child->name; + pathToNode[newChild->path()] = newChild; + + const int index = getOrderedIndexOfNodeName(t->children, newChild->name); + t->children.insert(index, newChild); + copyPendingList << qMakePair(child, newChild); + } + } +} + +bool DDciFilePrivate::loadDirectory(DDciFilePrivate::Node *directory, + const QByteArray &data, qint64 &offset, qint64 end, + QHash &pathToNode) +{ + // load files + while (offset < end) { + Node *node = new Node; + + node->parent = directory; + node->type = data.at(offset); + offset += FILE_TYPE_SIZE; + // 计算文件名的长度 + const int nameLength = data.indexOf('\0', offset) - offset; + if (nameLength <= 0 || nameLength >= FILE_NAME_SIZE) { + setErrorString(QString("Invalid file name, the data offset: %1").arg(offset)); + delete node; + return false; + } + node->name = QString::fromUtf8(data.constData() + offset, nameLength); + offset += FILE_NAME_SIZE; + + const qint64 dataSize = qFromLittleEndian(data.constData() + offset); + offset += FILE_DATA_SIZE; + + // 无失败时调用 break + do { + if (node->type == FILE_TYPE_DIR) { + if (loadDirectory(node, data, offset, offset + dataSize - 1, pathToNode)) { + break; + } + } else if (node->type == FILE_TYPE_FILE + || node->type == FILE_TYPE_SYMLINK) { + // 跳过文件内容 + node->data = QByteArray::fromRawData(data.constData() + offset, dataSize); + + if (node->data.size() == dataSize) { + offset += dataSize; + break; + } else { + setErrorString(QString("Invalid data size of \"%1\" file").arg(node->path())); + } + } else { + setErrorString(QString("Invalid file type: %1").arg(node->type)); + } + + delete node; + return false; + } while (false); + + directory->children << node; + pathToNode[node->path()] = node; + } + + return true; +} + +int DDciFilePrivate::getOrderedIndexOfNodeName(const decltype(Node::children) &list, const QString &name) +{ + QCollator collator(QLocale::English); + collator.setNumericMode(true); + for (int i = 0; i < list.count(); ++i) { + const Node *node = list.at(i); + if (collator.compare(name, node->name) < 0) + return i; + } + + return list.count(); +} + +void DDciFile::registerFileEngine() +{ + // 在 QAbstractFileEngineHandler 的构造函数中会注册自己,后续 + // 在使用 QFile 时会调用 DDciFileEngineHandler::create + static DDciFileEngineHandler globalHandler; + Q_UNUSED(globalHandler); +} + +#ifndef DTK_NO_PROJECT +DDciFile::DDciFile() + : DObject(*new DDciFilePrivate(this)) +{ + d_func()->load(QByteArrayLiteral("DCI\0\1\0\0\0")); +} + +DDciFile::DDciFile(const QString &fileName) + : DObject(*new DDciFilePrivate(this)) +{ + d_func()->load(fileName); +} + +DDciFile::DDciFile(const QByteArray &data) + : DObject(*new DDciFilePrivate(this)) +{ + d_func()->load(data); +} +#else +DDciFile::DDciFile() + : d(new DDciFilePrivate(this)) +{ + d->load(QByteArrayLiteral("DCI\0\1\0\0\0")); +} + +DDciFile::DDciFile(const QString &fileName) + : d(new DDciFilePrivate(this)) +{ + d->load(fileName); +} + +DDciFile::DDciFile(const QByteArray &data) + : d(new DDciFilePrivate(this)) +{ + d->load(data); +} +#endif + +bool DDciFile::isValid() const +{ + D_DC(DDciFile); + return d->root; +} + +QString DDciFile::lastErrorString() const +{ + D_DC(DDciFile); + return d->errorMessage; +} + +bool DDciFile::writeToFile(const QString &fileName) const +{ + QSaveFile sf(fileName); + do { + if (!sf.open(QIODevice::WriteOnly)) { + break; + } + if (!writeToDevice(&sf)) + return false; + if (!sf.commit()) + break; + return true; + } while (false); + + qCDebug(logDF, "Failed on write to file \"%s\", error message is: \"%s\"", + qPrintable(fileName), qPrintable(sf.errorString())); + return false; +} + +bool DDciFile::writeToDevice(QIODevice *device) const +{ + Q_ASSERT(isValid()); + D_DC(DDciFile); + + // magic + device->write(QByteArrayLiteral("DCI\0")); + // version + device->putChar(static_cast(d->version)); + char fileCountData[sizeof(int)]; + qToLittleEndian(d->root->children.count(), fileCountData); + // file count + device->write(fileCountData, FILE_COUNT_SIZE); + d->writeDataForNode(device, d->root.data()); + + return device->size() >= metadataSizeV1() + + (d->pathToNode.count() - 1) * FILE_META_SIZE; +} + +QByteArray DDciFile::toData() const +{ + if (!isValid()) + return QByteArray(); + + D_DC(DDciFile); + + qint64 allFilesContentSize = 0; + for (auto node : d->pathToNode) { + if (node->type == FILE_TYPE_FILE + || node->type == FILE_TYPE_SYMLINK) + allFilesContentSize += node->data.size(); + } + + QByteArray data; + // -1 是排除根目录 + data.resize(metadataSizeV1() + (d->pathToNode.count() - 1) * FILE_META_SIZE + + allFilesContentSize); + QBuffer buffer(&data); + + if (!buffer.open(QIODevice::WriteOnly) || !writeToDevice(&buffer)) + return QByteArray(); + + return data; +} + +constexpr int DDciFile::metadataSizeV1() +{ + return MAGIC_SIZE + VERSION_SIZE + FILE_COUNT_SIZE; +} + +QStringList DDciFile::list(const QString &dir, bool onlyFileName) const +{ + if (!isValid()) + return {}; + + D_DC(DDciFile); + + auto dirNode = d->pathToNode.value(dir); + if (!dirNode) { + qCDebug(logDF, "The \"%s\" is not exists", qPrintable(dir)); + return {}; + } + + if (dirNode->type != FILE_TYPE_DIR) { + qCWarning(logDF, "The \"%s\" is not a directory", qPrintable(dir)); + return {}; + } + + QStringList children; + for (auto child : dirNode->children) { + children << (onlyFileName ? child->name : QDir(dir).filePath(child->name)); + } + + return children; +} + +int DDciFile::childrenCount(const QString &dir) const +{ + if (!isValid()) + return 0; + + D_DC(DDciFile); + + auto dirNode = d->pathToNode.value(dir); + if (!dirNode) { + return 0; + } + + return dirNode->children.count(); +} + +bool DDciFile::exists(const QString &filePath) const +{ + if (!isValid()) + return false; + + D_DC(DDciFile); + return d->pathToNode.contains(filePath); +} + +DDciFile::FileType DDciFile::type(const QString &filePath) const +{ + if (!isValid()) + return UnknowFile; + + D_DC(DDciFile); + + auto node = d->pathToNode.value(filePath); + if (!node) { + qCDebug(logDF, "The \"%s\" is not exists", qPrintable(filePath)); + return DDciFile::UnknowFile; + } + + return static_cast(node->type); +} + +QByteArray DDciFile::dataRef(const QString &filePath) const +{ + if (!isValid()) + return QByteArray(); + + D_DC(DDciFile); + + auto node = d->pathToNode.value(filePath); + if (!node) { + qCDebug(logDF, "The \"%s\" is not exists", qPrintable(filePath)); + return QByteArray(); + } + + if (node->type == FILE_TYPE_SYMLINK) { + return dataRef(node->linkPath()); + } + + return node->data; +} + +QString DDciFile::name(const QString &filePath) const +{ + if (!isValid()) + return QString(); + + D_DC(DDciFile); + if (auto node = d->pathToNode.value(filePath)) { + return node->name; + } + + return QString(); +} + +QString DDciFile::symlinkTarget(const QString &filePath, bool originData) const +{ + if (!isValid()) + return QString(); + + D_DC(DDciFile); + if (auto node = d->pathToNode.value(filePath)) { + if (node->type != FILE_TYPE_SYMLINK) + return QString(); + + if (originData) { + return QString::fromUtf8(node->data); + } + + const QString &linkPath = node->linkPath(); + const auto targetNode = d->pathToNode.value(linkPath); + + // 链接的目标只能是“不存在的路径”、“文件”、“链接”,不可是目录 + if (!targetNode || targetNode->type == FILE_TYPE_FILE + || targetNode->type == FILE_TYPE_SYMLINK) + return linkPath; + } + + return QString(); +} + +bool DDciFile::mkdir(const QString &filePath) +{ + Q_ASSERT(isValid()); + D_D(DDciFile); + + qCDebug(logDF, "Request create the \"%s\" directory", qPrintable(filePath)); + auto node = d->mkNode(filePath); + if (!node) + return false; + node->type = FILE_TYPE_DIR; + return true; +} + +bool DDciFile::writeFile(const QString &filePath, const QByteArray &data, bool override) +{ + Q_ASSERT(isValid()); + D_D(DDciFile); + + qCDebug(logDF, "Request create the \"%s\" file", qPrintable(filePath)); + // 先删除旧的数据 + if (auto node = d->pathToNode.value(filePath)) { + if (override) { + if (node->type == FILE_TYPE_SYMLINK) { + const QString &linkPath = node->linkPath(); + qCDebug(logDF(), "Follow the symlink to \"%s\"", qPrintable(linkPath)); + + if (!d->pathToNode.contains(linkPath)) { + qCDebug(logDF(), "Can't write to a symlink target file if it is not existed"); + return false; + } + + return writeFile(linkPath, data, override); + } + + qCDebug(logDF, "Try override the file"); + if (node->type != FILE_TYPE_FILE) { + qCWarning(logDF, "The \"%s\" is existed and it is not a file", qPrintable(filePath)); + return false; + } + + node->data = data; + return true; + } else { + d->setErrorString("No the \"override\" flag and the file is existed, can't write"); + return false; + } + } + + auto node = d->mkNode(filePath); + if (!node) + return false; + + node->type = FILE_TYPE_FILE; + node->data = data; + return true; +} + +bool DDciFile::remove(const QString &filePath) +{ + Q_ASSERT(isValid()); + D_D(DDciFile); + + if (auto node = d->pathToNode.value(filePath)) { + if (node == d->root.data()) { + for (auto child : d->root->children) + d->removeNode(child); + d->root->children.clear(); + } else { + d->removeNode(node); + } + return true; + } else { + d->setErrorString("The file is not exists"); + return false; + } +} + +bool DDciFile::rename(const QString &filePath, const QString &newFilePath, bool override) +{ + Q_ASSERT(isValid()); + D_D(DDciFile); + + qCDebug(logDF, "Rename from \"%s\" to \"%s\"", qPrintable(filePath), qPrintable(newFilePath)); + if (filePath == newFilePath) + return false; + + if (newFilePath.toUtf8().size() >= FILE_META_SIZE) { + d->setErrorString(QString("The new name size must less then %1 bytes").arg(FILE_NAME_SIZE)); + return false; + } + + if (!override && d->pathToNode.contains(newFilePath)) { + d->setErrorString("The target file is existed"); + return false; + } + auto overrideNode = override ? d->pathToNode.take(newFilePath) : nullptr; + + if (auto node = d->pathToNode.take(filePath)) { + QFileInfo info(newFilePath); + if (auto parent = d->pathToNode.value(info.absolutePath())) { + node->name = info.fileName(); + + // 从旧节点删除添加到新的节点 + if (node->parent != parent) { + bool ok = node->parent->children.removeOne(node); + Q_ASSERT(ok); + const int index = d->getOrderedIndexOfNodeName(parent->children, node->name); + parent->children.insert(index, node); + node->parent = parent; + } + + d->pathToNode[info.absoluteFilePath()] = node; + Q_ASSERT(node->path() == info.absoluteFilePath()); + + // 删除被覆盖的节点 + if (overrideNode) { + Q_ASSERT(overrideNode->parent == parent); + overrideNode->parent->children.removeOne(overrideNode); + delete overrideNode; + } + + return true; + } else { + d->setErrorString(QString("The \"%1\" directory is not exists").arg(info.absolutePath())); + return false; + } + } else { + d->setErrorString("The file is not exists"); + return false; + } +} + +bool DDciFile::copy(const QString &from, const QString &to) +{ + Q_ASSERT(isValid()); + D_D(DDciFile); + + const auto fromNode = d->pathToNode.value(from); + if (!fromNode) { + d->setErrorString(QString("The \"%1\" is not exists").arg(from)); + return false; + } + + auto toNode = d->mkNode(to); + if (!toNode) { + return false; + } + + d->copyNode(fromNode, toNode); + return true; +} + +bool DDciFile::link(const QString &source, const QString &to) +{ + Q_ASSERT(isValid()); + D_D(DDciFile); + + if (source == to || source.isEmpty()) + return false; + + auto toNode = d->mkNode(to); + if (!toNode) + return false; + toNode->type = FILE_TYPE_SYMLINK; + toNode->data = source.toUtf8(); + + return true; +} + +DCORE_END_NAMESPACE diff -Nru dtkcore-5.5.33/src/dci/private/ddcifileengine.cpp dtkcore-5.6.2/src/dci/private/ddcifileengine.cpp --- dtkcore-5.5.33/src/dci/private/ddcifileengine.cpp 1970-01-01 00:00:00.000000000 +0000 +++ dtkcore-5.6.2/src/dci/private/ddcifileengine.cpp 2022-09-21 05:21:07.000000000 +0000 @@ -0,0 +1,613 @@ +// SPDX-FileCopyrightText: 2021 - 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later + +#define private public +#define protected public +#include +#undef private +#undef protected + +#include "ddcifileengine_p.h" +#include "dci/ddcifile.h" + +#include +#include + +DCORE_BEGIN_NAMESPACE + +#ifdef QT_DEBUG +Q_LOGGING_CATEGORY(logFE, "dtk.dci.fileengine") +#else +Q_LOGGING_CATEGORY(logFE, "dtk.dci.fileengine", QtInfoMsg) +#endif + +#define DCI_FILE_SCHEME "dci:" +#define DCI_FILE_SUFFIX ".dci" + +QAbstractFileEngine *DDciFileEngineHandler::create(const QString &fileName) const +{ + if (!fileName.startsWith(QStringLiteral(DCI_FILE_SCHEME))) + return nullptr; + + DDciFileEngine *engine = new DDciFileEngine(fileName); + if (!engine->isValid()) { + delete engine; + return nullptr; + } + + return engine; +} + +// 共享同个线程内的同个 DDciFile +static thread_local QHash> sharedDciFile; +static void doDeleteSharedDciFile(const QString &path, DDciFile *file) { + int count = sharedDciFile.remove(path); + Q_ASSERT(count > 0); + delete file; +} + +static DDciFileShared getDciFile(const QString &dciFilePath, bool usePath = true) +{ + if (auto shared = sharedDciFile.value(dciFilePath)) { + return shared.toStrongRef(); + } + + DDciFileShared shared(usePath ? new DDciFile(dciFilePath) : new DDciFile(), + std::bind(doDeleteSharedDciFile, dciFilePath, + std::placeholders::_1)); + sharedDciFile[dciFilePath] = shared.toWeakRef(); + return shared; +} + +DDciFileEngineIterator::DDciFileEngineIterator(QDir::Filters filters, const QStringList &nameFilters) + : QAbstractFileEngineIterator(filters, nameFilters) +{ + +} + +QString DDciFileEngineIterator::next() +{ + current = nextValid; + return DDciFileEngineIterator::currentFileName(); +} + +bool DDciFileEngineIterator::hasNext() const +{ + if (!file) { + const auto paths = DDciFileEngine::resolvePath(path()); + if (paths.first.isEmpty() + || paths.second.isEmpty()) + return false; + + file = getDciFile(paths.first); + list = file->list(paths.second); + } + + for (int i = current + 1; i < list.count(); ++i) { + // 先检查文件类型 + const auto filters = this->filters(); + const auto fileType = file->type(list.at(i)); + if (fileType == DDciFile::Directory) { + if (!filters.testFlag(QDir::Files)) + continue; + } else if (fileType == DDciFile::File) { + if (!filters.testFlag(QDir::Files)) + continue; + } else if (fileType == DDciFile::Symlink) { + if (filters.testFlag(QDir::NoSymLinks)) + continue; + } else { // DDciFile::UnknowFile + continue; + } + + // 按名称进行过滤 + if (!nameFilters().isEmpty() && !QDir::match(nameFilters(), list.at(i))) + continue; + + nextValid = i; + return true; + } + + return false; +} + +QString DDciFileEngineIterator::currentFileName() const +{ + return file->name(list.at(current)); +} + +DDciFileEngine::DDciFileEngine(const QString &fullPath) +{ + setFileName(fullPath); +} + +DDciFileEngine::~DDciFileEngine() +{ + close(); +} + +bool DDciFileEngine::isValid() const +{ + return file && file->isValid(); +} + +bool DDciFileEngine::open(QIODevice::OpenMode openMode) +{ + if (fileBuffer) { + setError(QFile::OpenError, "The file is opened"); + return false; + } + + if (!file->isValid()) { + setError(QFile::OpenError, "The DCI file is invalid"); + return false; + } + + if (file->type(subfilePath) == DDciFile::Directory) { + setError(QFile::OpenError, "Can't open a directory"); + return false; + } + + if (file->type(subfilePath) == DDciFile::Symlink) { + if (!file->exists(file->symlinkTarget(subfilePath))) { + setError(QFile::OpenError, "The symlink target is not existed"); + return false; + } + } + + if (openMode & QIODevice::Text) { + setError(QFile::OpenError, "Not supported open mode"); + return false; + } + + if (openMode & QIODevice::NewOnly) { + if (file->exists(subfilePath)) { + setError(QFile::OpenError, "The file is existed"); + return false; + } + } + + if ((openMode & QIODevice::ExistingOnly) + || !(openMode & QIODevice::WriteOnly)) { + if (!file->exists(subfilePath)) { + setError(QFile::OpenError, "The file is not exists"); + return false; + } + } + + // 此时当文件不存在时应当创建它 + if (openMode & QIODevice::WriteOnly) { + realDciFile.setFileName(dciFilePath); + if (!realDciFile.open(openMode)) { + return false; + } + + // 不存在时尝试新建 + if (!file->exists(subfilePath) + && !file->writeFile(subfilePath, QByteArray())) { + return false; + } + } + + // 加载数据 + fileData = file->dataRef(subfilePath); + fileBuffer = new QBuffer(&fileData); + bool ok = fileBuffer->open(openMode); + Q_ASSERT(ok); + if (Q_UNLIKELY(!ok)) { + delete fileBuffer; + fileBuffer = nullptr; + return false; + } + + return true; +} + +bool DDciFileEngine::close() +{ + if (!fileBuffer) { + return false; + } + + fileBuffer->close(); + delete fileBuffer; + fileBuffer = nullptr; + + bool ok = flush(); + realDciFile.close(); + return ok; +} + +bool DDciFileEngine::flushToFile(QFile *target, bool writeFile) const +{ + if (target->isWritable()) { + if (writeFile && !file->writeFile(subfilePath, fileData, true)) + return false; + if (!target->resize(0)) + return false; + const QByteArray &data = file->toData(); + if (target->write(data) != data.size()) + return false; + return true; + } + + return false; +} + +bool DDciFileEngine::flush() +{ + if (!flushToFile(&realDciFile, true)) + return false; + + return realDciFile.flush(); +} + +bool DDciFileEngine::syncToDisk() +{ + if (!flush()) + return false; + return realDciFile.d_func()->engine()->syncToDisk(); +} + +qint64 DDciFileEngine::size() const +{ + if (fileBuffer) { + return fileData.size(); + } + + return file->dataRef(subfilePath).size(); +} + +qint64 DDciFileEngine::pos() const +{ + return fileBuffer->size(); +} + +bool DDciFileEngine::seek(qint64 pos) +{ + return fileBuffer->seek(pos); +} + +bool DDciFileEngine::isSequential() const +{ + return false; +} + +bool DDciFileEngine::remove() +{ + return file->isValid() && file->remove(subfilePath) && forceSave(); +} + +bool DDciFileEngine::copy(const QString &newName) +{ + if (!file->isValid()) + return false; + // 解析出新的 dci 内部文件路径 + const auto paths = resolvePath(newName, dciFilePath); + if (paths.second.isEmpty()) + return false; + + return file->copy(subfilePath, paths.second) && forceSave(); +} + +bool DDciFileEngine::rename(const QString &newName) +{ + if (!file->isValid()) + return false; + // 解析出新的 dci 内部文件路径 + const auto paths = resolvePath(newName, dciFilePath); + if (paths.second.isEmpty()) + return false; + + return file->rename(subfilePath, paths.second, false) && forceSave(); +} + +bool DDciFileEngine::renameOverwrite(const QString &newName) +{ + if (!file->isValid()) + return false; + // 解析出新的 dci 内部文件路径 + const auto paths = resolvePath(newName, dciFilePath); + if (paths.second.isEmpty()) + return false; + + return file->rename(subfilePath, paths.second, true) && forceSave(); +} + +bool DDciFileEngine::link(const QString &newName) +{ + if (!file->isValid()) + return false; + + // 解析出新的 dci 内部文件路径 + const auto paths = resolvePath(newName, dciFilePath); + const QString &linkPath = paths.second.isEmpty() ? newName : paths.second; + + return file->link(subfilePath, linkPath) && forceSave(); +} + +bool DDciFileEngine::mkdir(const QString &dirName, bool createParentDirectories) const +{ + if (!file->isValid()) + return false; + // 解析出新的 dci 内部文件路径 + const auto paths = resolvePath(dirName, dciFilePath); + if (paths.second.isEmpty()) + return false; + + if (!createParentDirectories) + return file->mkdir(paths.second) && forceSave(); + + const QStringList dirItems = paths.second.split('/'); + QString currentPath; + for (const QString &newDir : dirItems) { + if (newDir.isEmpty()) + continue; + currentPath += ("/" + newDir); + if (file->exists(currentPath)) { + continue; + } + // 创建此路径 + if (!file->mkdir(currentPath)) + return false; + } + + return forceSave(); +} + +bool DDciFileEngine::rmdir(const QString &dirName, bool recurseParentDirectories) const +{ + if (!file->isValid()) + return false; + // 解析出新的 dci 内部文件路径 + const auto paths = resolvePath(dirName, dciFilePath); + if (paths.second.isEmpty()) + return false; + + if (!file->remove(paths.second)) + return false; + if (!recurseParentDirectories) + return forceSave(); + + // 查找空的父目录 + QDir dir(paths.second); + + while (dir.cdUp()) { + // 不删除根 + if (dir.isRoot()) + break; + + if (file->childrenCount(dir.absolutePath()) > 0) + continue; + if (!file->remove(dir.absolutePath())) + return false; + } + + return forceSave(); +} + +bool DDciFileEngine::setSize(qint64 size) +{ + if (!fileBuffer) { + fileData = file->dataRef(subfilePath); + } + + // 确保新数据填充为 0 + if (size > fileData.size()) { + fileData.append(size - fileData.size(), '\0'); + } else { + fileData.resize(size); + } + + return fileBuffer ? true : forceSave(true); +} + +bool DDciFileEngine::caseSensitive() const +{ + return true; +} + +bool DDciFileEngine::isRelativePath() const +{ + return !subfilePath.startsWith('/'); +} + +QByteArray DDciFileEngine::id() const +{ + return fileName().toUtf8(); +} + +uint DDciFileEngine::ownerId(QAbstractFileEngine::FileOwner owner) const +{ + QFileInfo info(dciFilePath); + return owner == OwnerUser ? info.ownerId() : info.groupId(); +} + +QString DDciFileEngine::owner(QAbstractFileEngine::FileOwner owner) const +{ + QFileInfo info(dciFilePath); + return owner == OwnerUser ? info.owner() : info.group(); +} + +QAbstractFileEngine::FileFlags DDciFileEngine::fileFlags(QAbstractFileEngine::FileFlags type) const +{ + auto flags = QAbstractFileEngine::FileFlags(); + + if (!file->isValid()) + return flags; + + if (type & TypesMask) { + const auto fileType = file->type(subfilePath); + + if (fileType == DDciFile::Directory) { + flags |= DirectoryType; + } else if (fileType == DDciFile::File) { + flags |= FileType; + } else if (fileType == DDciFile::Symlink) { + flags |= LinkType; + } + } + + if ((type & FlagsMask)) { + if (file->exists(subfilePath)) + flags |= ExistsFlag; + + if (subfilePath == QLatin1Char('/')) + flags |= RootFlag; + } + + if ((type & PermsMask) && file->exists(subfilePath)) { + flags |= static_cast(static_cast(QFileInfo(dciFilePath).permissions())); + } + + return flags; +} + +QString DDciFileEngine::fileName(QAbstractFileEngine::FileName file) const +{ + switch (file) { + case AbsoluteName: + case CanonicalName: + case DefaultName: + return QDir::cleanPath(DCI_FILE_SCHEME + dciFilePath + subfilePath); + case AbsolutePathName: + return QDir::cleanPath(DCI_FILE_SCHEME + dciFilePath); + case BaseName: + return QFileInfo(subfilePath).baseName(); + case LinkName: + return this->file->type(subfilePath) == DDciFile::Symlink + ? this->file->symlinkTarget(subfilePath) + : QString(); + default: + break; + } + + return QString(); +} + +void DDciFileEngine::setFileName(const QString &fullPath) +{ + // 销毁旧的内容 + close(); + file.reset(nullptr); + dciFilePath.clear(); + subfilePath.clear(); + + const auto paths = resolvePath(fullPath, QString(), false); + if (paths.first.isEmpty() + || paths.second.isEmpty()) + return; + + dciFilePath = paths.first; + subfilePath = paths.second; + file = getDciFile(dciFilePath, QFile::exists(dciFilePath)); +} + +QDateTime DDciFileEngine::fileTime(QAbstractFileEngine::FileTime time) const +{ + return QFileInfo(dciFilePath).fileTime(static_cast(time)); +} + +DDciFileEngine::Iterator *DDciFileEngine::beginEntryList(QDir::Filters filters, const QStringList &filterNames) +{ + return new DDciFileEngineIterator(filters, filterNames); +} + +DDciFileEngine::Iterator *DDciFileEngine::endEntryList() +{ + return nullptr; +} + +qint64 DDciFileEngine::read(char *data, qint64 maxlen) +{ + return fileBuffer->read(data, maxlen); +} + +qint64 DDciFileEngine::write(const char *data, qint64 len) +{ + return fileBuffer->write(data, len); +} + +bool DDciFileEngine::extension(QAbstractFileEngine::Extension extension, + const QAbstractFileEngine::ExtensionOption *option, + QAbstractFileEngine::ExtensionReturn *output) +{ + Q_UNUSED(option) + Q_UNUSED(output) + return extension == AtEndExtension && fileBuffer->atEnd(); +} + +bool DDciFileEngine::supportsExtension(QAbstractFileEngine::Extension extension) const +{ + return extension == AtEndExtension; +} + +bool DDciFileEngine::cloneTo(QAbstractFileEngine *target) +{ + const QByteArray &data = file->dataRef(subfilePath); + return target->write(data.constData(), data.size()) == data.size(); +} + +bool DDciFileEngine::forceSave(bool writeFile) const +{ + QFile file(dciFilePath); + if (!file.open(QIODevice::WriteOnly)) { + return false; + } + + return flushToFile(&file, writeFile); +} + +QPair DDciFileEngine::resolvePath(const QString &fullPath, + const QString &realFilePath, + bool needRealFileExists) +{ + if (!fullPath.startsWith(QStringLiteral(DCI_FILE_SCHEME) + realFilePath)) + return {}; + + qCDebug(logFE(), "Resolve the path: \"%s\"", qPrintable(fullPath)); + // 此路径来源于调用方,将其格式化为标准格式,尾部添加 "/" 以确保下文中得到的 + // subfilePath 绝对不为空 + QString formatFullPath = QDir::cleanPath(fullPath) + "/"; + QString dciFilePath = realFilePath, subfilePath; + const int schemeLength = qstrlen(DCI_FILE_SCHEME); + const int suffixLength = qstrlen(DCI_FILE_SUFFIX); + + if (dciFilePath.isEmpty()) { + // 尾部加 "/" 是确保 ".dci" 为一个文件的结尾 + int dciSuffixIndex = formatFullPath.indexOf(DCI_FILE_SUFFIX "/", schemeLength); + + while (dciSuffixIndex > 0) { + dciSuffixIndex += suffixLength; + dciFilePath = formatFullPath.mid(schemeLength, dciSuffixIndex - schemeLength); + // 查找一个有效的后缀名是 ".dci" 的文件 + if (needRealFileExists) { + if (QFileInfo(dciFilePath).isFile()) + break; + } else { + QFileInfo info(dciFilePath); + // 不存在的文件允许被新建 + if (!info.exists() && !info.isSymLink()) + break; + } + + dciSuffixIndex = dciFilePath.indexOf(DCI_FILE_SUFFIX, dciSuffixIndex + 1); + } + } else { + qCDebug(logFE(), "The base file path of user is: \"%s\"", qPrintable(realFilePath)); + } + + // 未找到有效的 dci 文件 + if (dciFilePath.isEmpty()) + return {}; + + subfilePath = QDir::cleanPath(formatFullPath.mid(schemeLength + dciFilePath.length())); + qCDebug(logFE(), "The DCI file path is: \"%s\", the subfile path is: \"%s\"", + qPrintable(dciFilePath), qPrintable(subfilePath)); + Q_ASSERT(!subfilePath.isEmpty()); + + return qMakePair(dciFilePath, subfilePath); +} + +DCORE_END_NAMESPACE diff -Nru dtkcore-5.5.33/src/dci/private/ddcifileengine_p.h dtkcore-5.6.2/src/dci/private/ddcifileengine_p.h --- dtkcore-5.5.33/src/dci/private/ddcifileengine_p.h 1970-01-01 00:00:00.000000000 +0000 +++ dtkcore-5.6.2/src/dci/private/ddcifileengine_p.h 2022-09-21 05:21:07.000000000 +0000 @@ -0,0 +1,127 @@ +// SPDX-FileCopyrightText: 2021 - 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later + +#pragma once + +#ifndef DTK_NO_PROJECT +#include +#else +#define DCORE_BEGIN_NAMESPACE +#define DCORE_END_NAMESPACE +#endif +#include + +#include +#include + +QT_BEGIN_NAMESPACE +class QBuffer; +QT_END_NAMESPACE + +DCORE_BEGIN_NAMESPACE + +class DDciFileEngineHandler : public QAbstractFileEngineHandler +{ +public: + QAbstractFileEngine *create(const QString &fileName) const override; +}; + +class DDciFile; +using DDciFileShared = QSharedPointer; +class DDciFileEngineIterator : public QAbstractFileEngineIterator +{ + friend class DDciFileEngine; +public: + DDciFileEngineIterator(QDir::Filters filters, const QStringList &nameFilters); + + QString next() override; + bool hasNext() const override; + + QString currentFileName() const override; + +private: + mutable DDciFileShared file; + mutable QStringList list; + mutable int nextValid = -1; + int current = -1; +}; + +class DDciFileEngine : public QAbstractFileEngine +{ + friend class DDciFileEngineIterator; +public: + explicit DDciFileEngine(const QString &fullPath); + ~DDciFileEngine(); + + bool isValid() const; + bool open(QIODevice::OpenMode openMode) override; + bool close() override; + bool flushToFile(QFile *target, bool writeFile) const; + bool flush() override; + bool syncToDisk() override; + + qint64 size() const override; + qint64 pos() const override; + bool seek(qint64 pos) override; + bool isSequential() const override; + bool remove() override; + bool copy(const QString &newName) override; + bool rename(const QString &newName) override; + bool renameOverwrite(const QString &newName) override; + bool link(const QString &newName) override; + bool mkdir(const QString &dirName, bool createParentDirectories) const override; + bool rmdir(const QString &dirName, bool recurseParentDirectories) const override; + bool setSize(qint64 size) override; + bool caseSensitive() const override; + bool isRelativePath() const override; + + QByteArray id() const override; + uint ownerId(FileOwner owner) const override; + QString owner(FileOwner owner) const override; + + FileFlags fileFlags(FileFlags type = FileInfoAll) const override; + QString fileName(FileName file = DefaultName) const override; + + void setFileName(const QString &fullPath) override; + + QDateTime fileTime(FileTime time) const override; + + typedef DDciFileEngineIterator Iterator; + Iterator *beginEntryList(QDir::Filters filters, const QStringList &filterNames) override; + Iterator *endEntryList() override; + + qint64 read(char *data, qint64 maxlen) override; + qint64 write(const char *data, qint64 len) override; + + bool extension(Extension extension, const ExtensionOption *option = 0, + ExtensionReturn *output = 0) override; + bool supportsExtension(Extension extension) const override; + + bool cloneTo(QAbstractFileEngine *target) override; + +private: + bool forceSave(bool writeFile = false) const; + + /* + * fullPath 格式:"dci:" + "真实文件路径" + "DCI 内部文件的路径" + * 例如:"dci:/home/user/test.dci/subfile.png" + * 其中 "/home/user/test.dci" 为真实文件路径,"/subfile.png" + * 是 DCI 文件的内部路径。 + * 函数返回的第一个数据是"真实文件路径"。 + */ + static QPair resolvePath(const QString &fullPath, + const QString &realFilePath = QString(), + bool needRealFileExists = true); + + DDciFileShared file; + QString dciFilePath; + QFile realDciFile; + QString subfilePath; + + QByteArray fileData; + QBuffer *fileBuffer = nullptr; +}; + + +DCORE_END_NAMESPACE diff -Nru dtkcore-5.5.33/src/DConfig dtkcore-5.6.2/src/DConfig --- dtkcore-5.5.33/src/DConfig 2022-07-19 09:10:28.000000000 +0000 +++ dtkcore-5.6.2/src/DConfig 1970-01-01 00:00:00.000000000 +0000 @@ -1 +0,0 @@ -#include "dconfig.h" diff -Nru dtkcore-5.5.33/src/dconfig.cpp dtkcore-5.6.2/src/dconfig.cpp --- dtkcore-5.5.33/src/dconfig.cpp 2022-07-19 09:10:28.000000000 +0000 +++ dtkcore-5.6.2/src/dconfig.cpp 2022-09-21 05:21:07.000000000 +0000 @@ -1,23 +1,7 @@ -/* - * Copyright (C) 2021 Uniontech Technology Co., Ltd. - * - * Author: zccrs - * - * Maintainer: zccrs - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * 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 Lesser General Public License - * along with this program. If not, see . - */ +// SPDX-FileCopyrightText: 2021 - 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later + #include "dconfig.h" #ifndef D_DISABLE_DCONFIG #include "dconfigfile.h" @@ -29,6 +13,7 @@ #include #endif #include "dobject_p.h" +#include #include #include @@ -40,11 +25,6 @@ Q_DECLARE_LOGGING_CATEGORY(cfLog) -inline static QString getAppId() { - // TODO: 应该使用更可靠的接口获取 appId - return QCoreApplication::applicationName(); -} - /*! \class Dtk::Core::DConfigBackend \inmodule dtkcore @@ -113,7 +93,7 @@ const QString &name, const QString &subpath) : DObjectPrivate(qq) - , appId(appId.isEmpty() ? getAppId() : appId) + , appId(appId.isEmpty() ? DSGApplication::id() : appId) , name(name) , subpath(subpath) { @@ -160,12 +140,12 @@ return configFile && configFile->isValid(); } - virtual bool load(const QString &appId) override + virtual bool load(const QString &/*appId*/) override { if (configFile) return true; - configFile.reset(new DConfigFile(appId,owner->name, owner->subpath)); + configFile.reset(new DConfigFile(owner->appId,owner->name, owner->subpath)); configCache.reset(configFile->createUserCache(getuid())); const QString &prefix = localPrefix(); @@ -186,7 +166,8 @@ virtual void setValue(const QString &key, const QVariant &value) override { - if (configFile->setValue(key, value, getAppId(), configCache.get())) { + // setValue's callerAppid is itself instead of config's appId. + if (configFile->setValue(key, value, DSGApplication::id(), configCache.get())) { Q_EMIT owner->q_func()->valueChanged(key); } } @@ -273,20 +254,20 @@ 初始化DBus连接,会先调用acquireManager动态获取一个配置连接, 再通过这个配置连接进行配置文件的访问. */ - virtual bool load(const QString &appid) override + virtual bool load(const QString &/*appId*/) override { if (config) return true; qCDebug(cfLog, "Try acquire config manager object form DBus"); DSGConfig dsg_config(DSG_CONFIG, "/", QDBusConnection::systemBus()); - QDBusPendingReply dbus_reply = dsg_config.acquireManager(appid, owner->name, owner->subpath); + QDBusPendingReply dbus_reply = dsg_config.acquireManager(owner->appId, owner->name, owner->subpath); const QDBusObjectPath dbus_path = dbus_reply.value(); if (dbus_reply.isError() || dbus_path.path().isEmpty()) { qCWarning(cfLog, "Can't acquire config manager. error:\"%s\"", qPrintable(dbus_reply.error().message())); return false; } else { - qCWarning(cfLog(), "dbus path=\"%s\"", qPrintable(dbus_path.path())); + qCDebug(cfLog(), "dbus path=\"%s\"", qPrintable(dbus_path.path())); config.reset(new DSGConfigManager(DSG_CONFIG_MANAGER, dbus_path.path(), QDBusConnection::systemBus(), owner->q_func())); if (!config->isValid()) { diff -Nru dtkcore-5.5.33/src/DConfigFile dtkcore-5.6.2/src/DConfigFile --- dtkcore-5.5.33/src/DConfigFile 2022-07-19 09:10:28.000000000 +0000 +++ dtkcore-5.6.2/src/DConfigFile 1970-01-01 00:00:00.000000000 +0000 @@ -1 +0,0 @@ -#include "dconfigfile.h" diff -Nru dtkcore-5.5.33/src/dconfigfile.cpp dtkcore-5.6.2/src/dconfigfile.cpp --- dtkcore-5.5.33/src/dconfigfile.cpp 2022-07-19 09:10:28.000000000 +0000 +++ dtkcore-5.6.2/src/dconfigfile.cpp 2022-09-21 05:21:07.000000000 +0000 @@ -1,23 +1,7 @@ -/* - * Copyright (C) 2021 Uniontech Technology Co., Ltd. - * - * Author: zccrs - * - * Maintainer: zccrs - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * 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 Lesser General Public License - * along with this program. If not, see . - */ +// SPDX-FileCopyrightText: 2021 - 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later + #include "dconfigfile.h" #include "dobject_p.h" @@ -152,7 +136,7 @@ #define MAGIC_OVERRIDE QLatin1String("dsg.config.override") #define MAGIC_CACHE QLatin1String("dsg.config.cache") -static const uint GlobalUID = 0xFFFF; +static const uint InvalidUID = 0xFFFF; inline static bool checkMagic(const QJsonObject &obj, QLatin1String request) { return obj[QLatin1String("magic")].toString() == request; @@ -961,13 +945,20 @@ return values.keyList(); } - inline QString applicationCacheDir(const QString &prefix) const { - const QString &homePath = DStandardPaths::homePath(userid); + inline static QString applicationCacheDir(const QString &prefix, const QString &suffix, + uint userid, const QString &appId) { + // If target user is current user, then get the home path by environment variable first. + const QString &homePath = (getuid() == userid) ? DStandardPaths::homePath() + : DStandardPaths::homePath(userid); if (homePath.isEmpty()) { return QString(); } - const QString userHomeConfigDir = homePath + QStringLiteral("/.config/dsg/configs/"); - return prefix + userHomeConfigDir + "/" + configKey.appId; + const QString userHomeConfigDir = homePath + QStringLiteral("/.config/dsg/configs") + suffix; + return prefix + userHomeConfigDir + QDir::separator() + appId; + } + + inline QString applicationCacheDir(const QString &prefix) const { + return applicationCacheDir(prefix, QString(), userid, configKey.appId); } inline QString cacheDir(const QString &basePath) { @@ -978,8 +969,18 @@ inline QString globalCacheDir(const QString &prefix) const { // TODO `DSG_APP_DATA` is not set and `appid` is not captured in `DStandardPaths::path`. QString appDataDir = DStandardPaths::path(DStandardPaths::DSG::AppData); - if (appDataDir.isEmpty()) - appDataDir = QString("/var/dsg/appdata"); + if (appDataDir.isEmpty()) { +#ifdef D_DSG_APP_DATA_FALLBACK + appDataDir = QStringLiteral(D_DSG_APP_DATA_FALLBACK); + QFileInfo tmp(appDataDir); + if (!tmp.exists() && !tmp.isSymLink() && !QDir::current().mkpath(appDataDir)) { + qCDebug(cfLog, "Not found a valid DSG_APP_DATA directory"); + return QString(); + } +#else + return QString(); +#endif + } return QString("%1/%2/configs/%3").arg(prefix, appDataDir, configKey.appId); } @@ -987,7 +988,12 @@ QString getCacheDir(const QString &localPrefix = QString()) { if (isGlobal()) { - return globalCacheDir(localPrefix); + const QString &dir = globalCacheDir(localPrefix); + if (!dir.isEmpty()) + return dir; + + // Not supported the global config, fallback the config cache data to user directory. + return applicationCacheDir(localPrefix, "-fake-global", getuid(), configKey.appId); } else { return applicationCacheDir(localPrefix); } @@ -1014,6 +1020,7 @@ values.setTime(key, QDateTime::currentDateTime().toString(Qt::ISODate)); values.setUser(key, uid); values.setAppId(key, appid.isEmpty() ? configKey.appId : appid); + cacheChanged = true; return true; } @@ -1028,7 +1035,7 @@ DConfigInfo values; uint userid; bool global; - char padding [3] = {}; + bool cacheChanged = false; }; DConfigCacheImpl::DConfigCacheImpl(const DConfigKey &configKey, const uint uid, bool global) @@ -1080,9 +1087,13 @@ bool DConfigCacheImpl::save(const QString &localPrefix, QJsonDocument::JsonFormat format, bool sync) { + if (!cacheChanged) + return true; + const QString &dir = getCacheDir(localPrefix); if (dir.isEmpty()) { - qCWarning(cfLog, "save Falied because home directory is not exist for the user[%d].", userid); + qCWarning(cfLog, "Falied on saveing, the config cache directory is empty for the user[%d], " + "the current user[%d].", userid, getuid()); return false; } QString path = cacheDir(dir); @@ -1093,7 +1104,7 @@ } if (!cache.open(QIODevice::WriteOnly)) { - qCWarning(cfLog, "save Falied on open file: \"%s\", error message: \"%s\"", + qCWarning(cfLog, "Falied on saveing data when open file: \"%s\", error message: \"%s\"", qPrintable(cache.fileName()), qPrintable(cache.errorString())); return false; } @@ -1237,14 +1248,14 @@ Q_ASSERT(!name.isEmpty()); D_D(DConfigFile); - d->globalCache = new DConfigCacheImpl(d->configKey, GlobalUID, true); + d->globalCache = new DConfigCacheImpl(d->configKey, InvalidUID, true); } DConfigFile::DConfigFile(const DConfigFile &other) : DObject(*new DConfigFilePrivate(this, other.d_func()->configKey)) { D_D(DConfigFile); - auto cache = new DConfigCacheImpl(d->configKey, GlobalUID, true); + auto cache = new DConfigCacheImpl(d->configKey, InvalidUID, true); cache->values = other.d_func()->globalCache->values; d->globalCache = cache; } diff -Nru dtkcore-5.5.33/src/dconfigfile.h dtkcore-5.6.2/src/dconfigfile.h --- dtkcore-5.5.33/src/dconfigfile.h 2022-07-19 09:10:28.000000000 +0000 +++ dtkcore-5.6.2/src/dconfigfile.h 1970-01-01 00:00:00.000000000 +0000 @@ -1,143 +0,0 @@ -/* - * Copyright (C) 2021 Uniontech Technology Co., Ltd. - * - * Author: zccrs - * - * Maintainer: zccrs - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * 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 Lesser General Public License - * along with this program. If not, see . - */ -#ifndef DCONFIGFILE_H -#define DCONFIGFILE_H - -#include -#include -#include -#include -#include -#include -#include -#include - -QT_BEGIN_NAMESPACE -class QIODevice; -QT_END_NAMESPACE - -DCORE_BEGIN_NAMESPACE - -class DConfigMeta; -class DConfigCache; -class DConfigFilePrivate; -class LIBDTKCORESHARED_EXPORT DConfigFile : public DObject{ - D_DECLARE_PRIVATE(DConfigFile) -public: - enum Flag { - NoOverride = 1 << 0, - Global = 1 << 1 - }; - Q_DECLARE_FLAGS(Flags, Flag) - - enum Permissions { - ReadOnly, - ReadWrite - }; - - enum Visibility { - Private, - Public - }; - - struct Version { - quint16 major; - quint16 minor; - }; - - static constexpr Version supportedVersion(); - - explicit DConfigFile(const QString &appId, const QString &name, - const QString &subpath = QString()); - explicit DConfigFile(const DConfigFile &other); - - bool load(const QString &localPrefix = QString()); - bool load(QIODevice *meta, const QList &overrides); - - bool save(const QString &localPrefix = QString(), QJsonDocument::JsonFormat format = QJsonDocument::Indented, - bool sync = false) const; - - bool isValid() const; - QVariant value(const QString &key, DConfigCache *userCache = nullptr) const; - bool setValue(const QString &key, const QVariant &value, const QString &callerAppid, - DConfigCache *userCache = nullptr); - - DConfigCache *createUserCache(const uint uid); - DConfigCache *globalCache() const; - - DConfigMeta *meta(); - -protected: - friend QDebug operator<<(QDebug, const DConfigFile &); -}; - -class LIBDTKCORESHARED_EXPORT DConfigMeta { -public: - virtual ~DConfigMeta(); - virtual DConfigFile::Version version() const = 0; - virtual void setVersion(quint16 major, quint16 minor) = 0; - - virtual bool load(const QString &localPrefix = QString()) = 0; - - virtual bool load(QIODevice *meta, const QList &overrides) = 0; - - virtual QStringList keyList() const = 0; - virtual DConfigFile::Flags flags(const QString &key) const = 0; - virtual DConfigFile::Permissions permissions(const QString &key) const = 0; - virtual DConfigFile::Visibility visibility(const QString &key) const = 0; - virtual int serial(const QString &key) const = 0; - - virtual QString displayName(const QString &key, const QLocale &locale) = 0; - virtual QString description(const QString &key, const QLocale &locale) = 0; - - virtual QString metaPath(const QString &localPrefix = QString(), bool *useAppId = nullptr) const = 0; - virtual QStringList allOverrideDirs(const bool useAppId, const QString &prefix = QString()) const = 0; - - virtual QVariant value(const QString &key) const = 0; -}; - -class LIBDTKCORESHARED_EXPORT DConfigCache { -public: - virtual ~DConfigCache(); - - virtual bool load(const QString &localPrefix = QString()) = 0; - virtual bool save(const QString &localPrefix = QString(), - QJsonDocument::JsonFormat format = QJsonDocument::Indented, bool sync = false) = 0; - virtual bool isGlobal() const = 0; - - virtual void remove(const QString &key) = 0; - virtual QStringList keyList() const = 0; - virtual bool setValue(const QString &key, const QVariant &value, const int serial, - const uint uid, const QString &callerAppid) = 0; - virtual QVariant value(const QString &key) const = 0; - virtual int serial(const QString &key) const = 0; - virtual uint uid() const = 0; -}; - -#ifndef QT_NO_DEBUG_STREAM -Q_CORE_EXPORT QDebug operator<<(QDebug, const DConfigFile &); -#endif - -Q_DECLARE_OPERATORS_FOR_FLAGS(DConfigFile::Flags) - -DCORE_END_NAMESPACE - -#endif // DCONFIGFILE_H diff -Nru dtkcore-5.5.33/src/dconfig.h dtkcore-5.6.2/src/dconfig.h --- dtkcore-5.5.33/src/dconfig.h 2022-07-19 09:10:28.000000000 +0000 +++ dtkcore-5.6.2/src/dconfig.h 1970-01-01 00:00:00.000000000 +0000 @@ -1,85 +0,0 @@ -/* - * Copyright (C) 2021 Uniontech Technology Co., Ltd. - * - * Author: zccrs - * - * Maintainer: zccrs - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * 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 Lesser General Public License - * along with this program. If not, see . - */ -#ifndef DCONFIG_H -#define DCONFIG_H - -#include -#include - -#include -#include - -DCORE_BEGIN_NAMESPACE -class DConfigBackend { -public: - virtual ~DConfigBackend(); - virtual bool isValid() const = 0; - virtual bool load(const QString &/*appId*/) = 0; - virtual QStringList keyList() const = 0; - virtual QVariant value(const QString &/*key*/, const QVariant &/*fallback*/) const = 0; - virtual void setValue(const QString &/*key*/, const QVariant &/*value*/) = 0; - virtual void reset(const QString &key) { setValue(key, QVariant());} - virtual QString name() const {return QString("");} -}; - -class DConfigPrivate; -class LIBDTKCORESHARED_EXPORT DConfig : public QObject, public DObject -{ - Q_OBJECT - D_DECLARE_PRIVATE(DConfig) - - Q_PROPERTY(QStringList keyList READ keyList FINAL) - -public: - explicit DConfig(const QString &name, const QString &subpath = QString(), - QObject *parent = nullptr); - - explicit DConfig(DConfigBackend *backend, const QString &name, const QString &subpath = QString(), - QObject *parent = nullptr); - - static DConfig *create(const QString &appId, const QString &name, const QString &subpath = QString(), - QObject *parent = nullptr); - static DConfig *create(DConfigBackend *backend, const QString &appId, const QString &name, const QString &subpath = QString(), - QObject *parent = nullptr); - - QString backendName() const; - - QStringList keyList() const; - - bool isValid() const; - QVariant value(const QString &key, const QVariant &fallback = QVariant()) const; - void setValue(const QString &key, const QVariant &value); - void reset(const QString &key); - - QString name() const; - QString subpath() const; - -Q_SIGNALS: - void valueChanged(const QString &key); - -private: - explicit DConfig(DConfigBackend *backend, const QString &appId, const QString &name, const QString &subpath, - QObject *parent = nullptr); -}; - -DCORE_END_NAMESPACE - -#endif // DCONFIG_H diff -Nru dtkcore-5.5.33/src/DDesktopEntry dtkcore-5.6.2/src/DDesktopEntry --- dtkcore-5.5.33/src/DDesktopEntry 2022-07-19 09:10:28.000000000 +0000 +++ dtkcore-5.6.2/src/DDesktopEntry 1970-01-01 00:00:00.000000000 +0000 @@ -1 +0,0 @@ -#include "ddesktopentry.h" diff -Nru dtkcore-5.5.33/src/ddesktopentry.cpp dtkcore-5.6.2/src/ddesktopentry.cpp --- dtkcore-5.5.33/src/ddesktopentry.cpp 2022-07-19 09:10:28.000000000 +0000 +++ dtkcore-5.6.2/src/ddesktopentry.cpp 2022-09-21 05:21:07.000000000 +0000 @@ -1,24 +1,6 @@ -/* - * Copyright (C) 2019 Deepin Technology Co., Ltd. - * 2019 Gary Wang - * - * Author: Gary Wang - * - * Maintainer: Gary Wang - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * 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 Lesser General Public License - * along with this program. If not, see . - */ +// SPDX-FileCopyrightText: 2019 - 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later #include "ddesktopentry.h" diff -Nru dtkcore-5.5.33/src/ddesktopentry.h dtkcore-5.6.2/src/ddesktopentry.h --- dtkcore-5.5.33/src/ddesktopentry.h 2022-07-19 09:10:28.000000000 +0000 +++ dtkcore-5.6.2/src/ddesktopentry.h 1970-01-01 00:00:00.000000000 +0000 @@ -1,113 +0,0 @@ -/* - * Copyright (C) 2019 Deepin Technology Co., Ltd. - * 2019 Gary Wang - * - * Author: Gary Wang - * - * Maintainer: Gary Wang - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * 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 Lesser General Public License - * along with this program. If not, see . - */ - -#pragma once - -#include - -#include -#include -#include - -DCORE_BEGIN_NAMESPACE - -class DDesktopEntryPrivate; -class LIBDTKCORESHARED_EXPORT DDesktopEntry -{ - Q_GADGET -public: - enum EntryType { - Unknown = 0, //!< Unknown desktop file type. Maybe is invalid. - Application, //!< The file describes application. - Link, //!< The file describes URL. - Directory, //!< The file describes directory settings. - ServiceType, //!< KDE specific type. mentioned in the spec, so listed here too. - Service, //!< KDE specific type. mentioned in the spec, so listed here too. - FSDevice //!< KDE specific type. mentioned in the spec, so listed here too. - }; - Q_ENUM(EntryType) - - enum ValueType { - Unparsed = 0, // Maybe useless, consider remove it? - String, - Strings, - Boolean, - Numeric, - NotExisted = 99 - }; - Q_ENUM(ValueType) - - enum Status { - NoError = 0, //!< No error occurred. - AccessError, //!< An access error occurred (e.g. trying to write to a read-only file). - FormatError //!< A format error occurred (e.g. loading a malformed desktop entry file). - }; - Q_ENUM(Status) - - explicit DDesktopEntry(const QString &filePath) noexcept; - ~DDesktopEntry(); - - bool save() const; - - Status status() const; - QStringList keys(const QString §ion = "Desktop Entry") const; - QStringList allGroups(bool sorted = false) const; - - bool contains(const QString &key, const QString §ion = "Desktop Entry") const; - - QString name() const; - QString genericName() const; - QString ddeDisplayName() const; - QString comment() const; - - QString rawValue(const QString &key, const QString §ion = "Desktop Entry", - const QString &defaultValue = QString()) const; - QString stringValue(const QString &key, const QString §ion = "Desktop Entry", - const QString &defaultValue = QString()) const; - QString localizedValue(const QString &key, const QString &localeKey = "default", - const QString §ion = "Desktop Entry", const QString& defaultValue = QString()) const; - QString localizedValue(const QString &key, const QLocale &locale, - const QString §ion = "Desktop Entry", const QString& defaultValue = QString()) const; - QStringList stringListValue(const QString &key, const QString §ion = "Desktop Entry") const; - - bool setRawValue(const QString &value, const QString &key, const QString& section = "Desktop Entry"); - bool setStringValue(const QString &value, const QString &key, const QString& section = "Desktop Entry"); - bool setLocalizedValue(const QString &value, const QString& localeKey, - const QString &key, const QString& section = "Desktop Entry"); - - bool removeEntry(const QString &key, const QString §ion = "Desktop Entry"); - - static QString &escape(QString &str); - static QString &escapeExec(QString &str); - static QString &unescape(QString &str, bool unescapeSemicolons = false); - static QString &unescapeExec(QString &str); - -protected: - bool setStatus(const Status &status); - -private: - QScopedPointer d_ptr; - - Q_DECLARE_PRIVATE(DDesktopEntry) -}; - -DCORE_END_NAMESPACE diff -Nru dtkcore-5.5.33/src/DSecureString dtkcore-5.6.2/src/DSecureString --- dtkcore-5.5.33/src/DSecureString 2022-07-19 09:10:28.000000000 +0000 +++ dtkcore-5.6.2/src/DSecureString 1970-01-01 00:00:00.000000000 +0000 @@ -1 +0,0 @@ -#include "dsecurestring.h" diff -Nru dtkcore-5.5.33/src/dsecurestring.cpp dtkcore-5.6.2/src/dsecurestring.cpp --- dtkcore-5.5.33/src/dsecurestring.cpp 2022-07-19 09:10:28.000000000 +0000 +++ dtkcore-5.6.2/src/dsecurestring.cpp 2022-09-21 05:21:07.000000000 +0000 @@ -1,23 +1,7 @@ -/* - * Copyright (C) 2019 Deepin Technology Co., Ltd. - * - * Author: Gary Wang - * - * Maintainer: Gary Wang - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * 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 Lesser General Public License - * along with this program. If not, see . - */ +// SPDX-FileCopyrightText: 2019 - 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later + #include "dsecurestring.h" #include "dutil.h" diff -Nru dtkcore-5.5.33/src/dsecurestring.h dtkcore-5.6.2/src/dsecurestring.h --- dtkcore-5.5.33/src/dsecurestring.h 2022-07-19 09:10:28.000000000 +0000 +++ dtkcore-5.6.2/src/dsecurestring.h 1970-01-01 00:00:00.000000000 +0000 @@ -1,36 +0,0 @@ -/* - * Copyright (C) 2019 Deepin Technology Co., Ltd. - * - * Author: Gary Wang - * - * Maintainer: Gary Wang - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * 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 Lesser General Public License - * along with this program. If not, see . - */ -#pragma once - -#include -#include - -DCORE_BEGIN_NAMESPACE - -class LIBDTKCORESHARED_EXPORT DSecureString : public QString -{ -public: - using QString::QString; - DSecureString(const QString &other) noexcept; - ~DSecureString(); -}; - -DCORE_END_NAMESPACE diff -Nru dtkcore-5.5.33/src/dsgapplication.cpp dtkcore-5.6.2/src/dsgapplication.cpp --- dtkcore-5.5.33/src/dsgapplication.cpp 1970-01-01 00:00:00.000000000 +0000 +++ dtkcore-5.6.2/src/dsgapplication.cpp 2022-09-21 05:21:07.000000000 +0000 @@ -0,0 +1,40 @@ +// SPDX-FileCopyrightText: 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later + +#include "dsgapplication.h" + +#include +#include + +DCORE_BEGIN_NAMESPACE + +static inline QByteArray getSelfAppId() { + // The env is set by the application starter(eg, org.desktopspec.ApplicationManager service) + QByteArray selfId = qgetenv("DSG_APP_ID"); + if (!selfId.isEmpty()) + return selfId; + selfId = DSGApplication::getId(QCoreApplication::applicationPid()); + if (selfId.isEmpty() && !qEnvironmentVariableIsSet("DTK_DISABLED_FALLBACK_APPID")) { + selfId = QCoreApplication::applicationName().toLocal8Bit(); + } + Q_ASSERT(!selfId.isEmpty()); + if (selfId.isEmpty()) { + qt_assert("The application ID is empty", __FILE__, __LINE__); + } + return selfId; +} + +QByteArray DSGApplication::id() +{ + static QByteArray selfId = getSelfAppId(); + return selfId; +} + +QByteArray DSGApplication::getId(qint64) +{ + // TODO(zccrs): Call the org.desktopspec.ApplicationManager DBus service + return nullptr; +} + +DCORE_END_NAMESPACE diff -Nru dtkcore-5.5.33/src/DSysInfo dtkcore-5.6.2/src/DSysInfo --- dtkcore-5.5.33/src/DSysInfo 2022-07-19 09:10:28.000000000 +0000 +++ dtkcore-5.6.2/src/DSysInfo 1970-01-01 00:00:00.000000000 +0000 @@ -1 +0,0 @@ -#include "dsysinfo.h" diff -Nru dtkcore-5.5.33/src/dsysinfo.cpp dtkcore-5.6.2/src/dsysinfo.cpp --- dtkcore-5.5.33/src/dsysinfo.cpp 2022-07-19 09:10:28.000000000 +0000 +++ dtkcore-5.6.2/src/dsysinfo.cpp 2022-09-21 05:21:07.000000000 +0000 @@ -1,23 +1,7 @@ -/* - * Copyright (C) 2017 ~ 2018 Deepin Technology Co., Ltd. - * - * Author: zccrs - * - * Maintainer: zccrs - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * 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 Lesser General Public License - * along with this program. If not, see . - */ +// SPDX-FileCopyrightText: 2017 - 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later + #include "dsysinfo.h" #include "ddesktopentry.h" @@ -454,6 +438,11 @@ if (productTypeString.compare("fedora", Qt::CaseInsensitive) == 0) productType = DSysInfo::Fedora; break; + case 'g': + case 'G': + if (productTypeString.compare("gentoo", Qt::CaseInsensitive) == 0) + productType = DSysInfo::Gentoo; + break; case 'l': case 'L': if (productTypeString.compare("linuxmint", Qt::CaseInsensitive) == 0) @@ -464,6 +453,11 @@ if (productTypeString.compare("manjaro", Qt::CaseInsensitive) == 0) productType = DSysInfo::Manjaro; break; + case 'n': + case 'N': + if (productTypeString.compare("nixos", Qt::CaseInsensitive) == 0) + productType = DSysInfo::NixOS; + break; case 'o': case 'O': if (productTypeString.compare("opensuse", Qt::CaseInsensitive) == 0) diff -Nru dtkcore-5.5.33/src/dsysinfo.h dtkcore-5.6.2/src/dsysinfo.h --- dtkcore-5.5.33/src/dsysinfo.h 2022-07-19 09:10:28.000000000 +0000 +++ dtkcore-5.6.2/src/dsysinfo.h 1970-01-01 00:00:00.000000000 +0000 @@ -1,154 +0,0 @@ -/* - * Copyright (C) 2017 ~ 2018 Deepin Technology Co., Ltd. - * - * Author: zccrs - * - * Maintainer: zccrs - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * 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 Lesser General Public License - * along with this program. If not, see . - */ -#ifndef DSYSINFO_H -#define DSYSINFO_H - -#include - -#include - -DCORE_BEGIN_NAMESPACE - -class DSysInfoPrivate; -class LIBDTKCORESHARED_EXPORT DSysInfo -{ -public: - enum ProductType { - UnknownType = 0, - Deepin, - ArchLinux, - CentOS, - Debian, - Fedora, - LinuxMint, - Manjaro, - openSUSE, - SailfishOS, - Ubuntu, - Uos - }; - - enum DeepinType { - UnknownDeepin = 0, - DeepinDesktop, - DeepinProfessional, - DeepinServer, - DeepinPersonal - }; - - enum LogoType { - Normal = 0, - Light, - Symbolic, - Transparent - }; - - enum OrgType { - Distribution, //!< distribution itself - Distributor, //!< distributer of the current distribution - Manufacturer //!< manufacturer of the current distribution or device - }; - - enum UosType { - UosTypeUnknown, - UosDesktop, - UosServer, - UosDevice, - - UosTypeCount // must at last - }; - - enum UosEdition { - UosEditionUnknown, - UosProfessional, - UosHome, - UosCommunity, - UosMilitary, - UosEnterprise, - UosEnterpriseC, - UosEuler, - UosMilitaryS, // for Server - UosDeviceEdition, - UosEducation, - - UosEditionCount // must at last - }; - - // 注意:此处架构是从OsBuild获取的系统版本的Arch信息,并不是指硬件的Arch信息 - enum UosArch { - UosArchUnknown, - UosAMD64 = 1 << 0, - UosARM64 = 1 << 1, - UosMIPS64 = 1 << 2, - UosSW64 = 1 << 3 - }; - -#ifdef Q_OS_LINUX - static bool isDeepin(); - static bool isDDE(); - static DeepinType deepinType(); - static QString deepinTypeDisplayName(const QLocale &locale = QLocale::system()); - static QString deepinVersion(); - static QString deepinEdition(); - static QString deepinCopyright(); - - // uos version interface - static UosType uosType(); - static UosEdition uosEditionType(); - static UosArch uosArch(); - static QString uosProductTypeName(const QLocale &locale = QLocale::system()); - static QString uosSystemName(const QLocale &locale = QLocale::system()); - static QString uosEditionName(const QLocale &locale = QLocale::system()); - - static QString spVersion(); // SP1...SP99 - static QString udpateVersion(); // update1...update9 - static QString majorVersion(); - static QString minorVersion(); - static QString buildVersion(); // xyzs -#endif - - Q_DECL_DEPRECATED_X("Use distributionInfoPath() instead") static QString deepinDistributionInfoPath(); - static QString distributionInfoPath(); - static QString distributionInfoSectionName(OrgType type); - - static QString distributionOrgName(OrgType type = Distribution, const QLocale &locale = QLocale::system()); - Q_DECL_DEPRECATED_X("Use deepinDistributionOrgName() instead") static QString deepinDistributorName(); - static QPair distributionOrgWebsite(OrgType type = Distribution); - Q_DECL_DEPRECATED_X("Use deepinDistributionOrgWebsite() instead") static QPair deepinDistributorWebsite(); - static QString distributionOrgLogo(OrgType orgType = Distribution, LogoType type = Normal, const QString & fallback = QString()); - Q_DECL_DEPRECATED_X("Use deepinDistributionOrgLogo() instead") static QString deepinDistributorLogo(LogoType type = Normal, const QString & fallback = QString()); - - static QString operatingSystemName(); - static ProductType productType(); - static QString productTypeString(); - static QString productVersion(); - static bool isCommunityEdition(); - - static QString computerName(); - static QString cpuModelName(); - static qint64 memoryInstalledSize(); - static qint64 memoryTotalSize(); - static qint64 systemDiskSize(); -}; - -DCORE_END_NAMESPACE - -#endif // DSYSINFO_H diff -Nru dtkcore-5.5.33/src/dtkcore_global.cpp dtkcore-5.6.2/src/dtkcore_global.cpp --- dtkcore-5.5.33/src/dtkcore_global.cpp 2022-07-19 09:10:28.000000000 +0000 +++ dtkcore-5.6.2/src/dtkcore_global.cpp 2022-09-21 05:21:07.000000000 +0000 @@ -1,3 +1,7 @@ +// SPDX-FileCopyrightText: 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later + #include "dtkcore_global.h" #include #include diff -Nru dtkcore-5.5.33/src/dtkcore_global.h dtkcore-5.6.2/src/dtkcore_global.h --- dtkcore-5.5.33/src/dtkcore_global.h 2022-07-19 09:10:28.000000000 +0000 +++ dtkcore-5.6.2/src/dtkcore_global.h 1970-01-01 00:00:00.000000000 +0000 @@ -1,73 +0,0 @@ -/* - * Copyright (C) 2017 ~ 2017 Deepin Technology Co., Ltd. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * 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 Lesser General Public License - * along with this program. If not, see . - */ - -#pragma once - -#include -#include - -#define DTK_NAMESPACE Dtk - -#if !defined(DTK_NAMESPACE) -# define DTK_BEGIN_NAMESPACE -# define DTK_END_NAMESPACE -# define DTK_USE_NAMESPACE -#else -# define DTK_BEGIN_NAMESPACE namespace DTK_NAMESPACE { -# define DTK_END_NAMESPACE } -# define DTK_USE_NAMESPACE using namespace DTK_NAMESPACE; -#endif - -#define DCORE_NAMESPACE Core -#define DTK_CORE_NAMESPACE DTK_NAMESPACE::DCORE_NAMESPACE - -#if !defined(DCORE_NAMESPACE) -# define DCORE_BEGIN_NAMESPACE -# define DCORE_END_NAMESPACE -# define DCORE_USE_NAMESPACE -#else -# define DCORE_BEGIN_NAMESPACE namespace DTK_NAMESPACE { namespace DCORE_NAMESPACE { -# define DCORE_END_NAMESPACE }} -# define DCORE_USE_NAMESPACE using namespace DTK_CORE_NAMESPACE; -#endif - - -#if defined(DTK_STATIC_LIB) -# define LIBDTKCORESHARED_EXPORT -#else -#if defined(LIBDTKCORE_LIBRARY) -# define LIBDTKCORESHARED_EXPORT Q_DECL_EXPORT -#else -# define LIBDTKCORESHARED_EXPORT Q_DECL_IMPORT -#endif -#endif - -#ifdef D_DEPRECATED_CHECK -#define D_DECL_DEPRECATED_X(text) Q_DECL_HIDDEN -#define D_DECL_DEPRECATED Q_DECL_HIDDEN -#else -#define D_DECL_DEPRECATED Q_DECL_DEPRECATED -#define D_DECL_DEPRECATED_X Q_DECL_DEPRECATED_X -#endif - -#define DTK_VERSION_CHECK(major, minor, patch, build) ((major<<24)|(minor<<16)|(patch<<8)|build) -#define DTK_VERSION DTK_VERSION_CHECK(DTK_VERSION_MAJOR, DTK_VERSION_MINOR, DTK_VERSION_PATCH, DTK_VERSION_BUILD) - -extern "C" { -int LIBDTKCORESHARED_EXPORT dtkVersion(); -const LIBDTKCORESHARED_EXPORT char *dtkVersionString(); -} diff -Nru dtkcore-5.5.33/src/filesystem/DBaseFileWatcher dtkcore-5.6.2/src/filesystem/DBaseFileWatcher --- dtkcore-5.5.33/src/filesystem/DBaseFileWatcher 2022-07-19 09:10:28.000000000 +0000 +++ dtkcore-5.6.2/src/filesystem/DBaseFileWatcher 1970-01-01 00:00:00.000000000 +0000 @@ -1 +0,0 @@ -#include "dbasefilewatcher.h" diff -Nru dtkcore-5.5.33/src/filesystem/dbasefilewatcher.cpp dtkcore-5.6.2/src/filesystem/dbasefilewatcher.cpp --- dtkcore-5.5.33/src/filesystem/dbasefilewatcher.cpp 2022-07-19 09:10:28.000000000 +0000 +++ dtkcore-5.6.2/src/filesystem/dbasefilewatcher.cpp 2022-09-21 05:21:07.000000000 +0000 @@ -1,19 +1,6 @@ -/* - * Copyright (C) 2017 ~ 2017 Deepin Technology Co., Ltd. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * 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 Lesser General Public License - * along with this program. If not, see . - */ +// SPDX-FileCopyrightText: 2017 - 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later #include "dbasefilewatcher.h" #include "private/dbasefilewatcher_p.h" @@ -197,4 +184,4 @@ DCORE_END_NAMESPACE -#include "moc_dbasefilewatcher.cpp" +//#include "moc_dbasefilewatcher.cpp" diff -Nru dtkcore-5.5.33/src/filesystem/dbasefilewatcher.h dtkcore-5.6.2/src/filesystem/dbasefilewatcher.h --- dtkcore-5.5.33/src/filesystem/dbasefilewatcher.h 2022-07-19 09:10:28.000000000 +0000 +++ dtkcore-5.6.2/src/filesystem/dbasefilewatcher.h 1970-01-01 00:00:00.000000000 +0000 @@ -1,67 +0,0 @@ -/* - * Copyright (C) 2017 ~ 2017 Deepin Technology Co., Ltd. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * 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 Lesser General Public License - * along with this program. If not, see . - */ - -#ifndef DBASEFILEWATCHER_H -#define DBASEFILEWATCHER_H - -#include "dtkcore_global.h" -#include "dobject.h" - -#include - -DCORE_BEGIN_NAMESPACE - -class DBaseFileWatcherPrivate; -class LIBDTKCORESHARED_EXPORT DBaseFileWatcher : public QObject, public DObject -{ - Q_OBJECT - -public: - ~DBaseFileWatcher(); - - QUrl fileUrl() const; - - bool startWatcher(); - bool stopWatcher(); - bool restartWatcher(); - - virtual void setEnabledSubfileWatcher(const QUrl &subfileUrl, bool enabled = true); - - using SignalType1 = void(DBaseFileWatcher::*)(const QUrl &); - using SignalType2 = void(DBaseFileWatcher::*)(const QUrl &, const QUrl &); - static bool ghostSignal(const QUrl &targetUrl, SignalType1 signal, const QUrl &arg1); - static bool ghostSignal(const QUrl &targetUrl, SignalType2 signal, const QUrl &arg1, const QUrl &arg2); - -Q_SIGNALS: - void fileDeleted(const QUrl &url); - void fileAttributeChanged(const QUrl &url); - void fileMoved(const QUrl &fromUrl, const QUrl &toUrl); - void subfileCreated(const QUrl &url); - void fileModified(const QUrl &url); - void fileClosed(const QUrl &url); - -protected: - explicit DBaseFileWatcher(DBaseFileWatcherPrivate &dd, const QUrl &url, QObject *parent = 0); - -private: - Q_DISABLE_COPY(DBaseFileWatcher) - D_DECLARE_PRIVATE(DBaseFileWatcher) -}; - -DCORE_END_NAMESPACE - -#endif // DBASEFILEWATCHER_H diff -Nru dtkcore-5.5.33/src/filesystem/dcapfile.cpp dtkcore-5.6.2/src/filesystem/dcapfile.cpp --- dtkcore-5.5.33/src/filesystem/dcapfile.cpp 1970-01-01 00:00:00.000000000 +0000 +++ dtkcore-5.6.2/src/filesystem/dcapfile.cpp 2022-09-21 05:21:07.000000000 +0000 @@ -0,0 +1,386 @@ +// SPDX-FileCopyrightText: 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later + +#include "dcapfile.h" +#include "dobject_p.h" +#include "dcapmanager.h" +#include "private/dcapfsfileengine_p.h" + +#include + +DCORE_BEGIN_NAMESPACE + +extern QString _d_cleanPath(const QString &path); +extern bool _d_isSubFileOf(const QString &filePath, const QString &directoryPath); + +class DCapFilePrivate : public DObjectPrivate +{ + D_DECLARE_PUBLIC(DCapFile) +public: + DCapFilePrivate(DCapFile *qq, const QString &fileName = QString()); + static bool canReadWrite(const QString &path); + + QString fileName; +}; + +DCapFilePrivate::DCapFilePrivate(DCapFile *qq, const QString &fileName) + : DObjectPrivate(qq) + , fileName(fileName) +{ +} + +bool DCapFilePrivate::canReadWrite(const QString &path) +{ + DCapFSFileEngine engine(path); + return engine.canReadWrite(path); +} + +DCapFile::DCapFile(QObject *parent) + : QFile(parent) + , DObject(*new DCapFilePrivate(this)) +{ + +} + +DCapFile::DCapFile(const QString &name, QObject *parent) + : QFile(name, parent) + , DObject(*new DCapFilePrivate(this, name)) +{ +} + +DCapFile::~DCapFile() +{ + +} + +void DCapFile::setFileName(const QString &name) +{ + D_D(DCapFile); + d->fileName = name; + return QFile::setFileName(name); +} + +bool DCapFile::exists() const +{ + D_DC(DCapFile); + if (!d->canReadWrite(d->fileName)) + return false; + + return QFile::exists(); +} + +bool DCapFile::exists(const QString &fileName) +{ + return DCapFile(fileName).exists(); +} + +QString DCapFile::readLink() const +{ + D_DC(DCapFile); + if (!d->canReadWrite(d->fileName)) + return {}; + + return QFile::readLink(); +} + +#if QT_VERSION >= QT_VERSION_CHECK(5, 13, 0) +QString DCapFile::symLinkTarget() const +{ + return readLink(); +} +#endif + +bool DCapFile::remove() +{ + D_D(DCapFile); + if (!d->canReadWrite(d->fileName)) + return false; + + return QFile::remove(); +} + +bool DCapFile::remove(const QString &fileName) +{ + return DCapFile(fileName).remove(); +} + +#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0) +bool DCapFile::moveToTrash() +{ + D_D(DCapFile); + if (!d->canReadWrite(d->fileName)) + return false; + + return QFile::moveToTrash(); +} + +bool DCapFile::moveToTrash(const QString &fileName, QString *pathInTrash) +{ + DCapFile file(fileName); + if (file.moveToTrash()) { + if (pathInTrash) + *pathInTrash = file.fileName(); + return true; + } + return false; +} +#endif + +bool DCapFile::rename(const QString &newName) +{ + D_D(DCapFile); + if (!d->canReadWrite(newName)) + return false; + + return QFile::rename(newName); +} + +bool DCapFile::rename(const QString &oldName, const QString &newName) +{ + if (!DCapFilePrivate::canReadWrite(oldName)) + return false; + + return DCapFile(oldName).rename(newName); +} + +bool DCapFile::link(const QString &newName) +{ + D_D(DCapFile); + if (!d->canReadWrite(newName)) + return false; + + return QFile::link(newName); +} + +bool DCapFile::link(const QString &oldName, const QString &newName) +{ + if (!DCapFilePrivate::canReadWrite(oldName)) + return false; + + return DCapFile(oldName).link(newName); +} + +bool DCapFile::copy(const QString &newName) +{ + D_D(DCapFile); + if (!d->canReadWrite(newName)) + return false; + + return QFile::copy(newName); +} + +bool DCapFile::copy(const QString &fileName, const QString &newName) +{ + if (!DCapFilePrivate::canReadWrite(fileName)) + return false; + + return DCapFile(fileName).copy(newName); +} + +bool DCapFile::open(QIODevice::OpenMode flags) +{ + D_D(DCapFile); + if (!d->canReadWrite(d->fileName)) + return false; + + return QFile::open(flags); +} + +bool DCapFile::resize(qint64 sz) +{ + D_D(DCapFile); + if (!d->canReadWrite(d->fileName)) + return false; + + return QFile::resize(sz); +} + +bool DCapFile::resize(const QString &fileName, qint64 sz) +{ + return DCapFile(fileName).resize(sz); +} + +bool DCapFile::open(FILE *, QIODevice::OpenMode, QFileDevice::FileHandleFlags) +{ + return false; +} + +bool DCapFile::open(int, QIODevice::OpenMode, QFileDevice::FileHandleFlags) +{ + return false; +} + +class DCapDirPrivate : public QSharedData +{ +public: + DCapDirPrivate(QString filePath); + explicit DCapDirPrivate(const DCapDirPrivate ©); + + QString filePath; +}; + +DCapDirPrivate::DCapDirPrivate(QString filePath) + : filePath(filePath) +{ +} + +DCapDirPrivate::DCapDirPrivate(const DCapDirPrivate ©) + : QSharedData(copy) + , filePath(copy.filePath) +{ +} + +DCapDir::DCapDir(const DCapDir &dir) + : QDir(dir) + , dd_ptr(dir.dd_ptr) +{ + +} + +DCapDir::DCapDir(const QString &path) + : QDir(path) + , dd_ptr(new DCapDirPrivate(path)) +{ + +} + +DCapDir::DCapDir(const QString &path, const QString &nameFilter, + QDir::SortFlags sort, QDir::Filters filter) + : QDir(path, nameFilter, sort, filter) + , dd_ptr(new DCapDirPrivate(path)) +{ + +} + +DCapDir::~DCapDir() +{ + +} + +void DCapDir::setPath(const QString &path) +{ + dd_ptr = new DCapDirPrivate(path); + return QDir::setPath(path); +} + +bool DCapDir::cd(const QString &dirName) +{ + auto old_d = d_ptr; + bool ret = QDir::cd(dirName); + if (!ret) + return ret; + + // take the new path. + auto path = QDir::filePath(""); + QScopedPointer fsEngine(new DCapFSFileEngine(path)); + if (fsEngine->fileFlags(QAbstractFileEngine::FlagsMask) & QAbstractFileEngine::ExistsFlag) { + dd_ptr = new DCapDirPrivate(path); + return true; + } + d_ptr = old_d; + return false; +} + +QStringList DCapDir::entryList(DCapDir::Filters filters, DCapDir::SortFlags sort) const +{ + const QDirPrivate* d = d_ptr.constData(); + return entryList(d->nameFilters, filters, sort); +} + +QStringList DCapDir::entryList(const QStringList &nameFilters, DCapDir::Filters filters, DCapDir::SortFlags sort) const +{ + if (!DCapFilePrivate::canReadWrite(dd_ptr->filePath)) + return {}; + return QDir::entryList(nameFilters, filters, sort); +} + +QFileInfoList DCapDir::entryInfoList(QDir::Filters filters, QDir::SortFlags sort) const +{ + const QDirPrivate* d = d_ptr.constData(); + return entryInfoList(d->nameFilters, filters, sort); +} + +QFileInfoList DCapDir::entryInfoList(const QStringList &nameFilters, DCapDir::Filters filters, DCapDir::SortFlags sort) const +{ + if (!DCapFilePrivate::canReadWrite(dd_ptr->filePath)) + return {}; + return QDir::entryInfoList(nameFilters, filters, sort); +} + +bool DCapDir::mkdir(const QString &dirName) const +{ + QString fn = filePath(dirName); + if (!DCapFilePrivate::canReadWrite(fn)) + return false; + + return QDir::mkdir(dirName); +} + +bool DCapDir::rmdir(const QString &dirName) const +{ + QString fn = filePath(dirName); + if (!DCapFilePrivate::canReadWrite(fn)) + return false; + + return QDir::rmdir(dirName); +} + +bool DCapDir::mkpath(const QString &dirPath) const +{ + QString fn = filePath(dirPath); + if (!DCapFilePrivate::canReadWrite(fn)) + return false; + + return QDir::mkpath(dirPath); +} + +bool DCapDir::rmpath(const QString &dirPath) const +{ + QString fn = filePath(dirPath); + if (!DCapFilePrivate::canReadWrite(fn)) + return false; + + return QDir::rmpath(dirPath); +} + +bool DCapDir::exists() const +{ + if (!DCapFilePrivate::canReadWrite(dd_ptr->filePath)) + return false; + + return QDir::exists(); +} + +bool DCapDir::exists(const QString &name) const +{ + if (name.isEmpty()) { + qWarning("DCapFile::exists: Empty or null file name"); + return false; + } + return DCapFile::exists(filePath(name)); +} + +bool DCapDir::remove(const QString &fileName) +{ + if (fileName.isEmpty()) { + qWarning("DCapDir::remove: Empty or null file name"); + return false; + } + return DCapFile::remove(filePath(fileName)); +} + +bool DCapDir::rename(const QString &oldName, const QString &newName) +{ + if (oldName.isEmpty() || newName.isEmpty()) { + qWarning("DCapDir::rename: Empty or null file name(s)"); + return false; + } + + DCapFile file(filePath(oldName)); + if (!file.exists()) + return false; + return file.rename(filePath(newName)); +} + +DCORE_END_NAMESPACE diff -Nru dtkcore-5.5.33/src/filesystem/dcapfsfileengine.cpp dtkcore-5.6.2/src/filesystem/dcapfsfileengine.cpp --- dtkcore-5.5.33/src/filesystem/dcapfsfileengine.cpp 1970-01-01 00:00:00.000000000 +0000 +++ dtkcore-5.6.2/src/filesystem/dcapfsfileengine.cpp 2022-09-21 05:21:07.000000000 +0000 @@ -0,0 +1,209 @@ +// SPDX-FileCopyrightText: 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later + +#include "private/dcapfsfileengine_p.h" +#include "private/dobject_p.h" +#include "dvtablehook.h" + +#include "dcapmanager.h" +#include + +DCORE_BEGIN_NAMESPACE + +extern QString _d_cleanPath(const QString &path); +extern bool _d_isSubFileOf(const QString &filePath, const QString &directoryPath); + +static bool capDirIteraterHasNext(QAbstractFileEngineIterator *it) +{ + const QStringList &paths = DCapManager::instance()->paths(); + QString path = it->path(); + QFileInfo info(path); + if (info.isSymLink()) + info = info.symLinkTarget(); + + bool ret = std::any_of(paths.cbegin(), paths.cend(), std::bind(_d_isSubFileOf, path, std::placeholders::_1)); + + if (!ret) + return ret; + return DVtableHook::callOriginalFun(it, &QAbstractFileEngineIterator::hasNext); +} + +QAbstractFileEngine *DCapFSFileEngineHandler::create(const QString &fileName) const +{ + return new DCapFSFileEngine(fileName); +} + + +class DCapFSFileEnginePrivate : public DObjectPrivate +{ + D_DECLARE_PUBLIC(DCapFSFileEngine) +public: + DCapFSFileEnginePrivate(const QString &file, DCapFSFileEngine *qq); + + bool canReadWrite(const QString &path) const; + + QString file; +}; + +DCapFSFileEnginePrivate::DCapFSFileEnginePrivate(const QString &file, DCapFSFileEngine *qq) + : DObjectPrivate(qq) + , file(file) +{ + +} + +bool DCapFSFileEnginePrivate::canReadWrite(const QString &path) const +{ + if (path.isEmpty()) + return false; + + QString target = path; + if (path == this->file) { + D_QC(DCapFSFileEngine); + target = q->fileName(DCapFSFileEngine::AbsoluteName); + } else { + QFSFileEngine engine(path); + target = engine.fileName(DCapFSFileEngine::AbsoluteName); + } + + auto paths = DCapManager::instance()->paths(); + return std::any_of(paths.cbegin(), paths.cend(), + std::bind(_d_isSubFileOf, target, std::placeholders::_1)); +} + +DCapFSFileEngine::DCapFSFileEngine(const QString &file) + : QFSFileEngine(file) + , DObject(*new DCapFSFileEnginePrivate(file, this)) +{ + +} + +DCapFSFileEngine::~DCapFSFileEngine() +{ +} + +bool DCapFSFileEngine::open(QIODevice::OpenMode openMode) +{ + D_D(DCapFSFileEngine); + if (!d->canReadWrite(d->file)) + return false; + return QFSFileEngine::open(openMode); +} + +bool DCapFSFileEngine::remove() +{ + D_D(DCapFSFileEngine); + if (!d->canReadWrite(d->file)) + return false; + return QFSFileEngine::remove(); +} + +bool DCapFSFileEngine::copy(const QString &newName) +{ + D_D(DCapFSFileEngine); + if (!d->canReadWrite(newName)) { + // ###(Chen Bin): If false is returned here, QFile + // will use the interface of qtemporaryfile for + // file operation, and the restrictions in + // DCapFSFileEngine cannot be used. And it will be + // copied successfully. + qWarning() << "DCapFSFileEngine: " << QStringLiteral("The file [%1] has no permission to copy!").arg(newName); + return true; + } + return QFSFileEngine::copy(newName); +} + +bool DCapFSFileEngine::rename(const QString &newName) +{ + D_D(DCapFSFileEngine); + if (!d->canReadWrite(newName)) + return false; + return QFSFileEngine::rename(newName); +} + +bool DCapFSFileEngine::renameOverwrite(const QString &newName) +{ + D_D(DCapFSFileEngine); + if (!d->canReadWrite(newName)) + return false; + return QFSFileEngine::renameOverwrite(newName); +} + +bool DCapFSFileEngine::link(const QString &newName) +{ + D_D(DCapFSFileEngine); + if (!d->canReadWrite(newName)) + return false; + return QFSFileEngine::link(newName); +} + +bool DCapFSFileEngine::mkdir(const QString &dirName, bool createParentDirectories) const +{ + D_DC(DCapFSFileEngine); + if (!d->canReadWrite(dirName)) + return false; + return QFSFileEngine::mkdir(dirName, createParentDirectories); +} + +bool DCapFSFileEngine::rmdir(const QString &dirName, bool recurseParentDirectories) const +{ + D_DC(DCapFSFileEngine); + if (!d->canReadWrite(dirName)) + return false; + return QFSFileEngine::rmdir(dirName, recurseParentDirectories); +} + +QAbstractFileEngine::FileFlags DCapFSFileEngine::fileFlags(QAbstractFileEngine::FileFlags type) const +{ + D_DC(DCapFSFileEngine); + FileFlags ret = QFSFileEngine::fileFlags(type); + if (ret | ExistsFlag) { + if (!d->canReadWrite(d->file)) { + ret &= ~ExistsFlag; + } + } + + return ret; +} + +bool DCapFSFileEngine::cloneTo(QAbstractFileEngine *target) +{ + D_DC(DCapFSFileEngine); + const QString targetPath = target->fileName(DCapFSFileEngine::AbsolutePathName); + if (!d->canReadWrite(targetPath)) + return false; + return QFSFileEngine::cloneTo(target); +} + +bool DCapFSFileEngine::setSize(qint64 size) +{ + D_D(DCapFSFileEngine); + if (!d->canReadWrite(d->file)) + return false; + return QFSFileEngine::setSize(size); +} + +QStringList DCapFSFileEngine::entryList(QDir::Filters filters, const QStringList &filterNames) const +{ + D_DC(DCapFSFileEngine); + if (!d->canReadWrite(d->file)) + return {}; + return QFSFileEngine::entryList(filters, filterNames); +} + +QAbstractFileEngine::Iterator *DCapFSFileEngine::beginEntryList(QDir::Filters filters, const QStringList &filterNames) +{ + auto ret = QFSFileEngine::beginEntryList(filters, filterNames); + DVtableHook::overrideVfptrFun(ret, &QAbstractFileEngineIterator::hasNext, &capDirIteraterHasNext); + return ret; +} + +bool DCapFSFileEngine::canReadWrite(const QString &path) const +{ + D_DC(DCapFSFileEngine); + return d->canReadWrite(path); +} + +DCORE_END_NAMESPACE + diff -Nru dtkcore-5.5.33/src/filesystem/dcapmanager.cpp dtkcore-5.6.2/src/filesystem/dcapmanager.cpp --- dtkcore-5.5.33/src/filesystem/dcapmanager.cpp 1970-01-01 00:00:00.000000000 +0000 +++ dtkcore-5.6.2/src/filesystem/dcapmanager.cpp 2022-09-21 05:21:07.000000000 +0000 @@ -0,0 +1,152 @@ +// SPDX-FileCopyrightText: 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later + +#include "dcapmanager.h" +#include "dobject_p.h" +#include "dstandardpaths.h" +#include "private/dcapfsfileengine_p.h" + +#include +#include + +DCORE_BEGIN_NAMESPACE + +QString _d_cleanPath(const QString &path) { + return path.size() < 2 || !path.endsWith(QDir::separator()) ? path : path.chopped(1); +} + +bool _d_isSubFileOf(const QString &filePath, const QString &directoryPath) +{ + QString path = _d_cleanPath(filePath); + bool ret = path.startsWith(directoryPath); + return ret; +} + +static QStringList defaultWriteablePaths() { + QStringList paths; + int list[] = { + QStandardPaths::AppConfigLocation, QStandardPaths::AppDataLocation, + QStandardPaths::CacheLocation, QStandardPaths::TempLocation, + QStandardPaths::DataLocation, QStandardPaths::GenericConfigLocation, + QStandardPaths::HomeLocation, QStandardPaths::MusicLocation, + QStandardPaths::DocumentsLocation, QStandardPaths::MoviesLocation, + QStandardPaths::PicturesLocation, QStandardPaths::DownloadLocation + }; + + for (uint i = 0; i < sizeof (list) / sizeof (int); ++i) { + const QString &path = QStandardPaths::writableLocation(QStandardPaths::StandardLocation(list[i])); + if (path.isEmpty()) + continue; + + paths.append(path); + } + + for (int i = 0; i <= static_cast(DStandardPaths::XDG::RuntimeTime); ++i) { + const QString &path = DStandardPaths::path(DStandardPaths::XDG(i)); + if (path.isEmpty()) + continue; + + paths.append(path); + } + + for (int i = 0; i <= static_cast(DStandardPaths::DSG::DataDir); ++i) { + const QStringList &pathList = DStandardPaths::paths(DStandardPaths::DSG(i)); + if (pathList.isEmpty()) + continue; + + for (auto path : pathList) { + if (path.isEmpty() || paths.contains(path)) + continue; + + paths.append(path); + } + } + return paths; +} + +static DCapFSFileEngineHandler *globalHandler = nullptr; + +class DCapManagerPrivate : public DObjectPrivate +{ + D_DECLARE_PUBLIC(DCapManager) +public: + DCapManagerPrivate(DCapManager *qq); + + QStringList pathList; +}; + +class DCapManager_ : public DCapManager {}; +Q_GLOBAL_STATIC(DCapManager_, capManager) + +DCapManagerPrivate::DCapManagerPrivate(DCapManager *qq) + : DObjectPrivate(qq) +{ + pathList = defaultWriteablePaths(); +} + +DCapManager::DCapManager() + : DObject(*new DCapManagerPrivate(this)) +{ + +} + +DCapManager *DCapManager::instance() +{ + return capManager; +} + +void DCapManager::registerFileEngine() +{ + if (globalHandler) + return; + globalHandler = new DCapFSFileEngineHandler; +} + +void DCapManager::unregisterFileEngine() +{ + if (!globalHandler) + return; + delete globalHandler; + globalHandler = nullptr; +} + +void DCapManager::appendPath(const QString &path) +{ + D_D(DCapManager); + const QString &targetPath = _d_cleanPath(path); + bool exist = std::any_of(d->pathList.cbegin(), d->pathList.cend(), + std::bind(_d_isSubFileOf, targetPath, std::placeholders::_1)); + if (exist) + return; + d->pathList.append(targetPath); +} + +void DCapManager::appendPaths(const QStringList &pathList) +{ + for (auto path : pathList) + appendPath(path); +} + +void DCapManager::removePath(const QString &path) +{ + D_D(DCapManager); + const QString &targetPath = _d_cleanPath(path); + if (!d->pathList.contains(targetPath)) + return; + d->pathList.removeOne(targetPath); +} + +void DCapManager::removePaths(const QStringList &paths) +{ + for (auto path : paths) + removePath(path); +} + +QStringList DCapManager::paths() const +{ + D_DC(DCapManager); + return d->pathList; +} + +DCORE_END_NAMESPACE diff -Nru dtkcore-5.5.33/src/filesystem/DFileSystemWatcher dtkcore-5.6.2/src/filesystem/DFileSystemWatcher --- dtkcore-5.5.33/src/filesystem/DFileSystemWatcher 2022-07-19 09:10:28.000000000 +0000 +++ dtkcore-5.6.2/src/filesystem/DFileSystemWatcher 1970-01-01 00:00:00.000000000 +0000 @@ -1 +0,0 @@ -#include "dfilesystemwatcher.h" diff -Nru dtkcore-5.5.33/src/filesystem/dfilesystemwatcher_dummy.cpp dtkcore-5.6.2/src/filesystem/dfilesystemwatcher_dummy.cpp --- dtkcore-5.5.33/src/filesystem/dfilesystemwatcher_dummy.cpp 2022-07-19 09:10:28.000000000 +0000 +++ dtkcore-5.6.2/src/filesystem/dfilesystemwatcher_dummy.cpp 2022-09-21 05:21:07.000000000 +0000 @@ -1,19 +1,7 @@ -/* - * Copyright (C) 2017 ~ 2017 Deepin Technology Co., Ltd. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * 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 Lesser General Public License - * along with this program. If not, see . - */ +// SPDX-FileCopyrightText: 2017 - 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later + #include "dfilesystemwatcher.h" #include "private/dfilesystemwatcher_dummy_p.h" diff -Nru dtkcore-5.5.33/src/filesystem/dfilesystemwatcher.h dtkcore-5.6.2/src/filesystem/dfilesystemwatcher.h --- dtkcore-5.5.33/src/filesystem/dfilesystemwatcher.h 2022-07-19 09:10:28.000000000 +0000 +++ dtkcore-5.6.2/src/filesystem/dfilesystemwatcher.h 1970-01-01 00:00:00.000000000 +0000 @@ -1,62 +0,0 @@ -/* - * Copyright (C) 2017 ~ 2017 Deepin Technology Co., Ltd. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * 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 Lesser General Public License - * along with this program. If not, see . - */ - -#ifndef DFILESYSTEMWATCHER_H -#define DFILESYSTEMWATCHER_H - -#include "dtkcore_global.h" -#include "dobject.h" - -#include - -DCORE_BEGIN_NAMESPACE - -class DFileSystemWatcherPrivate; -class LIBDTKCORESHARED_EXPORT DFileSystemWatcher : public QObject, public DObject -{ - Q_OBJECT - D_DECLARE_PRIVATE(DFileSystemWatcher) - -public: - DFileSystemWatcher(QObject *parent = Q_NULLPTR); - DFileSystemWatcher(const QStringList &paths, QObject *parent = Q_NULLPTR); - ~DFileSystemWatcher(); - - bool addPath(const QString &file); - QStringList addPaths(const QStringList &files); - bool removePath(const QString &file); - QStringList removePaths(const QStringList &files); - - QStringList files() const; - QStringList directories() const; - -Q_SIGNALS: - void fileDeleted(const QString &path, const QString &name, QPrivateSignal); - void fileAttributeChanged(const QString &path, const QString &name, QPrivateSignal); - void fileClosed(const QString &path, const QString &name, QPrivateSignal); - void fileMoved(const QString &fromPath, const QString &fromName, - const QString &toPath, const QString &toName, QPrivateSignal); - void fileCreated(const QString &path, const QString &name, QPrivateSignal); - void fileModified(const QString &path, const QString &name, QPrivateSignal); - -private: - Q_PRIVATE_SLOT(d_func(), void _q_readFromInotify()) -}; - -DCORE_END_NAMESPACE - -#endif // DFILESYSTEMWATCHER_H diff -Nru dtkcore-5.5.33/src/filesystem/dfilesystemwatcher_linux.cpp dtkcore-5.6.2/src/filesystem/dfilesystemwatcher_linux.cpp --- dtkcore-5.5.33/src/filesystem/dfilesystemwatcher_linux.cpp 2022-07-19 09:10:28.000000000 +0000 +++ dtkcore-5.6.2/src/filesystem/dfilesystemwatcher_linux.cpp 2022-09-21 05:21:07.000000000 +0000 @@ -1,19 +1,6 @@ -/* - * Copyright (C) 2017 ~ 2017 Deepin Technology Co., Ltd. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * 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 Lesser General Public License - * along with this program. If not, see . - */ +// SPDX-FileCopyrightText: 2017 - 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later #include "dfilesystemwatcher.h" #include "private/dfilesystemwatcher_linux_p.h" @@ -486,12 +473,7 @@ */ bool DFileSystemWatcher::addPath(const QString &path) { - if (path.isEmpty()) { - qWarning("DFileSystemWatcher::addPath: path is empty"); - return true; - } - - QStringList paths = addPaths(QStringList(path)); + const QStringList &paths = addPaths(QStringList(path)); return paths.isEmpty(); } @@ -522,22 +504,26 @@ { Q_D(DFileSystemWatcher); + if (!d) + return paths; + QStringList p = paths; QMutableListIterator it(p); while (it.hasNext()) { const QString &path = it.next(); - if (path.isEmpty()) + if (path.isEmpty()) { + qWarning() << Q_FUNC_INFO << "the path is empty and it is not be watched"; it.remove(); + } } if (p.isEmpty()) { - qWarning("DFileSystemWatcher::addPaths: list is empty"); - return QStringList(); + qWarning() << Q_FUNC_INFO << "all path are filtered and they are not be watched, paths are " << paths; + return paths; } - if (d) - p = d->addPaths(p, &d->files, &d->directories); + p = d->addPaths(p, &d->files, &d->directories); return p; } @@ -554,12 +540,7 @@ */ bool DFileSystemWatcher::removePath(const QString &path) { - if (path.isEmpty()) { - qWarning("DFileSystemWatcher::removePath: path is empty"); - return true; - } - - QStringList paths = removePaths(QStringList(path)); + const QStringList &paths = removePaths(QStringList(path)); return paths.isEmpty(); } @@ -578,22 +559,26 @@ { Q_D(DFileSystemWatcher); + if (!d) + return paths; + QStringList p = paths; QMutableListIterator it(p); while (it.hasNext()) { const QString &path = it.next(); - if (path.isEmpty()) + if (path.isEmpty()) { + qWarning() << Q_FUNC_INFO << "the path is empty and it is not be removed from watched list"; it.remove(); + } } if (p.isEmpty()) { - qWarning("DFileSystemWatcher::removePaths: list is empty"); - return QStringList(); + qWarning() << Q_FUNC_INFO << "all path are filtered and they are not be watched, paths are " << paths; + return paths; } - if (d) - p = d->removePaths(p, &d->files, &d->directories); + p = d->removePaths(p, &d->files, &d->directories); return p; } diff -Nru dtkcore-5.5.33/src/filesystem/dfilesystemwatcher_win.cpp dtkcore-5.6.2/src/filesystem/dfilesystemwatcher_win.cpp --- dtkcore-5.5.33/src/filesystem/dfilesystemwatcher_win.cpp 2022-07-19 09:10:28.000000000 +0000 +++ dtkcore-5.6.2/src/filesystem/dfilesystemwatcher_win.cpp 2022-09-21 05:21:07.000000000 +0000 @@ -1,19 +1,7 @@ -/* - * Copyright (C) 2017 ~ 2017 Deepin Technology Co., Ltd. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * 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 Lesser General Public License - * along with this program. If not, see . - */ +// SPDX-FileCopyrightText: 2017 - 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later + #include "dfilesystemwatcher.h" #include "private/dfilesystemwatcher_win_p.h" diff -Nru dtkcore-5.5.33/src/filesystem/DFileWatcher dtkcore-5.6.2/src/filesystem/DFileWatcher --- dtkcore-5.5.33/src/filesystem/DFileWatcher 2022-07-19 09:10:28.000000000 +0000 +++ dtkcore-5.6.2/src/filesystem/DFileWatcher 1970-01-01 00:00:00.000000000 +0000 @@ -1 +0,0 @@ -#include "dfilewatcher.h" diff -Nru dtkcore-5.5.33/src/filesystem/dfilewatcher.cpp dtkcore-5.6.2/src/filesystem/dfilewatcher.cpp --- dtkcore-5.5.33/src/filesystem/dfilewatcher.cpp 2022-07-19 09:10:28.000000000 +0000 +++ dtkcore-5.6.2/src/filesystem/dfilewatcher.cpp 2022-09-21 05:21:07.000000000 +0000 @@ -1,19 +1,6 @@ -/* - * Copyright (C) 2017 ~ 2017 Deepin Technology Co., Ltd. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * 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 Lesser General Public License - * along with this program. If not, see . - */ +// SPDX-FileCopyrightText: 2017 - 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later #include "dfilewatcher.h" #include "private/dbasefilewatcher_p.h" @@ -219,7 +206,7 @@ \class Dtk::Core::DFileWatcher \inmodule dtkcore - \brief The DFileWatcher class provides an implemention of DBaseFileWatcher for monitoring files and directories for modifications. + \brief The DFileWatcher class provides an implementation of DBaseFileWatcher for monitoring files and directories for modifications. \brief DFileWatcher 类提供了对 DBaseFileWatcher 接口的实现,可供监视文件和目录的变动。 */ diff -Nru dtkcore-5.5.33/src/filesystem/dfilewatcher.h dtkcore-5.6.2/src/filesystem/dfilewatcher.h --- dtkcore-5.5.33/src/filesystem/dfilewatcher.h 2022-07-19 09:10:28.000000000 +0000 +++ dtkcore-5.6.2/src/filesystem/dfilewatcher.h 1970-01-01 00:00:00.000000000 +0000 @@ -1,48 +0,0 @@ -/* - * Copyright (C) 2017 ~ 2017 Deepin Technology Co., Ltd. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * 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 Lesser General Public License - * along with this program. If not, see . - */ - -#ifndef DFILEWATCHER_H -#define DFILEWATCHER_H - -#include "dbasefilewatcher.h" - -DCORE_BEGIN_NAMESPACE - -class DFileWatcherPrivate; -class LIBDTKCORESHARED_EXPORT DFileWatcher : public DBaseFileWatcher -{ - Q_OBJECT - -public: - explicit DFileWatcher(const QString &filePath, QObject *parent = 0); - -private Q_SLOTS: - void onFileDeleted(const QString &path, const QString &name); - void onFileAttributeChanged(const QString &path, const QString &name); - void onFileMoved(const QString &fromPath, const QString &fromName, - const QString &toPath, const QString &toName); - void onFileCreated(const QString &path, const QString &name); - void onFileModified(const QString &path, const QString &name); - void onFileClosed(const QString &path, const QString &name); - -private: - D_DECLARE_PRIVATE(DFileWatcher) -}; - -DCORE_END_NAMESPACE - -#endif // DFILEWATCHER_H diff -Nru dtkcore-5.5.33/src/filesystem/DFileWatcherManager dtkcore-5.6.2/src/filesystem/DFileWatcherManager --- dtkcore-5.5.33/src/filesystem/DFileWatcherManager 2022-07-19 09:10:28.000000000 +0000 +++ dtkcore-5.6.2/src/filesystem/DFileWatcherManager 1970-01-01 00:00:00.000000000 +0000 @@ -1 +0,0 @@ -#include "dfilewatchermanager.h" diff -Nru dtkcore-5.5.33/src/filesystem/dfilewatchermanager.cpp dtkcore-5.6.2/src/filesystem/dfilewatchermanager.cpp --- dtkcore-5.5.33/src/filesystem/dfilewatchermanager.cpp 2022-07-19 09:10:28.000000000 +0000 +++ dtkcore-5.6.2/src/filesystem/dfilewatchermanager.cpp 2022-09-21 05:21:07.000000000 +0000 @@ -1,19 +1,6 @@ -/* - * Copyright (C) 2017 ~ 2017 Deepin Technology Co., Ltd. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * 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 Lesser General Public License - * along with this program. If not, see . - */ +// SPDX-FileCopyrightText: 2017 - 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later #include "dfilewatchermanager.h" #include "dfilewatcher.h" diff -Nru dtkcore-5.5.33/src/filesystem/dfilewatchermanager.h dtkcore-5.6.2/src/filesystem/dfilewatchermanager.h --- dtkcore-5.5.33/src/filesystem/dfilewatchermanager.h 2022-07-19 09:10:28.000000000 +0000 +++ dtkcore-5.6.2/src/filesystem/dfilewatchermanager.h 1970-01-01 00:00:00.000000000 +0000 @@ -1,59 +0,0 @@ -/* - * Copyright (C) 2017 ~ 2017 Deepin Technology Co., Ltd. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * 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 Lesser General Public License - * along with this program. If not, see . - */ - -#ifndef DFILEWATCHERMANAGER_H -#define DFILEWATCHERMANAGER_H - -#include "dtkcore_global.h" -#include "dobject.h" - -#include - -DCORE_BEGIN_NAMESPACE - -class DFileWatcher; - -class DFileWatcherManagerPrivate; -class LIBDTKCORESHARED_EXPORT DFileWatcherManager : public QObject, public DObject -{ - Q_OBJECT - -public: - explicit DFileWatcherManager(QObject *parent = 0); - ~DFileWatcherManager(); - - DFileWatcher *add(const QString &filePath); - void remove(const QString &filePath); - -Q_SIGNALS: - void fileDeleted(const QString &filePath); - void fileAttributeChanged(const QString &filePath); - void fileMoved(const QString &fromFilePath, const QString &toFilePath); - void subfileCreated(const QString &filePath); - void fileModified(const QString &filePath); - void fileClosed(const QString &filePath); - -private: - QScopedPointer d_ptr; - - D_DECLARE_PRIVATE(DFileWatcherManager) - Q_DISABLE_COPY(DFileWatcherManager) -}; - -DCORE_END_NAMESPACE - -#endif // DFILEWATCHERMANAGER_H diff -Nru dtkcore-5.5.33/src/filesystem/DPathBuf dtkcore-5.6.2/src/filesystem/DPathBuf --- dtkcore-5.5.33/src/filesystem/DPathBuf 2022-07-19 09:10:28.000000000 +0000 +++ dtkcore-5.6.2/src/filesystem/DPathBuf 1970-01-01 00:00:00.000000000 +0000 @@ -1 +0,0 @@ -#include "dpathbuf.h" diff -Nru dtkcore-5.5.33/src/filesystem/dpathbuf.cpp dtkcore-5.6.2/src/filesystem/dpathbuf.cpp --- dtkcore-5.5.33/src/filesystem/dpathbuf.cpp 2022-07-19 09:10:28.000000000 +0000 +++ dtkcore-5.6.2/src/filesystem/dpathbuf.cpp 2022-09-21 05:21:07.000000000 +0000 @@ -1,3 +1,7 @@ +// SPDX-FileCopyrightText: 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later + #include "dpathbuf.h" /*! diff -Nru dtkcore-5.5.33/src/filesystem/dpathbuf.h dtkcore-5.6.2/src/filesystem/dpathbuf.h --- dtkcore-5.5.33/src/filesystem/dpathbuf.h 2022-07-19 09:10:28.000000000 +0000 +++ dtkcore-5.6.2/src/filesystem/dpathbuf.h 1970-01-01 00:00:00.000000000 +0000 @@ -1,68 +0,0 @@ -/* - * Copyright (C) 2017 ~ 2017 Deepin Technology Co., Ltd. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * 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 Lesser General Public License - * along with this program. If not, see . - */ - -#pragma once - -#include - -#include "dtkcore_global.h" - -DCORE_BEGIN_NAMESPACE - -class LIBDTKCORESHARED_EXPORT DPathBuf -{ -public: - DPathBuf(); - DPathBuf(const QString &path); - - DPathBuf operator/(const QString &p) const - { - return DPathBuf(m_path + "/" + p); - } - - DPathBuf &operator/=(const QString &p) - { - return join(p); - } - - DPathBuf operator/(const char *p) const - { - return operator /(QString(p)); - } - - DPathBuf &operator/=(const char *p) - { - return operator /=(QString(p)); - } - - DPathBuf &join(const QString &p) - { - m_path += "/" + p; - m_path = QDir(m_path).absolutePath(); - return *this; - } - - QString toString() const - { - return QDir::toNativeSeparators(m_path); - } - -private: - QString m_path; -}; - -DCORE_END_NAMESPACE diff -Nru dtkcore-5.5.33/src/filesystem/DStandardPaths dtkcore-5.6.2/src/filesystem/DStandardPaths --- dtkcore-5.5.33/src/filesystem/DStandardPaths 2022-07-19 09:10:28.000000000 +0000 +++ dtkcore-5.6.2/src/filesystem/DStandardPaths 1970-01-01 00:00:00.000000000 +0000 @@ -1 +0,0 @@ -#include "dstandardpaths.h" diff -Nru dtkcore-5.5.33/src/filesystem/dstandardpaths.cpp dtkcore-5.6.2/src/filesystem/dstandardpaths.cpp --- dtkcore-5.5.33/src/filesystem/dstandardpaths.cpp 2022-07-19 09:10:28.000000000 +0000 +++ dtkcore-5.6.2/src/filesystem/dstandardpaths.cpp 2022-09-21 05:21:07.000000000 +0000 @@ -1,19 +1,6 @@ -/* - * Copyright (C) 2017 ~ 2021 Deepin Technology Co., Ltd. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * 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 Lesser General Public License - * along with this program. If not, see . - */ +// SPDX-FileCopyrightText: 2017 - 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later #include "dstandardpaths.h" diff -Nru dtkcore-5.5.33/src/filesystem/dstandardpaths.h dtkcore-5.6.2/src/filesystem/dstandardpaths.h --- dtkcore-5.5.33/src/filesystem/dstandardpaths.h 2022-07-19 09:10:28.000000000 +0000 +++ dtkcore-5.6.2/src/filesystem/dstandardpaths.h 1970-01-01 00:00:00.000000000 +0000 @@ -1,73 +0,0 @@ -/* - * Copyright (C) 2017 ~ 2021 Deepin Technology Co., Ltd. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * 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 Lesser General Public License - * along with this program. If not, see . - */ - -#ifndef DTK_CORE_FILESYSTEM_DSTANDARDPATHS_H -#define DTK_CORE_FILESYSTEM_DSTANDARDPATHS_H - -#include - -#include "dtkcore_global.h" - -DCORE_BEGIN_NAMESPACE - -class DStandardPathsPrivate; -class LIBDTKCORESHARED_EXPORT DStandardPaths -{ -public: - enum Mode { - Auto, - Snap, - Test, - }; - - static QString writableLocation(QStandardPaths::StandardLocation type); - static QStringList standardLocations(QStandardPaths::StandardLocation type); - - static QString locate(QStandardPaths::StandardLocation type, const QString &fileName, QStandardPaths::LocateOptions options = QStandardPaths::LocateFile); - static QStringList locateAll(QStandardPaths::StandardLocation type, const QString &fileName, QStandardPaths::LocateOptions options = QStandardPaths::LocateFile); - static QString findExecutable(const QString &executableName, const QStringList &paths = QStringList()); - static void setMode(Mode mode); - - enum class XDG { - DataHome, - ConfigHome, - CacheHome, - RuntimeTime - }; - - enum class DSG { - AppData, - DataDir - }; - - static QString homePath(); - static QString homePath(const uint uid); - static QString path(XDG type); - static QString path(DSG type); - static QStringList paths(DSG type); - static QString filePath(XDG type, QString fileName); - static QString filePath(DSG type, QString fileName); - -private: - DStandardPaths(); - ~DStandardPaths(); - Q_DISABLE_COPY(DStandardPaths) -}; - -DCORE_END_NAMESPACE - -#endif // DTK_CORE_FILESYSTEM_DSTANDARDPATHS_H diff -Nru dtkcore-5.5.33/src/filesystem/DTrashManager dtkcore-5.6.2/src/filesystem/DTrashManager --- dtkcore-5.5.33/src/filesystem/DTrashManager 2022-07-19 09:10:28.000000000 +0000 +++ dtkcore-5.6.2/src/filesystem/DTrashManager 1970-01-01 00:00:00.000000000 +0000 @@ -1 +0,0 @@ -#include "dtrashmanager.h" diff -Nru dtkcore-5.5.33/src/filesystem/dtrashmanager_dummy.cpp dtkcore-5.6.2/src/filesystem/dtrashmanager_dummy.cpp --- dtkcore-5.5.33/src/filesystem/dtrashmanager_dummy.cpp 2022-07-19 09:10:28.000000000 +0000 +++ dtkcore-5.6.2/src/filesystem/dtrashmanager_dummy.cpp 2022-09-21 05:21:07.000000000 +0000 @@ -1,19 +1,6 @@ -/* - * Copyright (C) 2017 ~ 2017 Deepin Technology Co., Ltd. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * 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 Lesser General Public License - * along with this program. If not, see . - */ +// SPDX-FileCopyrightText: 2017 - 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later #include "dtrashmanager.h" diff -Nru dtkcore-5.5.33/src/filesystem/dtrashmanager.h dtkcore-5.6.2/src/filesystem/dtrashmanager.h --- dtkcore-5.5.33/src/filesystem/dtrashmanager.h 2022-07-19 09:10:28.000000000 +0000 +++ dtkcore-5.6.2/src/filesystem/dtrashmanager.h 1970-01-01 00:00:00.000000000 +0000 @@ -1,47 +0,0 @@ -/* - * Copyright (C) 2017 ~ 2017 Deepin Technology Co., Ltd. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * 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 Lesser General Public License - * along with this program. If not, see . - */ - -#ifndef DTRASHMANAGER_H -#define DTRASHMANAGER_H - -#include -#include - -#include - -DCORE_BEGIN_NAMESPACE - -class DTrashManagerPrivate; -class LIBDTKCORESHARED_EXPORT DTrashManager : public QObject, public DObject -{ -public: - static DTrashManager *instance(); - - bool trashIsEmpty() const; - bool cleanTrash(); - bool moveToTrash(const QString &filePath, bool followSymlink = false); - -protected: - DTrashManager(); - -private: - D_DECLARE_PRIVATE(DTrashManager) -}; - -DCORE_END_NAMESPACE - -#endif // DTRASHMANAGER_H diff -Nru dtkcore-5.5.33/src/filesystem/dtrashmanager_linux.cpp dtkcore-5.6.2/src/filesystem/dtrashmanager_linux.cpp --- dtkcore-5.5.33/src/filesystem/dtrashmanager_linux.cpp 2022-07-19 09:10:28.000000000 +0000 +++ dtkcore-5.6.2/src/filesystem/dtrashmanager_linux.cpp 2022-09-21 05:21:07.000000000 +0000 @@ -1,23 +1,10 @@ -/* - * Copyright (C) 2017 ~ 2017 Deepin Technology Co., Ltd. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * 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 Lesser General Public License - * along with this program. If not, see . - */ +// SPDX-FileCopyrightText: 2017 - 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later #include "dtrashmanager.h" #include "dstandardpaths.h" -#include "private/dobject_p.h" +#include "base/private/dobject_p.h" #include #include diff -Nru dtkcore-5.5.33/src/filesystem/filesystem.cmake dtkcore-5.6.2/src/filesystem/filesystem.cmake --- dtkcore-5.5.33/src/filesystem/filesystem.cmake 1970-01-01 00:00:00.000000000 +0000 +++ dtkcore-5.6.2/src/filesystem/filesystem.cmake 2022-09-21 05:21:07.000000000 +0000 @@ -0,0 +1,57 @@ +if(APPLE) + set(FILESYSTEM_SOURCE + ${CMAKE_CURRENT_LIST_DIR}/private/dbasefilewatcher_p.h + ${CMAKE_CURRENT_LIST_DIR}/private/dfilesystemwatcher_linux_p.h + ${CMAKE_CURRENT_LIST_DIR}/private/dcapfsfileengine_p.h + ${CMAKE_CURRENT_LIST_DIR}/dbasefilewatcher.cpp + ${CMAKE_CURRENT_LIST_DIR}/dfilesystemwatcher_dummy.cpp + ${CMAKE_CURRENT_LIST_DIR}/dfilewatcher.cpp + ${CMAKE_CURRENT_LIST_DIR}/dfilewatchermanager.cpp + ${CMAKE_CURRENT_LIST_DIR}/dpathbuf.cpp + ${CMAKE_CURRENT_LIST_DIR}/dtrashmanager_dummy.cpp + ${CMAKE_CURRENT_LIST_DIR}/dstandardpaths.cpp + ${CMAKE_CURRENT_LIST_DIR}/dcapfile.cpp + ${CMAKE_CURRENT_LIST_DIR}/dcapmanager.cpp + ${CMAKE_CURRENT_LIST_DIR}/dcapfsfileengine.cpp + ) +elseif(WIN32) + set(FILESYSTEM_SOURCE + ${CMAKE_CURRENT_LIST_DIR}/private/dbasefilewatcher_p.h + ${CMAKE_CURRENT_LIST_DIR}/private/dfilesystemwatcher_linux_p.h + ${CMAKE_CURRENT_LIST_DIR}/private/dcapfsfileengine_p.h + ${CMAKE_CURRENT_LIST_DIR}/dbasefilewatcher.cpp + ${CMAKE_CURRENT_LIST_DIR}/dfilesystemwatcher_win.cpp + ${CMAKE_CURRENT_LIST_DIR}/dfilewatcher.cpp + ${CMAKE_CURRENT_LIST_DIR}/dfilewatchermanager.cpp + ${CMAKE_CURRENT_LIST_DIR}/dpathbuf.cpp + ${CMAKE_CURRENT_LIST_DIR}/dtrashmanager_dummy.cpp + ${CMAKE_CURRENT_LIST_DIR}/dstandardpaths.cpp + ${CMAKE_CURRENT_LIST_DIR}/dcapfile.cpp + ${CMAKE_CURRENT_LIST_DIR}/dcapmanager.cpp + ${CMAKE_CURRENT_LIST_DIR}/dcapfsfileengine.cpp + ) +else() + set(FILESYSTEM_SOURCE + ${CMAKE_CURRENT_LIST_DIR}/private/dbasefilewatcher_p.h + ${CMAKE_CURRENT_LIST_DIR}/private/dfilesystemwatcher_linux_p.h + ${CMAKE_CURRENT_LIST_DIR}/private/dcapfsfileengine_p.h + ${CMAKE_CURRENT_LIST_DIR}/dbasefilewatcher.cpp + ${CMAKE_CURRENT_LIST_DIR}/dfilesystemwatcher_linux.cpp + ${CMAKE_CURRENT_LIST_DIR}/dfilewatcher.cpp + ${CMAKE_CURRENT_LIST_DIR}/dfilewatchermanager.cpp + ${CMAKE_CURRENT_LIST_DIR}/dpathbuf.cpp + ${CMAKE_CURRENT_LIST_DIR}/dtrashmanager_linux.cpp + ${CMAKE_CURRENT_LIST_DIR}/dstandardpaths.cpp + ${CMAKE_CURRENT_LIST_DIR}/dcapfile.cpp + ${CMAKE_CURRENT_LIST_DIR}/dcapmanager.cpp + ${CMAKE_CURRENT_LIST_DIR}/dcapfsfileengine.cpp + ) +endif() +file(GLOB FILESYSTEM_HEAD + ${CMAKE_CURRENT_LIST_DIR}/../../include/filesystem/* +) +set(filesystem_SRCS + ${FILESYSTEM_HEAD} + ${FILESYSTEM_SOURCE} +) + diff -Nru dtkcore-5.5.33/src/filesystem/filesystem.pri dtkcore-5.6.2/src/filesystem/filesystem.pri --- dtkcore-5.5.33/src/filesystem/filesystem.pri 2022-07-19 09:10:28.000000000 +0000 +++ dtkcore-5.6.2/src/filesystem/filesystem.pri 1970-01-01 00:00:00.000000000 +0000 @@ -1,47 +0,0 @@ -include($$PWD/private/private.pri) - -INCLUDEPATH += $$PWD/../base - -INSTALL_PREFIX=$$QT_INSTALL_PREFIX -isEmpty(INSTALL_PREFIX): INSTALL_PREFIX=$$[QT_INSTALL_PREFIX] -DEFINES += PREFIX=\\\"$$INSTALL_PREFIX\\\" - -HEADERS += \ - $$PWD/dbasefilewatcher.h \ - $$PWD/dfilesystemwatcher.h \ - $$PWD/dfilewatcher.h \ - $$PWD/dfilewatchermanager.h \ - $$PWD/dpathbuf.h \ - $$PWD/dstandardpaths.h \ - $$PWD/dtrashmanager.h - -SOURCES += \ - $$PWD/dbasefilewatcher.cpp \ - $$PWD/dfilewatcher.cpp \ - $$PWD/dfilewatchermanager.cpp \ - $$PWD/dstandardpaths.cpp \ - $$PWD/dpathbuf.cpp - -linux { - SOURCES += \ - $$PWD/dfilesystemwatcher_linux.cpp \ - $$PWD/dtrashmanager_linux.cpp -} else:win* { - SOURCES += \ - $$PWD/dfilesystemwatcher_win.cpp \ - $$PWD/dtrashmanager_dummy.cpp -} else { - SOURCES += \ - $$PWD/dfilesystemwatcher_dummy.cpp \ - $$PWD/dtrashmanager_dummy.cpp -} - -includes.files += $$PWD/*.h -includes.files += \ - $$PWD/DFileWatcher \ - $$PWD/DBaseFileWatcher \ - $$PWD/DFileSystemWatcher \ - $$PWD/DFileWatcherManager \ - $$PWD/DPathBuf \ - $$PWD/DStandardPaths \ - $$PWD/DTrashManager diff -Nru dtkcore-5.5.33/src/filesystem/private/dbasefilewatcher_p.h dtkcore-5.6.2/src/filesystem/private/dbasefilewatcher_p.h --- dtkcore-5.5.33/src/filesystem/private/dbasefilewatcher_p.h 2022-07-19 09:10:28.000000000 +0000 +++ dtkcore-5.6.2/src/filesystem/private/dbasefilewatcher_p.h 2022-09-21 05:21:07.000000000 +0000 @@ -1,19 +1,6 @@ -/* - * Copyright (C) 2017 ~ 2017 Deepin Technology Co., Ltd. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * 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 Lesser General Public License - * along with this program. If not, see . - */ +// SPDX-FileCopyrightText: 2017 - 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later #ifndef DBASEFILEWATCHER_P_H #define DBASEFILEWATCHER_P_H diff -Nru dtkcore-5.5.33/src/filesystem/private/dcapfsfileengine_p.h dtkcore-5.6.2/src/filesystem/private/dcapfsfileengine_p.h --- dtkcore-5.5.33/src/filesystem/private/dcapfsfileengine_p.h 1970-01-01 00:00:00.000000000 +0000 +++ dtkcore-5.6.2/src/filesystem/private/dcapfsfileengine_p.h 2022-09-21 05:21:07.000000000 +0000 @@ -0,0 +1,46 @@ +// SPDX-FileCopyrightText: 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later + +#ifndef DCAPFSFILEENGINE_P_H +#define DCAPFSFILEENGINE_P_H + +#include + +#include + +DCORE_BEGIN_NAMESPACE + +class DCapFSFileEngineHandler : public QAbstractFileEngineHandler +{ +public: + QAbstractFileEngine *create(const QString &fileName) const override; +}; + +class DCapFSFileEnginePrivate; +class DCapFSFileEngine : public QFSFileEngine, public DObject +{ + D_DECLARE_PRIVATE(DCapFSFileEngine); +public: + DCapFSFileEngine(const QString &file); + ~DCapFSFileEngine() override; + + bool open(QIODevice::OpenMode openMode) override; + bool remove() override; + bool copy(const QString &newName) override; + bool rename(const QString &newName) override; + bool renameOverwrite(const QString &newName) override; + bool link(const QString &newName) override; + bool mkdir(const QString &dirName, bool createParentDirectories) const override; + bool rmdir(const QString &dirName, bool recurseParentDirectories) const override; + FileFlags fileFlags(FileFlags type) const override; + bool cloneTo(QAbstractFileEngine *target) override; + bool setSize(qint64 size) override; + QStringList entryList(QDir::Filters filters, const QStringList &filterNames) const override; + Iterator *beginEntryList(QDir::Filters filters, const QStringList &filterNames) override; + + bool canReadWrite(const QString &path) const; +}; + +DCORE_END_NAMESPACE +#endif // DCAPFSFILEENGINE_P_H diff -Nru dtkcore-5.5.33/src/filesystem/private/dfilesystemwatcher_dummy_p.h dtkcore-5.6.2/src/filesystem/private/dfilesystemwatcher_dummy_p.h --- dtkcore-5.5.33/src/filesystem/private/dfilesystemwatcher_dummy_p.h 2022-07-19 09:10:28.000000000 +0000 +++ dtkcore-5.6.2/src/filesystem/private/dfilesystemwatcher_dummy_p.h 2022-09-21 05:21:07.000000000 +0000 @@ -1,19 +1,6 @@ -/* - * Copyright (C) 2017 ~ 2017 Deepin Technology Co., Ltd. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * 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 Lesser General Public License - * along with this program. If not, see . - */ +// SPDX-FileCopyrightText: 2017 - 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later #ifndef DFILESYSTEMWATCHER_WIN_P_H #define DFILESYSTEMWATCHER_WIN_P_H diff -Nru dtkcore-5.5.33/src/filesystem/private/dfilesystemwatcher_linux_p.h dtkcore-5.6.2/src/filesystem/private/dfilesystemwatcher_linux_p.h --- dtkcore-5.5.33/src/filesystem/private/dfilesystemwatcher_linux_p.h 2022-07-19 09:10:28.000000000 +0000 +++ dtkcore-5.6.2/src/filesystem/private/dfilesystemwatcher_linux_p.h 2022-09-21 05:21:07.000000000 +0000 @@ -1,24 +1,11 @@ -/* - * Copyright (C) 2017 ~ 2017 Deepin Technology Co., Ltd. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * 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 Lesser General Public License - * along with this program. If not, see . - */ +// SPDX-FileCopyrightText: 2017 - 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later #ifndef DFILESYSTEMWATCHER_P_H #define DFILESYSTEMWATCHER_P_H -#include "base/private/dobject_p.h" +#include "dobject_p.h" #include #include diff -Nru dtkcore-5.5.33/src/filesystem/private/dfilesystemwatcher_win_p.h dtkcore-5.6.2/src/filesystem/private/dfilesystemwatcher_win_p.h --- dtkcore-5.5.33/src/filesystem/private/dfilesystemwatcher_win_p.h 2022-07-19 09:10:28.000000000 +0000 +++ dtkcore-5.6.2/src/filesystem/private/dfilesystemwatcher_win_p.h 2022-09-21 05:21:07.000000000 +0000 @@ -1,19 +1,6 @@ -/* - * Copyright (C) 2017 ~ 2017 Deepin Technology Co., Ltd. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * 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 Lesser General Public License - * along with this program. If not, see . - */ +// SPDX-FileCopyrightText: 2017 - 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later #ifndef DFILESYSTEMWATCHER_WIN_P_H #define DFILESYSTEMWATCHER_WIN_P_H diff -Nru dtkcore-5.5.33/src/filesystem/private/private.pri dtkcore-5.6.2/src/filesystem/private/private.pri --- dtkcore-5.5.33/src/filesystem/private/private.pri 2022-07-19 09:10:28.000000000 +0000 +++ dtkcore-5.6.2/src/filesystem/private/private.pri 2022-09-21 05:21:07.000000000 +0000 @@ -1,5 +1,6 @@ HEADERS += \ - $$PWD/dbasefilewatcher_p.h + $$PWD/dbasefilewatcher_p.h \ + $$PWD/dcapfsfileengine_p.h linux { HEADERS += \ diff -Nru dtkcore-5.5.33/src/glob.cmake dtkcore-5.6.2/src/glob.cmake --- dtkcore-5.5.33/src/glob.cmake 1970-01-01 00:00:00.000000000 +0000 +++ dtkcore-5.6.2/src/glob.cmake 2022-09-21 05:21:07.000000000 +0000 @@ -0,0 +1,29 @@ +if(LINUX) + file(GLOB OUTER_SOURCE + ${CMAKE_CURRENT_LIST_DIR}/*.cpp + ) + file(GLOB OUTER_HEADER + ${CMAKE_CURRENT_LIST_DIR}/../include/global/*.h + ) +else() + set(OUTER_SOURCE + ${CMAKE_CURRENT_LIST_DIR}/dconfig.cpp + ${CMAKE_CURRENT_LIST_DIR}/dsgapplication.cpp + ${CMAKE_CURRENT_LIST_DIR}/dsysinfo.cpp + ${CMAKE_CURRENT_LIST_DIR}/dsecurestring.cpp + ${CMAKE_CURRENT_LIST_DIR}/ddesktopentry.cpp + ${CMAKE_CURRENT_LIST_DIR}/dtkcore_global.cpp + ) + set(OUTER_HEADER + ${CMAKE_CURRENT_LIST_DIR}/../include/global/dtkcore_global.h + ${CMAKE_CURRENT_LIST_DIR}/../include/dconfig.h + ${CMAKE_CURRENT_LIST_DIR}/../include/dsgapplication.h + ${CMAKE_CURRENT_LIST_DIR}/../include/dsysinfo.h + ${CMAKE_CURRENT_LIST_DIR}/../include/dsecurestring.h + ${CMAKE_CURRENT_LIST_DIR}/../include/ddesktopentry.h + ) +endif() +set(glob_SRC + ${OUTER_HEADER} + ${OUTER_SOURCE} +) diff -Nru dtkcore-5.5.33/src/log/AbstractAppender.h dtkcore-5.6.2/src/log/AbstractAppender.h --- dtkcore-5.5.33/src/log/AbstractAppender.h 2022-07-19 09:10:28.000000000 +0000 +++ dtkcore-5.6.2/src/log/AbstractAppender.h 1970-01-01 00:00:00.000000000 +0000 @@ -1,52 +0,0 @@ -/* - Copyright (c) 2010 Boris Moiseev (cyberbobs at gmail dot com) - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 2.1 - as published by the Free Software Foundation and appearing in the file - LICENSE.LGPL included in the packaging of this file. - - 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 Lesser General Public License for more details. -*/ -#ifndef ABSTRACTAPPENDER_H -#define ABSTRACTAPPENDER_H - -// Local -#include "CuteLogger_global.h" -#include - -// Qt -#include - -DCORE_BEGIN_NAMESPACE - -class CUTELOGGERSHARED_EXPORT AbstractAppender -{ -public: - AbstractAppender(); - virtual ~AbstractAppender(); - - Logger::LogLevel detailsLevel() const; - void setDetailsLevel(Logger::LogLevel level); - void setDetailsLevel(const QString &level); - - void write(const QDateTime &timeStamp, Logger::LogLevel logLevel, const char *file, int line, const char *function, - const QString &category, const QString &message); - -protected: - virtual void append(const QDateTime &timeStamp, Logger::LogLevel logLevel, const char *file, int line, - const char *function, const QString &category, const QString &message) = 0; - -private: - QMutex m_writeMutex; - - Logger::LogLevel m_detailsLevel; - mutable QMutex m_detailsLevelMutex; -}; - -DCORE_END_NAMESPACE - -#endif // ABSTRACTAPPENDER_H diff -Nru dtkcore-5.5.33/src/log/AbstractStringAppender.h dtkcore-5.6.2/src/log/AbstractStringAppender.h --- dtkcore-5.5.33/src/log/AbstractStringAppender.h 2022-07-19 09:10:28.000000000 +0000 +++ dtkcore-5.6.2/src/log/AbstractStringAppender.h 1970-01-01 00:00:00.000000000 +0000 @@ -1,49 +0,0 @@ -/* - Copyright (c) 2010 Boris Moiseev (cyberbobs at gmail dot com) - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 2.1 - as published by the Free Software Foundation and appearing in the file - LICENSE.LGPL included in the packaging of this file. - - 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 Lesser General Public License for more details. -*/ -#ifndef ABSTRACTSTRINGAPPENDER_H -#define ABSTRACTSTRINGAPPENDER_H - -// Local -#include "CuteLogger_global.h" -#include - -// Qt -#include - -DCORE_BEGIN_NAMESPACE - -class CUTELOGGERSHARED_EXPORT AbstractStringAppender : public AbstractAppender -{ - public: - AbstractStringAppender(); - - virtual QString format() const; - void setFormat(const QString&); - - static QString stripFunctionName(const char*); - - protected: - QString formattedString(const QDateTime& timeStamp, Logger::LogLevel logLevel, const char* file, int line, - const char* function, const QString& category, const QString& message) const; - - private: - static QByteArray qCleanupFuncinfo(const char*); - - QString m_format; - mutable QReadWriteLock m_formatLock; -}; - -DCORE_END_NAMESPACE - -#endif // ABSTRACTSTRINGAPPENDER_H diff -Nru dtkcore-5.5.33/src/log/ConsoleAppender.h dtkcore-5.6.2/src/log/ConsoleAppender.h --- dtkcore-5.5.33/src/log/ConsoleAppender.h 2022-07-19 09:10:28.000000000 +0000 +++ dtkcore-5.6.2/src/log/ConsoleAppender.h 1970-01-01 00:00:00.000000000 +0000 @@ -1,39 +0,0 @@ -/* - Copyright (c) 2010 Boris Moiseev (cyberbobs at gmail dot com) - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 2.1 - as published by the Free Software Foundation and appearing in the file - LICENSE.LGPL included in the packaging of this file. - - 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 Lesser General Public License for more details. -*/ -#ifndef CONSOLEAPPENDER_H -#define CONSOLEAPPENDER_H - -#include "CuteLogger_global.h" -#include - -DCORE_BEGIN_NAMESPACE - -class CUTELOGGERSHARED_EXPORT ConsoleAppender : public AbstractStringAppender -{ - public: - ConsoleAppender(); - virtual QString format() const; - void ignoreEnvironmentPattern(bool ignore); - - protected: - virtual void append(const QDateTime& timeStamp, Logger::LogLevel logLevel, const char* file, int line, - const char* function, const QString& category, const QString& message); - - private: - bool m_ignoreEnvPattern; -}; - -DCORE_END_NAMESPACE - -#endif // CONSOLEAPPENDER_H diff -Nru dtkcore-5.5.33/src/log/CuteLogger_global.h dtkcore-5.6.2/src/log/CuteLogger_global.h --- dtkcore-5.5.33/src/log/CuteLogger_global.h 2022-07-19 09:10:28.000000000 +0000 +++ dtkcore-5.6.2/src/log/CuteLogger_global.h 1970-01-01 00:00:00.000000000 +0000 @@ -1,33 +0,0 @@ -/* - * Copyright (C) 2017 ~ 2017 Deepin Technology Co., Ltd. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * 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 Lesser General Public License - * along with this program. If not, see . - */ - -#ifndef CUTELOGGER_GLOBAL_H -#define CUTELOGGER_GLOBAL_H - -#include "dtkcore_global.h" - -#if defined(CUTELOGGER_LIBRARY) -# define CUTELOGGERSHARED_EXPORT Q_DECL_EXPORT -#else -#if defined(Q_OS_WIN32) -# define CUTELOGGERSHARED_EXPORT -#else -# define CUTELOGGERSHARED_EXPORT Q_DECL_IMPORT -#endif -#endif - -#endif // CUTELOGGER_GLOBAL_H diff -Nru dtkcore-5.5.33/src/log/cutelogger.pri dtkcore-5.6.2/src/log/cutelogger.pri --- dtkcore-5.5.33/src/log/cutelogger.pri 2022-07-19 09:10:28.000000000 +0000 +++ dtkcore-5.6.2/src/log/cutelogger.pri 1970-01-01 00:00:00.000000000 +0000 @@ -1,25 +0,0 @@ -INCLUDEPATH += $$PWD - -HEADERS += \ - $$PWD/RollingFileAppender.h \ - $$PWD/Logger.h \ - $$PWD/FileAppender.h \ - $$PWD/CuteLogger_global.h \ - $$PWD/ConsoleAppender.h \ - $$PWD/AbstractStringAppender.h \ - $$PWD/AbstractAppender.h \ - $$PWD/LogManager.h - -SOURCES += \ - $$PWD/RollingFileAppender.cpp \ - $$PWD/Logger.cpp \ - $$PWD/FileAppender.cpp \ - $$PWD/ConsoleAppender.cpp \ - $$PWD/AbstractStringAppender.cpp \ - $$PWD/AbstractAppender.cpp \ - $$PWD/LogManager.cpp - -win32 { - SOURCES += $$PWD/OutputDebugAppender.cpp - HEADERS += $$PWD/OutputDebugAppender.h -} diff -Nru dtkcore-5.5.33/src/log/DLog dtkcore-5.6.2/src/log/DLog --- dtkcore-5.5.33/src/log/DLog 2022-07-19 09:10:28.000000000 +0000 +++ dtkcore-5.6.2/src/log/DLog 1970-01-01 00:00:00.000000000 +0000 @@ -1,8 +0,0 @@ -#include "CuteLogger_global.h" -#include "RollingFileAppender.h" -#include "Logger.h" -#include "LogManager.h" -#include "FileAppender.h" -#include "ConsoleAppender.h" -#include "AbstractStringAppender.h" -#include "AbstractAppender.h" diff -Nru dtkcore-5.5.33/src/log/FileAppender.h dtkcore-5.6.2/src/log/FileAppender.h --- dtkcore-5.5.33/src/log/FileAppender.h 2022-07-19 09:10:28.000000000 +0000 +++ dtkcore-5.6.2/src/log/FileAppender.h 1970-01-01 00:00:00.000000000 +0000 @@ -1,52 +0,0 @@ -/* - Copyright (c) 2010 Boris Moiseev (cyberbobs at gmail dot com) - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 2.1 - as published by the Free Software Foundation and appearing in the file - LICENSE.LGPL included in the packaging of this file. - - 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 Lesser General Public License for more details. -*/ -#ifndef FILEAPPENDER_H -#define FILEAPPENDER_H - -// Logger -#include "CuteLogger_global.h" -#include - -// Qt -#include -#include - -DCORE_BEGIN_NAMESPACE - -class CUTELOGGERSHARED_EXPORT FileAppender : public AbstractStringAppender -{ - public: - FileAppender(const QString& fileName = QString()); - ~FileAppender(); - - QString fileName() const; - void setFileName(const QString&); - - qint64 size() const; - - protected: - virtual void append(const QDateTime& timeStamp, Logger::LogLevel logLevel, const char* file, int line, - const char* function, const QString& category, const QString& message); - bool openFile(); - void closeFile(); - - private: - QFile m_logFile; - QTextStream m_logStream; - mutable QMutex m_logFileMutex; -}; - -DCORE_END_NAMESPACE - -#endif // FILEAPPENDER_H diff -Nru dtkcore-5.5.33/src/log/log.cmake dtkcore-5.6.2/src/log/log.cmake --- dtkcore-5.5.33/src/log/log.cmake 1970-01-01 00:00:00.000000000 +0000 +++ dtkcore-5.6.2/src/log/log.cmake 2022-09-21 05:21:07.000000000 +0000 @@ -0,0 +1,25 @@ +file(GLOB LOG_HEADER + ${CMAKE_CURRENT_LIST_DIR}/../../include/log/*.h +) +set(LOG_SOURCE + ${CMAKE_CURRENT_LIST_DIR}/RollingFileAppender.cpp + ${CMAKE_CURRENT_LIST_DIR}/Logger.cpp + ${CMAKE_CURRENT_LIST_DIR}/FileAppender.cpp + ${CMAKE_CURRENT_LIST_DIR}/ConsoleAppender.cpp + ${CMAKE_CURRENT_LIST_DIR}/AbstractStringAppender.cpp + ${CMAKE_CURRENT_LIST_DIR}/AbstractAppender.cpp + ${CMAKE_CURRENT_LIST_DIR}/LogManager.cpp +) +if(WIN32) + set(log_SRCS + ${LOG_HEADER} + ${LOG_SOURCE} + ${CMAKE_CURRENT_LIST_DIR}/OutputDebugAppender.cpp + ${CMAKE_CURRENT_LIST_DIR}/../../include/log/win32/OutputDebugAppender.h + ) +else() + set(log_SRCS + ${LOG_HEADER} + ${LOG_SOURCE} + ) +endif() diff -Nru dtkcore-5.5.33/src/log/Logger.cpp dtkcore-5.6.2/src/log/Logger.cpp --- dtkcore-5.5.33/src/log/Logger.cpp 2022-07-19 09:10:28.000000000 +0000 +++ dtkcore-5.6.2/src/log/Logger.cpp 2022-09-21 05:21:07.000000000 +0000 @@ -1118,3 +1118,4 @@ } DCORE_END_NAMESPACE +#include "Logger.moc" diff -Nru dtkcore-5.5.33/src/log/Logger.h dtkcore-5.6.2/src/log/Logger.h --- dtkcore-5.5.33/src/log/Logger.h 2022-07-19 09:10:28.000000000 +0000 +++ dtkcore-5.6.2/src/log/Logger.h 1970-01-01 00:00:00.000000000 +0000 @@ -1,207 +0,0 @@ -/* - Copyright (c) 2012 Boris Moiseev (cyberbobs at gmail dot com) - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 2.1 - as published by the Free Software Foundation and appearing in the file - LICENSE.LGPL included in the packaging of this file. - - 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 Lesser General Public License for more details. -*/ -#ifndef LOGGER_H -#define LOGGER_H - -// Qt -#include -#include -#include - -// Local -#include "CuteLogger_global.h" - -DCORE_BEGIN_NAMESPACE - -class AbstractAppender; -class Logger; -CUTELOGGERSHARED_EXPORT Logger *loggerInstance(); -#define logger loggerInstance() - - -#define dTrace CuteMessageLogger(loggerInstance(), Logger::Trace, __FILE__, __LINE__, Q_FUNC_INFO).write -#define dDebug CuteMessageLogger(loggerInstance(), Logger::Debug, __FILE__, __LINE__, Q_FUNC_INFO).write -#define dInfo CuteMessageLogger(loggerInstance(), Logger::Info, __FILE__, __LINE__, Q_FUNC_INFO).write -#define dWarning CuteMessageLogger(loggerInstance(), Logger::Warning, __FILE__, __LINE__, Q_FUNC_INFO).write -#define dError CuteMessageLogger(loggerInstance(), Logger::Error, __FILE__, __LINE__, Q_FUNC_INFO).write -#define dFatal CuteMessageLogger(loggerInstance(), Logger::Fatal, __FILE__, __LINE__, Q_FUNC_INFO).write - -#define dCTrace(category) CuteMessageLogger(loggerInstance(), Logger::Trace, __FILE__, __LINE__, Q_FUNC_INFO, category).write() -#define dCDebug(category) CuteMessageLogger(loggerInstance(), Logger::Debug, __FILE__, __LINE__, Q_FUNC_INFO, category).write() -#define dCInfo(category) CuteMessageLogger(loggerInstance(), Logger::Info, __FILE__, __LINE__, Q_FUNC_INFO, category).write() -#define dCWarning(category) CuteMessageLogger(loggerInstance(), Logger::Warning, __FILE__, __LINE__, Q_FUNC_INFO, category).write() -#define dCError(category) CuteMessageLogger(loggerInstance(), Logger::Error, __FILE__, __LINE__, Q_FUNC_INFO, category).write() -#define dCFatal(category) CuteMessageLogger(loggerInstance(), Logger::Fatal, __FILE__, __LINE__, Q_FUNC_INFO, category).write() - -#define dTraceTime LoggerTimingHelper loggerTimingHelper(loggerInstance(), Logger::Trace, __FILE__, __LINE__, Q_FUNC_INFO); loggerTimingHelper.start -#define dDebugTime LoggerTimingHelper loggerTimingHelper(loggerInstance(), Logger::Debug, __FILE__, __LINE__, Q_FUNC_INFO); loggerTimingHelper.start -#define dInfoTime LoggerTimingHelper loggerTimingHelper(loggerInstance(), Logger::Info, __FILE__, __LINE__, Q_FUNC_INFO); loggerTimingHelper.start - -#define dAssert(cond) ((!(cond)) ? loggerInstance()->writeAssert(__FILE__, __LINE__, Q_FUNC_INFO, #cond) : qt_noop()) -#define dAssertX(cond, msg) ((!(cond)) ? loggerInstance()->writeAssert(__FILE__, __LINE__, Q_FUNC_INFO, msg) : qt_noop()) - -#define dCategory(category) \ - private:\ - Logger* loggerInstance()\ - {\ - static Logger customLoggerInstance(category);\ - return &customLoggerInstance;\ - }\ - -#define dGlobalCategory(category) \ - private:\ - Logger* loggerInstance()\ - {\ - static Logger customLoggerInstance(category);\ - customLoggerInstance.logToGlobalInstance(category, true);\ - return &customLoggerInstance;\ - }\ - - - class LoggerPrivate; - class CUTELOGGERSHARED_EXPORT Logger - { - Q_DISABLE_COPY(Logger) - - public: - Logger(); - Logger(const QString &defaultCategory); - ~Logger(); - - //! Describes the possible severity levels of the log records - enum LogLevel { - Trace, //!< Trace level. Can be used for mostly unneeded records used for internal code tracing. - Debug, //!< Debug level. Useful for non-necessary records used for the debugging of the software. - Info, //!< Info level. Can be used for informational records, which may be interesting for not only developers. - Warning, //!< Warning. May be used to log some non-fatal warnings detected by your application. - Error, //!< Error. May be used for a big problems making your application work wrong but not crashing. - Fatal //!< Fatal. Used for unrecoverable errors, crashes the application right after the log record is written. - }; - - static QString levelToString(LogLevel logLevel); - static LogLevel levelFromString(const QString &s); - - static Logger *globalInstance(); - - void registerAppender(AbstractAppender *appender); - void registerCategoryAppender(const QString &category, AbstractAppender *appender); - - void logToGlobalInstance(const QString &category, bool logToGlobal = false); - - void setDefaultCategory(const QString &category); - QString defaultCategory() const; - - void write(const QDateTime &timeStamp, LogLevel logLevel, const char *file, int line, const char *function, const char *category, - const QString &message); - void write(LogLevel logLevel, const char *file, int line, const char *function, const char *category, const QString &message); - QDebug write(LogLevel logLevel, const char *file, int line, const char *function, const char *category); - - void writeAssert(const char *file, int line, const char *function, const char *condition); - - private: - void write(const QDateTime &timeStamp, LogLevel logLevel, const char *file, int line, const char *function, const char *category, - const QString &message, bool fromLocalInstance); - Q_DECLARE_PRIVATE(Logger) - LoggerPrivate *d_ptr; - }; - - - class CUTELOGGERSHARED_EXPORT CuteMessageLogger - { - Q_DISABLE_COPY(CuteMessageLogger) - - public: - Q_DECL_CONSTEXPR CuteMessageLogger(Logger *l, Logger::LogLevel level, const char *file, int line, const char *function) - : m_l(l), - m_level(level), - m_file(file), - m_line(line), - m_function(function), - m_category(0) - {} - - Q_DECL_CONSTEXPR CuteMessageLogger(Logger *l, Logger::LogLevel level, const char *file, int line, const char *function, const char *category) - : m_l(l), - m_level(level), - m_file(file), - m_line(line), - m_function(function), - m_category(category) - {} - - void write(const char *msg, ...) const -#if defined(Q_CC_GNU) && !defined(__INSURE__) -# if defined(Q_CC_MINGW) && !defined(Q_CC_CLANG) - __attribute__((format(gnu_printf, 2, 3))) -# else - __attribute__((format(printf, 2, 3))) -# endif -#endif - ; - - void write(const QString &msg) const; - - QDebug write() const; - - private: - Logger *m_l; - Logger::LogLevel m_level; - const char *m_file; - int m_line; - const char *m_function; - const char *m_category; - }; - - - class CUTELOGGERSHARED_EXPORT LoggerTimingHelper - { - Q_DISABLE_COPY(LoggerTimingHelper) - - public: - inline explicit LoggerTimingHelper(Logger *l, Logger::LogLevel logLevel, const char *file, int line, - const char *function) - : m_logger(l), - m_logLevel(logLevel), - m_file(file), - m_line(line), - m_function(function) - {} - - void start(const char *msg, ...) -#if defined(Q_CC_GNU) && !defined(__INSURE__) -# if defined(Q_CC_MINGW) && !defined(Q_CC_CLANG) - __attribute__((format(gnu_printf, 2, 3))) -# else - __attribute__((format(printf, 2, 3))) -# endif -#endif - ; - - void start(const QString &msg = QString()); - - ~LoggerTimingHelper(); - - private: - Logger *m_logger; - QTime m_time; - Logger::LogLevel m_logLevel; - const char *m_file; - int m_line; - const char *m_function; - QString m_block; - }; - - DCORE_END_NAMESPACE - -#endif // LOGGER_H diff -Nru dtkcore-5.5.33/src/log/LogManager.h dtkcore-5.6.2/src/log/LogManager.h --- dtkcore-5.5.33/src/log/LogManager.h 2022-07-19 09:10:28.000000000 +0000 +++ dtkcore-5.6.2/src/log/LogManager.h 1970-01-01 00:00:00.000000000 +0000 @@ -1,68 +0,0 @@ -/* - * Copyright (C) 2017 ~ 2017 Deepin Technology Co., Ltd. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * 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 Lesser General Public License - * along with this program. If not, see . - */ - -#ifndef LOGMANAGER_H -#define LOGMANAGER_H - -#include - -#include "CuteLogger_global.h" - -DCORE_BEGIN_NAMESPACE - -class ConsoleAppender; -class RollingFileAppender; - -class LIBDTKCORESHARED_EXPORT DLogManager -{ -public: - static void registerConsoleAppender(); - static void registerFileAppender(); - - static QString getlogFilePath(); - - /*! - * \brief setlogFilePath will change log file path of registerFileAppender - * \a logFilePath is the full path of file appender log - */ - static void setlogFilePath(const QString& logFilePath); - - static void setLogFormat(const QString& format); - -private: - QString m_format; - QString m_logPath; - ConsoleAppender* m_consoleAppender; - RollingFileAppender* m_rollingFileAppender; - - void initConsoleAppender(); - void initRollingFileAppender(); - QString joinPath(const QString& path, const QString& fileName); - - inline static DLogManager* instance(){ - static DLogManager instance; - return &instance; - } - explicit DLogManager(); - ~DLogManager(); - DLogManager(const DLogManager &); - DLogManager & operator = (const DLogManager &); -}; - -DCORE_END_NAMESPACE - -#endif // LOGMANAGER_H diff -Nru dtkcore-5.5.33/src/log/log.pri dtkcore-5.6.2/src/log/log.pri --- dtkcore-5.5.33/src/log/log.pri 2022-07-19 09:10:28.000000000 +0000 +++ dtkcore-5.6.2/src/log/log.pri 1970-01-01 00:00:00.000000000 +0000 @@ -1,5 +0,0 @@ -include(cutelogger.pri) - -includes.files += $$PWD/*.h -includes.files += \ - $$PWD/DLog diff -Nru dtkcore-5.5.33/src/log/OutputDebugAppender.cpp dtkcore-5.6.2/src/log/OutputDebugAppender.cpp --- dtkcore-5.5.33/src/log/OutputDebugAppender.cpp 2022-07-19 09:10:28.000000000 +0000 +++ dtkcore-5.6.2/src/log/OutputDebugAppender.cpp 2022-09-21 05:21:07.000000000 +0000 @@ -12,7 +12,7 @@ GNU Lesser General Public License for more details. */ // Local -#include "OutputDebugAppender.h" +#include "win32/OutputDebugAppender.h" // STL #include diff -Nru dtkcore-5.5.33/src/log/OutputDebugAppender.h dtkcore-5.6.2/src/log/OutputDebugAppender.h --- dtkcore-5.5.33/src/log/OutputDebugAppender.h 2022-07-19 09:10:28.000000000 +0000 +++ dtkcore-5.6.2/src/log/OutputDebugAppender.h 1970-01-01 00:00:00.000000000 +0000 @@ -1,32 +0,0 @@ -/* - Copyright (c) 2010 Karl-Heinz Reichel (khreichel at googlemail dot com) - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 2.1 - as published by the Free Software Foundation and appearing in the file - LICENSE.LGPL included in the packaging of this file. - - 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 Lesser General Public License for more details. -*/ - -#ifndef OUTPUTDEBUGAPPENDER_H -#define OUTPUTDEBUGAPPENDER_H - -#include "CuteLogger_global.h" -#include - -DCORE_BEGIN_NAMESPACE - -class CUTELOGGERSHARED_EXPORT OutputDebugAppender : public AbstractStringAppender -{ - protected: - virtual void append(const QDateTime& timeStamp, Logger::LogLevel logLevel, const char* file, int line, - const char* function, const QString& category, const QString& message); -}; - -DCORE_END_NAMESPACE - -#endif // OUTPUTDEBUGAPPENDER_H diff -Nru dtkcore-5.5.33/src/log/README.md dtkcore-5.6.2/src/log/README.md --- dtkcore-5.5.33/src/log/README.md 2022-07-19 09:10:28.000000000 +0000 +++ dtkcore-5.6.2/src/log/README.md 2022-09-21 05:21:07.000000000 +0000 @@ -19,16 +19,16 @@ Just add pkgconfig in .pro file -```` +``` unix { CONFIG+=link_pkgconfig PKGCONFIG+=dtkcore } -```` +``` ### Example -```` +```cpp #include #include @@ -56,7 +56,7 @@ dWarning() << "Something went wrong." << "Result code is" << result; return result; } -```` +``` \sa Dtk::Core::DLogManager diff -Nru dtkcore-5.5.33/src/log/RollingFileAppender.h dtkcore-5.6.2/src/log/RollingFileAppender.h --- dtkcore-5.5.33/src/log/RollingFileAppender.h 2022-07-19 09:10:28.000000000 +0000 +++ dtkcore-5.6.2/src/log/RollingFileAppender.h 1970-01-01 00:00:00.000000000 +0000 @@ -1,87 +0,0 @@ -/* - * Copyright (C) 2017 ~ 2017 Deepin Technology Co., Ltd. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * 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 Lesser General Public License - * along with this program. If not, see . - */ - -#ifndef ROLLINGFILEAPPENDER_H -#define ROLLINGFILEAPPENDER_H - -#include - -#include - -DCORE_BEGIN_NAMESPACE - -class CUTELOGGERSHARED_EXPORT RollingFileAppender : public FileAppender -{ - public: - /*! - The enum DatePattern defines constants for date patterns. - \sa setDatePattern(DatePattern) - */ - enum DatePattern - { - /*! The minutely date pattern string is "'.'yyyy-MM-dd-hh-mm". */ - MinutelyRollover = 0, - /*! The hourly date pattern string is "'.'yyyy-MM-dd-hh". */ - HourlyRollover, - /*! The half-daily date pattern string is "'.'yyyy-MM-dd-a". */ - HalfDailyRollover, - /*! The daily date pattern string is "'.'yyyy-MM-dd". */ - DailyRollover, - /*! The weekly date pattern string is "'.'yyyy-ww". */ - WeeklyRollover, - /*! The monthly date pattern string is "'.'yyyy-MM". */ - MonthlyRollover - }; - - RollingFileAppender(const QString& fileName = QString()); - - DatePattern datePattern() const; - void setDatePattern(DatePattern datePattern); - void setDatePattern(const QString& datePattern); - - QString datePatternString() const; - - void setLogFilesLimit(int limit); - int logFilesLimit() const; - - void setLogSizeLimit(int qint64); - qint64 logSizeLimit() const; - - protected: - virtual void append(const QDateTime& timeStamp, Logger::LogLevel logLevel, const char* file, int line, - const char* function, const QString& category, const QString& message); - - private: - void rollOver(); - void computeRollOverTime(); - void computeFrequency(); - void removeOldFiles(); - void setDatePatternString(const QString& datePatternString); - - QString m_datePatternString; - DatePattern m_frequency; - - QDateTime m_rollOverTime; - QString m_rollOverSuffix; - int m_logFilesLimit; - qint64 m_logSizeLimit; - mutable QMutex m_rollingMutex; -}; - -DCORE_END_NAMESPACE - -#endif // ROLLINGFILEAPPENDER_H diff -Nru dtkcore-5.5.33/src/settings/backend/dsettingsdconfigbackend.cpp dtkcore-5.6.2/src/settings/backend/dsettingsdconfigbackend.cpp --- dtkcore-5.5.33/src/settings/backend/dsettingsdconfigbackend.cpp 2022-07-19 09:10:28.000000000 +0000 +++ dtkcore-5.6.2/src/settings/backend/dsettingsdconfigbackend.cpp 2022-09-21 05:21:07.000000000 +0000 @@ -1,25 +1,8 @@ -/* - * Copyright (C) 2021 Deepin Technology Co., Ltd. - * - * Author: Wang Fei - * - * Maintainer: Wang Fei - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * 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 Lesser General Public License - * along with this program. If not, see . - */ +// SPDX-FileCopyrightText: 2021 - 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later -#include "dsettingsdconfigbackend.h" +#include "settings/backend/dsettingsdconfigbackend.h" #include #include diff -Nru dtkcore-5.5.33/src/settings/backend/dsettingsdconfigbackend.h dtkcore-5.6.2/src/settings/backend/dsettingsdconfigbackend.h --- dtkcore-5.5.33/src/settings/backend/dsettingsdconfigbackend.h 2022-07-19 09:10:28.000000000 +0000 +++ dtkcore-5.6.2/src/settings/backend/dsettingsdconfigbackend.h 1970-01-01 00:00:00.000000000 +0000 @@ -1,51 +0,0 @@ -/* - * Copyright (C) 2021 Deepin Technology Co., Ltd. - * - * Author: Wang Fei - * - * Maintainer: Wang Fei - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * 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 Lesser General Public License - * along with this program. If not, see . - */ - -#pragma once - -#include -#include - -#include "dsettingsbackend.h" - -DCORE_BEGIN_NAMESPACE - -class DSettingsDConfigBackendPrivate; -class LIBDTKCORESHARED_EXPORT DSettingsDConfigBackend : public Dtk::Core::DSettingsBackend -{ - Q_OBJECT -public: - explicit DSettingsDConfigBackend(const QString &name, const QString &subpath = QString(), QObject *parent = nullptr); - ~DSettingsDConfigBackend() Q_DECL_OVERRIDE; - - virtual QStringList keys() const Q_DECL_OVERRIDE; - virtual QVariant getOption(const QString &key) const Q_DECL_OVERRIDE; - -protected Q_SLOTS: - virtual void doSetOption(const QString &key, const QVariant &value) Q_DECL_OVERRIDE; - virtual void doSync() Q_DECL_OVERRIDE; - -private: - QScopedPointer d_ptr; - Q_DECLARE_PRIVATE_D(qGetPtrHelper(d_ptr), DSettingsDConfigBackend) -}; - -DCORE_END_NAMESPACE diff -Nru dtkcore-5.5.33/src/settings/backend/gsettingsbackend.cpp dtkcore-5.6.2/src/settings/backend/gsettingsbackend.cpp --- dtkcore-5.5.33/src/settings/backend/gsettingsbackend.cpp 2022-07-19 09:10:28.000000000 +0000 +++ dtkcore-5.6.2/src/settings/backend/gsettingsbackend.cpp 2022-09-21 05:21:07.000000000 +0000 @@ -1,4 +1,8 @@ -#include "gsettingsbackend.h" +// SPDX-FileCopyrightText: 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later + +#include "settings/backend/gsettingsbackend.h" //#include #include diff -Nru dtkcore-5.5.33/src/settings/backend/gsettingsbackend.h dtkcore-5.6.2/src/settings/backend/gsettingsbackend.h --- dtkcore-5.5.33/src/settings/backend/gsettingsbackend.h 2022-07-19 09:10:28.000000000 +0000 +++ dtkcore-5.6.2/src/settings/backend/gsettingsbackend.h 1970-01-01 00:00:00.000000000 +0000 @@ -1,30 +0,0 @@ -#pragma once - -#include -#include - -#include "dsettingsbackend.h" - -DCORE_BEGIN_NAMESPACE - -class GSettingsBackendPrivate; -class LIBDTKCORESHARED_EXPORT GSettingsBackend: public DSettingsBackend -{ - Q_OBJECT -public: - explicit GSettingsBackend(DSettings *settings, QObject *parent = nullptr); - ~GSettingsBackend(); - - virtual QStringList keys() const Q_DECL_OVERRIDE; - virtual QVariant getOption(const QString &key) const Q_DECL_OVERRIDE; - -protected Q_SLOTS: - virtual void doSetOption(const QString &key, const QVariant &value) Q_DECL_OVERRIDE; - virtual void doSync() Q_DECL_OVERRIDE; - -private: - QScopedPointer d_ptr; - Q_DECLARE_PRIVATE_D(qGetPtrHelper(d_ptr), GSettingsBackend) -}; - -DCORE_END_NAMESPACE diff -Nru dtkcore-5.5.33/src/settings/backend/qsettingbackend.cpp dtkcore-5.6.2/src/settings/backend/qsettingbackend.cpp --- dtkcore-5.5.33/src/settings/backend/qsettingbackend.cpp 2022-07-19 09:10:28.000000000 +0000 +++ dtkcore-5.6.2/src/settings/backend/qsettingbackend.cpp 2022-09-21 05:21:07.000000000 +0000 @@ -1,21 +1,8 @@ -/* - * Copyright (C) 2016 ~ 2017 Deepin Technology Co., Ltd. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * 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 Lesser General Public License - * along with this program. If not, see . - */ +// SPDX-FileCopyrightText: 2016 - 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later -#include "qsettingbackend.h" +#include "settings/backend/qsettingbackend.h" #include #include diff -Nru dtkcore-5.5.33/src/settings/backend/qsettingbackend.h dtkcore-5.6.2/src/settings/backend/qsettingbackend.h --- dtkcore-5.5.33/src/settings/backend/qsettingbackend.h 2022-07-19 09:10:28.000000000 +0000 +++ dtkcore-5.6.2/src/settings/backend/qsettingbackend.h 1970-01-01 00:00:00.000000000 +0000 @@ -1,47 +0,0 @@ -/* - * Copyright (C) 2016 ~ 2017 Deepin Technology Co., Ltd. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * 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 Lesser General Public License - * along with this program. If not, see . - */ - -#pragma once - -#include -#include - -#include "dsettingsbackend.h" - -DCORE_BEGIN_NAMESPACE - -class QSettingBackendPrivate; -class LIBDTKCORESHARED_EXPORT QSettingBackend : public Dtk::Core::DSettingsBackend -{ - Q_OBJECT -public: - explicit QSettingBackend(const QString &filepath, QObject *parent = 0); - ~QSettingBackend(); - - virtual QStringList keys() const Q_DECL_OVERRIDE; - virtual QVariant getOption(const QString &key) const Q_DECL_OVERRIDE; - -protected Q_SLOTS: - virtual void doSetOption(const QString &key, const QVariant &value) Q_DECL_OVERRIDE; - virtual void doSync() Q_DECL_OVERRIDE; - -private: - QScopedPointer d_ptr; - Q_DECLARE_PRIVATE_D(qGetPtrHelper(d_ptr), QSettingBackend) -}; - -DCORE_END_NAMESPACE diff -Nru dtkcore-5.5.33/src/settings/DSettings dtkcore-5.6.2/src/settings/DSettings --- dtkcore-5.5.33/src/settings/DSettings 2022-07-19 09:10:28.000000000 +0000 +++ dtkcore-5.6.2/src/settings/DSettings 1970-01-01 00:00:00.000000000 +0000 @@ -1 +0,0 @@ -#include "dsettings.h" diff -Nru dtkcore-5.5.33/src/settings/dsettingsbackend.h dtkcore-5.6.2/src/settings/dsettingsbackend.h --- dtkcore-5.5.33/src/settings/dsettingsbackend.h 2022-07-19 09:10:28.000000000 +0000 +++ dtkcore-5.6.2/src/settings/dsettingsbackend.h 1970-01-01 00:00:00.000000000 +0000 @@ -1,56 +0,0 @@ -/* - * Copyright (C) 2016 ~ 2017 Deepin Technology Co., Ltd. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * 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 Lesser General Public License - * along with this program. If not, see . - */ - -#pragma once - -#include -#include - -#include "dtkcore_global.h" - -DCORE_BEGIN_NAMESPACE - -class DSettings; -class LIBDTKCORESHARED_EXPORT DSettingsBackend : public QObject -{ - Q_OBJECT -public: - explicit DSettingsBackend(QObject *parent = Q_NULLPTR): QObject(parent) - { - connect(this, &DSettingsBackend::sync, this, &DSettingsBackend::doSync, Qt::QueuedConnection); - connect(this, &DSettingsBackend::setOption, this, &DSettingsBackend::doSetOption, Qt::QueuedConnection); - } - virtual ~DSettingsBackend() {} - - virtual QStringList keys() const = 0; - virtual QVariant getOption(const QString &key) const = 0; - - virtual void doSync() = 0; - -protected: - virtual void doSetOption(const QString &key, const QVariant &value) = 0; - -Q_SIGNALS: - void optionChanged(const QString &key, const QVariant &value); - - // private signals; -Q_SIGNALS: - void sync(); - void setOption(const QString &key, const QVariant &value); -}; - -DCORE_END_NAMESPACE diff -Nru dtkcore-5.5.33/src/settings/dsettings.cpp dtkcore-5.6.2/src/settings/dsettings.cpp --- dtkcore-5.5.33/src/settings/dsettings.cpp 2022-07-19 09:10:28.000000000 +0000 +++ dtkcore-5.6.2/src/settings/dsettings.cpp 2022-09-21 05:21:07.000000000 +0000 @@ -1,19 +1,6 @@ -/* - * Copyright (C) 2016 ~ 2017 Deepin Technology Co., Ltd. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * 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 Lesser General Public License - * along with this program. If not, see . - */ +// SPDX-FileCopyrightText: 2016 - 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later #include "dsettings.h" diff -Nru dtkcore-5.5.33/src/settings/DSettingsGroup dtkcore-5.6.2/src/settings/DSettingsGroup --- dtkcore-5.5.33/src/settings/DSettingsGroup 2022-07-19 09:10:28.000000000 +0000 +++ dtkcore-5.6.2/src/settings/DSettingsGroup 1970-01-01 00:00:00.000000000 +0000 @@ -1 +0,0 @@ -#include "dsettingsgroup.h" diff -Nru dtkcore-5.5.33/src/settings/dsettingsgroup.cpp dtkcore-5.6.2/src/settings/dsettingsgroup.cpp --- dtkcore-5.5.33/src/settings/dsettingsgroup.cpp 2022-07-19 09:10:28.000000000 +0000 +++ dtkcore-5.6.2/src/settings/dsettingsgroup.cpp 2022-09-21 05:21:07.000000000 +0000 @@ -1,19 +1,6 @@ -/* - * Copyright (C) 2016 ~ 2017 Deepin Technology Co., Ltd. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * 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 Lesser General Public License - * along with this program. If not, see . - */ +// SPDX-FileCopyrightText: 2016 - 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later #include "dsettingsgroup.h" diff -Nru dtkcore-5.5.33/src/settings/dsettingsgroup.h dtkcore-5.6.2/src/settings/dsettingsgroup.h --- dtkcore-5.5.33/src/settings/dsettingsgroup.h 2022-07-19 09:10:28.000000000 +0000 +++ dtkcore-5.6.2/src/settings/dsettingsgroup.h 1970-01-01 00:00:00.000000000 +0000 @@ -1,62 +0,0 @@ -/* - * Copyright (C) 2016 ~ 2017 Deepin Technology Co., Ltd. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * 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 Lesser General Public License - * along with this program. If not, see . - */ - -#pragma once - -#include -#include - -#include "dsettingsoption.h" - -#include "dtkcore_global.h" - -DCORE_BEGIN_NAMESPACE - -class DSettingsGroupPrivate; -class LIBDTKCORESHARED_EXPORT DSettingsGroup : public QObject -{ - Q_OBJECT -public: - explicit DSettingsGroup(QObject *parent = Q_NULLPTR); - ~DSettingsGroup(); - - QPointer parentGroup() const; - void setParentGroup(QPointer parentGroup); - - QString key() const; - QString name() const; - bool isHidden() const; - - QPointer childGroup(const QString &groupKey) const; - QPointer option(const QString &key) const; - - QList > childGroups() const; - QList > childOptions() const; - QList > options() const; - - static QPointer fromJson(const QString &prefixKey, const QJsonObject &group); - -private: - void parseJson(const QString &prefixKey, const QJsonObject &group); - - QScopedPointer dd_ptr; - Q_DECLARE_PRIVATE_D(qGetPtrHelper(dd_ptr), DSettingsGroup) -}; - -typedef QPointer GroupPtr; - -DCORE_END_NAMESPACE diff -Nru dtkcore-5.5.33/src/settings/dsettings.h dtkcore-5.6.2/src/settings/dsettings.h --- dtkcore-5.5.33/src/settings/dsettings.h 2022-07-19 09:10:28.000000000 +0000 +++ dtkcore-5.6.2/src/settings/dsettings.h 1970-01-01 00:00:00.000000000 +0000 @@ -1,76 +0,0 @@ -/* - * Copyright (C) 2016 ~ 2017 Deepin Technology Co., Ltd. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * 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 Lesser General Public License - * along with this program. If not, see . - */ - -#pragma once - -#include -#include -#include - -#include "dtkcore_global.h" - -DCORE_BEGIN_NAMESPACE - -class DSettingsBackend; -class DSettingsOption; -class DSettingsGroup; -class DSettingsPrivate; -class LIBDTKCORESHARED_EXPORT DSettings : public QObject -{ - Q_OBJECT -public: - explicit DSettings(QObject *parent = Q_NULLPTR); - ~DSettings(); - - void setBackend(DSettingsBackend *backend = nullptr); - - static QPointer fromJson(const QByteArray &json); - static QPointer fromJsonFile(const QString &filepath); - QJsonObject meta() const; - - QStringList keys() const; - QList> options() const; - QPointer option(const QString &key) const; - QVariant value(const QString &key) const; - - QStringList groupKeys() const; - QList> groups() const; - QPointer group(const QString &key) const; - - QVariant getOption(const QString &key) const; - -Q_SIGNALS: - void valueChanged(const QString &key, const QVariant &value); - -public Q_SLOTS: - //! - //! \brief sync - //! WARNING: sync will block - void sync() ; - - void setOption(const QString &key, const QVariant &value); - void reset() ; - -private: - void parseJson(const QByteArray &json); - void loadValue(); - - QScopedPointer dd_ptr; - Q_DECLARE_PRIVATE_D(qGetPtrHelper(dd_ptr), DSettings) -}; - -DCORE_END_NAMESPACE diff -Nru dtkcore-5.5.33/src/settings/DSettingsOption dtkcore-5.6.2/src/settings/DSettingsOption --- dtkcore-5.5.33/src/settings/DSettingsOption 2022-07-19 09:10:28.000000000 +0000 +++ dtkcore-5.6.2/src/settings/DSettingsOption 1970-01-01 00:00:00.000000000 +0000 @@ -1 +0,0 @@ -#include "dsettingsoption.h" diff -Nru dtkcore-5.5.33/src/settings/dsettingsoption.cpp dtkcore-5.6.2/src/settings/dsettingsoption.cpp --- dtkcore-5.5.33/src/settings/dsettingsoption.cpp 2022-07-19 09:10:28.000000000 +0000 +++ dtkcore-5.6.2/src/settings/dsettingsoption.cpp 2022-09-21 05:21:07.000000000 +0000 @@ -1,19 +1,6 @@ -/* - * Copyright (C) 2016 ~ 2017 Deepin Technology Co., Ltd. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * 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 Lesser General Public License - * along with this program. If not, see . - */ +// SPDX-FileCopyrightText: 2016 - 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later #include "dsettingsoption.h" diff -Nru dtkcore-5.5.33/src/settings/dsettingsoption.h dtkcore-5.6.2/src/settings/dsettingsoption.h --- dtkcore-5.5.33/src/settings/dsettingsoption.h 2022-07-19 09:10:28.000000000 +0000 +++ dtkcore-5.6.2/src/settings/dsettingsoption.h 1970-01-01 00:00:00.000000000 +0000 @@ -1,70 +0,0 @@ -/* - * Copyright (C) 2016 ~ 2017 Deepin Technology Co., Ltd. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * 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 Lesser General Public License - * along with this program. If not, see . - */ - -#pragma once - -#include -#include -#include - -#include "dtkcore_global.h" - -DCORE_BEGIN_NAMESPACE - -class DSettingsGroup; -class DSettingsOptionPrivate; -class LIBDTKCORESHARED_EXPORT DSettingsOption : public QObject -{ - Q_OBJECT - Q_PROPERTY(QVariant value READ value WRITE setValue NOTIFY valueChanged) - -public: - explicit DSettingsOption(QObject *parent = Q_NULLPTR); - ~DSettingsOption(); - - QPointer parentGroup() const; - void setParentGroup(QPointer parentGroup); - - QString key() const; - QString name() const; - bool canReset() const; - QVariant defaultValue() const; - QVariant value() const; - QVariant data(const QString &dataType) const; - - QString viewType() const; - bool isHidden() const; - - static QPointer fromJson(const QString &prefixKey, const QJsonObject &json); -Q_SIGNALS: - void valueChanged(QVariant value); - void dataChanged(const QString &dataType, QVariant value); - -public Q_SLOTS: - void setValue(QVariant value); - void setData(const QString &dataType, QVariant value); - -private: - void parseJson(const QString &prefixKey, const QJsonObject &option); - - QScopedPointer dd_ptr; - Q_DECLARE_PRIVATE_D(qGetPtrHelper(dd_ptr), DSettingsOption) -}; - -typedef QPointer OptionPtr; - -DCORE_END_NAMESPACE diff -Nru dtkcore-5.5.33/src/settings/settings.cmake dtkcore-5.6.2/src/settings/settings.cmake --- dtkcore-5.5.33/src/settings/settings.cmake 1970-01-01 00:00:00.000000000 +0000 +++ dtkcore-5.6.2/src/settings/settings.cmake 2022-09-21 05:21:07.000000000 +0000 @@ -0,0 +1,25 @@ +if(LINUX) + file(GLOB SETTINGS_SOURCE + ${CMAKE_CURRENT_LIST_DIR}/*.cpp + ${CMAKE_CURRENT_LIST_DIR}/backend/*.cpp + ) + file(GLOB SETTINGS_HEADER + ${CMAKE_CURRENT_LIST_DIR}/../../include/settings/*.h + ${CMAKE_CURRENT_LIST_DIR}/../../include/settings/backend/*.h + ) +else() + file(GLOB SETTINGS_SOURCE + ${CMAKE_CURRENT_LIST_DIR}/*.cpp + ${CMAKE_CURRENT_LIST_DIR}/backend/dsettingsdconfigbackend.cpp + ${CMAKE_CURRENT_LIST_DIR}/backend/qsettingbackend.cpp + ) + file(GLOB SETTINGS_HEADER + ${CMAKE_CURRENT_LIST_DIR}/../../include/settings/*.h + ${CMAKE_CURRENT_LIST_DIR}/../../include/settings/backend/dsettingsdconfigbackend.h + ${CMAKE_CURRENT_LIST_DIR}/../../include/settings/backend/qsettingbackend.h + ) +endif() +set(settings_SRC + ${SETTINGS_HEADER} + ${SETTINGS_SOURCE} +) diff -Nru dtkcore-5.5.33/src/settings/settings.pri dtkcore-5.6.2/src/settings/settings.pri --- dtkcore-5.5.33/src/settings/settings.pri 2022-07-19 09:10:28.000000000 +0000 +++ dtkcore-5.6.2/src/settings/settings.pri 1970-01-01 00:00:00.000000000 +0000 @@ -1,33 +0,0 @@ -linux { - PKGCONFIG += gsettings-qt - -SOURCES += \ - $$PWD/backend/gsettingsbackend.cpp - -HEADERS +=\ - $$PWD/backend/gsettingsbackend.h -} - -INCLUDEPATH += $$PWD - -SOURCES += \ - $$PWD/backend/qsettingbackend.cpp \ - $$PWD/dsettings.cpp \ - $$PWD/dsettingsoption.cpp \ - $$PWD/dsettingsgroup.cpp \ - $$PWD/backend/dsettingsdconfigbackend.cpp - -HEADERS +=\ - $$PWD/backend/qsettingbackend.h \ - $$PWD/dsettings.h \ - $$PWD/dsettingsoption.h \ - $$PWD/dsettingsgroup.h \ - $$PWD/dsettingsbackend.h \ - $$PWD/backend/dsettingsdconfigbackend.h - -includes.files += $${PWD}/*.h -includes.files += $${PWD}/backend/*.h -includes.files += \ - $${PWD}/DSettings \ - $${PWD}/DSettingsGroup \ - $${PWD}/DSettingsOption diff -Nru dtkcore-5.5.33/src/src.pro dtkcore-5.6.2/src/src.pro --- dtkcore-5.5.33/src/src.pro 2022-07-19 09:10:28.000000000 +0000 +++ dtkcore-5.6.2/src/src.pro 1970-01-01 00:00:00.000000000 +0000 @@ -1,97 +0,0 @@ -QT -= gui -QT += dbus -QT += xml -CONFIG += link_pkgconfig -TARGET = dtkcore - -# 龙芯架构上没有默认添加PT_GNU_STACK-section,所以此处手动指定一下 -contains(QMAKE_HOST.arch, mips.*): QMAKE_LFLAGS_SHLIB += "-Wl,-z,noexecstack" - -QMAKE_CXXFLAGS_RELEASE += -fvisibility=hidden - -INCLUDEPATH += $$PWD -HEADERS += $$PWD/dtkcore_global.h \ - dconfig.h \ - dsysinfo.h \ - dsecurestring.h \ - ddesktopentry.h - -SOURCES += \ - dconfig.cpp \ - dsysinfo.cpp \ - dsecurestring.cpp \ - ddesktopentry.cpp \ - dtkcore_global.cpp - -linux: { - HEADERS += \ - $$PWD/dconfigfile.h - - SOURCES += \ - $$PWD/dconfigfile.cpp - - # generic dbus interfaces - isEmpty(DTK_DISABLE_DBUS_CONFIG) { - QT += dbus - - config.files = $$PWD/dbus/org.desktopspec.ConfigManager.xml - config.header_flags += -c DSGConfig -N - config.source_flags += -c DSGConfig -N - - manager.files = $$PWD/dbus/org.desktopspec.ConfigManager.Manager.xml - manager.header_flags += -c DSGConfigManager -N - manager.source_flags += -c DSGConfigManager -N - - DBUS_INTERFACES += config manager - } else { - DEFINES += D_DISABLE_DBUS_CONFIG - } -} else { - DEFINES += D_DISABLE_DCONFIG -} - -include($$PWD/base/base.pri) -include($$PWD/util/util.pri) -include($$PWD/log/log.pri) -include($$PWD/filesystem/filesystem.pri) -include($$PWD/settings/settings.pri) - -includes.files += \ - $$PWD/*.h \ - $$PWD/dtkcore_config.h \ - $$PWD/DtkCores \ - $$PWD/DSysInfo \ - $$PWD/DSecureString \ - $$PWD/DDesktopEntry \ - $$PWD/DConfigFile \ - $$PWD/DConfig - -# ---------------------------------------------- -# install config - -DTK_MODULE_NAME = $$TARGET -load(dtk_build) - -INSTALLS += includes target - -isEmpty(DTK_STATIC_LIB){ - DEFINES += LIBDTKCORE_LIBRARY -} else { - DEFINES += DTK_STATIC_LIB -} - -#cmake -load(dtk_cmake) - -#qt module -load(dtk_module) - -!isEmpty(DTK_MULTI_VERSION) { -# 支持上游一包多依赖 -load(dtk_multiversion) -# 5.5 5.6可通过重复调用此函数,来增加对更多版本的支持 -dtkBuildMultiVersion(5.5) - -# INSTALL变量增加多版本下的配置文件 -load(dtk_install_multiversion) -} diff -Nru dtkcore-5.5.33/src/util/DAbstractUnitFormatter dtkcore-5.6.2/src/util/DAbstractUnitFormatter --- dtkcore-5.5.33/src/util/DAbstractUnitFormatter 2022-07-19 09:10:28.000000000 +0000 +++ dtkcore-5.6.2/src/util/DAbstractUnitFormatter 1970-01-01 00:00:00.000000000 +0000 @@ -1 +0,0 @@ -#include "dabstractunitformatter.h" diff -Nru dtkcore-5.5.33/src/util/dabstractunitformatter.cpp dtkcore-5.6.2/src/util/dabstractunitformatter.cpp --- dtkcore-5.5.33/src/util/dabstractunitformatter.cpp 2022-07-19 09:10:28.000000000 +0000 +++ dtkcore-5.6.2/src/util/dabstractunitformatter.cpp 2022-09-21 05:21:07.000000000 +0000 @@ -1,19 +1,6 @@ -/* - * Copyright (C) 2017 ~ 2017 Deepin Technology Co., Ltd. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * 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 Lesser General Public License - * along with this program. If not, see . - */ +// SPDX-FileCopyrightText: 2017 - 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later #include "dabstractunitformatter.h" diff -Nru dtkcore-5.5.33/src/util/dabstractunitformatter.h dtkcore-5.6.2/src/util/dabstractunitformatter.h --- dtkcore-5.5.33/src/util/dabstractunitformatter.h 2022-07-19 09:10:28.000000000 +0000 +++ dtkcore-5.6.2/src/util/dabstractunitformatter.h 1970-01-01 00:00:00.000000000 +0000 @@ -1,50 +0,0 @@ -/* - * Copyright (C) 2017 ~ 2017 Deepin Technology Co., Ltd. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * 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 Lesser General Public License - * along with this program. If not, see . - */ - -#ifndef DABSTRACTUNITFORMATTER_H -#define DABSTRACTUNITFORMATTER_H - -#include "dtkcore_global.h" - -#include -#include - -DCORE_BEGIN_NAMESPACE - -class LIBDTKCORESHARED_EXPORT DAbstractUnitFormatter -{ -public: - DAbstractUnitFormatter(); - ~DAbstractUnitFormatter(); - -protected: - virtual int unitMax() const = 0; - virtual int unitMin() const = 0; - virtual uint unitConvertRate(int unitId) const = 0; - virtual qreal unitValueMax(int unitId) const { return unitConvertRate(unitId) - 1; } - virtual qreal unitValueMin(int unitId) const { Q_UNUSED(unitId); return 1; } - virtual QString unitStr(int unitId) const = 0; - -public: - qreal formatAs(qreal value, int currentUnit, const int targetUnit) const; - QPair format(const qreal value, const int unit) const; - QList> formatAsUnitList(const qreal value, int unit) const; -}; - -DCORE_END_NAMESPACE - -#endif // DABSTRACTUNITFORMATTER_H diff -Nru dtkcore-5.5.33/src/util/dasync.h dtkcore-5.6.2/src/util/dasync.h --- dtkcore-5.5.33/src/util/dasync.h 2022-07-19 09:10:28.000000000 +0000 +++ dtkcore-5.6.2/src/util/dasync.h 1970-01-01 00:00:00.000000000 +0000 @@ -1,505 +0,0 @@ -/* - * Copyright (C) 2021 ~ 2021 UnionTech Technology Co., Ltd. - * - * Author: Wang Peng <993381@qq.com> - * - * Maintainer: Wang Peng - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * 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 Lesser General Public License - * along with this program. If not, see . - */ -#ifndef DASYNC_H -#define DASYNC_H -#include - -#include -#include -#include -#include -#include - -#include -#include - -DCORE_BEGIN_NAMESPACE - -#define GUARDED_BY(...) -#define D_THREAD_IN_MAIN() (qApp->instance() && qApp->instance()->thread() == QThread::currentThread()) - -// TODO: 添加 DtkCorePrivate 到 dtkcore_global.h -namespace DtkCorePrivate -{ - // 本类是继承实现的,只有子类方法是安全的,暂不对外提供接口 - template - class DSafeQueue : public QQueue { - public: - inline void enqueue(const T &t) { - QMutexLocker lkc(&m_mtx); - QQueue::enqueue(t); - } - inline T dequeue() { - QMutexLocker lkc(&m_mtx); - return QQueue::dequeue(); - } - inline int size() { - QMutexLocker lkc(&m_mtx); - return QQueue::size(); - } - inline T &head() { - QMutexLocker lkc(&m_mtx); - return QQueue::head(); - } - inline const T &head() const { - QMutexLocker lkc(&m_mtx); - return QQueue::head(); - } - private: - QMutex m_mtx; - }; - - // 内部使用,不对外提供接口 - class MainWorker : public QObject { - Q_OBJECT - std::function m_handle; - std::function m_handleProxy; - - std::function m_handleV; - std::function m_handleVProxy; - - bool m_dasyncDestroyed = false; - char __padding[7]; - public: - void setDAsyncDestroyed() { - m_dasyncDestroyed = true; - } - bool dasyncDestroyed() { - return m_dasyncDestroyed; - } - public: - MainWorker(QObject *parent = nullptr) - : QObject (parent) - { - // Ensure that QApplication is initialized - Q_ASSERT(qApp->instance() && qApp->instance()->thread()); - moveToThread(qApp->instance()->thread()); - - bool isStartInMain = D_THREAD_IN_MAIN(); - - QObject::connect(this, &MainWorker::sigRunInMain, - this, &MainWorker::slotRunInMain, - isStartInMain ? Qt::AutoConnection : Qt::BlockingQueuedConnection); - - QObject::connect(this, &MainWorker::sigRunInMainVoid, - this, &MainWorker::slotRunInMainVoid, - isStartInMain ? Qt::AutoConnection : Qt::BlockingQueuedConnection); - } - - // 1. handle arg is non void - template - typename std::enable_if::value>::type - setHandle(FUNC &&func) { - m_handle = [&] (void *arg) { - DSafeQueue *q = static_cast*>(arg); - while (q && q->size()) { - // 这里是 then 回调真正执行到的地方 - func(q->dequeue()); - } - }; - - m_handleProxy = [this] (void *arg) { - if (m_handle) { - m_handle(arg); - } - }; - } - - // 2. handle arg is void - template - typename std::enable_if::value>::type - setHandle(FUNC &&func) { - m_handleV = [&] (void) { - // 这里是 then 回调真正执行到的地方 - func(); - }; - - m_handleVProxy = [this] (void) { - if (m_handleV) { - m_handleV(); - } - }; - } - Q_SIGNALS: - void sigRunInMain(void *arg); - void sigRunInMainVoid(); - public Q_SLOTS: - void slotRunInMain(void *arg) { - Q_ASSERT(D_THREAD_IN_MAIN()); - if (m_handleProxy && !m_dasyncDestroyed) { - m_handleProxy(arg); - } - } - void slotRunInMainVoid(void) { - Q_ASSERT(D_THREAD_IN_MAIN()); - if (m_handleVProxy && !m_dasyncDestroyed) { - m_handleVProxy(); - } - } - }; -} - -class DAsyncState : public QObject { - Q_OBJECT -public: - explicit DAsyncState(QObject *parent = nullptr) noexcept - : QObject (parent) - { - } - enum AsyncTaskState { - NotReady = 0x00, // initial state - Ready = 0x02, // deffered = false - Running = 0x04, // thread started - Pending = Ready | Running, // condition wait - Cancel = 0x08, // set thread canceled - WaitFinished = 0x10, // wiaitForFinished - Finished = 0x20, // thread exit - Forever = 0x30, // TODO: DAsync::post execute forever - }; - Q_DECLARE_FLAGS(AsyncTaskStatus, AsyncTaskState) -}; - -// Template classes not supported by Q_OBJECT, so class MainWorker is independent -template -class DAsync : public QObject { - - class Helper; - - std::mutex m_mtxIn; - std::condition_variable m_cvIn; - - std::mutex m_mtxForWaitTask; - std::condition_variable m_cvForWaitTask; - - class Guard { - DAsync *m_as; - // 如果 DAsync 已经析构了,工作线程还没结束 - // DAsync 中的有些数据就不能在 guard 的析构里面访问了 - bool m_dasDestructed = false; - public: - bool destructed() { - return m_dasDestructed; - } - void setDestructed() { - m_dasDestructed = true; - } - public: - explicit Guard(DAsync *as) noexcept : m_as (as) - { - m_as->m_status.setFlag(DAsyncState::Ready); - m_as->m_status.setFlag(DAsyncState::Finished, false); // 防止重入 - } - ~Guard() { - if (destructed()) { - return; - } - m_as->m_threadGuard = nullptr; - m_as->m_status.setFlag(DAsyncState::Finished); - m_as->m_status.setFlag(DAsyncState::Ready, false); // 防止重入 - if (m_as->m_status.testFlag(DAsyncState::WaitFinished)) { - m_as->m_cvForWaitTask.notify_one(); - } - setPending(false); - } - void setPending(bool isPending) { - if (!destructed()) { - m_as->m_status.setFlag(DAsyncState::Pending, isPending); - } - } - }; - Guard *m_threadGuard = nullptr; - - /* - * m_QueueIn 的作用是存储 PostData 传进来的数据 - * m_QueueOut 的作用是将 post 处理完的结果暂存起来然后传入到 then 中 - * 在 emitHelper 中调用 post 进来的任务,然后将结果传到主线程中处理 - * 数据传递使用 void * 做转换,对于复合类型避免了使用 qRegisterMetaType - */ - template - struct DataQueueType { DtkCorePrivate::DSafeQueue m_queue; }; - template - struct DataQueueType::value>::type> { }; - using DataInQueue = DataQueueType; - using DataOutQueue = DataQueueType; - // Queue 中处理完的结果经由 m_QueueIn 变量暂存,然后经由 signal、slot 传给 then 中的回调函数做参数 - DataInQueue m_QueueIn; - DataOutQueue m_QueueOut; - - // 存储不同类型的输入函数 - template - struct FuncType { - }; - template - struct FuncType::value>::type, - typename std::enable_if::value>::type> { - std::function cbp; - }; - template - struct FuncType::value>::type, - typename std::enable_if::value>::type> { - std::function cbp; - }; - template - struct FuncType::value>::type, - typename std::enable_if::value>::type> { - std::function cbp; - }; - template - struct FuncType::value>::type, - typename std::enable_if::value>::type> { - std::function cbp; - }; - - std::mutex m_mtxFunc; - FuncType m_func GUARDED_BY(m_mtxFunc); - DAsyncState::AsyncTaskStatus m_status; - -public: - explicit DAsync(QObject *parent = nullptr) noexcept - : QObject (parent) - , m_func ({nullptr}) - , m_status (DAsyncState::NotReady) - { - m_mainWorker = new DtkCorePrivate::MainWorker(); - m_helper = new Helper(this, this); - } - ~DAsync() { - if (m_threadGuard) { - m_threadGuard->setDestructed(); - } - m_status.setFlag(DAsyncState::Cancel); - if (m_status.testFlag(DAsyncState::Pending)) { - m_cvIn.notify_one(); - } - if (m_mainWorker) { - m_mainWorker->setDAsyncDestroyed(); - m_mainWorker->deleteLater(); - m_mainWorker = nullptr; - } - } - -private: - // 1. input void & emit void - template - typename std::enable_if::value && std::is_void::value>::type - emitHelper() { - m_func.cbp(); - Q_EMIT m_mainWorker->sigRunInMainVoid(); - } - // 2. input non void & emit non void - template - typename std::enable_if::value && !std::is_void::value>::type - emitHelper() { - m_QueueOut.m_queue.enqueue(m_func.cbp(m_QueueIn.m_queue.dequeue())); - Q_EMIT m_mainWorker->sigRunInMain(static_cast(&(m_QueueOut.m_queue))); - } - // 3. input non void & emit void - template - typename std::enable_if::value && std::is_void::value>::type - emitHelper() { - m_func.cbp(m_QueueIn.m_queue.dequeue()); - Q_EMIT m_mainWorker->sigRunInMainVoid(); - } - // 4. input void & emit non void - template - typename std::enable_if::value && !std::is_void::value>::type - emitHelper() { - m_QueueOut.m_queue.enqueue(m_func.cbp()); - Q_EMIT m_mainWorker->sigRunInMain(static_cast(&(m_QueueOut.m_queue))); - } - -public: - void startUp() { - if (m_status.testFlag(DAsyncState::Cancel)) { - return; - } - m_helper->start(); - } - void cancelAll() { - m_status.setFlag(DAsyncState::Cancel); - if (m_status.testFlag(DAsyncState::Pending)) { - m_cvIn.notify_one(); - } - } - bool isFinished() { - return m_status.testFlag(DAsyncState::Finished); - } - /* - * 不能在 QTimer 中使用 waitForFinished,防止阻塞主线程 - * 也不能在主线程执行前使用 waitForFinished() - * 它的默认参数为 true,等同于 waitForFinished(false) + - * cancelAll, 如果调用了后者, 会一直阻塞等待任务,直到 - * cancelAll 被调用之后 waitForFinished 才会在任务完成完 - * 成后退出,此时就可以删除DAsync了。最好的管理方式还是采用 - * QObject 的内存托管。主线程中使用,可以采用托管的方式, - * 任务结束只要调用 cancelAll + isFinished 轮询判断就行了, - * DAsync 的工作线程就会在完成后自动退出。 - */ - void waitForFinished(bool cancelAllWorks = true) { - Q_ASSERT(!D_THREAD_IN_MAIN()); - if (cancelAllWorks) { - cancelAll(); - } - if (!m_status.testFlag(DAsyncState::Finished)) { - if (m_status.testFlag(DAsyncState::Pending)) { - m_cvIn.notify_one(); - } - m_status.setFlag(DAsyncState::WaitFinished); - std::unique_lock lck(m_mtxForWaitTask); - m_cvForWaitTask.wait(lck); - } - } - // 输入数据不是 void 类型则依赖于 m_QueueIn - template - typename std::enable_if::value, Helper *>::type - post(FUNC &&func) { - m_func.cbp = std::forward(func); - if (m_postProxy) { - return m_helper; - } - m_postProxy = [this] () { - std::thread thread([this] { - if (m_status.testFlag(DAsyncState::Cancel)) { - return; - } - Guard guard(this); - m_threadGuard = &guard; - - std::unique_lock lck(m_mtxIn); - while (true) { - while (!m_status.testFlag(DAsyncState::Ready) || !m_QueueIn.m_queue.size()) { - guard.setPending(true); - // 定时查询 flag,防止睡死的情况发生 - m_cvIn.wait_for(lck, std::chrono::milliseconds(200)); - if (guard.destructed() || m_status.testFlag(DAsyncState::Cancel)) { - return; - } - } - guard.setPending(false); - - while (m_func.cbp && m_QueueIn.m_queue.size()) { - emitHelper(); - } - } - }); - thread.detach(); - }; - - return m_helper; - } - - template - typename std::enable_if::value, Helper *>::type - post(FUNC &&func) { - { - std::lock_guard lckFunc(m_mtxFunc); - m_func.cbp = std::forward(func); - } - if (m_postProxy) { - return m_helper; - } - m_postProxy = [this] () { - std::thread thread([this] { - if (m_status.testFlag(DAsyncState::Cancel)) { - return; - } - Guard guard(this); - m_threadGuard = &guard; - - std::unique_lock lck(m_mtxIn); - while (true) { - if (!m_status.testFlag(DAsyncState::Ready)) { - guard.setPending(true); - // 定时查询 flag,防止睡死的情况发生 - m_cvIn.wait_for(lck, std::chrono::milliseconds(200)); - if (guard.destructed() || m_status.testFlag(DAsyncState::Cancel)){ - return; - } - } - guard.setPending(false); - - if (m_func.cbp) { - std::lock_guard lckFunc(m_mtxFunc); - emitHelper(); - m_func.cbp = nullptr; // reset - } - } - }); - thread.detach(); - }; - - return m_helper; - } - - // only support DAsync - template - typename std::enable_if::value>::type - postData(const InputType &data) { - if (Q_UNLIKELY(!m_status.testFlag(DAsyncState::Cancel))) { - m_QueueIn.m_queue.enqueue(data); - if (m_status.testFlag(DAsyncState::Pending)) { - m_cvIn.notify_one(); - } - } - } - -private: - std::function m_postProxy; - class Helper : public QObject { - DAsync *m_async; - public: - explicit Helper(DAsync *async, QObject *parent = nullptr) noexcept - : QObject (parent) - , m_async (async) - { - } - - template - Helper *then(FUNC &&func) { - m_async->m_mainWorker->template setHandle(std::forward(func)); - return this; - } - // 仅启动,非阻塞 - void start(bool immediately = true) { - if (m_async->m_postProxy) { - m_async->m_postProxy(); - } - if (!immediately) { - m_async->m_status.setFlag(DAsyncState::Ready, false); - } else { - m_async->m_status.setFlag(DAsyncState::Ready); - if (m_async->m_status.testFlag(DAsyncState::Pending)) { - m_async->m_cvIn.notify_one(); - } - } - } - }; - - Helper *m_helper = nullptr; - DtkCorePrivate::MainWorker *m_mainWorker = nullptr; -}; - -DCORE_END_NAMESPACE -#endif //DASYNC_H diff -Nru dtkcore-5.5.33/src/util/ddbusinterface.cpp dtkcore-5.6.2/src/util/ddbusinterface.cpp --- dtkcore-5.5.33/src/util/ddbusinterface.cpp 1970-01-01 00:00:00.000000000 +0000 +++ dtkcore-5.6.2/src/util/ddbusinterface.cpp 2022-09-21 05:21:07.000000000 +0000 @@ -0,0 +1,196 @@ +// SPDX-FileCopyrightText: 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later + +#include "ddbusinterface.h" +#include "ddbusinterface_p.h" + +#include +#include +#include +#include +#include +#include +#include + +DCORE_BEGIN_NAMESPACE + +static const QString &FreedesktopService = QStringLiteral("org.freedesktop.DBus"); +static const QString &FreedesktopPath = QStringLiteral("/org/freedesktop/DBus"); +static const QString &FreedesktopInterface = QStringLiteral("org.freedesktop.DBus"); +static const QString &NameOwnerChanged = QStringLiteral("NameOwnerChanged"); + +static const QString &PropertiesInterface = QStringLiteral("org.freedesktop.DBus.Properties"); +static const QString &PropertiesChanged = QStringLiteral("PropertiesChanged"); +static const char *PropertyName = "propname"; + +DDBusInterfacePrivate::DDBusInterfacePrivate(DDBusInterface *interface, QObject *parent) + : QObject(interface) + , m_parent(parent) + , m_serviceValid(false) + , q_ptr(interface) +{ + QDBusMessage message = QDBusMessage::createMethodCall(FreedesktopService, FreedesktopPath, FreedesktopInterface, "NameHasOwner"); + message << interface->service(); + interface->connection().callWithCallback(message, this, SLOT(onDBusNameHasOwner(bool))); + + QStringList argumentMatch; + argumentMatch << interface->interface(); + interface->connection().connect(interface->service(), interface->path(), PropertiesInterface, PropertiesChanged, argumentMatch, QString(), this, SLOT(onPropertiesChanged(QString, QVariantMap, QStringList))); +} + +void DDBusInterfacePrivate::updateProp(const char *propname, const QVariant &value) +{ + if (!m_parent) + return; + + m_propertyMap.insert(propname, value); + const QMetaObject *metaObj = m_parent->metaObject(); + const char *signalName = propname + QStringLiteral("Changed").toLatin1(); + int i = metaObj->indexOfSignal(signalName); + if (i != -1) { + QMetaObject::invokeMethod(m_parent, signalName, Qt::DirectConnection, QGenericArgument(value.typeName(), value.data())); + } else + qWarning() << "invalid property changed:" << propname << value; +} + +void DDBusInterfacePrivate::initDBusConnection() +{ + if (!m_parent) + return; + + Q_Q(DDBusInterface); + QDBusConnection connection = q->connection(); + QStringList signalList; + QDBusInterface inter(q->service(), q->path(), q->interface(), connection); + const QMetaObject *meta = inter.metaObject(); + for (int i = meta->methodOffset(); i < meta->methodCount(); ++i) { + const QMetaMethod &method = meta->method(i); + if (method.methodType() == QMetaMethod::Signal) { + signalList << method.methodSignature(); + } + } + const QMetaObject *parentMeta = m_parent->metaObject(); + for (const QString &signal : signalList) { + int i = parentMeta->indexOfSignal(QMetaObject::normalizedSignature(signal.toLatin1())); + if (i != -1) { + const QMetaMethod &parentMethod = parentMeta->method(i); + connection.connect(q->service(), q->path(), q->interface(), parentMethod.name(), m_parent, QT_STRINGIFY(QSIGNAL_CODE) + parentMethod.methodSignature()); + } + } +} + +void DDBusInterfacePrivate::onPropertiesChanged(const QString &interfaceName, const QVariantMap &changedProperties, const QStringList &invalidatedProperties) +{ + Q_UNUSED(interfaceName) + Q_UNUSED(invalidatedProperties) + for (QVariantMap::const_iterator it = changedProperties.cbegin(); it != changedProperties.cend(); ++it) + updateProp((it.key() + m_suffix).toLatin1(), it.value()); +} + +void DDBusInterfacePrivate::onAsyncPropertyFinished(QDBusPendingCallWatcher *w) +{ + QDBusPendingReply reply = *w; + if (!reply.isError()) { + updateProp(w->property(PropertyName).toString().toLatin1(), reply.value()); + } + w->deleteLater(); +} + +void DDBusInterfacePrivate::setServiceValid(bool valid) +{ + if (m_serviceValid != valid) { + Q_Q(DDBusInterface); + m_serviceValid = valid; + Q_EMIT q->serviceValidChanged(m_serviceValid); + } +} + +void DDBusInterfacePrivate::onDBusNameHasOwner(bool valid) +{ + Q_Q(DDBusInterface); + setServiceValid(valid); + if (valid) + initDBusConnection(); + else + q->connection().connect(FreedesktopService, FreedesktopPath, FreedesktopInterface, NameOwnerChanged, this, SLOT(onDBusNameOwnerChanged(QString, QString, QString))); +} + +void DDBusInterfacePrivate::onDBusNameOwnerChanged(const QString &name, const QString &oldOwner, const QString &newOWner) +{ + Q_Q(DDBusInterface); + if (name == q->service() && oldOwner.isEmpty()) { + initDBusConnection(); + q->connection().disconnect(FreedesktopService, FreedesktopPath, FreedesktopInterface, NameOwnerChanged, this, SLOT(onDBusNameOwnerChanged(QString, QString, QString))); + setServiceValid(true); + } else if (name == q->service() && newOWner.isEmpty()) + setServiceValid(false); +} + +////////////////////////////////////////////////////////// +// class DDBusInterface +////////////////////////////////////////////////////////// + +DDBusInterface::DDBusInterface(const QString &service, const QString &path, const QString &interface, const QDBusConnection &connection, QObject *parent) + : QDBusAbstractInterface(service, path, interface.toLatin1(), connection, parent) + , d_ptr(new DDBusInterfacePrivate(this, parent)) +{ +} + +DDBusInterface::~DDBusInterface() +{ +} + +bool DDBusInterface::serviceValid() const +{ + Q_D(const DDBusInterface); + return d->m_serviceValid; +} + +QString DDBusInterface::suffix() const +{ + Q_D(const DDBusInterface); + return d->m_suffix; +} + +void DDBusInterface::setSuffix(const QString &suffix) +{ + Q_D(DDBusInterface); + d->m_suffix = suffix; +} + +inline QString originalPropname(const char *propname, QString suffix) +{ + QString propStr(propname); + return propStr.left(propStr.length() - suffix.length()); +} + +QVariant DDBusInterface::property(const char *propname) +{ + Q_D(DDBusInterface); + if (d->m_propertyMap.contains(propname)) + return d->m_propertyMap.value(propname); + + QDBusMessage msg = QDBusMessage::createMethodCall(service(), path(), PropertiesInterface, QStringLiteral("Get")); + msg << interface() << originalPropname(propname, d->m_suffix); + QDBusPendingReply prop = connection().asyncCall(msg); + if (prop.value().isValid()) + return prop.value(); + + QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(prop, this); + watcher->setProperty(PropertyName, propname); + connect(watcher, &QDBusPendingCallWatcher::finished, d, &DDBusInterfacePrivate::onAsyncPropertyFinished); + if (d->m_propertyMap.contains(propname)) + return d->m_propertyMap.value(propname); + + return QVariant(); +} + +void DDBusInterface::setProperty(const char *propname, const QVariant &value) +{ + Q_D(const DDBusInterface); + QDBusMessage msg = QDBusMessage::createMethodCall(service(), path(), PropertiesInterface, QStringLiteral("Set")); + msg << interface() << originalPropname(propname, d->m_suffix) << value; + connection().asyncCall(msg); +} +DCORE_END_NAMESPACE diff -Nru dtkcore-5.5.33/src/util/ddbusinterface_p.h dtkcore-5.6.2/src/util/ddbusinterface_p.h --- dtkcore-5.5.33/src/util/ddbusinterface_p.h 1970-01-01 00:00:00.000000000 +0000 +++ dtkcore-5.6.2/src/util/ddbusinterface_p.h 2022-09-21 05:21:07.000000000 +0000 @@ -0,0 +1,36 @@ +// SPDX-FileCopyrightText: 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later + +#pragma once +#include "ddbusinterface.h" + +class QDBusPendingCallWatcher; + +DCORE_BEGIN_NAMESPACE +class DDBusInterfacePrivate : public QObject +{ + Q_OBJECT + +public: + explicit DDBusInterfacePrivate(DDBusInterface *interface, QObject *parent); + void updateProp(const char *propname, const QVariant &value); + void initDBusConnection(); + void setServiceValid(bool valid); + +private Q_SLOTS: + void onPropertiesChanged(const QString &interfaceName, const QVariantMap &changedProperties, const QStringList &invalidatedProperties); + void onAsyncPropertyFinished(QDBusPendingCallWatcher *w); + void onDBusNameHasOwner(bool valid); + void onDBusNameOwnerChanged(const QString &name, const QString &oldOwner, const QString &newOWner); + +public: + QObject *m_parent; + QString m_suffix; + QVariantMap m_propertyMap; + bool m_serviceValid; + + DDBusInterface *q_ptr; + Q_DECLARE_PUBLIC(DDBusInterface) +}; +DCORE_END_NAMESPACE diff -Nru dtkcore-5.5.33/src/util/DDBusSender dtkcore-5.6.2/src/util/DDBusSender --- dtkcore-5.5.33/src/util/DDBusSender 2022-07-19 09:10:28.000000000 +0000 +++ dtkcore-5.6.2/src/util/DDBusSender 1970-01-01 00:00:00.000000000 +0000 @@ -1 +0,0 @@ -#include "ddbussender.h" diff -Nru dtkcore-5.5.33/src/util/ddbussender.cpp dtkcore-5.6.2/src/util/ddbussender.cpp --- dtkcore-5.5.33/src/util/ddbussender.cpp 2022-07-19 09:10:28.000000000 +0000 +++ dtkcore-5.6.2/src/util/ddbussender.cpp 2022-09-21 05:21:07.000000000 +0000 @@ -1,3 +1,7 @@ +// SPDX-FileCopyrightText: 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later + #include "ddbussender.h" #include diff -Nru dtkcore-5.5.33/src/util/ddbussender.h dtkcore-5.6.2/src/util/ddbussender.h --- dtkcore-5.5.33/src/util/ddbussender.h 2022-07-19 09:10:28.000000000 +0000 +++ dtkcore-5.6.2/src/util/ddbussender.h 1970-01-01 00:00:00.000000000 +0000 @@ -1,97 +0,0 @@ -#ifndef DDBUSSENDER_H -#define DDBUSSENDER_H - -#include "dtkcore_global.h" - -#include -#include -#include -#include - -#include - -class LIBDTKCORESHARED_EXPORT DDBusData -{ -public: - DDBusData(); - - QString service; - QString path; - QString interface; - QString queryName; - QDBusConnection connection; -}; - -class LIBDTKCORESHARED_EXPORT DDBusCaller -{ - friend class DDBusSender; - -public: - QDBusPendingCall call(); - - template - DDBusCaller arg(const T &argument); - -private: - explicit DDBusCaller(const QString &method, std::shared_ptr data); - -private: - std::shared_ptr m_dbusData; - QString m_methodName; - QVariantList m_arguments; -}; - -template -DDBusCaller DDBusCaller::arg(const T &argument) -{ - m_arguments << QVariant::fromValue(argument); - - return *this; -} - -class LIBDTKCORESHARED_EXPORT DDBusProperty -{ - friend class DDBusSender; - -public: - QDBusPendingCall get(); - template - QDBusPendingCall set(const T &value); - -private: - explicit DDBusProperty(const QString &property, std::shared_ptr data); - -private: - std::shared_ptr m_dbusData; - QString m_propertyName; -}; - -template -QDBusPendingCall DDBusProperty::set(const T &value) -{ - QDBusInterface iface(m_dbusData->service, m_dbusData->path, QStringLiteral("org.freedesktop.DBus.Properties"), m_dbusData->connection); - - const QVariantList args = { QVariant::fromValue(m_dbusData->interface), QVariant::fromValue(m_propertyName), QVariant::fromValue(QDBusVariant(value)) }; - - return iface.asyncCallWithArgumentList(QStringLiteral("Set"), args); -} - -class LIBDTKCORESHARED_EXPORT DDBusSender -{ -public: - explicit DDBusSender(); - - DDBusSender service(const QString &service); - DDBusSender interface(const QString &interface); - DDBusSender path(const QString &path); - DDBusCaller method(const QString &method); - DDBusProperty property(const QString &property); - -private: - DDBusSender type(const QDBusConnection::BusType busType); - -private: - std::shared_ptr m_dbusData; -}; - -#endif // DDBUSSENDER_H diff -Nru dtkcore-5.5.33/src/util/DDiskSizeFormatter dtkcore-5.6.2/src/util/DDiskSizeFormatter --- dtkcore-5.5.33/src/util/DDiskSizeFormatter 2022-07-19 09:10:28.000000000 +0000 +++ dtkcore-5.6.2/src/util/DDiskSizeFormatter 1970-01-01 00:00:00.000000000 +0000 @@ -1 +0,0 @@ -#include "ddisksizeformatter.h" diff -Nru dtkcore-5.5.33/src/util/ddisksizeformatter.cpp dtkcore-5.6.2/src/util/ddisksizeformatter.cpp --- dtkcore-5.5.33/src/util/ddisksizeformatter.cpp 2022-07-19 09:10:28.000000000 +0000 +++ dtkcore-5.6.2/src/util/ddisksizeformatter.cpp 2022-09-21 05:21:07.000000000 +0000 @@ -1,19 +1,6 @@ -/* - * Copyright (C) 2017 ~ 2017 Deepin Technology Co., Ltd. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * 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 Lesser General Public License - * along with this program. If not, see . - */ +// SPDX-FileCopyrightText: 2017 - 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later #include "ddisksizeformatter.h" diff -Nru dtkcore-5.5.33/src/util/ddisksizeformatter.h dtkcore-5.6.2/src/util/ddisksizeformatter.h --- dtkcore-5.5.33/src/util/ddisksizeformatter.h 2022-07-19 09:10:28.000000000 +0000 +++ dtkcore-5.6.2/src/util/ddisksizeformatter.h 1970-01-01 00:00:00.000000000 +0000 @@ -1,54 +0,0 @@ -/* - * Copyright (C) 2017 ~ 2017 Deepin Technology Co., Ltd. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * 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 Lesser General Public License - * along with this program. If not, see . - */ - -#ifndef DISKSIZEFORMATTER_H -#define DISKSIZEFORMATTER_H - -#include "dabstractunitformatter.h" - -DCORE_BEGIN_NAMESPACE - -class LIBDTKCORESHARED_EXPORT DDiskSizeFormatter : public DAbstractUnitFormatter -{ -public: - DDiskSizeFormatter(); - - enum DiskUnits - { - B, - K, - M, - G, - T, - }; - - QString unitStr(int unitId) const override; - - DDiskSizeFormatter rate(int rate); - -protected: - int unitMin() const override { return B; } - int unitMax() const override { return T; } - uint unitConvertRate(int unitId) const override { Q_UNUSED(unitId); return m_rate; } - -private: - int m_rate = 1000; -}; - -DCORE_END_NAMESPACE - -#endif // DISKSIZEFORMATTER_H diff -Nru dtkcore-5.5.33/src/util/DExportedInterface dtkcore-5.6.2/src/util/DExportedInterface --- dtkcore-5.5.33/src/util/DExportedInterface 2022-07-19 09:10:28.000000000 +0000 +++ dtkcore-5.6.2/src/util/DExportedInterface 1970-01-01 00:00:00.000000000 +0000 @@ -1 +0,0 @@ -#include "dexportedinterface.h" diff -Nru dtkcore-5.5.33/src/util/dexportedinterface.cpp dtkcore-5.6.2/src/util/dexportedinterface.cpp --- dtkcore-5.5.33/src/util/dexportedinterface.cpp 2022-07-19 09:10:28.000000000 +0000 +++ dtkcore-5.6.2/src/util/dexportedinterface.cpp 2022-09-21 05:21:07.000000000 +0000 @@ -1,26 +1,9 @@ -/* - * Copyright (C) 2017 ~ 2019 Deepin Technology Co., Ltd. - * - * Author: Chris Xiong - * - * Maintainer: Chris Xiong - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * 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 Lesser General Public License - * along with this program. If not, see . - */ +// SPDX-FileCopyrightText: 2017 - 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later #include "dexportedinterface.h" -#include "private/dobject_p.h" +#include "base/private/dobject_p.h" #include #include diff -Nru dtkcore-5.5.33/src/util/dexportedinterface.h dtkcore-5.6.2/src/util/dexportedinterface.h --- dtkcore-5.5.33/src/util/dexportedinterface.h 2022-07-19 09:10:28.000000000 +0000 +++ dtkcore-5.6.2/src/util/dexportedinterface.h 1970-01-01 00:00:00.000000000 +0000 @@ -1,52 +0,0 @@ -/* - * Copyright (C) 2017 ~ 2019 Deepin Technology Co., Ltd. - * - * Author: Chris Xiong - * - * Maintainer: Chris Xiong - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * 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 Lesser General Public License - * along with this program. If not, see . - */ - -#ifndef DEXPORTEDINTERFACE_H -#define DEXPORTEDINTERFACE_H - -#include -#include - -#include - -#include - -DCORE_BEGIN_NAMESPACE - -namespace DUtil { -class DExportedInterfacePrivate; -class LIBDTKCORESHARED_EXPORT DExportedInterface : public QObject, public DObject -{ - Q_OBJECT -public: - explicit DExportedInterface(QObject *parent = nullptr); - ~DExportedInterface(); - - void registerAction(const QString &action, const QString &description, const std::function handler = nullptr); - virtual QVariant invoke(const QString &action, const QString ¶meters) const; -private: - D_DECLARE_PRIVATE(DExportedInterface) -}; -} - -DCORE_END_NAMESPACE - -#endif diff -Nru dtkcore-5.5.33/src/util/DFileServices dtkcore-5.6.2/src/util/DFileServices --- dtkcore-5.5.33/src/util/DFileServices 2022-07-19 09:10:28.000000000 +0000 +++ dtkcore-5.6.2/src/util/DFileServices 1970-01-01 00:00:00.000000000 +0000 @@ -1 +0,0 @@ -#include "dfileservices.h" diff -Nru dtkcore-5.5.33/src/util/dfileservices_dummy.cpp dtkcore-5.6.2/src/util/dfileservices_dummy.cpp --- dtkcore-5.5.33/src/util/dfileservices_dummy.cpp 2022-07-19 09:10:28.000000000 +0000 +++ dtkcore-5.6.2/src/util/dfileservices_dummy.cpp 2022-09-21 05:21:07.000000000 +0000 @@ -1,19 +1,6 @@ -/* - * Copyright (C) 2017 ~ 2017 Deepin Technology Co., Ltd. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * 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 Lesser General Public License - * along with this program. If not, see . - */ +// SPDX-FileCopyrightText: 2017 - 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later #include "dfileservices.h" diff -Nru dtkcore-5.5.33/src/util/dfileservices.h dtkcore-5.6.2/src/util/dfileservices.h --- dtkcore-5.5.33/src/util/dfileservices.h 2022-07-19 09:10:28.000000000 +0000 +++ dtkcore-5.6.2/src/util/dfileservices.h 1970-01-01 00:00:00.000000000 +0000 @@ -1,55 +0,0 @@ -/* - * Copyright (C) 2017 ~ 2017 Deepin Technology Co., Ltd. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * 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 Lesser General Public License - * along with this program. If not, see . - */ - -#ifndef DFILESERVICES_H -#define DFILESERVICES_H - -#include - -#include - -DCORE_BEGIN_NAMESPACE - -class LIBDTKCORESHARED_EXPORT DFileServices -{ -public: - static bool showFolder(QString localFilePath, const QString &startupId = QString()); - static bool showFolders(const QList localFilePaths, const QString &startupId = QString()); - static bool showFolder(QUrl url, const QString &startupId = QString()); - static bool showFolders(const QList urls, const QString &startupId = QString()); - - static bool showFileItemPropertie(QString localFilePath, const QString &startupId = QString()); - static bool showFileItemProperties(const QList localFilePaths, const QString &startupId = QString()); - static bool showFileItemPropertie(QUrl url, const QString &startupId = QString()); - static bool showFileItemProperties(const QList urls, const QString &startupId = QString()); - - static bool showFileItem(QString localFilePath, const QString &startupId = QString()); - static bool showFileItems(const QList localFilePaths, const QString &startupId = QString()); - static bool showFileItem(QUrl url, const QString &startupId = QString()); - static bool showFileItems(const QList urls, const QString &startupId = QString()); - - static bool trash(QString localFilePath); - static bool trash(const QList localFilePaths); - static bool trash(QUrl urlstartupId); - static bool trash(const QList urls); - - static QString errorMessage(); -}; - -DCORE_END_NAMESPACE - -#endif // DFILESERVICES_H diff -Nru dtkcore-5.5.33/src/util/dfileservices_linux.cpp dtkcore-5.6.2/src/util/dfileservices_linux.cpp --- dtkcore-5.5.33/src/util/dfileservices_linux.cpp 2022-07-19 09:10:28.000000000 +0000 +++ dtkcore-5.6.2/src/util/dfileservices_linux.cpp 2022-09-21 05:21:07.000000000 +0000 @@ -1,19 +1,6 @@ -/* - * Copyright (C) 2017 ~ 2017 Deepin Technology Co., Ltd. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * 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 Lesser General Public License - * along with this program. If not, see . - */ +// SPDX-FileCopyrightText: 2017 - 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later #include #include diff -Nru dtkcore-5.5.33/src/util/DNotifySender dtkcore-5.6.2/src/util/DNotifySender --- dtkcore-5.5.33/src/util/DNotifySender 2022-07-19 09:10:28.000000000 +0000 +++ dtkcore-5.6.2/src/util/DNotifySender 1970-01-01 00:00:00.000000000 +0000 @@ -1 +0,0 @@ -#include "dnotifysender.h" diff -Nru dtkcore-5.5.33/src/util/dnotifysender.cpp dtkcore-5.6.2/src/util/dnotifysender.cpp --- dtkcore-5.5.33/src/util/dnotifysender.cpp 2022-07-19 09:10:28.000000000 +0000 +++ dtkcore-5.6.2/src/util/dnotifysender.cpp 2022-09-21 05:21:07.000000000 +0000 @@ -1,23 +1,6 @@ -/* - * Copyright (C) 2017 ~ 2019 Deepin Technology Co., Ltd. - * - * Author: justforlxz - * - * Maintainer: justforlxz - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * 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 Lesser General Public License - * along with this program. If not, see . - */ +// SPDX-FileCopyrightText: 2017 - 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later #include "dnotifysender.h" #include "ddbussender.h" diff -Nru dtkcore-5.5.33/src/util/dnotifysender.h dtkcore-5.6.2/src/util/dnotifysender.h --- dtkcore-5.5.33/src/util/dnotifysender.h 2022-07-19 09:10:28.000000000 +0000 +++ dtkcore-5.6.2/src/util/dnotifysender.h 1970-01-01 00:00:00.000000000 +0000 @@ -1,32 +0,0 @@ -#ifndef DNOTIFYSENDER_H -#define DNOTIFYSENDER_H - -#include "dtkcore_global.h" - -#include -#include - -DCORE_BEGIN_NAMESPACE - -namespace DUtil { -struct DNotifyData; -class LIBDTKCORESHARED_EXPORT DNotifySender { -public: - DNotifySender(const QString &summary); - DNotifySender appName(const QString &appName = QString()); - DNotifySender appIcon(const QString &appIcon = QString()); - DNotifySender appBody(const QString &appBody = QString()); - DNotifySender replaceId(const uint replaceId = 0); - DNotifySender timeOut(const int timeOut = -1); - DNotifySender actions(const QStringList &actions = QStringList()); - DNotifySender hints(const QVariantMap &hints = QVariantMap()); - QDBusPendingCall call(); - -private: - std::shared_ptr m_dbusData; -}; -} // namespace DUtil - -DCORE_END_NAMESPACE - -#endif // DNOTIFYSENDER_H diff -Nru dtkcore-5.5.33/src/util/DPinyin dtkcore-5.6.2/src/util/DPinyin --- dtkcore-5.5.33/src/util/DPinyin 2022-07-19 09:10:28.000000000 +0000 +++ dtkcore-5.6.2/src/util/DPinyin 1970-01-01 00:00:00.000000000 +0000 @@ -1 +0,0 @@ -#include "dpinyin.h" diff -Nru dtkcore-5.5.33/src/util/dpinyin.cpp dtkcore-5.6.2/src/util/dpinyin.cpp --- dtkcore-5.5.33/src/util/dpinyin.cpp 2022-07-19 09:10:28.000000000 +0000 +++ dtkcore-5.6.2/src/util/dpinyin.cpp 2022-09-21 05:21:07.000000000 +0000 @@ -1,23 +1,7 @@ -/* - * Copyright (C) 2019 ~ 2019 Deepin Technology Co., Ltd. - * - * Author: zccrs - * - * Maintainer: zccrs - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * 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 Lesser General Public License - * along with this program. If not, see . - */ +// SPDX-FileCopyrightText: 2019 - 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later + #include "dpinyin.h" #include diff -Nru dtkcore-5.5.33/src/util/dpinyin.h dtkcore-5.6.2/src/util/dpinyin.h --- dtkcore-5.5.33/src/util/dpinyin.h 2022-07-19 09:10:28.000000000 +0000 +++ dtkcore-5.6.2/src/util/dpinyin.h 1970-01-01 00:00:00.000000000 +0000 @@ -1,34 +0,0 @@ -/* - * Copyright (C) 2017 ~ 2017 Deepin Technology Co., Ltd. - * - * Author: kirigaya - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * 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 Lesser General Public License - * along with this program. If not, see . - * - * pinyin.dict from https://github.com/flyerhzm/chinese_pinyin - */ - -#ifndef DPINYIN_H -#define DPINYIN_H - -#include - -#include - -DCORE_BEGIN_NAMESPACE - -QString LIBDTKCORESHARED_EXPORT Chinese2Pinyin(const QString& words); - -DCORE_END_NAMESPACE - -#endif // DPINYIN_H diff -Nru dtkcore-5.5.33/src/util/DRecentManager dtkcore-5.6.2/src/util/DRecentManager --- dtkcore-5.5.33/src/util/DRecentManager 2022-07-19 09:10:28.000000000 +0000 +++ dtkcore-5.6.2/src/util/DRecentManager 1970-01-01 00:00:00.000000000 +0000 @@ -1 +0,0 @@ -#include "drecentmanager.h" diff -Nru dtkcore-5.5.33/src/util/drecentmanager.cpp dtkcore-5.6.2/src/util/drecentmanager.cpp --- dtkcore-5.5.33/src/util/drecentmanager.cpp 2022-07-19 09:10:28.000000000 +0000 +++ dtkcore-5.6.2/src/util/drecentmanager.cpp 2022-09-21 05:21:07.000000000 +0000 @@ -1,23 +1,6 @@ -/* - * Copyright (C) 2017 ~ 2018 Deepin Technology Co., Ltd. - * - * Author: rekols - * - * Maintainer: rekols - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * 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 Lesser General Public License - * along with this program. If not, see . - */ +// SPDX-FileCopyrightText: 2017 - 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later #include "drecentmanager.h" #include diff -Nru dtkcore-5.5.33/src/util/drecentmanager.h dtkcore-5.6.2/src/util/drecentmanager.h --- dtkcore-5.5.33/src/util/drecentmanager.h 2022-07-19 09:10:28.000000000 +0000 +++ dtkcore-5.6.2/src/util/drecentmanager.h 1970-01-01 00:00:00.000000000 +0000 @@ -1,47 +0,0 @@ -/* - * Copyright (C) 2017 ~ 2018 Deepin Technology Co., Ltd. - * - * Author: rekols - * - * Maintainer: rekols - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * 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 Lesser General Public License - * along with this program. If not, see . - */ - -#ifndef DRECENTMANAGER_H -#define DRECENTMANAGER_H - -#include "dtkcore_global.h" -#include - -DCORE_BEGIN_NAMESPACE - -struct LIBDTKCORESHARED_EXPORT DRecentData -{ - QString appName; - QString appExec; - QString mimeType; -}; - -class LIBDTKCORESHARED_EXPORT DRecentManager -{ -public: - static bool addItem(const QString &uri, DRecentData &data); - static void removeItem(const QString &target); - static void removeItems(const QStringList &list); -}; - -DCORE_END_NAMESPACE - -#endif // DRECENTMANAGER_H diff -Nru dtkcore-5.5.33/src/util/DThreadUtils dtkcore-5.6.2/src/util/DThreadUtils --- dtkcore-5.5.33/src/util/DThreadUtils 2022-07-19 09:10:28.000000000 +0000 +++ dtkcore-5.6.2/src/util/DThreadUtils 1970-01-01 00:00:00.000000000 +0000 @@ -1 +0,0 @@ -#include "dthreadutils.h" diff -Nru dtkcore-5.5.33/src/util/dthreadutils.cpp dtkcore-5.6.2/src/util/dthreadutils.cpp --- dtkcore-5.5.33/src/util/dthreadutils.cpp 2022-07-19 09:10:28.000000000 +0000 +++ dtkcore-5.6.2/src/util/dthreadutils.cpp 2022-09-21 05:21:07.000000000 +0000 @@ -1,23 +1,6 @@ -/* - * Copyright (C) 2020 ~ 2020 Deepin Technology Co., Ltd. - * - * Author: zccrs - * - * Maintainer: zccrs - * - * 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 - * 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 . - */ +// SPDX-FileCopyrightText: 2020 - 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later #include "dthreadutils.h" diff -Nru dtkcore-5.5.33/src/util/dthreadutils.h dtkcore-5.6.2/src/util/dthreadutils.h --- dtkcore-5.5.33/src/util/dthreadutils.h 2022-07-19 09:10:28.000000000 +0000 +++ dtkcore-5.6.2/src/util/dthreadutils.h 1970-01-01 00:00:00.000000000 +0000 @@ -1,174 +0,0 @@ -/* - * Copyright (C) 2020 ~ 2020 Deepin Technology Co., Ltd. - * - * Author: zccrs - * - * Maintainer: zccrs - * - * 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 - * 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 . - */ -#ifndef DTHREADUTILS_H -#define DTHREADUTILS_H - -#include -#include -#include -#include -#include -#include -#include - -DCORE_BEGIN_NAMESPACE - -namespace DThreadUtil { -typedef std::function FunctionType; - -class LIBDTKCORESHARED_EXPORT FunctionCallProxy : public QObject -{ - Q_OBJECT -public: - explicit FunctionCallProxy(QThread *thread); - - static void proxyCall(QSemaphore *s, QThread *thread, QObject *target, FunctionType fun); - -Q_SIGNALS: - void callInLiveThread(QSemaphore *s, QPointer target, FunctionType *func); -}; - -template -class LIBDTKCORESHARED_EXPORT _TMP -{ -public: - inline static ReturnType runInThread(QSemaphore *s, QThread *thread, QObject *target, std::function fun) - { - ReturnType result; - FunctionType proxyFun = [&result, &fun] () { - result = fun(); - }; - - FunctionCallProxy::proxyCall(s, thread, target, proxyFun); - return result; - } - - template - inline static typename std::enable_if::value, ReturnType>::type - runInThread(QSemaphore *s, QThread *thread, T *, std::function fun) - { - return runInThread(s, thread, static_cast(nullptr), fun); - } -}; -template <> -class LIBDTKCORESHARED_EXPORT _TMP -{ -public: - inline static void runInThread(QSemaphore *s, QThread *thread, QObject *target, std::function fun) - { - FunctionCallProxy::proxyCall(s, thread, target, fun); - } - - template - inline static typename std::enable_if::value, void>::type - runInThread(QSemaphore *s, QThread *thread, T *, std::function fun) - { - return runInThread(s, thread, static_cast(nullptr), fun); - } -}; - -template -inline auto runInThread(QSemaphore *s, QThread *thread, QObject *target, Fun fun, Args&&... args) -> decltype(fun(args...)) -{ - return _TMP::runInThread(s, thread, target, std::bind(fun, std::forward(args)...)); -} -template -inline auto runInThread(QSemaphore *s, QThread *thread, Fun fun, Args&&... args) -> decltype(fun(args...)) -{ - return runInThread(s, thread, nullptr, fun, std::forward(args)...); -} -template -inline typename QtPrivate::FunctionPointer::ReturnType - runInThread(QSemaphore *s, QThread *thread, QObject *target, typename QtPrivate::FunctionPointer::Object *obj, Fun fun, Args&&... args) -{ - return _TMP::ReturnType>::runInThread(s, thread, target, std::bind(fun, obj, std::forward(args)...)); -} -template -inline typename QtPrivate::FunctionPointer::ReturnType - runInThread(QSemaphore *s, QThread *thread, typename QtPrivate::FunctionPointer::Object *obj, Fun fun, Args&&... args) -{ - return _TMP::ReturnType>::runInThread(s, thread, obj, std::bind(fun, obj, std::forward(args)...)); -} - -template -inline auto runInThread(QThread *thread, QObject *target, Fun fun, Args&&... args) -> decltype(fun(args...)) -{ - QSemaphore s; - - return runInThread(&s, thread, target, fun, std::forward(args)...); -} -template -inline auto runInThread(QThread *thread, Fun fun, Args&&... args) -> decltype(fun(args...)) -{ - return runInThread(thread, nullptr, fun, std::forward(args)...); -} -template -inline typename QtPrivate::FunctionPointer::ReturnType - runInThread(QThread *thread, T *target, typename QtPrivate::FunctionPointer::Object *obj, Fun fun, Args&&... args) -{ - QSemaphore s; - - return runInThread(&s, thread, target, obj, fun, std::forward(args)...); -} - -template -inline typename QtPrivate::FunctionPointer::ReturnType - runInThread(QThread *thread, typename QtPrivate::FunctionPointer::Object *obj, Fun fun, Args&&... args) -{ - return runInThread(thread, obj, obj, fun, std::forward(args)...); -} - -template -inline auto runInMainThread(QObject *target, Fun fun, Args&&... args) -> decltype(fun(args...)) -{ - if (!QCoreApplication::instance()) { - return fun(std::forward(args)...); - } - - return runInThread(QCoreApplication::instance()->thread(), target, fun, std::forward(args)...); -} -template -inline auto runInMainThread(Fun fun, Args&&... args) -> decltype(fun(args...)) -{ - return runInMainThread(nullptr, fun, std::forward(args)...); -} - -template -inline typename QtPrivate::FunctionPointer::ReturnType - runInMainThread(T *target, typename QtPrivate::FunctionPointer::Object *obj, Fun fun, Args&&... args) -{ - if (!QCoreApplication::instance()) { - return (obj->*fun)(std::forward(args)...); - } - - return runInThread(QCoreApplication::instance()->thread(), target, obj, fun, std::forward(args)...); -} -template -inline typename QtPrivate::FunctionPointer::ReturnType - runInMainThread(typename QtPrivate::FunctionPointer::Object *obj, Fun fun, Args&&... args) -{ - return runInMainThread(obj, obj, fun, std::forward(args)...); -} -} - -DCORE_END_NAMESPACE - -#endif // DTHREADUTILS_H diff -Nru dtkcore-5.5.33/src/util/dtimedloop.cpp dtkcore-5.6.2/src/util/dtimedloop.cpp --- dtkcore-5.5.33/src/util/dtimedloop.cpp 2022-07-19 09:10:28.000000000 +0000 +++ dtkcore-5.6.2/src/util/dtimedloop.cpp 2022-09-21 05:21:07.000000000 +0000 @@ -1,23 +1,7 @@ -/* - * Copyright (C) 2021 ~ 2021 UnionTech Technology Co., Ltd. - * - * Author: Wang Peng <993381@qq.com> - * - * Maintainer: Wang Peng - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * 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 Lesser General Public License - * along with this program. If not, see . - */ +// SPDX-FileCopyrightText: 2021 - 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later + #include "dtimedloop.h" #include #include diff -Nru dtkcore-5.5.33/src/util/dtimedloop.h dtkcore-5.6.2/src/util/dtimedloop.h --- dtkcore-5.5.33/src/util/dtimedloop.h 2022-07-19 09:10:28.000000000 +0000 +++ dtkcore-5.6.2/src/util/dtimedloop.h 1970-01-01 00:00:00.000000000 +0000 @@ -1,62 +0,0 @@ -/* - * Copyright (C) 2021 ~ 2021 UnionTech Technology Co., Ltd. - * - * Author: Wang Peng <993381@qq.com> - * - * Maintainer: Wang Peng - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * 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 Lesser General Public License - * along with this program. If not, see . - */ -#ifndef DTIMEDLOOP_H -#define DTIMEDLOOP_H -#include -#include - -#include - -DCORE_BEGIN_NAMESPACE - -class DObject; -class DTimedLoopPrivate; -class DTimedLoop : public QEventLoop, public DObject { - Q_OBJECT -public: - explicit DTimedLoop() noexcept; - explicit DTimedLoop(QObject *parent) noexcept; - - ~DTimedLoop(); - - // 如果是 isRunning 则返回从开始到现在的 exec 执行时间,否则返回上次运行的时间 - int runningTime(); - void setTimeDump(bool flag = true); - - void exit(int returnCode = 0); - - // 方式1:不传定时时间,如果不退出就一直执行,配合 exit 使用 - // 方式2:传入durationMs 参数的是定时执行的,也能调用 exit 提前退出 - // 如果传入了 executionName 就会为本次执行设置一个名字,会输出到 log - // 在执行结束将会打印 exec 的执行时间,可以用 setTimeDump 控制其是否打印 - int exec(QEventLoop::ProcessEventsFlags flags = QEventLoop::AllEvents); - int exec(int durationMs, QEventLoop::ProcessEventsFlags flags = QEventLoop::AllEvents); - int exec(const QString &executionName, QEventLoop::ProcessEventsFlags flags = QEventLoop::AllEvents); - int exec(int durationMs, const QString &executionName, QEventLoop::ProcessEventsFlags flags = QEventLoop::AllEvents); - -private: - Q_DISABLE_COPY(DTimedLoop) - D_DECLARE_PRIVATE(DTimedLoop) -}; - -DCORE_END_NAMESPACE - -#endif // DTIMEDLOOP_H diff -Nru dtkcore-5.5.33/src/util/DTimeUnitFormatter dtkcore-5.6.2/src/util/DTimeUnitFormatter --- dtkcore-5.5.33/src/util/DTimeUnitFormatter 2022-07-19 09:10:28.000000000 +0000 +++ dtkcore-5.6.2/src/util/DTimeUnitFormatter 1970-01-01 00:00:00.000000000 +0000 @@ -1 +0,0 @@ -#include "dtimeunitformatter.h" diff -Nru dtkcore-5.5.33/src/util/dtimeunitformatter.cpp dtkcore-5.6.2/src/util/dtimeunitformatter.cpp --- dtkcore-5.5.33/src/util/dtimeunitformatter.cpp 2022-07-19 09:10:28.000000000 +0000 +++ dtkcore-5.6.2/src/util/dtimeunitformatter.cpp 2022-09-21 05:21:07.000000000 +0000 @@ -1,19 +1,6 @@ -/* - * Copyright (C) 2017 ~ 2017 Deepin Technology Co., Ltd. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * 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 Lesser General Public License - * along with this program. If not, see . - */ +// SPDX-FileCopyrightText: 2017 - 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later #include "dtimeunitformatter.h" diff -Nru dtkcore-5.5.33/src/util/dtimeunitformatter.h dtkcore-5.6.2/src/util/dtimeunitformatter.h --- dtkcore-5.5.33/src/util/dtimeunitformatter.h 2022-07-19 09:10:28.000000000 +0000 +++ dtkcore-5.6.2/src/util/dtimeunitformatter.h 1970-01-01 00:00:00.000000000 +0000 @@ -1,49 +0,0 @@ -/* - * Copyright (C) 2017 ~ 2017 Deepin Technology Co., Ltd. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * 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 Lesser General Public License - * along with this program. If not, see . - */ - -#ifndef DTIMEUNITFORMATTER_H -#define DTIMEUNITFORMATTER_H - -#include "dtkcore_global.h" -#include "dabstractunitformatter.h" - -DCORE_BEGIN_NAMESPACE - -class LIBDTKCORESHARED_EXPORT DTimeUnitFormatter : public DAbstractUnitFormatter -{ -public: - DTimeUnitFormatter(); - - enum TimeUnits - { - Seconds, - Minute, - Hour, - Day, - }; - - QString unitStr(int unitId) const override; - -protected: - int unitMax() const override { return Day; } - int unitMin() const override { return Seconds; } - uint unitConvertRate(int unitId) const override; -}; - -DCORE_END_NAMESPACE - -#endif // DTIMEUNITFORMATTER_H diff -Nru dtkcore-5.5.33/src/util/DUtil dtkcore-5.6.2/src/util/DUtil --- dtkcore-5.5.33/src/util/DUtil 2022-07-19 09:10:28.000000000 +0000 +++ dtkcore-5.6.2/src/util/DUtil 1970-01-01 00:00:00.000000000 +0000 @@ -1 +0,0 @@ -#include "dutil.h" diff -Nru dtkcore-5.5.33/src/util/dutil.h dtkcore-5.6.2/src/util/dutil.h --- dtkcore-5.5.33/src/util/dutil.h 2022-07-19 09:10:28.000000000 +0000 +++ dtkcore-5.6.2/src/util/dutil.h 1970-01-01 00:00:00.000000000 +0000 @@ -1,60 +0,0 @@ -/* - * Copyright (C) 2016 ~ 2017 Deepin Technology Co., Ltd. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * 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 Lesser General Public License - * along with this program. If not, see . - */ - -#pragma once - -#include -#include -#include -#include - -namespace DUtil -{ - -template -inline void TimerSingleShot(int msec, Func1 slot) -{ -#if QT_VERSION >= 0x050500 - QTimer::singleShot(msec, slot); -#else - QTimer *timer = new QTimer; - timer->setSingleShot(true); - timer->setInterval(msec); - timer->moveToThread(qApp->thread()); - QObject::connect(timer, &QTimer::timeout, slot); - QObject::connect(timer, &QTimer::timeout, timer, &QTimer::deleteLater); - if (QThread::currentThread() == qApp->thread()) { timer->start(); } - else { QMetaObject::invokeMethod(timer, "start", Qt::QueuedConnection); } -#endif -} - -template -void SecureErase(T *p, size_t size) -{ - memset(p, 0, size); -} - -template -void SecureErase(T &obj) -{ - for (typename T::iterator i = obj.begin(); i != obj.end(); ++i) { - *i = 0; - } - obj.clear(); -} - -} diff -Nru dtkcore-5.5.33/src/util/DVtableHook dtkcore-5.6.2/src/util/DVtableHook --- dtkcore-5.5.33/src/util/DVtableHook 2022-07-19 09:10:28.000000000 +0000 +++ dtkcore-5.6.2/src/util/DVtableHook 1970-01-01 00:00:00.000000000 +0000 @@ -1 +0,0 @@ -#include "dvtablehook.h" diff -Nru dtkcore-5.5.33/src/util/dvtablehook.cpp dtkcore-5.6.2/src/util/dvtablehook.cpp --- dtkcore-5.5.33/src/util/dvtablehook.cpp 2022-07-19 09:10:28.000000000 +0000 +++ dtkcore-5.6.2/src/util/dvtablehook.cpp 2022-09-21 05:21:07.000000000 +0000 @@ -1,23 +1,7 @@ -/* - * Copyright (C) 2019 ~ 2019 Deepin Technology Co., Ltd. - * - * Author: zccrs - * - * Maintainer: zccrs - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * 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 Lesser General Public License - * along with this program. If not, see . - */ +// SPDX-FileCopyrightText: 2019 - 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later + #include "dvtablehook.h" #include diff -Nru dtkcore-5.5.33/src/util/dvtablehook.h dtkcore-5.6.2/src/util/dvtablehook.h --- dtkcore-5.5.33/src/util/dvtablehook.h 2022-07-19 09:10:28.000000000 +0000 +++ dtkcore-5.6.2/src/util/dvtablehook.h 1970-01-01 00:00:00.000000000 +0000 @@ -1,354 +0,0 @@ -/* - * Copyright (C) 2019 ~ 2019 Deepin Technology Co., Ltd. - * - * Author: zccrs - * - * Maintainer: zccrs - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * 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 Lesser General Public License - * along with this program. If not, see . - */ -#ifndef DVTABLEHOOK_H -#define DVTABLEHOOK_H - -#include - -#include -#include -#include - -#include -#include - -DCORE_BEGIN_NAMESPACE - -class LIBDTKCORESHARED_EXPORT DVtableHook -{ -public: - static inline quintptr toQuintptr(const void *ptr) - { - return *(quintptr*)ptr; - } - - static inline int getVtableSize(quintptr **obj) - { - quintptr *begin = *obj; - while(*begin) ++begin; - return begin - *obj; - } - - static inline quintptr *getVtableOfObject(const void *obj) - { - return *(quintptr**)obj; - } - - template - static quintptr *getVtableOfClass() - { - QByteArray vtable_symbol(typeid(T).name()); - vtable_symbol.prepend("_ZTV"); - - quintptr *vfptr_t1 = reinterpret_cast(resolve(vtable_symbol.constData())); - - if (!vfptr_t1) - return nullptr; - - // symbol address + 2 * sizeof(quintptr) = virtal table start address - return vfptr_t1 + 2; - } - - static int getDestructFunIndex(quintptr **obj, std::function destoryObjFun); - static constexpr const QObject *getQObject(...) { return nullptr;} - static constexpr const QObject *getQObject(const QObject *obj) { return obj;} - static void autoCleanVtable(const void *obj); - static bool ensureVtable(const void *obj, std::function destoryObjFun); - static bool hasVtable(const void *obj); - static void resetVtable(const void *obj); - static quintptr resetVfptrFun(const void *obj, quintptr functionOffset); - static quintptr originalFun(const void *obj, quintptr functionOffset); - static bool forceWriteMemory(void *adr, const void *data, size_t length); - static QFunctionPointer resolve(const char *symbol); - - template class OverrideDestruct : public T { ~OverrideDestruct() override;}; - template struct CheckCompatibleArguments { enum { value = false }; }; - template struct CheckCompatibleArguments { enum { value = true }; }; - - template - static bool overrideVfptrFun(quintptr *vfptr_t1, Fun1 fun1, quintptr *vfptr_t2, Fun2 fun2, bool forceWrite) - { - typedef QtPrivate::FunctionPointer FunInfo1; - typedef QtPrivate::FunctionPointer FunInfo2; - - //compilation error if the arguments does not match. - Q_STATIC_ASSERT_X((CheckCompatibleArguments::value), - "Function1 and Function2 arguments are not compatible."); - Q_STATIC_ASSERT_X((CheckCompatibleArguments, QtPrivate::List>::value), - "Function1 and Function2 return type are not compatible.."); - - //! ({code}) in the form of a code is to eliminate - Wstrict - aliasing build warnings - quintptr fun1_offset = toQuintptr(&fun1); - quintptr fun2_offset = toQuintptr(&fun2); - - if (fun1_offset < 0 || fun1_offset > UINT_LEAST16_MAX) - return false; - - quintptr *vfun = vfptr_t1 + fun1_offset / sizeof(quintptr); - - // if the fun2 is not virtual function - if (fun2_offset <= UINT_LEAST16_MAX) { - fun2_offset = *(vfptr_t2 + fun2_offset / sizeof(quintptr)); - } - - if (forceWrite) - return forceWriteMemory(vfun, &fun2_offset, sizeof(fun2_offset)); - - *vfun = fun2_offset; - - return true; - } - - template - static bool overrideVfptrFun(const typename QtPrivate::FunctionPointer::Object *t1, Fun1 fun1, - const typename QtPrivate::FunctionPointer::Object *t2, Fun2 fun2) - { - typedef QtPrivate::FunctionPointer FunInfo1; - // 检查析构函数是否为虚 - class OverrideDestruct : public FunInfo1::Object { ~OverrideDestruct() override;}; - - if (!ensureVtable((void*)t1, std::bind(&_destory_helper, t1))) { - return false; - } - - quintptr *vfptr_t1 = getVtableOfObject(t1); - quintptr *vfptr_t2 = getVtableOfObject(t2); - - bool ok = overrideVfptrFun(vfptr_t1, fun1, vfptr_t2, fun2, false); - - if (!ok) { - // 恢复旧环境 - resetVtable(t1); - } - - return ok; - } - - template - static bool overrideVfptrFun(Fun1 fun1, const typename QtPrivate::FunctionPointer::Object *t2, Fun2 fun2) - { - quintptr *vfptr_t1 = getVtableOfClass(); - - if (!vfptr_t1) { - abort(); - } - - quintptr *vfptr_t2 = getVtableOfObject(t2); - - return overrideVfptrFun(vfptr_t1, fun1, vfptr_t2, fun2, true); - } - - template - static bool overrideVfptrFun(Fun1 fun1, const typename QtPrivate::FunctionPointer::Object *t2, Fun2 fun2) - { - typedef QtPrivate::FunctionPointer FunInfo1; - return overrideVfptrFun(fun1, t2, fun2); - } - - template struct FunctionPointer { }; - template struct FunctionPointer - { - typedef QtPrivate::List Arguments; - }; - template struct FunctionPointer - { - typedef QtPrivate::List Arguments; - }; - template - static typename std::enable_if::ArgumentCount >= 0, bool>::type - overrideVfptrFun(quintptr *vfptr_t1, Fun1 fun1, Fun2 fun2, bool forceWrite) - { - typedef QtPrivate::FunctionPointer FunInfo1; - typedef QtPrivate::FunctionPointer FunInfo2; - - Q_STATIC_ASSERT(!FunInfo2::IsPointerToMemberFunction); - //compilation error if the arguments does not match. - Q_STATIC_ASSERT_X((CheckCompatibleArguments::Arguments, typename FunInfo2::Arguments>::value), - "Function1 and Function2 arguments are not compatible."); - Q_STATIC_ASSERT_X((CheckCompatibleArguments, QtPrivate::List>::value), - "Function1 and Function2 return type are not compatible.."); - - //! ({code}) in the form of a code is to eliminate - Wstrict - aliasing build warnings - quintptr fun1_offset = toQuintptr(&fun1); - quintptr fun2_offset = toQuintptr(&fun2); - - if (fun1_offset < 0 || fun1_offset > UINT_LEAST16_MAX) - return false; - - quintptr *vfun = vfptr_t1 + fun1_offset / sizeof(quintptr); - - if (forceWrite) - return forceWriteMemory(vfun, &fun2_offset, sizeof(fun2_offset)); - - *vfun = fun2_offset; - - return true; - } - - template struct StdFunWrap {}; - template - struct StdFunWrap { - typedef std::function StdFunType; - static inline StdFunType fun(StdFunType f, bool check = true) { - static StdFunType fun = f; - static bool initialized = false; - if (initialized && check) { - qWarning("The StdFunWrap is dirty! Don't use std::bind(use lambda functions)."); - } - initialized = true; - return fun; - } - static Ret call(Obj *o, Args... args) { - return fun(call, false)(o, std::forward(args)...); - } - }; - template - struct StdFunWrap : StdFunWrap{}; - - template - static inline typename std::enable_if::ArgumentCount == -1, bool>::type - overrideVfptrFun(quintptr *vfptr_t1, Fun1 fun1, Fun2 fun2, bool forceWrite) - { - typedef QtPrivate::FunctionPointer FunInfo1; - const int FunctorArgumentCount = QtPrivate::ComputeFunctorArgumentCount::Arguments>::Value; - - Q_STATIC_ASSERT_X((FunctorArgumentCount >= 0), - "Function1 and Function2 arguments are not compatible."); - const int Fun2ArgumentCount = (FunctorArgumentCount >= 0) ? FunctorArgumentCount : 0; - typedef typename QtPrivate::FunctorReturnType::Arguments, Fun2ArgumentCount>::Value>::Value Fun2ReturnType; - - Q_STATIC_ASSERT_X((QtPrivate::AreArgumentsCompatible::value), - "Function1 and Function2 return type are not compatible."); - - StdFunWrap::fun(fun2); - return overrideVfptrFun(vfptr_t1, fun1, StdFunWrap::call, forceWrite); - } - - /*! - * \fn template static bool overrideVfptrFun(const typename QtPrivate::FunctionPointer::Object *t1, Fun1 fun1, Fun2 fun2) - * - * \note 重载多继承类中的多个虚函数时,fun1务必标记成一个类名的函数。否则可能出现内存泄露的情况 - * \note 例如 class A 继承于 B,C,D,当需要重载B中的foo1,C中的foo2时,以下函数的fun1需要统一标记为&A::foo1和&A::foo2 - * \note 因为如果分开写为&B::foo1和&C::foo2的话,指针转换内部会记录多张虚表,重载多份析构函数,可能导致最开始的部分无法正常析构! - */ - template - static bool overrideVfptrFun(const typename QtPrivate::FunctionPointer::Object *t1, Fun1 fun1, Fun2 fun2) - { - typedef QtPrivate::FunctionPointer FunInfo1; - // 检查析构函数是否为虚 - class OverrideDestruct : public FunInfo1::Object { ~OverrideDestruct() override;}; - - if (!ensureVtable((void*)t1, std::bind(&_destory_helper, t1))) { - return false; - } - - bool ok = overrideVfptrFun(getVtableOfObject(t1), fun1, fun2, false); - - if (!ok) { - // 恢复旧环境 - resetVtable(t1); - } - - return true; - } - - template - static bool overrideVfptrFun(Fun1 fun1, Fun2 fun2) - { - quintptr *vfptr_t1 = getVtableOfClass(); - - if (!vfptr_t1) { - abort(); - } - - return overrideVfptrFun(vfptr_t1, fun1, fun2, true); - } - - template - static bool overrideVfptrFun(Fun1 fun1, Fun2 fun2) - { - typedef QtPrivate::FunctionPointer FunInfo1; - return overrideVfptrFun(fun1, fun2); - } - - template - static bool resetVfptrFun(const typename QtPrivate::FunctionPointer::Object *obj, Fun1 fun) - { - return resetVfptrFun((void*)obj, toQuintptr(&fun)) > 0; - } - - template - static Fun originalFun(const typename QtPrivate::FunctionPointer::Object *obj, Fun fun) - { - quintptr o_fun = originalFun((void*)obj, toQuintptr(&fun)); - - return *reinterpret_cast(o_fun); - } - - template - static typename QtPrivate::FunctionPointer::ReturnType - callOriginalFun(typename QtPrivate::FunctionPointer::Object *obj, Fun fun, Args&&... args) - { - quintptr fun_offset = toQuintptr(&fun); - - class _ResetVFun - { - public: - ~_ResetVFun() { - *(vfptr + offset / sizeof(quintptr)) = oldFun; - } - quintptr *vfptr = nullptr; - quint16 offset = 0; - quintptr oldFun = 0; - }; - - _ResetVFun rvf; - - rvf.vfptr = *(quintptr**)(obj); - rvf.offset = fun_offset; - rvf.oldFun = DVtableHook::resetVfptrFun((void*)obj, fun_offset); - - if (!rvf.oldFun) { - qWarning() << "Reset the function failed, object:" << obj; - abort(); - } - - // call - return (obj->*fun)(std::forward(args)...); - } - -private: - static bool copyVtable(quintptr **obj); - static bool clearGhostVtable(const void *obj); - - template - static void _destory_helper(const T *obj) { - delete obj; - } - - static QMap objToOriginalVfptr; - static QMap objToGhostVfptr; - static QMap objDestructFun; -}; - -DCORE_END_NAMESPACE - -#endif // DVTABLEHOOK_H diff -Nru dtkcore-5.5.33/src/util/util.cmake dtkcore-5.6.2/src/util/util.cmake --- dtkcore-5.5.33/src/util/util.cmake 1970-01-01 00:00:00.000000000 +0000 +++ dtkcore-5.6.2/src/util/util.cmake 2022-09-21 05:21:07.000000000 +0000 @@ -0,0 +1,44 @@ +if(LINUX) + set(UTILS_SOURCE + ${CMAKE_CURRENT_LIST_DIR}/dtimeunitformatter.cpp + ${CMAKE_CURRENT_LIST_DIR}/dabstractunitformatter.cpp + ${CMAKE_CURRENT_LIST_DIR}/ddisksizeformatter.cpp + ${CMAKE_CURRENT_LIST_DIR}/ddbussender.cpp + ${CMAKE_CURRENT_LIST_DIR}/drecentmanager.cpp + ${CMAKE_CURRENT_LIST_DIR}/dnotifysender.cpp + ${CMAKE_CURRENT_LIST_DIR}/dpinyin.cpp + ${CMAKE_CURRENT_LIST_DIR}/dexportedinterface.cpp + ${CMAKE_CURRENT_LIST_DIR}/dvtablehook.cpp + ${CMAKE_CURRENT_LIST_DIR}/dthreadutils.cpp + ${CMAKE_CURRENT_LIST_DIR}/dtimedloop.cpp + ${CMAKE_CURRENT_LIST_DIR}/dfileservices_linux.cpp + ${CMAKE_CURRENT_LIST_DIR}/dexportedinterface.cpp + ${CMAKE_CURRENT_LIST_DIR}/ddbusinterface.cpp + ) +else() + set(UTILS_SOURCE + ${CMAKE_CURRENT_LIST_DIR}/dtimeunitformatter.cpp + ${CMAKE_CURRENT_LIST_DIR}/dabstractunitformatter.cpp + ${CMAKE_CURRENT_LIST_DIR}/ddisksizeformatter.cpp + ${CMAKE_CURRENT_LIST_DIR}/ddbussender.cpp + ${CMAKE_CURRENT_LIST_DIR}/drecentmanager.cpp + ${CMAKE_CURRENT_LIST_DIR}/dnotifysender.cpp + ${CMAKE_CURRENT_LIST_DIR}/dpinyin.cpp + ${CMAKE_CURRENT_LIST_DIR}/dexportedinterface.cpp + ${CMAKE_CURRENT_LIST_DIR}/dvtablehook.cpp + ${CMAKE_CURRENT_LIST_DIR}/dthreadutils.cpp + ${CMAKE_CURRENT_LIST_DIR}/dtimedloop.cpp + ${CMAKE_CURRENT_LIST_DIR}/dfileservices_dummy.cpp + ${CMAKE_CURRENT_LIST_DIR}/dexportedinterface.cpp + ${CMAKE_CURRENT_LIST_DIR}/ddbusinterface.cpp + ) +endif() +file(GLOB UTILS_HEADER + ${CMAKE_CURRENT_LIST_DIR}/../../include/util/* + ${CMAKE_CURRENT_LIST_DIR}/ddbusinterface_p.h +) +set(utils_SRC + ${UTILS_HEADER} + ${UTILS_SOURCE} + ${CMAKE_CURRENT_LIST_DIR}/util.qrc +) diff -Nru dtkcore-5.5.33/src/util/util.pri dtkcore-5.6.2/src/util/util.pri --- dtkcore-5.5.33/src/util/util.pri 2022-07-19 09:10:28.000000000 +0000 +++ dtkcore-5.6.2/src/util/util.pri 1970-01-01 00:00:00.000000000 +0000 @@ -1,55 +0,0 @@ -HEADERS += \ - $$PWD/dutil.h \ - $$PWD/dpinyin.h \ - $$PWD/dtimeunitformatter.h \ - $$PWD/dabstractunitformatter.h \ - $$PWD/ddisksizeformatter.h \ - $$PWD/ddbussender.h \ - $$PWD/drecentmanager.h \ - $$PWD/dnotifysender.h \ - $$PWD/dexportedinterface.h \ - $$PWD/dvtablehook.h \ - $$PWD/dfileservices.h \ - $$PWD/dthreadutils.h \ - $$PWD/dasync.h \ - $$PWD/dtimedloop.h - -INCLUDEPATH += $$PWD - -includes.files += $$PWD/*.h -includes.files += \ - $$PWD/DUtil \ - $$PWD/DPinyin \ - $$PWD/DDBusSender \ - $$PWD/DRecentManager \ - $$PWD/DNotifySender \ - $$PWD/DExportedInterface \ - $$PWD/DVtableHook \ - $$PWD/DFileServices \ - $$PWD/DThreadUtils - -RESOURCES += \ - $$PWD/util.qrc - -SOURCES += \ - $$PWD/dtimeunitformatter.cpp \ - $$PWD/dabstractunitformatter.cpp \ - $$PWD/ddisksizeformatter.cpp \ - $$PWD/ddbussender.cpp \ - $$PWD/drecentmanager.cpp \ - $$PWD/dnotifysender.cpp \ - $$PWD/dpinyin.cpp \ - $$PWD/dexportedinterface.cpp \ - $$PWD/dvtablehook.cpp \ - $$PWD/dthreadutils.cpp \ - $$PWD/dtimedloop.cpp - -linux { - QT += dbus - - SOURCES += \ - $$PWD/dfileservices_linux.cpp -} else { - SOURCES += \ - $$PWD/dfileservices_dummy.cpp -} diff -Nru dtkcore-5.5.33/tests/CMakeLists.txt dtkcore-5.6.2/tests/CMakeLists.txt --- dtkcore-5.5.33/tests/CMakeLists.txt 1970-01-01 00:00:00.000000000 +0000 +++ dtkcore-5.6.2/tests/CMakeLists.txt 2022-09-21 05:21:07.000000000 +0000 @@ -0,0 +1,174 @@ +set(BIN_NAME "ut-${PROJECT_NAME}") + +set(CMAKE_INCLUDE_CURRENT_DIR ON) +set(CMAKE_EXPORT_COMPILE_COMMANDS ON) + +set(CMAKE_AUTOMOC ON) +set(CMAKE_AUTOUIC ON) +set(CMAKE_AUTORCC ON) +# dbus +set(CMAKE_CXX_FLAGS "-fno-access-control -ldl") +add_compile_options(-fsanitize=address) +add_link_options(-fsanitize=address) +add_definitions(-DPREFIX="${CMAKE_PREFIX_PATH}") +add_definitions(-DOS_VERSION_TEST_FILE="/tmp/etc/os-version") +find_package(Qt5 REQUIRED COMPONENTS Gui) +find_package(Qt5 REQUIRED COMPONENTS Core) +if(LINUX) + find_package(Qt5 REQUIRED COMPONENTS DBus) + find_package(PkgConfig REQUIRED) + pkg_check_modules(QGSettings REQUIRED gsettings-qt) +endif() +find_package(Qt5 REQUIRED COMPONENTS Xml) +find_package(Qt5 REQUIRED COMPONENTS Concurrent) +find_package(Qt5 REQUIRED COMPONENTS Test) +find_package(GTest REQUIRED) + +# start base +include(../src/base/base.cmake) + +# end base +if(LINUX) + include(../src/dbus/dbus.cmake) +endif() +#message(${dbus_SRCS}) +# end dbus + + + +# start dci +include(../src/dci/dci.cmake) +#end dci + +#start filesystem +include(../src/filesystem/filesystem.cmake) +#end filesystem +# start log +include(../src/log/log.cmake) +#end log +# start settings +include(../src/settings/settings.cmake) +#message(${settings_SRC}) +#end settings + +#start utils + +# TODO match linux and others +include(../src/util/util.cmake) +#end utils + +#GLOB +include(../src/glob.cmake) + +#endglob + + +# test +file(GLOB TEST_HEADER + ut_.*h +) +file(GLOB TEST_SOURCE + *.cpp +) +set(test_SRC + ${TEST_HEADER} + ${TEST_SOURCE} +) + + + +# end test +if(LINUX) + add_executable(${BIN_NAME} + ${dbus_SRCS} + ${base_SRCS} + ${dci_SRCS} + ${filesystem_SRCS} + ${log_SRCS} + ${settings_SRC} + ${utils_SRC} + ${glob_SRC} + ${test_SRC} + ./data.qrc + ) + target_link_libraries( + ${BIN_NAME} PRIVATE + Qt5::Gui + Qt5::Core + Qt5::DBus + Qt5::Xml + Qt5::Concurrent + Qt5::Test + ${GTEST_LIBRARIES} + ${QGSettings_LIBRARIES} + -lpthread + -lm + -lgcov + ) + if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang") + target_compile_options(${BIN_NAME} PRIVATE -fprofile-instr-generate -ftest-coverage) + endif() + if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU") + target_compile_options(${BIN_NAME} PRIVATE -fprofile-arcs -ftest-coverage) + endif() + target_include_directories( ${BIN_NAME} PUBLIC + ${Qt5Core_PRIVATE_INCLUDE_DIRS} + ${QGSettings_INCULDE_DIRS} + ../include/util/ + ../include/dci/ + ../include/log/ + ../include/base/ + ../include/base/private/ + ../include/global/ + ../include/DtkCore/ + ../include/settings/ + ../include/filesystem/ + ../include/ + ../src/filesystem/private/ + ) +else() + add_executable(${BIN_NAME} + ${base_SRCS} + ${dci_SRCS} + ${filesystem_SRCS} + ${log_SRCS} + ${settings_SRC} + ${utils_SRC} + ${glob_SRC} + ${test_SRC} + ./data.qrc + ) + target_link_libraries( + ${BIN_NAME} PRIVATE + Qt5::Gui + Qt5::Core + Qt5::Xml + Qt5::Concurrent + Qt5::Test + ${GTEST_LIBRARIES} + -lpthread + -lm + -lgcov + ) + if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang") + target_compile_options(${BIN_NAME} PRIVATE -fprofile-instr-generate -ftest-coverage) + endif() + if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU") + target_compile_options(${BIN_NAME} PRIVATE -fprofile-arcs -ftest-coverage) + endif() + target_include_directories( ${BIN_NAME} PUBLIC + ${Qt5Core_PRIVATE_INCLUDE_DIRS} + ../include/util/ + ../include/dci/ + ../include/log/ + ../include/base/ + ../include/base/private/ + ../include/global/ + ../include/DtkCore/ + ../include/settings/ + ../include/filesystem/ + ../include/ + ) +endif() + +add_test(NAME ${BIN_NAME} COMMAND ${BIN_NAME}) diff -Nru dtkcore-5.5.33/tests/ddesktopentry/ddesktopentry.pro dtkcore-5.6.2/tests/ddesktopentry/ddesktopentry.pro --- dtkcore-5.5.33/tests/ddesktopentry/ddesktopentry.pro 2022-07-19 09:10:28.000000000 +0000 +++ dtkcore-5.6.2/tests/ddesktopentry/ddesktopentry.pro 1970-01-01 00:00:00.000000000 +0000 @@ -1,27 +0,0 @@ -QT += testlib -QT -= gui - -TARGET = tst_ddesktopentrytest -TEMPLATE = app -CONFIG += c++11 -CONFIG -= app_bundle - -!isEmpty(DTK_STATIC_LIB){ - DEFINES += DTK_STATIC_LIB -} - -load(dtk_testcase) - -win32:CONFIG(release, debug|release): LIBS += -L$$OUT_PWD/../../src/release/ -ldtkcore -lgtest -else:win32:CONFIG(debug, debug|release): LIBS += -L$$OUT_PWD/../../src/debug/ -ldtkcore -lgtest -else:unix: LIBS += -L$$OUT_PWD/../../src/ -ldtkcore -lgtest - -INCLUDEPATH += $$PWD/../../src -DEPENDPATH += $$PWD/../../src -unix:QMAKE_RPATHDIR += $$OUT_PWD/../../src - -QMAKE_LFLAGS += -Wl,--export-dynamic - -SOURCES += \ - $$PWD/../../src/ddesktopentry.cpp \ - ut_ddesktopentrytest.cpp diff -Nru dtkcore-5.5.33/tests/dthreadutils/dthreadutils.pro dtkcore-5.6.2/tests/dthreadutils/dthreadutils.pro --- dtkcore-5.5.33/tests/dthreadutils/dthreadutils.pro 2022-07-19 09:10:28.000000000 +0000 +++ dtkcore-5.6.2/tests/dthreadutils/dthreadutils.pro 1970-01-01 00:00:00.000000000 +0000 @@ -1,25 +0,0 @@ -QT += testlib concurrent -QT -= gui - -TEMPLATE = app -CONFIG += c++11 - -!isEmpty(DTK_STATIC_LIB){ - DEFINES += DTK_STATIC_LIB -} - -load(dtk_testcase) - -win32:CONFIG(release, debug|release): LIBS += -L$$OUT_PWD/../../src/release/ -ldtkcore -else:win32:CONFIG(debug, debug|release): LIBS += -L$$OUT_PWD/../../src/debug/ -ldtkcore -else:unix: LIBS += -L$$OUT_PWD/../../src/ -ldtkcore - -INCLUDEPATH += $$PWD/../../src -DEPENDPATH += $$PWD/../../src -QMAKE_RPATHDIR += $$OUT_PWD/../../src - -QMAKE_LFLAGS += -Wl,--export-dynamic - -SOURCES += \ - $$PWD/../../src/util/dthreadutils.cpp \ - ut_dthreadutils.cpp diff -Nru dtkcore-5.5.33/tests/dutils/dutils.pro dtkcore-5.6.2/tests/dutils/dutils.pro --- dtkcore-5.5.33/tests/dutils/dutils.pro 2022-07-19 09:10:28.000000000 +0000 +++ dtkcore-5.6.2/tests/dutils/dutils.pro 1970-01-01 00:00:00.000000000 +0000 @@ -1,54 +0,0 @@ -QT += testlib dbus -QT -= gui - -TEMPLATE = app -CONFIG += c++11 - -!isEmpty(DTK_STATIC_LIB){ - DEFINES += DTK_STATIC_LIB -} -# 使用 tmp 目录下的 os-version -DEFINES += OS_VERSION_TEST_FILE=\\\"/tmp/etc/os-version\\\" - -load(dtk_testcase) - -SOURCES += \ - $$PWD/../../src/util/dtimeunitformatter.cpp \ - $$PWD/../../src/util/ddisksizeformatter.cpp \ - $$PWD/../../src/log/LogManager.cpp \ - $$PWD/../../src/filesystem/dpathbuf.cpp \ - $$PWD/../../src/util/ddbussender.cpp \ - $$PWD/../../src/settings/dsettings.cpp \ - $$PWD/../../src/settings/dsettingsgroup.cpp \ - $$PWD/../../src/settings/dsettingsoption.cpp \ - $$PWD/../../src/dsysinfo.cpp \ - main.cpp \ - ut_dutil.cpp \ - ut_singleton.cpp - -HEADERS += \ - $$PWD/../../src/util/dtimeunitformatter.h \ - $$PWD/../../src/util/ddisksizeformatter.h \ - $$PWD/../../src/log/LogManager.h \ - $$PWD/../../src/filesystem/dpathbuf.h \ - $$PWD/../../src/util/ddbussender.h \ - $$PWD/../../src/settings/dsettings.h \ - $$PWD/../../src/settings/dsettingsgroup.h \ - $$PWD/../../src/settings/dsettingsoption.h \ - $$PWD/../../src/dsysinfo.h \ - $$PWD/../../src/base/dsingleton.h \ - ut_dutil.h \ - ut_singleton.h - -win32:CONFIG(release, debug|release): LIBS += -L$$OUT_PWD/../../src/release/ -ldtkcore -lgtest -else:win32:CONFIG(debug, debug|release): LIBS += -L$$OUT_PWD/../../src/debug/ -ldtkcore -lgtest -else:unix: LIBS += -L$$OUT_PWD/../../src/ -ldtkcore -lgtest - -INCLUDEPATH += \ - $$PWD/../../src \ - $$PWD/../../src/log -DEPENDPATH += $$PWD/../../src -QMAKE_RPATHDIR += $$PWD/../../src - -RESOURCES += \ - data.qrc diff -Nru dtkcore-5.5.33/tests/dvtablehook/dvtablehook.pro dtkcore-5.6.2/tests/dvtablehook/dvtablehook.pro --- dtkcore-5.5.33/tests/dvtablehook/dvtablehook.pro 2022-07-19 09:10:28.000000000 +0000 +++ dtkcore-5.6.2/tests/dvtablehook/dvtablehook.pro 1970-01-01 00:00:00.000000000 +0000 @@ -1,31 +0,0 @@ -QT += testlib -QT -= gui - -TEMPLATE = app -CONFIG += c++11 - -# TODO: vtabhook release test failed -QMAKE_CXXFLAGS_RELEASE -= -O2 - -!isEmpty(DTK_STATIC_LIB){ - DEFINES += DTK_STATIC_LIB -} - -load(dtk_testcase) - -win32:CONFIG(release, debug|release): LIBS += -L$$OUT_PWD/../../src/release/ -ldtkcore -lgtest -else:win32:CONFIG(debug, debug|release): LIBS += -L$$OUT_PWD/../../src/debug/ -ldtkcore -lgtest -else:unix: LIBS += -L$$OUT_PWD/../../src/ -ldtkcore -lgtest -ldl - -INCLUDEPATH += $$PWD/../../src -DEPENDPATH += $$PWD/../../src -QMAKE_RPATHDIR += $$OUT_PWD/../../src - -QMAKE_LFLAGS += -Wl,--export-dynamic - -HEADERS += \ - $$PWD/../../src/util/dvtablehook.h - -SOURCES += \ - $$PWD/../../src/util/dvtablehook.cpp \ - ut_dvtablehook.cpp diff -Nru dtkcore-5.5.33/tests/main.cpp dtkcore-5.6.2/tests/main.cpp --- dtkcore-5.5.33/tests/main.cpp 2022-07-19 09:10:28.000000000 +0000 +++ dtkcore-5.6.2/tests/main.cpp 2022-09-21 05:21:07.000000000 +0000 @@ -1,19 +1,6 @@ -/* - * Copyright (C) 2017 ~ 2017 Deepin Technology Co., Ltd. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * 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 Lesser General Public License - * along with this program. If not, see . - */ +// SPDX-FileCopyrightText: 2017 - 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later #include "ut_dutil.h" #include diff -Nru dtkcore-5.5.33/tests/test_helper.hpp dtkcore-5.6.2/tests/test_helper.hpp --- dtkcore-5.5.33/tests/test_helper.hpp 2022-07-19 09:10:28.000000000 +0000 +++ dtkcore-5.6.2/tests/test_helper.hpp 2022-09-21 05:21:07.000000000 +0000 @@ -1,23 +1,7 @@ -/* - * Copyright (C) 2021 Uniontech Technology Co., Ltd. - * - * Author: yeshanshan - * - * Maintainer: yeshanshan - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * 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 Lesser General Public License - * along with this program. If not, see . - */ +// SPDX-FileCopyrightText: 2021 - 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later + #pragma once #include diff -Nru dtkcore-5.5.33/tests/test-recoverage-qmake.sh dtkcore-5.6.2/tests/test-recoverage-qmake.sh --- dtkcore-5.5.33/tests/test-recoverage-qmake.sh 2022-07-19 09:10:28.000000000 +0000 +++ dtkcore-5.6.2/tests/test-recoverage-qmake.sh 1970-01-01 00:00:00.000000000 +0000 @@ -1,29 +0,0 @@ -#!/bin/bash - -BUILD_DIR=`pwd`/../build-ut -HTML_DIR=${BUILD_DIR}/html -XML_DIR=${BUILD_DIR}/report -#EXTRACT_ARGS="src" -cd ../ -rm -rf $BUILD_DIR -mkdir $BUILD_DIR -cd $BUILD_DIR -qmake .. CONFIG+=debug -make -j$(nproc) -cd ../tests/ - -rm -rf $BUILD_DIR -mkdir $BUILD_DIR -cd $BUILD_DIR -qmake ../ CONFIG+=debug -export ASAN_OPTIONS=halt_on_error=0 -TESTARGS="--gtest_output=xml:${XML_DIR}/report_dtkcore.xml" make check -j$(nproc) - -lcov -d ./ -c -o coverage_all.info -#lcov --extract coverage_all.info $EXTRACT_ARGS --output-file coverage.info -lcov --remove coverage_all.info "*/tests/*" "*/usr/include*" "*build/src*" "*build-ut/src*" --output-file coverage.info -cd .. -genhtml -o $HTML_DIR $BUILD_DIR/coverage.info && mv ${BUILD_DIR}/html/index.html ${BUILD_DIR}/html/cov_dtkcore.html - -test -e ${BUILD_DIR}/asan.log* && mv ${BUILD_DIR}/asan.log* ${BUILD_DIR}/asan_dtkcore.log || touch ${BUILD_DIR}/asan.log - diff -Nru dtkcore-5.5.33/tests/test-recoverage.sh dtkcore-5.6.2/tests/test-recoverage.sh --- dtkcore-5.5.33/tests/test-recoverage.sh 1970-01-01 00:00:00.000000000 +0000 +++ dtkcore-5.6.2/tests/test-recoverage.sh 2022-09-21 05:21:07.000000000 +0000 @@ -0,0 +1,31 @@ +#!/bin/bash + +# SPDX-FileCopyrightText: 2022 UnionTech Software Technology Co., Ltd. +# +# SPDX-License-Identifier: LGPL-3.0-or-later + +BUILD_DIR=`pwd`/../build/tests/ +HTML_DIR=${BUILD_DIR}/html +XML_DIR=${BUILD_DIR}/report + +export ASAN_OPTIONS="halt_on_error=0" + +# back to project directroy +cd .. + +cmake -Bbuild -DCMAKE_BUILD_TYPE=Debug + +cmake --build build --target ut-DtkCore -j$(nproc) + +cd $BUILD_DIR + +./ut-DtkCore --gtest_output=xml:${XML_DIR}/report_dtkcore.xml + +lcov -d ./ -c -o coverage_all.info +#lcov --extract coverage_all.info $EXTRACT_ARGS --output-file coverage.info +lcov --remove coverage_all.info "*/tests/*" "*/usr/include*" "*build/src*" "*build-ut/src*" --output-file coverage.info +cd .. +genhtml -o $HTML_DIR $BUILD_DIR/coverage.info && mv ${BUILD_DIR}/html/index.html ${BUILD_DIR}/html/cov_dtkcore.html + +test -e ${BUILD_DIR}/asan.log* && mv ${BUILD_DIR}/asan.log* ${BUILD_DIR}/asan_dtkcore.log || touch ${BUILD_DIR}/asan.log + diff -Nru dtkcore-5.5.33/tests/tests.pro dtkcore-5.6.2/tests/tests.pro --- dtkcore-5.5.33/tests/tests.pro 2022-07-19 09:10:28.000000000 +0000 +++ dtkcore-5.6.2/tests/tests.pro 1970-01-01 00:00:00.000000000 +0000 @@ -1,83 +0,0 @@ -TEMPLATE = app -QT += core dbus xml testlib concurrent -CONFIG += thread c++11 link_pkgconfig -CONFIG -= app_bundle - -QMAKE_LFLAGS += -Wl,--export-dynamic - -CONFIG(debug, debug|release) { -LIBS += -lgtest -lgmock -QMAKE_CXXFLAGS += -g -Wall -fprofile-arcs -ftest-coverage -fsanitize=address -fsanitize-recover=address -O2 -QMAKE_LFLAGS += -g -Wall -fprofile-arcs -ftest-coverage -fsanitize=address -fsanitize-recover=address -O2 -QMAKE_CXX += -g -fprofile-arcs -ftest-coverage -fsanitize=address -fsanitize-recover=address -O2 -} - -load(dtk_testcase) - -# 指定moc文件生成目录和src一样 -MOC_DIR=$$OUT_PWD/../src - -# 使用 tmp 目录下的 os-version -DEFINES += OS_VERSION_TEST_FILE=\\\"/tmp/etc/os-version\\\" - -DEPENDPATH += $$PWD/../src - -unix: { -QMAKE_RPATHDIR += $$OUT_PWD/../src -LIBS += -lgtest -# for dlsym -LIBS += -ldl -# TODO: vtabhook release test failed -QMAKE_CXXFLAGS_RELEASE -= -O2 -} - -INCLUDEPATH += \ - $$PWD/../src \ - $$PWD/../src/base \ - $$PWD/../src/base/private \ - $$PWD/../src/filesystem \ - $$PWD/../src/log \ - $$PWD/../src/settings \ - $$PWD/../src/util - -include($$PWD/../src/base/base.pri) -include($$PWD/../src/filesystem/filesystem.pri) -include($$PWD/../src/log/log.pri) -include($$PWD/../src/settings/settings.pri) -include($$PWD/../src/util/util.pri) - -HEADERS += $$PWD/ut_*.h \ - $$PWD/../src/dtkcore_global.h \ - $$PWD/../src/dsysinfo.h \ - $$PWD/../src/dsecurestring.h \ - $$PWD/../src/ddesktopentry.h \ - $$PWD/../src/dconfig.h - -SOURCES += $$PWD/*.cpp \ - $$PWD/../src/dsysinfo.cpp \ - $$PWD/../src/dsecurestring.cpp \ - $$PWD/../src/ddesktopentry.cpp \ - $$PWD/../src/dconfig.cpp - -linux: { - HEADERS += \ - $$PWD/../src/dconfigfile.h - - SOURCES += \ - $$PWD/../src/dconfigfile.cpp - - QT += dbus - - config.files = $$PWD/../src/dbus/org.desktopspec.ConfigManager.xml - config.header_flags += -c DSGConfig -N - config.source_flags += -c DSGConfig -N - - manager.files = $$PWD/../src/dbus/org.desktopspec.ConfigManager.Manager.xml - manager.header_flags += -c DSGConfigManager -N - manager.source_flags += -c DSGConfigManager -N - - DBUS_INTERFACES += config manager - -} - -RESOURCES += data.qrc diff -Nru dtkcore-5.5.33/tests/ut_dasync.cpp dtkcore-5.6.2/tests/ut_dasync.cpp --- dtkcore-5.5.33/tests/ut_dasync.cpp 2022-07-19 09:10:28.000000000 +0000 +++ dtkcore-5.6.2/tests/ut_dasync.cpp 2022-09-21 05:21:07.000000000 +0000 @@ -1,23 +1,7 @@ -/* - * Copyright (C) 2021 ~ 2021 UnionTech Technology Co., Ltd. - * - * Author: Wang Peng <993381@qq.com> - * - * Maintainer: Wang Peng - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * 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 Lesser General Public License - * along with this program. If not, see . - */ +// SPDX-FileCopyrightText: 2021 - 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later + #include #include #include diff -Nru dtkcore-5.5.33/tests/ut_dcapfile.cpp dtkcore-5.6.2/tests/ut_dcapfile.cpp --- dtkcore-5.5.33/tests/ut_dcapfile.cpp 1970-01-01 00:00:00.000000000 +0000 +++ dtkcore-5.6.2/tests/ut_dcapfile.cpp 2022-09-21 05:21:07.000000000 +0000 @@ -0,0 +1,318 @@ +// SPDX-FileCopyrightText: 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later + +#include "dcapfsfileengine_p.h" +#include "filesystem/dcapmanager.h" +#include "filesystem/dcapfile.h" + +#include +#include +#include +#include + +DCORE_USE_NAMESPACE + +#ifndef GTEST_SKIP +#define SKIP return GTEST_SUCCEED() << "Skip all tests" +#else +#define SKIP GTEST_SKIP() << "Skip all tests" +#endif + +#define TMPCAP_PATH "/tmp/cap" + +class ut_DCapFSFileEngine : public testing::Test +{ +protected: + void SetUp() override; + void TearDown() override; + + DCapManager *manager; + QFile *file; +}; + +void ut_DCapFSFileEngine::SetUp() +{ + manager = DCapManager::instance(); + manager->removePath("/tmp"); + manager->appendPath(TMPCAP_PATH); + manager->registerFileEngine(); + + file = new QFile(nullptr); + QDir dir(TMPCAP_PATH); + if (!dir.exists()) + ASSERT_TRUE(dir.mkdir(TMPCAP_PATH)); +} + +void ut_DCapFSFileEngine::TearDown() +{ + manager->unregisterFileEngine(); + manager->appendPath("/tmp"); + delete file; + QDir dir(TMPCAP_PATH); + if (dir.exists()) + ASSERT_TRUE(dir.removeRecursively()); +} + +TEST_F(ut_DCapFSFileEngine, testSubDirCanReadWrite) +{ + manager->appendPath("/usr/share/"); + ASSERT_FALSE(DCapFSFileEngine("").canReadWrite("/tmp/usr/share/file0")); + manager->removePath("/usr/share/"); +} + +TEST_F(ut_DCapFSFileEngine, testDCapFileOpenFile) +{ + file->setFileName("/tmp/file0"); + bool open = file->open(QIODevice::WriteOnly); + ASSERT_FALSE(open); // path `/tmp` has removed from setup. + + QDir dir(TMPCAP_PATH); + ASSERT_TRUE(dir.exists()); + if (!dir.exists("subdir")) + ASSERT_TRUE(dir.mkdir("subdir")); + ASSERT_TRUE(dir.cd("subdir")); + file->close(); + file->setFileName(dir.path() + "/file0"); // path: /tmp/etc/subdir/file0 + ASSERT_TRUE(file->open(QIODevice::WriteOnly)); +} + +TEST_F(ut_DCapFSFileEngine, testDCapFileRename) +{ + file->setFileName(TMPCAP_PATH"/file0"); + bool open = file->open(QIODevice::WriteOnly); + ASSERT_TRUE(open); // Default path contains the `/tmp` path. + file->close(); + + ASSERT_TRUE(file->rename(TMPCAP_PATH"/file1")); + ASSERT_FALSE(file->rename("/tmp/file1")); + + QDir dir(TMPCAP_PATH); + if (!dir.exists("subdir")) + ASSERT_TRUE(dir.mkdir("subdir")); + ASSERT_TRUE(file->rename(TMPCAP_PATH"/subdir/file0")); +} + +TEST_F(ut_DCapFSFileEngine, testDCapFileRemove) +{ + file->setFileName(TMPCAP_PATH"/test"); + ASSERT_TRUE(file->open(QFile::WriteOnly)); + file->close(); + ASSERT_TRUE(file->exists()); + ASSERT_TRUE(file->remove()); + ASSERT_FALSE(file->exists()); + + QDir dir(TMPCAP_PATH); + if (!dir.exists("subdir")) + ASSERT_TRUE(dir.mkdir("subdir")); + + manager->appendPath(TMPCAP_PATH"/subdir"); // create a new subdir file. + ASSERT_FALSE(manager->paths().contains(TMPCAP_PATH"/subdir")); // already has /tmp/cap + QFile f(TMPCAP_PATH"/subdir/test"); + ASSERT_TRUE(f.open(QFile::WriteOnly)); + f.close(); + ASSERT_TRUE(f.exists()); + + file->setFileName(TMPCAP_PATH"/subdir/test"); + ASSERT_TRUE(file->remove()); + + manager->appendPath("/tmp"); + ASSERT_TRUE(manager->paths().contains("/tmp")); + file->setFileName("/tmp/file0"); + bool open = file->open(QIODevice::WriteOnly); + ASSERT_TRUE(open); + manager->removePath("/tmp"); + ASSERT_FALSE(manager->paths().contains("/tmp")); + ASSERT_FALSE(file->remove()); +} + +TEST_F(ut_DCapFSFileEngine, testDCapFileLink) +{ + file->setFileName(TMPCAP_PATH"/test"); + ASSERT_TRUE(file->open(QFile::WriteOnly)); + file->close(); + ASSERT_TRUE(file->exists()); + ASSERT_TRUE(file->link(TMPCAP_PATH"/test1")); + ASSERT_FALSE(file->link("/tmp/test1")); + + QDir dir(TMPCAP_PATH); + if (!dir.exists("subdir")) + ASSERT_TRUE(dir.mkdir("subdir")); + ASSERT_TRUE(file->link(TMPCAP_PATH"/subdir/test1")); + + ASSERT_TRUE(file->remove()); // clean the file. +} + +TEST_F(ut_DCapFSFileEngine, testDCapFileCopy) +{ + file->setFileName(TMPCAP_PATH"/test"); + ASSERT_TRUE(file->open(QFile::WriteOnly)); + file->write("test"); + file->close(); + ASSERT_TRUE(file->exists()); + ASSERT_TRUE(file->copy(TMPCAP_PATH"/test2")); + ASSERT_TRUE(file->copy("/tmp/test2")); + ASSERT_FALSE(QFileInfo::exists(TMPCAP_PATH"/subdir/test2")); + + QDir dir(TMPCAP_PATH); + if (!dir.exists("subdir")) + ASSERT_TRUE(dir.mkdir("subdir")); + ASSERT_TRUE(file->copy(TMPCAP_PATH"/subdir/test2")); + ASSERT_TRUE(QFileInfo::exists(TMPCAP_PATH"/subdir/test2")); +} + +TEST_F(ut_DCapFSFileEngine, testDCapFileResize) +{ + file->setFileName(TMPCAP_PATH"/test"); + ASSERT_TRUE(file->open(QFile::WriteOnly)); + file->write("test"); + file->close(); + ASSERT_TRUE(file->exists()); + ASSERT_TRUE(file->resize(10)); + ASSERT_EQ(file->size(), 10); + + QDir dir(TMPCAP_PATH); + if (!dir.exists("subdir")) + ASSERT_TRUE(dir.mkdir("subdir")); + + QFile f(TMPCAP_PATH"/subdir/test"); + ASSERT_TRUE(f.open(QFile::WriteOnly)); + f.write("test"); + f.close(); + ASSERT_TRUE(f.exists()); + + file->setFileName(TMPCAP_PATH"/subdir/test"); + ASSERT_TRUE(file->resize(10)); + + DCapManager::instance()->appendPath("/tmp"); + + f.setFileName("/tmp/test"); + ASSERT_TRUE(f.open(QFile::WriteOnly)); + f.write("test"); + f.close(); + ASSERT_TRUE(f.exists()); + DCapManager::instance()->removePath("/tmp"); + + file->setFileName("/tmp/test"); + ASSERT_FALSE(file->resize(10)); + file->remove();} + +TEST_F(ut_DCapFSFileEngine, testDCapDirEntry) +{ + auto createFiles = [this](const QString & path, int count) { + for (int i = 0; i < count; ++i) { + file->setFileName(QString(path) + "/test" + QString::number(i)); + ASSERT_TRUE(file->open(QFile::WriteOnly)); + file->close(); + ASSERT_TRUE(file->exists()); + } + }; + + createFiles(TMPCAP_PATH, 10); + QDir dir(TMPCAP_PATH); + ASSERT_TRUE(dir.entryList(QDir::Files).length() == 10); + + if (!dir.exists("subdir")) + ASSERT_TRUE(dir.mkdir("subdir")); + + dir.setPath(TMPCAP_PATH"/subdir"); + createFiles(TMPCAP_PATH"/subdir", 10); + ASSERT_TRUE(dir.entryList(QDir::Files).length() == 10); + manager->removePath(TMPCAP_PATH); + ASSERT_TRUE(dir.entryList(QDir::Files).length() == 0); +} + +TEST(ut_DCapFileAndDir, testDCapFileOpen) +{ + DCapFile file("/tmp/test0"); + ASSERT_TRUE(file.open(DCapFile::WriteOnly)); // Default, '/tmp' is allowable for writing. + file.close(); + + DCapManager::instance()->removePath("/tmp"); + ASSERT_FALSE(file.open(DCapFile::WriteOnly)); + DCapManager::instance()->appendPath("/tmp"); +} + +TEST(ut_DCapFileAndDir, testDCapFileOperation) +{ + auto CheckResult = [](bool result) { + DCapFile file("/tmp/test0"); + ASSERT_EQ(file.open(DCapFile::WriteOnly), result); + file.close(); + + ASSERT_EQ(file.exists(), result); + ASSERT_EQ(DCapFile::exists(file.fileName()), result); + ASSERT_EQ(file.remove(), result); + + ASSERT_EQ(file.open(DCapFile::WriteOnly), result); + file.close(); + ASSERT_EQ(DCapFile::remove(file.fileName()), result); + + ASSERT_EQ(file.open(DCapFile::WriteOnly), result); + file.close(); + ASSERT_EQ(file.rename("/tmp/test1"), result); + ASSERT_EQ(DCapFile::rename(file.fileName(), "/tmp/test0"), result); + + file.setFileName("/tmp/test0"); + ASSERT_EQ(file.link("/tmp/test_link0"), result); + ASSERT_EQ(DCapFile::link(file.fileName(), "/tmp/test_link1"), result); + ASSERT_EQ(DCapFile::remove("/tmp/test_link0"), result); + ASSERT_EQ(DCapFile::remove("/tmp/test_link1"), result); + + file.setFileName("/tmp/test0"); + ASSERT_EQ(file.copy("/tmp/test_copy0"), result); + ASSERT_EQ(DCapFile::copy(file.fileName(), "/tmp/test_copy1"), result); + ASSERT_EQ(DCapFile::remove("/tmp/test_copy0"), result); + ASSERT_EQ(DCapFile::remove("/tmp/test_copy1"), result); + + ASSERT_EQ(file.resize(10), result); + ASSERT_EQ(file.size() == 10, result); + ASSERT_EQ(DCapFile::resize(file.fileName(), 5), result); + ASSERT_EQ(file.size() == 5, result); + ASSERT_EQ(file.remove(), result); + }; + + CheckResult(true); + DCapManager::instance()->removePath("/tmp"); + CheckResult(false); + DCapManager::instance()->appendPath("/tmp"); +} + +TEST(ut_DCapFileAndDir, testDCapDirOperation) +{ + DCapDir dir("/tmp"); + ASSERT_TRUE(dir.exists()); + ASSERT_FALSE(dir.entryList().isEmpty()); + ASSERT_FALSE(dir.entryInfoList().isEmpty()); + + DCapFile file(dir.path() + "/test0"); + ASSERT_TRUE(file.open(DCapFile::WriteOnly)); + file.close(); + ASSERT_TRUE(dir.exists("test0")); + + ASSERT_TRUE(dir.mkdir("cap")); + ASSERT_TRUE(dir.exists("cap")); + ASSERT_TRUE(dir.rmdir("cap")); + ASSERT_FALSE(dir.exists("cap")); + + dir.mkdir("cap"); + ASSERT_TRUE(dir.cd("cap")); + ASSERT_TRUE(dir.exists()); + DCapManager::instance()->removePath("/tmp"); + DCapManager::instance()->appendPath(dir.path()); + ASSERT_FALSE(dir.cd("..")); + dir.setPath("/tmp"); + + ASSERT_TRUE(dir.entryList().isEmpty()); + ASSERT_TRUE(dir.entryInfoList().isEmpty()); + ASSERT_TRUE(dir.exists("cap")); + ASSERT_FALSE(dir.remove("test0")); + ASSERT_FALSE(dir.rename("test0", "test1")); + + ASSERT_TRUE(dir.mkpath(TMPCAP_PATH"/subdir")); + ASSERT_TRUE(dir.rmpath(TMPCAP_PATH"/subdir")); + + DCapManager::instance()->appendPath("/tmp"); + ASSERT_TRUE(dir.rename("test0", "test1")); + ASSERT_TRUE(dir.remove("test1")); +} diff -Nru dtkcore-5.5.33/tests/ut_dconfig.cpp dtkcore-5.6.2/tests/ut_dconfig.cpp --- dtkcore-5.5.33/tests/ut_dconfig.cpp 2022-07-19 09:10:28.000000000 +0000 +++ dtkcore-5.6.2/tests/ut_dconfig.cpp 2022-09-21 05:21:07.000000000 +0000 @@ -1,23 +1,6 @@ -/* - * Copyright (C) 2021 Uniontech Technology Co., Ltd. - * - * Author: yeshanshan - * - * Maintainer: yeshanshan - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * 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 Lesser General Public License - * along with this program. If not, see . - */ +// SPDX-FileCopyrightText: 2021 - 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later #include #include @@ -29,9 +12,9 @@ DCORE_USE_NAMESPACE +static EnvGuard dsgDataDir; static constexpr char const *APP_ID = "tests"; static constexpr char const *FILE_NAME = "example"; -static EnvGuard dsgDataDir; class ut_DConfig : public testing::Test { protected: diff -Nru dtkcore-5.5.33/tests/ut_dconfigfile.cpp dtkcore-5.6.2/tests/ut_dconfigfile.cpp --- dtkcore-5.5.33/tests/ut_dconfigfile.cpp 2022-07-19 09:10:28.000000000 +0000 +++ dtkcore-5.6.2/tests/ut_dconfigfile.cpp 2022-09-21 05:21:07.000000000 +0000 @@ -1,23 +1,6 @@ -/* - * Copyright (C) 2021 Uniontech Technology Co., Ltd. - * - * Author: zccrs - * - * Maintainer: zccrs - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * 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 Lesser General Public License - * along with this program. If not, see . - */ +// SPDX-FileCopyrightText: 2021 - 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later #include #include diff -Nru dtkcore-5.5.33/tests/ut_ddci.cpp dtkcore-5.6.2/tests/ut_ddci.cpp --- dtkcore-5.5.33/tests/ut_ddci.cpp 1970-01-01 00:00:00.000000000 +0000 +++ dtkcore-5.6.2/tests/ut_ddci.cpp 2022-09-21 05:21:07.000000000 +0000 @@ -0,0 +1,447 @@ +// SPDX-FileCopyrightText: 2021 - 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later + +#include + +#include +#include +#include +#include +#include +#include + +#include + +DCORE_USE_NAMESPACE + +class ut_DCI : public testing::Test { +public: + void SetUp() override { + QLoggingCategory::setFilterRules("dtk.dci.file.debug=true\n" + "dtk.dci.fileengine.debug=true"); + } +}; + +TEST_F(ut_DCI, DDciFile) { + { + // 空文件 + DDciFile dciFile; + ASSERT_TRUE(dciFile.isValid()); + ASSERT_TRUE(dciFile.exists("/")); + ASSERT_EQ(dciFile.list("/").count(), 0); + ASSERT_EQ(dciFile.toData(), QByteArrayLiteral("DCI\0\1\0\0\0")); + } + + { + // 最小数据文件 + DDciFile dciFile(QByteArrayLiteral("DCI\0\1\0\0\0")); + ASSERT_TRUE(dciFile.isValid()); + ASSERT_TRUE(dciFile.exists("/")); + ASSERT_EQ(dciFile.list("/").count(), 0); + ASSERT_EQ(dciFile.toData(), QByteArrayLiteral("DCI\0\1\0\0\0")); + } + + { + // 错误的版本 + DDciFile dciFile(QByteArrayLiteral("DCI\0\0\0\0\0")); + ASSERT_FALSE(dciFile.isValid()); + } + + { + // 错误的文件数量 + DDciFile dciFile(QByteArrayLiteral("DCI\0\1\255\255\255")); + ASSERT_FALSE(dciFile.isValid()); + } + + { + // 创建目录 + DDciFile dciFile; + ASSERT_TRUE(dciFile.mkdir("/test")); + ASSERT_TRUE(dciFile.exists("/test")); + ASSERT_EQ(dciFile.list("/"), QStringList{"/test"}); + ASSERT_EQ(dciFile.childrenCount("/"), 1); + } + + { + // 创建目录 + DDciFile dciFile; + ASSERT_TRUE(dciFile.mkdir("/test")); + ASSERT_TRUE(dciFile.exists("/test")); + ASSERT_EQ(dciFile.list("/"), QStringList{"/test"}); + ASSERT_EQ(dciFile.type("/test"), DDciFile::Directory); + ASSERT_EQ(dciFile.childrenCount("/"), 1); + + // 创建文件 + ASSERT_TRUE(dciFile.writeFile("/test/test.txt", "test\n")); + ASSERT_TRUE(dciFile.exists("/test/test.txt")); + ASSERT_EQ(dciFile.list("/test"), QStringList{"/test/test.txt"}); + ASSERT_EQ(dciFile.childrenCount("/test"), 1); + ASSERT_EQ(dciFile.type("/test/test.txt"), DDciFile::File); + ASSERT_EQ(dciFile.dataRef("/test/test.txt"), QByteArray("test\n")); + + // 软链接 + // 链接一个不存在的文件 + ASSERT_TRUE(dciFile.link("/no", "/1.link")); + ASSERT_TRUE(dciFile.exists("/1.link")); + ASSERT_EQ(dciFile.type("/1.link"), DDciFile::Symlink); + ASSERT_EQ(dciFile.symlinkTarget("/1.link"), "/no"); + ASSERT_EQ(dciFile.symlinkTarget("/1.link", true), "/no"); + // 当链接目标无效时,无论如何都不允许写入数据 + ASSERT_FALSE(dciFile.writeFile("/1.link", "", false)); + ASSERT_FALSE(dciFile.writeFile("/1.link", "", true)); + // 链接一个目录 + ASSERT_TRUE(dciFile.link("/test", "/2.link")); + ASSERT_TRUE(dciFile.symlinkTarget("/2.link").isEmpty()); + ASSERT_FALSE(dciFile.mkdir("/2.link/test")); + // 链接一个存在的文件 + ASSERT_TRUE(dciFile.link("/test/test.txt", "/3.link")); + ASSERT_EQ(dciFile.symlinkTarget("/3.link"), "/test/test.txt"); + ASSERT_EQ(dciFile.dataRef("/3.link"), QByteArray("test\n")); + ASSERT_TRUE(dciFile.writeFile("/3.link", "TEST", true)); + ASSERT_EQ(dciFile.dataRef("/test/test.txt"), QByteArray("TEST")); + // 相对路径链接 + ASSERT_TRUE(dciFile.link("./test/test.txt", "/4.link")); + ASSERT_EQ(dciFile.symlinkTarget("/4.link"), "/test/test.txt"); + ASSERT_EQ(dciFile.symlinkTarget("/4.link", true), "./test/test.txt"); + ASSERT_EQ(dciFile.dataRef("/4.link"), QByteArray("TEST")); + // 链接一个软链接,测试 ".." 类型的相对路径 + ASSERT_TRUE(dciFile.link("../4.link", "/test/5.link")); + ASSERT_EQ(dciFile.symlinkTarget("/test/5.link"), "/4.link"); + ASSERT_EQ(dciFile.symlinkTarget("/test/5.link", true), "../4.link"); + ASSERT_EQ(dciFile.dataRef("/test/5.link"), QByteArray("TEST")); + ASSERT_TRUE(dciFile.writeFile("/test/5.link", "test\n", true)); + ASSERT_EQ(dciFile.dataRef("/test/test.txt"), QByteArray("test\n")); + // 链接同目录文件 + ASSERT_TRUE(dciFile.link("test.txt", "/test/6.link")); + ASSERT_EQ(dciFile.dataRef("/test/6.link"), QByteArray("test\n")); + // 链接对象删除 + ASSERT_TRUE(dciFile.remove("/4.link")); + ASSERT_TRUE(dciFile.exists("/test/5.link")); + ASSERT_EQ(dciFile.symlinkTarget("/test/5.link"), "/4.link"); + ASSERT_TRUE(dciFile.dataRef("/test/5.link").isEmpty()); + ASSERT_FALSE(dciFile.writeFile("/test/5.link", "", true)); + // 链接对象改名 + ASSERT_TRUE(dciFile.rename("/test/6.link", "/test/7.link")); + ASSERT_EQ(dciFile.dataRef("/test/7.link"), QByteArray("test\n")); + // 链接对象更换目录 + ASSERT_TRUE(dciFile.rename("/test/7.link", "/7.link")); + ASSERT_EQ(dciFile.symlinkTarget("/7.link"), "/test.txt"); + ASSERT_TRUE(dciFile.dataRef("/7.link").isEmpty()); + + { + // 复制数据 + DDciFile dciFile2(dciFile.toData()); + ASSERT_TRUE(dciFile2.isValid()); + ASSERT_EQ(dciFile2.list("/"), dciFile.list("/")); + ASSERT_EQ(dciFile2.list("/test"), dciFile.list("/test")); + ASSERT_EQ(dciFile2.dataRef("/test/test.txt"), QByteArray("test\n")); + ASSERT_EQ(dciFile2.dataRef("/test/3.link"), + dciFile2.dataRef("/test/text.txt")); + ASSERT_EQ(dciFile.toData(), dciFile2.toData()); + } + + // 清理链接文件 + for (const QString &file : dciFile.list("/", false)) { + if (dciFile.type(file) == DDciFile::Symlink) + dciFile.remove(file); + } + for (const QString &file : dciFile.list("/test", false)) { + if (dciFile.type(file) == DDciFile::Symlink) + dciFile.remove(file); + } + + // 改写文件数据 + ASSERT_FALSE(dciFile.writeFile("/test/test.txt", "override the\"test.txt\"")); + ASSERT_TRUE(dciFile.writeFile("/test/test.txt", "override the\"test.txt\"", true)); + ASSERT_EQ(dciFile.dataRef("/test/test.txt"), "override the\"test.txt\""); + + // 文件删除 + ASSERT_TRUE(dciFile.remove("/test/test.txt")); + ASSERT_FALSE(dciFile.exists("/test/test.txt")); + ASSERT_EQ(dciFile.list("/test"), QStringList{}); + + // 目录删除 + ASSERT_TRUE(dciFile.writeFile("/test/test.txt", "")); + ASSERT_TRUE(dciFile.remove("/test")); + ASSERT_FALSE(dciFile.exists("/test")); + ASSERT_EQ(dciFile.list("/"), QStringList{}); + ASSERT_EQ(dciFile.toData(), QByteArrayLiteral("DCI\0\1\0\0\0")); + } + + { + DDciFile dciFile; + ASSERT_TRUE(dciFile.mkdir("/test")); + ASSERT_TRUE(dciFile.writeFile("/test.txt", "")); + + // 重命名 + ASSERT_TRUE(dciFile.rename("/test.txt", "/test/new_test.txt")); + ASSERT_TRUE(dciFile.exists("/test/new_test.txt")); + ASSERT_FALSE(dciFile.rename("/test.txt", "/test/new_test.txt")); + ASSERT_EQ(dciFile.list("/test", true), QStringList{"new_test.txt"}); + ASSERT_EQ(dciFile.list("/test"), QStringList{"/test/new_test.txt"}); + // override 重命名 + ASSERT_TRUE(dciFile.writeFile("/test.txt", "test", false)); + ASSERT_FALSE(dciFile.rename("/test.txt", "/test/new_test.txt", false)); + ASSERT_TRUE(dciFile.rename("/test.txt", "/test/new_test.txt", true)); + ASSERT_EQ(dciFile.dataRef("/test/new_test.txt"), "test"); + + // 文件清空 + ASSERT_TRUE(dciFile.remove("/")); + ASSERT_EQ(dciFile.list("/"), QStringList{}); + ASSERT_EQ(dciFile.childrenCount("/"), 0); + ASSERT_EQ(dciFile.toData(), QByteArrayLiteral("DCI\0\1\0\0\0")); + } + + // DDciFile::copy + { + DDciFile dciFile; + // 文件复制 + ASSERT_TRUE(dciFile.writeFile("/test.txt", "test")); + ASSERT_TRUE(dciFile.copy("/test.txt", "/test.txt.new")); + ASSERT_TRUE(dciFile.exists("/test.txt.new")); + ASSERT_EQ(dciFile.list("/", true), (QStringList{"test.txt", "test.txt.new"})); + ASSERT_EQ(dciFile.dataRef("/test.txt"), dciFile.dataRef("/test.txt.new")); + + // 目录复制 + ASSERT_TRUE(dciFile.mkdir("/test")); + ASSERT_TRUE(dciFile.rename("/test.txt", "/test/test.txt")); + ASSERT_TRUE(dciFile.copy("/test", "/test.new")); + ASSERT_TRUE(dciFile.exists("/test.new/test.txt")); + ASSERT_EQ(dciFile.list("/test.new", true), (QStringList{"test.txt"})); + ASSERT_EQ(dciFile.dataRef("/test/test.txt"), dciFile.dataRef("/test.new/test.txt")); + } + + // 文件排序 + { + DDciFile dciFile; + dciFile.mkdir("/b01"); + dciFile.writeFile("/a2.txt", ""); + dciFile.writeFile("/b2", ""); + dciFile.writeFile("/a11.txt", ""); + const auto &list = dciFile.list("/", true); + ASSERT_EQ(list, (QStringList{"a2.txt", "a11.txt", "b01", "b2"})); + + dciFile.writeFile("/b01/222", ""); + dciFile.link("/b01/33", "/b01/1111"); + dciFile.writeFile("/b01/33", ""); + ASSERT_EQ(dciFile.list("/b01", true), (QStringList{"33", "222", "1111"})); + + ASSERT_TRUE(dciFile.rename("/a11.txt", "/b01/200")); + ASSERT_TRUE(dciFile.copy("/a2.txt", "/b01/200.txt")); + ASSERT_EQ(dciFile.list("/", true), (QStringList{"a2.txt", "b01", "b2"})); + ASSERT_EQ(dciFile.list("/b01", true), (QStringList{"33", "200", "200.txt", "222", "1111"})); + } +} + +class TestDCIFileHelper { +public: + TestDCIFileHelper(const QString &fileName) + : fileName(fileName) + { + if (QFile::exists(fileName)) + QFile::remove(fileName); + } + ~TestDCIFileHelper() { + QFile::remove(fileName); + } + + inline QString dciFormatFilePath(const QString &subfile = QString()) const { + return "dci:" + fileName + subfile; + } + + inline QString sourceFileName() const { + return fileName; + } + +private: + QString fileName; +}; + +static QByteArray readAll(const QString &file) { + QFile f(file); + if (!f.open(QIODevice::ReadOnly)) + return {}; + return f.readAll(); +} + +TEST_F(ut_DCI, DFileEngine) { + DDciFile::registerFileEngine(); + + { + TestDCIFileHelper helper(QDir::temp().absoluteFilePath("test.dci")); + // 空 dci 文件创建 + QFile file(helper.dciFormatFilePath()); + ASSERT_TRUE(file.exists()); + QFileInfo info(file); + ASSERT_TRUE(info.isDir()); + ASSERT_TRUE(info.isRoot()); + // 文件夹不可写入 + ASSERT_FALSE(file.open(QIODevice::WriteOnly)); + // 空文件遍历 + QDir dir(info.absoluteFilePath()); + ASSERT_EQ(dir.entryList(), QStringList{}); + } + + { + TestDCIFileHelper helper(QDir::temp().absoluteFilePath("test.dci")); + { + // 内部文件创建 + QFile file(helper.dciFormatFilePath("/test.txt")); + ASSERT_FALSE(file.open(QIODevice::ReadOnly)); + ASSERT_TRUE(file.open(QIODevice::ReadOnly | QIODevice::WriteOnly)); + ASSERT_TRUE(file.exists()); + ASSERT_TRUE(QFileInfo(file).isFile()); + ASSERT_TRUE(file.write("Hello") == 5); + ASSERT_TRUE(file.seek(0)); + ASSERT_EQ(file.readAll(), "Hello"); + ASSERT_TRUE(file.flush()); + // 链接文件创建,绝对路径链接 + ASSERT_TRUE(file.link(helper.dciFormatFilePath("/test.txt.link"))); + { + QFile linkFile(helper.dciFormatFilePath("/test.txt.link")); + ASSERT_TRUE(QFileInfo(linkFile).isSymLink()); + ASSERT_EQ(linkFile.symLinkTarget(), "/test.txt"); + ASSERT_TRUE(linkFile.open(QIODevice::ReadOnly)); + ASSERT_EQ(linkFile.readAll(), "Hello"); + ASSERT_EQ(linkFile.size(), file.size()); + } + + file.close(); + + // 文件信息 + QFileInfo info1(file); + QFileInfo info2(helper.sourceFileName()); + ASSERT_FALSE(info1.isRoot()); + ASSERT_EQ(info1.permissions(), info2.permissions()); + ASSERT_EQ(info1.fileTime(QFile::FileAccessTime), + info2.fileTime(QFile::FileAccessTime)); + ASSERT_EQ(info1.fileTime(QFile::FileBirthTime), + info2.fileTime(QFile::FileBirthTime)); + ASSERT_EQ(info1.fileTime(QFile::FileMetadataChangeTime), + info2.fileTime(QFile::FileMetadataChangeTime)); + ASSERT_EQ(info1.fileTime(QFile::FileModificationTime), + info2.fileTime(QFile::FileModificationTime)); + ASSERT_EQ(info1.ownerId(), info2.ownerId()); + ASSERT_EQ(info1.owner(), info2.owner()); + ASSERT_EQ(info1.groupId(), info2.groupId()); + ASSERT_EQ(info1.group(), info2.group()); + + // 目录遍历 + QDir dir(helper.dciFormatFilePath()); + ASSERT_EQ(dir.entryList(), (QStringList{"test.txt", "test.txt.link"})); + + // 文件大小 + ASSERT_EQ(file.size(), 5); + ASSERT_TRUE(file.resize(10)); + ASSERT_EQ(file.size(), 10); + ASSERT_EQ(QFile(helper.dciFormatFilePath("/test.txt.link")).size(), 10); + } + + { + // 文件读取 + QFile file(helper.dciFormatFilePath("/test.txt")); + ASSERT_TRUE(file.exists()); + ASSERT_TRUE(file.open(QIODevice::ReadOnly)); + ASSERT_EQ(file.readAll(), QByteArrayLiteral("Hello\0\0\0\0\0")); + file.close(); + // [/test.txt, /test.txt.link] + } + + { + // 文件内容改写 + QFile file(helper.dciFormatFilePath("/test.txt")); + ASSERT_TRUE(file.open(QIODevice::ReadWrite)); + ASSERT_TRUE(file.seek(1)); + ASSERT_TRUE(file.putChar('E')); + char ch; + ASSERT_TRUE(file.getChar(&ch)); + ASSERT_EQ(ch, 'l'); + ASSERT_EQ(file.readAll(), QByteArrayLiteral("lo\0\0\0\0\0")); + ASSERT_TRUE(file.seek(0)); + ASSERT_EQ(file.readAll(), QByteArrayLiteral("HEllo\0\0\0\0\0")); + ASSERT_EQ(readAll(helper.dciFormatFilePath("/test.txt.link")), + QByteArrayLiteral("HEllo\0\0\0\0\0")); + } + + // 目录创建 + ASSERT_TRUE(QDir(helper.dciFormatFilePath()).mkdir("1")); + ASSERT_FALSE(QDir(helper.dciFormatFilePath()).mkdir("2/3")); + ASSERT_TRUE(QDir(helper.dciFormatFilePath()).mkpath("2/3")); + ASSERT_TRUE(QFileInfo(helper.dciFormatFilePath("/1")).isDir()); + // [/test.txt, /test.txt.link, /1, /2, /2/3] + + // 目录 rename + ASSERT_FALSE(QFile::rename(helper.dciFormatFilePath("/1"), "/1")); + ASSERT_TRUE(QFile::rename(helper.dciFormatFilePath("/1"), + helper.dciFormatFilePath("/1.new"))); + ASSERT_TRUE(QFile::rename(helper.dciFormatFilePath("/2"), + helper.dciFormatFilePath("/2.new"))); + ASSERT_TRUE(QFile::rename(helper.dciFormatFilePath("/2.new/3"), + helper.dciFormatFilePath("/3"))); + // [/test.txt, /test.txt.link, /1.new, /2.new, /3] + + // 文件 rename + ASSERT_TRUE(QFile::rename(helper.dciFormatFilePath("/test.txt"), + helper.dciFormatFilePath("/test.txt.new"))); + ASSERT_TRUE(QFile::rename(helper.dciFormatFilePath("/test.txt.new"), + helper.dciFormatFilePath("/1.new/test.txt"))); + // [/1.new, /1.new/test.txt.new, /test.txt.link, /2.new, /3] + // 此时的 link file 应该无效 + ASSERT_TRUE(readAll(helper.dciFormatFilePath("/test.txt.link")).isEmpty()); + // 链接文件 rename + ASSERT_TRUE(QFile::rename(helper.dciFormatFilePath("/test.txt.link"), + helper.dciFormatFilePath("/1.new/test.txt.link"))); + + // 复制 + ASSERT_TRUE(QFile::copy(helper.dciFormatFilePath("/1.new/test.txt"), + helper.dciFormatFilePath("/test.txt"))); + // 链接文件复制 + ASSERT_TRUE(QFile::copy(helper.dciFormatFilePath("/1.new/test.txt.link"), + helper.dciFormatFilePath("/test.txt.link"))); + // 检查复制/rename后的链接文件 + ASSERT_EQ(QFile(helper.dciFormatFilePath("/test.txt.link")).symLinkTarget(), + QStringLiteral("/test.txt")); + ASSERT_EQ(readAll(helper.dciFormatFilePath("/test.txt.link")), + readAll(helper.dciFormatFilePath("/test.txt"))); + ASSERT_EQ(QFile(helper.dciFormatFilePath("/1.new/test.txt.link")).symLinkTarget(), + QStringLiteral("/test.txt")); + ASSERT_EQ(readAll(helper.dciFormatFilePath("/1.new/test.txt.link")), + readAll(helper.dciFormatFilePath("/test.txt"))); + // 复制目录 + ASSERT_TRUE(QFile::copy(helper.dciFormatFilePath("/1.new"), + helper.dciFormatFilePath("/1"))); + ASSERT_EQ(QDir(helper.dciFormatFilePath("/1")).entryList(), + QDir(helper.dciFormatFilePath("/1.new")).entryList()); + // [/1.new, /1.new/test.txt, /1.new/test.txt.link, /2.new, /3, /test.txt, /test.txt.link, /1] + + // 目录遍历 + QStringList list { + helper.dciFormatFilePath("/1"), + helper.dciFormatFilePath("/1/test.txt.link"), + helper.dciFormatFilePath("/1/test.txt"), + helper.dciFormatFilePath("/1.new"), + helper.dciFormatFilePath("/1.new/test.txt"), + helper.dciFormatFilePath("/1.new/test.txt.link"), + helper.dciFormatFilePath("/2.new"), + helper.dciFormatFilePath("/3"), + helper.dciFormatFilePath("/test.txt"), + helper.dciFormatFilePath("/test.txt.link") + }; + QDirIterator di(helper.dciFormatFilePath(), QDirIterator::Subdirectories); + while (di.hasNext()) { + const QString &file = di.next(); + ASSERT_TRUE(list.removeOne(file)); + } + ASSERT_TRUE(list.isEmpty()); + + // 删除 + ASSERT_TRUE(QFile::remove(helper.dciFormatFilePath("/test.txt"))); + ASSERT_TRUE(QFile::remove(helper.dciFormatFilePath("/test.txt.link"))); + ASSERT_TRUE(QFile::remove(helper.dciFormatFilePath("/2.new"))); + ASSERT_TRUE(QFile::remove(helper.dciFormatFilePath("/1.new"))); + // [/3] + ASSERT_EQ(QDir(helper.dciFormatFilePath()).entryList(), + (QStringList {"1", "3"})); + } +} diff -Nru dtkcore-5.5.33/tests/ut_ddesktopentrytest.cpp dtkcore-5.6.2/tests/ut_ddesktopentrytest.cpp --- dtkcore-5.5.33/tests/ut_ddesktopentrytest.cpp 2022-07-19 09:10:28.000000000 +0000 +++ dtkcore-5.6.2/tests/ut_ddesktopentrytest.cpp 2022-09-21 05:21:07.000000000 +0000 @@ -1,24 +1,6 @@ -/* - * Copyright (C) 2019 Deepin Technology Co., Ltd. - * 2019 Gary Wang - * - * Author: Gary Wang - * - * Maintainer: Gary Wang - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * 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 Lesser General Public License - * along with this program. If not, see . - */ +// SPDX-FileCopyrightText: 2019 - 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later #include #include diff -Nru dtkcore-5.5.33/tests/ut_ddisksizeformatter.cpp dtkcore-5.6.2/tests/ut_ddisksizeformatter.cpp --- dtkcore-5.5.33/tests/ut_ddisksizeformatter.cpp 2022-07-19 09:10:28.000000000 +0000 +++ dtkcore-5.6.2/tests/ut_ddisksizeformatter.cpp 2022-09-21 05:21:07.000000000 +0000 @@ -1,23 +1,6 @@ -/* - * Copyright (C) 2021 ~ 2021 Deepin Technology Co., Ltd. - * - * Author: Wang Fei - * - * Maintainer: Wang Fei - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * 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 Lesser General Public License - * along with this program. If not, see . - */ +// SPDX-FileCopyrightText: 2021 - 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later #include #include "util/ddisksizeformatter.h" diff -Nru dtkcore-5.5.33/tests/ut_dfilesystemwatcher.cpp dtkcore-5.6.2/tests/ut_dfilesystemwatcher.cpp --- dtkcore-5.5.33/tests/ut_dfilesystemwatcher.cpp 2022-07-19 09:10:28.000000000 +0000 +++ dtkcore-5.6.2/tests/ut_dfilesystemwatcher.cpp 2022-09-21 05:21:07.000000000 +0000 @@ -1,23 +1,6 @@ -/* - * Copyright (C) 2021 ~ 2021 Deepin Technology Co., Ltd. - * - * Author: Wang Fei - * - * Maintainer: Wang Fei - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * 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 Lesser General Public License - * along with this program. If not, see . - */ +// SPDX-FileCopyrightText: 2021 - 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later #include #include diff -Nru dtkcore-5.5.33/tests/ut_dfilewatcher.cpp dtkcore-5.6.2/tests/ut_dfilewatcher.cpp --- dtkcore-5.5.33/tests/ut_dfilewatcher.cpp 2022-07-19 09:10:28.000000000 +0000 +++ dtkcore-5.6.2/tests/ut_dfilewatcher.cpp 2022-09-21 05:21:07.000000000 +0000 @@ -1,23 +1,6 @@ -/* - * Copyright (C) 2021 ~ 2021 Deepin Technology Co., Ltd. - * - * Author: Wang Fei - * - * Maintainer: Wang Fei - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * 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 Lesser General Public License - * along with this program. If not, see . - */ +// SPDX-FileCopyrightText: 2021 - 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later #include #include diff -Nru dtkcore-5.5.33/tests/ut_dfilewatchermanager.cpp dtkcore-5.6.2/tests/ut_dfilewatchermanager.cpp --- dtkcore-5.5.33/tests/ut_dfilewatchermanager.cpp 2022-07-19 09:10:28.000000000 +0000 +++ dtkcore-5.6.2/tests/ut_dfilewatchermanager.cpp 2022-09-21 05:21:07.000000000 +0000 @@ -1,23 +1,6 @@ -/* - * Copyright (C) 2021 ~ 2021 Deepin Technology Co., Ltd. - * - * Author: Wang Fei - * - * Maintainer: Wang Fei - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * 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 Lesser General Public License - * along with this program. If not, see . - */ +// SPDX-FileCopyrightText: 2021 - 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later #include #include diff -Nru dtkcore-5.5.33/tests/ut_dpathbuf.cpp dtkcore-5.6.2/tests/ut_dpathbuf.cpp --- dtkcore-5.5.33/tests/ut_dpathbuf.cpp 2022-07-19 09:10:28.000000000 +0000 +++ dtkcore-5.6.2/tests/ut_dpathbuf.cpp 2022-09-21 05:21:07.000000000 +0000 @@ -1,23 +1,6 @@ -/* - * Copyright (C) 2021 ~ 2021 Deepin Technology Co., Ltd. - * - * Author: Wang Fei - * - * Maintainer: Wang Fei - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * 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 Lesser General Public License - * along with this program. If not, see . - */ +// SPDX-FileCopyrightText: 2021 - 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later #include #include diff -Nru dtkcore-5.5.33/tests/ut_dpinyin.cpp dtkcore-5.6.2/tests/ut_dpinyin.cpp --- dtkcore-5.5.33/tests/ut_dpinyin.cpp 2022-07-19 09:10:28.000000000 +0000 +++ dtkcore-5.6.2/tests/ut_dpinyin.cpp 2022-09-21 05:21:07.000000000 +0000 @@ -1,23 +1,6 @@ -/* - * Copyright (C) 2021 ~ 2021 Deepin Technology Co., Ltd. - * - * Author: Wang Fei - * - * Maintainer: Wang Fei - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * 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 Lesser General Public License - * along with this program. If not, see . - */ +// SPDX-FileCopyrightText: 2021 - 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later #include #include "util/dpinyin.h" diff -Nru dtkcore-5.5.33/tests/ut_drecentmanager.cpp dtkcore-5.6.2/tests/ut_drecentmanager.cpp --- dtkcore-5.5.33/tests/ut_drecentmanager.cpp 2022-07-19 09:10:28.000000000 +0000 +++ dtkcore-5.6.2/tests/ut_drecentmanager.cpp 2022-09-21 05:21:07.000000000 +0000 @@ -1,23 +1,6 @@ -/* - * Copyright (C) 2021 ~ 2021 Deepin Technology Co., Ltd. - * - * Author: Wang Fei - * - * Maintainer: Wang Fei - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * 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 Lesser General Public License - * along with this program. If not, see . - */ +// SPDX-FileCopyrightText: 2021 - 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later #include #include diff -Nru dtkcore-5.5.33/tests/ut_dsecurestring.cpp dtkcore-5.6.2/tests/ut_dsecurestring.cpp --- dtkcore-5.5.33/tests/ut_dsecurestring.cpp 2022-07-19 09:10:28.000000000 +0000 +++ dtkcore-5.6.2/tests/ut_dsecurestring.cpp 2022-09-21 05:21:07.000000000 +0000 @@ -1,23 +1,6 @@ -/* - * Copyright (C) 2021 ~ 2021 Deepin Technology Co., Ltd. - * - * Author: Wang Fei - * - * Maintainer: Wang Fei - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * 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 Lesser General Public License - * along with this program. If not, see . - */ +// SPDX-FileCopyrightText: 2021 - 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later #include #include "dsecurestring.h" diff -Nru dtkcore-5.5.33/tests/ut_dsettings.cpp dtkcore-5.6.2/tests/ut_dsettings.cpp --- dtkcore-5.5.33/tests/ut_dsettings.cpp 2022-07-19 09:10:28.000000000 +0000 +++ dtkcore-5.6.2/tests/ut_dsettings.cpp 2022-09-21 05:21:07.000000000 +0000 @@ -1,23 +1,6 @@ -/* - * Copyright (C) 2021 ~ 2021 Deepin Technology Co., Ltd. - * - * Author: Wang Fei - * - * Maintainer: Wang Fei - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * 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 Lesser General Public License - * along with this program. If not, see . - */ +// SPDX-FileCopyrightText: 2021 - 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later #include #include diff -Nru dtkcore-5.5.33/tests/ut_dstandardpaths.cpp dtkcore-5.6.2/tests/ut_dstandardpaths.cpp --- dtkcore-5.5.33/tests/ut_dstandardpaths.cpp 2022-07-19 09:10:28.000000000 +0000 +++ dtkcore-5.6.2/tests/ut_dstandardpaths.cpp 2022-09-21 05:21:07.000000000 +0000 @@ -1,23 +1,6 @@ -/* - * Copyright (C) 2021 ~ 2021 Deepin Technology Co., Ltd. - * - * Author: Wang Fei - * - * Maintainer: Wang Fei - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * 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 Lesser General Public License - * along with this program. If not, see . - */ +// SPDX-FileCopyrightText: 2021 - 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later #include #include diff -Nru dtkcore-5.5.33/tests/ut_dthreadutils.cpp dtkcore-5.6.2/tests/ut_dthreadutils.cpp --- dtkcore-5.5.33/tests/ut_dthreadutils.cpp 2022-07-19 09:10:28.000000000 +0000 +++ dtkcore-5.6.2/tests/ut_dthreadutils.cpp 2022-09-21 05:21:07.000000000 +0000 @@ -1,30 +1,13 @@ -/* - * Copyright (C) 2020 ~ 2020 Deepin Technology Co., Ltd. - * - * Author: zccrs - * - * Maintainer: zccrs - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * 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 Lesser General Public License - * along with this program. If not, see . - */ +// SPDX-FileCopyrightText: 2020 - 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later #include #include #include #include -#include +#include DCORE_USE_NAMESPACE diff -Nru dtkcore-5.5.33/tests/ut_dtimeunitformatter.cpp dtkcore-5.6.2/tests/ut_dtimeunitformatter.cpp --- dtkcore-5.5.33/tests/ut_dtimeunitformatter.cpp 2022-07-19 09:10:28.000000000 +0000 +++ dtkcore-5.6.2/tests/ut_dtimeunitformatter.cpp 2022-09-21 05:21:07.000000000 +0000 @@ -1,23 +1,6 @@ -/* - * Copyright (C) 2021 ~ 2021 Deepin Technology Co., Ltd. - * - * Author: Wang Fei - * - * Maintainer: Wang Fei - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * 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 Lesser General Public License - * along with this program. If not, see . - */ +// SPDX-FileCopyrightText: 2021 - 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later #include #include "util/dtimeunitformatter.h" diff -Nru dtkcore-5.5.33/tests/ut_dtrashmanager.cpp dtkcore-5.6.2/tests/ut_dtrashmanager.cpp --- dtkcore-5.5.33/tests/ut_dtrashmanager.cpp 2022-07-19 09:10:28.000000000 +0000 +++ dtkcore-5.6.2/tests/ut_dtrashmanager.cpp 2022-09-21 05:21:07.000000000 +0000 @@ -1,23 +1,6 @@ -/* - * Copyright (C) 2021 ~ 2021 Deepin Technology Co., Ltd. - * - * Author: Wang Fei - * - * Maintainer: Wang Fei - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * 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 Lesser General Public License - * along with this program. If not, see . - */ +// SPDX-FileCopyrightText: 2021 - 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later #include #include diff -Nru dtkcore-5.5.33/tests/ut_dutil.cpp dtkcore-5.6.2/tests/ut_dutil.cpp --- dtkcore-5.5.33/tests/ut_dutil.cpp 2022-07-19 09:10:28.000000000 +0000 +++ dtkcore-5.6.2/tests/ut_dutil.cpp 2022-09-21 05:21:07.000000000 +0000 @@ -1,19 +1,6 @@ -/* - * Copyright (C) 2017 ~ 2017 Deepin Technology Co., Ltd. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * 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 Lesser General Public License - * along with this program. If not, see . - */ +// SPDX-FileCopyrightText: 2017 - 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later #include "ut_dutil.h" diff -Nru dtkcore-5.5.33/tests/ut_dutil.h dtkcore-5.6.2/tests/ut_dutil.h --- dtkcore-5.5.33/tests/ut_dutil.h 2022-07-19 09:10:28.000000000 +0000 +++ dtkcore-5.6.2/tests/ut_dutil.h 2022-09-21 05:21:07.000000000 +0000 @@ -1,19 +1,6 @@ -/* - * Copyright (C) 2017 ~ 2017 Deepin Technology Co., Ltd. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * 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 Lesser General Public License - * along with this program. If not, see . - */ +// SPDX-FileCopyrightText: 2017 - 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later #pragma once diff -Nru dtkcore-5.5.33/tests/ut_dvtablehook.cpp dtkcore-5.6.2/tests/ut_dvtablehook.cpp --- dtkcore-5.5.33/tests/ut_dvtablehook.cpp 2022-07-19 09:10:28.000000000 +0000 +++ dtkcore-5.6.2/tests/ut_dvtablehook.cpp 2022-09-21 05:21:07.000000000 +0000 @@ -1,26 +1,9 @@ -/* - * Copyright (C) 2019 ~ 2019 Deepin Technology Co., Ltd. - * - * Author: zccrs - * - * Maintainer: zccrs - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * 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 Lesser General Public License - * along with this program. If not, see . - */ +// SPDX-FileCopyrightText: 2019 - 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later #include -#include +#include namespace TestClass { class A diff -Nru dtkcore-5.5.33/tests/ut_gsettingsbackend.cpp dtkcore-5.6.2/tests/ut_gsettingsbackend.cpp --- dtkcore-5.5.33/tests/ut_gsettingsbackend.cpp 2022-07-19 09:10:28.000000000 +0000 +++ dtkcore-5.6.2/tests/ut_gsettingsbackend.cpp 2022-09-21 05:21:07.000000000 +0000 @@ -1,23 +1,6 @@ -/* - * Copyright (C) 2021 ~ 2021 Deepin Technology Co., Ltd. - * - * Author: Wang Fei - * - * Maintainer: Wang Fei - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * 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 Lesser General Public License - * along with this program. If not, see . - */ +// SPDX-FileCopyrightText: 2021 - 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later #include #include diff -Nru dtkcore-5.5.33/tests/ut_logger.cpp dtkcore-5.6.2/tests/ut_logger.cpp --- dtkcore-5.5.33/tests/ut_logger.cpp 2022-07-19 09:10:28.000000000 +0000 +++ dtkcore-5.6.2/tests/ut_logger.cpp 2022-09-21 05:21:07.000000000 +0000 @@ -1,23 +1,6 @@ -/* - * Copyright (C) 2021 ~ 2021 Deepin Technology Co., Ltd. - * - * Author: Wang Fei - * - * Maintainer: Wang Fei - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * 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 Lesser General Public License - * along with this program. If not, see . - */ +// SPDX-FileCopyrightText: 2021 - 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later #include #include diff -Nru dtkcore-5.5.33/tests/ut_qsettingsbackend.cpp dtkcore-5.6.2/tests/ut_qsettingsbackend.cpp --- dtkcore-5.5.33/tests/ut_qsettingsbackend.cpp 2022-07-19 09:10:28.000000000 +0000 +++ dtkcore-5.6.2/tests/ut_qsettingsbackend.cpp 2022-09-21 05:21:07.000000000 +0000 @@ -1,23 +1,6 @@ -/* - * Copyright (C) 2021 ~ 2021 Deepin Technology Co., Ltd. - * - * Author: Wang Fei - * - * Maintainer: Wang Fei - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * 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 Lesser General Public License - * along with this program. If not, see . - */ +// SPDX-FileCopyrightText: 2021 - 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later #include #include diff -Nru dtkcore-5.5.33/tests/ut_singleton.cpp dtkcore-5.6.2/tests/ut_singleton.cpp --- dtkcore-5.5.33/tests/ut_singleton.cpp 2022-07-19 09:10:28.000000000 +0000 +++ dtkcore-5.6.2/tests/ut_singleton.cpp 2022-09-21 05:21:07.000000000 +0000 @@ -1,19 +1,6 @@ -/* - * Copyright (C) 2016 ~ 2017 Deepin Technology Co., Ltd. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * 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 Lesser General Public License - * along with this program. If not, see . - */ +// SPDX-FileCopyrightText: 2016 - 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later #include "ut_singleton.h" diff -Nru dtkcore-5.5.33/tests/ut_singleton.h dtkcore-5.6.2/tests/ut_singleton.h --- dtkcore-5.5.33/tests/ut_singleton.h 2022-07-19 09:10:28.000000000 +0000 +++ dtkcore-5.6.2/tests/ut_singleton.h 2022-09-21 05:21:07.000000000 +0000 @@ -1,19 +1,6 @@ -/* - * Copyright (C) 2016 ~ 2017 Deepin Technology Co., Ltd. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * 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 Lesser General Public License - * along with this program. If not, see . - */ +// SPDX-FileCopyrightText: 2016 - 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later #pragma once diff -Nru dtkcore-5.5.33/tools/CMakeLists.txt dtkcore-5.6.2/tools/CMakeLists.txt --- dtkcore-5.5.33/tools/CMakeLists.txt 1970-01-01 00:00:00.000000000 +0000 +++ dtkcore-5.6.2/tools/CMakeLists.txt 2022-09-21 05:21:07.000000000 +0000 @@ -0,0 +1,4 @@ +add_subdirectory(dci) +add_subdirectory(deepin-os-release) +add_subdirectory(qdbusxml2cpp) +add_subdirectory(settings) diff -Nru dtkcore-5.5.33/tools/dci/CMakeLists.txt dtkcore-5.6.2/tools/dci/CMakeLists.txt --- dtkcore-5.5.33/tools/dci/CMakeLists.txt 1970-01-01 00:00:00.000000000 +0000 +++ dtkcore-5.6.2/tools/dci/CMakeLists.txt 2022-09-21 05:21:07.000000000 +0000 @@ -0,0 +1,22 @@ +set(BIN_NAME dci) +set(CMAKE_EXPORT_COMPILE_COMMANDS ON) +find_package(Qt5 REQUIRED COMPONENTS Core) +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 + Qt5::Core +) +target_include_directories(${BIN_NAME} PUBLIC + ${Qt5Core_PRIVATE_INCLUDE_DIRS} + ../../include/ + ../../include/dci/ + ../../include/DtkCore/ + ../../include/base/ + ../../include/global/ +) +#end dci diff -Nru dtkcore-5.5.33/tools/dci/dci.pro dtkcore-5.6.2/tools/dci/dci.pro --- dtkcore-5.5.33/tools/dci/dci.pro 1970-01-01 00:00:00.000000000 +0000 +++ dtkcore-5.6.2/tools/dci/dci.pro 2022-09-21 05:21:07.000000000 +0000 @@ -0,0 +1,23 @@ +QT -= gui + +CONFIG += c++11 console +CONFIG -= app_bundle + +# You can make your code fail to compile if it uses deprecated APIs. +# In order to do so, uncomment the following line. +#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 + +DEFINES += DTK_NO_PROJECT + +# 支持从当前目录找到动态库 +mac { + QMAKE_RPATHDIR = "@executable_path" +} + +SOURCES += \ + main.cpp + +include($$PWD/../../src/dci/dci.pri) +INCLUDEPATH += $$PWD/../../src + +#不要依赖于 dtk 的其它任何文件,要确保能在 macox 上独立编译 diff -Nru dtkcore-5.5.33/tools/dci/main.cpp dtkcore-5.6.2/tools/dci/main.cpp --- dtkcore-5.5.33/tools/dci/main.cpp 1970-01-01 00:00:00.000000000 +0000 +++ dtkcore-5.6.2/tools/dci/main.cpp 2022-09-21 05:21:07.000000000 +0000 @@ -0,0 +1,177 @@ +// SPDX-FileCopyrightText: 2021 - 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later + +#include +#include +#include +#include +#include +#include +#include + +#include + +#include "dci/ddcifile.h" + +static QString getSymLinkTarget(const QString &file, const QString &originPath) { + char target[512] = {0}; + const auto ret = readlink(file.toLocal8Bit().constData(), target, 511); + if (ret <= 0) + return QString(); + QString tar = QByteArray(target, ret); + QString path = originPath; + if (originPath.endsWith('/')) + path = path.left(path.length() - 1); + if (tar.startsWith(path)) { + tar = tar.remove(0, path.length()); + } + return tar; +} + +static bool copyFilesToDci(DDciFile *dci, const QString &targetDir, const QString &sourceDir, const QString &originPath) { + QDir dir(sourceDir); + for (const auto &info : dir.entryInfoList(QDir::AllEntries | QDir::NoDotAndDotDot)) { + const QString &newFile = QDir(targetDir).filePath(info.fileName()); + if (info.isDir()) { + if (!dci->mkdir(newFile)) + return false; + if (!copyFilesToDci(dci, newFile, info.absoluteFilePath(), originPath)) + return false; + } else if (info.isSymLink()) { + if (!dci->link(getSymLinkTarget(info.absoluteFilePath(), originPath), newFile)) + return false; + } else if (info.isFile()) { + QFile file(info.absoluteFilePath()); + if (!file.open(QIODevice::ReadOnly)) + return false; + if (!dci->writeFile(newFile, file.readAll())) + return false; + } + } + + return true; +} + +QString cleanPath(const QString &path) { + return path.size() < 2 || !path.endsWith(QDir::separator()) ? path : path.chopped(1); +} + +bool createTo(const QString &sourceDir, const QString &targetDir) { + QFileInfo info(cleanPath(sourceDir)); + if (!info.isDir()) + return false; + + const QString &iconName = info.fileName(); + if (iconName.isEmpty()) { + printf("The icon name is not correctly resolved in the source path: \"%s\".\n", qPrintable(sourceDir)); + return false; + } + + const auto newFile = QDir(targetDir).filePath(iconName + ".dci"); + if (QFile::exists(newFile)) { + printf("The path \"%s\" already exists.\n", qPrintable(newFile)); + return false; + } + + DDciFile dci; + if (!copyFilesToDci(&dci, "/", sourceDir, sourceDir)) + return false; + + return dci.writeToFile(newFile); +} + +static bool copyFilesFromDci(const DDciFile *dci, const QString &targetDir, const QString &sourceDir) { + QDir target(targetDir); + for (const QString &file : dci->list(sourceDir)) { + const QString &newFileName = QFileInfo(file).fileName(); + const QString &newFilePath = target.filePath(newFileName); + const auto &type = dci->type(file); + if (type == DDciFile::Directory) { + if (!target.mkdir(newFileName)) + return false; + if (!copyFilesFromDci(dci, newFilePath, file)) + return false; + } else if (type == DDciFile::File) { + QFile newFile(newFilePath); + if (!newFile.open(QIODevice::WriteOnly)) + return false; + const auto &data = dci->dataRef(file); + if (newFile.write(data) != data.size()) + return false; + } else if (type == DDciFile::Symlink) { + if (!QFile::link(dci->symlinkTarget(file, true), newFilePath)) + return false; + } else { + return false; + } + } + + return true; +} + +bool exportTo(const QString &dciFile, const QString &targetDir) { + QFileInfo info(dciFile); + if (!info.isFile() || info.suffix() != "dci") + return false; + const QString &newDir = QDir(targetDir).filePath(info.baseName()); + if (QDir(newDir).exists()) + return false; + if (!QDir::current().mkdir(newDir)) + return false; + + DDciFile dci(dciFile); + if (!dci.isValid()) + return false; + + return copyFilesFromDci(&dci, newDir, "/"); +} + +int main(int argc, char *argv[]) +{ + QCoreApplication a(argc, argv); + + a.setOrganizationName("zccrs"); + a.setApplicationName("dci"); + a.setApplicationVersion("0.0.1"); + + QCommandLineParser commandParser; + commandParser.setApplicationDescription("DCI tool is a command tool that automatically packs and unpacks DCI directories.\n" + "If you have created an icon directory according to the correct DCI directory specification,\n" + "you can easily make the DCI icons with this tool.\n" + "The commands of DCI tools can be expressed as follows:\n" + "\t dci --create [target file path] [source directory path]\n" + "\t dci --export [target directory path] [source file path]\n" + "For example, the tool is used in the following ways: \n" + "\t dci --create ~/Desktop ~/Desktop/action_add\n" + "\t dci --export ~/Desktop ~/Desktop/action_add.dci\n"); + + auto options = QList { + QCommandLineOption("create", "Create the new dci files by the directorys", "targetDirectiry"), + QCommandLineOption("export", "Export the dci files to the directorys", "targetDirectory"), + }; + commandParser.addOptions(options); + commandParser.addPositionalArgument("sources", "The directorys of create or the dci files of export", + "[dir1 dir2...]/[file1 file2...]"); + commandParser.addHelpOption(); + commandParser.addVersionOption(); + commandParser.process(a); + + if (commandParser.isSet(options.at(0))) { + for (const QString &dir : commandParser.positionalArguments()) { + if (!createTo(dir, commandParser.value(options.at(0)))) { + printf("Failed on create dci file for \"%s\"\n", qPrintable(dir)); + } + } + } else if (commandParser.isSet(options.at(1))) { + for (const QString &dci : commandParser.positionalArguments()) { + if (!exportTo(dci, commandParser.value(options.at(1)))) { + printf("Failed on export the \"%s\" dci file\n", qPrintable(dci)); + } + } + } else { + commandParser.showHelp(-1); + } + + return 0; +} diff -Nru dtkcore-5.5.33/tools/deepin-os-release/CMakeLists.txt dtkcore-5.6.2/tools/deepin-os-release/CMakeLists.txt --- dtkcore-5.5.33/tools/deepin-os-release/CMakeLists.txt 1970-01-01 00:00:00.000000000 +0000 +++ dtkcore-5.6.2/tools/deepin-os-release/CMakeLists.txt 2022-09-21 05:21:07.000000000 +0000 @@ -0,0 +1,30 @@ +set(BIN_NAME deepin-os-release) +set(CMAKE_EXPORT_COMPILE_COMMANDS ON) +set(CMAKE_AUTOMOC ON) +find_package(Qt5 REQUIRED COMPONENTS Core) +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_link_libraries(${BIN_NAME} PRIVATE + Qt5::Core +) +target_include_directories(${BIN_NAME} PUBLIC + ${Qt5Core_PRIVATE_INCLUDE_DIRS} + ../../include/ + ../../include/dci/ + ../../include/DtkCore/ + ../../include/base/ + ../../include/global/ +) +install(TARGETS ${BIN_NAME} DESTINATION "${TOOL_INSTALL_DIR}") + +#end dci diff -Nru dtkcore-5.5.33/tools/deepin-os-release/main.cpp dtkcore-5.6.2/tools/deepin-os-release/main.cpp --- dtkcore-5.5.33/tools/deepin-os-release/main.cpp 2022-07-19 09:10:28.000000000 +0000 +++ dtkcore-5.6.2/tools/deepin-os-release/main.cpp 2022-09-21 05:21:07.000000000 +0000 @@ -1,23 +1,7 @@ -/* - * Copyright (C) 2017 ~ 2018 Deepin Technology Co., Ltd. - * - * Author: zccrs - * - * Maintainer: zccrs - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * 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 Lesser General Public License - * along with this program. If not, see . - */ +// SPDX-FileCopyrightText: 2017 - 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later + #include "dsysinfo.h" #include diff -Nru dtkcore-5.5.33/tools/qdbusxml2cpp/CMakeLists.txt dtkcore-5.6.2/tools/qdbusxml2cpp/CMakeLists.txt --- dtkcore-5.5.33/tools/qdbusxml2cpp/CMakeLists.txt 1970-01-01 00:00:00.000000000 +0000 +++ dtkcore-5.6.2/tools/qdbusxml2cpp/CMakeLists.txt 2022-09-21 05:21:07.000000000 +0000 @@ -0,0 +1,20 @@ +set(BIN_NAME qdbusxml2cpp-fix) + +set(CMAKE_CXX_STANDARD 11) +set(CMAKE_EXPORT_COMPILE_COMMANDS ON) +find_package(Qt5 REQUIRED COMPONENTS Core) +find_package(Qt5 REQUIRED COMPONENTS DBus) + +add_executable(${BIN_NAME} + qdbusxml2cpp.cpp +) + +target_link_libraries( + ${BIN_NAME} PRIVATE + Qt5::DBus + Qt5::Core +) +target_include_directories(${BIN_NAME} PUBLIC + ${Qt5DBus_PRIVATE_INCLUDE_DIRS} +) +install(TARGETS ${BIN_NAME} DESTINATION ${CMAKE_INSTALL_BINDIR}) diff -Nru dtkcore-5.5.33/tools/qdbusxml2cpp/qdbusxml2cpp.cpp dtkcore-5.6.2/tools/qdbusxml2cpp/qdbusxml2cpp.cpp --- dtkcore-5.5.33/tools/qdbusxml2cpp/qdbusxml2cpp.cpp 2022-07-19 09:10:28.000000000 +0000 +++ dtkcore-5.6.2/tools/qdbusxml2cpp/qdbusxml2cpp.cpp 2022-09-21 05:21:07.000000000 +0000 @@ -1,35 +1,6 @@ -/**************************************************************************** -** -** Copyright (C) 2015 The Qt Company Ltd. -** Contact: http://www.qt.io/licensing/ -** -** This file is part of the tools applications of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL21$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see http://www.qt.io/terms-conditions. For further -** information use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 or version 3 as published by the Free -** Software Foundation and appearing in the file LICENSE.LGPLv21 and -** LICENSE.LGPLv3 included in the packaging of this file. Please review the -** following information to ensure the GNU Lesser General Public License -** requirements will be met: https://www.gnu.org/licenses/lgpl.html and -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** As a special exception, The Qt Company gives you certain additional -** rights. These rights are described in The Qt Company LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// SPDX-FileCopyrightText: 2016 - 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later #include #include diff -Nru dtkcore-5.5.33/tools/script/dtk-license.py dtkcore-5.6.2/tools/script/dtk-license.py --- dtkcore-5.5.33/tools/script/dtk-license.py 2022-07-19 09:10:28.000000000 +0000 +++ dtkcore-5.6.2/tools/script/dtk-license.py 1970-01-01 00:00:00.000000000 +0000 @@ -1,320 +0,0 @@ -#!/usr/bin/env python3 - -import fnmatch -import os -import argparse -import re -import datetime - - -license_header = '''/*\n''' -license_empty = ''' *\n''' -license_copyright_prifix = ''' * Copyright (C) {0}\n''' -license_copyright_indent = ''' * {0}\n''' -license_author_prifix = ''' * Author: {0}\n''' -license_person_indent = ''' * {0}\n''' -license_maintainer_prifix = ''' * Maintainer: {0}\n''' -license_tail = ''' */\n\n''' -default_license_body = ''' * 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 - * 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 . -''' - - -def isInt(value): - try: - int(value) - return True - except ValueError: - return False - - -class Copyright: - def __init__(self, line): - self.year_start = datetime.datetime.now().year - self.year_end = datetime.datetime.now().year - - if "copyright" in line.lower(): - line = line[re.search("copyright", line, re.IGNORECASE).end():] - - copyright_sysbol = re.search("\(.\)", line, re.IGNORECASE) - if copyright_sysbol is not None: - copyright_brace_end_pos = copyright_sysbol.end() - line = line[copyright_brace_end_pos:] - pass - - if re.search("[0-9]+", line) is not None: - year_start_pos = re.search("[0-9]+", line).start() - year_start_end_pos = re.search("[0-9]+", line).end() - self.year_start = int(line[year_start_pos: year_start_end_pos]) - line = line[year_start_end_pos:] - - if re.search("[0-9]+", line) is not None: - year_end_pos = re.search("[0-9]+", line).start() - year_end_end_pos = re.search("[0-9]+", line).end() - if re.search("~", line) is not None: - year_spilt = re.search("~", line).start() - if (year_spilt < year_end_pos): - self.year_end = int(line[year_end_pos: year_end_end_pos]) - line = line[year_end_end_pos:] - - self.name = line.strip() - - def string(self): - return "{0} ~ {1} {2}".format( - self.year_start, - self.year_end, - self.name) - - -class Person: - def __init__(self, line): - if re.search(":", line, re.IGNORECASE) is not None: - split_end = re.search(":", line).end() - line = line[split_end:] - - self.name = line.strip() - - -def filter_files(file_list, ext_list): - for file in file_list: - for ext in ext_list: - if fnmatch.fnmatch(file, ext): - yield file - break - - -class Source: - def __init__(self, filename): - self.body = [] - self.copyrights = {} - self.authors = {} - self.maintainers = {} - self.filename = filename - self.is_deepin_copyright = False - self.update_license(filename) - - def update_license(self, filename): - find_license_start = False - find_license_end = False - - parse_copyright_start = False - parse_author_start = False - parse_maintainer_start = False - - with open(filename, "r") as f: - print("process:", filename) - for line in f: - if line.strip().startswith("/*") and (0 == len(self.body)): - find_license_start = True - - if (0 != len(self.body)) or (0 != len(line.strip())): - self.body.append(line) - - if "*/" in line.strip() and find_license_start: - if not find_license_end: - # print("clean body") - self.body = [] - find_license_end = True - - if find_license_start and not find_license_end: - if re.search("(\*)+", line): - # remove ***** - line = line[re.search("(\*)+", line).end():] - - if "copyright" in line.lower(): - parse_copyright_start = True - parse_author_start = False - parse_maintainer_start = False - if "author" in line.lower(): - parse_copyright_start = False - parse_author_start = True - parse_maintainer_start = False - if "maintainer" in line.lower(): - parse_copyright_start = False - parse_author_start = False - parse_maintainer_start = True - if 0 == len(line.strip()): - parse_copyright_start = False - parse_author_start = False - parse_maintainer_start = False - - if parse_copyright_start: - cr = Copyright(line) - self.copyrights[cr.name] = cr - - if parse_author_start: - p = Person(line) - self.authors[p.name] = p - - if parse_maintainer_start: - p = Person(line) - self.maintainers[p.name] = p - - def fix_deepin(self): - new_cr = {} - self.is_deepin_copyright = False - for k, cr in self.copyrights.items(): - if "deepin" in cr.name.lower(): - cr.name = "Deepin Technology Co., Ltd." - self.is_deepin_copyright = True - new_cr[cr.name] = cr - self.copyrights = new_cr - - def dump(self): - for cr in self.copyrights: - print(cr.year_start, cr.year_end, cr.name) - for a in self.authors: - print(a.name) - for a in self.maintainers: - print(a.name) - print("body size:", len(self.body)) - - def save(self): - wf = open(self.filename, 'w') - wf.write(license_header) - - if len(self.copyrights): - write_first = False - for k, cr in self.copyrights.items(): - if not write_first: - wf.write(license_copyright_prifix.format(cr.string())) - write_first = True - else: - wf.write(license_copyright_indent.format(cr.string())) - wf.write(license_empty) - - if len(self.authors): - write_first = False - for k, author in self.authors.items(): - if not write_first: - wf.write(license_author_prifix.format(author.name)) - write_first = True - else: - wf.write(license_person_indent.format(author.name)) - wf.write(license_empty) - - if len(self.maintainers): - write_first = False - for k, maintainer in self.maintainers.items(): - if not write_first: - wf.write(license_maintainer_prifix.format(maintainer.name)) - write_first = True - else: - wf.write(license_person_indent.format(maintainer.name)) - wf.write(license_empty) - - wf.write(default_license_body) - wf.write(license_tail) - - for l in self.body: - wf.write(l) - wf.close() - - -def parse_args(): - parser = argparse.ArgumentParser() - parser.add_argument('--authors', help='''authors split by ":". For example:\n - "Iceyer :Li He "''') - parser.add_argument('--maintainers', help='''maintainers split by ":". For example: \n - "Iceyer :Li He "''') - parser.add_argument('--copyrights', help='''copyrights split by ":". For example: \n - "2011 ~ 2017 Deepin Technology Co., Ltd.:2011 ~ 2017 Li He"''') - parser.add_argument('--fix-deepin', dest='fixdeepin', - action='store_const', const=True, default=False, help=''' - fix deein copyrights''') - parser.add_argument('dir', help=''' - source code dir''') - - args = parser.parse_args() - return args - - -def match_files(dir): - EXTENSIONS = "*.cpp", "*.c", "*.h", "*.go" - matches = [] - for root, dirnames, filenames in os.walk(dir): - for filename in filter_files(filenames, EXTENSIONS): - matches.append(os.path.join(root, filename)) - return matches - - -def test(): - cr = Copyright("Copyright (C) Deepin Technology Co., Ltd.") - print(cr.year_start, cr.year_end, cr.name) - cr = Copyright("Copyright (C) 2007 Deepin Technology Co., Ltd.") - print(cr.year_start, cr.year_end, cr.name) - cr = Copyright("Copyright (C) 2007 ~ 2016 Deepin Technology Co., Ltd.") - print(cr.year_start, cr.year_end, cr.name) - - p = Person("Author: Wang Yong ") - print(p.name) - p = Person(" Wang Yong ") - print(p.name) - - -def get_authors(args): - authors = [] - if args.authors is not None: - for a in args.authors.split(":"): - authors.append(Person(a)) - return authors - - -def get_copyrights(args): - copyrights = [] - if args.copyrights is not None: - for a in args.copyrights.split(":"): - copyrights.append(Copyright(a)) - return copyrights - - -def get_maintainers(args): - maintainers = [] - if args.maintainers is not None: - for a in args.maintainers.split(":"): - maintainers.append(Copyright(a)) - return maintainers - - -def main(): - args = parse_args() - authors = get_authors(args) - copyrights = get_copyrights(args) - maintainers = get_maintainers(args) - fixdeepin = args.fixdeepin - files = match_files(args.dir) - - for filename in files: - s = Source(filename) - # s.dump() - if fixdeepin: - s.fix_deepin() - if not s.is_deepin_copyright and 0 != len(s.copyrights): - continue - - if 0 == len(s.copyrights): - for cr in copyrights: - s.copyrights[cr.name] = cr - - for p in authors: - s.authors[p.name] = p - - for p in maintainers: - s.maintainers[p.name] = p - - s.save() - # s.dump() - - -if __name__ == "__main__": - main() diff -Nru dtkcore-5.5.33/tools/script/dtk-translate.py dtkcore-5.6.2/tools/script/dtk-translate.py --- dtkcore-5.5.33/tools/script/dtk-translate.py 2022-07-19 09:10:28.000000000 +0000 +++ dtkcore-5.6.2/tools/script/dtk-translate.py 1970-01-01 00:00:00.000000000 +0000 @@ -1,18 +0,0 @@ -#!/usr/bin/env python3 - -import sys,os,fnmatch -from subprocess import call - -translations_dir = os.getcwd() + "/translations" -if (len(sys.argv) == 2): - translations_dir = sys.argv[1] + "/translations" - -print("set translations dir:", translations_dir) - -tslist = fnmatch.filter(os.listdir(translations_dir), '*.ts') - -# This would print all the files and directories -for tsfile in tslist: - tspath = translations_dir + "/" + tsfile - print ("process", tspath) - call(["lrelease", tspath]) diff -Nru dtkcore-5.5.33/tools/settings/CMakeLists.txt dtkcore-5.6.2/tools/settings/CMakeLists.txt --- dtkcore-5.5.33/tools/settings/CMakeLists.txt 1970-01-01 00:00:00.000000000 +0000 +++ dtkcore-5.6.2/tools/settings/CMakeLists.txt 2022-09-21 05:21:07.000000000 +0000 @@ -0,0 +1,29 @@ +set(BIN_NAME dtk-settings) + +find_package(Qt5 REQUIRED COMPONENTS Core) +find_package(Qt5 REQUIRED COMPONENTS Xml) +find_package(PkgConfig REQUIRED) +pkg_check_modules(QGSettings REQUIRED gsettings-qt) +add_executable(${BIN_NAME} + main.cpp +) +target_link_libraries( + ${BIN_NAME} PRIVATE + Qt5::Core + Qt5::Xml + dtkcore + ${QGSettings_LIBRARIES} +) +target_include_directories( ${BIN_NAME} PUBLIC + ${QGSettings_INCLUDE_DIRS} + ../../include/util/ + ../../include/dci/ + ../../include/log/ + ../../include/base/ + ../../include/global/ + ../../include/DtkCore/ + ../../include/settings/ + ../../include/filesystem/ + ../../include/ +) +install(TARGETS ${BIN_NAME} DESTINATION "${TOOL_INSTALL_DIR}") diff -Nru dtkcore-5.5.33/tools/settings/main.cpp dtkcore-5.6.2/tools/settings/main.cpp --- dtkcore-5.5.33/tools/settings/main.cpp 2022-07-19 09:10:28.000000000 +0000 +++ dtkcore-5.6.2/tools/settings/main.cpp 2022-09-21 05:21:07.000000000 +0000 @@ -1,19 +1,6 @@ -/* - * Copyright (C) 2017 ~ 2017 Deepin Technology Co., Ltd. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * 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 Lesser General Public License - * along with this program. If not, see . - */ +// SPDX-FileCopyrightText: 2017 - 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later #include diff -Nru dtkcore-5.5.33/tools/tools.pro dtkcore-5.6.2/tools/tools.pro --- dtkcore-5.5.33/tools/tools.pro 2022-07-19 09:10:28.000000000 +0000 +++ dtkcore-5.6.2/tools/tools.pro 1970-01-01 00:00:00.000000000 +0000 @@ -1,3 +0,0 @@ -TEMPLATE = subdirs - -!mac:!win*: SUBDIRS += settings deepin-os-release qdbusxml2cpp