11 #include "staticxmlprovider_p.h" 13 #include "xmlloader.h" 15 #include <knewstuffcore_debug.h> 17 #include <tagsfilterchecker.h> 23 StaticXmlProvider::StaticXmlProvider()
28 QString StaticXmlProvider::id()
const 33 bool StaticXmlProvider::setProviderXML(
const QDomElement &xmldata)
39 mUploadUrl =
QUrl(xmldata.
attribute(QStringLiteral(
"uploadurl")));
40 mNoUploadUrl =
QUrl(xmldata.
attribute(QStringLiteral(
"nouploadurl")));
47 url = xmldata.
attribute(QStringLiteral(
"downloadurl-latest"));
49 mDownloadUrls.
insert(QStringLiteral(
"latest"),
QUrl(url));
52 url = xmldata.
attribute(QStringLiteral(
"downloadurl-score"));
54 mDownloadUrls.
insert(QStringLiteral(
"score"),
QUrl(url));
57 url = xmldata.
attribute(QStringLiteral(
"downloadurl-downloads"));
59 mDownloadUrls.
insert(QStringLiteral(
"downloads"),
QUrl(url));
64 if (!iconurl.isValid()) {
75 qCDebug(KNEWSTUFFCORE) <<
"add name for provider ("<<
this <<
"): " << e.
text();
80 if ((mNoUploadUrl.
isValid()) && (mUploadUrl.isValid())) {
81 qWarning() <<
"StaticXmlProvider: both uploadurl and nouploadurl given";
85 if ((!mNoUploadUrl.
isValid()) && (!mUploadUrl.isValid())) {
86 qWarning() <<
"StaticXmlProvider: neither uploadurl nor nouploadurl given";
90 mId = mDownloadUrls[
QString()].url();
92 mId = mDownloadUrls[mDownloadUrls.begin().key()].url();
100 void StaticXmlProvider::slotEmitProviderInitialized()
103 Q_EMIT providerInitialized(
this);
106 bool StaticXmlProvider::isInitialized()
const 113 qCDebug(KNEWSTUFFCORE) <<
"Set cached entries " << cachedEntries.
size();
114 mCachedEntries.append(cachedEntries);
119 mCurrentRequest = request;
122 if (request.page > 0) {
123 Q_EMIT loadingFinished(request, EntryInternal::List());
127 if (request.filter == Installed) {
128 qCDebug(KNEWSTUFFCORE) <<
"Installed entries: " << mId << installedEntries().size();
129 Q_EMIT loadingFinished(request, installedEntries());
133 QUrl url = downloadUrl(request.sortMode);
137 XmlLoader *loader =
new XmlLoader(
this);
139 connect(loader, &XmlLoader::signalFailed,
this, &StaticXmlProvider::slotFeedFailed);
140 loader->setProperty(
"filter", request.filter);
141 loader->setProperty(
"searchTerm", request.searchTerm);
143 mFeedLoaders.insert(request.sortMode, loader);
147 Q_EMIT loadingFailed(request);
151 QUrl StaticXmlProvider::downloadUrl(SortMode mode)
const 156 url = mDownloadUrls.value(QStringLiteral(
"score"));
159 url = mDownloadUrls.value(
QString());
162 url = mDownloadUrls.value(QStringLiteral(
"latest"));
165 url = mDownloadUrls.value(QStringLiteral(
"downloads"));
169 url = mDownloadUrls.value(
QString());
174 void StaticXmlProvider::slotFeedFileLoaded(
const QDomDocument &doc)
178 qWarning() <<
"Loader not found!";
179 Q_EMIT loadingFailed(mCurrentRequest);
184 EntryInternal::List entries;
186 const Provider::Filter
filter = loader->property(
"filter").value<Provider::Filter>();
187 const QString searchTerm = loader->property(
"searchTerm").toString();
189 TagsFilterChecker checker(tagFilter());
190 TagsFilterChecker downloadschecker(downloadTagFilter());
196 entry.setStatus(KNS3::Entry::Downloadable);
197 entry.setProviderId(mId);
199 int index = mCachedEntries.indexOf(entry);
202 EntryInternal cacheEntry = mCachedEntries.takeAt(index);
204 if ((cacheEntry.status() == KNS3::Entry::Installed) &&
205 ((cacheEntry.version() != entry.version()) || (cacheEntry.releaseDate() != entry.releaseDate()))) {
206 entry.setStatus(KNS3::Entry::Updateable);
207 entry.setUpdateVersion(entry.version());
208 entry.setVersion(cacheEntry.version());
209 entry.setUpdateReleaseDate(entry.releaseDate());
210 entry.setReleaseDate(cacheEntry.releaseDate());
212 entry.setStatus(cacheEntry.status());
217 if (checker.filterAccepts(entry.tags())) {
218 bool filterAcceptsDownloads =
true;
219 if (entry.downloadCount() > 0) {
220 const auto downloadInfoList = entry.downloadLinkInformationList();
221 for (
const KNSCore::EntryInternal::DownloadLinkInformation &dli : downloadInfoList) {
222 if (downloadschecker.filterAccepts(dli.tags)) {
223 filterAcceptsDownloads =
true;
228 if (filterAcceptsDownloads) {
229 mCachedEntries.append(entry);
231 if (searchIncludesEntry(entry)) {
237 if (entry.status() == KNS3::Entry::Updateable) {
242 if (entry.uniqueId() == searchTerm) {
252 qCDebug(KNEWSTUFFCORE) <<
"Filter has excluded" << entry.name() <<
"on download filter" << downloadTagFilter();
255 qCDebug(KNEWSTUFFCORE) <<
"Filter has excluded" << entry.name() <<
"on entry filter" << tagFilter();
258 Q_EMIT loadingFinished(mCurrentRequest, entries);
261 void StaticXmlProvider::slotFeedFailed()
263 Q_EMIT loadingFailed(mCurrentRequest);
268 if (mCurrentRequest.filter == Updates) {
269 if (entry.
status() != KNS3::Entry::Updateable) {
274 if (mCurrentRequest.searchTerm.isEmpty()) {
277 QString search = mCurrentRequest.searchTerm;
289 qCDebug(KNEWSTUFFCORE) <<
"Payload: " << entry.
payload();
290 Q_EMIT payloadLinkLoaded(entry);
293 EntryInternal::List StaticXmlProvider::installedEntries()
const 295 EntryInternal::List entries;
296 for (
const EntryInternal &entry : qAsConst(mCachedEntries)) {
297 if (entry.
status() == KNS3::Entry::Installed || entry.
status() == KNS3::Entry::Updateable) {
298 entries.append(entry);
void signalLoaded(const QDomDocument &)
Indicates that the list of providers has been successfully loaded.
QString summary() const
Retrieve a (potentially very long) description of the object.
Author author() const
Retrieve the author of the object.
QString attribute(const QString &name, const QString &defValue) const const
QObject * sender() const const
Contains the core functionality for handling interaction with NewStuff providers. ...
QDomElement nextSiblingElement(const QString &tagName) const const
QDomElement documentElement() const const
used to keep track of a search
bool isEmpty() const const
QDomNode nextSibling() const const
QDomElement toElement() const const
QString payload() const
Retrieve the file name of the object.
QString & insert(int position, QChar ch)
QString text() const const
QString trimmed() const const
QFuture< void > filter(Sequence &sequence, KeepFunctor filterFunction)
bool contains(QChar ch, Qt::CaseSensitivity cs) const const
bool isNull() const const
bool isValid() const const
QDomNode firstChild() const const
KNewStuff data entry container.
QDomElement firstChildElement(const QString &tagName) const const
QString tagName() const const
KNS3::Entry::Status status() const
Retrieves the entry's status.
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
QString name() const
Retrieve the name of the data object.
T qobject_cast(QObject *object)
QUrl fromLocalFile(const QString &localFile)
QString name() const
Retrieve the author's name.