diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2017-11-25 01:04:49 +0100 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2017-11-25 01:04:49 +0100 |
commit | b68115aec3d0fd5bfa423cb265306e47b9defa73 (patch) | |
tree | 4aaf02e51c68ba8c43f684d133f4f8ea4a40f443 | |
parent | 86927d185fec4d4621aa6d7744a88285fcf233b7 (diff) | |
download | kube-b68115aec3d0fd5bfa423cb265306e47b9defa73.tar.gz kube-b68115aec3d0fd5bfa423cb265306e47b9defa73.zip |
Only look for keys when crypto is enabled
-rw-r--r-- | components/kube/contents/ui/AddresseeListEditor.qml | 1 | ||||
-rw-r--r-- | framework/src/domain/composercontroller.cpp | 52 | ||||
-rw-r--r-- | framework/src/domain/composercontroller.h | 1 |
3 files changed, 42 insertions, 12 deletions
diff --git a/components/kube/contents/ui/AddresseeListEditor.qml b/components/kube/contents/ui/AddresseeListEditor.qml index df09449f..c6149d13 100644 --- a/components/kube/contents/ui/AddresseeListEditor.qml +++ b/components/kube/contents/ui/AddresseeListEditor.qml | |||
@@ -75,6 +75,7 @@ FocusScope { | |||
75 | } | 75 | } |
76 | height: Kube.Units.gridUnit | 76 | height: Kube.Units.gridUnit |
77 | width: height | 77 | width: height |
78 | visible: model.keyFound || model.keyMissing | ||
78 | iconName: model.keyFound ? Kube.Icons.secure: Kube.Icons.insecure | 79 | iconName: model.keyFound ? Kube.Icons.secure: Kube.Icons.insecure |
79 | } | 80 | } |
80 | } | 81 | } |
diff --git a/framework/src/domain/composercontroller.cpp b/framework/src/domain/composercontroller.cpp index c20c2b0f..59c18cb6 100644 --- a/framework/src/domain/composercontroller.cpp +++ b/framework/src/domain/composercontroller.cpp | |||
@@ -90,6 +90,14 @@ public: | |||
90 | } | 90 | } |
91 | }; | 91 | }; |
92 | 92 | ||
93 | static void traverse(const QStandardItemModel *model, const std::function<void(QStandardItem *item)> &f) | ||
94 | { | ||
95 | auto root = model->invisibleRootItem(); | ||
96 | for (int row = 0; row < root->rowCount(); row++) { | ||
97 | f(root->child(row, 0)); | ||
98 | } | ||
99 | } | ||
100 | |||
93 | class AddresseeModel : public QStandardItemModel | 101 | class AddresseeModel : public QStandardItemModel |
94 | { | 102 | { |
95 | public: | 103 | public: |
@@ -98,6 +106,7 @@ public: | |||
98 | { | 106 | { |
99 | setItemRoleNames({{ComposerController::AddresseeNameRole, "addresseeName"}, | 107 | setItemRoleNames({{ComposerController::AddresseeNameRole, "addresseeName"}, |
100 | {ComposerController::KeyFoundRole, "keyFound"}, | 108 | {ComposerController::KeyFoundRole, "keyFound"}, |
109 | {ComposerController::KeyMissingRole, "keyMissing"}, | ||
101 | {ComposerController::KeyRole, "key"}}); | 110 | {ComposerController::KeyRole, "key"}}); |
102 | } | 111 | } |
103 | 112 | ||
@@ -106,18 +115,24 @@ public: | |||
106 | auto item = new QStandardItem; | 115 | auto item = new QStandardItem; |
107 | item->setData(addressee, ComposerController::AddresseeNameRole); | 116 | item->setData(addressee, ComposerController::AddresseeNameRole); |
108 | item->setData(false, ComposerController::KeyFoundRole); | 117 | item->setData(false, ComposerController::KeyFoundRole); |
118 | item->setData(mCryptoEnabled, ComposerController::KeyMissingRole); | ||
109 | appendRow(QList<QStandardItem*>() << item); | 119 | appendRow(QList<QStandardItem*>() << item); |
110 | findKey(addressee, item); | 120 | if (mCryptoEnabled) { |
121 | findKey(addressee, item); | ||
122 | } | ||
111 | } | 123 | } |
112 | 124 | ||
113 | void findKey(const QString &addressee, QStandardItem *item) | 125 | void findKey(const QString &addressee, QStandardItem *item) |
114 | { | 126 | { |
115 | SinkLog() << "Searching key for: " << addressee; | 127 | KMime::Types::Mailbox mb; |
116 | auto keys = MailCrypto::findKeys(QStringList{} << addressee, false, false, MailCrypto::OPENPGP); | 128 | mb.fromUnicodeString(addressee); |
129 | |||
130 | SinkLog() << "Searching key for: " << mb.address(); | ||
131 | auto keys = MailCrypto::findKeys(QStringList{} << mb.address(), false, false, MailCrypto::OPENPGP); | ||
117 | if (keys.empty()) { | 132 | if (keys.empty()) { |
118 | //Search for key on remote server if it's missing and import | 133 | //Search for key on remote server if it's missing and import |
119 | //TODO: this is blocking and thus blocks the UI | 134 | //TODO: this is blocking and thus blocks the UI |
120 | keys = MailCrypto::findKeys(QStringList{} << addressee, false, true, MailCrypto::OPENPGP); | 135 | keys = MailCrypto::findKeys(QStringList{} << mb.address(), false, true, MailCrypto::OPENPGP); |
121 | MailCrypto::importKeys(keys); | 136 | MailCrypto::importKeys(keys); |
122 | } | 137 | } |
123 | if (item) { | 138 | if (item) { |
@@ -161,11 +176,9 @@ public: | |||
161 | std::vector<GpgME::Key> getKeys() | 176 | std::vector<GpgME::Key> getKeys() |
162 | { | 177 | { |
163 | std::vector<GpgME::Key> keys; | 178 | std::vector<GpgME::Key> keys; |
164 | auto root = invisibleRootItem(); | 179 | traverse(this, [&] (QStandardItem *item) { |
165 | for (int row = 0; row < root->rowCount(); row++) { | ||
166 | auto item = root->child(row, 0); | ||
167 | keys.push_back(item->data(ComposerController::KeyRole).value<GpgME::Key>()); | 180 | keys.push_back(item->data(ComposerController::KeyRole).value<GpgME::Key>()); |
168 | } | 181 | }); |
169 | return keys; | 182 | return keys; |
170 | } | 183 | } |
171 | 184 | ||
@@ -180,13 +193,24 @@ public: | |||
180 | QStringList stringList() const | 193 | QStringList stringList() const |
181 | { | 194 | { |
182 | QStringList list; | 195 | QStringList list; |
183 | auto root = invisibleRootItem(); | 196 | traverse(this, [&] (QStandardItem *item) { |
184 | for (int row = 0; row < root->rowCount(); row++) { | 197 | list << item->data(ComposerController::AddresseeNameRole).toString(); |
185 | list << root->child(row, 0)->data(ComposerController::AddresseeNameRole).toString(); | 198 | }); |
186 | } | ||
187 | return list; | 199 | return list; |
188 | } | 200 | } |
189 | 201 | ||
202 | void setCryptoEnabled(bool enabled) | ||
203 | { | ||
204 | mCryptoEnabled = enabled; | ||
205 | traverse(this, [&] (QStandardItem *item) { | ||
206 | item->setData(mCryptoEnabled, ComposerController::KeyMissingRole); | ||
207 | if (mCryptoEnabled) { | ||
208 | findKey(item->data(ComposerController::AddresseeNameRole).toString(), item); | ||
209 | } | ||
210 | }); | ||
211 | } | ||
212 | |||
213 | bool mCryptoEnabled = false; | ||
190 | }; | 214 | }; |
191 | 215 | ||
192 | 216 | ||
@@ -224,6 +248,10 @@ ComposerController::ComposerController() | |||
224 | QObject::connect(this, &ComposerController::accountIdChanged, &ComposerController::updateSaveAsDraftAction); | 248 | QObject::connect(this, &ComposerController::accountIdChanged, &ComposerController::updateSaveAsDraftAction); |
225 | QObject::connect(this, &ComposerController::identityChanged, &ComposerController::findPersonalKey); | 249 | QObject::connect(this, &ComposerController::identityChanged, &ComposerController::findPersonalKey); |
226 | updateSendAction(); | 250 | updateSendAction(); |
251 | |||
252 | QObject::connect(this, &ComposerController::encryptChanged, [&] () { mToModel->setCryptoEnabled(getEncrypt()); }); | ||
253 | QObject::connect(this, &ComposerController::encryptChanged, [&] () { mCcModel->setCryptoEnabled(getEncrypt()); }); | ||
254 | QObject::connect(this, &ComposerController::encryptChanged, [&] () { mBccModel->setCryptoEnabled(getEncrypt()); }); | ||
227 | } | 255 | } |
228 | 256 | ||
229 | void ComposerController::findPersonalKey() | 257 | void ComposerController::findPersonalKey() |
diff --git a/framework/src/domain/composercontroller.h b/framework/src/domain/composercontroller.h index 3a0d4878..00386c5c 100644 --- a/framework/src/domain/composercontroller.h +++ b/framework/src/domain/composercontroller.h | |||
@@ -81,6 +81,7 @@ class ComposerController : public Kube::Controller | |||
81 | public: | 81 | public: |
82 | enum AddresseeRoles { | 82 | enum AddresseeRoles { |
83 | KeyFoundRole = Qt::UserRole + 1, | 83 | KeyFoundRole = Qt::UserRole + 1, |
84 | KeyMissingRole, | ||
84 | KeyRole, | 85 | KeyRole, |
85 | AddresseeNameRole | 86 | AddresseeNameRole |
86 | }; | 87 | }; |