KNewStuff

provider.h
1 /*
2  knewstuff3/provider.h
3  This file is part of KNewStuff2.
4  SPDX-FileCopyrightText: 2009 Jeremy Whiting <[email protected]>
5  SPDX-FileCopyrightText: 2009 Frederik Gladhorn <[email protected]>
6 
7  SPDX-License-Identifier: LGPL-2.1-or-later
8 */
9 
10 #ifndef KNEWSTUFF3_PROVIDER_P_H
11 #define KNEWSTUFF3_PROVIDER_P_H
12 
13 #include <QList>
14 #include <QString>
15 #include <QUrl>
16 #include <QDebug>
17 
18 #include <memory>
19 
20 #include "entryinternal.h"
21 #include "errorcode.h"
22 
23 #include "knewstuffcore_export.h"
24 
25 class KJob;
26 
27 namespace KNSCore
28 {
29 struct Comment;
42 class KNEWSTUFFCORE_EXPORT Provider: public QObject
43 {
44  Q_OBJECT
45 public:
46  typedef QList<Provider *> List;
47 
48  enum SortMode {
49  Newest,
50  Alphabetical,
51  Rating,
52  Downloads,
53  };
54  Q_ENUM(SortMode)
55 
56  enum Filter {
57  None,
58  Installed,
59  Updates,
60  ExactEntryId,
61  };
62  Q_ENUM(Filter)
63 
64 
67  struct SearchRequest {
68  SortMode sortMode;
69  Filter filter;
70  QString searchTerm;
71  QStringList categories;
72  int page;
73  int pageSize;
74 
75  SearchRequest(SortMode sortMode_ = Newest, Filter filter_ = None, const QString &searchTerm_ = QString(), const QStringList &categories_ = QStringList(), int page_ = -1, int pageSize_ = 20)
76  : sortMode(sortMode_), filter(filter_), searchTerm(searchTerm_), categories(categories_), page(page_), pageSize(pageSize_)
77  {}
78 
79  QString hashForRequest() const;
80  };
81 
86  QString id;
87  QString name;
88  QString displayName;
89  };
90 
94  Provider();
95 
99  virtual ~Provider();
100 
104  virtual QString id() const = 0;
105 
110  virtual bool setProviderXML(const QDomElement &xmldata) = 0;
111 
112  virtual bool isInitialized() const = 0;
113 
114  virtual void setCachedEntries(const KNSCore::EntryInternal::List &cachedEntries) = 0;
115 
121  virtual QString name() const;
122 
128  virtual QUrl icon() const; // FIXME use QIcon::fromTheme or pixmap?
129 
138  virtual void loadEntries(const KNSCore::Provider::SearchRequest &request) = 0;
139  virtual void loadEntryDetails(const KNSCore::EntryInternal &) {}
140  virtual void loadPayloadLink(const EntryInternal &entry, int linkId) = 0;
152  Q_SIGNAL void loadComments(const EntryInternal &entry, int commentsPerPage, int page);
163  Q_SIGNAL void loadPerson(const QString &username);
164 
165  virtual bool userCanVote()
166  {
167  return false;
168  }
169  virtual void vote(const EntryInternal &entry, uint rating)
170  {
171  Q_UNUSED(entry) Q_UNUSED(rating)
172  }
173 
174  virtual bool userCanBecomeFan()
175  {
176  return false;
177  }
178  virtual void becomeFan(const EntryInternal &entry)
179  {
180  Q_UNUSED(entry)
181  }
182 
189  void setTagFilter(const QStringList &tagFilter);
196  QStringList tagFilter() const;
203  void setDownloadTagFilter(const QStringList &downloadTagFilter);
210  QStringList downloadTagFilter() const;
211 
212 Q_SIGNALS:
213  void providerInitialized(KNSCore::Provider *);
214 
215  void loadingFinished(const KNSCore::Provider::SearchRequest &, const KNSCore::EntryInternal::List &) const;
216  void loadingFailed(const KNSCore::Provider::SearchRequest &);
217 
218  void entryDetailsLoaded(const KNSCore::EntryInternal &);
219  void payloadLinkLoaded(const KNSCore::EntryInternal &);
225  void commentsLoaded(const QList<std::shared_ptr<KNSCore::Comment>> comments);
231  void personLoaded(const std::shared_ptr<KNSCore::Author> author);
232 
233  void signalInformation(const QString &) const;
234  void signalError(const QString &) const;
235  void signalErrorCode(const KNSCore::ErrorCode &errorCode, const QString &message, const QVariant &metadata) const;
236 
237  void categoriesMetadataLoded(const QList<CategoryMetadata> &categories);
238 
239 protected:
240  QString mName;
241  QUrl mIcon;
242 
243 private:
244  Q_DISABLE_COPY(Provider)
245 };
246 
247 KNEWSTUFFCORE_EXPORT QDebug operator<<(QDebug, const Provider::SearchRequest &);
248 }
249 
250 #endif
Rating
Contains the core functionality for handling interaction with NewStuff providers. ...
used to keep track of a search
Definition: provider.h:67
ErrorCode
An enumeration of specific error conditions which might occur and which users of KNewStuff would want...
Definition: errorcode.h:25
Comment
KNewStuff Base Provider class.
Definition: provider.h:42
QDataStream & operator<<(QDataStream &out, const KDateTime::Spec &spec)
KNewStuff data entry container.
Definition: entryinternal.h:49
Describes a category: id/name/disaplayName.
Definition: provider.h:85
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Mon Jan 18 2021 22:43:50 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.