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

feat: Optimization of 1072 dde-file-manager Search Monitor Indicator Occupation Issue #2254

Merged
merged 1 commit into from
Sep 4, 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
3 changes: 2 additions & 1 deletion include/dfm-base/base/schemefactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,8 @@ class InfoFactory final : public SchemeFactory<FileInfo>
if (info && tarScheme == Global::Scheme::kAsyncFile)
info->updateAttributes();

emit InfoCacheController::instance().cacheFileInfo(url, info);
if (type != Global::CreateFileInfoType::kCreateFileInfoAutoNoCache)
emit InfoCacheController::instance().cacheFileInfo(url, info);
}

if (!info)
Expand Down
3 changes: 2 additions & 1 deletion include/dfm-base/dfm_global_defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,8 @@ enum CreateFileInfoType : uint8_t {
kCreateFileInfoSync = 1,
kCreateFileInfoAsync = 2,
kCreateFileInfoSyncAndCache = 3, // create file info Synchronize and cache file info
kCreateFileInfoAsyncAndCache = 4 // create file info Asynchronous and cache file info
kCreateFileInfoAsyncAndCache = 4, // create file info Asynchronous and cache file info
kCreateFileInfoAutoNoCache = 5, // can not cache file info, virtual schema will synchronize create file info
};

namespace Mime {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -301,5 +301,14 @@ void FileOperations::followEvents()
FileOperationsEventReceiver::instance(), &FileOperationsEventReceiver::handleShortCut);
dpfHookSequence->follow("dfmplugin_workspace", "hook_ShortCut_PasteFiles",
FileOperationsEventReceiver::instance(), &FileOperationsEventReceiver::handleShortCutPaste);
connect(
DPF_NAMESPACE::Listener::instance(), &DPF_NAMESPACE::Listener::pluginStarted, this, [](const QString &iid, const QString &name) {
Q_UNUSED(iid)
if (name == "dfmplugin-search")
dpfHookSequence->follow("dfmplugin_search", "hook_Url_IsSubFile",
FileOperationsEventReceiver::instance(),
&FileOperationsEventReceiver::handleIsSubFile);
},
Qt::DirectConnection);
}
} // namespace dfmplugin_fileoperations
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ class FileOperations : public dpf::Plugin
DPF_EVENT_REG_HOOK(hook_Operation_RenameFiles)
DPF_EVENT_REG_HOOK(hook_Operation_RenameFilesAddText)

DPF_EVENT_REG_SIGNAL(signal_File_Add)
DPF_EVENT_REG_SIGNAL(signal_File_Delete)
DPF_EVENT_REG_SIGNAL(signal_File_Rename)

public:
virtual void initialize() override;
virtual bool start() override;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,13 @@ bool DoCleanTrashFilesWorker::clearTrashFile(const FileInfoPointer &trashInfo)
const QUrl &fileUrl = trashInfo->urlOf(UrlInfoType::kUrl);
bool resultFile = deleteFile(fileUrl);

if (!resultFile)
if (!resultFile) {
action = doHandleErrorAndWait(fileUrl, AbstractJobHandler::JobErrorType::kDeleteTrashFileError,
false, localFileHandler->errorString());
} else {
dpfSignalDispatcher->publish("dfmplugin_fileoperations", "signal_File_Delete",
fileUrl);
}

} while (isStopped() && action == AbstractJobHandler::SupportAction::kRetryAction);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,18 @@ bool DoCutFilesWorker::doCutFile(const DFileInfoPointer &fromInfo, const DFileIn
if (sizeInfo->totalSize <= 0)
workData->zeroOrlinkOrDirWriteSize += workData->dirSize;
}
if (isTrashFile)
QUrl orignalUrl = fromInfo->uri();
if (isTrashFile) {
removeTrashInfo(trashInfoUrl);
orignalUrl.setScheme("trash");
orignalUrl.setPath("/" + orignalUrl.path().replace("/", "\\"));
auto tmpFileName = fromInfo->uri().fileName();
auto orignalName = QUrl::toPercentEncoding(tmpFileName);
orignalUrl.setPath(orignalUrl.path().replace(tmpFileName, orignalName));
}
if (toInfo)
dpfSignalDispatcher->publish("dfmplugin_fileoperations", "signal_File_Rename",
orignalUrl, toInfo->uri());
return true;
}

