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..14b2a0a 100644 --- a/src/dci/private/ddcifileengine.cpp +++ b/src/dci/private/ddcifileengine.cpp @@ -30,14 +30,25 @@ 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,11 +77,16 @@ 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; @@ -78,6 +94,9 @@ QString DDciFileEngineIterator::next() } bool DDciFileEngineIterator::hasNext() const +#else +bool DDciFileEngineIterator::advance() +#endif { if (!file) { const auto paths = DDciFileEngine::resolvePath(path()); @@ -111,6 +130,9 @@ bool DDciFileEngineIterator::hasNext() const continue; nextValid = i; +#if QT_VERSION >= QT_VERSION_CHECK(6, 8, 0) + current = nextValid; +#endif return true; } @@ -543,12 +565,24 @@ 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) +#else DDciFileEngine::Iterator *DDciFileEngine::beginEntryList(QDir::Filters filters, const QStringList &filterNames) +#endif { +#if QT_VERSION >= QT_VERSION_CHECK(6, 8, 0) + return QAbstractFileEngine::IteratorUniquePtr(new DDciFileEngineIterator(filters, filterNames)); +#else 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..118b971 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) QString next() override; bool hasNext() const override; +#else + bool advance() override; +#endif QString currentFileName() const override; @@ -102,8 +110,14 @@ 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..4cefc1b 100644 --- a/src/filesystem/dcapfsfileengine.cpp +++ b/src/filesystem/dcapfsfileengine.cpp @@ -14,6 +14,7 @@ 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) static bool capDirIteraterHasNext(QAbstractFileEngineIterator *it) { const QStringList &paths = DCapManager::instance()->paths(); @@ -28,10 +29,19 @@ static bool capDirIteraterHasNext(QAbstractFileEngineIterator *it) return ret; return DVtableHook::callOriginalFun(it, &QAbstractFileEngineIterator::hasNext); } +#endif +#if QT_VERSION >= QT_VERSION_CHECK(6, 8, 0) +std::unique_ptr DCapFSFileEngineHandler::create(const QString &fileName) const +#else QAbstractFileEngine *DCapFSFileEngineHandler::create(const QString &fileName) const +#endif { +#if QT_VERSION >= QT_VERSION_CHECK(6, 8, 0) + return std::unique_ptr(new DCapFSFileEngine(fileName)); +#else return new DCapFSFileEngine(fileName); +#endif } @@ -210,10 +220,18 @@ 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) +#else QAbstractFileEngine::Iterator *DCapFSFileEngine::beginEntryList(QDir::Filters filters, const QStringList &filterNames) +#endif { +#if QT_VERSION >= QT_VERSION_CHECK(6, 8, 0) + auto ret = QFSFileEngine::beginEntryList(path, filters, filterNames); +#else auto ret = QFSFileEngine::beginEntryList(filters, filterNames); DVtableHook::overrideVfptrFun(ret, &QAbstractFileEngineIterator::hasNext, &capDirIteraterHasNext); +#endif return ret; } 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