-
Notifications
You must be signed in to change notification settings - Fork 55
feat: implement trash empty state detection #1323
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Reviewer's GuideThis PR implements a reliable trash-empty detection feature by introducing a Sequence diagram for context menu trash state detection and menu item enablingsequenceDiagram
participant User as actor User
participant AppItem.qml
participant TaskManager
User->>AppItem.qml: Right-clicks on trash icon
AppItem.qml->>TaskManager: isTrashEmpty()
TaskManager->>TaskManager: queryTrashCountAndEmpty() (runs gio trash --list)
TaskManager-->>AppItem.qml: returns trashEmpty state
AppItem.qml->>AppItem.qml: Set contextMenuLoader.trashEmpty
AppItem.qml->>AppItem.qml: Enable/disable "Clean Trash" menu item
Class diagram for updated TaskManager trash detection methodsclassDiagram
class TaskManager {
+QString getTrashTipText()
+bool isTrashEmpty() const
+std::pair<int, bool> queryTrashCountAndEmpty() const
}
TaskManager : getTrashTipText() uses queryTrashCountAndEmpty()
TaskManager : isTrashEmpty() uses queryTrashCountAndEmpty()
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this 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 and they look great!
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location> `panels/dock/taskmanager/taskmanager.cpp:457-468` </location>
<code_context>
+ int count = 0;
+ bool empty = true;
+
+ QProcess gio;
+ gio.start("gio", QStringList() << "trash" << "--list");
+ if (gio.waitForFinished(1000) && gio.exitStatus() == QProcess::NormalExit && gio.exitCode() == 0) {
</code_context>
<issue_to_address>
**suggestion (bug_risk):** Consider error handling for QProcess failures.
Returning zero and 'empty' on process failure may hide real errors. Logging failures or adding a fallback would make the function more robust.
```suggestion
QProcess gio;
gio.start("gio", QStringList() << "trash" << "--list");
if (gio.waitForFinished(1000) && gio.exitStatus() == QProcess::NormalExit && gio.exitCode() == 0) {
const QByteArray out = gio.readAllStandardOutput();
const QList<QByteArray> lines = out.split('\n');
for (const QByteArray &l : lines) {
if (!l.trimmed().isEmpty()) count++;
}
empty = (count == 0);
return { count, empty };
} else {
qWarning("Failed to query trash with gio: exitStatus=%d, exitCode=%d, error=%d",
gio.exitStatus(), gio.exitCode(), gio.error());
// Optionally, you could set count = -1 to indicate error, or keep as is.
// count = -1;
// empty = false;
}
return { count, empty };
```
</issue_to_address>
### Comment 2
<location> `panels/dock/taskmanager/taskmanager.cpp:452` </location>
<code_context>
+}
- return tr("%1 files").arg(fileCount);
+std::pair<int, bool> TaskManager::queryTrashCountAndEmpty() const
+{
+ int count = 0;
</code_context>
<issue_to_address>
**issue (complexity):** Consider using Qt's split with SkipEmptyParts and std::ignore in structured bindings to simplify trash counting and avoid unused variables.
Here are two small tweaks that keep the current `gio`‐based approach but shave off the extra loop and the unused-variable noise:
1. In `queryTrashCountAndEmpty()`, split the output once with `Qt::SkipEmptyParts` instead of manually iterating every line.
2. Replace `Q_UNUSED(empty)` by using `std::ignore` in your structured bindings.
```cpp
std::pair<int,bool> TaskManager::queryTrashCountAndEmpty() const
{
QProcess gio;
gio.start("gio", {"trash", "--list"});
if (gio.waitForFinished(1000) && gio.exitCode() == 0) {
// one‐liner to split & drop empty lines
const auto out = gio.readAllStandardOutput();
const auto list = QString::fromUtf8(out)
.split('\n', Qt::SkipEmptyParts);
const int count = list.size();
return { count, count == 0 };
}
// on error assume empty
return { 0, true };
}
```
```cpp
QString TaskManager::getTrashTipText()
{
int count;
std::tie(count, std::ignore) = queryTrashCountAndEmpty();
return tr("%1 files").arg(count);
}
bool TaskManager::isTrashEmpty() const
{
bool empty;
std::tie(std::ignore, empty) = queryTrashCountAndEmpty();
return empty;
}
```
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
| } | ||
|
|
||
| return tr("%1 files").arg(fileCount); | ||
| std::pair<int, bool> TaskManager::queryTrashCountAndEmpty() const |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
issue (complexity): Consider using Qt's split with SkipEmptyParts and std::ignore in structured bindings to simplify trash counting and avoid unused variables.
Here are two small tweaks that keep the current gio‐based approach but shave off the extra loop and the unused-variable noise:
- In
queryTrashCountAndEmpty(), split the output once withQt::SkipEmptyPartsinstead of manually iterating every line. - Replace
Q_UNUSED(empty)by usingstd::ignorein your structured bindings.
std::pair<int,bool> TaskManager::queryTrashCountAndEmpty() const
{
QProcess gio;
gio.start("gio", {"trash", "--list"});
if (gio.waitForFinished(1000) && gio.exitCode() == 0) {
// one‐liner to split & drop empty lines
const auto out = gio.readAllStandardOutput();
const auto list = QString::fromUtf8(out)
.split('\n', Qt::SkipEmptyParts);
const int count = list.size();
return { count, count == 0 };
}
// on error assume empty
return { 0, true };
}QString TaskManager::getTrashTipText()
{
int count;
std::tie(count, std::ignore) = queryTrashCountAndEmpty();
return tr("%1 files").arg(count);
}
bool TaskManager::isTrashEmpty() const
{
bool empty;
std::tie(std::ignore, empty) = queryTrashCountAndEmpty();
return empty;
}| model: JSON.parse(menus) | ||
| delegate: LP.MenuItem { | ||
| text: modelData.name | ||
| enabled: (root.itemId === "dde-trash" && modelData.id === "clean-trash") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
当数据为空的时候,能不能不要“清空”这一菜单项?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
单子上面说是要设置为灰色,不能点击,
| QProcess gio; | ||
| gio.start("gio", QStringList() << "trash" << "--list"); | ||
| if (gio.waitForFinished(1000) && gio.exitStatus() == QProcess::NormalExit && gio.exitCode() == 0) { | ||
| const QByteArray out = gio.readAllStandardOutput(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
加上const &
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
6ac530a to
98c0feb
Compare
deepin pr auto review我来对这个diff进行审查,主要从语法逻辑、代码质量、性能和安全几个方面来分析:
具体改进建议: // 在taskmanager.h中修改返回类型
size_t queryTrashCount() const;
// 在taskmanager.cpp中添加缓存和错误处理
private:
mutable size_t m_lastTrashCount = 0;
mutable QDateTime m_lastTrashCheck;
size_t TaskManager::queryTrashCount() const
{
// 缓存检查,避免1秒内重复查询
const auto now = QDateTime::currentDateTime();
if (m_lastTrashCheck.isValid() && m_lastTrashCheck.secsTo(now) < 1) {
return m_lastTrashCount;
}
size_t count = 0;
QProcess gio;
gio.start("gio", QStringList() << "trash" << "--list");
if (!gio.waitForFinished(1000)) {
qWarning() << "Failed to query trash count: timeout";
return m_lastTrashCount;
}
if (gio.exitStatus() != QProcess::NormalExit || gio.exitCode() != 0) {
qWarning() << "Failed to query trash count:" << gio.errorString();
return m_lastTrashCount;
}
const QByteArray &out = gio.readAllStandardOutput();
const QList<QByteArray> lines = out.split('\n');
for (const QByteArray &l : lines) {
if (!l.trimmed().isEmpty()) count++;
}
m_lastTrashCount = count;
m_lastTrashCheck = now;
return count;
}这些改进可以:
总体来说,这个改动是合理的,主要改进了回收站状态检查的实现方式,使其更可靠和符合现代Linux桌面环境的最佳实践。 |
|
[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. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
|
/forcemerge |
|
This pr force merged! (status: blocked) |
feat: 实现回收站空状态检测
PMS: BUG-335901
Summary by Sourcery
Implement detection of an empty trash state using the gio command and update the UI to reflect and disable the “Clean Trash” action when no items are present
New Features:
Enhancements: