Skip to content

Commit 39f426d

Browse files
committed
feat: implement real-time trash file count monitoring
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
1 parent 4c11f38 commit 39f426d

File tree

3 files changed

+25
-5
lines changed

3 files changed

+25
-5
lines changed

panels/dock/taskmanager/package/AppItem.qml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ Item {
369369

370370
PanelToolTip {
371371
id: toolTip
372-
text: root.itemId === "dde-trash" ? root.name + "-" + taskmanager.Applet.getTrashTipText() : root.name
372+
text: root.itemId === "dde-trash" ? root.name + "-" + taskmanager.Applet.trashFilesCount : root.name
373373
toolTipX: DockPanelPositioner.x
374374
toolTipY: DockPanelPositioner.y
375375
}

panels/dock/taskmanager/taskmanager.cpp

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
Q_LOGGING_CATEGORY(taskManagerLog, "dde.shell.dock.taskmanager", QtDebugMsg)
3939

4040
#define Settings TaskManagerSettings::instance()
41+
#define TRASH_FILES_PATH (QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + "/Trash/files")
4142

4243
#define DESKTOPFILEFACTORY DesktopfileParserFactory< \
4344
DesktopFileAMParser, \
@@ -76,9 +77,11 @@ TaskManager::TaskManager(QObject *parent)
7677
: DContainment(parent)
7778
, AbstractTaskManagerInterface(nullptr)
7879
, m_windowFullscreen(false)
80+
, m_trashWatcher(nullptr)
7981
{
8082
connect(Settings, &TaskManagerSettings::allowedForceQuitChanged, this, &TaskManager::allowedForceQuitChanged);
8183
connect(Settings, &TaskManagerSettings::windowSplitChanged, this, &TaskManager::windowSplitChanged);
84+
setupTrashWatcher();
8285
}
8386

8487
bool TaskManager::load()
@@ -427,11 +430,10 @@ void TaskManager::saveDockElementsOrder(const QStringList &appIds)
427430
TaskManagerSettings::instance()->setDockedElements(newDockedElements);
428431
}
429432

430-
QString TaskManager::getTrashTipText()
433+
QString TaskManager::trashFilesCount()
431434
{
432435
int fileCount = 0;
433-
QString trashPath = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + "/Trash/files";
434-
QDir trashDir(trashPath);
436+
QDir trashDir(TRASH_FILES_PATH);
435437

436438
if (trashDir.exists()) {
437439
QStringList entries = trashDir.entryList(QDir::Files | QDir::Dirs | QDir::NoDotAndDotDot);
@@ -455,6 +457,19 @@ void TaskManager::modifyOpacityChanged()
455457
}
456458
}
457459

460+
void TaskManager::setupTrashWatcher()
461+
{
462+
QDir trashDir(TRASH_FILES_PATH);
463+
464+
if (!trashDir.exists()) {
465+
trashDir.mkpath(TRASH_FILES_PATH);
466+
}
467+
m_trashWatcher = new QFileSystemWatcher(this);
468+
m_trashWatcher->addPath(TRASH_FILES_PATH);
469+
connect(m_trashWatcher, &QFileSystemWatcher::directoryChanged,
470+
this, &TaskManager::trashFilesCountChanged);
471+
}
472+
458473
D_APPLET_CLASS(TaskManager)
459474
}
460475

panels/dock/taskmanager/taskmanager.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include "hoverpreviewproxymodel.h"
1414

1515
#include <QPointer>
16+
#include <QFileSystemWatcher>
1617

1718
namespace dock {
1819
class AppItem;
@@ -25,6 +26,7 @@ class TaskManager : public DS_NAMESPACE::DContainment, public AbstractTaskManage
2526
Q_PROPERTY(bool windowSplit READ windowSplit NOTIFY windowSplitChanged)
2627
Q_PROPERTY(bool windowFullscreen READ windowFullscreen NOTIFY windowFullscreenChanged)
2728
Q_PROPERTY(bool allowForceQuit READ allowForceQuit NOTIFY allowedForceQuitChanged)
29+
Q_PROPERTY(QString trashFilesCount READ trashFilesCount NOTIFY trashFilesCountChanged)
2830

2931
public:
3032
enum Roles {
@@ -95,16 +97,18 @@ class TaskManager : public DS_NAMESPACE::DContainment, public AbstractTaskManage
9597

9698
Q_INVOKABLE void activateWindow(uint32_t windowID);
9799
Q_INVOKABLE void saveDockElementsOrder(const QStringList &appIds);
98-
Q_INVOKABLE QString getTrashTipText();
100+
Q_INVOKABLE QString trashFilesCount();
99101

100102
private:
101103
void moveFilesToTrash(const QStringList& urls);
104+
void setupTrashWatcher();
102105

103106
Q_SIGNALS:
104107
void dataModelChanged();
105108
void windowSplitChanged();
106109
void windowFullscreenChanged(bool);
107110
void allowedForceQuitChanged();
111+
void trashFilesCountChanged();
108112

109113
private Q_SLOTS:
110114
void handleWindowAdded(QPointer<AbstractWindow> window);
@@ -117,6 +121,7 @@ private Q_SLOTS:
117121
DockGlobalElementModel *m_dockGlobalElementModel = nullptr;
118122
DockItemModel *m_itemModel = nullptr;
119123
HoverPreviewProxyModel *m_hoverPreviewModel = nullptr;
124+
QFileSystemWatcher *m_trashWatcher = nullptr;
120125
};
121126

122127
}

0 commit comments

Comments
 (0)