File indexing completed on 2025-04-27 03:43:31
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::Entry::List &cachedEntries) override; 0054 0055 void loadEntries(const KNSCore::Provider::SearchRequest &request) override; 0056 void loadEntryDetails(const KNSCore::Entry &entry) override; 0057 void loadPayloadLink(const Entry &entry, int linkId) override; 0058 0059 void loadComments(const KNSCore::Entry &entry, int commentsPerPage, int page) override; 0060 void loadPerson(const QString &username) override; 0061 void loadBasics() override; 0062 0063 bool userCanVote() override 0064 { 0065 return true; 0066 } 0067 void vote(const Entry &entry, uint rating) override; 0068 0069 bool userCanBecomeFan() override 0070 { 0071 return true; 0072 } 0073 void becomeFan(const Entry &entry) override; 0074 0075 Attica::Provider *provider() 0076 { 0077 return &m_provider; 0078 } 0079 0080 private Q_SLOTS: 0081 void providerLoaded(const Attica::Provider &provider); 0082 void listOfCategoriesLoaded(Attica::BaseJob *); 0083 void categoryContentsLoaded(Attica::BaseJob *job); 0084 void downloadItemLoaded(Attica::BaseJob *job); 0085 void accountBalanceLoaded(Attica::BaseJob *job); 0086 void onAuthenticationCredentialsMissing(const Attica::Provider &); 0087 void votingFinished(Attica::BaseJob *); 0088 void becomeFanFinished(Attica::BaseJob *job); 0089 void detailsLoaded(Attica::BaseJob *job); 0090 void loadedComments(Attica::BaseJob *job); 0091 void loadedPerson(Attica::BaseJob *job); 0092 void loadedConfig(Attica::BaseJob *job); 0093 0094 private: 0095 void checkForUpdates(); 0096 Entry::List installedEntries() const; 0097 bool jobSuccess(Attica::BaseJob *job); 0098 0099 Attica::Provider::SortMode atticaSortMode(SortMode sortMode); 0100 0101 Entry entryFromAtticaContent(const Attica::Content &); 0102 0103 // the attica categories we are interested in (e.g. Wallpaper, Application, Vocabulary File...) 0104 QMultiHash<QString, Attica::Category> mCategoryMap; 0105 0106 Attica::ProviderManager m_providerManager; 0107 Attica::Provider m_provider; 0108 0109 KNSCore::Entry::List mCachedEntries; 0110 QHash<QString, Attica::Content> mCachedContent; 0111 0112 // Associate job and entry, this is needed when fetching 0113 // download links or the account balance in order to continue 0114 // when the result is there. 0115 QHash<Attica::BaseJob *, QPair<Entry, int>> mDownloadLinkJobs; 0116 0117 // keep track of the current request 0118 QPointer<Attica::BaseJob> mEntryJob; 0119 Provider::SearchRequest mCurrentRequest; 0120 0121 QSet<Attica::BaseJob *> m_updateJobs; 0122 0123 bool mInitialized; 0124 QString m_providerId; 0125 0126 Q_DISABLE_COPY(AtticaProvider) 0127 }; 0128 0129 } 0130 0131 #endif