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;
46 QTimer::singleShot(interval: 0, receiver: q, slot: &Provider::loadBasics);
47 }
48 };
49 void throttleBasics()
50 {
51 if (!basicsThrottle) {
52 basicsThrottle = new QTimer(q);
53 basicsThrottle->setInterval(0);
54 basicsThrottle->setSingleShot(true);
55 QObject::connect(sender: basicsThrottle, signal: &QTimer::timeout, context: q, slot: &Provider::basicsLoaded);
56 }
57 basicsThrottle->start();
58 }
59};
60
61QString Provider::SearchRequest::hashForRequest() const
62{
63 return QString::number((int)sortMode) + QLatin1Char(',') + searchTerm + QLatin1Char(',') + categories.join(sep: QLatin1Char('-')) + QLatin1Char(',')
64 + QString::number(page) + QLatin1Char(',') + QString::number(pageSize);
65}
66
67Provider::Provider()
68 : d(new ProviderPrivate(this))
69{
70}
71
72Provider::~Provider() = default;
73
74QString Provider::name() const
75{
76 return d->name;
77}
78
79QUrl Provider::icon() const
80{
81 return d->icon;
82}
83
84void Provider::setTagFilter(const QStringList &tagFilter)
85{
86 d->tagFilter = tagFilter;
87}
88
89QStringList Provider::tagFilter() const
90{
91 return d->tagFilter;
92}
93
94void Provider::setDownloadTagFilter(const QStringList &downloadTagFilter)
95{
96 d->downloadTagFilter = downloadTagFilter;
97}
98
99QStringList Provider::downloadTagFilter() const
100{
101 return d->downloadTagFilter;
102}
103
104QDebug 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
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"
200

source code of knewstuff/src/core/provider.cpp