| 1 | /* |
| 2 | SPDX-FileCopyrightText: 2009-2010 Frederik Gladhorn <gladhorn@kde.org> |
| 3 | |
| 4 | SPDX-License-Identifier: LGPL-2.1-or-later |
| 5 | */ |
| 6 | |
| 7 | #ifndef KNEWSTUFF3_ATTICAPROVIDER_P_H |
| 8 | #define KNEWSTUFF3_ATTICAPROVIDER_P_H |
| 9 | |
| 10 | #include <QPointer> |
| 11 | #include <QSet> |
| 12 | |
| 13 | #include <attica/content.h> |
| 14 | #include <attica/provider.h> |
| 15 | #include <attica/providermanager.h> |
| 16 | |
| 17 | #include "providerbase_p.h" |
| 18 | |
| 19 | namespace Attica |
| 20 | { |
| 21 | class BaseJob; |
| 22 | } |
| 23 | |
| 24 | namespace KNSCore |
| 25 | { |
| 26 | /** |
| 27 | * @short KNewStuff Attica Provider class. |
| 28 | * |
| 29 | * This class provides accessors for the provider object. |
| 30 | * It should not be used directly by the application. |
| 31 | * This class is the base class and will be instantiated for |
| 32 | * websites that implement the Open Collaboration Services. |
| 33 | * |
| 34 | * @author Frederik Gladhorn <gladhorn@kde.org> |
| 35 | * |
| 36 | * @internal |
| 37 | */ |
| 38 | class /* for autotest: */ KNEWSTUFFCORE_EXPORT AtticaProvider : public ProviderBase |
| 39 | { |
| 40 | Q_OBJECT |
| 41 | public: |
| 42 | explicit AtticaProvider(const QStringList &categories, const QString &additionalAgentInformation); |
| 43 | AtticaProvider(const Attica::Provider &provider, const QStringList &categories, const QString &additionalAgentInformation); |
| 44 | |
| 45 | QString id() const override; |
| 46 | |
| 47 | /** |
| 48 | * set the provider data xml, to initialize the provider |
| 49 | */ |
| 50 | bool setProviderXML(const QDomElement &xmldata) override; |
| 51 | |
| 52 | bool isInitialized() const override; |
| 53 | void setCachedEntries(const KNSCore::Entry::List &cachedEntries) override; |
| 54 | |
| 55 | void loadEntries(const KNSCore::SearchRequest &request) override; |
| 56 | void loadEntryDetails(const KNSCore::Entry &entry) override; |
| 57 | void loadPayloadLink(const Entry &entry, int linkId) override; |
| 58 | |
| 59 | void (const KNSCore::Entry &entry, int , int page) override; |
| 60 | void loadPerson(const QString &username) override; |
| 61 | |
| 62 | bool userCanVote() override |
| 63 | { |
| 64 | return true; |
| 65 | } |
| 66 | void vote(const Entry &entry, uint rating) override; |
| 67 | |
| 68 | bool userCanBecomeFan() override |
| 69 | { |
| 70 | return true; |
| 71 | } |
| 72 | void becomeFan(const Entry &entry) override; |
| 73 | |
| 74 | Attica::Provider *provider() |
| 75 | { |
| 76 | return &m_provider; |
| 77 | } |
| 78 | |
| 79 | [[nodiscard]] QString name() const override; |
| 80 | [[nodiscard]] QUrl icon() const override; |
| 81 | [[nodiscard]] QString version() override; |
| 82 | [[nodiscard]] QUrl website() override; |
| 83 | [[nodiscard]] QUrl host() override; |
| 84 | [[nodiscard]] QString contactEmail() override; |
| 85 | [[nodiscard]] bool supportsSsl() override; |
| 86 | |
| 87 | private Q_SLOTS: |
| 88 | void providerLoaded(const Attica::Provider &provider); |
| 89 | void listOfCategoriesLoaded(Attica::BaseJob *); |
| 90 | void downloadItemLoaded(Attica::BaseJob *job); |
| 91 | void accountBalanceLoaded(Attica::BaseJob *job); |
| 92 | void onAuthenticationCredentialsMissing(const Attica::Provider &); |
| 93 | void votingFinished(Attica::BaseJob *); |
| 94 | void becomeFanFinished(Attica::BaseJob *job); |
| 95 | void (Attica::BaseJob *job); |
| 96 | void loadedPerson(Attica::BaseJob *job); |
| 97 | void loadedConfig(Attica::BaseJob *job); |
| 98 | |
| 99 | private: |
| 100 | bool jobSuccess(Attica::BaseJob *job); |
| 101 | void updateOnFirstBasicsGet(); |
| 102 | |
| 103 | // the attica categories we are interested in (e.g. Wallpaper, Application, Vocabulary File...) |
| 104 | QMultiHash<QString, Attica::Category> mCategoryMap; |
| 105 | |
| 106 | Attica::ProviderManager m_providerManager; |
| 107 | Attica::Provider m_provider; |
| 108 | |
| 109 | KNSCore::Entry::List mCachedEntries; |
| 110 | QHash<QString, Attica::Content> mCachedContent; |
| 111 | |
| 112 | // Associate job and entry, this is needed when fetching |
| 113 | // download links or the account balance in order to continue |
| 114 | // when the result is there. |
| 115 | QHash<Attica::BaseJob *, QPair<Entry, int>> mDownloadLinkJobs; |
| 116 | |
| 117 | bool mInitialized; |
| 118 | QString m_providerId; |
| 119 | bool m_basicsGot = false; |
| 120 | QString m_name; |
| 121 | QUrl m_icon; |
| 122 | QString m_version; |
| 123 | QUrl m_website; |
| 124 | QUrl m_host; |
| 125 | QString m_contactEmail; |
| 126 | bool m_supportsSsl = true; |
| 127 | |
| 128 | Q_DISABLE_COPY(AtticaProvider) |
| 129 | friend class AtticaRequester; |
| 130 | }; |
| 131 | |
| 132 | } |
| 133 | |
| 134 | #endif |
| 135 | |