diff --git a/CHANGELOG.md b/CHANGELOG.md
index e27d79fe..cd1c3573 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -22,6 +22,7 @@
* KColorUtils migration has been completed.
* KColorScheme migration has been completed.
* KIconThemes migration has been completed.
+* The MeshMC News section is now displayed via KF6 Syndication.
## Removed
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 241d1035..30804d61 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -171,6 +171,7 @@ find_package(KF6 6.23 REQUIRED COMPONENTS I18n
ColorScheme
IconThemes
BreezeIcons
+ Syndication
)
if(UNIX)
diff --git a/launcher/CMakeLists.txt b/launcher/CMakeLists.txt
index 6bfe1b51..3efa871a 100644
--- a/launcher/CMakeLists.txt
+++ b/launcher/CMakeLists.txt
@@ -415,6 +415,7 @@ target_link_libraries(MeshMC_logic
KF6::ColorScheme
KF6::IconThemes
KF6::BreezeIcons
+ KF6::Syndication
LibArchive::LibArchive
cmark::cmark
LocalPeer::LocalPeer
diff --git a/launcher/news/CMakeLists.txt b/launcher/news/CMakeLists.txt
index 3367ac32..0ea59e58 100644
--- a/launcher/news/CMakeLists.txt
+++ b/launcher/news/CMakeLists.txt
@@ -5,4 +5,6 @@ target_sources(MeshMC_logic PRIVATE
NewsChecker.cpp
NewsEntry.h
NewsEntry.cpp
+ NewsFeed.h
+ NewsFeed.cpp
)
diff --git a/launcher/news/NewsChecker.cpp b/launcher/news/NewsChecker.cpp
index ac0a751b..1919cc55 100644
--- a/launcher/news/NewsChecker.cpp
+++ b/launcher/news/NewsChecker.cpp
@@ -19,10 +19,10 @@
*/
#include "NewsChecker.h"
+#include "NewsFeed.h"
#include "Logging.h"
#include
-#include
#include
@@ -130,44 +130,21 @@ void NewsChecker::rssDownloadFinished(int feedIndex)
feed.job.reset();
feed.entries.clear();
- QDomDocument doc;
- {
- // Stuff to store error info in.
- QString errorMsg = "Unknown error.";
- int errorLine = -1;
- int errorCol = -1;
-
- // Parse the XML.
- if (!doc.setContent(feed.data, false, &errorMsg, &errorLine,
- &errorCol)) {
- QString fullErrorMsg =
- QString("Error parsing RSS feed XML. %1 at %2:%3.")
- .arg(errorMsg)
- .arg(errorLine)
- .arg(errorCol);
- feed.data.clear();
- rssDownloadFailed(feedIndex, fullErrorMsg);
- return;
- }
+ QList parsed;
+ QString errorMsg;
+ if (!News::parseFeed(feed.data, feed.url, feedIndex, &parsed, &errorMsg)) {
feed.data.clear();
+ rssDownloadFailed(
+ feedIndex,
+ QStringLiteral("Error reading the feed. %1.").arg(errorMsg));
+ return;
}
+ feed.data.clear();
- // If the parsing succeeded, read it.
- QDomNodeList items = doc.elementsByTagName("item");
- for (int i = 0; i < items.length(); i++) {
- QDomElement element = items.at(i).toElement();
- NewsEntryPtr entry;
- entry.reset(new NewsEntry());
- QString errorMsg = "An unknown error occurred.";
- if (NewsEntry::fromXmlElement(element, entry.get(), &errorMsg)) {
- entry->feedIndex = feedIndex;
- qCDebug(newsLog) << "Loaded news entry" << entry->title;
- feed.entries.append(entry);
- } else {
- qCWarning(newsLog) << "Failed to load news entry at index" << i << ":"
- << errorMsg;
- }
+ for (const auto& entry : parsed) {
+ qCDebug(newsLog) << "Loaded news entry" << entry->title;
}
+ feed.entries = parsed;
feedSettled();
}
diff --git a/launcher/news/NewsEntry.cpp b/launcher/news/NewsEntry.cpp
index 57780cbc..48150e29 100644
--- a/launcher/news/NewsEntry.cpp
+++ b/launcher/news/NewsEntry.cpp
@@ -20,8 +20,6 @@
#include "NewsEntry.h"
-#include
-#include
#include
NewsEntry::NewsEntry(QObject* parent) : QObject(parent)
@@ -44,41 +42,3 @@ NewsEntry::NewsEntry(const QString& title, const QString& content,
this->author = author;
this->pubDate = pubDate;
}
-
-/*!
- * Gets the text content of the given child element as a QVariant.
- */
-inline QString childValue(const QDomElement& element, const QString& childName,
- QString defaultVal = "")
-{
- QDomNodeList nodes = element.elementsByTagName(childName);
- if (nodes.count() > 0) {
- QDomElement childElement = nodes.at(0).toElement();
- return childElement.text();
- } else {
- return defaultVal;
- }
-}
-
-bool NewsEntry::fromXmlElement(const QDomElement& element, NewsEntry* entry,
- QString* errorMsg)
-{
- (void)errorMsg;
- QString title = childValue(element, "title", i18n("Untitled"));
- QString content = childValue(element, "description", i18n("No content."));
- QString link = childValue(element, "link");
- QString author = childValue(element, "dc:creator", i18n("Unknown Author"));
- QString pubDateStr = childValue(element, "pubDate");
-
- // FIXME: For now, we're just ignoring timezones. We assume that all time
- // zones in the RSS feed are the same.
- QString dateFormat("ddd, dd MMM yyyy hh:mm:ss");
- QDateTime pubDate = QDateTime::fromString(pubDateStr, dateFormat);
-
- entry->title = title;
- entry->content = content;
- entry->link = link;
- entry->author = author;
- entry->pubDate = pubDate;
- return true;
-}
diff --git a/launcher/news/NewsEntry.h b/launcher/news/NewsEntry.h
index 789b25e8..0940bc07 100644
--- a/launcher/news/NewsEntry.h
+++ b/launcher/news/NewsEntry.h
@@ -22,7 +22,6 @@
#include
#include
-#include
#include
#include
@@ -45,14 +44,6 @@ class NewsEntry : public QObject
const QString& author, const QDateTime& pubDate,
QObject* parent = 0);
- /*!
- * Attempts to load information from the given XML element into the given
- * news entry pointer. If this fails, the function will return false and
- * store an error message in the errorMsg pointer.
- */
- static bool fromXmlElement(const QDomElement& element, NewsEntry* entry,
- QString* errorMsg = 0);
-
//! The post title.
QString title;
@@ -71,9 +62,9 @@ class NewsEntry : public QObject
/*!
* Which of NewsChecker's feeds this entry came from. 0 is the
* launcher's own feed; anything higher is an extra feed configured
- * at build time via MeshMC_NEWS_EXTRA_FEEDS. Set by NewsChecker
- * after parsing, not by fromXmlElement() — the XML says nothing
- * about where it was downloaded from.
+ * at build time via MeshMC_NEWS_EXTRA_FEEDS. Set by News::parseFeed()
+ * from the index NewsChecker gives it — the XML says nothing about
+ * where it was downloaded from.
*/
int feedIndex = 0;
};
diff --git a/launcher/news/NewsFeed.cpp b/launcher/news/NewsFeed.cpp
new file mode 100644
index 00000000..49cec225
--- /dev/null
+++ b/launcher/news/NewsFeed.cpp
@@ -0,0 +1,82 @@
+/* SPDX-FileCopyrightText: 2026 Project Tick
+ * SPDX-FileContributor: Project Tick
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Copyright 2013-2021 MultiMC Contributors
+ * Copyright (C) 2026 Project Tick
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "NewsFeed.h"
+
+#include
+
+#include
+
+#include
+
+namespace News
+{
+ bool parseFeed(const QByteArray& data, const QString& url, int feedIndex,
+ QList* entries, QString* error)
+ {
+ const Syndication::FeedPtr feed =
+ Syndication::parse(Syndication::DocumentSource(data, url));
+ if (!feed) {
+ *error = QStringLiteral("this is not an RSS or an Atom feed");
+ return false;
+ }
+
+ entries->clear();
+ for (const Syndication::ItemPtr& item : feed->items()) {
+ auto entry = std::make_shared();
+
+ // The title of an item is HTML as far as Syndication is
+ // concerned ("Fish & Chips"); a NewsEntry has plain text
+ // there, which the news dialog escapes itself.
+ const QString title = Syndication::resolveEntities(item->title());
+ if (!title.isEmpty()) {
+ entry->title = title;
+ }
+
+ // An RSS item says its text in the description, unless it has a
+ // content of its own; an Atom entry, the other way round.
+ const QString content = item->content().isEmpty()
+ ? item->description()
+ : item->content();
+ if (!content.isEmpty()) {
+ entry->content = content;
+ }
+
+ entry->link = item->link();
+
+ const auto authors = item->authors();
+ if (!authors.isEmpty() && !authors.first()->name().isEmpty()) {
+ entry->author =
+ Syndication::resolveEntities(authors.first()->name());
+ }
+
+ const time_t published = item->datePublished() != 0
+ ? item->datePublished()
+ : item->dateUpdated();
+ entry->pubDate = published != 0
+ ? QDateTime::fromSecsSinceEpoch(published)
+ : QDateTime();
+
+ entry->feedIndex = feedIndex;
+ entries->append(entry);
+ }
+ return true;
+ }
+} // namespace News
diff --git a/launcher/news/NewsFeed.h b/launcher/news/NewsFeed.h
new file mode 100644
index 00000000..bea648f7
--- /dev/null
+++ b/launcher/news/NewsFeed.h
@@ -0,0 +1,46 @@
+/* SPDX-FileCopyrightText: 2026 Project Tick
+ * SPDX-FileContributor: Project Tick
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Copyright 2013-2021 MultiMC Contributors
+ * Copyright (C) 2026 Project Tick
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#pragma once
+
+#include
+#include
+#include
+
+#include "NewsEntry.h"
+
+namespace News
+{
+ /*!
+ * Reads the entries of a news feed, which is an RSS or an Atom document
+ * (KDE Frameworks' Syndication tells which, and reads either).
+ *
+ * Every entry gets \p feedIndex. A date is taken as it is given, with its
+ * time zone; an entry without a date has an invalid one, which makes it
+ * the oldest. An entry that has no title, content or author gets the
+ * words NewsEntry has for that.
+ *
+ * \param url where the document came from, which a feed may use to
+ * resolve addresses that are relative to it.
+ * \return false if \p data is not a feed; \p error then says what is wrong.
+ */
+ bool parseFeed(const QByteArray& data, const QString& url, int feedIndex,
+ QList* entries, QString* error);
+} // namespace News
diff --git a/launcher/news/NewsFeed_test.cpp b/launcher/news/NewsFeed_test.cpp
new file mode 100644
index 00000000..cb7a3218
--- /dev/null
+++ b/launcher/news/NewsFeed_test.cpp
@@ -0,0 +1,170 @@
+/* SPDX-FileCopyrightText: 2026 Project Tick
+ * SPDX-FileContributor: Project Tick
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Copyright 2013-2021 MultiMC Contributors
+ * Copyright (C) 2026 Project Tick
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include
+
+#include
+#include
+
+#include
+
+#include "news/NewsFeed.h"
+
+// What the news bar gets out of a feed: the RSS one that MeshMC's site
+// publishes, and Atom, which Syndication reads as well.
+class NewsFeedTest : public QObject
+{
+ Q_OBJECT
+
+ private slots:
+ void initTestCase()
+ {
+ KLocalizedString::setApplicationDomain("meshmc");
+ }
+
+ void test_AnRssFeedIsRead()
+ {
+ const QByteArray rss = QByteArray(
+ "\n"
+ "\n"
+ " \n"
+ " MeshMC\n"
+ " https://example.org/\n"
+ " News\n"
+ " \n"
+ " Fish & Chips\n"
+ " https://example.org/fish\n"
+ " Hello world