Skip to content

Commit 3021870

Browse files
committed
feat: add default mirror source selection with DBus integration
1. Added MirrorSourceModel (QAbstractListModel) to manage mirror list data with roles for id, name, url, and speed 2. Moved mirror info struct to common/dbus for shared use across modules 3. Replaced static mirrors.json with dynamic DBus-based mirror fetching via ListMirrorSources and MirrorSource 4. Added MirrorSourcePopup QML component for mirror selection UI with keyboard navigation and speed display 5. Refactored UpdateModel to use MirrorSourceModel instead of raw MirrorInfoList and removed old speed info map 6. Updated UpdateWorker to fetch mirrors from DBus on activation and handle mirror speed testing asynchronously 7. Changed setDefaultMirror to emit mirrorId string instead of MirrorInfo object 8. Added getMirrorNameById utility method to UpdateModel Log: Added default mirror source selection UI with DBus backend, replacing static configuration; improved mirror speed testing and display Influence: 1. Verify mirror list is correctly loaded from DBus service on startup 2. Test default mirror selection and persistence across application restarts 3. Validate mirror speed test results are displayed correctly (Untested/ Testing.../Timeout/ms) 4. Test keyboard navigation (up/down/enter/escape) in mirror popup window 5. Verify smart mirror switch toggles visibility of default mirror selection 6. Test mirror change propagation to system update backend via SetMirrorSource 7. Ensure backward compatibility with existing update flow feat: 添加默认镜像源选择功能及 DBus 集成 1. 新增 MirrorSourceModel 模型类管理镜像列表数据,包含 id、name、url、 speed 角色 2. 将镜像信息结构体移动到 common/dbus 目录供模块共享使用 3. 用 DBus 动态获取镜像列表替代静态 mirrors.json 配置文件 4. 添加 MirrorSourcePopup QML 组件实现镜像选择界面,支持键盘导航和速度 显示 5. 重构 UpdateModel,使用 MirrorSourceModel 替代原始 MirrorInfoList,移 除旧的测速信息映射 6. 更新 UpdateWorker,启动时通过 DBus 获取镜像列表,并异步处理镜像测速 7. 修改 setDefaultMirror 信号,发射镜像 ID 字符串而非对象 8. 添加 getMirrorNameById 工具方法 Log: 新增默认镜像源选择界面及 DBus 后端支持,替代静态配置;改进镜像测速 结果显示 Influence: 1. 验证启动时镜像列表正确从 DBus 服务加载 2. 测试默认镜像选择及应用重启后持久化保持 3. 验证镜像测速结果正确显示(未检测/测试中/超时/毫秒数) 4. 测试键盘导航(上/下/回车/退出)在镜像弹出窗口中的表现 5. 验证智能镜像开关切换时默认镜像选择区域的显隐逻辑 6. 测试通过 SetMirrorSource 接口切换镜像对系统更新的影响 7. 确保不影响现有更新流程的向后兼容性 PMS: TASK-388775 Change-Id: I0c267ba0b29c43845dd7ee3ea29d52852b344ff4
1 parent 2c5cc22 commit 3021870

60 files changed

Lines changed: 5467 additions & 1750 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/dcc-update-plugin/operation/mirrorinfolist.cpp renamed to src/common/dbus/mirrorinfolist.cpp

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,31 @@
1-
//SPDX-FileCopyrightText: 2025 UnionTech Software Technology Co., Ltd.
1+
//SPDX-FileCopyrightText: 2026 UnionTech Software Technology Co., Ltd.
22
//
33
//SPDX-License-Identifier: GPL-3.0-or-later
44
#include "mirrorinfolist.h"
55
#include <QLoggingCategory>
66

7-
Q_DECLARE_LOGGING_CATEGORY(logDccUpdatePlugin)
7+
Q_LOGGING_CATEGORY(logMirrorInfo, "dde.update.mirrorinfo")
88

99
MirrorInfo::MirrorInfo()
1010
{
11-
qCDebug(logDccUpdatePlugin) << "Initialize MirrorInfo";
1211
}
1312

1413
const QDBusArgument &operator>>(const QDBusArgument &argument, MirrorInfo &info)
1514
{
16-
qCDebug(logDccUpdatePlugin) << "Deserializing MirrorInfo from DBus";
15+
qCDebug(logMirrorInfo) << "Deserializing MirrorInfo from DBus";
1716
argument.beginStructure();
1817
argument >> info.m_id;
1918
argument >> info.m_url;
2019
argument >> info.m_name;
2120
argument.endStructure();
22-
qCDebug(logDccUpdatePlugin) << "MirrorInfo deserialized - ID:" << info.m_id << "name:" << info.m_name;
21+
qCDebug(logMirrorInfo) << "MirrorInfo deserialized - ID:" << info.m_id << "name:" << info.m_name;
2322

2423
return argument;
2524
}
2625

