KNewStuff

xmlloader.cpp
1 /*
2  knewstuff3/xmlloader.cpp.
3  SPDX-FileCopyrightText: 2002 Cornelius Schumacher <[email protected]>
4  SPDX-FileCopyrightText: 2003-2007 Josef Spillner <[email protected]>
5  SPDX-FileCopyrightText: 2009 Jeremy Whiting <[email protected]>
6  SPDX-FileCopyrightText: 2010 Frederik Gladhorn <[email protected]>
7 
8  SPDX-License-Identifier: LGPL-2.1-or-later
9 */
10 
11 #include "xmlloader.h"
12 
13 #include "knewstuffcore_debug.h"
14 #include "jobs/httpjob.h"
15 
16 #include <KConfig>
17 
18 #include <QByteArray>
19 
20 namespace KNSCore
21 {
22 
24  : QObject(parent)
25 {
26 }
27 
28 void XmlLoader::load(const QUrl &url)
29 {
30  m_jobdata.clear();
31 
32  qCDebug(KNEWSTUFFCORE) << "XmlLoader::load(): url: " << url;
33 
34  HTTPJob *job = HTTPJob::get(url, Reload, JobFlag::HideProgressInfo);
35  connect(job, &KJob::result,
36  this, &XmlLoader::slotJobResult);
37  connect(job, &HTTPJob::data,
38  this, &XmlLoader::slotJobData);
39 
40  emit jobStarted(job);
41 }
42 
43 void XmlLoader::slotJobData(KJob *, const QByteArray &data)
44 {
45  qCDebug(KNEWSTUFFCORE) << "XmlLoader::slotJobData()";
46 
47  m_jobdata.append(data);
48 }
49 
50 void XmlLoader::slotJobResult(KJob *job)
51 {
52  deleteLater();
53  if (job->error()) {
54  emit signalFailed();
55  return;
56  }
57  qCDebug(KNEWSTUFFCORE) << "--Xml Loader-START--";
58  qCDebug(KNEWSTUFFCORE) << QString::fromUtf8(m_jobdata);
59  qCDebug(KNEWSTUFFCORE) << "--Xml Loader-END--";
60  QDomDocument doc;
61  if (!doc.setContent(m_jobdata)) {
62  emit signalFailed();
63  return;
64  }
65  emit signalLoaded(doc);
66 }
67 
68 QDomElement addElement(QDomDocument &doc, QDomElement &parent,
69  const QString &tag, const QString &value)
70 {
71  QDomElement n = doc.createElement(tag);
72  n.appendChild(doc.createTextNode(value));
73  parent.appendChild(n);
74 
75  return n;
76 }
77 } // end KNS namespace
78 
void signalLoaded(const QDomDocument &)
Indicates that the list of providers has been successfully loaded.
XmlLoader(QObject *parent)
Constructor.
Definition: xmlloader.cpp:23
void clear()
QDomNode appendChild(const QDomNode &newChild)
Contains the core functionality for handling interaction with NewStuff providers. ...
QString fromUtf8(const char *str, int size)
void load(const QUrl &url)
Starts asynchronously loading the xml document from the specified URL.
Definition: xmlloader.cpp:28
void deleteLater()
QByteArray & append(char ch)
QDomText createTextNode(const QString &value)
void result(KJob *job)
QDomElement createElement(const QString &tagName)
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
QObject * parent() const const
int error() const
bool setContent(const QByteArray &data, bool namespaceProcessing, QString *errorMsg, int *errorLine, int *errorColumn)
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Tue Aug 11 2020 22:43:24 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.