-
Notifications
You must be signed in to change notification settings - Fork 55
fix: ensure preview icon will use icon from theme as fallback #1272
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
确保窗口预览图会使用来自图标主题的名称作为 fallback PMS: BUG-335563 Log:
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: BLumia The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
Reviewer's guide (collapsed on small PRs)Reviewer's GuideReplaced the base64-only icon loader with a unified method that parses the input string, loads embedded base64 data if present, or falls back to a theme icon by name, with logging and transparent placeholder on failure. File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
deepin pr auto review我对这段代码进行了仔细审查,以下是我的分析和改进建议: 1. 语法逻辑
2. 代码质量
3. 代码性能
4. 代码安全
5. 具体改进建议代码void X11WindowPreviewContainer::updatePreviewIconFromString(const QString &stringData)
{
// 支持两种格式:
// 1. base64编码的图片数据,格式为 "data:image/xxx;base64,xxxx"
// 2. 系统主题图标名称
QPixmap pix;
const QStringList strs = stringData.split("base64,", Qt::SkipEmptyParts);
if (strs.size() == 2) {
// 处理base64图片数据
QByteArray base64Data = strs.at(1).toLatin1();
// 验证base64数据有效性
if (base64Data.size() > MAX_ICON_DATA_SIZE) {
qCWarning(x11WindowPreview) << "Icon data too large, size:" << base64Data.size();
pix = createFallbackIcon();
goto setPixmap;
}
pix.loadFromData(QByteArray::fromBase64(base64Data));
if (pix.isNull()) {
qCWarning(x11WindowPreview) << "Failed to load icon from base64 data";
pix = createFallbackIcon();
}
} else {
// 处理主题图标名称
pix = QIcon::fromTheme(stringData, QIcon()).pixmap(PREVIEW_TITLE_HEIGHT, PREVIEW_TITLE_HEIGHT);
if (pix.isNull()) {
qCWarning(x11WindowPreview) << "Failed to load theme icon:" << stringData;
pix = createFallbackIcon();
}
}
setPixmap:
m_previewIcon->setPixmap(pix);
}
QPixmap X11WindowPreviewContainer::createFallbackIcon()
{
QPixmap icon(PREVIEW_TITLE_HEIGHT, PREVIEW_TITLE_HEIGHT);
icon.fill(Qt::transparent);
return icon;
}6. 其他建议
private:
static const int MAX_ICON_DATA_SIZE = 1024 * 1024; // 1MB
static const int PREVIEW_TITLE_HEIGHT = 24;这些改进将提高代码的健壮性、可维护性和安全性,同时保持良好的性能表现。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey there - I've reviewed your changes and they look great!
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location> `panels/dock/taskmanager/x11preview.cpp:766-774` </location>
<code_context>
{
- const QStringList strs = base64Data.split("base64,");
QPixmap pix;
+ const QStringList strs = stringData.split("base64,");
if (strs.size() == 2) {
+ // is base64 image data
</code_context>
<issue_to_address>
**suggestion:** Splitting on 'base64,' may not handle malformed or unexpected input robustly.
If 'base64,' is missing or appears multiple times, the split may not work as intended. Input validation or a more reliable parsing method is recommended.
```suggestion
QPixmap pix;
int base64Idx = stringData.indexOf("base64,");
if (base64Idx != -1) {
QString base64Part = stringData.mid(base64Idx + 7); // 7 = length of "base64,"
if (!base64Part.isEmpty()) {
QByteArray decoded = QByteArray::fromBase64(base64Part.toLatin1());
if (!decoded.isEmpty() && pix.loadFromData(decoded)) {
// Successfully loaded base64 image data
} else {
// Malformed base64 or failed to load, fallback to icon theme
pix = QIcon::fromTheme(stringData).pixmap(PREVIEW_TITLE_HEIGHT, PREVIEW_TITLE_HEIGHT);
}
} else {
// Empty base64 part, fallback to icon theme
pix = QIcon::fromTheme(stringData).pixmap(PREVIEW_TITLE_HEIGHT, PREVIEW_TITLE_HEIGHT);
}
} else {
// "base64," not found, treat as icon name from theme
pix = QIcon::fromTheme(stringData).pixmap(PREVIEW_TITLE_HEIGHT, PREVIEW_TITLE_HEIGHT);
}
```
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
| QPixmap pix; | ||
| const QStringList strs = stringData.split("base64,"); | ||
| if (strs.size() == 2) { | ||
| // is base64 image data | ||
| pix.loadFromData(QByteArray::fromBase64(strs.at(1).toLatin1())); | ||
| } else { | ||
| // is (likely) icon name from theme | ||
| pix = QIcon::fromTheme(stringData).pixmap(PREVIEW_TITLE_HEIGHT, PREVIEW_TITLE_HEIGHT); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion: Splitting on 'base64,' may not handle malformed or unexpected input robustly.
If 'base64,' is missing or appears multiple times, the split may not work as intended. Input validation or a more reliable parsing method is recommended.
| QPixmap pix; | |
| const QStringList strs = stringData.split("base64,"); | |
| if (strs.size() == 2) { | |
| // is base64 image data | |
| pix.loadFromData(QByteArray::fromBase64(strs.at(1).toLatin1())); | |
| } else { | |
| // is (likely) icon name from theme | |
| pix = QIcon::fromTheme(stringData).pixmap(PREVIEW_TITLE_HEIGHT, PREVIEW_TITLE_HEIGHT); | |
| } | |
| QPixmap pix; | |
| int base64Idx = stringData.indexOf("base64,"); | |
| if (base64Idx != -1) { | |
| QString base64Part = stringData.mid(base64Idx + 7); // 7 = length of "base64," | |
| if (!base64Part.isEmpty()) { | |
| QByteArray decoded = QByteArray::fromBase64(base64Part.toLatin1()); | |
| if (!decoded.isEmpty() && pix.loadFromData(decoded)) { | |
| // Successfully loaded base64 image data | |
| } else { | |
| // Malformed base64 or failed to load, fallback to icon theme | |
| pix = QIcon::fromTheme(stringData).pixmap(PREVIEW_TITLE_HEIGHT, PREVIEW_TITLE_HEIGHT); | |
| } | |
| } else { | |
| // Empty base64 part, fallback to icon theme | |
| pix = QIcon::fromTheme(stringData).pixmap(PREVIEW_TITLE_HEIGHT, PREVIEW_TITLE_HEIGHT); | |
| } | |
| } else { | |
| // "base64," not found, treat as icon name from theme | |
| pix = QIcon::fromTheme(stringData).pixmap(PREVIEW_TITLE_HEIGHT, PREVIEW_TITLE_HEIGHT); | |
| } |
确保窗口预览图会使用来自图标主题的名称作为 fallback
Summary by Sourcery
Improve the window preview icon loader to handle both base64 image data and named icons by theme, renaming the method and adding fallback behavior and logging
Enhancements: