2020-02-28 23:25:08 +01:00
|
|
|
/**
|
2020-08-14 20:56:04 +02:00
|
|
|
* SPDX-FileCopyrightText: 2020 Tobias Fella <fella@posteo.de>
|
2021-04-08 13:16:36 +02:00
|
|
|
* SPDX-FileCopyrightText: 2021 Bart De Vries <bart@mogwai.be>
|
2020-02-28 23:25:08 +01:00
|
|
|
*
|
2020-08-14 20:56:04 +02:00
|
|
|
* SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
|
2020-02-28 23:25:08 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2020-04-26 23:40:09 +02:00
|
|
|
#include <QNetworkAccessManager>
|
2021-04-20 21:27:14 +02:00
|
|
|
#include <QNetworkReply>
|
2020-02-28 23:25:08 +01:00
|
|
|
#include <QObject>
|
|
|
|
#include <QUrl>
|
2020-05-18 16:47:12 +02:00
|
|
|
#include <Syndication/Syndication>
|
2020-02-28 23:25:08 +01:00
|
|
|
|
|
|
|
class Fetcher : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
2021-04-20 19:17:46 +02:00
|
|
|
|
|
|
|
Q_PROPERTY(int updateProgress MEMBER m_updateProgress NOTIFY updateProgressChanged)
|
|
|
|
Q_PROPERTY(int updateTotal MEMBER m_updateTotal NOTIFY updateTotalChanged)
|
|
|
|
Q_PROPERTY(bool updating MEMBER m_updating NOTIFY updatingChanged)
|
|
|
|
|
2020-02-28 23:25:08 +01:00
|
|
|
public:
|
|
|
|
static Fetcher &instance()
|
|
|
|
{
|
|
|
|
static Fetcher _instance;
|
|
|
|
return _instance;
|
|
|
|
}
|
2021-04-26 16:58:22 +02:00
|
|
|
|
2020-11-01 13:18:11 +01:00
|
|
|
Q_INVOKABLE void fetch(const QString &url);
|
2021-04-20 20:53:24 +02:00
|
|
|
Q_INVOKABLE void fetch(const QStringList &urls);
|
2020-05-31 18:17:25 +02:00
|
|
|
Q_INVOKABLE void fetchAll();
|
2021-04-07 12:47:46 +02:00
|
|
|
Q_INVOKABLE QString image(const QString &url) const;
|
2020-11-01 13:18:11 +01:00
|
|
|
void removeImage(const QString &url);
|
2021-04-07 12:47:46 +02:00
|
|
|
Q_INVOKABLE QNetworkReply *download(const QString &url, const QString &fileName) const;
|
|
|
|
QNetworkReply *get(QNetworkRequest &request) const;
|
|
|
|
QString imagePath(const QString &url) const;
|
|
|
|
QString enclosurePath(const QString &url) const;
|
2020-02-28 23:25:08 +01:00
|
|
|
|
2021-04-20 19:17:46 +02:00
|
|
|
Q_SIGNALS:
|
|
|
|
void startedFetchingFeed(const QString &url);
|
|
|
|
void feedUpdated(const QString &url);
|
2021-05-01 21:35:37 +02:00
|
|
|
void feedDetailsUpdated(const QString &url,
|
|
|
|
const QString &name,
|
|
|
|
const QString &image,
|
|
|
|
const QString &link,
|
|
|
|
const QString &description,
|
|
|
|
const QDateTime &lastUpdated);
|
2021-04-20 19:17:46 +02:00
|
|
|
void feedUpdateFinished(const QString &url);
|
2021-04-22 17:05:33 +02:00
|
|
|
void error(const QString &url, const QString &id, const int errorId, const QString &errorString);
|
2021-04-20 19:17:46 +02:00
|
|
|
void entryAdded(const QString &feedurl, const QString &id);
|
|
|
|
void downloadFinished(QString url) const;
|
|
|
|
|
|
|
|
void updateProgressChanged(int progress);
|
|
|
|
void updateTotalChanged(int nrOfFeeds);
|
|
|
|
void updatingChanged(bool state);
|
|
|
|
|
|
|
|
private Q_SLOTS:
|
|
|
|
void updateMonitor(int progress);
|
|
|
|
|
2020-02-28 23:25:08 +01:00
|
|
|
private:
|
|
|
|
Fetcher();
|
|
|
|
|
2021-04-26 16:58:22 +02:00
|
|
|
void retrieveFeed(const QString &url);
|
2020-11-01 13:18:11 +01:00
|
|
|
void processFeed(Syndication::FeedPtr feed, const QString &url);
|
2021-05-01 21:35:37 +02:00
|
|
|
bool processEntry(Syndication::ItemPtr entry, const QString &url, bool isNewFeed); // returns true if this is a new entry; false if it already existed
|
2021-04-05 12:43:35 +02:00
|
|
|
void processAuthor(const QString &url, const QString &entryId, const QString &authorName, const QString &authorUri, const QString &authorEmail);
|
2020-11-01 13:18:11 +01:00
|
|
|
void processEnclosure(Syndication::EnclosurePtr enclosure, Syndication::ItemPtr entry, const QString &feedUrl);
|
2020-04-26 23:40:09 +02:00
|
|
|
|
2020-04-25 22:16:19 +02:00
|
|
|
QNetworkAccessManager *manager;
|
2021-04-20 19:17:46 +02:00
|
|
|
int m_updateProgress;
|
|
|
|
int m_updateTotal;
|
|
|
|
bool m_updating;
|
2020-02-28 23:25:08 +01:00
|
|
|
};
|