diff --git a/src/appdelegate.cpp b/src/appdelegate.cpp index 57987f9..506506b 100644 --- a/src/appdelegate.cpp +++ b/src/appdelegate.cpp @@ -163,3 +163,18 @@ bool AppDelegate::editorEvent(QEvent *event, QAbstractItemModel *model, return QStyledItemDelegate::editorEvent(event, model, option, index); } + +void AppDelegate::startDownloadForAll() { + if (!m_model) return; + for (int row = 0; row < m_model->rowCount(); ++row) { + QModelIndex index = m_model->index(row, 0); + QString packageName = index.data(Qt::UserRole + 1).toString(); + if (m_downloads.contains(packageName) && m_downloads[packageName].isDownloading) + continue; // 跳过正在下载的 + QString downloadUrl = index.data(Qt::UserRole + 7).toString(); + QString outputPath = QString("%1/%2.metalink").arg(QDir::tempPath(), packageName); + m_downloads[packageName] = {0, true}; + m_downloadManager->startDownload(packageName, downloadUrl, outputPath); + emit updateDisplay(packageName); + } +} diff --git a/src/appdelegate.h b/src/appdelegate.h index 37f7a77..9e4ac3a 100644 --- a/src/appdelegate.h +++ b/src/appdelegate.h @@ -20,6 +20,7 @@ public: QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const override; bool editorEvent(QEvent *event, QAbstractItemModel *model, const QStyleOptionViewItem &option, const QModelIndex &index) override; + void startDownloadForAll(); // 新增:批量下载所有应用 signals: void updateDisplay(const QString &packageName); diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 9b20071..f961afc 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -14,6 +14,9 @@ MainWindow::MainWindow(QWidget *parent) listView->setModel(m_model); listView->setItemDelegate(m_delegate); + // 新增:确保 delegate 拥有 model 指针 + m_delegate->setModel(m_model); + // 设置 QListView 填充 ui->appWidget QVBoxLayout *layout = new QVBoxLayout(ui->appWidget); layout->addWidget(listView); @@ -27,6 +30,13 @@ MainWindow::MainWindow(QWidget *parent) } } }); + + // 新增:点击“更新全部”按钮批量下载 + connect(ui->updatePushButton, &QPushButton::clicked, this, [=](){ + qDebug()<<"更新全部按钮被点击"; + m_delegate->startDownloadForAll(); + }); + checkUpdates(); initStyle(); }