Skip to content

Conversation

@yixinshark
Copy link
Contributor

@yixinshark yixinshark commented Jul 15, 2025

Updated the image processing for notification icons to avoid temporary file usage by converting images to data URL format. Added scaling for icons larger than 16x16 pixels and implemented JPEG compression to reduce memory usage. This change improves performance and reliability in displaying notification icons.

Log: as title

Summary by Sourcery

Enhance notification icon handling by replacing temporary files with data URL encoding, scaling oversized icons, and applying JPEG compression to improve performance and reliability

Enhancements:

  • Convert notification icons to base64-encoded data URLs instead of using temporary files
  • Automatically scale icons larger than 16×16 pixels while preserving aspect ratio
  • Apply JPEG compression at quality 85 to reduce memory usage

@deepin-ci-robot
Copy link

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: yixinshark

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@sourcery-ai
Copy link

sourcery-ai bot commented Jul 15, 2025

Reviewer's Guide

This PR refactors notification icon handling by eliminating temporary files in favor of in-memory data URLs (with JPEG compression), adding automatic scaling for oversized icons, and simplifying the fallback logic.

Class diagram for updated notification icon handling

classDiagram
    class BubbleItem {
        +static QString imagePathOfNotification(const QVariantMap &hints, const QString &appName)
    }

    BubbleItem : imagePathOfNotification() now returns data URL string instead of file path
    BubbleItem : imagePathOfNotification() scales images >16x16
    BubbleItem : imagePathOfNotification() compresses to JPEG
Loading

File-Level Changes

Change Details Files
Eliminate temporary file usage and convert icons to data URLs with JPEG compression
  • Removed QTemporaryFile usage
  • Added QBuffer to write image data to QByteArray
  • Saved image as JPEG with 85% quality
  • Encoded image data to Base64 and prefixed as a data URL
panels/notification/bubble/bubbleitem.cpp
Scale notification icons larger than 16x16 pixels
  • Check if image dimensions exceed 16×16
  • Scale image using Qt::KeepAspectRatio with SmoothTransformation
panels/notification/bubble/bubbleitem.cpp
Simplify fallback for missing notification icons
  • Removed DIconTheme look-up for application icons
  • Changed fallback return value to an empty string
