Changeset View
Changeset View
Standalone View
Standalone View
framework/src/domain/mime/attachmentmodel.cpp
Show All 26 Lines | |||||
27 | #include <KMime/Content> | 27 | #include <KMime/Content> | ||
28 | #include <QFile> | 28 | #include <QFile> | ||
29 | #include <QStandardPaths> | 29 | #include <QStandardPaths> | ||
30 | #include <QDesktopServices> | 30 | #include <QDesktopServices> | ||
31 | #include <QDir> | 31 | #include <QDir> | ||
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; | ||
38 | list << "KB" << "MB" << "GB" << "TB"; | 43 | list << "KB" << "MB" << "GB" << "TB"; | ||
39 | 44 | | |||
40 | QStringListIterator i(list); | 45 | QStringListIterator i(list); | ||
41 | QString unit("Bytes"); | 46 | QString unit("Bytes"); | ||
42 | 47 | | |||
▲ Show 20 Lines • Show All 162 Lines • ▼ Show 20 Line(s) | 208 | if (!QDesktopServices::openUrl(QUrl("file://" + filePath))) { | |||
205 | return false; | 210 | return false; | ||
206 | } | 211 | } | ||
207 | return true; | 212 | return true; | ||
208 | } | 213 | } | ||
209 | Kube::Fabric::Fabric{}.postMessage("notification", {{"message", tr("Failed to save attachment for opening.")}}); | 214 | Kube::Fabric::Fabric{}.postMessage("notification", {{"message", tr("Failed to save attachment for opening.")}}); | ||
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(); | ||
216 | } | 251 | } | ||
217 | 252 | | |||
218 | int AttachmentModel::rowCount(const QModelIndex &parent) const | 253 | int AttachmentModel::rowCount(const QModelIndex &parent) const | ||
219 | { | 254 | { | ||
220 | if (!parent.isValid()) { | 255 | if (!parent.isValid()) { | ||
Show All 9 Lines |