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

Prefill expiration date with default if expiration is enabled

If expiration is enabled and the expiration date is not yet set to a
valid value, then set the expiration date to the default.

GnuPG-bug-id: 5708
parent a2919db7
Pipeline #103773 passed with stage
in 1 minute and 45 seconds
......@@ -439,22 +439,6 @@
</hint>
</hints>
</connection>
<connection>
<sender>expiryCB</sender>
<signal>toggled(bool)</signal>
<receiver>expiryDE</receiver>
<slot>setEnabled(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>120</x>
<y>328</y>
</hint>
<hint type="destinationlabel">
<x>172</x>
<y>326</y>
</hint>
</hints>
</connection>
<connection>
<sender>dsaRB</sender>
<signal>toggled(bool)</signal>
......
......@@ -102,6 +102,9 @@ static const QStringList curveNames {
{ QStringLiteral("NIST P-521") },
};
namespace
{
class EmptyPassphraseProvider: public PassphraseProvider
{
public:
......@@ -282,6 +285,27 @@ static void parseAlgoString(const QString &algoString, int *size, Subkey::Pubkey
qCWarning(KLEOPATRA_LOG) << "Failed to parse default_pubkey_algo:" << algoString;
}
enum class OnUnlimitedValidity {
ReturnInvalidDate,
ReturnInternalDefault
};
QDate defaultExpirationDate(OnUnlimitedValidity onUnlimitedValidity)
{
QDate expirationDate{};
const auto settings = Kleo::Settings{};
const auto defaultExpirationInDays = settings.validityPeriodInDays();
if (defaultExpirationInDays > 0) {
expirationDate = QDate::currentDate().addDays(defaultExpirationInDays);
} else if (defaultExpirationInDays < 0 || onUnlimitedValidity == OnUnlimitedValidity::ReturnInternalDefault) {
expirationDate = QDate::currentDate().addYears(2);
}
return expirationDate;
}
}
Q_DECLARE_METATYPE(GpgME::Subkey::PubkeyAlgo)
namespace Kleo
{
......@@ -403,6 +427,14 @@ public:
ui.uriLW->setDefaultValue(i18n("new uri"));
fillKeySizeComboBoxen();
connect(ui.expiryCB, &QAbstractButton::toggled,
this, [this](bool checked) {
ui.expiryDE->setEnabled(checked);
if (checked && !ui.expiryDE->isValid()) {
ui.expiryDE->setDate(defaultExpirationDate(OnUnlimitedValidity::ReturnInternalDefault));
}
});
}
void setProtocol(GpgME::Protocol proto)
......@@ -1837,15 +1869,7 @@ void AdvancedSettingsDialog::loadDefaultExpiration()
return;
}
const auto settings = Kleo::Settings{};
const auto defaultExpirationInDays = settings.validityPeriodInDays();
if (defaultExpirationInDays > 0) {
setExpiryDate(QDate::currentDate().addDays(defaultExpirationInDays));
} else if (defaultExpirationInDays == 0) {
setExpiryDate({}); // no expiration
} else {
setExpiryDate(QDate::currentDate().addYears(2));
}
setExpiryDate(defaultExpirationDate(OnUnlimitedValidity::ReturnInvalidDate));
}
void AdvancedSettingsDialog::loadDefaults()
......
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