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#393
  • Loading branch information
deepin-ci-robot authored and kegechen committed Nov 14, 2023
1 parent 5b38c9c commit e7b8166
Show file tree
Hide file tree
Showing 6 changed files with 126 additions and 14 deletions.
47 changes: 47 additions & 0 deletions docs/filesystem/dstandardpaths.zh_CN.dox
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*!
@~chinese
@ingroup dfilesystem
@file include/filesystem/dstandardpaths.h

@class DStandardPaths
@brief DStandardPaths 类描述了一些标准的文件路径,包括XDG文件路径,locate等

@fn static QString DStandardPaths::writableLocation(QStandardPaths::StandardLocation type)
@brief DStandardPaths提供兼容Snap/Dtk标准的路径模式。DStandardPaths实现了Qt的QStandardPaths主要接口。此处返回可写路径

@fn static QStringList DStandardPaths::standardLocations (QStandardPaths::StandardLocation type)
@brief DStandardPaths提供兼容Snap/Dtk标准的路径模式。DStandardPaths实现了Qt的QStandardPaths主要接口。此处返回所有Standardpath

@fn static QString DStandardPaths::locate(QStandardPaths::StandardLocation type, const QString &fileName, QStandardPaths::LocateOptions options = QStandardPaths::LocateFile)
@brief 在 type 的标准位置查找名为 fileName 的文件或目录。选项标志允许您指定是否查找文件或目录。默认情况下,此标志设置为 LocateFile。返回找到的第一个文件或目录的绝对路径,否则返回空字符串。

@fn static QStringList DStandardPaths::locateAll(QStandardPaths::StandardLocation type, const QString &fileName, QStandardPaths::LocateOptions options = QStandardPaths::LocateFile)
@brief 在类型的标准位置中按名称 fileName 查找所有文件或目录。选项标志允许您指定是否查找文件或目录。默认情况下,此标志设置为 LocateFile。返回找到的所有文件的列表。

@fn static QString DStandardPaths::findExecutable(const QString &executableName, const QStringList &paths = QStringList())
@brief 同QStandardPaths::findExecutable, 查找可执行文件

@fn static void DStandardPaths::setMode(DStandardPaths::Mode mode)
@brief 同QStandardPaths::setTestModeEnabled, 设置是否是测试模式

@fn static QString DStandardPaths::homePath()
@brief 返回家目录

@fn static QString DStandardPaths::homePath(const uint uid)
@brief 用uid返回家目录

@fn static QString DStandardPaths::path(DStandardPaths::XDG type)
@brief 返回对应的xdg目录

@fn static QString DStandardPaths::path(DStandardPaths::DSG type)
@brief 返回对应Dsg目录

@fn static QStringList DStandardPaths::paths(DStandardPaths::DSG type)
@brief 返回所有DSG下所有目录

@fn static QString DStandardPaths::filePath(DStandardPaths::XDG type, QString fileName)
@brief 用xdg和文件名称拼接,返回文件绝对路径

@fn static QString DStandardPaths::filePath(DStandardPaths::DSG type, QString fileName)
@brief 用dsg和文件名称拼接,返回文件绝对路径
*/
24 changes: 23 additions & 1 deletion include/filesystem/dstandardpaths.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,33 @@ class LIBDTKCORESHARED_EXPORT DStandardPaths
static QString findExecutable(const QString &executableName, const QStringList &paths = QStringList());
static void setMode(Mode mode);

/**
* @brief About XDG dir, view it in https://gitlab.freedesktop.org/xdg/xdg-specs/
*/
enum class XDG {
/*
* @brief DataHome, usually is ~/.local/share, also can be defined by ${XDG_DATA_HOME}, where stores the data of applications
*/
DataHome,
/*
* @brief ConfigHome, usually is ~/.config, can be defined by ${XDG_CONFIG_HOME}, where stores the config of applications
*/
ConfigHome,
/*
* @brief CacheHome, usually is ~/.cache, can be defined by ${XDG_CACHE_HOME}, where stores caches, can be always cleared
*/
CacheHome,
/*
* @brief Where temp files or sock files always be put in, like sddm.sock. It is unique per session. It is /run/user/${uid} or ${XDG_RUNTIME_DIR},
*/
RuntimeDir,
#if DTK_VERSION < DTK_VERSION_CHECK(6, 0, 0, 0)
RuntimeTime [[deprecated("Use RuntimeDir Instead")]] = RuntimeDir
RuntimeTime [[deprecated("Use RuntimeDir Instead")]] = RuntimeDir,
#endif
/*
* @brief where history file and state file should be. It is induced because users do not want to mix their config files and state files. It is always ~/.local/state, or defined by ${XDG_STATE_HOME}
*/
StateHome
};

