diff options
Diffstat (limited to 'framework/src')
-rw-r--r-- | framework/src/async.h | 40 | ||||
-rw-r--r-- | framework/src/domain/composercontroller.cpp | 22 | ||||
-rw-r--r-- | framework/src/domain/composercontroller.h | 4 | ||||
-rw-r--r-- | framework/src/domain/mime/messageparser.cpp | 32 |
4 files changed, 55 insertions, 43 deletions
diff --git a/framework/src/async.h b/framework/src/async.h new file mode 100644 index 00000000..34233244 --- /dev/null +++ b/framework/src/async.h | |||
@@ -0,0 +1,40 @@ | |||
1 | /* | ||
2 | Copyright (c) 2017 Christian Mollekopf <mollekopf@kolabsys.com> | ||
3 | |||
4 | This library is free software; you can redistribute it and/or modify it | ||
5 | under the terms of the GNU Library General Public License as published by | ||
6 | the Free Software Foundation; either version 2 of the License, or (at your | ||
7 | option) any later version. | ||
8 | |||
9 | This library is distributed in the hope that it will be useful, but WITHOUT | ||
10 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
11 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public | ||
12 | License for more details. | ||
13 | |||
14 | You should have received a copy of the GNU Library General Public License | ||
15 | along with this library; see the file COPYING.LIB. If not, write to the | ||
16 | Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA | ||
17 | 02110-1301, USA. | ||
18 | */ | ||
19 | #pragma once | ||
20 | |||
21 | #include <QtConcurrent/QtConcurrentRun> | ||
22 | #include <QFuture> | ||
23 | #include <QFutureWatcher> | ||
24 | #include <QPointer> | ||
25 | |||
26 | template<typename T> | ||
27 | void asyncRun(QObject *object, std::function<T()> run, std::function<void(T)> continuation) | ||
28 | { | ||
29 | auto guard = QPointer<QObject>{object}; | ||
30 | auto future = QtConcurrent::run(run); | ||
31 | auto watcher = new QFutureWatcher<T>; | ||
32 | QObject::connect(watcher, &QFutureWatcher<T>::finished, watcher, [watcher, continuation, guard]() { | ||
33 | if (guard) { | ||
34 | continuation(watcher->future().result()); | ||
35 | } | ||
36 | delete watcher; | ||
37 | }); | ||
38 | watcher->setFuture(future); | ||
39 | } | ||
40 | |||
diff --git a/framework/src/domain/composercontroller.cpp b/framework/src/domain/composercontroller.cpp index 471c30f8..e3218007 100644 --- a/framework/src/domain/composercontroller.cpp +++ b/framework/src/domain/composercontroller.cpp | |||
@@ -17,22 +17,16 @@ | |||
17 | Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA | 17 | Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
18 | 02110-1301, USA. | 18 | 02110-1301, USA. |
19 | */ | 19 | */ |
20 | |||
21 | |||
22 | #include "composercontroller.h" | 20 | #include "composercontroller.h" |
23 | #include <settings/settings.h> | 21 | #include <settings/settings.h> |
24 | #include <KMime/Message> | 22 | #include <KMime/Message> |
25 | #include <QVariant> | 23 | #include <QVariant> |
26 | #include <QSortFilterProxyModel> | ||
27 | #include <QList> | 24 | #include <QList> |
28 | #include <QDebug> | 25 | #include <QDebug> |
29 | #include <QMimeDatabase> | 26 | #include <QMimeDatabase> |
30 | #include <QUrlQuery> | 27 | #include <QUrlQuery> |
31 | #include <QFileInfo> | 28 | #include <QFileInfo> |
32 | #include <QFile> | 29 | #include <QFile> |
33 | #include <QtConcurrent/QtConcurrentRun> | ||
34 | #include <QFuture> | ||
35 | #include <QFutureWatcher> | ||
36 | #include <sink/store.h> | 30 | #include <sink/store.h> |
37 | #include <sink/log.h> | 31 | #include <sink/log.h> |
38 | 32 | ||
@@ -40,6 +34,7 @@ | |||
40 | #include "recepientautocompletionmodel.h" | 34 | #include "recepientautocompletionmodel.h" |
41 | #include "mime/mailtemplates.h" | 35 | #include "mime/mailtemplates.h" |
42 | #include "mime/mailcrypto.h" | 36 | #include "mime/mailcrypto.h" |
37 | #include "async.h" | ||
43 | 38 | ||
44 | std::vector<GpgME::Key> &operator+=(std::vector<GpgME::Key> &list, const std::vector<GpgME::Key> &add) | 39 | std::vector<GpgME::Key> &operator+=(std::vector<GpgME::Key> &list, const std::vector<GpgME::Key> &add) |
45 | { | 40 | { |
@@ -97,21 +92,6 @@ public: | |||
97 | } | 92 | } |
98 | }; | 93 | }; |
99 | 94 | ||
100 | template<typename T> | ||
101 | void asyncRun(QObject *object, std::function<T()> run, std::function<void(T)> continuation) | ||
102 | { | ||
103 | auto guard = QPointer<QObject>{object}; | ||
104 | auto future = QtConcurrent::run(run); | ||
105 | auto watcher = new QFutureWatcher<T>; | ||
106 | QObject::connect(watcher, &QFutureWatcher<T>::finished, watcher, [watcher, continuation, guard]() { | ||
107 | if (guard) { | ||
108 | continuation(watcher->future().result()); | ||
109 | } | ||
110 | delete watcher; | ||
111 | }); | ||
112 | watcher->setFuture(future); | ||
113 | } | ||
114 | |||
115 | class AddresseeController : public Kube::ListPropertyController | 95 | class AddresseeController : public Kube::ListPropertyController |
116 | { | 96 | { |
117 | public: | 97 | public: |
diff --git a/framework/src/domain/composercontroller.h b/framework/src/domain/composercontroller.h index 70a88900..df3c7b1b 100644 --- a/framework/src/domain/composercontroller.h +++ b/framework/src/domain/composercontroller.h | |||
@@ -22,10 +22,8 @@ | |||
22 | 22 | ||
23 | #include <QObject> | 23 | #include <QObject> |
24 | #include <QString> | 24 | #include <QString> |
25 | #include <QStringList> | ||
26 | #include <QStringListModel> | ||
27 | #include <QStandardItemModel> | ||
28 | #include <QVariant> | 25 | #include <QVariant> |
26 | #include <QStandardItemModel> | ||
29 | #include <sink/applicationdomaintype.h> | 27 | #include <sink/applicationdomaintype.h> |
30 | #include <KMime/Message> | 28 | #include <KMime/Message> |
31 | #include <gpgme++/key.h> | 29 | #include <gpgme++/key.h> |
diff --git a/framework/src/domain/mime/messageparser.cpp b/framework/src/domain/mime/messageparser.cpp index 6dc880f3..bc7535ec 100644 --- a/framework/src/domain/mime/messageparser.cpp +++ b/framework/src/domain/mime/messageparser.cpp | |||
@@ -18,15 +18,12 @@ | |||
18 | */ | 18 | */ |
19 | #include "messageparser.h" | 19 | #include "messageparser.h" |
20 | 20 | ||
21 | #include <mimetreeparser/objecttreeparser.h> | ||
22 | |||
21 | #include "partmodel.h" | 23 | #include "partmodel.h" |
22 | #include "attachmentmodel.h" | 24 | #include "attachmentmodel.h" |
23 | #include "modeltest.h" | 25 | #include "modeltest.h" |
24 | #include <mimetreeparser/objecttreeparser.h> | 26 | #include "async.h" |
25 | |||
26 | #include <QDebug> | ||
27 | #include <QtConcurrent/QtConcurrentRun> | ||
28 | #include <QFuture> | ||
29 | #include <QFutureWatcher> | ||
30 | 27 | ||
31 | class MessagePartPrivate | 28 | class MessagePartPrivate |
32 | { | 29 | { |
@@ -54,19 +51,16 @@ QVariant MessageParser::message() const | |||
54 | void MessageParser::setMessage(const QVariant &message) | 51 | void MessageParser::setMessage(const QVariant &message) |
55 | { | 52 | { |
56 | mRawContent = message.toString(); | 53 | mRawContent = message.toString(); |
57 | auto future = QtConcurrent::run([message] { | 54 | asyncRun<std::shared_ptr<MimeTreeParser::ObjectTreeParser>>(this, [=] { |
58 | auto parser = std::make_shared<MimeTreeParser::ObjectTreeParser>(); | 55 | auto parser = std::make_shared<MimeTreeParser::ObjectTreeParser>(); |
59 | parser->parseObjectTree(message.toByteArray()); | 56 | parser->parseObjectTree(message.toByteArray()); |
60 | parser->decryptParts(); | 57 | parser->decryptParts(); |
61 | return parser; | 58 | return parser; |
62 | }); | 59 | }, |
63 | auto watcher = new QFutureWatcher<std::shared_ptr<MimeTreeParser::ObjectTreeParser>>; | 60 | [this](const std::shared_ptr<MimeTreeParser::ObjectTreeParser> &parser) { |
64 | QObject::connect(watcher, &QFutureWatcher<std::shared_ptr<MimeTreeParser::ObjectTreeParser>>::finished, watcher, [this, watcher]() { | 61 | d->mParser = parser; |
65 | d->mParser = watcher->future().result(); | 62 | emit htmlChanged(); |
66 | delete watcher; | 63 | }); |
67 | emit htmlChanged(); | ||
68 | }); | ||
69 | watcher->setFuture(future); | ||
70 | } | 64 | } |
71 | 65 | ||
72 | QString MessageParser::rawContent() const | 66 | QString MessageParser::rawContent() const |