Skip to content

Commit 22c33f3

Browse files
committed
1
1 parent 154a9e5 commit 22c33f3

10 files changed

Lines changed: 94 additions & 51 deletions

File tree

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

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -148,16 +148,10 @@ struct UpgradeSpeedLimitConfig {
148148
QDateTime endTime; // 结束时间
149149

150150
bool ifInOnlineLimit() const {
151-
if (limitType != 3) {
152-
return false;
153-
}
154-
155-
if (!startTime.isValid() || !endTime.isValid()) {
156-
return false;
157-
}
151+
if (limitType == 2)
152+
return true;
158153

159-
QDateTime currentTime = QDateTime::currentDateTime();
160-
return currentTime >= startTime && currentTime <= endTime;
154+
return false;
161155
}
162156

163157
bool shouldLimitRate() const {
@@ -185,7 +179,6 @@ struct UpgradeSpeedLimitConfig {
185179

186180
static UpgradeSpeedLimitConfig fromJson(const QByteArray& configStr)
187181
{
188-
qWarning() << "xiongbo123 fromJson: " << configStr;
189182
UpgradeSpeedLimitConfig config;
190183
QJsonParseError jsonParseError;
191184
const QJsonDocument doc = QJsonDocument::fromJson(configStr, &jsonParseError);
@@ -318,6 +311,15 @@ struct LastoreDaemonUpdateStatus {
318311
}
319312
};
320313

314+
inline QString transferDeliveryConfigToLastoreDeliveryConfig(const QString& deliveryConfig)
315+
{
316+
LastoreUpgradeSpeedLimitConfig lastoreDeliveryConfig;
317+
lastoreDeliveryConfig.isOnlineSpeedLimit = UpgradeSpeedLimitConfig::fromJson(deliveryConfig.toUtf8()).ifInOnlineLimit();
318+
lastoreDeliveryConfig.speedLimitEnabled = UpgradeSpeedLimitConfig::fromJson(deliveryConfig.toUtf8()).shouldLimitRate();
319+
lastoreDeliveryConfig.limitSpeed = QString::number(UpgradeSpeedLimitConfig::fromJson(deliveryConfig.toUtf8()).currentRate);
320+
return lastoreDeliveryConfig.toJson();
321+
}
322+
321323
const int INSTALLATION_IS_READY = 1 << 0; // 是否可以安装
322324
const int UPDATE_IS_DISABLED = 1 << 1; // 更新功能是否被禁用
323325
struct LastoreDaemonDConfigStatusHelper {

src/dcc-update-plugin/operation/updateloghelper.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ QString UpdateLogHelper::sumCveLevelUp(const QMap<VulLevel, int>& vulCount)
6666

6767
void UpdateLogHelper::handleUpdateLog(const QString &log)
6868
{
69+
qCDebug(logDccUpdatePlugin) << "Handling update log: " << log;
6970
qCDebug(logDccUpdatePlugin) << "Handling update log, length:" << log.length();
7071
const QJsonDocument& doc = QJsonDocument::fromJson(log.toLocal8Bit());
7172
const QJsonObject& rootObj = doc.object();

src/dcc-update-plugin/operation/updatemodel.cpp

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1169,9 +1169,11 @@ DownloadSpeedLimitConfig UpdateModel::speedLimitConfig() const
11691169
return DownloadSpeedLimitConfig::fromJson(m_speedLimitConfig);
11701170
}
11711171

1172-
void UpdateModel::setSpeedLimitConfig(const QByteArray& config)
1172+
void UpdateModel::setSpeedLimitConfig(const QByteArray& config, bool isFromQml)
11731173
{
11741174
qCDebug(logDccUpdatePlugin) << "Set speed limit config:" << config;
1175+
if (DownloadSpeedLimitConfig::fromJson(m_speedLimitConfig).isOnlineSpeedLimit && isFromQml)
1176+
return;
11751177
if (m_speedLimitConfig == config)
11761178
return;
11771179

@@ -1523,7 +1525,6 @@ void UpdateModel::onUpdatePropertiesChanged(const QString& interfaceName, const
15231525
{
15241526
qCDebug(logDccUpdatePlugin) << "Update properties changed for interface:" << interfaceName << "properties count:" << changedProperties.size();
15251527
Q_UNUSED(invalidatedProperties)
1526-
15271528
if (interfaceName == "org.deepin.dde.Lastore1.Manager") {
15281529
qCDebug(logDccUpdatePlugin) << "Handling Lastore Manager property changes";
15291530
if (changedProperties.contains("CheckUpdateMode")) {
@@ -1561,7 +1562,21 @@ void UpdateModel::onUpdatePropertiesChanged(const QString& interfaceName, const
15611562

15621563
if (changedProperties.contains("P2PUpdateEnable")) {
15631564
qCDebug(logDccUpdatePlugin) << "P2PUpdateEnable property changed";
1564-
setP2PUpdateEnabled(changedProperties.value("P2PUpdateEnable").toBool());
1565+
setUpgradeDeliveryEnable(changedProperties.value("P2PUpdateEnable").toBool());
1566+
}
1567+
}
1568+
1569+
if (interfaceName == "org.deepin.upgradedelivery") {
1570+
qCDebug(logDccUpdatePlugin) << "Handling upgrade delivery property changes";
1571+
if (changedProperties.contains("DownloadLimitSpeed")) {
1572+
qCDebug(logDccUpdatePlugin) << "P2PUpgradeDownloadSpeedLimitConfig property changed";
1573+
qCDebug(logDccUpdatePlugin) << "P2PUpgradeDownloadSpeedLimitConfig property changed " << changedProperties.value("DownloadLimitSpeed");
1574+
setUpgradeDownloadSpeedLimitConfig(transferDeliveryConfigToLastoreDeliveryConfig(changedProperties.value("DownloadLimitSpeed").toByteArray()).toUtf8());
1575+
}
1576+
1577+
if (changedProperties.contains("UploadLimitSpeed")) {
1578+
qCDebug(logDccUpdatePlugin) << "P2PUpgradeUploadSpeedLimitConfig property changed";
1579+
setUpgradeUploadSpeedLimitConfig(transferDeliveryConfigToLastoreDeliveryConfig(changedProperties.value("UploadLimitSpeed").toByteArray()).toUtf8());
15651580
}
15661581
}
15671582
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ class UpdateModel : public QObject
8888
Q_PROPERTY(QString upgradeDownloadSpeedCurrentRate READ upgradeDownloadSpeedCurrentRate NOTIFY upgradeDownloadSpeedLimitConfigChanged FINAL)
8989
Q_PROPERTY(QString upgradeDownloadSpeedLimitRate READ upgradeDownloadSpeedLimitRate NOTIFY upgradeDownloadSpeedLimitConfigChanged FINAL)
9090
Q_PROPERTY(bool upgradeDownloadSpeedEnable READ upgradeDownloadSpeedEnable NOTIFY upgradeDownloadSpeedLimitConfigChanged FINAL)
91+
Q_PROPERTY(bool upgradeDownloadSpeedIsOnline READ upgradeDownloadSpeedIsOnline NOTIFY upgradeDownloadSpeedLimitConfigChanged FINAL)
9192
Q_PROPERTY(QString upgradeUploadSpeedCurrentRate READ upgradeUploadSpeedCurrentRate NOTIFY upgradeUploadSpeedLimitConfigChanged FINAL)
9293
Q_PROPERTY(QString upgradeUploadSpeedLimitRate READ upgradeUploadSpeedLimitRate NOTIFY upgradeUploadSpeedLimitConfigChanged FINAL)
9394
Q_PROPERTY(bool upgradeUploadSpeedEnable READ upgradeUploadSpeedEnable NOTIFY upgradeUploadSpeedLimitConfigChanged FINAL)
@@ -282,7 +283,7 @@ class UpdateModel : public QObject
282283
bool downloadIsOnlineSpeedLimit() const;
283284
QString downloadSpeedLimitSize() const;
284285
DownloadSpeedLimitConfig speedLimitConfig() const;
285-
void setSpeedLimitConfig(const QByteArray &config);
286+
void setSpeedLimitConfig(const QByteArray &config, bool isFromQml = false);
286287

287288
void setUpgradeDownloadSpeedLimitConfig(const QByteArray& config, bool needEmitSignal = true);
288289
QString upgradeDownloadSpeedCurrentRate() const;

src/dcc-update-plugin/operation/updatework.cpp

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -928,7 +928,7 @@ void UpdateWorker::setDownloadSpeedLimitEnabled(bool enable)
928928
config.downloadSpeedLimitEnabled = enable;
929929
config.isOnlineSpeedLimit = false;
930930
// dbus返回需要1s,导致界面更新慢,这里直接先更新model
931-
m_model->setSpeedLimitConfig(config.toJson().toUtf8());
931+
m_model->setSpeedLimitConfig(config.toJson().toUtf8(), true);
932932
setDownloadSpeedLimitConfig(config.toJson());
933933
}
934934

@@ -1294,17 +1294,6 @@ void UpdateWorker::initTestingChannel()
12941294
});
12951295
}
12961296

1297-
QString UpdateWorker::transferDeliveryConfigToLastoreDeliveryConfig(const QString& deliveryConfig)
1298-
{
1299-
qCDebug(logDccUpdatePlugin) << "xiongbo55555 transferDeliveryConfigToLastoreDeliveryConfig " << deliveryConfig;
1300-
LastoreUpgradeSpeedLimitConfig lastoreDeliveryConfig;
1301-
lastoreDeliveryConfig.isOnlineSpeedLimit = UpgradeSpeedLimitConfig::fromJson(deliveryConfig.toUtf8()).ifInOnlineLimit();
1302-
lastoreDeliveryConfig.speedLimitEnabled = UpgradeSpeedLimitConfig::fromJson(deliveryConfig.toUtf8()).shouldLimitRate();
1303-
lastoreDeliveryConfig.limitSpeed = QString::number(UpgradeSpeedLimitConfig::fromJson(deliveryConfig.toUtf8()).currentRate);
1304-
qCDebug(logDccUpdatePlugin) << "xiongbo55555 " << lastoreDeliveryConfig.toJson();
1305-
return lastoreDeliveryConfig.toJson();
1306-
}
1307-
13081297
void UpdateWorker::refreshUpgradeDeliveryInfo()
13091298
{
13101299
qCDebug(logDccUpdatePlugin) << "Refresh upgrade delivery info";
@@ -1786,11 +1775,10 @@ void UpdateWorker::setUpgradeDeliveryEnabled(bool enabled, bool fromRetryDialog)
17861775
//设置更新传递下载限速
17871776
void UpdateWorker::setUpgradeDeliveryDownloadLimitSpeed(const QString& speed, bool enable)
17881777
{
1789-
qCInfo(logDccUpdatePlugin) << "xiongbo123 speed: " << speed;
17901778
LastoreUpgradeSpeedLimitConfig downloadSpeedLimitConfig;
17911779
downloadSpeedLimitConfig.isOnlineSpeedLimit = false;
17921780
downloadSpeedLimitConfig.speedLimitEnabled = enable;
1793-
downloadSpeedLimitConfig.limitSpeed = QString::number(speed.toInt() * 1024);
1781+
downloadSpeedLimitConfig.limitSpeed = speed;
17941782
qCInfo(logDccUpdatePlugin) << "Set upgrade download speed limit: " << downloadSpeedLimitConfig.toJson();
17951783
auto watcher = new QDBusPendingCallWatcher(m_updateInter->SetUpgradeDeliveryDownloadSpeedLimit(downloadSpeedLimitConfig.toJson()), this);
17961784
connect(watcher, &QDBusPendingCallWatcher::finished, [watcher, this, downloadSpeedLimitConfig] {
@@ -1801,7 +1789,6 @@ void UpdateWorker::setUpgradeDeliveryDownloadLimitSpeed(const QString& speed, bo
18011789
Q_EMIT upgradeDeliveryConfigSetFailed();
18021790
return;
18031791
}
1804-
m_model->setUpgradeDownloadSpeedLimitConfig(downloadSpeedLimitConfig.toJson().toUtf8(), false);
18051792
});
18061793
}
18071794

@@ -1811,7 +1798,7 @@ void UpdateWorker::setUpgradeDeliveryUploadLimitSpeed(const QString& speed, bool
18111798
LastoreUpgradeSpeedLimitConfig uploadSpeedLimitConfig;
18121799
uploadSpeedLimitConfig.isOnlineSpeedLimit = false;
18131800
uploadSpeedLimitConfig.speedLimitEnabled = enable;
1814-
uploadSpeedLimitConfig.limitSpeed = QString::number(speed.toInt() * 1024);
1801+
uploadSpeedLimitConfig.limitSpeed = speed;
18151802
qCInfo(logDccUpdatePlugin) << "Set upgrade upload speed limit: " << uploadSpeedLimitConfig.toJson();
18161803
auto watcher = new QDBusPendingCallWatcher(m_updateInter->SetUpgradeDeliveryUploadSpeedLimit(uploadSpeedLimitConfig.toJson()), this);
18171804
connect(watcher, &QDBusPendingCallWatcher::finished, [watcher, this, uploadSpeedLimitConfig] {
@@ -1822,7 +1809,6 @@ void UpdateWorker::setUpgradeDeliveryUploadLimitSpeed(const QString& speed, bool
18221809
Q_EMIT upgradeDeliveryConfigSetFailed();
18231810
return;
18241811
}
1825-
m_model->setUpgradeUploadSpeedLimitConfig(uploadSpeedLimitConfig.toJson().toUtf8(), false);
18261812
});
18271813
}
18281814

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,6 @@ class UpdateWorker : public QObject
110110
void setRemovePackageJob(const QString& jobPath);
111111
QString getServiceUrlByRegion();
112112
void refreshUpgradeDeliveryInfo();
113-
QString transferDeliveryConfigToLastoreDeliveryConfig(const QString& deliveryConfig);
114113

115114
Q_INVOKABLE bool openUrl(const QString& url);
116115
Q_INVOKABLE void onRequestRetry(int type, int updateTypes);

src/dcc-update-plugin/qml/UpdateSetting.qml

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,8 @@ DccObject {
103103
Layout.fillWidth: true
104104
horizontalAlignment: Text.AlignHCenter
105105
wrapMode: Text.WordWrap
106-
text: qsTr("Failed to change Upgrade Delivery setting")
106+
text: root.pendingUpgradeDeliveryEnabled ? qsTr("Update Delivery Optimization service exception. Failed to enable.")
107+
: qsTr("Update Delivery Optimization service exception. Failed to disable.")
107108
}
108109

109110
Item {
@@ -122,7 +123,7 @@ DccObject {
122123
focus: upgradeDeliverySetEnableFailedDialog.visible
123124
onClicked: {
124125
upgradeDeliverySetEnableFailedDialog.close()
125-
dccData.work().setUpgradeDeliveryEnabled(!root.pendingUpgradeDeliveryEnabled, true)
126+
dccData.work().setUpgradeDeliveryEnabled(root.pendingUpgradeDeliveryEnabled, true)
126127
}
127128
}
128129

@@ -335,7 +336,7 @@ DccObject {
335336
name: "upgradeDeliverySwitch"
336337
parentName: "upgradeDeliveryGrp"
337338
displayName: qsTr("Upgrade Delivery")
338-
description: qsTr("Turning this on may cause your device to send previously downloaded system updates to devices on the local network. Turning this off will clear files cached for update delivery on restart")
339+
description: qsTr("When enabled, your device may share previously downloaded system updates with other devices on your local network.When you turn it off, cached files from update delivery will be cleared during the next restart.")
339340
weight: 10
340341
enabled: !dccData.model().updateProhibited
341342
pageType: DccObject.Editor
@@ -361,13 +362,20 @@ DccObject {
361362
}
362363

363364
DccObject {
365+
id: upgradeDeliveryUploadLimitSetting
364366
name: "upgradeDeliveryUploadLimitSetting"
365367
parentName: "upgradeDeliveryGrp"
366368
displayName: qsTr("Upgrade Delivery Upload Limit Setting")
367369
visible: dccData.model().upgradeDeliveryEnable
368370
weight: 20
369371
enabled: !dccData.model().upgradeUploadSpeedIsOnline
370372
pageType: DccObject.Item
373+
Connections {
374+
target: dccData.model()
375+
function onUpgradeUploadSpeedLimitConfigChanged() {
376+
upgradeDeliveryUploadLimitSetting.enabled = !dccData.model().upgradeUploadSpeedIsOnline
377+
}
378+
}
371379
page: RowLayout {
372380
D.CheckBox {
373381
id: limitCheckBox
@@ -454,13 +462,20 @@ DccObject {
454462
}
455463

456464
DccObject {
465+
id: upgradeDeliveryDownloadLimitSetting
457466
name: "upgradeDeliveryDownloadLimitSetting"
458467
parentName: "upgradeDeliveryGrp"
459468
displayName: qsTr("Upgrade Delivery Download Limit Setting")
460469
visible: dccData.model().upgradeDeliveryEnable
461470
weight: 20
462471
enabled: !dccData.model().upgradeDownloadSpeedIsOnline
463472
pageType: DccObject.Item
473+
Connections {
474+
target: dccData.model()
475+
function onUpgradeDownloadSpeedLimitConfigChanged() {
476+
upgradeDeliveryDownloadLimitSetting.enabled = !dccData.model().upgradeDownloadSpeedIsOnline
477+
}
478+
}
464479
page: RowLayout {
465480
D.CheckBox {
466481
id: limitCheckBox
@@ -591,7 +606,7 @@ DccObject {
591606
page: RowLayout {
592607
D.LineEdit {
593608
id: lineEdit
594-
maximumLength: 5
609+
maximumLength: 6
595610
validator: RegularExpressionValidator { regularExpression: /^\d*$/ }
596611
alertText: qsTr("Only numbers between 10-999999 are allowed")
597612
alertDuration: 3000

src/dcc-update-plugin/translations/update_zh_CN.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,7 @@
447447
<translation>传递优化</translation>
448448
</message>
449449
<message>
450-
<source>Turning this on may cause your device to send previously downloaded system updates to devices on the local network. Turning this off will clear files cached for update delivery on restart</source>
450+
<source>When enabled, your device may share previously downloaded system updates with other devices on your local network.When you turn it off, cached files from update delivery will be cleared during the next restart.</source>
451451
<translation>开启此功能,你的设备可能会将以前下载的部分系统更新发送到本地网络的设备上。关闭此功能后,将在重启时清除传递优化时缓存的文件</translation>
452452
</message>
453453
<message>
@@ -532,11 +532,19 @@
532532
</message>
533533
<message>
534534
<source>Failed to change Upgrade Delivery setting</source>
535-
<translation>更新传递优化服务异常,设置失败</translation>
535+
<translation>更新传递优化服务异常</translation>
536+
</message>
537+
<message>
538+
<source>Update Delivery Optimization service exception. Failed to enable.</source>
539+
<translation>更新传递优化服务异常,开启失败</translation>
540+
</message>
541+
<message>
542+
<source>Update Delivery Optimization service exception. Failed to disable.</source>
543+
<translation>更新传递优化服务异常,关闭失败</translation>
536544
</message>
537545
<message>
538546
<source>Retry</source>
539-
<translation>重试</translation>
547+
<translation>再试一次</translation>
540548
</message>
541549
<message>
542550
<source>OK</source>

src/dcc-update-plugin/translations/update_zh_HK.ts

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -444,19 +444,19 @@
444444
</message>
445445
<message>
446446
<source>Upgrade Delivery</source>
447-
<translation>更新傳遞</translation>
447+
<translation>傳遞優化</translation>
448448
</message>
449449
<message>
450-
<source>Turning this on may cause your device to send previously downloaded system updates to devices on the local network. Turning this off will clear files cached for update delivery on restart</source>
450+
<source>When enabled, your device may share previously downloaded system updates with other devices on your local network.When you turn it off, cached files from update delivery will be cleared during the next restart.</source>
451451
<translation>開啟此功能,你的裝置可能會將以前下載的部分系統更新傳送到本地網絡的裝置上。關閉此功能後,將在重新啟動時清除更新傳遞時快取的檔案</translation>
452452
</message>
453453
<message>
454454
<source>Upgrade Delivery Download Limit Setting</source>
455-
<translation>更新傳遞-下載限速</translation>
455+
<translation>下載限速</translation>
456456
</message>
457457
<message>
458458
<source>Upgrade Delivery Upload Limit Setting</source>
459-
<translation>更新傳遞-上傳限速</translation>
459+
<translation>上傳限速</translation>
460460
</message>
461461
<message>
462462
<source>Limit Speed</source>
@@ -528,11 +528,19 @@
528528
</message>
529529
<message>
530530
<source>Failed to change Upgrade Delivery setting</source>
531-
<translation>更新傳遞優化服務異常,設置失敗</translation>
531+
<translation>更新傳遞優化服務異常</translation>
532+
</message>
533+
<message>
534+
<source>Update Delivery Optimization service exception. Failed to enable.</source>
535+
<translation>更新傳遞優化服務異常,開啓失敗</translation>
536+
</message>
537+
<message>
538+
<source>Update Delivery Optimization service exception. Failed to disable.</source>
539+
<translation>更新傳遞優化服務異常,關閉失敗</translation>
532540
</message>
533541
<message>
534542
<source>Retry</source>
535-
<translation>重試</translation>
543+
<translation>再試一次</translation>
536544
</message>
537545
<message>
538546
<source>OK</source>

0 commit comments

Comments
 (0)