Skip to content

Commit

Permalink
sync: from linuxdeepin/dtkcore
Browse files Browse the repository at this point in the history
Synchronize source files from linuxdeepin/dtkcore.

Source-pull-request: linuxdeepin/dtkcore#438
  • Loading branch information
deepin-ci-robot committed Oct 18, 2024
1 parent 0efd5df commit 23b9953
Show file tree
Hide file tree
Showing 7 changed files with 79 additions and 10 deletions.
3 changes: 3 additions & 0 deletions dtkcore.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
34 changes: 34 additions & 0 deletions src/dci/private/ddcifileengine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<QAbstractFileEngine> 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<DDciFileEngine> 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;
}

Expand Down Expand Up @@ -66,18 +77,26 @@ 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();
}

bool DDciFileEngineIterator::hasNext() const
#else
bool DDciFileEngineIterator::advance()

Check warning on line 98 in src/dci/private/ddcifileengine.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

The function 'advance' is never used.
#endif
{
if (!file) {
const auto paths = DDciFileEngine::resolvePath(path());
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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()

Check warning on line 584 in src/dci/private/ddcifileengine.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

The function 'endEntryList' is never used.
#endif
{
return nullptr;
}
Expand Down
14 changes: 14 additions & 0 deletions src/dci/private/ddcifileengine_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@ DCORE_BEGIN_NAMESPACE
class DDciFileEngineHandler : public QAbstractFileEngineHandler
{
public:
#if QT_VERSION >= QT_VERSION_CHECK(6, 8, 0)
std::unique_ptr<QAbstractFileEngine> create(const QString &fileName) const override;
#else
QAbstractFileEngine *create(const QString &fileName) const override;
#endif
};

class DDciFile;
Expand All @@ -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;

Expand Down Expand Up @@ -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;
Expand Down
18 changes: 18 additions & 0 deletions src/filesystem/dcapfsfileengine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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<QAbstractFileEngine> 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<QAbstractFileEngine>(new DCapFSFileEngine(fileName));
#else
return new DCapFSFileEngine(fileName);
#endif
}


Expand Down Expand Up @@ -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;
}

Expand Down
8 changes: 8 additions & 0 deletions src/filesystem/private/dcapfsfileengine_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@ DCORE_BEGIN_NAMESPACE
class DCapFSFileEngineHandler : public QAbstractFileEngineHandler
{
public:
#if QT_VERSION >= QT_VERSION_CHECK(6, 8, 0)
std::unique_ptr<QAbstractFileEngine> create(const QString &fileName) const override;
#else
QAbstractFileEngine *create(const QString &fileName) const override;
#endif
};

class DCapFSFileEnginePrivate;
Expand Down Expand Up @@ -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;
};
Expand Down
2 changes: 2 additions & 0 deletions src/log/LogManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
10 changes: 0 additions & 10 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 23b9953

Please sign in to comment.