diff --git a/libs/ui/utils/KisManualUpdater.cpp b/libs/ui/utils/KisManualUpdater.cpp index 982bc6e7af..ac6d658056 100644 --- a/libs/ui/utils/KisManualUpdater.cpp +++ b/libs/ui/utils/KisManualUpdater.cpp @@ -1,121 +1,120 @@ /* * Copyright (c) 2019 Anna Medonosova * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "KisManualUpdater.h" #include #include #include #include #include #include #include KisManualUpdater::KisManualUpdater() : m_currentVersion(KritaVersionWrapper::versionString()) { m_rssModel.reset(new MultiFeedRssModel()); } KisManualUpdater::KisManualUpdater(MultiFeedRssModel* rssModel, QString ¤tVersion) : m_currentVersion(currentVersion) { m_rssModel.reset(rssModel); } void KisManualUpdater::checkForUpdate() { -// m_rssModel->addFeed(QLatin1String("https://krita.org/en/feed/")); - m_rssModel->addFeed(QLatin1String("http://localhost/feed.xml")); + m_rssModel->addFeed(QLatin1String("https://krita.org/en/feed/")); connect(m_rssModel.data(), SIGNAL(feedDataChanged()), this, SLOT(rssDataChanged())); } void KisManualUpdater::rssDataChanged() { // grab the latest release post and URL for reference later // if we need to update QString availableVersion; QString downloadLink; 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(KisRssReader::RssRoles::CategoryRole).toString() != "Official Release") { continue; } QString linkTitle = idx.data(KisRssReader::RssRoles::TitleRole).toString(); // regex to capture 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()) { availableVersion = matched.captured(0); downloadLink = idx.data(KisRssReader::RssRoles::LinkRole).toString(); break; } } } UpdaterStatus::StatusID status; if (availableVersionIsHigher(m_currentVersion, availableVersion)) { status = UpdaterStatus::StatusID::UPDATE_AVAILABLE; } else { status = UpdaterStatus::StatusID::UPTODATE; } m_updaterStatus.setStatus(status); m_updaterStatus.setAvailableVersion(availableVersion); m_updaterStatus.setDownloadLink(downloadLink); emit sigUpdateCheckStateChange(m_updaterStatus); } bool KisManualUpdater::availableVersionIsHigher(QString currentVersion, QString availableVersion) { if (currentVersion.isEmpty() || availableVersion.isEmpty()) { return false; } int currentSuffixIndex {5}; int availableSuffixIndex {5}; QVersionNumber currentVersionNumber = QVersionNumber::fromString(currentVersion, ¤tSuffixIndex); QVersionNumber availableVersionNumber = QVersionNumber::fromString(availableVersion, &availableSuffixIndex); QString currentSuffix = currentVersion.mid(currentSuffixIndex); QString availableSuffix = availableVersion.mid(availableSuffixIndex); if (currentVersionNumber.normalized() == availableVersionNumber.normalized()) { if (!currentSuffix.isEmpty() && availableSuffix.isEmpty()) { return true; } else { return false; } } else { return (currentVersionNumber.normalized() < availableVersionNumber.normalized()); } } diff --git a/libs/ui/widgets/KisNewsWidget.cpp b/libs/ui/widgets/KisNewsWidget.cpp index f35c7f680e..ff021d912b 100644 --- a/libs/ui/widgets/KisNewsWidget.cpp +++ b/libs/ui/widgets/KisNewsWidget.cpp @@ -1,144 +1,142 @@ /* * Copyright (c) 2018 boud * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "KisNewsWidget.h" #include #include #include #include #include #include #include #include "kis_config.h" #include "KisMultiFeedRSSModel.h" #include "QRegularExpression" KisNewsDelegate::KisNewsDelegate(QObject *parent) : QStyledItemDelegate(parent) { } void KisNewsDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const { painter->save(); QStyleOptionViewItem optionCopy = option; initStyleOption(&optionCopy, index); QStyle *style = optionCopy.widget? optionCopy.widget->style() : QApplication::style(); QTextDocument doc; doc.setHtml(optionCopy.text); doc.setDocumentMargin(10); /// Painting item without text optionCopy.text = QString(); style->drawControl(QStyle::CE_ItemViewItem, &optionCopy, painter); QAbstractTextDocumentLayout::PaintContext ctx; // Highlighting text if item is selected if (optionCopy.state & QStyle::State_Selected) { ctx.palette.setColor(QPalette::Text, optionCopy.palette.color(QPalette::Active, QPalette::HighlightedText)); } painter->translate(optionCopy.rect.left(), optionCopy.rect.top()); QRect clip(0, 0, optionCopy.rect.width(), optionCopy.rect.height()); doc.setPageSize(clip.size()); doc.drawContents(painter, clip); painter->restore(); } QSize KisNewsDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const { QStyleOptionViewItem optionCopy = option; initStyleOption(&optionCopy, index); QTextDocument doc; doc.setHtml(optionCopy.text); doc.setTextWidth(optionCopy.rect.width()); return QSize(doc.idealWidth(), doc.size().height()); } KisNewsWidget::KisNewsWidget(QWidget *parent) : QWidget(parent) , m_getNews(false) , m_rssModel(0) { setupUi(this); m_rssModel = new MultiFeedRssModel(this); connect(m_rssModel, SIGNAL(feedDataChanged()), this, SLOT(rssDataChanged())); setCursor(Qt::PointingHandCursor); listNews->setModel(m_rssModel); listNews->setItemDelegate(new KisNewsDelegate(listNews)); connect(listNews, SIGNAL(clicked(QModelIndex)), this, SLOT(itemSelected(QModelIndex))); } void KisNewsWidget::setAnalyticsTracking(QString text) { m_analyticsTrackingParameters = text; } void KisNewsWidget::toggleNews(bool toggle) { KisConfig cfg(false); cfg.writeEntry("FetchNews", toggle); if (toggle) { -// m_rssModel->addFeed(QLatin1String("https://krita.org/en/feed/")); - m_rssModel->addFeed(QLatin1String("http://localhost/feed.xml")); + m_rssModel->addFeed(QLatin1String("https://krita.org/en/feed/")); } else { -// m_rssModel->removeFeed(QLatin1String("https://krita.org/en/feed/")); - m_rssModel->removeFeed(QLatin1String("http://localhost/feed.xml")); + m_rssModel->removeFeed(QLatin1String("https://krita.org/en/feed/")); } } void KisNewsWidget::itemSelected(const QModelIndex &idx) { if (idx.isValid()) { QString link = idx.data(KisRssReader::RssRoles::LinkRole).toString(); // append query string for analytics tracking if we set it if (m_analyticsTrackingParameters != "") { // use title in analytics query string QString linkTitle = idx.data(KisRssReader::RssRoles::TitleRole).toString(); linkTitle = linkTitle.simplified(); // trims and makes 1 white space linkTitle = linkTitle.replace(" ", ""); m_analyticsTrackingParameters = m_analyticsTrackingParameters.append(linkTitle); QDesktopServices::openUrl(QUrl(link.append(m_analyticsTrackingParameters))); } else { QDesktopServices::openUrl(QUrl(link)); } } } void KisNewsWidget::rssDataChanged() { emit newsDataChanged(); }