Skip to content

Commit deec269

Browse files
committed
chore: update license info handling and add default loading
1. Updated copyright year range from 2023 to 2023-2026 in header 2. Replaced DObject include with QObject for better compatibility 3. Added loadDefault() and clear() public methods to DLicenseInfo class 4. Enhanced license content search to use QStandardPaths for cross- platform compatibility 5. Added support for both system licenses (/usr/share/spdx-licenses) and custom licenses 6. Implemented automatic loading of application-specific license config from standard data locations 7. Improved error handling with clearer warning messages Log: Improved license information management with better path handling and default configuration loading chore: 更新许可证信息处理并添加默认加载功能 1. 将头文件中的版权年份范围从2023更新为2023-2026 2. 将DObject引用替换为QObject以提高兼容性 3. 为DLicenseInfo类添加了loadDefault()和clear()公共方法 4. 使用QStandardPaths增强许可证内容搜索,提高跨平台兼容性 5. 添加了对系统许可证(/usr/share/spdx-licenses)和自定义许可证的支持 6. 实现了从标准数据位置自动加载应用程序特定的许可证配置 7. 改进了错误处理,提供更清晰的警告信息 Log: 改进了许可证信息管理,提供更好的路径处理和默认配置加载功能 PMS: TASK-387863
1 parent 3e34c88 commit deec269

2 files changed

Lines changed: 31 additions & 18 deletions

File tree

include/global/dlicenseinfo.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd.
1+
// SPDX-FileCopyrightText: 2023 - 2026 UnionTech Software Technology Co., Ltd.
22
//
33
// SPDX-License-Identifier: LGPL-3.0-or-later
44

src/dlicenseinfo.cpp

Lines changed: 30 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd.
1+
// SPDX-FileCopyrightText: 2023 - 2026 UnionTech Software Technology Co., Ltd.
22
//
33
// SPDX-License-Identifier: LGPL-3.0-or-later
44

@@ -11,9 +11,16 @@
1111
#include <QJsonObject>
1212
#include <QJsonArray>
1313
#include <QDebug>
14+
#include <QCoreApplication>
15+
#include <QStandardPaths>
1416

1517
DCORE_BEGIN_NAMESPACE
1618

19+
// /usr/share/spdx-licenses
20+
constexpr auto SystemLicenseDir = "spdx-licenses";
21+
constexpr auto CustomLicenseDir = "custom-licenses";
22+
constexpr auto SystemConfigDir = "deepin/credits";
23+
1724
class DLicenseInfo::DComponentInfoPrivate : public DObjectPrivate
1825
{
1926
public:
@@ -90,6 +97,16 @@ DLicenseInfoPrivate::~DLicenseInfoPrivate()
9097

9198
bool DLicenseInfoPrivate::loadFile(const QString &file)
9299
{
100+
clear();
101+
if (file.isEmpty()) {
102+
const QString relPath = QString("%1/%2.json").arg(SystemConfigDir, qApp->applicationName());
103+
for (const QString &dataDir : QStandardPaths::standardLocations(QStandardPaths::GenericDataLocation)) {
104+
const QString file = dataDir + '/' + relPath;
105+
if (QFile::exists(file))
106+
return loadFile(file);
107+
}
108+
return false;
109+
}
93110
QFile jsonFile(file);
94111
if (!jsonFile.open(QIODevice::ReadOnly)) {
95112
qWarning() << QString("Failed on open file: \"%1\", error message: \"%2\"").arg(
@@ -141,24 +158,20 @@ bool DLicenseInfoPrivate::loadContent(const QByteArray &content)
141158

142159
QByteArray DLicenseInfoPrivate::licenseContent(const QString &licenseName)
143160
{
144-
QByteArray content;
145-
QStringList dirs{"/usr/share/spdx-license"};
161+
const QStringList dataDirs = QStandardPaths::standardLocations(QStandardPaths::GenericDataLocation);
162+
QStringList searchDirs;
146163
if (!licenseSearchPath.isEmpty())
147-
dirs.prepend(licenseSearchPath);
148-
for (const QString &dir : dirs) {
149-
QFile file(QString("%1/%2.txt").arg(dir).arg(licenseName));
150-
if (!file.exists())
151-
continue;
152-
if (file.open(QIODevice::ReadOnly)) {
153-
content = file.readAll();
154-
file.close();
155-
break;
156-
}
157-
}
158-
if (content.isEmpty()) {
159-
qWarning() << QString("License content is empty when getting license content!");
164+
searchDirs << licenseSearchPath;
165+
for (const QString &dataDir : dataDirs)
166+
for (const auto *dir : {CustomLicenseDir, SystemLicenseDir})
167+
searchDirs << (dataDir + '/' + dir);
168+
169+
for (const QString &dir : searchDirs) {
170+
QFile file(dir + '/' + licenseName + ".txt");
171+
if (file.open(QIODevice::ReadOnly))
172+
return file.readAll();
160173
}
161-
return content;
174+
return {};
162175
}
163176

164177
void DLicenseInfoPrivate::clear()

0 commit comments

Comments
 (0)