File indexing completed on 2024-04-28 03:56:27

0001 /*
0002     knewstuff3/xmlloader.h.
0003     SPDX-FileCopyrightText: 2002 Cornelius Schumacher <schumacher@kde.org>
0004     SPDX-FileCopyrightText: 2003-2007 Josef Spillner <spillner@kde.org>
0005     SPDX-FileCopyrightText: 2009 Jeremy Whiting <jpwhiting@kde.org>
0006     SPDX-FileCopyrightText: 2010 Frederik Gladhorn <gladhorn@kde.org>
0007 
0008     SPDX-License-Identifier: LGPL-2.1-or-later
0009 */
0010 
0011 #ifndef KNEWSTUFF3_XMLLOADER_P_H
0012 #define KNEWSTUFF3_XMLLOADER_P_H
0013 
0014 #include "provider.h"
0015 #include <QNetworkReply>
0016 #include <QObject>
0017 #include <QString>
0018 #include <QUrl>
0019 #include <qdom.h>
0020 
0021 class KJob;
0022 
0023 namespace KNSCore
0024 {
0025 QDomElement addElement(QDomDocument &doc, QDomElement &parent, const QString &tag, const QString &value);
0026 
0027 /**
0028  * KNewStuff xml loader.
0029  * This class loads an xml document from a kurl and returns the
0030  * resulting domdocument once completed.
0031  * It should probably not be used directly by the application.
0032  *
0033  * @internal
0034  */
0035 class XmlLoader : public QObject
0036 {
0037     Q_OBJECT
0038 public:
0039     /**
0040      * Constructor.
0041      */
0042     explicit XmlLoader(QObject *parent);
0043 
0044     /**
0045      * Starts asynchronously loading the xml document from the
0046      * specified URL.
0047      *
0048      * @param url location of the XML file
0049      */
0050     void load(const QUrl &url);
0051 
0052     void setFilter(Provider::Filter filter)
0053     {
0054         m_filter = filter;
0055     }
0056 
0057     void setSearchTerm(const QString &searchTerm)
0058     {
0059         m_searchTerm = searchTerm;
0060     }
0061 
0062     Provider::Filter filter() const
0063     {
0064         return m_filter;
0065     }
0066 
0067     QString searchTerm() const
0068     {
0069         return m_searchTerm;
0070     }
0071 Q_SIGNALS:
0072     /**
0073      * Indicates that the list of providers has been successfully loaded.
0074      */
0075     void signalLoaded(const QDomDocument &);
0076     void signalFailed();
0077     /**
0078      * Fired in case there is a http error reported
0079      * In some instances this is useful information for our users, and we want to make sure we report this centrally
0080      * @param status The HTTP status code (fired in cases where it is perceived by QNetworkReply as an error)
0081      * @param rawHeaders The raw HTTP headers for the errored-out network request
0082      */
0083     void signalHttpError(int status, QList<QNetworkReply::RawHeaderPair> rawHeaders);
0084 
0085     void jobStarted(KJob *);
0086 
0087 protected Q_SLOTS:
0088     void slotJobData(KJob *, const QByteArray &);
0089     void slotJobResult(KJob *);
0090 
0091 private:
0092     QByteArray m_jobdata;
0093     Provider::Filter m_filter;
0094     QString m_searchTerm;
0095 };
0096 
0097 }
0098 
0099 #endif