Skip to content

Conversation

@yixinshark
Copy link
Contributor

@yixinshark yixinshark commented Jul 16, 2025

as title

Log: as title

Summary by Sourcery

Convert notification icon handling to generate and return base64 data URIs instead of writing temporary files and using theme fallbacks

Enhancements:

  • Replace image decoding function with one that encodes QImage into a base64 data URI
  • Add regex-based detection of inline data URIs for notification icons
  • Simplify imagePathOfNotification to return data URIs directly and drop temporary file creation and icon theme fallback

@deepin-ci-robot
Copy link

deepin pr auto review

关键摘要:

  • decodeImageFromBase64 函数被重命名为 decodeImageToBase64,但函数签名表明它现在应该是一个将 QImage 转换为 Base64 编码字符串的函数,而不是解码。
  • decodeImageToBase64 函数中的 format 参数默认值为 "PNG",这可能会导致与预期不符的行为,如果调用者没有指定格式。
  • imagePathOfNotification 函数中新增了对 Base64 图像数据的检查,但未处理非 Base64 图像数据的情况。
  • imagePathOfNotification 函数中的 DIconTheme 使用被移除,可能导致图标查找失败。
  • imagePathOfNotification 函数返回 QString() 而不是 QString(""),这可能是一个错误,因为 QString() 创建了一个空字符串,而 QString("") 创建了一个空字符串对象。

是否建议立即修改:

  • 应该立即修正 decodeImageToBase64 函数的命名和签名,使其与函数的实际功能相符。
  • 应该确保 format 参数的默认值是正确的,或者提供一种方式让调用者指定格式。
  • 应该处理 imagePathOfNotification 函数中非 Base64 图像数据的情况,或者提供一种方式来处理这种情况。
  • 应该恢复 DIconTheme 的使用,或者提供一种替代方案来查找图标。
  • 应该将 QString() 修改为 QString(""),以避免潜在的混淆。

@sourcery-ai
Copy link

sourcery-ai bot commented Jul 16, 2025

Reviewer's Guide

Refactored notification icon handling to fully support inline base64 data URIs, replace temporary file usage with a direct encoding function, and streamline fallback behavior.

File-Level Changes

Change Details Files
Replace legacy decoding with encode utility
  • Removed decodeImageFromBase64 function
  • Added decodeImageToBase64 that saves QImage to a QBuffer and returns a data URI
  • Included QBuffer header
panels/notification/bubble/bubbleitem.cpp
Refactor imagePathOfNotification to detect and return data URIs
  • Added QRegularExpression header
  • Inserted regex check for base64 data URIs to return inline image data
  • Replaced temporary file save path logic with direct use of decodeImageToBase64
panels/notification/bubble/bubbleitem.cpp
Simplify fallback logic when no icon is found
  • Removed DIconTheme-based fallback code
  • Dropped QTemporaryFile usage
  • Updated function to return an empty string for missing icons
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 - here's some feedback:

  • The method decodeImageToBase64 is actually encoding an image into a base64 data URI—consider renaming it to something like encodeImageToBase64 and add a null‐image guard to avoid producing invalid URIs.
  • The imagePathOfNotification change removed the fallback to the application-x-desktop icon; please reintroduce a sensible default return value so you don’t end up returning an empty string when no image is provided.
  • You recreate the QRegularExpression on every call—consider making it a static or precompiled pattern to avoid unnecessary overhead.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The method `decodeImageToBase64` is actually encoding an image into a base64 data URI—consider renaming it to something like `encodeImageToBase64` and add a null‐image guard to avoid producing invalid URIs.
- The `imagePathOfNotification` change removed the fallback to the application-x-desktop icon; please reintroduce a sensible default return value so you don’t end up returning an empty string when no image is provided.
- You recreate the QRegularExpression on every call—consider making it a static or precompiled pattern to avoid unnecessary overhead.

## Individual Comments

### Comment 1
<location> `panels/notification/bubble/bubbleitem.cpp:96` </location>
<code_context>
 }

-static QImage decodeImageFromBase64(const QString &arg)
+static QString decodeImageToBase64(const QImage &image, const char *format = "PNG")
 {
-    if (arg.startsWith("data:image/")) {
</code_context>

<issue_to_address>
Function name may be misleading regarding its purpose.

Consider renaming the function to encodeImageToBase64 or imageToBase64Uri to better reflect that it encodes a QImage to a base64 data URI.

Suggested implementation:

```cpp
static QString encodeImageToBase64(const QImage &image, const char *format = "PNG")

```

If this function is called elsewhere in the file or project, those call sites should also be updated to use the new name `encodeImageToBase64`.
</issue_to_address>

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.

if (arg.startsWith("data:image/")) {
// iconPath is a string representing an inline image.
QStringList strs = arg.split("base64,");
if (strs.length() == 2) {
Copy link

Choose a reason for hiding this comment

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

suggestion: Function name may be misleading regarding its purpose.

Consider renaming the function to encodeImageToBase64 or imageToBase64Uri to better reflect that it encodes a QImage to a base64 data URI.

Suggested implementation:

static QString encodeImageToBase64(const QImage &image, const char *format = "PNG")

If this function is called elsewhere in the file or project, those call sites should also be updated to use the new name encodeImageToBase64.

@deepin-ci-robot
Copy link

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: 18202781743, 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

@yixinshark
Copy link
Contributor Author

/forcemerge

@deepin-bot
Copy link

deepin-bot bot commented Jul 16, 2025

This pr force merged! (status: blocked)

@deepin-bot deepin-bot bot merged commit 203db7a into linuxdeepin:master Jul 16, 2025
7 of 10 checks passed
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.

3 participants