KNewStuff

provider.cpp
1/*
2 knewstuff3/provider.cpp
3 SPDX-FileCopyrightText: 2002 Cornelius Schumacher <schumacher@kde.org>
4 SPDX-FileCopyrightText: 2003-2007 Josef Spillner <spillner@kde.org>
5 SPDX-FileCopyrightText: 2009 Jeremy Whiting <jpwhiting@kde.org>
6 SPDX-FileCopyrightText: 2009 Frederik Gladhorn <gladhorn@kde.org>
7
8 SPDX-License-Identifier: LGPL-2.1-or-later
9*/
10
11#include "provider.h"
12
13#include "xmlloader_p.h"
14
15#include <KLocalizedString>
16
17#include <QTimer>
18
19namespace KNSCore
20{
21class ProviderPrivate
22{
23public:
24 ProviderPrivate(Provider *qq)
25 : q(qq)
26 {
27 }
28 Provider *const q;
29 QStringList tagFilter;
30 QStringList downloadTagFilter;
31
32 QTimer *basicsThrottle{nullptr};
33 QString version;
34 QUrl website;
35 QUrl host;
36 QString contactEmail;
37 QString name;
38 QUrl icon;
39 bool supportsSsl{false};
40 bool basicsGot{false};
41
42 void updateOnFirstBasicsGet()
43 {
44 if (!basicsGot) {
45 basicsGot = true;
47 }
48 };
49 void throttleBasics()
50 {
51 if (!basicsThrottle) {
52 basicsThrottle = new QTimer(q);
53 basicsThrottle->setInterval(0);
54 basicsThrottle->setSingleShot(true);
56 }
57 basicsThrottle->start();
58 }
59};
60
61QString Provider::SearchRequest::hashForRequest() const
62{
63 return QString::number((int)sortMode) + QLatin1Char(',') + searchTerm + QLatin1Char(',') + categories.join(QLatin1Char('-')) + QLatin1Char(',')
64 + QString::number(page) + QLatin1Char(',') + QString::number(pageSize);
65}
66
68 : d(new ProviderPrivate(this))
69{
70}
71
72Provider::~Provider() = default;
73
75{
76 return d->name;
77}
78
80{
81 return d->icon;
82}
83
84void Provider::setTagFilter(const QStringList &tagFilter)
85{
86 d->tagFilter = tagFilter;
87}
88
90{
91 return d->tagFilter;
92}
93
94void Provider::setDownloadTagFilter(const QStringList &downloadTagFilter)
95{
96 d->downloadTagFilter = downloadTagFilter;
97}
98
100{
101 return d->downloadTagFilter;
102}
103
105{
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
118QString Provider::version() const
119{
120 d->updateOnFirstBasicsGet();
121 return d->version;
122}
123
124void Provider::setVersion(const QString &version)
125{
126 if (d->version != version) {
127 d->version = version;
128 d->throttleBasics();
129 }
130}
131
132QUrl Provider::website() const
133{
134 d->updateOnFirstBasicsGet();
135 return d->website;
136}
137
138void Provider::setWebsite(const QUrl &website)
139{
140 if (d->website != website) {
141 d->website = website;
142 d->throttleBasics();
143 }
144}
145
146QUrl Provider::host() const
147{
148 d->updateOnFirstBasicsGet();
149 return d->host;
150}
151
152void Provider::setHost(const QUrl &host)
153{
154 if (d->host != host) {
155 d->host = host;
156 d->throttleBasics();
157 }
158}
159
160QString Provider::contactEmail() const
161{
162 d->updateOnFirstBasicsGet();
163 return d->contactEmail;
164}
165
166void Provider::setContactEmail(const QString &contactEmail)
167{
168 if (d->contactEmail != contactEmail) {
169 d->contactEmail = contactEmail;
170 d->throttleBasics();
171 }
172}
173
174bool Provider::supportsSsl() const
175{
176 d->updateOnFirstBasicsGet();
177 return d->supportsSsl;
178}
179
180void Provider::setSupportsSsl(bool supportsSsl)
181{
182 if (d->supportsSsl != supportsSsl) {
183 d->supportsSsl = supportsSsl;
184 d->throttleBasics();
185 }
186}
187
188void Provider::setName(const QString &name)
189{
190 d->name = name;
191}
192
193void Provider::setIcon(const QUrl &icon)
194{
195 d->icon = icon;
196}
197}
198
199#include "moc_provider.cpp"
virtual void loadBasics()
Request loading of the basic information for this provider.
Definition provider.h:244
~Provider() override
Destructor.
QStringList tagFilter() const
The tag filter used for downloads by this provider.
Definition provider.cpp:89
void setVersion(const QString &version)
Definition provider.cpp:124
void basicsLoaded()
Fired when the provider's basic information has been fetched and updated.
void setTagFilter(const QStringList &tagFilter)
Set the tag filter used for entries by this provider.
Definition provider.cpp:84
virtual QString name() const
Retrieves the common name of the provider.
Definition provider.cpp:74
void setContactEmail(const QString &contactEmail)
Sets the general contact email address for this provider.
Definition provider.cpp:166
Provider()
Constructor.
Definition provider.cpp:67
void setHost(const QUrl &host)
Definition provider.cpp:152
void setWebsite(const QUrl &website)
Definition provider.cpp:138
QStringList downloadTagFilter() const
The tag filter used for downloads by this provider.
Definition provider.cpp:99
virtual QUrl icon() const
Retrieves the icon URL for this provider.
Definition provider.cpp:79
void setSupportsSsl(bool supportsSsl)
Set whether or not the provider supports SSL connections.
Definition provider.cpp:180
void setDownloadTagFilter(const QStringList &downloadTagFilter)
Set the tag filter used for download items by this provider.
Definition provider.cpp:94
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
QString number(double n, char format, int precision)
QString join(QChar separator) const const
void setInterval(int msec)
void start()
void timeout()
used to keep track of a search
Definition provider.h:70
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Tue Mar 26 2024 11:21:35 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.