diff options
author | Minijackson <minijackson@riseup.net> | 2018-03-01 11:13:22 +0100 |
---|---|---|
committer | Minijackson <minijackson@riseup.net> | 2018-03-08 16:29:09 +0100 |
commit | f6e8b7ff01c7de0a7b7613bf46b51adf3a8a59a1 (patch) | |
tree | 15263afda758e6384c97b779b3452be66a817cca /framework/src/domain/mime/attachmentmodel.cpp | |
parent | ef3433a40e23c56a3a9c6158fde06729e7b0cd12 (diff) | |
download | kube-f6e8b7ff01c7de0a7b7613bf46b51adf3a8a59a1.tar.gz kube-f6e8b7ff01c7de0a7b7613bf46b51adf3a8a59a1.zip |
Add key import
Diffstat (limited to 'framework/src/domain/mime/attachmentmodel.cpp')
-rw-r--r-- | framework/src/domain/mime/attachmentmodel.cpp | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/framework/src/domain/mime/attachmentmodel.cpp b/framework/src/domain/mime/attachmentmodel.cpp index 2eb2cc13..8b12679b 100644 --- a/framework/src/domain/mime/attachmentmodel.cpp +++ b/framework/src/domain/mime/attachmentmodel.cpp | |||
@@ -32,6 +32,11 @@ | |||
32 | #include <QUrl> | 32 | #include <QUrl> |
33 | #include <QMimeDatabase> | 33 | #include <QMimeDatabase> |
34 | 34 | ||
35 | #include <QGpgME/ImportJob> | ||
36 | #include <QGpgME/Protocol> | ||
37 | |||
38 | #include <memory> | ||
39 | |||
35 | QString sizeHuman(float size) | 40 | QString sizeHuman(float size) |
36 | { | 41 | { |
37 | QStringList list; | 42 | QStringList list; |
@@ -210,6 +215,36 @@ bool AttachmentModel::openAttachment(const QModelIndex &index) | |||
210 | return false; | 215 | return false; |
211 | } | 216 | } |
212 | 217 | ||
218 | bool AttachmentModel::importPublicKey(const QModelIndex &index) | ||
219 | { | ||
220 | Q_ASSERT(index.internalPointer()); | ||
221 | const auto part = static_cast<MimeTreeParser::MessagePart *>(index.internalPointer()); | ||
222 | Q_ASSERT(part); | ||
223 | auto pkey = part->node()->decodedContent(); | ||
224 | |||
225 | const auto *proto = QGpgME::openpgp(); | ||
226 | std::unique_ptr<QGpgME::ImportJob> job(proto->importJob()); | ||
227 | auto result = job->exec(pkey); | ||
228 | |||
229 | bool success = true; | ||
230 | |||
231 | QString message; | ||
232 | if(result.numConsidered() == 0) { | ||
233 | message = tr("No keys were found in this attachment"); | ||
234 | success = false; | ||
235 | } else { | ||
236 | message = tr("%n Key(s) imported", "", result.numImported()); | ||
237 | if(result.numUnchanged() != 0) { | ||
238 | message += "\n" + tr("%n Key(s) were already imported", "", result.numUnchanged()); | ||
239 | } | ||
240 | } | ||
241 | |||
242 | Kube::Fabric::Fabric{}.postMessage("notification", | ||
243 | {{"message", message}}); | ||
244 | |||
245 | return success; | ||
246 | } | ||
247 | |||
213 | QModelIndex AttachmentModel::parent(const QModelIndex &) const | 248 | QModelIndex AttachmentModel::parent(const QModelIndex &) const |
214 | { | 249 | { |
215 | return QModelIndex(); | 250 | return QModelIndex(); |