Skip to content

Conversation

@yixinshark
Copy link
Contributor

@yixinshark yixinshark commented Jul 16, 2025

as title

Log: as title

Summary by Sourcery

Enhance notification icon handling by generating unique temporary icon files in the system temp directory, caching and cleaning them up in the BubbleItem lifecycle, and delegating fallback to the UI when no icon is available

Enhancements:

  • Generate unique notification icon files using QTemporaryFile in the system temp directory with debug logging
  • Cache the temporary icon path in BubbleItem and return it on subsequent calls to appIcon
  • Introduce a BubbleItem destructor to remove the temporary icon file on object destruction
  • Remove in-code fallback to a default theme icon to allow the UI to handle missing icons

@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 16, 2025

Reviewer's Guide

This PR refactors notification icon handling in BubbleItem by improving temporary file creation and cleanup, caching icon paths, and streamlining fallback logic to return an empty path when no icon is available.

Class diagram for updated BubbleItem icon handling

classDiagram
    class BubbleItem {
        +BubbleItem(QObject* parent = nullptr)
        +BubbleItem(const NotifyEntity &entity, QObject* parent = nullptr)
        +~BubbleItem()
        +void setEntity(const NotifyEntity &entity)
        +qint64 id() const
        +uint bubbleId() const
        +QString appName() const
        +QString appIcon()
        +QString summary() const
        +QString body() const
        +uint replacesId() const
        +bool m_enablePreview
        +QVariantList m_actions
        +QString m_defaultAction
        +QString m_tempIconPath
    }
Loading

Flow diagram for enhanced notification icon handling and cleanup

flowchart TD
    A[Notification received] --> B{Does entity have appIcon?}
    B -- Yes --> C[Return appIcon]
    B -- No --> D{Is m_tempIconPath set and file exists?}
    D -- Yes --> E[Return m_tempIconPath]
    D -- No --> F[Call imagePathOfNotification]
    F --> G[Set m_tempIconPath]
    G --> H[Return m_tempIconPath]

    subgraph Cleanup
        I[BubbleItem destroyed]
        J{m_tempIconPath exists?}
        I --> J
        J -- Yes --> K[Remove temp icon file]
        J -- No --> L[Do nothing]
    end
Loading

File-Level Changes

Change Details Files
Enhanced temporary icon file handling in imagePathOfNotification
  • Imported QDir and QFile for file path management
  • Use QTemporaryFile with a custom filename template and disable auto-removal
  • Open the temporary file, save decoded QImage to it, log its path, and return the path
  • Simplify fallback logic to return an empty string instead of an icon name
panels/notification/bubble/bubbleitem.cpp
Added destructor to cleanup temporary icon files
  • Declared ~BubbleItem() in the header
  • Implemented destructor to check for and remove m_tempIconPath if it exists
panels/notification/bubble/bubbleitem.cpp
panels/notification/bubble/bubbleitem.h
Refactored appIcon method to cache and reuse icon path
  • Removed const qualifier from appIcon() to allow modifying m_tempIconPath
  • Check for existing valid m_tempIconPath and return it if present
  • Assign m_tempIconPath on first call via imagePathOfNotification
  • Added comment noting UI can fallback when path is empty
panels/notification/bubble/bubbleitem.cpp
panels/notification/bubble/bubbleitem.h

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:

  • Instead of returning an empty string when image decoding fails, return the default application icon name to preserve the previous fallback behavior.
  • You changed appIcon() from const to non-const; consider restoring const-correctness or documenting why mutation on a const object is acceptable.
  • Add error logging for cases where the temporary file cannot be created or the image cannot be saved to assist in troubleshooting failures.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Instead of returning an empty string when image decoding fails, return the default application icon name to preserve the previous fallback behavior.
- You changed appIcon() from const to non-const; consider restoring const-correctness or documenting why mutation on a const object is acceptable.
- Add error logging for cases where the temporary file cannot be created or the image cannot be saved to assist in troubleshooting failures.

## Individual Comments

### Comment 1
<location> `panels/notification/bubble/bubbleitem.cpp:177` </location>
<code_context>
     setEntity(entity);
 }

+BubbleItem::~BubbleItem()
+{
+    // clean up temporary icon file.
</code_context>

<issue_to_address>
Destructor cleanup may not handle all edge cases for temporary file removal.

Currently, only the most recent temp file is removed. If multiple temp files can be created, consider tracking all of them or restricting creation to a single file.
</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 (!m_tempIconPath.isEmpty() && QFile::exists(m_tempIconPath)) {
QFile::remove(m_tempIconPath);
}
}
Copy link

Choose a reason for hiding this comment

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

issue: Destructor cleanup may not handle all edge cases for temporary file removal.

Currently, only the most recent temp file is removed. If multiple temp files can be created, consider tracking all of them or restricting creation to a single file.

@yixinshark yixinshark force-pushed the fix-enhanceTempIcon branch from bc7b1c7 to 5e04c51 Compare July 16, 2025 04:34
@yixinshark yixinshark force-pushed the fix-enhanceTempIcon branch from 5e04c51 to 0047a56 Compare July 16, 2025 04:37
@deepin-ci-robot
Copy link

deepin pr auto review

关键摘要:

  • imagePathOfNotification函数中,QTemporaryFile的文件名模式应该确保文件名的唯一性,避免潜在的文件名冲突。
  • imagePathOfNotification函数中的qDebug日志应该使用qCDebug宏来代替,以便更好地控制日志输出。
  • BubbleItem类中的appIcon函数应该标记为const,因为它没有修改任何成员变量。
  • BubbleItem类中的appIcon函数在返回之前应该检查m_tempIconPath是否为空,以避免不必要的文件操作。
  • BubbleItem类中的appIcon函数在返回之前应该检查m_tempIconPath是否存在,以避免返回无效的文件路径。
  • BubbleItem类中的appIcon函数在返回之前应该检查img.save(filePath)的返回值,以确保文件保存成功。

是否建议立即修改:

@yixinshark yixinshark closed this Jul 16, 2025
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.

2 participants