Libkleo

expiration.h
1/* -*- mode: c++; c-basic-offset:4 -*-
2 utils/expiration.h
3
4 This file is part of Libkleo
5 SPDX-FileCopyrightText: 2023 g10 Code GmbH
6 SPDX-FileContributor: Ingo Klöcker <dev@ingo-kloecker.de>
7
8 SPDX-License-Identifier: GPL-2.0-or-later
9*/
10
11#pragma once
12
13#include "kleo_export.h"
14
15#include <QDate>
16
17class KDateComboBox;
18
19namespace Kleo
20{
21namespace Expiration
22{
23struct KLEO_EXPORT DateRange {
24 QDate minimum;
25 QDate maximum;
26};
27
28/**
29 * Returns a date a bit before the technically possible latest expiration
30 * date (~2106-02-07) that is safe to use as latest expiration date.
31 */
32KLEO_EXPORT QDate maximumAllowedDate();
33
34/**
35 * Returns the earliest allowed expiration date.
36 *
37 * This is either tomorrow or the configured number of days after today
38 * (whichever is later).
39 *
40 * \sa OpenPGPCertificateCreationConfig::validityPeriodInDaysMin
41 */
42KLEO_EXPORT QDate minimumExpirationDate();
43
44/**
45 * Returns the latest allowed expiration date.
46 *
47 * If unlimited validity is allowed, then an invalid date is returned.
48 * Otherwise, either the configured number of days after today or
49 * the maximum allowed date, whichever is earlier, is returned.
50 * Additionally, the returned date is never earlier than the minimum
51 * expiration date.
52 *
53 * \sa OpenPGPCertificateCreationConfig::validityPeriodInDaysMax
54 */
55KLEO_EXPORT QDate maximumExpirationDate();
56
57/**
58 * Returns the allowed range for the expiration date.
59 *
60 * \sa minimumExpirationDate, maximumExpirationDate
61 */
62KLEO_EXPORT DateRange expirationDateRange();
63
64enum class KLEO_EXPORT ExpirationOnUnlimitedValidity {
65 NoExpiration,
66 InternalDefaultExpiration,
67};
68
69/**
70 * Returns a useful value for the default expiration date based on the current
71 * date and the configured default validity. If the configured validity is
72 * unlimited, then the return value depends on \p onUnlimitedValidity.
73 *
74 * The returned value is always in the allowed range for the expiration date.
75 *
76 * \sa expirationDateRange
77 */
78KLEO_EXPORT QDate defaultExpirationDate(ExpirationOnUnlimitedValidity onUnlimitedValidity);
79
80/**
81 * Returns true, if \p date is a valid expiration date.
82 */
83KLEO_EXPORT bool isValidExpirationDate(const QDate &date);
84
85/**
86 * Returns a hint which dates are valid expiration dates for the date
87 * combo box \p dateCB.
88 * The hint can be used as tool tip or as error message when the user
89 * entered an invalid date.
90 */
91KLEO_EXPORT QString validityPeriodHint();
92
93/**
94 * Configures the date combo box \p dateCB for choosing an expiration date.
95 *
96 * Sets the allowed date range to the \p dateRange, or to the configured
97 * validity period range if the minimum date is invalid. If the maximum
98 * date is invalid, then the maximumAllowedDate is set as maximum.
99 * Also sets a tooltip and a few fixed values to choose from, enables
100 * warnings on invalid or not allowed dates, and disables the combo box if
101 * the date range spans a single day.
102 */
103KLEO_EXPORT void setUpExpirationDateComboBox(KDateComboBox *dateCB, const Kleo::Expiration::DateRange &dateRange = {});
104}
105}
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Jul 26 2024 11:50:31 by doxygen 1.11.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.