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 text which can be used as label for a date combo box.
87 *
88 * If the allowed range for the expiration date is not empty then the text
89 * "Valid until (between MIN_DATE and MAX_DATE):" is returned. Otherwise,
90 * "Valid until (MIN_DATE):" is returned.
91 */
92KLEO_EXPORT QString validUntilLabel();
93
94/**
95 * Returns a hint which dates are valid expiration dates for a date
96 * combo box.
97 * The hint can be used as tool tip or as error message when the user
98 * entered an invalid date.
99 */
100KLEO_EXPORT QString validityPeriodHint();
101
102/**
103 * Configures the date combo box \p dateCB for choosing an expiration date.
104 *
105 * Sets the allowed date range to the \p dateRange, or to the configured
106 * validity period range if the minimum date is invalid. If the maximum
107 * date is invalid, then the maximumAllowedDate is set as maximum.
108 * Also sets a tooltip and a few fixed values to choose from, enables
109 * warnings on invalid or not allowed dates, and disables the combo box if
110 * the date range spans a single day.
111 */
112KLEO_EXPORT void setUpExpirationDateComboBox(KDateComboBox *dateCB, const Kleo::Expiration::DateRange &dateRange = {});
113}
114}
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Dec 13 2024 11:51:42 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.