Expand All @@ -187,8 +197,17 @@ bool DoCutFilesWorker::doCutFile(const DFileInfoPointer &fromInfo, const DFileIn
return result;

workData->currentWriteSize += fromSize;
if (isTrashFile)
QUrl orignalUrl = fromInfo->uri();
if (isTrashFile) {
removeTrashInfo(trashInfoUrl);
orignalUrl.setScheme("trash");
orignalUrl.setPath("/" + orignalUrl.path().replace("/", "\\"));
auto tmpFileName = fromInfo->uri().fileName();
auto orignalName = QUrl::toPercentEncoding(tmpFileName);
orignalUrl.setPath(orignalUrl.path().replace(tmpFileName, orignalName));
}
dpfSignalDispatcher->publish("dfmplugin_fileoperations", "signal_File_Rename",
orignalUrl, toInfo->uri());
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ bool DoDeleteFilesWorker::deleteFilesOnCanNotRemoveDevice()

if (action != AbstractJobHandler::SupportAction::kNoAction)
return false;

dpfSignalDispatcher->publish("dfmplugin_fileoperations", "signal_File_Delete", url);
}
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
#include <dfm-base/interfaces/fileinfo.h>
#include <dfm-base/utils/filestatisticsjob.h>

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

#include <QObject>
#include <QUrl>
#include <QQueue>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1183,6 +1183,10 @@ bool FileOperateBaseWorker::doCopyFile(const DFileInfoPointer &fromInfo, const D
result = checkAndCopyFile(fromInfo, newTargetInfo, skip);
}

if (result)
dpfSignalDispatcher->publish("dfmplugin_fileoperations", "signal_File_Add",
newTargetInfo->uri());

if (targetInfo == toInfo) {
completeSourceFiles.append(fromInfo->uri());
precompleteTargetFileInfo.append(newTargetInfo);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <dfm-base/base/device/deviceutils.h>

#include <dfm-io/dfmio_utils.h>
#include <dfm-io/trashhelper.h>

#include <QUrl>
#include <QDebug>
Expand Down Expand Up @@ -128,6 +129,10 @@ bool DoMoveToTrashFilesWorker::doMoveToTrash()
completeTargetFiles.append(trashUrl);
emitProgressChangedNotify(completeFilesCount);
completeSourceFiles.append(urlSource);
auto targetTash = trashTargetUrl(trashUrl);
if (targetTash.isValid())
dpfSignalDispatcher->publish("dfmplugin_fileoperations", "signal_File_Rename",
urlSource, targetTash);
continue;
} else {
// pause and emit error msg
Expand Down Expand Up @@ -184,3 +189,38 @@ bool DoMoveToTrashFilesWorker::isCanMoveToTrash(const QUrl &url, bool *result)

return true;
}

