Skip to content
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

fix: After mounting the SMB folder, shutting down the network and clicking on the "Trash" directory will cause the file manager to freeze #2067

Merged
merged 1 commit into from
Jul 1, 2024
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
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 @@ -81,10 +83,15 @@
for (int count = urls.size() - 1; count >= 0; count--) {
QUrl curUrl { urls.at(count) };
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,15 +104,10 @@
{
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.
{
QUrl url;
url.setScheme(TrashHelper::scheme());
Expand Down Expand Up @@ -324,6 +319,20 @@
}
}

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
Loading