Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sync: from linuxdeepin/dtkcore #73

Merged
merged 1 commit into from
Oct 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,24 @@
#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 +76,28 @@
}

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());
Expand Down Expand Up @@ -111,6 +131,9 @@
continue;

nextValid = i;
#if QT_VERSION >= QT_VERSION_CHECK(6, 8 ,0)
current = nextValid;
#endif
return true;
}

Expand Down Expand Up @@ -543,12 +566,23 @@
}
#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()

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
13 changes: 13 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)
bool advance() override;
#else
QString next() override;
bool hasNext() const override;
#endif

QString currentFileName() const override;

Expand Down Expand Up @@ -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;
Expand Down
15 changes: 15 additions & 0 deletions src/filesystem/dcapfsfileengine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<QAbstractFileEngine> DCapFSFileEngineHandler::create(const QString &fileName) const
{
return std::unique_ptr<QAbstractFileEngine>(new DCapFSFileEngine(fileName));
}
#else
static bool capDirIteraterHasNext(QAbstractFileEngineIterator *it)
{
const QStringList &paths = DCapManager::instance()->paths();
Expand All @@ -33,6 +39,7 @@ QAbstractFileEngine *DCapFSFileEngineHandler::create(const QString &fileName) co
{
return new DCapFSFileEngine(fileName);
}
#endif


class DCapFSFileEnginePrivate : public DObjectPrivate
Expand Down Expand Up @@ -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
{
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
Loading