From 357d2c68537283e40e901b30f1ca615bc2c61d9e Mon Sep 17 00:00:00 2001 From: deepin-ci-robot Date: Sat, 19 Oct 2024 13:41:00 +0000 Subject: [PATCH] sync: from linuxdeepin/dtkcore Synchronize source files from linuxdeepin/dtkcore. Source-pull-request: https://github.com/linuxdeepin/dtkcore/pull/440 --- dtkcore.cmake | 3 ++ src/dci/private/ddcifileengine.cpp | 34 +++++++++++++++++++++ src/dci/private/ddcifileengine_p.h | 13 ++++++++ src/filesystem/dcapfsfileengine.cpp | 15 +++++++++ src/filesystem/private/dcapfsfileengine_p.h | 8 +++++ src/log/LogManager.cpp | 2 ++ tests/CMakeLists.txt | 10 ------ 7 files changed, 75 insertions(+), 10 deletions(-) diff --git a/dtkcore.cmake b/dtkcore.cmake index 3a7307c..95c98d4 100644 --- a/dtkcore.cmake +++ b/dtkcore.cmake @@ -27,6 +27,9 @@ if(UNIX AND NOT APPLE) endif() set (BUILD_WITH_SYSTEMD OFF CACHE BOOL "Build with systemd") +if (BUILD_WITH_SYSTEMD) + add_definitions(-DBUILD_WITH_SYSTEMD) +endif() set(CMAKE_CXX_STANDARD 17) diff --git a/src/dci/private/ddcifileengine.cpp b/src/dci/private/ddcifileengine.cpp index bf2090d..49ffb18 100644 --- a/src/dci/private/ddcifileengine.cpp +++ b/src/dci/private/ddcifileengine.cpp @@ -30,14 +30,24 @@ Q_LOGGING_CATEGORY(logFE, "dtk.dci.fileengine", QtInfoMsg) #define DCI_FILE_SCHEME "dci:" #define DCI_FILE_SUFFIX ".dci" +#if QT_VERSION >= QT_VERSION_CHECK(6, 8 ,0) +std::unique_ptr DDciFileEngineHandler::create(const QString &fileName) const +#else QAbstractFileEngine *DDciFileEngineHandler::create(const QString &fileName) const +#endif { if (!fileName.startsWith(QStringLiteral(DCI_FILE_SCHEME))) return nullptr; +#if QT_VERSION >= QT_VERSION_CHECK(6, 8 ,0) + std::unique_ptr engine(new DDciFileEngine(fileName)); +#else DDciFileEngine *engine = new DDciFileEngine(fileName); +#endif if (!engine->isValid()) { +#if QT_VERSION < QT_VERSION_CHECK(6, 8, 0) delete engine; +#endif return nullptr; } @@ -66,18 +76,28 @@ static DDciFileShared getDciFile(const QString &dciFilePath, bool usePath = true } DDciFileEngineIterator::DDciFileEngineIterator(QDir::Filters filters, const QStringList &nameFilters) +#if QT_VERSION >= QT_VERSION_CHECK(6, 8 ,0) + : QAbstractFileEngineIterator(nullptr, filters, nameFilters) +#else : QAbstractFileEngineIterator(filters, nameFilters) +#endif { } +#if QT_VERSION < QT_VERSION_CHECK(6, 8, 0) QString DDciFileEngineIterator::next() { current = nextValid; return DDciFileEngineIterator::currentFileName(); } +#endif +#if QT_VERSION >= QT_VERSION_CHECK(6, 8 ,0) +bool DDciFileEngineIterator::advance() +#else bool DDciFileEngineIterator::hasNext() const +#endif { if (!file) { const auto paths = DDciFileEngine::resolvePath(path()); @@ -111,6 +131,9 @@ bool DDciFileEngineIterator::hasNext() const continue; nextValid = i; +#if QT_VERSION >= QT_VERSION_CHECK(6, 8 ,0) + current = nextValid; +#endif return true; } @@ -543,12 +566,23 @@ QDateTime DDciFileEngine::fileTime(QAbstractFileEngine::FileTime time) const } #endif +#if QT_VERSION >= QT_VERSION_CHECK(6, 8 ,0) +QAbstractFileEngine::IteratorUniquePtr DDciFileEngine::beginEntryList(const QString &path, QDir::Filters filters, const QStringList &filterNames) +{ + return QAbstractFileEngine::IteratorUniquePtr(new DDciFileEngineIterator(filters, filterNames)); +} +#else DDciFileEngine::Iterator *DDciFileEngine::beginEntryList(QDir::Filters filters, const QStringList &filterNames) { return new DDciFileEngineIterator(filters, filterNames); } +#endif +#if QT_VERSION >= QT_VERSION_CHECK(6, 8 ,0) +QAbstractFileEngine::IteratorUniquePtr DDciFileEngine::endEntryList() +#else DDciFileEngine::Iterator *DDciFileEngine::endEntryList() +#endif { return nullptr; } diff --git a/src/dci/private/ddcifileengine_p.h b/src/dci/private/ddcifileengine_p.h index 143365d..0730a69 100644 --- a/src/dci/private/ddcifileengine_p.h +++ b/src/dci/private/ddcifileengine_p.h @@ -24,7 +24,11 @@ DCORE_BEGIN_NAMESPACE class DDciFileEngineHandler : public QAbstractFileEngineHandler { public: +#if QT_VERSION >= QT_VERSION_CHECK(6, 8 ,0) + std::unique_ptr create(const QString &fileName) const override; +#else QAbstractFileEngine *create(const QString &fileName) const override; +#endif }; class DDciFile; @@ -35,8 +39,12 @@ class DDciFileEngineIterator : public QAbstractFileEngineIterator public: DDciFileEngineIterator(QDir::Filters filters, const QStringList &nameFilters); +#if QT_VERSION >= QT_VERSION_CHECK(6, 8 ,0) + bool advance() override; +#else QString next() override; bool hasNext() const override; +#endif QString currentFileName() const override; @@ -102,8 +110,13 @@ class DDciFileEngine : public QAbstractFileEngine #endif typedef DDciFileEngineIterator Iterator; +#if QT_VERSION >= QT_VERSION_CHECK(6, 8, 0) + IteratorUniquePtr beginEntryList(const QString &path, QDir::Filters filters, const QStringList &filterNames) override; + IteratorUniquePtr endEntryList() override; +#else Iterator *beginEntryList(QDir::Filters filters, const QStringList &filterNames) override; Iterator *endEntryList() override; +#endif qint64 read(char *data, qint64 maxlen) override; qint64 write(const char *data, qint64 len) override; diff --git a/src/filesystem/dcapfsfileengine.cpp b/src/filesystem/dcapfsfileengine.cpp index 933616b..65e160f 100644 --- a/src/filesystem/dcapfsfileengine.cpp +++ b/src/filesystem/dcapfsfileengine.cpp @@ -14,6 +14,12 @@ DCORE_BEGIN_NAMESPACE extern QString _d_cleanPath(const QString &path); extern bool _d_isSubFileOf(const QString &filePath, const QString &directoryPath); +#if QT_VERSION >= QT_VERSION_CHECK(6, 8 ,0) +std::unique_ptr DCapFSFileEngineHandler::create(const QString &fileName) const +{ + return std::unique_ptr(new DCapFSFileEngine(fileName)); +} +#else static bool capDirIteraterHasNext(QAbstractFileEngineIterator *it) { const QStringList &paths = DCapManager::instance()->paths(); @@ -33,6 +39,7 @@ QAbstractFileEngine *DCapFSFileEngineHandler::create(const QString &fileName) co { return new DCapFSFileEngine(fileName); } +#endif class DCapFSFileEnginePrivate : public DObjectPrivate @@ -210,12 +217,20 @@ QStringList DCapFSFileEngine::entryList(QDir::Filters filters, const QStringList return QFSFileEngine::entryList(filters, filterNames); } +#if QT_VERSION >= QT_VERSION_CHECK(6, 8 ,0) +QAbstractFileEngine::IteratorUniquePtr DCapFSFileEngine::beginEntryList(const QString &path, QDir::Filters filters, const QStringList &filterNames) +{ + auto ret = QFSFileEngine::beginEntryList(path, filters, filterNames); + return ret; +} +#else QAbstractFileEngine::Iterator *DCapFSFileEngine::beginEntryList(QDir::Filters filters, const QStringList &filterNames) { auto ret = QFSFileEngine::beginEntryList(filters, filterNames); DVtableHook::overrideVfptrFun(ret, &QAbstractFileEngineIterator::hasNext, &capDirIteraterHasNext); return ret; } +#endif bool DCapFSFileEngine::canReadWrite(const QString &path) const { diff --git a/src/filesystem/private/dcapfsfileengine_p.h b/src/filesystem/private/dcapfsfileengine_p.h index 3a4a06b..d7a4427 100644 --- a/src/filesystem/private/dcapfsfileengine_p.h +++ b/src/filesystem/private/dcapfsfileengine_p.h @@ -14,7 +14,11 @@ DCORE_BEGIN_NAMESPACE class DCapFSFileEngineHandler : public QAbstractFileEngineHandler { public: +#if QT_VERSION >= QT_VERSION_CHECK(6, 8, 0) + std::unique_ptr create(const QString &fileName) const override; +#else QAbstractFileEngine *create(const QString &fileName) const override; +#endif }; class DCapFSFileEnginePrivate; @@ -47,7 +51,11 @@ class DCapFSFileEngine : public QFSFileEngine, public DObject bool cloneTo(QAbstractFileEngine *target) override; bool setSize(qint64 size) override; QStringList entryList(QDir::Filters filters, const QStringList &filterNames) const override; +#if QT_VERSION >= QT_VERSION_CHECK(6, 8, 0) + IteratorUniquePtr beginEntryList(const QString &path, QDir::Filters filters, const QStringList &filterNames) override; +#else Iterator *beginEntryList(QDir::Filters filters, const QStringList &filterNames) override; +#endif bool canReadWrite(const QString &path) const; }; diff --git a/src/log/LogManager.cpp b/src/log/LogManager.cpp index 50246ff..5ff0c19 100644 --- a/src/log/LogManager.cpp +++ b/src/log/LogManager.cpp @@ -149,6 +149,8 @@ void DLogManager::initJournalAppender() Q_D(DLogManager); d->m_journalAppender = new JournalAppender(); dlogger->registerAppender(d->m_journalAppender); +#else + qWarning() << "BUILD_WITH_SYSTEMD not defined or OS not support!!"; #endif } diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index a42284d..bc1b5a2 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -21,9 +21,6 @@ if(LINUX) if("${QT_VERSION_MAJOR}" STREQUAL "5") pkg_check_modules(QGSettings REQUIRED IMPORTED_TARGET gsettings-qt) endif() - if(BUILD_WITH_SYSTEMD) - pkg_check_modules(Systemd REQUIRED IMPORTED_TARGET libsystemd) - endif() endif() find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Xml) @@ -88,13 +85,6 @@ if(LINUX) ) endif() - if(BUILD_WITH_SYSTEMD) - target_link_libraries( - ${BIN_NAME} PRIVATE - PkgConfig::Systemd - ) - endif() - target_link_libraries( ${BIN_NAME} PRIVATE Qt${QT_VERSION_MAJOR}::DBus