KNewStuff

provider.h
1 /*
2  knewstuff3/provider.h
3  This file is part of KNewStuff2.
4  Copyright (c) 2009 Jeremy Whiting <[email protected]>
5  Copyright (C) 2009 Frederik Gladhorn <[email protected]>
6 
7  This library is free software; you can redistribute it and/or
8  modify it under the terms of the GNU Lesser General Public
9  License as published by the Free Software Foundation; either
10  version 2.1 of the License, or (at your option) any later version.
11 
12  This library is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  Lesser General Public License for more details.
16 
17  You should have received a copy of the GNU Lesser General Public
18  License along with this library. If not, see <http://www.gnu.org/licenses/>.
19 */
20 #ifndef KNEWSTUFF3_PROVIDER_P_H
21 #define KNEWSTUFF3_PROVIDER_P_H
22 
23 #include <QList>
24 #include <QString>
25 #include <QUrl>
26 #include <QDebug>
27 
28 #include <memory>
29 
30 #include "entryinternal.h"
31 #include "errorcode.h"
32 
33 #include "knewstuffcore_export.h"
34 
35 class KJob;
36 
37 namespace KNSCore
38 {
39 struct Comment;
52 class KNEWSTUFFCORE_EXPORT Provider: public QObject
53 {
54  Q_OBJECT
55 public:
56  typedef QList<Provider *> List;
57 
58  enum SortMode {
59  Newest,
60  Alphabetical,
61  Rating,
62  Downloads,
63  };
64  Q_ENUM(SortMode)
65 
66  enum Filter {
67  None,
68  Installed,
69  Updates,
70  ExactEntryId
71  };
72  Q_ENUM(Filter)
73 
74 
77  struct SearchRequest {
78  SortMode sortMode;
79  Filter filter;
80  QString searchTerm;
81  QStringList categories;
82  int page;
83  int pageSize;
84 
85  SearchRequest(SortMode sortMode_ = Newest, Filter filter_ = None, const QString &searchTerm_ = QString(), const QStringList &categories_ = QStringList(), int page_ = -1, int pageSize_ = 20)
86  : sortMode(sortMode_), filter(filter_), searchTerm(searchTerm_), categories(categories_), page(page_), pageSize(pageSize_)
87  {}
88 
89  QString hashForRequest() const;
90  };
91 
96  QString id;
97  QString name;
98  QString displayName;
99  };
100 
104  Provider();
105 
109  virtual ~Provider();
110 
114  virtual QString id() const = 0;
115 
120  virtual bool setProviderXML(const QDomElement &xmldata) = 0;
121 
122  virtual bool isInitialized() const = 0;
123 
124  virtual void setCachedEntries(const KNSCore::EntryInternal::List &cachedEntries) = 0;
125 
131  virtual QString name() const;
132 
138  virtual QUrl icon() const; // FIXME use QIcon::fromTheme or pixmap?
139 
148  virtual void loadEntries(const KNSCore::Provider::SearchRequest &request) = 0;
149  virtual void loadEntryDetails(const KNSCore::EntryInternal &) {}
150  virtual void loadPayloadLink(const EntryInternal &entry, int linkId) = 0;
162  Q_SIGNAL void loadComments(const EntryInternal &entry, int commentsPerPage, int page);
173  Q_SIGNAL void loadPerson(const QString &username);
174 
175  virtual bool userCanVote()
176  {
177  return false;
178  }
179  virtual void vote(const EntryInternal &entry, uint rating)
180  {
181  Q_UNUSED(entry) Q_UNUSED(rating)
182  }
183 
184  virtual bool userCanBecomeFan()
185  {
186  return false;
187  }
188  virtual void becomeFan(const EntryInternal &entry)
189  {
190  Q_UNUSED(entry)
191  }
192 
199  void setTagFilter(const QStringList &tagFilter);
206  QStringList tagFilter() const;
213  void setDownloadTagFilter(const QStringList &downloadTagFilter);
220  QStringList downloadTagFilter() const;
221 
222 Q_SIGNALS:
223  void providerInitialized(KNSCore::Provider *);
224 
225  void loadingFinished(const KNSCore::Provider::SearchRequest &, const KNSCore::EntryInternal::List &) const;
226  void loadingFailed(const KNSCore::Provider::SearchRequest &);
227 
228  void entryDetailsLoaded(const KNSCore::EntryInternal &);
229  void payloadLinkLoaded(const KNSCore::EntryInternal &);
235  void commentsLoaded(const QList<std::shared_ptr<KNSCore::Comment>> comments);
241  void personLoaded(const std::shared_ptr<KNSCore::Author> author);
242 
243  void signalInformation(const QString &) const;
244  void signalError(const QString &) const;
245  void signalErrorCode(const KNSCore::ErrorCode &errorCode, const QString &message, const QVariant &metadata) const;
246 
247  void categoriesMetadataLoded(const QList<CategoryMetadata> &categories);
248 
249 protected:
250  QString mName;
251  QUrl mIcon;
252 
253 private:
254  Q_DISABLE_COPY(Provider)
255 };
256 
257 KNEWSTUFFCORE_EXPORT QDebug operator<<(QDebug, const Provider::SearchRequest &);
258 }
259 
260 #endif
Rating
Contains the core functionality for handling interaction with NewStuff providers. ...
used to keep track of a search
Definition: provider.h:77
ErrorCode
An enumeration of specific error conditions which might occur and which users of KNewStuff would want...
Definition: errorcode.h:35
Comment
KNewStuff Base Provider class.
Definition: provider.h:52
QDataStream & operator<<(QDataStream &out, const KDateTime::Spec &spec)
KNewStuff data entry container.
Definition: entryinternal.h:60
Describes a category: id/name/disaplayName.
Definition: provider.h:95
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Sun Aug 9 2020 22:43:40 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.