2726
QDBusArgument &operator<<(QDBusArgument &argument, const MirrorInfo &info)
2827
{
29-
qCDebug(logDccUpdatePlugin) << "Serializing MirrorInfo to DBus - ID:" << info.m_id << "name:" << info.m_name;
28+
qCDebug(logMirrorInfo) << "Serializing MirrorInfo to DBus - ID:" << info.m_id << "name:" << info.m_name;
3029
argument.beginStructure();
3130
argument << info.m_id;
3231
argument << info.m_url;
@@ -38,7 +37,7 @@ QDBusArgument &operator<<(QDBusArgument &argument, const MirrorInfo &info)
3837

3938
QDebug operator<<(QDebug argument, const MirrorInfo &info)
4039
{
41-
qCDebug(logDccUpdatePlugin) << "Debug output for MirrorInfo";
40+
qCDebug(logMirrorInfo) << "Debug output for MirrorInfo";
4241
argument << "mirror id: " << info.m_id;
4342
argument << "mirror url: " << info.m_url;
4443
argument << "mirror name: " << info.m_name;
@@ -48,7 +47,7 @@ QDebug operator<<(QDebug argument, const MirrorInfo &info)
4847

4948
void registerMirrorInfoListMetaType()
5049
{
51-
qCDebug(logDccUpdatePlugin) << "Registering MirrorInfo meta types";
50+
qCDebug(logMirrorInfo) << "Registering MirrorInfo meta types";
5251
qRegisterMetaType<MirrorInfo>();
5352
qDBusRegisterMetaType<MirrorInfo>();
5453
qRegisterMetaType<MirrorInfoList>();

src/dcc-update-plugin/operation/mirrorinfolist.h renamed to src/common/dbus/mirrorinfolist.h

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

src/common/dbus/updatedbusproxy.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ UpdateDBusProxy::UpdateDBusProxy(QObject *parent)
4949
qRegisterMetaType<BatteryPercentageInfo>("BatteryPercentageInfo");
5050
qDBusRegisterMetaType<BatteryPercentageInfo>();
5151

52+
registerMirrorInfoListMetaType();
53+
5254
m_interWatcher->setWatchedServices({UpdaterService, ManagerInterface, HostnameService});
5355

5456
connect(m_interWatcher, &QDBusServiceWatcher::serviceRegistered, this, [this](const QString &serviceName) {
@@ -181,6 +183,19 @@ void UpdateDBusProxy::SetMirrorSource(const QString &in0)
181183
m_updateInter->asyncCallWithArgumentList(QStringLiteral("SetMirrorSource"), argumentList);
182184
}
183185

186+
QDBusPendingReply<MirrorInfoList> UpdateDBusProxy::ListMirrorSources(const QString &lang)
187+
{
188+
qCDebug(logCommon) << "Listing mirror sources for language:" << lang;
189+
QList<QVariant> argumentList;
190+
argumentList << QVariant::fromValue(lang);
191+
return m_updateInter->asyncCallWithArgumentList(QStringLiteral("ListMirrorSources"), argumentList);
192+
}
193+
194+
QString UpdateDBusProxy::MirrorSource()
195+
{
196+
return qvariant_cast<QString>(m_updateInter->property("MirrorSource"));
197+
}
198+
184199
bool UpdateDBusProxy::autoClean()
185200
{
186201
return qvariant_cast<bool>(m_managerInter->property("AutoClean"));

src/common/dbus/updatedbusproxy.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
#include <QObject>
1212
#include <QDBusServiceWatcher>
1313

14+
#include "mirrorinfolist.h"
15+
1416
typedef QMap<QString, QStringList> LastoreUpdatePackagesInfo;
1517
typedef QMap<QString, double> BatteryPercentageInfo;
1618

@@ -52,6 +54,8 @@ class UpdateDBusProxy : public QObject
5254
bool autoCheckUpdates();
5355
void SetAutoCheckUpdates(bool in0);
5456
void SetMirrorSource(const QString &in0);
57+
QDBusPendingReply<MirrorInfoList> ListMirrorSources(const QString &lang);
58+
QString MirrorSource();
5559

5660
// ManagerInter
5761
Q_PROPERTY(bool AutoClean READ autoClean NOTIFY AutoCleanChanged)

src/dcc-update-plugin/operation/common.h

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

@@ -131,6 +131,14 @@ enum CtrlWidgetType {
131131
};
132132
Q_ENUM_NS(CtrlWidgetType)
133133

134+
enum SpeedStatus {
135+
Untested = -2, // 未检测
136+
Testing = -1, // 测试中
137+
Fast = 200, // 快速阈值,单位ms
138+
Medium = 2000, // 中速阈值,单位ms
139+
Timeout = 10000 // 超时阈值,单位ms
140+
};
141+
Q_ENUM_NS(SpeedStatus)
134142

135143

136144
static inline QString formatCap(qulonglong cap, const int size = 1024)
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
// SPDX-FileCopyrightText: 2026 UnionTech Software Technology Co., Ltd.
2+
// SPDX-License-Identifier: GPL-3.0-or-later
3+
#include "mirrorsourcemodel.h"
4+
#include <QLoggingCategory>
5+
6+
Q_DECLARE_LOGGING_CATEGORY(logDccUpdatePlugin)
7+
8+
MirrorSourceModel::MirrorSourceModel(QObject *parent)
9+
: QAbstractListModel(parent)
10+
{
11+
}
12+
13+
int MirrorSourceModel::rowCount(const QModelIndex &parent) const
14+
{
15+
if (parent.isValid())
16+
return 0;
17+
18+
return m_mirrors.count();
19+
}
20+
21+
QVariant MirrorSourceModel::data(const QModelIndex &index, int role) const
22+
{
23+
if (!index.isValid() || index.row() >= m_mirrors.size())
24+
return QVariant();
25+
26+
const MirrorData &item = m_mirrors[index.row()];
27+
28+
switch (role) {
29+
case IdRole:
30+
return item.id;
31+
case NameRole:
32+
return item.name;
33+
case UrlRole:
34+
return item.url;
35+
case SpeedRole:
36+
return item.speed;
37+
default:
38+
break;
39+
}
40+
return QVariant();
41+
}
42+
43+
void MirrorSourceModel::setMirrorList(const MirrorInfoList &list)
44+
{
45+
beginResetModel();
46+
m_mirrors.clear();
47+
for (const MirrorInfo &info : list) {
48+
m_mirrors.append({info.m_id, info.m_name, info.m_url, SpeedStatus::Untested});
49+
}
50+
endResetModel();
51+
}
52+
53+
void MirrorSourceModel::updateMirrorSpeed(const QString &mirrorId, int speed)
54+
{
55+
for (int i = 0; i < m_mirrors.size(); ++i) {
56+
if (m_mirrors[i].id == mirrorId) {
57+
m_mirrors[i].speed = speed;
58+
QModelIndex changedIndex = index(i);
59+
emit dataChanged(changedIndex, changedIndex, {SpeedRole});
60+
return;
61+
}
62+
}
63+
}
64+
65+
void MirrorSourceModel::resetSpeedInfo()
66+
{
67+
if (m_mirrors.isEmpty())
68+
return;
69+
70+
for (auto &item : m_mirrors) {
71+
item.speed = SpeedStatus::Testing;
72+
}
73+
emit dataChanged(index(0), index(m_mirrors.count() - 1), {SpeedRole});
74+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
// SPDX-FileCopyrightText: 2026 UnionTech Software Technology Co., Ltd.
2+
// SPDX-License-Identifier: GPL-3.0-or-later
3+
#ifndef MIRRORSOURCEMODEL_H
4+
#define MIRRORSOURCEMODEL_H
5+
6+
#include "common/dbus/mirrorinfolist.h"
7+
#include "common.h"
8+
9+
#include <QAbstractListModel>
10+
11+
using namespace dcc::update::common;
12+
class MirrorSourceModel : public QAbstractListModel
13+
{
14+
Q_OBJECT
15+
16+
public:
17+
enum MirrorRoles {
18+
IdRole = Qt::UserRole + 1,
19+
NameRole,
20+
UrlRole,
21+
SpeedRole
22+
};
23+
24+
explicit MirrorSourceModel(QObject *parent = nullptr);
25+
26+
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
27+
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
28+
QHash<int, QByteArray> roleNames() const override
29+
{
30+
QHash<int, QByteArray> roles;
31+
roles[IdRole] = "id";
32+
roles[NameRole] = "name";
33+
roles[UrlRole] = "url";
34+
roles[SpeedRole] = "speed";
35+
return roles;
36+
}
37+
38+
void setMirrorList(const MirrorInfoList &list);
39+
void updateMirrorSpeed(const QString &mirrorId, int speed);
40+
void resetSpeedInfo();
41+
42+
private:
43+
struct MirrorData {
44+
QString id;
45+
QString name;
46+
QString url;
47+
int speed = SpeedStatus::Untested;
48+
};
49+
50+
QList<MirrorData> m_mirrors;
51+
};
52+
53+
#endif // MIRRORSOURCEMODEL_H

0 commit comments

Comments
 (0)