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 "provider.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 AtticaProvider : public Provider |
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::Provider::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 | void loadBasics() override; |
62 | |
63 | bool userCanVote() override |
64 | { |
65 | return true; |
66 | } |
67 | void vote(const Entry &entry, uint rating) override; |
68 | |
69 | bool userCanBecomeFan() override |
70 | { |
71 | return true; |
72 | } |
73 | void becomeFan(const Entry &entry) override; |
74 | |
75 | Attica::Provider *provider() |
76 | { |
77 | return &m_provider; |
78 | } |
79 | |
80 | private Q_SLOTS: |
81 | void providerLoaded(const Attica::Provider &provider); |
82 | void listOfCategoriesLoaded(Attica::BaseJob *); |
83 | void categoryContentsLoaded(Attica::BaseJob *job); |
84 | void downloadItemLoaded(Attica::BaseJob *job); |
85 | void accountBalanceLoaded(Attica::BaseJob *job); |
86 | void onAuthenticationCredentialsMissing(const Attica::Provider &); |
87 | void votingFinished(Attica::BaseJob *); |
88 | void becomeFanFinished(Attica::BaseJob *job); |
89 | void detailsLoaded(Attica::BaseJob *job); |
90 | void (Attica::BaseJob *job); |
91 | void loadedPerson(Attica::BaseJob *job); |
92 | void loadedConfig(Attica::BaseJob *job); |
93 | |
94 | private: |
95 | void checkForUpdates(); |
96 | Entry::List installedEntries() const; |
97 | bool jobSuccess(Attica::BaseJob *job); |
98 | |
99 | Attica::Provider::SortMode atticaSortMode(SortMode sortMode); |
100 | |
101 | Entry entryFromAtticaContent(const Attica::Content &); |
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 | // keep track of the current request |
118 | QPointer<Attica::BaseJob> mEntryJob; |
119 | Provider::SearchRequest mCurrentRequest; |
120 | |
121 | QSet<Attica::BaseJob *> m_updateJobs; |
122 | |
123 | bool mInitialized; |
124 | QString m_providerId; |
125 | |
126 | Q_DISABLE_COPY(AtticaProvider) |
127 | }; |
128 | |
129 | } |
130 | |
131 | #endif |
132 | |