summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--framework/src/domain/composercontroller.cpp30
1 files changed, 21 insertions, 9 deletions
diff --git a/framework/src/domain/composercontroller.cpp b/framework/src/domain/composercontroller.cpp
index 59c18cb6..b6079f77 100644
--- a/framework/src/domain/composercontroller.cpp
+++ b/framework/src/domain/composercontroller.cpp
@@ -30,6 +30,9 @@
30#include <QUrlQuery> 30#include <QUrlQuery>
31#include <QFileInfo> 31#include <QFileInfo>
32#include <QFile> 32#include <QFile>
33#include <QtConcurrent/QtConcurrentRun>
34#include <QFuture>
35#include <QFutureWatcher>
33#include <sink/store.h> 36#include <sink/store.h>
34#include <sink/log.h> 37#include <sink/log.h>
35 38
@@ -128,14 +131,22 @@ public:
128 mb.fromUnicodeString(addressee); 131 mb.fromUnicodeString(addressee);
129 132
130 SinkLog() << "Searching key for: " << mb.address(); 133 SinkLog() << "Searching key for: " << mb.address();
131 auto keys = MailCrypto::findKeys(QStringList{} << mb.address(), false, false, MailCrypto::OPENPGP); 134
132 if (keys.empty()) { 135 auto future = QtConcurrent::run([mb] {
133 //Search for key on remote server if it's missing and import 136 auto keys = MailCrypto::findKeys(QStringList{} << mb.address(), false, false, MailCrypto::OPENPGP);
134 //TODO: this is blocking and thus blocks the UI 137 if (keys.empty()) {
135 keys = MailCrypto::findKeys(QStringList{} << mb.address(), false, true, MailCrypto::OPENPGP); 138 //Search for key on remote server if it's missing and import
136 MailCrypto::importKeys(keys); 139 //TODO: this is blocking and thus blocks the UI
137 } 140 keys = MailCrypto::findKeys(QStringList{} << mb.address(), false, true, MailCrypto::OPENPGP);
138 if (item) { 141 MailCrypto::importKeys(keys);
142 }
143 return keys;
144 });
145 auto watcher = new QFutureWatcher<std::vector<GpgME::Key>>;
146 //FIXME holding on to the item pointer like this is not safe
147 QObject::connect(watcher, &QFutureWatcher<std::vector<GpgME::Key>>::finished, watcher, [this, watcher, item]() {
148 auto keys = watcher->future().result();
149 delete watcher;
139 if (!keys.empty()) { 150 if (!keys.empty()) {
140 if (keys.size() > 1 ) { 151 if (keys.size() > 1 ) {
141 SinkWarning() << "Found more than one key, picking first one."; 152 SinkWarning() << "Found more than one key, picking first one.";
@@ -146,7 +157,8 @@ public:
146 } else { 157 } else {
147 SinkWarning() << "Failed to find key for recipient."; 158 SinkWarning() << "Failed to find key for recipient.";
148 } 159 }
149 } 160 });
161 watcher->setFuture(future);
150 } 162 }
151 163
152 void remove(const QString &addressee) 164 void remove(const QString &addressee)