|
1 | | -// SPDX-FileCopyrightText: 2024 UnionTech Software Technology Co., Ltd. |
| 1 | +// SPDX-FileCopyrightText: 2024-2026 UnionTech Software Technology Co., Ltd. |
2 | 2 | // SPDX-License-Identifier: GPL-3.0-or-later |
3 | 3 | import QtQuick |
4 | 4 | import QtQuick.Controls |
@@ -118,14 +118,115 @@ ColumnLayout { |
118 | 118 |
|
119 | 119 | Repeater { |
120 | 120 | model: btnActions |
121 | | - delegate: D.Button { |
| 121 | + delegate: Loader { |
| 122 | + id: buttonLoader |
122 | 123 | Layout.alignment: Qt.AlignRight | Qt.AlignVCenter |
123 | | - text: modelData |
124 | | - font: D.DTK.fontManager.t6 |
125 | 124 | visible: modelData.length !== 0 && !initAnimation.visible |
126 | 125 | enabled: updatelistModel.model.isUpdateEnable |
127 | | - onClicked: { |
128 | | - rootLayout.btnClicked(index, updateListModels.getAllUpdateType()) |
| 126 | + |
| 127 | + Connections { |
| 128 | + target: dccData.model() |
| 129 | + function onIsPrivateUpdateChanged() { |
| 130 | + updateButtonType() |
| 131 | + } |
| 132 | + function onIsUpdateDisabledChanged() { |
| 133 | + updateButtonType() |
| 134 | + } |
| 135 | + function onShowCheckUpdateChanged() { |
| 136 | + updateButtonType() |
| 137 | + } |
| 138 | + } |
| 139 | + |
| 140 | + Component.onCompleted: { |
| 141 | + updateButtonType() |
| 142 | + } |
| 143 | + |
| 144 | + function updateButtonType() { |
| 145 | + var model = dccData.model() |
| 146 | + if (!model) { |
| 147 | + console.log("Model not ready yet") |
| 148 | + return |
| 149 | + } |
| 150 | + if (index === 1) { |
| 151 | + buttonLoader.sourceComponent = normalButtonComponent |
| 152 | + } else if (model.isPrivateUpdate && |
| 153 | + !model.isUpdateDisabled && |
| 154 | + !model.showCheckUpdate && |
| 155 | + model.preInstallListModel.anyVisible) { |
| 156 | + buttonLoader.sourceComponent = dropdownButtonComponent |
| 157 | + } else { |
| 158 | + // 默认使用普通按钮 |
| 159 | + buttonLoader.sourceComponent = normalButtonComponent |
| 160 | + } |
| 161 | + } |
| 162 | + |
| 163 | + Component { |
| 164 | + id: normalButtonComponent |
| 165 | + D.Button { |
| 166 | + text: modelData |
| 167 | + font: D.DTK.fontManager.t6 |
| 168 | + onClicked: { |
| 169 | + rootLayout.btnClicked(index, updateListModels.getAllUpdateType()) |
| 170 | + } |
| 171 | + } |
| 172 | + } |
| 173 | + |
| 174 | + Component { |
| 175 | + id: dropdownButtonComponent |
| 176 | + Item { |
| 177 | + implicitWidth: button.implicitWidth |
| 178 | + implicitHeight: button.implicitHeight |
| 179 | + |
| 180 | + enum InstallType { |
| 181 | + Now, |
| 182 | + Shutdown |
| 183 | + } |
| 184 | + |
| 185 | + property int curType: DropdownButton.InstallType.Now |
| 186 | + |
| 187 | + signal requestUpdateNow() |
| 188 | + signal requestUpdateShutdown() |
| 189 | + |
| 190 | + D.Button { |
| 191 | + id: button |
| 192 | + text: qsTr("Install") |
| 193 | + |
| 194 | + Menu { |
| 195 | + id: contextMenu |
| 196 | + |
| 197 | + MenuItem { |
| 198 | + text: qsTr("Install Now") |
| 199 | + onClicked: { |
| 200 | + dccData.work().setShutdownAndUpgrade(false) |
| 201 | + dccData.work().doUpgrade(updateListModels.getAllUpdateType(), true) |
| 202 | + } |
| 203 | + } |
| 204 | + |
| 205 | + MenuItem { |
| 206 | + text: qsTr("Install Shutdown") |
| 207 | + onClicked: { |
| 208 | + dccData.work().setShutdownAndUpgrade(true) |
| 209 | + } |
| 210 | + } |
| 211 | + } |
| 212 | + |
| 213 | + // 点击按钮显示菜单 |
| 214 | + onClicked: { |
| 215 | + contextMenu.open() |
| 216 | + } |
| 217 | + } |
| 218 | + |
| 219 | + // 连接内部信号到外部 |
| 220 | + Connections { |
| 221 | + target: parent |
| 222 | + function onRequestUpdateNow() { |
| 223 | + rootLayout.btnClicked(index, 0) |
| 224 | + } |
| 225 | + function onRequestUpdateShutdown() { |
| 226 | + rootLayout.btnClicked(index, 1) |
| 227 | + } |
| 228 | + } |
| 229 | + } |
129 | 230 | } |
130 | 231 | } |
131 | 232 | } |
@@ -180,7 +281,7 @@ ColumnLayout { |
180 | 281 | icon.height: 24 |
181 | 282 | implicitWidth: 24 |
182 | 283 | implicitHeight: 24 |
183 | | - visible: isDownloading |
| 284 | + visible: isDownloading && !dccData.model().isPrivateUpdate |
184 | 285 |
|
185 | 286 | onClicked: { |
186 | 287 | rootLayout.closeDownload() |
|
0 commit comments