File indexing completed on 2024-05-12 16:23:40
0001 /** 0002 * SPDX-FileCopyrightText: 2020 Tobias Fella <fella@posteo.de> 0003 * 0004 * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL 0005 */ 0006 0007 #pragma once 0008 0009 #include <QNetworkAccessManager> 0010 #include <QObject> 0011 #include <QUrl> 0012 #include <Syndication/Syndication> 0013 0014 class Fetcher : public QObject 0015 { 0016 Q_OBJECT 0017 0018 Q_PROPERTY(bool refreshing READ refreshing NOTIFY refreshingChanged) 0019 0020 public: 0021 static Fetcher &instance() 0022 { 0023 static Fetcher _instance; 0024 return _instance; 0025 } 0026 Q_INVOKABLE void fetch(const QString &url, const bool markEntriesRead = false); 0027 Q_INVOKABLE void fetchAll(); 0028 Q_INVOKABLE QString image(const QString &url); 0029 void removeImage(const QString &url); 0030 Q_INVOKABLE void download(const QString &url); 0031 QNetworkReply *get(QNetworkRequest &request); 0032 0033 private: 0034 Fetcher(); 0035 0036 QString filePath(const QString &url); 0037 void processFeed(Syndication::FeedPtr feed, const QString &url, const bool markEntriesRead = false); 0038 void processEntry(Syndication::ItemPtr entry, const QString &url, const bool markEntriesRead = false); 0039 void processAuthor(Syndication::PersonPtr author, const QString &entryId, const QString &url); 0040 void processEnclosure(Syndication::EnclosurePtr enclosure, Syndication::ItemPtr entry, const QString &feedUrl); 0041 QString syndicationErrorToString(Syndication::ErrorCode errorCode); 0042 0043 bool refreshing() const 0044 { 0045 return m_fetchCount > 0; 0046 }; 0047 void setFetchCount(int count); 0048 0049 int m_fetchCount; 0050 0051 QNetworkAccessManager *manager; 0052 0053 Q_SIGNALS: 0054 void startedFetchingFeed(const QString &url); 0055 void feedUpdated(const QString &url); 0056 void feedDetailsUpdated(const QString &url, 0057 const QString &name, 0058 const QString &image, 0059 const QString &link, 0060 const QString &description, 0061 const QDateTime &lastUpdated); 0062 void error(const QString &url, int errorId, const QString &errorString); 0063 void imageDownloadFinished(const QString &url); 0064 void refreshingChanged(bool refreshing); 0065 };