Skip to content

Commit c2cf6a1

Browse files
wjyrichdeepin-bot[bot]
authored andcommitted
feat: implement trash empty state detection
1. Add isTrashEmpty() method to detect if trash is empty using gio command 2. Modify context menu to disable "Clean Trash" option when trash is empty 3. Update trash tip text generation to use new queryTrashCountAndEmpty method 4. Add property binding to dynamically enable/disable menu items based on trash state 5. Use gio trash --list command for more reliable trash content detection feat: 实现回收站空状态检测 1. 添加 isTrashEmpty() 方法使用 gio 命令检测回收站是否为空 2. 修改上下文菜单,在回收站为空时禁用"清空回收站"选项 3. 更新回收站提示文本生成以使用新的 queryTrashCountAndEmpty 方法 4. 添加属性绑定以根据回收站状态动态启用/禁用菜单项 5. 使用 gio trash --list 命令进行更可靠的回收站内容检测 PMS: BUG-335901
1 parent f167635 commit c2cf6a1

File tree

3 files changed

+31
-9
lines changed

3 files changed

+31
-9
lines changed

panels/dock/taskmanager/package/AppItem.qml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,13 +137,17 @@ Item {
137137
Loader {
138138
id: contextMenuLoader
139139
active: false
140+
property bool trashEmpty: true
140141
sourceComponent: LP.Menu {
141142
id: contextMenu
142143
Instantiator {
143144
id: menuItemInstantiator
144145
model: JSON.parse(menus)
145146
delegate: LP.MenuItem {
146147
text: modelData.name
148+
enabled: (root.itemId === "dde-trash" && modelData.id === "clean-trash")
149+
? !contextMenuLoader.trashEmpty
150+
: true
147151
onTriggered: {
148152
TaskManager.requestNewInstance(root.modelIndex, modelData.id);
149153
}
@@ -319,6 +323,7 @@ Item {
319323
onClicked: function (mouse) {
320324
let index = root.modelIndex;
321325
if (mouse.button === Qt.RightButton) {
326+
contextMenuLoader.trashEmpty = TaskManager.isTrashEmpty()
322327
contextMenuLoader.active = true
323328
MenuHelper.openMenu(contextMenuLoader.item)
324329
} else {

panels/dock/taskmanager/taskmanager.cpp

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include <QStringLiteral>
2626
#include <QUrl>
2727
#include <QStandardPaths>
28+
#include <QProcess>
2829

2930
#include <appletbridge.h>
3031
#include <DSGApplication>
@@ -436,16 +437,30 @@ void TaskManager::saveDockElementsOrder(const QStringList &appIds)
436437

437438
QString TaskManager::getTrashTipText()
438439
{
439-
int fileCount = 0;
440-
QString trashPath = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + "/Trash/files";
441-
QDir trashDir(trashPath);
442-
443-
if (trashDir.exists()) {
444-
QStringList entries = trashDir.entryList(QDir::Files | QDir::Dirs | QDir::NoDotAndDotDot);
445-
fileCount = entries.size();
446-
}
440+
const auto count = queryTrashCount();
441+
return tr("%1 files").arg(count);
442+
}
443+
444+
bool TaskManager::isTrashEmpty() const
445+
{
446+
return queryTrashCount() == 0;
447+
}
447448

448-
return tr("%1 files").arg(fileCount);
449+
int TaskManager::queryTrashCount() const
450+
{
451+
int count = 0;
452+
453+
QProcess gio;
454+
gio.start("gio", QStringList() << "trash" << "--list");
455+
if (gio.waitForFinished(1000) && gio.exitStatus() == QProcess::NormalExit && gio.exitCode() == 0) {
456+
const QByteArray &out = gio.readAllStandardOutput();
457+
const QList<QByteArray> lines = out.split('\n');
458+
for (const QByteArray &l : lines) {
459+
if (!l.trimmed().isEmpty()) count++;
460+
}
461+
return count;
462+
}
463+
return count;
449464
}
450465

451466
void TaskManager::modifyOpacityChanged()

panels/dock/taskmanager/taskmanager.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ class TaskManager : public DS_NAMESPACE::DContainment, public AbstractTaskManage
9797
Q_INVOKABLE void saveDockElementsOrder(const QStringList &appIds);
9898
Q_INVOKABLE QString getTrashTipText();
9999

100+
Q_INVOKABLE bool isTrashEmpty() const;
100101
Q_SIGNALS:
101102
void dataModelChanged();
102103
void windowSplitChanged();
@@ -114,6 +115,7 @@ private Q_SLOTS:
114115
DockGlobalElementModel *m_dockGlobalElementModel = nullptr;
115116
DockItemModel *m_itemModel = nullptr;
116117
HoverPreviewProxyModel *m_hoverPreviewModel = nullptr;
118+
int queryTrashCount() const;
117119
};
118120

119121
}

0 commit comments

Comments
 (0)