Commit bd4a5291 authored by Ingo Klöcker's avatar Ingo Klöcker
Browse files

Disable the Encrypt button if required information is missing

Now that we show prominent error messages if some of the recipients are
not resolved, it should be okay to disable the Encrypt button as long as
some recipients are not resolved.

GnuPG-bug-id: 5845
parent 60e3ae56
......@@ -540,6 +540,12 @@ bool CertificateLineEdit::isEmpty() const
return d->mStatus == Private::Status::Empty;
}
bool CertificateLineEdit::hasAcceptableInput() const
{
return d->mStatus == Private::Status::Empty
|| d->mStatus == Private::Status::Success;
}
void CertificateLineEdit::Private::setKeyFilter(const std::shared_ptr<KeyFilter> &filter)
{
mFilter = filter;
......
......@@ -62,6 +62,9 @@ public:
/** Check if the text is empty */
bool isEmpty() const;
/** Returns true if the field is empty or if a key or group is selected. */
bool hasAcceptableInput() const;
/** Set the preselected Key for this widget. */
void setKey(const GpgME::Key &key);
......
......@@ -214,7 +214,7 @@ public:
if (Kleo::gnupgUsesDeVsCompliance() && !Kleo::gnupgIsDeVsCompliant()) {
return false;
}
return !mWidget->currentOp().isNull();
return mWidget->isComplete();
}
int nextId() const override
......
......@@ -628,12 +628,19 @@ void Kleo::SignEncryptWidget::onProtocolChanged()
}
}
bool SignEncryptWidget::isComplete() const
{
return !currentOp().isEmpty()
&& std::all_of(std::cbegin(mRecpWidgets), std::cend(mRecpWidgets),
[](auto w) { return !w->isEnabled() || w->hasAcceptableInput(); });
}
bool SignEncryptWidget::validate()
{
CertificateLineEdit *firstUnresolvedRecipient = nullptr;
QStringList unresolvedRecipients;
for (const auto edit: std::as_const(mRecpWidgets)) {
if (edit->isEnabled() && !edit->isEmpty() && edit->key().isNull() && edit->group().isNull()) {
if (edit->isEnabled() && !edit->hasAcceptableInput()) {
if (!firstUnresolvedRecipient) {
firstUnresolvedRecipient = edit;
}
......
......@@ -95,7 +95,11 @@ public:
/** Remove a recipient group */
void removeRecipient(const Kleo::KeyGroup &group);
/** Validate that each line edit with content has a key. */
/** Returns true if all required information has been entered. */
bool isComplete() const;
/** Returns true if all recipients have been resolved. Otherwise, shows
an error message and returns false. */
bool validate();
protected Q_SLOTS:
......
Supports Markdown
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