2020-02-28 23:25:08 +01:00
|
|
|
/**
|
2023-02-27 19:18:46 +01:00
|
|
|
* SPDX-FileCopyrightText: 2020 Tobias Fella <tobias.fella@kde.org>
|
2022-05-25 16:01:38 +02:00
|
|
|
* SPDX-FileCopyrightText: 2021-2022 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
|
|
|
|
|
2024-04-16 16:08:37 +02:00
|
|
|
#include <QDateTime>
|
2021-06-04 21:34:50 +02:00
|
|
|
#include <QFile>
|
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>
|
2024-01-02 14:27:27 +01:00
|
|
|
#include <QQmlEngine>
|
2024-04-16 16:08:37 +02:00
|
|
|
#include <QTimer>
|
2020-02-28 23:25:08 +01:00
|
|
|
#include <QUrl>
|
2020-05-18 16:47:12 +02:00
|
|
|
#include <Syndication/Syndication>
|
2020-02-28 23:25:08 +01:00
|
|
|
|
2021-09-23 19:23:39 +02:00
|
|
|
#include "enclosure.h"
|
2021-05-14 16:46:54 +02:00
|
|
|
#include "error.h"
|
|
|
|
|
2020-02-28 23:25:08 +01:00
|
|
|
class Fetcher : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
2024-01-02 14:27:27 +01:00
|
|
|
QML_ELEMENT
|
|
|
|
QML_SINGLETON
|
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;
|
|
|
|
}
|
2024-01-02 14:27:27 +01:00
|
|
|
static Fetcher *create(QQmlEngine *engine, QJSEngine *)
|
|
|
|
{
|
|
|
|
engine->setObjectOwnership(&instance(), QQmlEngine::CppOwnership);
|
|
|
|
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-10-06 16:07:05 +02:00
|
|
|
Q_INVOKABLE QString image(const QString &url);
|
2021-04-07 12:47:46 +02:00
|
|
|
Q_INVOKABLE QNetworkReply *download(const QString &url, const QString &fileName) const;
|
2023-02-15 16:43:57 +01:00
|
|
|
void getRedirectedUrl(const QUrl &url);
|
2021-05-14 16:46:54 +02:00
|
|
|
|
2021-06-27 00:53:28 +02:00
|
|
|
QNetworkReply *get(QNetworkRequest &request) const;
|
2021-10-29 17:00:52 +02:00
|
|
|
QNetworkReply *post(QNetworkRequest &request, const QByteArray &data) const;
|
2020-02-28 23:25:08 +01:00
|
|
|
|
2024-04-16 16:08:37 +02:00
|
|
|
void initializeUpdateTimer();
|
|
|
|
void checkUpdateTimer();
|
|
|
|
|
2024-04-23 16:50:32 +02:00
|
|
|
Q_INVOKABLE void setNetworkProxy();
|
|
|
|
Q_INVOKABLE bool isSystemProxyDefined();
|
|
|
|
|
2021-04-20 19:17:46 +02:00
|
|
|
Q_SIGNALS:
|
2021-09-23 19:23:39 +02:00
|
|
|
void entryAdded(const QString &feedurl, const QString &id);
|
2022-05-25 16:01:38 +02:00
|
|
|
void entryUpdated(const QString &feedurl, const QString &id);
|
2021-04-20 19:17:46 +02:00
|
|
|
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,
|
2023-07-05 16:03:11 +02:00
|
|
|
const QDateTime &lastUpdated,
|
|
|
|
const QString &dirname);
|
2021-09-23 19:23:39 +02:00
|
|
|
void feedUpdateStatusChanged(const QString &url, bool status);
|
|
|
|
void cancelFetching();
|
2021-04-20 19:17:46 +02:00
|
|
|
|
|
|
|
void updateProgressChanged(int progress);
|
|
|
|
void updateTotalChanged(int nrOfFeeds);
|
|
|
|
void updatingChanged(bool state);
|
|
|
|
|
2021-09-23 19:23:39 +02:00
|
|
|
void error(Error::Type type, const QString &url, const QString &id, const int errorId, const QString &errorString, const QString &title);
|
|
|
|
void downloadFinished(QString url) const;
|
2023-02-15 16:43:57 +01:00
|
|
|
void foundRedirectedUrl(const QUrl &url, const QUrl &newUrl);
|
2021-04-20 19:17:46 +02:00
|
|
|
|
2020-02-28 23:25:08 +01:00
|
|
|
private:
|
|
|
|
Fetcher();
|
|
|
|
|
2021-06-04 22:47:40 +02:00
|
|
|
QNetworkReply *head(QNetworkRequest &request) const;
|
|
|
|
void setHeader(QNetworkRequest &request) const;
|
|
|
|
|
2021-10-06 16:07:05 +02:00
|
|
|
QSet<QString> m_ongoingImageDownloads;
|
|
|
|
|
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;
|
2024-04-16 16:08:37 +02:00
|
|
|
|
|
|
|
const qint64 m_checkInterval = 10 * 60 * 1000; // trigger timer every 10 minutes
|
|
|
|
QTimer *m_updateTimer;
|
|
|
|
QDateTime m_updateTriggerTime;
|
2024-04-23 16:50:32 +02:00
|
|
|
|
|
|
|
QByteArray m_systemHttpProxy;
|
|
|
|
QByteArray m_systemHttpsProxy;
|
|
|
|
bool m_isSystemProxyDefined;
|
2021-06-23 22:29:15 +02:00
|
|
|
};
|