mirror of
https://gitee.com/spark-store-project/spark-store
synced 2025-12-15 21:32:05 +08:00
fix:修复无icon时,加载默认图标失效问题
This commit is contained in:
@@ -92,8 +92,18 @@ void AppDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, c
|
|||||||
|
|
||||||
// 检查图标路径是否存在,如果不存在则使用默认图标
|
// 检查图标路径是否存在,如果不存在则使用默认图标
|
||||||
QString finalIconPath = iconPath;
|
QString finalIconPath = iconPath;
|
||||||
|
qDebug() << "原始图标路径:" << iconPath;
|
||||||
if (iconPath.isEmpty() || !QFile::exists(iconPath)) {
|
if (iconPath.isEmpty() || !QFile::exists(iconPath)) {
|
||||||
finalIconPath = ":/resources/default_icon.svg";
|
finalIconPath = ":/resources/default_icon.svg";
|
||||||
|
qDebug() << "图标文件不存在,使用默认图标:" << finalIconPath;
|
||||||
|
} else {
|
||||||
|
qDebug() << "使用图标文件:" << finalIconPath;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 额外检查资源文件是否存在
|
||||||
|
if (finalIconPath.startsWith(":/") && QIcon(finalIconPath).isNull()) {
|
||||||
|
qDebug() << "资源图标无法加载,使用备用默认图标";
|
||||||
|
finalIconPath = ":/resources/default_icon.svg";
|
||||||
}
|
}
|
||||||
|
|
||||||
// 如果是忽略状态,绘制灰色图标
|
// 如果是忽略状态,绘制灰色图标
|
||||||
|
|||||||
@@ -248,6 +248,7 @@ QStringList aptssUpdater::getPackageIcons()
|
|||||||
if (!dpkgProcess.waitForFinished(30000)) { // 30秒超时
|
if (!dpkgProcess.waitForFinished(30000)) { // 30秒超时
|
||||||
qWarning() << "获取包文件列表失败:" << packageName << "(超时)";
|
qWarning() << "获取包文件列表失败:" << packageName << "(超时)";
|
||||||
dpkgProcess.kill();
|
dpkgProcess.kill();
|
||||||
|
packageIcons << QString("%1: %2").arg(packageName, iconPath);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
QStringList files = QString(dpkgProcess.readAllStandardOutput()).split('\n', Qt::SkipEmptyParts);
|
QStringList files = QString(dpkgProcess.readAllStandardOutput()).split('\n', Qt::SkipEmptyParts);
|
||||||
@@ -278,6 +279,7 @@ QStringList aptssUpdater::getPackageIcons()
|
|||||||
foreach (const QString &path, iconPaths) {
|
foreach (const QString &path, iconPaths) {
|
||||||
if (QFile::exists(path)) {
|
if (QFile::exists(path)) {
|
||||||
iconPath = path;
|
iconPath = path;
|
||||||
|
qDebug() << "找到图标文件:" << path;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -285,6 +287,7 @@ QStringList aptssUpdater::getPackageIcons()
|
|||||||
// 已经是绝对路径
|
// 已经是绝对路径
|
||||||
if (QFile::exists(iconName)) {
|
if (QFile::exists(iconName)) {
|
||||||
iconPath = iconName;
|
iconPath = iconName;
|
||||||
|
qDebug() << "使用绝对路径图标文件:" << iconName;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@@ -296,9 +299,13 @@ QStringList aptssUpdater::getPackageIcons()
|
|||||||
|
|
||||||
// 如果.desktop中没有找到图标,尝试直接查找包中的图标文件
|
// 如果.desktop中没有找到图标,尝试直接查找包中的图标文件
|
||||||
if (iconPath == ":/resources/default_icon.svg") {
|
if (iconPath == ":/resources/default_icon.svg") {
|
||||||
|
qDebug() << "未在.desktop文件中找到图标,尝试直接查找包中的图标文件";
|
||||||
QStringList iconFiles = files.filter(QRegularExpression("/(usr/share/pixmaps|usr/share/icons|opt/apps/.*/entries/icons)/.*\\.(png|svg)$"));
|
QStringList iconFiles = files.filter(QRegularExpression("/(usr/share/pixmaps|usr/share/icons|opt/apps/.*/entries/icons)/.*\\.(png|svg)$"));
|
||||||
if (!iconFiles.isEmpty()) {
|
if (!iconFiles.isEmpty()) {
|
||||||
iconPath = iconFiles.first();
|
iconPath = iconFiles.first();
|
||||||
|
qDebug() << "从包中找到图标文件:" << iconPath;
|
||||||
|
} else {
|
||||||
|
qDebug() << "未在包中找到图标文件,使用默认图标";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user