29#include <QtCore/QTimer>
46 kDebug(550) <<
"setting provider xml";
48 if (xmldata.tagName() !=
"provider")
51 mUploadUrl = xmldata.attribute(
"uploadurl");
52 mNoUploadUrl = xmldata.attribute(
"nouploadurl");
54 QString url = xmldata.attribute(
"downloadurl");
56 mDownloadUrls.insert(QString(),
KUrl(url));
59 url = xmldata.attribute(
"downloadurl-latest");
61 mDownloadUrls.insert(
"latest",
KUrl(url));
64 url = xmldata.attribute(
"downloadurl-score");
66 mDownloadUrls.insert(
"score",
KUrl(url));
69 url = xmldata.attribute(
"downloadurl-downloads");
71 mDownloadUrls.insert(
"downloads",
KUrl(url));
77 KUrl iconurl(xmldata.attribute(
"icon"));
78 if (!iconurl.isValid())
79 iconurl.
setPath(xmldata.attribute(
"icon"));
83 for (n = xmldata.firstChild(); !n.isNull(); n = n.nextSibling()) {
84 QDomElement e = n.toElement();
85 if (e.tagName() ==
"title") {
87 mName = e.text().trimmed();
88 kDebug() <<
"add name for provider ("<<
this <<
"): " << e.text();
93 if ((mNoUploadUrl.isValid()) && (mUploadUrl.isValid())) {
94 kWarning(550) <<
"StaticXmlProvider: both uploadurl and nouploadurl given";
98 if ((!mNoUploadUrl.isValid()) && (!mUploadUrl.isValid())) {
99 kWarning(550) <<
"StaticXmlProvider: neither uploadurl nor nouploadurl given";
103 mId = mDownloadUrls[QString()].url();
105 mId = mDownloadUrls[mDownloadUrls.keys().first()].url();
108 QTimer::singleShot(0,
this, SLOT(slotEmitProviderInitialized()));
113void StaticXmlProvider::slotEmitProviderInitialized()
126 kDebug() <<
"Set cached entries " << cachedEntries.size();
127 mCachedEntries.append(cachedEntries);
132 mCurrentRequest = request;
135 if (request.
page > 0) {
141 kDebug() <<
"Installed entries: " << mId << installedEntries().size();
147 if (!url.isEmpty()) {
151 connect(loader, SIGNAL(signalLoaded(QDomDocument)), SLOT(slotFeedFileLoaded(QDomDocument)));
152 connect(loader, SIGNAL(signalFailed()), SLOT(slotFeedFailed()));
154 mFeedLoaders.insert(request.
sortMode, loader);
162KUrl StaticXmlProvider::downloadUrl(SortMode mode)
const
168 url = mDownloadUrls.value(
"score");
171 url = mDownloadUrls.value(QString());
175 url = mDownloadUrls.value(
"latest");
178 url = mDownloadUrls.value(
"downloads");
182 url = mDownloadUrls.value(QString());
187void StaticXmlProvider::slotFeedFileLoaded(
const QDomDocument& doc)
189 XmlLoader * loader = qobject_cast<KNS3::XmlLoader*>(sender());
201 element = doc.documentElement();
203 for (n = element.firstChildElement(); !n.isNull(); n = n.nextSiblingElement()) {
205 entry.setEntryXML(n.toElement());
207 entry.setProviderId(mId);
209 int index = mCachedEntries.indexOf(entry);
212 EntryInternal cacheEntry = mCachedEntries.takeAt(index);
215 ((cacheEntry.version() != entry.version()) || (cacheEntry.releaseDate() != entry.releaseDate()))) {
217 entry.setUpdateVersion(entry.version());
218 entry.setVersion(cacheEntry.version());
219 entry.setUpdateReleaseDate(entry.releaseDate());
220 entry.setReleaseDate(cacheEntry.releaseDate());
222 entry.setStatus(cacheEntry.status());
226 mCachedEntries.append(entry);
228 if (searchIncludesEntry(entry)) {
235void StaticXmlProvider::slotFeedFailed()
252 if (entry.
name().contains(search, Qt::CaseInsensitive) ||
253 entry.
summary().contains(search, Qt::CaseInsensitive) ||
254 entry.
author().
name().contains(search, Qt::CaseInsensitive)
273 entries.append(entry);
282#include "staticxmlprovider.moc"
QString name() const
Retrieve the author's name.
KNewStuff data entry container.
QString name() const
Retrieve the name of the data object.
QString payload() const
Retrieve the file name of the object.
QList< EntryInternal > List
Author author() const
Retrieve the author of the object.
Entry::Status status() const
Retrieves the entry's status.
QString summary() const
Retrieve a short description about the object.
void payloadLinkLoaded(const KNS3::EntryInternal &)
void loadingFinished(const KNS3::Provider::SearchRequest &, const KNS3::EntryInternal::List &) const
void providerInitialized(KNS3::Provider *)
void loadingFailed(const KNS3::Provider::SearchRequest &)
virtual QString id() const
A unique Id for this provider (the url in most cases)
virtual bool isInitialized() const
virtual void loadPayloadLink(const KNS3::EntryInternal &entry, int)
StaticXmlProvider()
Constructor.
virtual void setCachedEntries(const KNS3::EntryInternal::List &cachedEntries)
virtual bool setProviderXML(const QDomElement &xmldata)
set the provider data xml, to initialize the provider
virtual void loadEntries(const KNS3::Provider::SearchRequest &request)
load the given search and return given page
void load(const KUrl &url)
Starts asynchronously loading the xml document from the specified URL.
void setPath(const QString &path)
used to keep track of a search