mirror of
https://gitee.com/spark-store-project/spark-store
synced 2025-10-04 09:32:21 +08:00
chore:删除多余注释
This commit is contained in:
parent
03b053bcc0
commit
6f66cd664d
@ -7,6 +7,9 @@
|
|||||||
#include <QPushButton>
|
#include <QPushButton>
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
#include <QMouseEvent>
|
#include <QMouseEvent>
|
||||||
|
#include <QProcess> // 确保 QProcess 头文件已包含
|
||||||
|
#include <QFile> // 确保 QFile 头文件已包含
|
||||||
|
#include <QQueue> // 确保 QQueue 头文件已包含
|
||||||
|
|
||||||
AppDelegate::AppDelegate(QObject *parent)
|
AppDelegate::AppDelegate(QObject *parent)
|
||||||
: QStyledItemDelegate(parent), m_downloadManager(new DownloadManager(this)), m_installProcess(nullptr) {
|
: QStyledItemDelegate(parent), m_downloadManager(new DownloadManager(this)), m_installProcess(nullptr) {
|
||||||
@ -54,7 +57,7 @@ void AppDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, c
|
|||||||
QString newVersion = index.data(Qt::UserRole + 3).toString();
|
QString newVersion = index.data(Qt::UserRole + 3).toString();
|
||||||
QString iconPath = index.data(Qt::UserRole + 4).toString();
|
QString iconPath = index.data(Qt::UserRole + 4).toString();
|
||||||
QString size = index.data(Qt::UserRole + 5).toString();
|
QString size = index.data(Qt::UserRole + 5).toString();
|
||||||
QString description = index.data(Qt::UserRole + 6).toString();
|
// QString description = index.data(Qt::UserRole + 6).toString(); // description 未使用
|
||||||
|
|
||||||
QRect rect = option.rect;
|
QRect rect = option.rect;
|
||||||
int margin = 10, spacing = 6, iconSize = 40;
|
int margin = 10, spacing = 6, iconSize = 40;
|
||||||
@ -84,7 +87,7 @@ void AppDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, c
|
|||||||
|
|
||||||
QString packageName = index.data(Qt::UserRole + 1).toString();
|
QString packageName = index.data(Qt::UserRole + 1).toString();
|
||||||
bool isDownloading = m_downloads.contains(packageName) && m_downloads[packageName].isDownloading;
|
bool isDownloading = m_downloads.contains(packageName) && m_downloads[packageName].isDownloading;
|
||||||
int progress = m_downloads.value(packageName, DownloadInfo{0, false}).progress;
|
int progress = m_downloads.value(packageName, DownloadInfo{0, false, false, false}).progress; // 确保 DownloadInfo 有默认构造或匹配的初始化
|
||||||
bool isInstalled = m_downloads.value(packageName).isInstalled;
|
bool isInstalled = m_downloads.value(packageName).isInstalled;
|
||||||
bool isInstalling = m_downloads.value(packageName).isInstalling;
|
bool isInstalling = m_downloads.value(packageName).isInstalling;
|
||||||
|
|
||||||
@ -171,14 +174,17 @@ bool AppDelegate::editorEvent(QEvent *event, QAbstractItemModel *model,
|
|||||||
QRect buttonRect(rect.right() - 80, rect.top() + (rect.height() - 30) / 2, 70, 30);
|
QRect buttonRect(rect.right() - 80, rect.top() + (rect.height() - 30) / 2, 70, 30);
|
||||||
if (buttonRect.contains(mouseEvent->pos())) {
|
if (buttonRect.contains(mouseEvent->pos())) {
|
||||||
// 判断是否为“下载完成”状态,如果是则不响应点击
|
// 判断是否为“下载完成”状态,如果是则不响应点击
|
||||||
if (m_downloads.contains(packageName) && !m_downloads[packageName].isDownloading) {
|
// 同时也要判断是否为“已安装”状态,如果是也不响应点击
|
||||||
// “下载完成”状态,按钮失效,点击无效
|
if ((m_downloads.contains(packageName) && !m_downloads[packageName].isDownloading) ||
|
||||||
|
(m_downloads.contains(packageName) && m_downloads[packageName].isInstalled)) {
|
||||||
|
// “下载完成”或“已安装”状态,按钮失效,点击无效
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
QString downloadUrl = index.data(Qt::UserRole + 7).toString();
|
QString downloadUrl = index.data(Qt::UserRole + 7).toString();
|
||||||
QString outputPath = QString("%1/%2.metalink").arg(QDir::tempPath(), packageName);
|
QString outputPath = QString("%1/%2.metalink").arg(QDir::tempPath(), packageName);
|
||||||
|
|
||||||
m_downloads[packageName] = {0, true};
|
// 假设 DownloadInfo 结构体的构造函数或聚合初始化方式支持四个成员
|
||||||
|
m_downloads[packageName] = {0, true, false, false}; // progress, isDownloading, isInstalling, isInstalled
|
||||||
m_downloadManager->startDownload(packageName, downloadUrl, outputPath);
|
m_downloadManager->startDownload(packageName, downloadUrl, outputPath);
|
||||||
emit updateDisplay(packageName);
|
emit updateDisplay(packageName);
|
||||||
return true;
|
return true;
|
||||||
@ -194,11 +200,16 @@ void AppDelegate::startDownloadForAll() {
|
|||||||
for (int row = 0; row < m_model->rowCount(); ++row) {
|
for (int row = 0; row < m_model->rowCount(); ++row) {
|
||||||
QModelIndex index = m_model->index(row, 0);
|
QModelIndex index = m_model->index(row, 0);
|
||||||
QString packageName = index.data(Qt::UserRole + 1).toString();
|
QString packageName = index.data(Qt::UserRole + 1).toString();
|
||||||
if (m_downloads.contains(packageName) && (m_downloads[packageName].isDownloading || m_downloads[packageName].isInstalled))
|
// 确保跳过正在下载、正在安装或已安装的
|
||||||
continue; // 跳过正在下载或已安装的
|
if (m_downloads.contains(packageName) &&
|
||||||
|
(m_downloads[packageName].isDownloading ||
|
||||||
|
m_downloads[packageName].isInstalling ||
|
||||||
|
m_downloads[packageName].isInstalled)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
QString downloadUrl = index.data(Qt::UserRole + 7).toString();
|
QString downloadUrl = index.data(Qt::UserRole + 7).toString();
|
||||||
QString outputPath = QString("%1/%2.metalink").arg(QDir::tempPath(), packageName);
|
QString outputPath = QString("%1/%2.metalink").arg(QDir::tempPath(), packageName);
|
||||||
m_downloads[packageName] = {0, true, false};
|
m_downloads[packageName] = {0, true, false, false}; // progress, isDownloading, isInstalling, isInstalled
|
||||||
m_downloadManager->startDownload(packageName, downloadUrl, outputPath);
|
m_downloadManager->startDownload(packageName, downloadUrl, outputPath);
|
||||||
emit updateDisplay(packageName);
|
emit updateDisplay(packageName);
|
||||||
}
|
}
|
||||||
@ -240,6 +251,9 @@ void AppDelegate::startNextInstall() {
|
|||||||
if (debPath.isEmpty()) {
|
if (debPath.isEmpty()) {
|
||||||
qWarning() << "未找到deb文件,包名:" << packageName;
|
qWarning() << "未找到deb文件,包名:" << packageName;
|
||||||
m_downloads[packageName].isInstalling = false;
|
m_downloads[packageName].isInstalling = false;
|
||||||
|
// 如果找不到deb文件,也应该根据情况处理是已安装还是未安装
|
||||||
|
// 这里只是简单地设置为未安装,并更新显示
|
||||||
|
m_downloads[packageName].isInstalled = false; // 确保如果未找到文件则不显示已安装
|
||||||
emit updateDisplay(packageName);
|
emit updateDisplay(packageName);
|
||||||
m_installingPackage.clear();
|
m_installingPackage.clear();
|
||||||
startNextInstall();
|
startNextInstall();
|
||||||
@ -262,12 +276,7 @@ void AppDelegate::startNextInstall() {
|
|||||||
logFile->flush();
|
logFile->flush();
|
||||||
QString text = QString::fromLocal8Bit(out);
|
QString text = QString::fromLocal8Bit(out);
|
||||||
qDebug().noquote() << text;
|
qDebug().noquote() << text;
|
||||||
// 检查“软件包已安装”关键字
|
// 尽管此处可以检查关键字,但最终的安装状态应由进程退出码决定
|
||||||
if (text.contains(QStringLiteral("软件包已安装"))) {
|
|
||||||
m_downloads[packageName].isInstalling = false;
|
|
||||||
m_downloads[packageName].isInstalled = true;
|
|
||||||
emit updateDisplay(packageName);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
connect(m_installProcess, &QProcess::readyReadStandardError, this, [this, logFile]() {
|
connect(m_installProcess, &QProcess::readyReadStandardError, this, [this, logFile]() {
|
||||||
QByteArray err = m_installProcess->readAllStandardError();
|
QByteArray err = m_installProcess->readAllStandardError();
|
||||||
@ -276,17 +285,28 @@ void AppDelegate::startNextInstall() {
|
|||||||
qDebug().noquote() << QString::fromLocal8Bit(err);
|
qDebug().noquote() << QString::fromLocal8Bit(err);
|
||||||
});
|
});
|
||||||
connect(m_installProcess, QOverload<int, QProcess::ExitStatus>::of(&QProcess::finished),
|
connect(m_installProcess, QOverload<int, QProcess::ExitStatus>::of(&QProcess::finished),
|
||||||
this, [this, packageName, logFile](int /*exitCode*/, QProcess::ExitStatus /*status*/) {
|
this, [this, packageName, logFile](int exitCode, QProcess::ExitStatus exitStatus) {
|
||||||
if (logFile) logFile->close();
|
if (logFile) logFile->close();
|
||||||
// 若未检测到“软件包已安装”,此处兜底
|
|
||||||
if (!m_downloads[packageName].isInstalled) {
|
// === 关键修改 ===
|
||||||
m_downloads[packageName].isInstalling = false;
|
// 检查进程是否正常退出且退出码为0,这通常表示成功
|
||||||
|
if (exitStatus == QProcess::NormalExit && exitCode == 0) {
|
||||||
|
m_downloads[packageName].isInstalled = true; // 安装成功,设置为已安装
|
||||||
|
qDebug() << "安装成功:" << packageName;
|
||||||
|
} else {
|
||||||
|
// 安装失败或异常退出
|
||||||
|
m_downloads[packageName].isInstalled = false; // 确保不是已安装状态
|
||||||
|
qWarning() << "安装失败或异常退出:" << packageName << "Exit Code:" << exitCode << "Exit Status:" << exitStatus;
|
||||||
}
|
}
|
||||||
emit updateDisplay(packageName);
|
// === 关键修改结束 ===
|
||||||
|
|
||||||
|
m_downloads[packageName].isInstalling = false; // 安装过程结束
|
||||||
|
emit updateDisplay(packageName); // 更新UI显示
|
||||||
|
|
||||||
m_installProcess->deleteLater();
|
m_installProcess->deleteLater();
|
||||||
m_installProcess = nullptr;
|
m_installProcess = nullptr;
|
||||||
m_installingPackage.clear();
|
m_installingPackage.clear();
|
||||||
startNextInstall();
|
startNextInstall(); // 处理队列中的下一个安装任务
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
// 日志文件无法打开时,仍然要连接原有信号
|
// 日志文件无法打开时,仍然要连接原有信号
|
||||||
@ -294,18 +314,25 @@ void AppDelegate::startNextInstall() {
|
|||||||
QByteArray out = m_installProcess->readAllStandardOutput();
|
QByteArray out = m_installProcess->readAllStandardOutput();
|
||||||
QString text = QString::fromLocal8Bit(out);
|
QString text = QString::fromLocal8Bit(out);
|
||||||
qDebug().noquote() << text;
|
qDebug().noquote() << text;
|
||||||
if (text.contains(QStringLiteral("软件包已安装"))) {
|
// 同样,这里的关键字检查不是最可靠的
|
||||||
m_downloads[packageName].isInstalling = false;
|
|
||||||
m_downloads[packageName].isInstalled = true;
|
|
||||||
emit updateDisplay(packageName);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
connect(m_installProcess, &QProcess::readyReadStandardError, this, [this]() {
|
connect(m_installProcess, &QProcess::readyReadStandardError, this, [this]() {
|
||||||
QByteArray err = m_installProcess->readAllStandardError();
|
QByteArray err = m_installProcess->readAllStandardError();
|
||||||
qDebug().noquote() << QString::fromLocal8Bit(err);
|
qDebug().noquote() << QString::fromLocal8Bit(err);
|
||||||
});
|
});
|
||||||
connect(m_installProcess, QOverload<int, QProcess::ExitStatus>::of(&QProcess::finished),
|
connect(m_installProcess, QOverload<int, QProcess::ExitStatus>::of(&QProcess::finished),
|
||||||
this, [this, packageName](int /*exitCode*/, QProcess::ExitStatus /*status*/) {
|
this, [this, packageName](int exitCode, QProcess::ExitStatus exitStatus) {
|
||||||
|
// === 关键修改 (与上面相同) ===
|
||||||
|
if (exitStatus == QProcess::NormalExit && exitCode == 0) {
|
||||||
|
m_downloads[packageName].isInstalled = true;
|
||||||
|
qDebug() << "安装成功 (无日志文件):" << packageName;
|
||||||
|
} else {
|
||||||
|
m_downloads[packageName].isInstalled = false;
|
||||||
|
qWarning() << "安装失败或异常退出 (无日志文件):" << packageName << "Exit Code:" << exitCode << "Exit Status:" << exitStatus;
|
||||||
|
}
|
||||||
|
// === 关键修改结束 ===
|
||||||
|
|
||||||
|
m_downloads[packageName].isInstalling = false;
|
||||||
emit updateDisplay(packageName);
|
emit updateDisplay(packageName);
|
||||||
m_installProcess->deleteLater();
|
m_installProcess->deleteLater();
|
||||||
m_installProcess = nullptr;
|
m_installProcess = nullptr;
|
||||||
@ -319,3 +346,4 @@ void AppDelegate::startNextInstall() {
|
|||||||
args << debPath << "--no-create-desktop-entry";
|
args << debPath << "--no-create-desktop-entry";
|
||||||
m_installProcess->start("ssinstall", args);
|
m_installProcess->start("ssinstall", args);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user