Fix reenable of keyselectioncombo after keylisting

We only want to renenable the keyselectioncombo when we
triggered the keylisting in refresh keys and so disabled
the combo. Otherwise the enable / disable state is changed
at random times when any keylisting in the global keycache
finishes.

This fixes a bug in Kleopatra's signencryptwidget where
random keylistings would enable the combo box even if
the operation belonging to that combo was unchecked.
parent 4ae2d16e
......@@ -265,6 +265,7 @@ public:
std::shared_ptr<Kleo::KeyCache> cache;
QString defaultKey;
bool wasEnabled = false;
bool useWasEnabled = false;
bool secretOnly;
private:
......@@ -322,8 +323,20 @@ void KeySelectionCombo::init()
// so this can be a blocking call if the cache is not initalized
d->model->useKeyCache(true, d->secretOnly);
d->proxyModel->removeCustomItem(QStringLiteral("-libkleo-loading-keys"));
setEnabled(d->wasEnabled);
Q_EMIT keyListingFinished();
// We use the useWasEnabled state variable to decide if we should
// change the enable / disable state based on the keylist done signal.
// If we triggered the refresh useWasEnabled is true and we want to
// enable / disable again after our refresh, as the refresh disabled it.
//
// But if a keyListingDone signal comes from just a generic refresh
// triggered by someone else we don't want to change the enable / disable
// state.
if (d->useWasEnabled) {
setEnabled(d->wasEnabled);
d->useWasEnabled = false;
}
Q_EMIT keyListingFinished();
});
connect(this, &KeySelectionCombo::keyListingFinished, this, [this]() { setCurrentKey(d->defaultKey); });
......@@ -389,6 +402,7 @@ void Kleo::KeySelectionCombo::setCurrentKey(const QString &fingerprint)
void KeySelectionCombo::refreshKeys()
{
d->wasEnabled = isEnabled();
d->useWasEnabled = true;
setEnabled(false);
const bool wasBlocked = blockSignals(true);
prependCustomItem(QIcon(), i18n("Loading keys ..."), QStringLiteral("-libkleo-loading-keys"));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment