Krita Source Code Documentation
Loading...
Searching...
No Matches
KisManualUpdater.cpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2019 Anna Medonosova <anna.medonosova@gmail.com>
3 *
4 * SPDX-License-Identifier: GPL-2.0-or-later
5 */
6
7
8#include "KisManualUpdater.h"
10#include <KritaVersionWrapper.h>
11
12#include <QModelIndex>
13#include <QRegularExpression>
14#include <QRegularExpressionMatch>
15#include <QVersionNumber>
16
17#include <kis_debug.h>
18
19
21 : m_currentVersion(KritaVersionWrapper::versionString())
22{
23 m_rssModel.reset(new MultiFeedRssModel());
24}
25
26KisManualUpdater::KisManualUpdater(MultiFeedRssModel* rssModel, QString &currentVersion)
27 : m_currentVersion(currentVersion)
28{
29 m_rssModel.reset(rssModel);
30}
31
33{
34 connect(m_rssModel.data(), SIGNAL(feedDataChanged()), this, SLOT(rssDataChanged()));
35 m_rssModel->addFeed(QLatin1String("https://krita.org/en/feed/"));
36}
37
39{
40 // grab the latest release post and URL for reference later
41 // if we need to update
42 QString availableVersion;
43 QString downloadLink;
44
45 for (int i = 0; i < m_rssModel->rowCount(); i++) {
46 const QModelIndex &idx = m_rssModel->index(i);
47
48 if (idx.isValid()) {
49 // only use official release announcements to get version number
50 if ( idx.data(KisRssReader::RssRoles::CategoryRole).toString() != "Official Release") {
51 continue;
52 }
53
54 QString linkTitle = idx.data(KisRssReader::RssRoles::TitleRole).toString();
55
56 // regex to capture version number
57 QRegularExpression versionRegex("\\d\\.\\d\\.?\\d?\\.?\\d");
58 QRegularExpressionMatch matched = versionRegex.match(linkTitle);
59
60 // only take the top match for release version since that is the newest
61 if (matched.hasMatch()) {
62 availableVersion = matched.captured(0);
63 downloadLink = idx.data(KisRssReader::RssRoles::LinkRole).toString();
64 break;
65 }
66 }
67 }
68
70
71 if (availableVersionIsHigher(m_currentVersion, availableVersion)) {
73 } else {
75 }
76
78 m_updaterStatus.setAvailableVersion(availableVersion);
79 m_updaterStatus.setDownloadLink(downloadLink);
80
82}
83
84bool KisManualUpdater::availableVersionIsHigher(QString currentVersion, QString availableVersion)
85{
86 if (currentVersion.isEmpty() || availableVersion.isEmpty()) {
87 return false;
88 }
89
90 int currentSuffixIndex {5};
91 int availableSuffixIndex {5};
92
93 QVersionNumber currentVersionNumber = QVersionNumber::fromString(currentVersion, &currentSuffixIndex);
94 QVersionNumber availableVersionNumber = QVersionNumber::fromString(availableVersion, &availableSuffixIndex);
95
96 QString currentSuffix = currentVersion.mid(currentSuffixIndex);
97 QString availableSuffix = availableVersion.mid(availableSuffixIndex);
98
99 if (currentVersionNumber.normalized() == availableVersionNumber.normalized()) {
100 if (!currentSuffix.isEmpty() && availableSuffix.isEmpty()) {
101 return true;
102 } else {
103 return false;
104 }
105 } else {
106 return (currentVersionNumber.normalized() < availableVersionNumber.normalized());
107 }
108}
connect(this, SIGNAL(optionsChanged()), this, SLOT(saveOptions()))
bool availableVersionIsHigher(QString currentVersion, QString availableVersion)
void checkForUpdate() override
start the process checking whether there is an update available or not When the check is done,...
QScopedPointer< MultiFeedRssModel > m_rssModel
KisUpdaterStatus m_updaterStatus
void sigUpdateCheckStateChange(KisUpdaterStatus)
void setStatus(const UpdaterStatus::StatusID &status)
void setDownloadLink(const QString &downloadLink)
void setAvailableVersion(const QString &availableVersion)