Pimcommon

needupdateversionutils.cpp
1/*
2 SPDX-FileCopyrightText: 2023-2024 Laurent Montel <montel.org>
3
4 SPDX-License-Identifier: GPL-2.0-or-later
5 code based on kdenlive
6*/
7
8#include "needupdateversionutils.h"
9
10#include <KConfigGroup>
11#include <KSharedConfig>
12
13#include <QRegularExpression>
14
15PimCommon::NeedUpdateVersionUtils::ObsoleteVersion PimCommon::NeedUpdateVersionUtils::obsoleteVersionStatus(const QString &str, QDate currentDate)
16{
17 static QRegularExpression regular{QStringLiteral("\\((.*)\\)")};
19 QString captured;
20 if (str.contains(regular, &match)) {
21 captured = match.captured(1);
22 } else {
23 captured = str;
24 }
25 if (!captured.isEmpty()) {
26 const QStringList version = captured.split(QLatin1Char('.'));
27 if (version.size() > 2) {
28 bool ok;
29 int year = version.at(0).toInt(&ok);
30 if (ok) {
31 const int month = version.at(1).toInt(&ok);
32 if (ok) {
33 if (year < 100) {
34 year += 2000;
35 }
36 const QDate releaseDate = QDate(year, month, 1);
37 if (releaseDate.isValid()) {
38 const int days = releaseDate.daysTo(currentDate);
39 if (days > 180) {
40 if (days > 360) {
41 return PimCommon::NeedUpdateVersionUtils::ObsoleteVersion::OlderThan12Months;
42 }
43 return PimCommon::NeedUpdateVersionUtils::ObsoleteVersion::OlderThan6Months;
44 }
45 }
46 }
47 }
48 }
49 } else {
50 return PimCommon::NeedUpdateVersionUtils::ObsoleteVersion::Unknown;
51 }
52 return PimCommon::NeedUpdateVersionUtils::ObsoleteVersion::NotObsoleteYet;
53}
54
55void PimCommon::NeedUpdateVersionUtils::disableCheckVersion()
56{
57 KSharedConfig::Ptr config = KSharedConfig::openConfig();
58 KConfigGroup group(config, QStringLiteral("Check Version"));
59 group.writeEntry("checkerVersionEnabled", false);
60}
61
62bool PimCommon::NeedUpdateVersionUtils::checkVersion()
63{
64#if ENABLE_WARN_OUTDATED == 1
65 KSharedConfig::Ptr config = KSharedConfig::openConfig();
66 KConfigGroup group(config, QStringLiteral("Check Version"));
67 return group.readEntry("checkerVersionEnabled", true);
68#else
69 return false;
70#endif
71}
static KSharedConfig::Ptr openConfig(const QString &fileName=QString(), OpenFlags mode=FullConfig, QStandardPaths::StandardLocation type=QStandardPaths::GenericConfigLocation)
KDB_EXPORT KDbVersionInfo version()
KCOREADDONS_EXPORT Result match(QStringView pattern, QStringView str)
qint64 daysTo(QDate d) const const
bool isValid(int year, int month, int day)
bool contains(QChar ch, Qt::CaseSensitivity cs) const const
bool isEmpty() const const
QStringList split(QChar sep, Qt::SplitBehavior behavior, Qt::CaseSensitivity cs) const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:14:35 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.