| 1 | // For license of this file, see <project-root-folder>/LICENSE.md. |
| 2 | |
| 3 | #ifndef REDDITNETWORKFACTORY_H |
| 4 | #define REDDITNETWORKFACTORY_H |
| 5 | |
| 6 | #include "core/message.h" |
| 7 | #include "services/abstract/feed.h" |
| 8 | #include "services/abstract/rootitem.h" |
| 9 | #include "src/3rd-party/mimesis/mimesis.hpp" |
| 10 | |
| 11 | #include <QNetworkReply> |
| 12 | #include <QObject> |
| 13 | |
| 14 | class RootItem; |
| 15 | class RedditServiceRoot; |
| 16 | class OAuth2Service; |
| 17 | |
| 18 | struct Subreddit {}; |
| 19 | |
| 20 | class RedditNetworkFactory : public QObject { |
| 21 | Q_OBJECT |
| 22 | |
| 23 | public: |
| 24 | explicit RedditNetworkFactory(QObject* parent = nullptr); |
| 25 | |
| 26 | void setService(RedditServiceRoot* service); |
| 27 | |
| 28 | OAuth2Service* oauth() const; |
| 29 | void setOauth(OAuth2Service* oauth); |
| 30 | |
| 31 | QString username() const; |
| 32 | void setUsername(const QString& username); |
| 33 | |
| 34 | int batchSize() const; |
| 35 | void setBatchSize(int batch_size); |
| 36 | |
| 37 | bool downloadOnlyUnreadMessages() const; |
| 38 | void setDownloadOnlyUnreadMessages(bool download_only_unread_messages); |
| 39 | |
| 40 | // API methods. |
| 41 | QVariantHash me(const QNetworkProxy& custom_proxy); |
| 42 | QList<Feed*> subreddits(const QNetworkProxy& custom_proxy); |
| 43 | QList<Message> hot(const QString& sub_name, const QNetworkProxy& custom_proxy); |
| 44 | |
| 45 | private slots: |
| 46 | void onTokensError(const QString& error, const QString& error_description); |
| 47 | void onAuthFailed(); |
| 48 | |
| 49 | private: |
| 50 | void initializeOauth(); |
| 51 | |
| 52 | private: |
| 53 | RedditServiceRoot* m_service; |
| 54 | QString m_username; |
| 55 | int m_batchSize; |
| 56 | bool m_downloadOnlyUnreadMessages; |
| 57 | OAuth2Service* m_oauth2; |
| 58 | }; |
| 59 | |
| 60 | #endif // REDDITNETWORKFACTORY_H |