File indexing completed on 2025-04-20 12:26:24
0001 /* 0002 SPDX-FileCopyrightText: 2009-2010 Frederik Gladhorn <gladhorn@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.1-or-later 0005 */ 0006 0007 #ifndef KNEWSTUFF3_ATTICAPROVIDER_P_H 0008 #define KNEWSTUFF3_ATTICAPROVIDER_P_H 0009 0010 #include <QPointer> 0011 #include <QSet> 0012 0013 #include <attica/content.h> 0014 #include <attica/provider.h> 0015 #include <attica/providermanager.h> 0016 0017 #include "provider.h" 0018 0019 namespace Attica 0020 { 0021 class BaseJob; 0022 } 0023 0024 namespace KNSCore 0025 { 0026 /** 0027 * @short KNewStuff Attica Provider class. 0028 * 0029 * This class provides accessors for the provider object. 0030 * It should not be used directly by the application. 0031 * This class is the base class and will be instantiated for 0032 * websites that implement the Open Collaboration Services. 0033 * 0034 * @author Frederik Gladhorn <gladhorn@kde.org> 0035 * 0036 * @internal 0037 */ 0038 class AtticaProvider : public Provider 0039 { 0040 Q_OBJECT 0041 public: 0042 explicit AtticaProvider(const QStringList &categories, const QString &additionalAgentInformation); 0043 AtticaProvider(const Attica::Provider &provider, const QStringList &categories, const QString &additionalAgentInformation); 0044 0045 QString id() const override; 0046 0047 /** 0048 * set the provider data xml, to initialize the provider 0049 */ 0050 bool setProviderXML(const QDomElement &xmldata) override; 0051 0052 bool isInitialized() const override; 0053 void setCachedEntries(const KNSCore::EntryInternal::List &cachedEntries) override; 0054 0055 void loadEntries(const KNSCore::Provider::SearchRequest &request) override; 0056 void loadEntryDetails(const KNSCore::EntryInternal &entry) override; 0057 void loadPayloadLink(const EntryInternal &entry, int linkId) override; 0058 /** 0059 * The slot which causes loading of comments for the Attica provider 0060 * @see Provider::loadComments(const EntryInternal &entry, int commentsPerPage, int page) 0061 */ 0062 Q_SLOT void loadComments(const EntryInternal &entry, int commentsPerPage, int page); 0063 /** 0064 * The slot which causes loading of a person's details 0065 * @see Provider::loadPerson(const QString &username) 0066 */ 0067 Q_SLOT void loadPerson(const QString &username); 0068 /** 0069 * The slot which causes the provider's basic information to be fetched. 0070 * For the Attica provider, this translates to an OCS Config call 0071 * @see Provider::loadBasics() 0072 */ 0073 Q_SLOT void loadBasics(); 0074 0075 bool userCanVote() override 0076 { 0077 return true; 0078 } 0079 void vote(const EntryInternal &entry, uint rating) override; 0080 0081 bool userCanBecomeFan() override 0082 { 0083 return true; 0084 } 0085 void becomeFan(const EntryInternal &entry) override; 0086 0087 Attica::Provider *provider() 0088 { 0089 return &m_provider; 0090 } 0091 0092 private Q_SLOTS: 0093 void providerLoaded(const Attica::Provider &provider); 0094 void listOfCategoriesLoaded(Attica::BaseJob *); 0095 void categoryContentsLoaded(Attica::BaseJob *job); 0096 void downloadItemLoaded(Attica::BaseJob *job); 0097 void accountBalanceLoaded(Attica::BaseJob *job); 0098 void onAuthenticationCredentialsMissing(const Attica::Provider &); 0099 void votingFinished(Attica::BaseJob *); 0100 void becomeFanFinished(Attica::BaseJob *job); 0101 void detailsLoaded(Attica::BaseJob *job); 0102 void loadedComments(Attica::BaseJob *job); 0103 void loadedPerson(Attica::BaseJob *job); 0104 void loadedConfig(Attica::BaseJob *job); 0105 0106 private: 0107 void checkForUpdates(); 0108 EntryInternal::List installedEntries() const; 0109 bool jobSuccess(Attica::BaseJob *job) const; 0110 0111 Attica::Provider::SortMode atticaSortMode(const SortMode &sortMode); 0112 0113 EntryInternal entryFromAtticaContent(const Attica::Content &); 0114 0115 // the attica categories we are interested in (e.g. Wallpaper, Application, Vocabulary File...) 0116 QMultiHash<QString, Attica::Category> mCategoryMap; 0117 0118 Attica::ProviderManager m_providerManager; 0119 Attica::Provider m_provider; 0120 0121 KNSCore::EntryInternal::List mCachedEntries; 0122 QHash<QString, Attica::Content> mCachedContent; 0123 0124 // Associate job and entry, this is needed when fetching 0125 // download links or the account balance in order to continue 0126 // when the result is there. 0127 QHash<Attica::BaseJob *, QPair<EntryInternal, int>> mDownloadLinkJobs; 0128 0129 // keep track of the current request 0130 QPointer<Attica::BaseJob> mEntryJob; 0131 Provider::SearchRequest mCurrentRequest; 0132 0133 QSet<Attica::BaseJob *> m_updateJobs; 0134 0135 bool mInitialized; 0136 QString m_providerId; 0137 0138 Q_DISABLE_COPY(AtticaProvider) 0139 }; 0140 0141 } 0142 0143 #endif