enum class DSG {
Expand All @@ -46,6 +65,9 @@ class LIBDTKCORESHARED_EXPORT DStandardPaths

static QString homePath();
static QString homePath(const uint uid);
/*
* @brief Get the XDG dir path by XDG type
*/
static QString path(XDG type);
static QString path(DSG type);
static QStringList paths(DSG type);
Expand Down
40 changes: 36 additions & 4 deletions src/dsgapplication.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,27 @@
// SPDX-FileCopyrightText: 2022 UnionTech Software Technology Co., Ltd.
// SPDX-FileCopyrightText: 2022-2023 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: LGPL-3.0-or-later

#include "dsgapplication.h"

#include <sys/syscall.h>
#include <unistd.h>

#include <QByteArray>
#include <QCoreApplication>
#include <QDebug>
#include <QDBusUnixFileDescriptor>
#include <QDBusReply>
#include <QRegularExpression>
#include <QLoggingCategory>

#include <DDBusInterface>

#ifdef QT_DEBUG
Q_LOGGING_CATEGORY(dsgApp, "dtk.core.dsg")
#else
Q_LOGGING_CATEGORY(dsgApp, "dtk.core.dsg", QtInfoMsg)
#endif

DCORE_BEGIN_NAMESPACE

Expand Down Expand Up @@ -34,10 +50,26 @@ QByteArray DSGApplication::id()
return result;
}

QByteArray DSGApplication::getId(qint64)
QByteArray DSGApplication::getId(qint64 pid)
{
// TODO(zccrs): Call the org.desktopspec.ApplicationManager DBus service
return nullptr;
int pidfd = syscall(SYS_pidfd_open, pid, 0);
if (pidfd < 0) {
qCWarning(dsgApp) << "pidfd open failed:" << strerror(errno);
return QByteArray();
}

DDBusInterface infc("org.desktopspec.ApplicationManager1",
"/org/desktopspec/ApplicationManager1",
"org.desktopspec.ApplicationManager1");

QDBusReply<QString> reply = infc.call("Identify", QVariant::fromValue(QDBusUnixFileDescriptor(pidfd)));

if (!reply.isValid()) {
qCWarning(dsgApp) << "Identify from AM failed." << reply.error().message();
return QByteArray();
}

return reply.value().toLatin1();
}

DCORE_END_NAMESPACE
11 changes: 11 additions & 0 deletions src/filesystem/dstandardpaths.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,17 @@ QString DStandardPaths::path(DStandardPaths::XDG type)
return QString::fromLocal8Bit(path);
return QStringLiteral("/run/user/") + QString::number(getuid());
}
case XDG::StateHome: {
const QByteArray &path = qgetenv("XDG_STATE_HOME");
if (!path.isEmpty())
return QString::fromLocal8Bit(path);
#ifdef Q_OS_LINUX
return homePath() + QStringLiteral("/.local/state");
#else
// TODO: handle it on mac
return QString();
#endif
}
}
return QString();
}
Expand Down
6 changes: 3 additions & 3 deletions src/log/RollingFileAppender.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ void RollingFileAppender::removeOldFiles()

void RollingFileAppender::computeRollOverTime()
{
if (auto *fs = get_sink<rolling_file_sink_st>(loggerName(fileName()))){
if (auto *fs = get_sink<rolling_file_sink_mt>(loggerName(fileName()))){
return fs->set_interval(RollingInterval(m_frequency));
}
}
Expand All @@ -99,7 +99,7 @@ void RollingFileAppender::setLogFilesLimit(int limit)
QMutexLocker locker(&m_rollingMutex);
m_logFilesLimit = limit;

if (auto *fs = get_sink<rolling_file_sink_st>(loggerName(fileName()))){
if (auto *fs = get_sink<rolling_file_sink_mt>(loggerName(fileName()))){
return fs->set_max_files(std::size_t(limit));
}
}
Expand All @@ -115,7 +115,7 @@ void RollingFileAppender::setLogSizeLimit(int limit)
QMutexLocker locker(&m_rollingMutex);
m_logSizeLimit = limit;

if (auto *fs = get_sink<rolling_file_sink_st>(loggerName(fileName()))){
if (auto *fs = get_sink<rolling_file_sink_mt>(loggerName(fileName()))){
return fs->set_max_size(std::size_t(limit));
}
}
Expand Down
12 changes: 6 additions & 6 deletions src/util/dpinyin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,12 +133,12 @@ static QStringList permutations(const QList<QStringList> &pyList)

static QStringList deduplication(const QStringList &list)
{
#if QT_VERSION >= QT_VERSION_CHECK(5,14,0)
const auto &dedupList = QSet<QString>{list.begin(), list.end()};
return QStringList{dedupList.begin(), dedupList.end()};
#else
return QSet<QString>::fromList(list).toList();
#endif
QStringList result;
for (const QString &item : list)
if (!result.contains(item))
result.append(item);

return result;
}

/*!
Expand Down

0 comments on commit e7b8166

Please sign in to comment.