Skip to content

Commit

Permalink
fix: After mounting the SMB folder, shutting down the network and cli…
Browse files Browse the repository at this point in the history
…cking on the "Trash" directory will cause the file manager to freeze

When the network is disconnected, the main thread creates trash:///, which will query the root nodes of all trashes, causing a lag. The monitor that starts trash:/// lags

Log: After mounting the SMB folder, shutting down the network and clicking on the "Trash" directory will cause the file manager to freeze
Bug: https://pms.uniontech.com/bug-view-260029.html
  • Loading branch information
liyigang1 committed Jun 28, 2024
1 parent 0cdcb76 commit 5cb2199
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#include <dfm-base/base/schemefactory.h>
#include <dfm-base/utils/universalutils.h>
#include <dfm-base/utils/fileutils.h>

#include <dfm-framework/event/event.h>

Expand Down Expand Up @@ -38,6 +39,11 @@ void CoreHelper::cd(quint64 windowId, const QUrl &url)
fmInfo() << "cd to " << url;
window->cd(url);

if (UniversalUtils::urlEquals(url, FileUtils::trashRootUrl())) {
window->setWindowTitle(QCoreApplication::translate("PathManager", "Trash"));
return;
}

QUrl titleUrl { url };
QList<QUrl> urls {};
bool ok = UniversalUtils::urlsTransformToLocal({ titleUrl }, &urls);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
#include <dfm-base/base/urlroute.h>
#include <dfm-base/base/schemefactory.h>
#include <dfm-base/dfm_global_defines.h>
#include <dfm-base/utils/universalutils.h>
#include <dfm-base/utils/fileutils.h>

#include <dfm-framework/event/event.h>

Expand Down Expand Up @@ -83,8 +85,13 @@ QList<CrumbData> CrumbInterface::seprateUrl(const QUrl &url)
QStringList pathList { curUrl.path().split("/") };
QString displayText = pathList.isEmpty() ? "" : pathList.last();

Check warning on line 86 in src/plugins/filemanager/core/dfmplugin-titlebar/utils/crumbinterface.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Condition 'pathList.isEmpty()' is always false

Check warning on line 86 in src/plugins/filemanager/core/dfmplugin-titlebar/utils/crumbinterface.cpp

View workflow job for this annotation

GitHub Actions / static-check / Static-Check

Condition 'pathList.isEmpty()' is always false
if (curUrl.scheme() == Global::Scheme::kTrash) {
auto info = InfoFactory::create<FileInfo>(curUrl);
displayText = info ? info->displayOf(DisPlayInfoType::kFileDisplayName) : displayText;
if (UniversalUtils::urlEquals(curUrl, FileUtils::trashRootUrl())) {
displayText = QCoreApplication::translate("PathManager", "Trash");
} else {
auto info = InfoFactory::create<FileInfo>(curUrl);
displayText = info ? info->displayOf(DisPlayInfoType::kFileDisplayName) : displayText;
}

}
CrumbData data { curUrl, displayText};
if (UrlRoute::isRootUrl(curUrl))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class TrashDirIteratorPrivate
QUrl currentUrl;
QMap<QString, QString> fstabMap;
FileInfoPointer fileInfo{nullptr};
std::atomic_bool once{ false };
};

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ bool TrashDirIterator::hasNext() const
return has;

if (d->dEnumerator) {
if (!d->once)
TrashHelper::instance()->onTrashNotEmptyState();

d->once = true;
const QUrl &urlNext = d->dEnumerator->next();
d->fileInfo = InfoFactory::create<FileInfo>(urlNext);
if (d->fileInfo) {
Expand Down
21 changes: 15 additions & 6 deletions src/plugins/filemanager/core/dfmplugin-trash/utils/trashhelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,7 @@ bool TrashHelper::showTopWidget(QWidget *w, const QUrl &url)
{
Q_UNUSED(w)

auto rootUrl = TrashHelper::rootUrl();
if (UniversalUtils::urlEquals(url, rootUrl) && !FileUtils::trashIsEmpty()) {
return true;
} else {
return false;
}
return false;
}

QUrl TrashHelper::transToTrashFile(const QString &filePath)

Check warning on line 110 in src/plugins/filemanager/core/dfmplugin-trash/utils/trashhelper.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

The function 'transToTrashFile' is never used.

Check warning on line 110 in src/plugins/filemanager/core/dfmplugin-trash/utils/trashhelper.cpp

View workflow job for this annotation

GitHub Actions / static-check / Static-Check

The function 'transToTrashFile' is never used.
Expand Down Expand Up @@ -324,6 +319,20 @@ void TrashHelper::onTrashEmptyState() {
}
}

void TrashHelper::onTrashNotEmptyState()
{
isTrashEmpty = false;
const QList<quint64> &windowIds = FMWindowsIns.windowIdList();
for (const quint64 winId : windowIds) {
auto window = FMWindowsIns.findWindowById(winId);
if (window) {
const QUrl &url = window->currentUrl();
if (url.scheme() == scheme())
TrashEventCaller::sendShowEmptyTrash(winId, !isTrashEmpty);
}
}
}

TrashHelper::TrashHelper(QObject *parent)
: QObject(parent)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ class TrashHelper final : public QObject
bool customColumnRole(const QUrl &rootUrl, QList<DFMGLOBAL_NAMESPACE::ItemRoles> *roleList);
bool customRoleDisplayName(const QUrl &url, const DFMGLOBAL_NAMESPACE::ItemRoles role, QString *displayName);
void onTrashEmptyState();
void onTrashNotEmptyState();

private:
void onTrashStateChanged();
Expand Down

0 comments on commit 5cb2199

Please sign in to comment.