QUrl DoMoveToTrashFilesWorker::trashTargetUrl(const QUrl &url)
{
auto fileUrl = url;
if (!url.isValid() || url.scheme() != dfmbase::Global::Scheme::kFile)
return QUrl();

QMap<QUrl, QSharedPointer<TrashHelper::DeleteTimeInfo>> targetUrls;
QList<QUrl> fileUrls;
QStringList deleteInfo;
auto userInfo = url.userInfo();
deleteInfo = userInfo.split("-");
// 错误处理
if (deleteInfo.length() != 2)
return QUrl();

if (isStopped())
return QUrl();

QSharedPointer<TrashHelper::DeleteTimeInfo> info(new TrashHelper::DeleteTimeInfo);
info->startTime = deleteInfo.first().toInt();
info->endTime = deleteInfo.at(1).toInt();
fileUrl.setUserInfo("");
targetUrls.insert(fileUrl, info);

QString errorMsg;
TrashHelper trashHelper;
trashHelper.setDeleteInfos(targetUrls);
if (!trashHelper.getTrashUrls(&fileUrls, &errorMsg))
return QUrl();
if (fileUrls.length() <= 0)
return QUrl();

return fileUrls.first();
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class DoMoveToTrashFilesWorker : public FileOperateBaseWorker
protected:
bool doMoveToTrash();
bool isCanMoveToTrash(const QUrl &url, bool *result);
QUrl trashTargetUrl(const QUrl &url);

private:
FileInfoPointer targetFileInfo { nullptr }; // target file information
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ bool DoRestoreTrashFilesWorker::doRestoreTrashFiles()
}
if (!completeTargetFiles.contains(restoreInfo->uri()))
completeTargetFiles.append(restoreInfo->uri());
dpfSignalDispatcher->publish("dfmplugin_fileoperations", "signal_File_Rename", fileUrl, newTargetInfo->uri());
} else {
auto errorCode = fileHandler.errorCode();
switch (errorCode) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1008,8 +1008,11 @@
QMap<QUrl, QUrl> renamedFiles { { oldUrl, newUrl } };
dpfSignalDispatcher->publish(DFMBASE_NAMESPACE::GlobalEventType::kRenameFileResult,
windowId, renamedFiles, ok, error);
if (ok)
if (ok) {
ClipBoard::instance()->replaceClipboardUrl(oldUrl, newUrl);
dpfSignalDispatcher->publish("dfmplugin_fileoperations", "signal_File_Rename",
oldUrl, newUrl);
}

AbstractJobHandler::JobFlags tmFlags = flags;
if (!tmFlags.testFlag(AbstractJobHandler::JobFlag::kRedo))
Expand Down Expand Up @@ -1056,9 +1059,13 @@
// publish result
dpfSignalDispatcher->publish(DFMBASE_NAMESPACE::GlobalEventType::kRenameFileResult,
windowId, successUrls, ok, error);
if (!successUrls.isEmpty())
if (!successUrls.isEmpty()) {
saveFileOperation(successUrls.values(), successUrls.keys(), GlobalEventType::kRenameFiles,
successUrls.keys(), successUrls.values(), GlobalEventType::kRenameFiles);
for (const auto &source : successUrls.keys())
dpfSignalDispatcher->publish("dfmplugin_fileoperations", "signal_File_Rename",
source, successUrls.value(source));
}

return ok;
}
Expand Down Expand Up @@ -1117,9 +1124,13 @@
// publish result
dpfSignalDispatcher->publish(DFMBASE_NAMESPACE::GlobalEventType::kRenameFileResult,
windowId, successUrls, ok, error);
if (!successUrls.isEmpty())
if (!successUrls.isEmpty()) {
saveFileOperation(successUrls.values(), successUrls.keys(), GlobalEventType::kRenameFiles,
successUrls.keys(), successUrls.values(), GlobalEventType::kRenameFiles);
for (const auto &source : successUrls.keys())
dpfSignalDispatcher->publish("dfmplugin_fileoperations", "signal_File_Rename",
source, successUrls.value(source));
}
}

bool FileOperationsEventReceiver::handleOperationMkdir(const quint64 windowId, const QUrl url)
Expand Down Expand Up @@ -1531,4 +1542,12 @@
handleCallback(handle);
FileOperationsEventHandler::instance()->handleJobResult(AbstractJobHandler::JobType::kCutType, handle);
}

bool FileOperationsEventReceiver::handleIsSubFile(const QUrl &parent, const QUrl &sub)

Check warning on line 1546 in src/plugins/common/core/dfmplugin-fileoperations/fileoperationsevent/fileoperationseventreceiver.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

The function 'handleIsSubFile' is never used.

Check warning on line 1546 in src/plugins/common/core/dfmplugin-fileoperations/fileoperationsevent/fileoperationseventreceiver.cpp

View workflow job for this annotation

GitHub Actions / static-check / Call-CppCheck

The function 'handleIsSubFile' is never used.
{
if (parent.scheme() != Global::Scheme::kFile)
return false;

return sub.path().startsWith(parent.path());
}
} // namespace dfmplugin_fileoperations
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,8 @@ public slots:
const DFMBASE_NAMESPACE::AbstractJobHandler::JobFlag flags,
DFMBASE_NAMESPACE::AbstractJobHandler::OperatorHandleCallback handleCallback,
const QVariantMap &op);

bool handleIsSubFile(const QUrl &parent, const QUrl &sub);
private:
enum class RenameTypes {
kBatchRepalce,
Expand Down
9 changes: 9 additions & 0 deletions src/plugins/filemanager/core/dfmplugin-trash/trash.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,15 @@ void Trash::followEvents()
dpfHookSequence->follow("dfmplugin_tag", "hook_CanTaged", TrashFileHelper::instance(), &TrashFileHelper::handleCanTag);
},
Qt::DirectConnection);
connect(
DPF_NAMESPACE::Listener::instance(), &DPF_NAMESPACE::Listener::pluginStarted, this, [](const QString &iid, const QString &name) {
Q_UNUSED(iid)
if (name == "dfmplugin-search")
dpfHookSequence->follow("dfmplugin_search", "hook_Url_IsSubFile",
TrashFileHelper::instance(),
&TrashFileHelper::handleIsSubFile);
},
Qt::DirectConnection);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <dfm-base/file/local/localfilehandler.h>
#include <dfm-base/base/schemefactory.h>
#include <dfm-base/utils/clipboard.h>
#include <dfm-base/utils/universalutils.h>

#include <dfm-framework/event/event.h>
#include <dfm-io/dfmio_utils.h>
Expand Down Expand Up @@ -152,3 +153,15 @@ bool TrashFileHelper::handleCanTag(const QUrl &url, bool *canTag)

return false;
}

bool TrashFileHelper::handleIsSubFile(const QUrl &parent, const QUrl &sub)
{
if (parent.scheme() != scheme())
return false;
if (!FileUtils::isTrashFile(sub))
return false;
if (UniversalUtils::urlEquals( FileUtils::trashRootUrl(), parent))
return true;

return sub.path().contains(parent.path());
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class TrashFileHelper : public QObject
bool blockPaste(quint64 winId, const QList<QUrl> &fromUrls, const QUrl &to);
bool disableOpenWidgetWidget(const QUrl &url, bool *result);
bool handleCanTag(const QUrl &url, bool *canTag);
bool handleIsSubFile(const QUrl &parent, const QUrl &sub);

private:
explicit TrashFileHelper(QObject *parent = nullptr);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ int TraversalDirThreadManager::iteratorOneByOne(const QElapsedTimer &timere)
QList<FileInfoPointer> childrenList; // 当前遍历出来的所有文件
QSet<QUrl> urls;
int filecount = 0;
bool noCache = dirIterator->property("FileInfoNoCache").toBool();
while (dirIterator->hasNext()) {
if (stopFlag)
break;
Expand All @@ -162,8 +163,10 @@ int TraversalDirThreadManager::iteratorOneByOne(const QElapsedTimer &timere)
urls.insert(fileUrl);
auto fileInfo = dirIterator->fileInfo();
if (fileUrl.isValid() && !fileInfo) {
fileInfo = InfoFactory::create<FileInfo>(fileUrl);
} else if (!fileInfo.isNull()) {
fileInfo = InfoFactory::create<FileInfo>(fileUrl,
noCache ? Global::CreateFileInfoType::kCreateFileInfoAutoNoCache
: Global::CreateFileInfoType::kCreateFileInfoAuto);
} else if (!fileInfo.isNull() && !noCache) {
InfoFactory::cacheFileInfo(fileInfo);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,21 @@ void SearchEventReceiver::handleAddressInputStr(quint64 windId, QString *str)
}
}

void SearchEventReceiver::handleFileAdd(const QUrl &url)
{
emit SearchManager::instance()->fileAdd(url);
}

void SearchEventReceiver::handleFileDelete(const QUrl &url)
{
emit SearchManager::instance()->fileDelete(url);
}

void SearchEventReceiver::handleFileRename(const QUrl &oldUrl, const QUrl &newUrl)
{
emit SearchManager::instance()->fileRename(oldUrl, newUrl);
}

SearchEventReceiver::SearchEventReceiver(QObject *parent)
: QObject(parent)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ public slots:
void handleShowAdvanceSearchBar(quint64 winId, bool visible);
void handleUrlChanged(quint64 winId, const QUrl &u);
void handleAddressInputStr(quint64 windId, QString *str);
void handleFileAdd(const QUrl &url);
void handleFileDelete(const QUrl &url);
void handleFileRename(const QUrl &oldUrl, const QUrl &newUrl);

private:
explicit SearchEventReceiver(QObject *parent = nullptr);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ SearchDirIterator::SearchDirIterator(const QUrl &url,
: AbstractDirIterator(url, nameFilters, filters, flags),
d(new SearchDirIteratorPrivate(url, this))
{
setProperty("FileInfoNoCache", true);
}

SearchDirIterator::~SearchDirIterator()
Expand Down Expand Up @@ -156,7 +157,8 @@ const FileInfoPointer SearchDirIterator::fileInfo() const
if (!d->currentFileUrl.isValid())
return nullptr;

return InfoFactory::create<FileInfo>(d->currentFileUrl);
return InfoFactory::create<FileInfo>(d->currentFileUrl,
Global::CreateFileInfoType::kCreateFileInfoAutoNoCache);
}

QUrl SearchDirIterator::url() const
Expand Down
Loading
Loading