Skip to content

Conversation

@wjyrich
Copy link
Contributor

@wjyrich wjyrich commented Oct 21, 2025

  1. Replace static trash tip text with dynamic file count property
  2. Add QFileSystemWatcher to monitor trash directory changes
  3. Create setupTrashWatcher method to initialize directory monitoring
  4. Define TRASH_FILES_PATH constant for consistent trash path usage
  5. Add trashFilesCountChanged signal to notify UI of updates
  6. Ensure trash directory exists before setting up watcher

feat: 实现实时回收站文件数量监控

  1. 将静态回收站提示文本替换为动态文件计数属性
  2. 添加 QFileSystemWatcher 监控回收站目录变化
  3. 创建 setupTrashWatcher 方法初始化目录监控
  4. 定义 TRASH_FILES_PATH 常量确保回收站路径一致性
  5. 添加 trashFilesCountChanged 信号通知 UI 更新
  6. 在设置监控器前确保回收站目录存在

PMS: BUG-336825

Summary by Sourcery

Implement real-time Trash file count monitoring by adding a dynamic property, defining a constant path, setting up a filesystem watcher that emits updates, and updating the UI to reflect live count changes

New Features:

  • Add trashFilesCount Q_PROPERTY with dynamic computation of Trash directory file count
  • Introduce TRASH_FILES_PATH constant and setupTrashWatcher method to ensure the directory exists, watch it with QFileSystemWatcher, and emit trashFilesCountChanged on updates
  • Update AppItem.qml tooltip to display trashFilesCount instead of static tip text

@sourcery-ai
Copy link

sourcery-ai bot commented Oct 21, 2025

Reviewer's Guide

This PR implements real-time trash file count monitoring by introducing a centralized TRASH_FILES_PATH constant, integrating a QFileSystemWatcher to track changes in the trash directory, and replacing the static trash tip text with a dynamic trashFilesCount property and signal for seamless UI updates.

Sequence diagram for real-time trash file count monitoring and UI update

sequenceDiagram
participant TaskManager
participant QFileSystemWatcher
participant UI
TaskManager->>QFileSystemWatcher: setupTrashWatcher()
QFileSystemWatcher-->>TaskManager: directoryChanged signal
TaskManager-->>UI: trashFilesCountChanged signal
UI->>TaskManager: Read trashFilesCount property
Loading

Updated class diagram for TaskManager with trash monitoring

classDiagram
class TaskManager {
  +QString trashFilesCount()
  +void setupTrashWatcher()
  +signal trashFilesCountChanged()
  -QFileSystemWatcher *m_trashWatcher
}
class QFileSystemWatcher
TaskManager --> QFileSystemWatcher : uses
Loading

File-Level Changes

Change Details Files
Centralize trash directory path usage
  • Define TRASH_FILES_PATH constant
  • Replace inline trash path literals with TRASH_FILES_PATH
panels/dock/taskmanager/taskmanager.cpp
panels/dock/taskmanager/taskmanager.h
Add real-time monitoring via QFileSystemWatcher
  • Include QFileSystemWatcher header and add m_trashWatcher member
  • Implement setupTrashWatcher to initialize watcher and ensure directory exists
  • Invoke setupTrashWatcher in constructor and connect directoryChanged to trashFilesCountChanged
panels/dock/taskmanager/taskmanager.cpp
panels/dock/taskmanager/taskmanager.h
Replace static trash tip with dynamic property
  • Rename getTrashTipText method to trashFilesCount and mark as Q_INVOKABLE
  • Add Q_PROPERTY(trashFilesCount) and trashFilesCountChanged signal
  • Update QML tooltip binding to use trashFilesCount
panels/dock/taskmanager/taskmanager.cpp
panels/dock/taskmanager/taskmanager.h
panels/dock/taskmanager/package/AppItem.qml

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 there - I've reviewed your changes - here's some feedback:

  • Replace the TRASH_FILES_PATH macro with a static const QString (or constexpr) and build the path using QDir::cleanPath or QDir::separator instead of hard-coding "/" for better readability and portability.
  • Emit trashFilesCountChanged() once after setupTrashWatcher runs so the UI receives the initial file count immediately on startup.
  • Consider changing trashFilesCount to expose an integer property instead of a QString so QML can format the count directly and maintain semantic clarity.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Replace the TRASH_FILES_PATH macro with a static const QString (or constexpr) and build the path using QDir::cleanPath or QDir::separator instead of hard-coding "/" for better readability and portability.
- Emit trashFilesCountChanged() once after setupTrashWatcher runs so the UI receives the initial file count immediately on startup.
- Consider changing trashFilesCount to expose an integer property instead of a QString so QML can format the count directly and maintain semantic clarity.

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.

1. Move tooltip text assignment from property initialization to
onTriggered handler
2. This ensures the trash tip text is dynamically updated when tooltip
is shown
3. Fixes potential stale trash status display in tooltips
4. Maintains same functionality but with proper timing

fix: 将工具提示文本赋值移动到显示处理程序

1. 将工具提示文本赋值从属性初始化移动到 onTriggered 处理程序
2. 确保垃圾桶提示文本在工具提示显示时动态更新
3. 修复工具提示中可能显示过时垃圾桶状态的问题
4. 保持相同功能但具有正确的时机控制

PMS: BUG-336825
@deepin-ci-robot
Copy link

deepin pr auto review

这是一个关于 Qt/QML 代码的修改,主要涉及到了工具提示(tooltip)文本的设置时机。让我来分析一下这个改动:

  1. 修改内容分析:
  • 原代码将 tooltip 的 text 属性直接设置在 PanelToolTip 组件的声明中
  • 新代码将 text 的设置移到了 tooltip 打开之前(onTriggered事件中)
  1. 改进点:
  • 性能优化:避免了不必要的重复计算。之前的代码会在组件初始化时就计算文本,即使 tooltip 不一定会被显示。现在改为在需要显示时才计算。
  • 数据实时性:确保显示的文本是最新的。对于垃圾桶这种可能状态会变化的项(比如空间使用情况),实时更新更准确。
  • 逻辑清晰:将相关操作集中在一起,代码更容易维护。
  1. 建议和注意事项:
  • 确保在 onTriggered 中设置 text 不会造成明显的延迟,因为用户期望 tooltip 能即时显示
  • 建议添加注释说明为什么要在运行时设置文本,以便其他开发者理解这个设计决策
  • 如果 getTrashTipText() 是一个耗时操作,可能需要考虑缓存机制
  1. 安全性:
  • 这个修改不会带来安全风险,只是改变了文本设置的时机
  • 仍然保持了原来的条件判断逻辑,确保不同类型的 item 显示正确的文本

总的来说,这是一个合理的优化,提高了代码的效率和可维护性。建议采纳这个修改。

@deepin-ci-robot
Copy link

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: 18202781743, wjyrich

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

@wjyrich wjyrich merged commit c2e93df into linuxdeepin:master Oct 21, 2025
9 of 11 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