Skip to content

chore: enhance logging and error handling in file manager components #2917

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

Merged
merged 1 commit into from
Jun 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/apps/dde-file-manager/dragmonitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ bool DragMoniter::eventFilter(QObject *watched, QEvent *event)
}

if (!str.isEmpty()) {
qCDebug(logAppFileManager) << "DragMoniter::eventFilter: Drag enter event with" << str.size() << "URLs";
QMetaObject::invokeMethod(this, "DragEnter", Qt::QueuedConnection, Q_ARG(QStringList, str));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@ BaseSortMenuScenePrivate::BaseSortMenuScenePrivate(BaseSortMenuScene *qq)

void BaseSortMenuScenePrivate::sortMenuActions(QMenu *menu, const QStringList &sortRule, bool isFuzzy)
{
if (!menu) {
fmWarning() << "Cannot sort menu actions: menu is null";
return;
}

fmDebug() << "Sorting menu actions with" << sortRule.size() << "rules, fuzzy matching:" << isFuzzy;

auto findIndex = [&isFuzzy, &sortRule](const QString &property) {
int index1 = -1;
for (int i = 0, nEnd = sortRule.size(); i < nEnd; ++i) {
Expand Down Expand Up @@ -89,18 +96,29 @@ void BaseSortMenuScenePrivate::sortMenuActions(QMenu *menu, const QStringList &s
}

menu->addActions(actions);
fmDebug() << "Menu actions sorted successfully," << actions.size() << "actions added to menu";
}

void BaseSortMenuScenePrivate::sortPrimaryMenu(QMenu *menu)
{
if (!menu) {
fmWarning() << "Cannot sort primary menu: menu is null";
return;
}

fmDebug() << "Sorting primary menu";
const QStringList &sortRule = primaryMenuRule();
sortMenuActions(menu, sortRule, false);
}

void BaseSortMenuScenePrivate::sortSecondaryMenu(QMenu *menu)
{
const QMap<QString, QStringList> &sortRuleMap = secondaryMenuRule();
if (!menu) {
fmWarning() << "Cannot sort secondary menu: menu is null";
return;
}

const QMap<QString, QStringList> &sortRuleMap = secondaryMenuRule();
auto actions = menu->actions();
for (QAction *action : actions) {
QMenu *secondaryMenu = action->menu();
Expand Down Expand Up @@ -145,6 +163,7 @@ QStringList BaseSortMenuScenePrivate::primaryMenuRule()
static std::once_flag flag;

std::call_once(flag, [&]() {
fmDebug() << "Initializing primary menu rules";
// file
ret.append("open"); // 打开
ret.append("open-file-location"); // 打开文件所在位置
Expand Down Expand Up @@ -209,6 +228,7 @@ QStringList BaseSortMenuScenePrivate::primaryMenuRule()
ret.append(ActionID::kSeparatorLine);

ret.append("property");
fmDebug() << "Primary menu rules initialized with" << ret.size() << "rules";
});

return ret;
Expand All @@ -220,6 +240,7 @@ QMap<QString, QStringList> BaseSortMenuScenePrivate::secondaryMenuRule()
static std::once_flag flag;

std::call_once(flag, [&]() {
fmDebug() << "Initializing secondary menu rules";
// file
ret.insert("open-with",
QStringList { "open-with-app",
Expand Down Expand Up @@ -261,6 +282,7 @@ QMap<QString, QStringList> BaseSortMenuScenePrivate::secondaryMenuRule()

ret.insert("send-to",
sendToList); // 发送到
fmDebug() << "Secondary menu rules initialized with" << ret.size() << "rule groups";
});

return ret;
Expand All @@ -269,10 +291,12 @@ QMap<QString, QStringList> BaseSortMenuScenePrivate::secondaryMenuRule()
BaseSortMenuScene::BaseSortMenuScene(QObject *parent)
: AbstractMenuScene(parent), d(new BaseSortMenuScenePrivate(this))
{
fmDebug() << "BaseSortMenuScene initialized";
}

BaseSortMenuScene::~BaseSortMenuScene()
{
fmDebug() << "BaseSortMenuScene destroyed";
}

QString BaseSortMenuScene::name() const
Expand All @@ -292,13 +316,25 @@ bool BaseSortMenuScene::create(QMenu *parent)

void BaseSortMenuScene::updateState(QMenu *parent)
{
if (!parent) {
fmWarning() << "Cannot update state: parent menu is null";
return;
}

fmDebug() << "Updating BaseSortMenuScene state";
d->sortPrimaryMenu(parent);
d->sortSecondaryMenu(parent);
AbstractMenuScene::updateState(parent);
fmDebug() << "BaseSortMenuScene state update completed";
}

bool BaseSortMenuScene::triggered(QAction *action)
{
if (!action) {
fmWarning() << "Cannot trigger action: action is null";
return false;
}

return AbstractMenuScene::triggered(action);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@
#include "workspacemenu_defines.h"
#include "views/fileview.h"
#include "models/fileviewmodel.h"
#include "utils/workspacehelper.h"

Check warning on line 10 in src/plugins/filemanager/dfmplugin-workspace/menus/sortanddisplaymenuscene.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: "utils/workspacehelper.h" not found.

Check warning on line 10 in src/plugins/filemanager/dfmplugin-workspace/menus/sortanddisplaymenuscene.cpp

View workflow job for this annotation

GitHub Actions / static-check / static-check

Include file: "utils/workspacehelper.h" not found.
#include "events/workspaceeventcaller.h"

Check warning on line 11 in src/plugins/filemanager/dfmplugin-workspace/menus/sortanddisplaymenuscene.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: "events/workspaceeventcaller.h" not found.

Check warning on line 11 in src/plugins/filemanager/dfmplugin-workspace/menus/sortanddisplaymenuscene.cpp

View workflow job for this annotation

GitHub Actions / static-check / static-check

Include file: "events/workspaceeventcaller.h" not found.

#include <dfm-base/dfm_log_defines.h>

Check warning on line 13 in src/plugins/filemanager/dfmplugin-workspace/menus/sortanddisplaymenuscene.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <dfm-base/dfm_log_defines.h> not found. Please note: Cppcheck does not need standard library headers to get proper results.

Check warning on line 13 in src/plugins/filemanager/dfmplugin-workspace/menus/sortanddisplaymenuscene.cpp

View workflow job for this annotation

GitHub Actions / static-check / static-check

Include file: <dfm-base/dfm_log_defines.h> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <dfm-base/dfm_menu_defines.h>

Check warning on line 14 in src/plugins/filemanager/dfmplugin-workspace/menus/sortanddisplaymenuscene.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <dfm-base/dfm_menu_defines.h> not found. Please note: Cppcheck does not need standard library headers to get proper results.

Check warning on line 14 in src/plugins/filemanager/dfmplugin-workspace/menus/sortanddisplaymenuscene.cpp

View workflow job for this annotation

GitHub Actions / static-check / static-check

Include file: <dfm-base/dfm_menu_defines.h> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <dfm-base/dfm_global_defines.h>

Check warning on line 15 in src/plugins/filemanager/dfmplugin-workspace/menus/sortanddisplaymenuscene.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <dfm-base/dfm_global_defines.h> not found. Please note: Cppcheck does not need standard library headers to get proper results.

Check warning on line 15 in src/plugins/filemanager/dfmplugin-workspace/menus/sortanddisplaymenuscene.cpp

View workflow job for this annotation

GitHub Actions / static-check / static-check

Include file: <dfm-base/dfm_global_defines.h> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <dfm-base/dfm_event_defines.h>

Check warning on line 16 in src/plugins/filemanager/dfmplugin-workspace/menus/sortanddisplaymenuscene.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <dfm-base/dfm_event_defines.h> not found. Please note: Cppcheck does not need standard library headers to get proper results.

Check warning on line 16 in src/plugins/filemanager/dfmplugin-workspace/menus/sortanddisplaymenuscene.cpp

View workflow job for this annotation

GitHub Actions / static-check / static-check

Include file: <dfm-base/dfm_event_defines.h> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <dfm-base/base/configs/dconfig/dconfigmanager.h>

#include <dfm-framework/dpf.h>
Expand All @@ -27,12 +28,14 @@

AbstractMenuScene *SortAndDisplayMenuCreator::create()
{
fmDebug() << "Creating SortAndDisplayMenuScene instance";
return new SortAndDisplayMenuScene();
}

SortAndDisplayMenuScene::SortAndDisplayMenuScene(QObject *parent)
: AbstractMenuScene(parent), d(new SortAndDisplayMenuScenePrivate(this))
{
fmDebug() << "SortAndDisplayMenuScene initialized";
d->predicateName[ActionID::kSortBy] = tr("Sort by");
d->predicateName[ActionID::kDisplayAs] = tr("Display as");

Expand All @@ -51,6 +54,7 @@

SortAndDisplayMenuScene::~SortAndDisplayMenuScene()
{
fmDebug() << "SortAndDisplayMenuScene destroyed";
}

QString SortAndDisplayMenuScene::name() const
Expand All @@ -62,8 +66,16 @@
{
d->windowId = params.value(MenuParamKey::kWindowId).toULongLong();
d->isEmptyArea = params.value(MenuParamKey::kIsEmptyArea).toBool();
if (d->isEmptyArea)

fmDebug() << "Initializing SortAndDisplayMenuScene - windowId:" << d->windowId
<< "isEmptyArea:" << d->isEmptyArea;

if (d->isEmptyArea) {
fmDebug() << "SortAndDisplayMenuScene initialization successful for empty area";
return AbstractMenuScene::initialize(params);
}

fmDebug() << "SortAndDisplayMenuScene initialization skipped - not empty area";
return false;
}

Expand All @@ -80,40 +92,59 @@

bool SortAndDisplayMenuScene::create(QMenu *parent)
{
if (!parent) {
fmWarning() << "Cannot create SortAndDisplayMenuScene: parent menu is null";
return false;
}

fmDebug() << "Creating sort and display menu";
d->view = qobject_cast<FileView *>(parent->parent());
d->createEmptyMenu(parent);
return AbstractMenuScene::create(parent);
}

void SortAndDisplayMenuScene::updateState(QMenu *parent)
{
fmDebug() << "Updating sort and display menu state";
d->updateEmptyAreaActionState();
AbstractMenuScene::updateState(parent);
}

bool SortAndDisplayMenuScene::triggered(QAction *action)
{
if (!d->view)
if (!action) {
fmWarning() << "Cannot trigger action: action is null";
return false;
}

if (!d->view) {
fmWarning() << "Cannot trigger action: view is null";
return false;
}

const auto &actionId = action->property(ActionPropertyKey::kActionID).toString();
fmDebug() << "Action triggered in SortAndDisplayMenuScene:" << actionId;

if (d->predicateAction.values().contains(action)) {
// display as
{
// display as icon
if (actionId == ActionID::kDisplayIcon) {
fmInfo() << "Switching to icon view mode";
WorkspaceEventCaller::sendViewModeChanged(d->windowId, DFMGLOBAL_NAMESPACE::ViewMode::kIconMode);
return true;
}

// display as list
if (actionId == ActionID::kDisplayList) {
fmInfo() << "Switching to list view mode";
WorkspaceEventCaller::sendViewModeChanged(d->windowId, DFMGLOBAL_NAMESPACE::ViewMode::kListMode);
return true;
}

// display as tree
if (actionId == ActionID::kDisplayTree) {
fmInfo() << "Switching to tree view mode";
WorkspaceEventCaller::sendViewModeChanged(d->windowId, DFMGLOBAL_NAMESPACE::ViewMode::kTreeMode);
return true;
}
Expand All @@ -123,30 +154,35 @@
{
// sort by name
if (actionId == ActionID::kSrtName) {
fmInfo() << "Sorting by name";
d->sortByRole(Global::ItemRoles::kItemFileDisplayNameRole);
return true;
}

// sort by time modified
if (actionId == ActionID::kSrtTimeModified) {
fmInfo() << "Sorting by time modified";
d->sortByRole(Global::ItemRoles::kItemFileLastModifiedRole);
return true;
}

// sort by time created
if (actionId == ActionID::kSrtTimeCreated) {
fmInfo() << "Sorting by time created";
d->sortByRole(Global::ItemRoles::kItemFileCreatedRole);
return true;
}

// sort by size
if (actionId == ActionID::kSrtSize) {
fmInfo() << "Sorting by size";
d->sortByRole(Global::ItemRoles::kItemFileSizeRole);
return true;
}

// sort by type
if (actionId == ActionID::kSrtType) {
fmInfo() << "Sorting by type";
d->sortByRole(Global::ItemRoles::kItemFileMimeTypeRole);
return true;
}
Expand All @@ -163,6 +199,13 @@

void SortAndDisplayMenuScenePrivate::createEmptyMenu(QMenu *parent)
{
if (!parent) {
fmWarning() << "Cannot create empty menu: parent is null";
return;
}

fmDebug() << "Creating empty area menu with sort and display options";

QAction *tempAction = parent->addAction(predicateName.value(ActionID::kDisplayAs));
tempAction->setMenu(addDisplayAsActions(parent));
predicateAction[ActionID::kDisplayAs] = tempAction;
Expand All @@ -172,10 +215,13 @@
tempAction->setMenu(addSortByActions(parent));
predicateAction[ActionID::kSortBy] = tempAction;
tempAction->setProperty(ActionPropertyKey::kActionID, QString(ActionID::kSortBy));

fmDebug() << "Empty area menu created with" << predicateAction.size() << "main actions";
}

QMenu *SortAndDisplayMenuScenePrivate::addSortByActions(QMenu *menu)
{
fmDebug() << "Adding sort by actions to submenu";
QMenu *subMenu = new QMenu(menu);

// SortBy
Expand Down Expand Up @@ -209,6 +255,7 @@

QMenu *SortAndDisplayMenuScenePrivate::addDisplayAsActions(QMenu *menu)
{
fmDebug() << "Adding display as actions to submenu";
QMenu *subMenu = new QMenu(menu);

// DisplayAs
Expand Down Expand Up @@ -242,14 +289,19 @@
: order == Qt::AscendingOrder ? Qt::DescendingOrder
: Qt::AscendingOrder;

fmDebug() << "Sorting by role:" << role << "order:" << (order == Qt::AscendingOrder ? "Ascending" : "Descending")
<< "old role:" << oldRole;

view->setSort(itemRole, order);
}

void SortAndDisplayMenuScenePrivate::updateEmptyAreaActionState()
{
fmDebug() << "Updating empty area action state";
using namespace Global;
// sort by
auto role = static_cast<ItemRoles>(view->model()->sortRole());
fmDebug() << "Current sort role:" << role;
switch (role) {
case kItemFileDisplayNameRole:
predicateAction[ActionID::kSrtName]->setChecked(true);
Expand All @@ -272,6 +324,7 @@

// display as
auto mode = view->currentViewMode();
fmDebug() << "Current view mode:" << static_cast<int>(mode);
switch (mode) {
case Global::ViewMode::kIconMode:
predicateAction[ActionID::kDisplayIcon]->setChecked(true);
Expand Down
Loading
Loading