KNewStuff

provider.cpp
1 /*
2  knewstuff3/provider.cpp
3  Copyright (c) 2002 Cornelius Schumacher <[email protected]>
4  Copyright (c) 2003 - 2007 Josef Spillner <[email protected]>
5  Copyright (c) 2009 Jeremy Whiting <[email protected]>
6  Copyright (C) 2009 Frederik Gladhorn <[email protected]>
7 
8  This library is free software; you can redistribute it and/or
9  modify it under the terms of the GNU Lesser General Public
10  License as published by the Free Software Foundation; either
11  version 2.1 of the License, or (at your option) any later version.
12 
13  This library is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  Lesser General Public License for more details.
17 
18  You should have received a copy of the GNU Lesser General Public
19  License along with this library. If not, see <http://www.gnu.org/licenses/>.
20 */
21 
22 #include "provider.h"
23 
24 #include "xmlloader.h"
25 
26 #include <KLocalizedString>
27 
28 namespace KNSCore
29 {
30 
31 // BCI: Add a real d-pointer
32 class ProviderPrivate {
33 public:
34  QStringList tagFilter;
35  QStringList downloadTagFilter;
36 };
37 typedef QHash<const Provider *, ProviderPrivate *> ProviderPrivateHash;
38 Q_GLOBAL_STATIC(ProviderPrivateHash, d_func)
39 
40 static ProviderPrivate *d(const Provider *provider)
41 {
42  ProviderPrivate *ret = d_func()->value(provider);
43  if (!ret) {
44  ret = new ProviderPrivate;
45  d_func()->insert(provider, ret);
46  }
47  return ret;
48 }
49 
50 static void delete_d(const Provider *provider)
51 {
52  if (auto d = d_func()) {
53  delete d->take(provider);
54  }
55 }
56 
57 QString Provider::SearchRequest::hashForRequest() const
58 {
59  return QString(QString::number((int)sortMode) + QLatin1Char(',')
60  + searchTerm + QLatin1Char(',')
61  + categories.join(QLatin1Char('-')) + QLatin1Char(',')
62  + QString::number(page) + QLatin1Char(',')
63  + QString::number(pageSize));
64 }
65 
67 {}
68 
70 {
71  delete_d(this);
72 }
73 
75 {
76  return mName;
77 }
78 
80 {
81  return mIcon;
82 }
83 
84 void Provider::setTagFilter(const QStringList &tagFilter)
85 {
86  d(this)->tagFilter = tagFilter;
87 }
88 
90 {
91  return d(this)->tagFilter;
92 }
93 
94 void Provider::setDownloadTagFilter(const QStringList &downloadTagFilter)
95 {
96  d(this)->downloadTagFilter = downloadTagFilter;
97 }
98 
100 {
101  return d(this)->downloadTagFilter;
102 }
103 
104 QDebug operator<<(QDebug dbg, const Provider::SearchRequest & search)
105 {
106  QDebugStateSaver saver(dbg);
107  dbg.nospace();
108  dbg << "Provider::SearchRequest(";
109  dbg << "searchTerm: " << search.searchTerm << ',';
110  dbg << "categories: " << search.categories << ',';
111  dbg << "filter: " << search.filter << ',';
112  dbg << "page: " << search.page << ',';
113  dbg << "pageSize: " << search.pageSize;
114  dbg << ')';
115  return dbg;
116 }
117 
118 }
119 
Provider()
Constructor.
Definition: provider.cpp:66
QStringList tagFilter() const
The tag filter used for downloads by this provider.
Definition: provider.cpp:89
void setTagFilter(const QStringList &tagFilter)
Set the tag filter used for entries by this provider.
Definition: provider.cpp:84
Contains the core functionality for handling interaction with NewStuff providers. ...
QDebug & nospace()
void setDownloadTagFilter(const QStringList &downloadTagFilter)
Set the tag filter used for download items by this provider.
Definition: provider.cpp:94
used to keep track of a search
Definition: provider.h:77
virtual ~Provider()
Destructor.
Definition: provider.cpp:69
QString number(int n, int base)
QDataStream & operator<<(QDataStream &out, const KDateTime::Spec &spec)
virtual QString name() const
Retrieves the common name of the provider.
Definition: provider.cpp:74
virtual QUrl icon() const
Retrieves the icon URL for this provider.
Definition: provider.cpp:79
QStringList downloadTagFilter() const
The tag filter used for downloads by this provider.
Definition: provider.cpp:99
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.