[pim/kleopatra] src/crypto/gui: Avoid multiple connections for each unknown recipient

Ingo Klöcker <[email protected]>
Newsgroups gmane.comp.kde.cvs
Message-ID <[email protected]>
Git commit dc23b64b3e80741d63b9dba8ab9031626d57d467 by Ingo Klöcker, on behalf of Ingo Klöcker.
Committed on 27/07/2026 at 13:58.
Pushed by kloecker into branch 'master'.

Avoid multiple connections for each unknown recipient

Reported-by: Vadim
CCBUG: 523471

M  +25   -22   src/crypto/gui/signencryptwidget.cpp

https://invent.kde.org/pim/kleopatra/-/commit/dc23b64b3e80741d63b9dba8ab9031626d57d467

diff --git a/src/crypto/gui/signencryptwidget.cpp b/src/crypto/gui/signencryptwidget.cpp
index f2102b17d..8fabf254c 100644
--- a/src/crypto/gui/signencryptwidget.cpp
+++ b/src/crypto/gui/signencryptwidget.cpp
@@ -127,6 +127,7 @@ public:
     /* Inserts a new recipient widget after widget @p after or at the end
      * if @p after is null. */
     CertificateLineEdit *insertRecipientWidget(CertificateLineEdit *after);
+    void updateUnknownRecipients();
     void recpRemovalRequested(const RecipientWidgets &recipient);
     void onProtocolChanged();
     void updateCheckBoxes();
@@ -368,6 +369,7 @@ SignEncryptWidget::SignEncryptWidget(QWidget *parent, bool sigEncExclusive)
     connect(KeyCache::instance().get(), &Kleo::KeyCache::keysMayHaveChanged, this, [this]() {
         d->updateCheckBoxes();
         d->updateAllExpiryMessages();
+        d->updateUnknownRecipients();
     });
     connect(KleopatraApplication::instance(), &KleopatraApplication::configurationChanged, this, [this]() {
         d->updateCheckBoxes();
@@ -621,31 +623,32 @@ void SignEncryptWidget::addUnknownRecipient(const char *keyID)
         setTabOrder(lastWidget, unknownWidget);
     }
     d->mRecpLayout->addWidget(unknownWidget);
+}
 
-    connect(KeyCache::instance().get(), &Kleo::KeyCache::keysMayHaveChanged, this, [this]() {
-        // Check if any unknown recipient can now be found.
-        // Iterate over a copy because mUnknownWidgets might be modified in the loop
-        const auto unknownWidgets = d->mUnknownWidgets;
-        for (auto w : unknownWidgets) {
-            auto key = KeyCache::instance()->findByKeyIDOrFingerprint(w->keyID().toLatin1().constData());
-            if (key.isNull()) {
-                std::vector<std::string> subids;
-                subids.push_back(std::string(w->keyID().toLatin1().constData()));
-                for (const auto &subkey : KeyCache::instance()->findSubkeysByKeyID(subids)) {
-                    key = subkey.parent();
-                }
-            }
-            if (key.isNull()) {
-                continue;
+void SignEncryptWidget::Private::updateUnknownRecipients()
+{
+    // Check if any unknown recipient can now be found.
+    // Iterate over a copy because mUnknownWidgets might be modified in the loop
+    const auto unknownWidgets = mUnknownWidgets;
+    for (auto w : unknownWidgets) {
+        auto key = KeyCache::instance()->findByKeyIDOrFingerprint(w->keyID().toLatin1().constData());
+        if (key.isNull()) {
+            std::vector<std::string> subids;
+            subids.push_back(std::string(w->keyID().toLatin1().constData()));
+            for (const auto &subkey : KeyCache::instance()->findSubkeysByKeyID(subids)) {
+                key = subkey.parent();
             }
-            // Key is now available replace by line edit.
-            qCDebug(KLEOPATRA_LOG) << "Removing widget for keyid: " << w->keyID();
-            d->mRecpLayout->removeWidget(w);
-            d->mUnknownWidgets.removeAll(w);
-            delete w;
-            addRecipient(key);
         }
-    });
+        if (key.isNull()) {
+            continue;
+        }
+        // Key is now available replace by line edit.
+        qCDebug(KLEOPATRA_LOG) << "Removing widget for keyid: " << w->keyID();
+        mRecpLayout->removeWidget(w);
+        mUnknownWidgets.removeAll(w);
+        delete w;
+        q->addRecipient(key);
+    }
 }
 
 void SignEncryptWidget::recipientsChanged()
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.