aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSaturneric <[email protected]>2022-05-09 15:03:01 +0000
committerSaturneric <[email protected]>2022-05-09 15:03:01 +0000
commit772d8fc81e0afcb0a873738cde649e5e640d8a41 (patch)
tree7773ae03a4129d0d5b806842f70916726cfc0533
parentfix: fix build issues on linux platform (diff)
downloadGpgFrontend-dev/2.0.6.tar.gz
GpgFrontend-dev/2.0.6.zip
fix: avoid block when refreshing keysdev/2.0.6
-rw-r--r--src/ui/UserInterfaceUtils.cpp44
1 files changed, 24 insertions, 20 deletions
diff --git a/src/ui/UserInterfaceUtils.cpp b/src/ui/UserInterfaceUtils.cpp
index 9859ff65..724a467e 100644
--- a/src/ui/UserInterfaceUtils.cpp
+++ b/src/ui/UserInterfaceUtils.cpp
@@ -330,28 +330,32 @@ void CommonUtils::SlotImportKeyFromKeyServer(
void CommonUtils::slot_update_key_status() {
LOG(INFO) << "called";
+ auto *thread = QThread::create([this]() {
+ std::vector<QThread *> threads;
+
+ // flush key cache for all GpgKeyGetter Intances.
+ for (const auto &channel_id : GpgKeyGetter::GetAllChannelId()) {
+ // multi threading
+ auto *refresh_thread = QThread::create([channel_id]() {
+ LOG(INFO) << "FlushKeyCache thread start"
+ << "channel:" << channel_id;
+ GpgKeyGetter::GetInstance(channel_id).FlushKeyCache();
+ });
+ refresh_thread->start();
+ threads.push_back(refresh_thread);
+ }
- std::vector<QThread *> threads;
-
- // flush key cache for all GpgKeyGetter Intances.
- for (const auto &channel_id : GpgKeyGetter::GetAllChannelId()) {
- // multi threading
- auto *thread = QThread::create([channel_id]() {
- LOG(INFO) << "thread start"
- << "channel:" << channel_id;
- GpgKeyGetter::GetInstance(channel_id).FlushKeyCache();
- });
- thread->start();
- threads.push_back(thread);
- }
-
- for (auto *thread : threads) {
- thread->wait();
- thread->deleteLater();
- }
+ for (auto *thread : threads) {
+ thread->wait();
+ thread->deleteLater();
+ }
- emit SignalKeyDatabaseRefreshDone();
- LOG(INFO) << "finished";
+ emit SignalKeyDatabaseRefreshDone();
+ LOG(INFO) << "finished";
+ });
+ connect(thread, &QThread::finished, thread, &QThread::deleteLater);
+ LOG(INFO) << "start thread";
+ thread->start();
}
} // namespace GpgFrontend::UI \ No newline at end of file