aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSaturneric <[email protected]>2022-05-14 18:25:47 +0000
committerSaturneric <[email protected]>2022-05-14 18:25:47 +0000
commiteb0178651f46792bacfbe9aeece92e33028b0406 (patch)
tree72a2021538af076d41a1c0ab8f302c975d4769b1
parentfeat(core): upgrade task runner system. (diff)
downloadGpgFrontend-eb0178651f46792bacfbe9aeece92e33028b0406.tar.gz
GpgFrontend-eb0178651f46792bacfbe9aeece92e33028b0406.zip
feat: improve processing using task runner system
-rw-r--r--src/ui/GpgFrontendUI.h2
-rw-r--r--src/ui/UserInterfaceUtils.cpp28
-rw-r--r--src/ui/UserInterfaceUtils.h7
3 files changed, 24 insertions, 13 deletions
diff --git a/src/ui/GpgFrontendUI.h b/src/ui/GpgFrontendUI.h
index b355ec85..9fa9e3a7 100644
--- a/src/ui/GpgFrontendUI.h
+++ b/src/ui/GpgFrontendUI.h
@@ -44,7 +44,7 @@
#include "GpgFrontend.h"
#include "core/GpgFrontendCore.h"
#include "core/GpgModel.h"
-
+#include "core/Thread/ThreadingModel.h"
#include "ui/GpgFrontendUIExport.h"
/**
diff --git a/src/ui/UserInterfaceUtils.cpp b/src/ui/UserInterfaceUtils.cpp
index 65c55c8f..adcbd6ff 100644
--- a/src/ui/UserInterfaceUtils.cpp
+++ b/src/ui/UserInterfaceUtils.cpp
@@ -114,21 +114,29 @@ void process_result_analyse(TextEdit *edit, InfoBoardWidget *info_board,
}
void process_operation(QWidget *parent, const std::string &waiting_title,
- const std::function<void()> &func) {
+ const Thread::Task::TaskRunnable func,
+ const Thread::Task::TaskCallback callback,
+ Thread::Task::DataObjectPtr data_object) {
auto *dialog =
new WaitingDialog(QString::fromStdString(waiting_title), parent);
- auto thread = QThread::create(func);
- QApplication::connect(thread, &QThread::finished, thread,
- &QThread::deleteLater);
- QApplication::connect(thread, &QThread::finished, dialog, &QDialog::close);
- QApplication::connect(thread, &QThread::finished, dialog,
- &QDialog::deleteLater);
+ auto *process_task =
+ new Thread::Task(std::move(func), std::move(callback), data_object);
+
+ QApplication::connect(process_task, &Thread::Task::SignalTaskFinished, dialog,
+ &QDialog::close);
QEventLoop looper;
- QApplication::connect(dialog, &QDialog::finished, &looper, &QEventLoop::quit);
+ QApplication::connect(process_task, &Thread::Task::SignalTaskFinished,
+ &looper, &QEventLoop::quit);
- thread->start();
+ // post process task to task runner
+ Thread::TaskRunnerGetter::GetInstance()
+ .GetTaskRunner(Thread::TaskRunnerGetter::kTaskRunnerType_GPG)
+ ->PostTask(process_task);
+
+ // block until task finished
+ // this is to keep reference vaild until task finished
looper.exec();
}
@@ -350,7 +358,7 @@ void CommonUtils::SlotImportKeyFromKeyServer(
void CommonUtils::slot_update_key_status() {
LOG(INFO) << "called";
- auto refresh_task = new Thread::Task([]() -> int {
+ auto refresh_task = new Thread::Task([](Thread::Task::DataObjectPtr) -> int {
// flush key cache for all GpgKeyGetter Intances.
for (const auto &channel_id : GpgKeyGetter::GetAllChannelId()) {
GpgKeyGetter::GetInstance(channel_id).FlushKeyCache();
diff --git a/src/ui/UserInterfaceUtils.h b/src/ui/UserInterfaceUtils.h
index 85ef012b..bfd8a3ae 100644
--- a/src/ui/UserInterfaceUtils.h
+++ b/src/ui/UserInterfaceUtils.h
@@ -101,8 +101,11 @@ void process_result_analyse(TextEdit* edit, InfoBoardWidget* info_board,
* @param waiting_title
* @param func
*/
-void process_operation(QWidget* parent, const std::string& waiting_title,
- const std::function<void()>& func);
+void process_operation(
+ QWidget* parent, const std::string& waiting_title,
+ GpgFrontend::Thread::Task::TaskRunnable func,
+ GpgFrontend::Thread::Task::TaskCallback callback = nullptr,
+ Thread::Task::DataObjectPtr data_object = nullptr);
/**
* @brief