Krita is a free and open source cross-platform application that offers an end-to-end solution for creating digital art files from scratch built on the KDE and Qt frameworks.
C++
Enable news and update notifications by default
Carsten Hartenfels39f8402e158b
diff --git a/libs/ui/KisWelcomePageWidget.cpp b/libs/ui/KisWelcomePageWidget.cppindex bb3570983e..2c5dd10235 100644--- a/libs/ui/KisWelcomePageWidget.cpp+++ b/libs/ui/KisWelcomePageWidget.cpp@@ -90,13 +90,6 @@#include <QRandomGenerator>#endif-// Used for triggering a QAction::setChecked signal from a QLabel::linkActivated signal-void ShowNewsAction::enableFromLink(QString unused_url)-{- Q_UNUSED(unused_url);- Q_EMIT setChecked(true);-}-// class to override item height for Breeze since qss seems to not workclass RecentItemDelegate : public QStyledItemDelegate@@ -155,10 +148,9 @@ KisWelcomePageWidget::KisWelcomePageWidget(QWidget *parent)// News widget...QMenu *newsOptionsMenu = new QMenu(this);newsOptionsMenu->setToolTipsVisible(true);- ShowNewsAction *showNewsAction = new ShowNewsAction(i18n("Enable news and check for new releases"), newsOptionsMenu);- newsOptionsMenu->addAction(showNewsAction);- showNewsAction->setToolTip(i18n("Show news about Krita: this needs internet to retrieve information from the krita.org website"));- showNewsAction->setCheckable(true);+ m_enableNewsAction = newsOptionsMenu->addAction(i18n("Automatically check for updates"));+ m_enableNewsAction->setToolTip(i18n("Show news about Krita: this needs internet to retrieve information from the krita.org website"));+ m_enableNewsAction->setCheckable(true);newsOptionsMenu->addSection(i18n("Language"));QAction *newsInfoAction = newsOptionsMenu->addAction(i18n("English news is always up to date."));@@ -167,20 +159,17 @@ KisWelcomePageWidget::KisWelcomePageWidget(QWidget *parent)setupNewsLangSelection(newsOptionsMenu);btnNewsOptions->setMenu(newsOptionsMenu);+ checkNowButton->setIcon(KisIconUtils::loadIcon(QStringLiteral("view-refresh")));+labelSupportText->setFont(largerFont());connect(btnDismisAll, SIGNAL(clicked()), newsWidget, SLOT(dismissAll()));connect(newsWidget, SIGNAL(newsStateChanged(bool)), this, SLOT(newsStateChanged(bool)));newsStateChanged(false);- connect(showNewsAction, SIGNAL(toggled(bool)), newsWidget, SLOT(setVisible(bool)));- connect(showNewsAction, SIGNAL(toggled(bool)), labelNoFeed, SLOT(setHidden(bool)));- connect(showNewsAction, SIGNAL(toggled(bool)), newsWidget, SLOT(toggleNews(bool)));- connect(labelNoFeed, SIGNAL(linkActivated(QString)), showNewsAction, SLOT(enableFromLink(QString)));--#ifdef ENABLE_UPDATERS- connect(showNewsAction, SIGNAL(toggled(bool)), this, SLOT(slotToggleUpdateChecks(bool)));-#endif+ connect(m_enableNewsAction, SIGNAL(triggered(bool)), this, SLOT(slotSetNewsEnabled(bool)));+ connect(enableNewsBox, SIGNAL(clicked(bool)), this, SLOT(slotSetNewsEnabled(bool)));+ connect(checkNowButton, SIGNAL(clicked()), this, SLOT(slotCheckNews()));supporterBadge->hide();wdgAndroidSupportBanner->hide();@@ -188,10 +177,19 @@ KisWelcomePageWidget::KisWelcomePageWidget(QWidget *parent)initDonations();#endif- // configure the News area- KisConfig cfg(true);- m_networkIsAllowed = cfg.readEntry<bool>("FetchNews", false);+ // We want to enable updates by default, but allow the user the chance to+ // disable them before making a network connection when they see the option+ // the first time.+ bool newsCheckEnabled, newsFirstStartup;+ {+ KisConfig cfg(false);+ newsCheckEnabled = cfg.newsCheckEnabled();+ newsFirstStartup = cfg.newsFirstStartup();+ cfg.setNewsFirstStartup(false);+ }+ m_enableNewsAction->setChecked(newsCheckEnabled);+ enableNewsBox->setChecked(newsCheckEnabled);#ifdef ENABLE_UPDATERS#ifndef Q_OS_ANDROID@@ -227,18 +225,15 @@ KisWelcomePageWidget::KisWelcomePageWidget(QWidget *parent)connect(bnErrorDetails, SIGNAL(clicked()), this, SLOT(slotShowUpdaterErrorDetails()));connect(m_versionUpdater.data(), SIGNAL(sigUpdateCheckStateChange(KisUpdaterStatus)),this, SLOT(slotSetUpdateStatus(const KisUpdaterStatus&)));-- if (m_networkIsAllowed) { // only if the user wants them- m_versionUpdater->checkForUpdate();- }}#endif // ifndef Q_OS_ANDROID#endif // ENABLE_UPDATERS-- showNewsAction->setChecked(m_networkIsAllowed);- newsWidget->setVisible(m_networkIsAllowed);- versionNotificationLabel->setEnabled(m_networkIsAllowed);+ if (newsCheckEnabled && !newsFirstStartup) {+ slotCheckNews();+ } else {+ newsWidget->hide();+ }// Drop area..setAcceptDrops(true);@@ -374,14 +369,6 @@ void KisWelcomePageWidget::slotUpdateThemeColors()poweredByKDELink->setText(QString("<a style=\"color: " + blendedColor.name() + " \" href=\"https://userbase.kde.org/What_is_KDE\">").append(i18n("Powered by KDE")).append("</a>"));- QString translationNoFeed = i18n("You can <a href=\"ignored\" style=\"color: COLOR_PLACEHOLDER; text-decoration: underline;\">enable news</a> from krita.org in various languages with the menu above");- labelNoFeed->setText(translationNoFeed.replace("COLOR_PLACEHOLDER", blendedColor.name()));-- const QColor faintTextColor = KisPaintingTweaks::blendColors(textColor, backgroundColor, 0.4);- const QString &faintTextStyle = "QWidget{color: " + faintTextColor.name() + "}";- labelNoRecentDocs->setStyleSheet(faintTextStyle);- labelNoFeed->setStyleSheet(faintTextStyle);-const QColor frameColor = KisPaintingTweaks::blendColors(textColor, backgroundColor, 0.1);const QString &frameQss = "{border: 1px solid " + frameColor.name() + "}";recentDocsStackedWidget->setStyleSheet("QStackedWidget#recentDocsStackedWidget" + frameQss);@@ -697,28 +684,29 @@ void KisWelcomePageWidget::slotRecentFilesModelIsUpToDate()clearRecentFilesLink->setVisible(!modelIsEmpty);}-#ifdef ENABLE_UPDATERS-void KisWelcomePageWidget::slotToggleUpdateChecks(bool state)+void KisWelcomePageWidget::slotSetNewsEnabled(bool newsEnabled){- if (m_versionUpdater.isNull()) {- return;- }-- m_networkIsAllowed = state;-- if (m_networkIsAllowed) {- m_versionUpdater->checkForUpdate();- }+ enableNewsBox->setChecked(newsEnabled);+ m_enableNewsAction->setChecked(newsEnabled);+ KisConfig(false).setNewsCheckEnabled(newsEnabled);+}+void KisWelcomePageWidget::slotCheckNews()+{+ checkNowButton->setEnabled(false);+ noNewsWidget->hide();+ newsWidget->show();+ newsWidget->toggleNews(true);+#ifdef ENABLE_UPDATERS+ m_versionUpdater->checkForUpdate();updateVersionUpdaterFrame();+#endif}++#ifdef ENABLE_UPDATERSvoid KisWelcomePageWidget::slotRunVersionUpdate(){- if (m_versionUpdater.isNull()) {- return;- }-- if (m_networkIsAllowed) {+ if (!m_versionUpdater.isNull()) {m_versionUpdater->doUpdate();}}@@ -741,7 +729,7 @@ void KisWelcomePageWidget::updateVersionUpdaterFrame()bnVersionUpdate->setVisible(false);bnErrorDetails->setVisible(false);- if (!m_networkIsAllowed || m_versionUpdater.isNull()) {+ if (m_versionUpdater.isNull()) {return;}diff --git a/libs/ui/KisWelcomePageWidget.h b/libs/ui/KisWelcomePageWidget.hindex 9f320e48f5..2df1daa279 100644--- a/libs/ui/KisWelcomePageWidget.h+++ b/libs/ui/KisWelcomePageWidget.h@@ -23,16 +23,6 @@class RecentItemDelegate;class KisMainWindow;-// Custom QAction to bridge a QLabel::linkActivated signal to a QAction::setChecked signal-class ShowNewsAction : public QAction-{- Q_OBJECT-public:- using QAction::QAction;-private Q_SLOTS:- void enableFromLink(QString unused_url);-};-/// A widget for displaying if no documents are open. This will display in the MDI areaclass KRITAUI_EXPORT KisWelcomePageWidget : public QWidget, public Ui::KisWelcomePage{@@ -75,9 +65,11 @@ private Q_SLOTS:void slotScrollerStateChanged(QScroller::State state){ KisKineticScroller::updateCursor(this, state); }+ void slotSetNewsEnabled(bool newsEnabled);+ void slotCheckNews();+#ifdef ENABLE_UPDATERSvoid slotRunVersionUpdate();- void slotToggleUpdateChecks(bool state);#endif#ifdef Q_OS_ANDROID@@ -129,11 +121,11 @@ private:QColor blendedColor;QString blendedStyle;+ QAction *m_enableNewsAction;#ifdef ENABLE_UPDATERSQScopedPointer<KisUpdaterBase> m_versionUpdater;KisUpdaterStatus m_updaterStatus;#endif- bool m_networkIsAllowed {false};QScopedPointer<RecentItemDelegate> recentItemDelegate;diff --git a/libs/ui/forms/KisWelcomePage.ui b/libs/ui/forms/KisWelcomePage.uiindex 3017d04ef6..ad4fd87ab3 100644--- a/libs/ui/forms/KisWelcomePage.ui+++ b/libs/ui/forms/KisWelcomePage.ui@@ -1552,37 +1552,73 @@ recently opened documents</string></property><layout class="QVBoxLayout" name="verticalLayout"><item>- <widget class="QLabel" name="labelNoFeed">- <property name="sizePolicy">- <sizepolicy hsizetype="Preferred" vsizetype="Expanding">- <horstretch>0</horstretch>- <verstretch>0</verstretch>- </sizepolicy>- </property>- <property name="text">- <string>You can <a href="ignored" style="color: COLOR_PLACEHOLDER; text-decoration: underline;">enable news</a> from krita.org in various languages with the menu above</string>- </property>- <property name="textFormat">- <enum>Qt::RichText</enum>- </property>- <property name="alignment">- <set>Qt::AlignCenter</set>- </property>- <property name="wordWrap">- <bool>true</bool>- </property>- <property name="margin">- <number>0</number>- </property>- <property name="indent">- <number>-1</number>- </property>- <property name="openExternalLinks">- <bool>false</bool>- </property>- <property name="textInteractionFlags">- <set>Qt::LinksAccessibleByKeyboard|Qt::LinksAccessibleByMouse</set>- </property>+ <widget class="QWidget" name="noNewsWidget" native="true">+ <layout class="QGridLayout" name="noNewsWidgetLayout" columnstretch="1,0,1">+ <property name="leftMargin">+ <number>0</number>+ </property>+ <property name="topMargin">+ <number>0</number>+ </property>+ <property name="rightMargin">+ <number>0</number>+ </property>+ <property name="bottomMargin">+ <number>0</number>+ </property>+ <property name="horizontalSpacing">+ <number>0</number>+ </property>+ <property name="verticalSpacing">+ <number>12</number>+ </property>+ <item row="0" column="0" colspan="3">+ <spacer name="noNewsTopSpacer">+ <property name="orientation">+ <enum>Qt::Vertical</enum>+ </property>+ <property name="sizeHint" stdset="0">+ <size>+ <width>0</width>+ <height>0</height>+ </size>+ </property>+ </spacer>+ </item>+ <item row="1" column="1">+ <widget class="QCheckBox" name="enableNewsBox">+ <property name="toolTip">+ <string>Show news about Krita: this needs internet to retrieve information from the krita.org website</string>+ </property>+ <property name="text">+ <string>Automatically check for updates</string>+ </property>+ </widget>+ </item>+ <item row="3" column="0" colspan="3">+ <spacer name="noNewsBottomSpacer">+ <property name="orientation">+ <enum>Qt::Vertical</enum>+ </property>+ <property name="sizeHint" stdset="0">+ <size>+ <width>0</width>+ <height>0</height>+ </size>+ </property>+ </spacer>+ </item>+ <item row="2" column="1">+ <widget class="QPushButton" name="checkNowButton">+ <property name="toolTip">+ <string>Retrieve news and updates from krita.org now.</string>+ </property>+ <property name="text">+ <string>Check Now</string>+ </property>+ </widget>+ </item>+ </layout></widget></item><item>diff --git a/libs/ui/kis_config.cc b/libs/ui/kis_config.ccindex b8bbf555e5..a30e19544a 100644--- a/libs/ui/kis_config.cc+++ b/libs/ui/kis_config.cc@@ -3024,6 +3024,26 @@ void KisConfig::setLayerThumbnailGenerationTimeout(int value)m_cfg.writeEntry("layerThumbnailGenerationTimeout", value);}+bool KisConfig::newsCheckEnabled() const+{+ return m_cfg.readEntry(QStringLiteral("newsCheckEnabled"), true);+}++void KisConfig::setNewsCheckEnabled(bool value)+{+ m_cfg.writeEntry(QStringLiteral("newsCheckEnabled"), value);+}++bool KisConfig::newsFirstStartup() const+{+ return m_cfg.readEntry(QStringLiteral("newsFirstStartup"), true);+}++void KisConfig::setNewsFirstStartup(bool value)+{+ m_cfg.writeEntry(QStringLiteral("newsFirstStartup"), value);+}+#include <QDomDocument>#include <QDomElement>diff --git a/libs/ui/kis_config.h b/libs/ui/kis_config.hindex 7aaecec53d..3587fd89c5 100644--- a/libs/ui/kis_config.h+++ b/libs/ui/kis_config.h@@ -888,6 +888,12 @@ public:int layerThumbnailGenerationTimeout(bool defaultValue = false) const;void setLayerThumbnailGenerationTimeout(int value);+ bool newsCheckEnabled() const;+ void setNewsCheckEnabled(bool value);++ bool newsFirstStartup() const;+ void setNewsFirstStartup(bool value);+template<class T>void writeEntry(const QString& name, const T& value) {m_cfg.writeEntry(name, value);diff --git a/libs/ui/widgets/KisNewsWidget.h b/libs/ui/widgets/KisNewsWidget.hindex 7561ecff27..385e976be4 100644--- a/libs/ui/widgets/KisNewsWidget.h+++ b/libs/ui/widgets/KisNewsWidget.h@@ -27,6 +27,7 @@ public:explicit KisNewsWidget(QWidget *parent = nullptr);void toggleNewsLanguage(QString langCode, bool enabled);+ void toggleNews(bool toggle);Q_SIGNALS:void newsDataChanged();@@ -37,7 +38,6 @@ protected:bool event(QEvent *event) override;private Q_SLOTS:- void toggleNews(bool toggle);void rssDataChanged();void dismissAll();void updateNewsState();