[pim/kleopatra/release/26.08] 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 940caa069d9e0d3b75513bc6d9a3cb7c472765a5 by Ingo Klöcker, on behalf of Ingo Klöcker.
Committed on 27/07/2026 at 14:00.
Pushed by kloecker into branch 'release/26.08'.

Avoid multiple connections for each unknown recipient

Reported-by: Vadim
CCBUG: 523471
(cherry picked from commit dc23b64b3e80741d63b9dba8ab9031626d57d467)

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

https://invent.kde.org/pim/kleopatra/-/commit/940caa069d9e0d3b75513bc6d9a3cb7c472765a5

diff --git a/src/crypto/gui/signencryptwidget.cpp b/src/crypto/gui/signencryptwidget.cpp
index 57d36440e..fad79f6a6 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();
@@ -384,6 +385,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();
@@ -640,31 +642,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.