fix: update trash icon dynamically based on trash state - #1701
Conversation
1. Add TrashMonitor class that uses GIO to monitor trash directory changes 2. Connect trash monitor signals to update trash app icon in real-time 3. Switch icon between "user-trash" and "user-trash-full" based on trash emptiness 4. Handle dataChanged signal to refresh icon when app item properties change 5. Add GLIB2/GIO dependency and Qt Concurrent library to build configuration Log: Trash icon now updates dynamically when trash is emptied or filled Influence: 1. Test trash icon displays correctly when trash is empty (user-trash icon) 2. Delete a file and verify icon changes to full state (user-trash- full icon) 3. Empty the trash and verify icon changes back to empty state 4. Test multiple files being deleted simultaneously 5. Verify trash icon updates when files are restored from trash 6. Test with slow file systems to ensure no UI lag during updates 7. Verify no memory leaks during extended monitoring fix: 根据回收站状态动态更新回收站图标 1. 添加 TrashMonitor 类,使用 GIO 监控回收站目录变化 2. 连接回收站监控信号,实时更新回收站应用图标 3. 根据回收站是否为空在 "user-trash" 和 "user-trash-full" 图标间切换 4. 处理 dataChanged 信号,在应用项属性变化时刷新图标 5. 在构建配置中添加 GLIB2/GIO 依赖和 Qt Concurrent 库 Log: 回收站图标会随回收站清空或填充状态动态更新 Influence: 1. 测试回收站为空时图标显示正常(user-trash 图标) 2. 删除文件后验证图标是否变为满状态(user-trash-full 图标) 3. 清空回收站后验证图标是否恢复为空状态 4. 测试同时删除多个文件的情况 5. 验证从回收站恢复文件后图标是否正确更新 6. 在慢速文件系统上测试,确保更新过程中无 UI 卡顿 7. 验证长时间监控过程中无内存泄漏 PMS: BUG-285725
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: wjyrich 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 GuideThis PR introduces a GIO-based TrashMonitor that tracks trash:/// item count and wires it into AMAppItemModel so the launcher’s trash app icon switches between "user-trash" and "user-trash-full" in real time based on trash emptiness, with build configuration updated to include GLIB2/GIO and Qt Concurrent dependencies. Sequence diagram for dynamic trash icon updatessequenceDiagram
participant GIO
participant TrashMonitor
participant AMAppItemModel
participant AMAppItem
GIO->>TrashMonitor: onTrashChanged(eventType)
TrashMonitor->>TrashMonitor: updateState()
TrashMonitor-->>AMAppItemModel: emptyChanged(empty)
AMAppItemModel->>AMAppItemModel: updateTrashIcon()
AMAppItemModel->>AMAppItem: setAppIconName(iconName)
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
deepin pr auto review★ 总体评分:85分■ 【总体评价】
■ 【详细分析】
■ 【改进建议代码示例】 // amappitemmodel.h
namespace apps
{
class AMAppItem;
class TrashMonitor;
class AMAppItemModel : public AppItemModel
{
Q_OBJECT
// ... 其他代码
private:
void updateTrashIcon();
bool m_ready;
ObjectManager *m_manager;
TrashMonitor *m_trashMonitor;
int m_trashRow = -1; // 新增:缓存回收站行号
};
}// amappitemmodel.cpp
AMAppItemModel::AMAppItemModel(QObject *parent)
: AppItemModel(parent)
, m_manager(new ObjectManager("org.desktopspec.ApplicationManager1", "/org/desktopspec/ApplicationManager1", QDBusConnection::sessionBus(), this))
, m_trashMonitor(new TrashMonitor(this))
, m_ready(false)
, m_trashRow(-1)
{
// ... 其他初始化代码
connect(m_trashMonitor, &TrashMonitor::emptyChanged, this, &AMAppItemModel::updateTrashIcon);
connect(this, &QAbstractItemModel::dataChanged, this,
[this](const QModelIndex &topLeft, const QModelIndex &bottomRight, const QList<int> &roles) {
// O(1) 范围预判,避免每次 dataChanged 都执行 O(N) 的 match
if (m_trashRow >= 0 && (m_trashRow < topLeft.row() || m_trashRow > bottomRight.row()))
return;
const auto trashIndex = match(index(0, 0), AppItemModel::DesktopIdRole,
QStringLiteral("dde-trash"), 1, Qt::MatchExactly).value(0);
if (trashIndex.isValid()) {
m_trashRow = trashIndex.row(); // 更新缓存
if (m_trashRow >= topLeft.row() && m_trashRow <= bottomRight.row()
&& (roles.isEmpty() || roles.contains(AppItemModel::IconNameRole))) {
updateTrashIcon();
}
} else {
m_trashRow = -1; // 缓存失效重置
}
});
// ... 其他代码
}
void AMAppItemModel::updateTrashIcon()
{
auto *trash = appItem(QStringLiteral("dde-trash"));
if (!trash) {
m_trashRow = -1;
return;
}
const QString iconName = m_trashMonitor->isEmpty()
? QStringLiteral("user-trash")
: QStringLiteral("user-trash-full");
if (trash->appIconName() != iconName)
trash->setAppIconName(iconName);
// 同步更新缓存行号
m_trashRow = trash->index().row();
} |
让文管改一下,更新那个Icon么? |
对,或者即便是我们也就都可以走同一套方案,不用在 amappitemmodel 里特判了。 |
Log: Trash icon now updates dynamically when trash is emptied or filled
Influence:
fix: 根据回收站状态动态更新回收站图标
Log: 回收站图标会随回收站清空或填充状态动态更新
Influence:
PMS: BUG-285725
Summary by Sourcery
Monitor the system trash directory and update the trash app icon in the apps applet according to whether the trash is empty or contains items.
New Features:
Enhancements:
Build: