Commit 5cad27a8 authored by Scott Petrovic's avatar Scott Petrovic

Add logic to grab version numbers and calulcate if we need an update

parent 93b3a266
......@@ -174,6 +174,8 @@ void MultiFeedRssModel::appendFeedData(QNetworkReply *reply)
setArticleCount(m_aggregatedFeed.size());
beginResetModel();
endResetModel();
emit feedDataChanged();
}
void MultiFeedRssModel::removeFeed(const QString &feed)
......
......@@ -90,6 +90,7 @@ public Q_SLOTS:
Q_SIGNALS:
void articleCountChanged(int arg);
void feedDataChanged();
private Q_SLOTS:
void appendFeedData(QNetworkReply *reply);
......
......@@ -27,6 +27,7 @@
#include "kis_config.h"
#include "KisMultiFeedRSSModel.h"
#include "QRegularExpression"
KisNewsDelegate::KisNewsDelegate(QObject *parent)
......@@ -81,6 +82,8 @@ KisNewsWidget::KisNewsWidget(QWidget *parent)
{
setupUi(this);
m_rssModel = new MultiFeedRssModel(this);
connect(m_rssModel, SIGNAL(feedDataChanged()), this, SLOT(rssDataChanged()));
setCursor(Qt::PointingHandCursor);
......@@ -130,3 +133,86 @@ void KisNewsWidget::itemSelected(const QModelIndex &idx)
}
}
void KisNewsWidget::rssDataChanged()
{
// grab the latest release post and URL for reference later
// if we need to update
for (int i = 0; i < m_rssModel->rowCount(); i++)
{
const QModelIndex &idx = m_rssModel->index(i);
if (idx.isValid()) {
// only use official release announcements to get version number
if ( idx.data(RssRoles::CategoryRole).toString() != "Official Release") {
continue;
}
QString linkTitle = idx.data(RssRoles::TitleRole).toString();
// come up with a regex pattern to find version number
QRegularExpression versionRegex("\\d\\.\\d\\.?\\d?\\.?\\d");
QRegularExpressionMatch matched = versionRegex.match(linkTitle);
// only take the top match for release version since that is the newest
if (matched.hasMatch()) {
newVersionNumber = matched.captured(0);
newVersionLink = idx.data(RssRoles::LinkRole).toString();
break;
}
}
}
// see if we need to update our version, or we are on a dev version
calculateVersionUpdateStatus();
}
void KisNewsWidget::calculateVersionUpdateStatus()
{
// do version compare to see if there is a new version available
// also check to see if we are on a dev version (newer than newest release)
QStringList currentVersionParts = qApp->applicationVersion().split(".");
QStringList onlineReleaseAnnouncement = newVersionNumber.split(".");
// is the major version different?
if (onlineReleaseAnnouncement[0] > currentVersionParts[0] ) {
needsVersionUpdate = true; // we are a major version behind
return;
}
else if (onlineReleaseAnnouncement[0] < currentVersionParts[0] ) {
isDevelopmentVersion = true;
return;
}
// major versions are the same, so check minor versions
if (onlineReleaseAnnouncement[1] > currentVersionParts[1] ) {
needsVersionUpdate = true; // we are a minor version behind
return;
}
else if (onlineReleaseAnnouncement[1] < currentVersionParts[1] ) {
isDevelopmentVersion = true;
return;
}
// minor versions are the same, so maybe bugfix version is different
// sometimes we don't communicate this, implictly make 0 if it doesn't exist
if (onlineReleaseAnnouncement[2].isNull()) {
onlineReleaseAnnouncement[2] = "0";
}
if (currentVersionParts[2].isNull()) {
currentVersionParts[2] = "0";
}
if (onlineReleaseAnnouncement[2] > currentVersionParts[2] ) {
needsVersionUpdate = true; // we are a bugfix version behind
return;
}
else if (onlineReleaseAnnouncement[2] < currentVersionParts[2] ) {
isDevelopmentVersion = true;
return;
}
}
......@@ -49,10 +49,21 @@ public:
private Q_SLOTS:
void toggleNews(bool toggle);
void itemSelected(const QModelIndex &idx);
void rssDataChanged();
private:
bool m_getNews {false};
MultiFeedRssModel *m_rssModel {0};
QString analyticsTrackingParameters;
/// for new Krita version notification
QString newVersionNumber;
QString newVersionLink;
// version checking logic tells us we need to update our Krita
void calculateVersionUpdateStatus();
bool isDevelopmentVersion = false;
bool needsVersionUpdate = false;
};
#endif // KISNEWSWIDGET_H
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment