File indexing completed on 2024-05-19 05:57:22

0001 // SPDX-FileCopyrightText: 2022 Plata Hill <plata.hill@kdemail.net>
0002 // SPDX-License-Identifier: LGPL-2.1-or-later
0003 
0004 #pragma once
0005 
0006 #include "fetcherimpl.h"
0007 #include "types.h"
0008 
0009 #include <QObject>
0010 
0011 #include <memory>
0012 
0013 class QNetworkAccessManager;
0014 class QNetworkReply;
0015 class QNetworkRequest;
0016 class QString;
0017 
0018 class Fetcher : public QObject
0019 {
0020     Q_OBJECT
0021 public:
0022     static Fetcher &instance()
0023     {
0024         static Fetcher _instance;
0025         return _instance;
0026     }
0027     Q_INVOKABLE void fetchFavorites();
0028     Q_INVOKABLE void fetchGroups();
0029     Q_INVOKABLE void fetchGroup(const QString &url, const QString &groupId);
0030     Q_INVOKABLE void fetchProgramDescription(const QString &channelId, const QString &programId, const QString &url);
0031     Q_INVOKABLE QString image(const QString &url);
0032     void setImpl(std::unique_ptr<FetcherImpl> fetcherImpl);
0033 
0034 private:
0035     Fetcher();
0036 
0037     void fetchGroup(const QString &url, const GroupId &groupId);
0038     void fetchProgramDescription(const ChannelId &channelId, const ProgramId &programId, const QString &url);
0039 
0040     void removeImage(const QString &url);
0041 
0042     std::unique_ptr<FetcherImpl> m_fetcherImpl;
0043 
0044 Q_SIGNALS:
0045     void startedFetchingGroup(const GroupId &id);
0046     void groupUpdated(const GroupId &id);
0047 
0048     void startedFetchingChannel(const ChannelId &id);
0049     void channelUpdated(const ChannelId &id);
0050 
0051     void errorFetchingGroup(const GroupId &id, const Error &error);
0052     void errorFetchingChannel(const ChannelId &id, const Error &error);
0053 
0054     void imageDownloadFinished(const QString &url);
0055     void errorDownloadingImage(const QString &url, const Error &error);
0056 };