21 #include <QtCore/QFile>
22 #include <QtCore/QDir>
23 #include <QtCore/QFileInfo>
24 #include <QtCore/QXmlStreamReader>
35 m_kns2ComponentName = appName;
38 kDebug() <<
"Using registry file: " << registryFile;
43 CacheHash::const_iterator it = s_caches->constFind(appName);
44 if ((it != s_caches->constEnd()) && !(*it).isNull()) {
45 return QSharedPointer<Cache>(*it);
48 QSharedPointer<Cache> p(
new Cache(appName));
49 s_caches->insert(appName, QWeakPointer<Cache>(p));
63 QFile f(registryFile);
64 if (!f.open(QIODevice::ReadOnly)) {
65 kWarning() <<
"The file " << registryFile <<
" could not be opened.";
70 if (!doc.setContent(&f)) {
71 kWarning() <<
"The file could not be parsed.";
75 QDomElement root = doc.documentElement();
76 if (root.tagName() !=
"hotnewstuffregistry") {
77 kWarning() <<
"The file doesn't seem to be of interest.";
81 QDomElement stuff = root.firstChildElement(
"stuff");
82 while (!stuff.isNull()) {
87 stuff = stuff.nextSiblingElement(
"stuff");
90 kDebug() <<
"Cache read... entries: " << cache.size();
93 void Cache::readKns2MetaFiles()
96 kDebug() <<
"Loading KNS2 registry of files for the component: " << m_kns2ComponentName;
98 QString realAppName = m_kns2ComponentName.split(
':')[0];
101 for (QStringList::ConstIterator it = dirs.begin(); it != dirs.end(); ++it) {
104 const QStringList files =
dir.entryList(QDir::Files | QDir::Readable);
105 for (QStringList::const_iterator fit = files.begin(); fit != files.end(); ++fit) {
106 QString filepath = (*it) +
'/' + (*fit);
108 kDebug() <<
" Load from file '" + filepath +
"'.";
110 QFileInfo info(filepath);
116 QString thisAppName = QString::fromUtf8(QByteArray::fromBase64(info.baseName().toUtf8()));
120 thisAppName = thisAppName.split(
':')[0];
122 if (thisAppName != realAppName) {
126 if (!f.open(QIODevice::ReadOnly)) {
127 kWarning() <<
"The file: " << filepath <<
" could not be opened.";
132 if (!doc.setContent(&f)) {
133 kWarning() <<
"The file could not be parsed.";
136 kDebug() <<
"found entry: " << doc.toString();
138 QDomElement root = doc.documentElement();
139 if (root.tagName() !=
"ghnsinstall") {
140 kWarning() <<
"The file doesn't seem to be of interest.";
145 QDomElement stuff = root.firstChildElement(
"stuff");
150 if (e.
payload().startsWith(QLatin1String(
"http://download.kde.org/khotnewstuff"))) {
152 e.
setProviderId(QLatin1String(
"https://api.opendesktop.org/v1/"));
155 }
else if (e.
payload().startsWith(QLatin1String(
"http://edu.kde.org/contrib/kvtml/"))) {
157 e.
setProviderId(
"http://edu.kde.org/contrib/kvtml/kvtml.xml");
158 }
else if (e.
payload().startsWith(QLatin1String(
"http://edu.kde.org/contrib/kvtml2/"))) {
160 e.
setProviderId(
"http://edu.kde.org/contrib/kvtml2/provider41.xml");
163 kWarning() <<
"Could not load entry: " << filepath;
170 QDomDocument tmp(
"yay");
172 kDebug() <<
"new entry: " << tmp.toString();
177 if (!dir.remove(filepath)) {
178 kWarning() <<
"could not delete old kns2 .meta file: " << filepath;
180 kDebug() <<
"Migrated KNS2 entry to KNS3.";
201 kDebug() <<
"Write registry";
203 QFile f(registryFile);
204 if (!f.open(QIODevice::WriteOnly | QIODevice::Text)) {
205 kWarning() <<
"Cannot write meta information to '" << registryFile <<
"'." << endl;
209 QDomDocument doc(
"khotnewstuff3");
210 doc.appendChild(doc.createProcessingInstruction(
"xml",
"version=\"1.0\" encoding=\"UTF-8\"" ));
211 QDomElement root = doc.createElement(
"hotnewstuffregistry");
212 doc.appendChild(root);
217 QDomElement exml = entry.
entryXML();
218 root.appendChild(exml);
222 QTextStream metastream(&f);
223 metastream << doc.toByteArray();
237 kDebug() << request.
hashForRequest() <<
" add: " << entries.size() <<
" keys: " << requestCache.keys();