File indexing completed on 2024-12-08 04:34:26
0001 /* 0002 SPDX-FileCopyrightText: 2023-2024 Laurent Montel <montel.org> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 code based on kdenlive 0006 */ 0007 0008 #include "needupdateversionutils.h" 0009 0010 #include <KConfigGroup> 0011 #include <KSharedConfig> 0012 0013 #include <QRegularExpression> 0014 0015 NeedUpdateVersionUtils::ObsoleteVersion NeedUpdateVersionUtils::obsoleteVersionStatus(const QString &str, const QDate ¤tDate) 0016 { 0017 static QRegularExpression regular{QStringLiteral("\\((.*)\\)")}; 0018 QRegularExpressionMatch match; 0019 QString captured; 0020 if (str.contains(regular, &match)) { 0021 captured = match.captured(1); 0022 } else { 0023 captured = str; 0024 } 0025 if (!captured.isEmpty()) { 0026 const QStringList version = captured.split(QLatin1Char('.')); 0027 if (version.size() > 2) { 0028 bool ok; 0029 int year = version.at(0).toInt(&ok); 0030 if (ok) { 0031 const int month = version.at(1).toInt(&ok); 0032 if (ok) { 0033 if (year < 100) { 0034 year += 2000; 0035 } 0036 const QDate releaseDate = QDate(year, month, 1); 0037 if (releaseDate.isValid()) { 0038 const int days = releaseDate.daysTo(currentDate); 0039 if (days > 180) { 0040 if (days > 360) { 0041 return NeedUpdateVersionUtils::ObsoleteVersion::OlderThan12Months; 0042 } 0043 return NeedUpdateVersionUtils::ObsoleteVersion::OlderThan6Months; 0044 } 0045 } 0046 } 0047 } 0048 } 0049 } else { 0050 return NeedUpdateVersionUtils::ObsoleteVersion::Unknown; 0051 } 0052 return NeedUpdateVersionUtils::ObsoleteVersion::NotObsoleteYet; 0053 } 0054 0055 void NeedUpdateVersionUtils::disableCheckVersion() 0056 { 0057 KSharedConfig::Ptr config = KSharedConfig::openConfig(); 0058 KConfigGroup group(config, QStringLiteral("Check Version")); 0059 group.writeEntry("checkerVersionEnabled", false); 0060 } 0061 0062 bool NeedUpdateVersionUtils::checkVersion() 0063 { 0064 KSharedConfig::Ptr config = KSharedConfig::openConfig(); 0065 KConfigGroup group(config, QStringLiteral("Check Version")); 0066 return group.readEntry("checkerVersionEnabled", true); 0067 }