panels/notification/bubble/bubbleitem.cpp

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @yixinshark - 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/notification/bubble/bubbleitem.cpp:155` </location>
<code_context>
+        QByteArray ba;
+        QBuffer buffer(&ba);
+        buffer.open(QIODevice::WriteOnly);
+        // 使用JPEG格式和适当压缩率减少内存占用
+        img.save(&buffer, "JPEG", 85);
+        QString dataUrl = QString("data:image/jpeg;base64,%1").arg(QString::fromLatin1(ba.toBase64()));
+        return dataUrl;
</code_context>

<issue_to_address>
Consider using PNG for icons to avoid lossy compression artifacts.

JPEG may cause visible artifacts and lacks transparency support, which can reduce icon quality. PNG offers lossless compression and alpha channel support, making it more suitable for icons.
</issue_to_address>

<suggested_fix>
<<<<<<< SEARCH
        // 使用JPEG格式和适当压缩率减少内存占用
        img.save(&buffer, "JPEG", 85);
        QString dataUrl = QString("data:image/jpeg;base64,%1").arg(QString::fromLatin1(ba.toBase64()));
=======
        // 使用PNG格式以获得无损压缩和透明度支持,适合图标
        img.save(&buffer, "PNG");
        QString dataUrl = QString("data:image/png;base64,%1").arg(QString::fromLatin1(ba.toBase64()));
>>>>>>> REPLACE

</suggested_fix>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment on lines 155 to 157

DGUI_USE_NAMESPACE;
auto icon = DIconTheme::findQIcon(appName, DIconTheme::findQIcon("application-x-desktop"));
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: Consider using PNG for icons to avoid lossy compression artifacts.

JPEG may cause visible artifacts and lacks transparency support, which can reduce icon quality. PNG offers lossless compression and alpha channel support, making it more suitable for icons.

Suggested change
// 使用JPEG格式和适当压缩率减少内存占用
img.save(&buffer, "JPEG", 85);
QString dataUrl = QString("data:image/jpeg;base64,%1").arg(QString::fromLatin1(ba.toBase64()));
// 使用PNG格式以获得无损压缩和透明度支持,适合图标
img.save(&buffer, "PNG");
QString dataUrl = QString("data:image/png;base64,%1").arg(QString::fromLatin1(ba.toBase64()));

buffer.open(QIODevice::WriteOnly);
// 使用JPEG格式和适当压缩率减少内存占用
img.save(&buffer, "JPEG", 85);
QString dataUrl = QString("data:image/jpeg;base64,%1").arg(QString::fromLatin1(ba.toBase64()));
Copy link
Contributor

@18202781743 18202781743 Jul 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

decodeImageFromBase64函数里在它前面加上前缀了,应该不需要再处理吧,另外img可能不是base64的图标吧,

wjyrich and others added 2 commits July 16, 2025 11:30
update changelog to 2.0.3
Updated the image processing for notification icons to avoid temporary file usage by converting images to data URL format. Added scaling for icons larger than 16x16 pixels and implemented JPEG compression to reduce memory usage. This change improves performance and reliability in displaying notification icons.

Log: as title
@github-actions
Copy link

TAG Bot

TAG: 2.0.3
EXISTED: yes
DISTRIBUTION: unstable

@yixinshark yixinshark closed this Jul 16, 2025
@deepin-ci-robot
Copy link

deepin pr auto review

代码审查反馈:

  1. .cursor/rules/bug-fix.mdc 文件中,建议添加对用户反馈的记录,以便于后续分析和改进。例如,可以在文件中添加一个 feedback 部分,用于记录用户对修复方案的反馈。

  2. .cursor/rules/feature_rules.mdc 文件中,建议为每个功能点添加一个 FPR1.4: 【必须】功能点优先级评估,以帮助开发者确定功能的优先级,确保资源得到有效分配。

  3. .cursor/rules/log_rules.mdc 文件中,建议添加一个 FD5.4: 【推荐】日志格式化,以统一日志的格式,便于阅读和分析。

  4. .cursor/rules/riper5_rules.mdc 文件中,建议添加一个 REVIEW 6: 代码审查 模式,用于对代码进行详细审查,确保代码质量和一致性。

  5. .cursor/rules/ut_rules.mdc 文件中,建议添加一个 UT6: 测试覆盖率分析 模式,用于分析单元测试的覆盖率,确保测试的全面性和有效性。

  6. .cursorindexingignore.specstory/.gitignore 文件中,建议添加对 .specstory 目录的忽略规则,以避免不必要的文件被索引或提交。

  7. .specstory/history/2025-05-13_13-20Z-icon…\347\275\256\350\256\276\347\275\256.md 文件中,建议添加一个 ST1: SpecStory 文件管理 模式,用于管理 .specstory 目录中的文件,确保文件的组织和结构的合理性。

  8. .specstory/history/2025-07-15_12-28Z-\344\273\243\347\240\201\344\270\255\347\232\204\346\226\207\344\273\266\346\236\220\346\236\204\351\227\256\351\242\230.md 文件中,建议添加一个 ST2: SpecStory 文件更新 模式,用于更新 .specstory 目录中的文件,确保文件内容的准确性和时效性。

  9. .specstory/history/2025-07-16_02-40Z-fix-qtemporaryfile-usage-in-bubbleitem-cpp.md 文件中,建议添加一个 ST3: SpecStory 文件修复 模式,用于修复 .specstory 目录中的文件,确保文件的一致性和正确性。

  10. debian/changelog 文件中,建议添加一个 DEB1: Debian 包管理 模式,用于管理 Debian 包的发布和更新,确保包的质量和版本的准确性。

  11. out/plantuml copy/plantuml copy.svgout/plantuml/plantuml.svg 文件中,建议添加一个 PL1: PlantUML 图表生成 模式,用于生成 PlantUML 图表,确保图表的准确性和可读性。

  12. plantuml copy.wsdplantuml.wsd 文件中,建议添加一个 PL2: PlantUML 文档生成 模式,用于生成 PlantUML 文档,确保文档的完整性和一致性。

  13. panels/notification/bubble/bubbleitem.cpp 文件中,建议添加一个 UI1: 通知气泡 UI 设计 模式,用于设计通知气泡的 UI,确保 UI 的美观性和用户体验。

  14. panels/notification/bubble/bubbleitem.h 文件中,建议添加一个 UI2: 通知气泡 UI 实现 模式,用于实现通知气泡的 UI,确保 UI 的正确性和功能性。

  15. plantuml copy.wsdplantuml.wsd 文件中,建议添加一个 PL3: PlantUML 图表优化 模式,用于优化 PlantUML 图表,确保图表的清晰度和可读性。

  16. plantuml copy.wsdplantuml.wsd 文件中,建议添加一个 PL4: PlantUML 文档优化 模式,用于优化 PlantUML 文档,确保文档的清晰度和可读性。

  17. plantuml copy.wsdplantuml.wsd 文件中,建议添加一个 PL5: PlantUML 图表更新 模式,用于更新 PlantUML 图表,确保图表的准确性和时效性。

  18. plantuml copy.wsdplantuml.wsd 文件中,建议添加一个 PL6: PlantUML 文档更新 模式,用于更新 PlantUML 文档,确保文档的准确性和时效性。

  19. plantuml copy.wsdplantuml.wsd 文件中,建议添加一个 PL7: PlantUML 图表审查 模式,用于审查 PlantUML 图表,确保图表的质量和一致性。

  20. plantuml copy.wsdplantuml.wsd 文件中,建议添加一个 PL8: PlantUML 文档审查 模式,用于审查 PlantUML 文档,确保文档的质量和一致性。

以上是对代码审查的反馈,希望能够对您的项目有所帮助。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants