From 0ff4345f4ce20be2f0d20a597da324d4f4855999 Mon Sep 17 00:00:00 2001 From: saturneric Date: Mon, 22 Jan 2024 22:01:34 +0800 Subject: fix: stop reading all data into memory at file hash calculation --- src/ui/widgets/FileTreeView.cpp | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) (limited to 'src/ui/widgets/FileTreeView.cpp') diff --git a/src/ui/widgets/FileTreeView.cpp b/src/ui/widgets/FileTreeView.cpp index 41cd9aff..0c299a97 100644 --- a/src/ui/widgets/FileTreeView.cpp +++ b/src/ui/widgets/FileTreeView.cpp @@ -28,8 +28,10 @@ #include "FileTreeView.h" +#include "core/utils/AsyncUtils.h" #include "core/utils/IOUtils.h" #include "ui/UISignalStation.h" +#include "ui/UserInterfaceUtils.h" namespace GpgFrontend::UI { @@ -372,8 +374,24 @@ void FileTreeView::slot_show_custom_context_menu(const QPoint& point) { } void FileTreeView::slot_calculate_hash() { - emit UISignalStation::GetInstance()->SignalRefreshInfoBoard( - CalculateHash(this->GetSelectedPath()), InfoBoardStatus::INFO_ERROR_OK); + CommonUtils::WaitForOpera( + this->parentWidget(), tr("Calculating"), [=](const OperaWaitingHd& hd) { + RunOperaAsync( + [=](DataObjectPtr data_object) { + data_object->Swap({CalculateHash(this->GetSelectedPath())}); + return 0; + }, + [hd](int rtn, DataObjectPtr data_object) { + hd(); + if (rtn < 0 || !data_object->Check()) { + return; + } + auto result = ExtractParams(data_object, 0); + emit UISignalStation::GetInstance()->SignalRefreshInfoBoard( + result, InfoBoardStatus::INFO_ERROR_OK); + }, + "calculate_file_hash"); + }); } void FileTreeView::slot_compress_files() {} -- cgit v1.2.3