11#include "staticxmlprovider_p.h"
13#include "xmlloader_p.h"
15#include "searchrequest_p.h"
17#include <knewstuffcore_debug.h>
18#include <tagsfilterchecker.h>
22StaticXmlProvider::StaticXmlProvider()
27QString StaticXmlProvider::id()
const
32bool StaticXmlProvider::setProviderXML(
const QDomElement &xmldata)
38 mUploadUrl =
QUrl(xmldata.
attribute(QStringLiteral(
"uploadurl")));
39 mNoUploadUrl =
QUrl(xmldata.
attribute(QStringLiteral(
"nouploadurl")));
46 url = xmldata.
attribute(QStringLiteral(
"downloadurl-latest"));
48 mDownloadUrls.insert(QStringLiteral(
"latest"),
QUrl(url));
51 url = xmldata.
attribute(QStringLiteral(
"downloadurl-score"));
53 mDownloadUrls.insert(QStringLiteral(
"score"),
QUrl(url));
56 url = xmldata.
attribute(QStringLiteral(
"downloadurl-downloads"));
58 mDownloadUrls.insert(QStringLiteral(
"downloads"),
QUrl(url));
62 m_iconUrl = [&xmldata] {
64 if (!iconurl.isValid()) {
77 bool useThisTitle{
false};
84 if (systemLanguage == locale.language()) {
90 qCDebug(KNEWSTUFFCORE) <<
"add name for provider (" <<
this <<
"): " << e.
text();
97 if (
name().isEmpty()) {
103 if ((mNoUploadUrl.isValid()) && (mUploadUrl.isValid())) {
104 qWarning() <<
"StaticXmlProvider: both uploadurl and nouploadurl given";
108 if ((!mNoUploadUrl.isValid()) && (!mUploadUrl.isValid())) {
109 qWarning() <<
"StaticXmlProvider: neither uploadurl nor nouploadurl given";
113 mId = mDownloadUrls[
QString()].url();
115 mId = mDownloadUrls[mDownloadUrls.begin().key()].url();
120 Q_EMIT providerInitialized(
this);
121 Q_EMIT basicsLoaded();
127bool StaticXmlProvider::isInitialized()
const
134 qCDebug(KNEWSTUFFCORE) <<
"Set cached entries " << cachedEntries.
size();
135 mCachedEntries.append(cachedEntries);
141 if (request.d->page > 0) {
142 Q_EMIT loadingDone(request);
146 if (request.d->filter == Filter::Installed) {
147 qCDebug(KNEWSTUFFCORE) <<
"Installed entries: " << mId << installedEntries().size();
148 if (request.d->page == 0) {
149 Q_EMIT entriesLoaded(request, installedEntries());
150 Q_EMIT loadingDone(request);
152 Q_EMIT loadingDone(request);
157 QUrl url = downloadUrl(request.d->sortMode);
161 XmlLoader *loader =
new XmlLoader(
this);
163 slotFeedFileLoaded(request, doc);
164 Q_EMIT loadingDone(request);
166 connect(loader, &XmlLoader::signalFailed,
this, [
this, request] {
167 Q_EMIT loadingFailed(request);
169 loader->setFilter(request.d->filter);
170 loader->setSearchTerm(request.d->searchTerm);
174 Q_EMIT loadingFailed(request);
178QUrl StaticXmlProvider::downloadUrl(SortMode mode)
const
182 case SortMode::Rating:
183 url = mDownloadUrls.value(QStringLiteral(
"score"));
185 case SortMode::Alphabetical:
186 url = mDownloadUrls.value(
QString());
188 case SortMode::Newest:
189 url = mDownloadUrls.value(QStringLiteral(
"latest"));
191 case SortMode::Downloads:
192 url = mDownloadUrls.value(QStringLiteral(
"downloads"));
196 url = mDownloadUrls.value(
QString());
203 XmlLoader *loader = qobject_cast<KNSCore::XmlLoader *>(sender());
205 qWarning() <<
"Loader not found!";
206 Q_EMIT loadingFailed(request);
214 TagsFilterChecker checker(tagFilter());
215 TagsFilterChecker downloadschecker(downloadTagFilter());
221 entry.setStatus(KNSCore::Entry::Downloadable);
222 entry.setProviderId(mId);
224 int index = mCachedEntries.indexOf(entry);
226 Entry cacheEntry = mCachedEntries.takeAt(index);
228 if ((cacheEntry.status() == KNSCore::Entry::Installed)
229 && ((cacheEntry.version() != entry.version()) || (cacheEntry.releaseDate() != entry.releaseDate()))) {
230 entry.setStatus(KNSCore::Entry::Updateable);
231 entry.setUpdateVersion(entry.version());
232 entry.setVersion(cacheEntry.version());
233 entry.setUpdateReleaseDate(entry.releaseDate());
234 entry.setReleaseDate(cacheEntry.releaseDate());
236 entry.setStatus(cacheEntry.status());
241 if (checker.filterAccepts(entry.tags())) {
242 bool filterAcceptsDownloads =
true;
243 if (entry.downloadCount() > 0) {
244 const auto downloadInfoList = entry.downloadLinkInformationList();
245 for (
const KNSCore::Entry::DownloadLinkInformation &dli : downloadInfoList) {
246 if (downloadschecker.filterAccepts(dli.tags)) {
247 filterAcceptsDownloads =
true;
252 if (filterAcceptsDownloads) {
253 mCachedEntries.append(entry);
255 if (searchIncludesEntry(request, entry)) {
256 switch (loader->filter()) {
257 case Filter::Installed:
260 case Filter::Updates:
261 if (entry.status() == KNSCore::Entry::Updateable) {
265 case Filter::ExactEntryId:
266 if (entry.uniqueId() == loader->searchTerm()) {
276 qCDebug(KNEWSTUFFCORE) <<
"Filter has excluded" << entry.name() <<
"on download filter" << downloadTagFilter();
279 qCDebug(KNEWSTUFFCORE) <<
"Filter has excluded" << entry.name() <<
"on entry filter" << tagFilter();
282 Q_EMIT entriesLoaded(request, entries);
287 if (request.d->filter == Filter::Updates) {
288 if (entry.status() != KNSCore::Entry::Updateable) {
293 if (request.d->searchTerm.isEmpty()) {
296 QString search = request.d->searchTerm;
304void StaticXmlProvider::loadPayloadLink(
const KNSCore::Entry &entry,
int)
306 qCDebug(KNEWSTUFFCORE) <<
"Payload: " << entry.
payload();
307 Q_EMIT payloadLinkLoaded(entry);
310Entry::List StaticXmlProvider::installedEntries()
const
313 for (
const Entry &entry : std::as_const(mCachedEntries)) {
314 if (entry.status() == KNSCore::Entry::Installed || entry.status() == KNSCore::Entry::Updateable) {
315 entries.append(entry);
321QString StaticXmlProvider::name()
const
326QUrl StaticXmlProvider::icon()
const
331QString StaticXmlProvider::version()
336QUrl StaticXmlProvider::website()
338 return mUploadUrl.
isValid() ? mUploadUrl : mNoUploadUrl;
341QUrl StaticXmlProvider::host()
346QString StaticXmlProvider::contactEmail()
351bool StaticXmlProvider::supportsSsl()
358#include "moc_staticxmlprovider_p.cpp"
KNewStuff data entry container.
QString payload() const
Retrieve the file name of the object.
QString name(StandardAction id)
QDomElement documentElement() const const
QString attribute(const QString &name, const QString &defValue) const const
QString tagName() const const
QString text() const const
QDomNode firstChild() const const
QDomElement firstChildElement(const QString &tagName, const QString &namespaceURI) const const
bool isNull() const const
QDomNode nextSibling() const const
QDomElement nextSiblingElement(const QString &tagName, const QString &namespaceURI) const const
QDomElement toElement() const const
qsizetype size() const const
Language language() const const
bool contains(QChar ch, Qt::CaseSensitivity cs) const const
bool isEmpty() const const
QString trimmed() const const
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)
QUrl fromLocalFile(const QString &localFile)
bool isEmpty() const const
bool isValid() const const