File indexing completed on 2024-12-01 06:46:09

0001 /*
0002     knewstuff3/provider.h
0003     This file is part of KNewStuff2.
0004     SPDX-FileCopyrightText: 2009 Jeremy Whiting <jpwhiting@kde.org>
0005     SPDX-FileCopyrightText: 2009-2010 Frederik Gladhorn <gladhorn@kde.org>
0006 
0007     SPDX-License-Identifier: LGPL-2.1-or-later
0008 */
0009 
0010 #ifndef KNEWSTUFF3_STATICXMLPROVIDER_P_H
0011 #define KNEWSTUFF3_STATICXMLPROVIDER_P_H
0012 
0013 #include "provider.h"
0014 #include <QDomDocument>
0015 #include <QMap>
0016 
0017 namespace KNSCore
0018 {
0019 class XmlLoader;
0020 
0021 /**
0022  * @short KNewStuff Base Provider class.
0023  *
0024  * This class provides accessors for the provider object.
0025  * It should not be used directly by the application.
0026  * This class is the base class and will be instantiated for
0027  * static website providers.
0028  *
0029  * @author Jeremy Whiting <jpwhiting@kde.org>
0030  *
0031  * @internal
0032  */
0033 class StaticXmlProvider : public Provider
0034 {
0035     Q_OBJECT
0036 public:
0037     typedef QList<Provider *> List;
0038     /**
0039      * Constructor.
0040      */
0041     StaticXmlProvider();
0042 
0043     QString id() const override;
0044 
0045     /**
0046      * set the provider data xml, to initialize the provider
0047      */
0048     bool setProviderXML(const QDomElement &xmldata) override;
0049 
0050     bool isInitialized() const override;
0051 
0052     void setCachedEntries(const KNSCore::Entry::List &cachedEntries) override;
0053 
0054     void loadEntries(const KNSCore::Provider::SearchRequest &request) override;
0055     void loadPayloadLink(const KNSCore::Entry &entry, int) override;
0056 
0057 private Q_SLOTS:
0058     void slotEmitProviderInitialized();
0059     void slotFeedFileLoaded(const QDomDocument &);
0060     void slotFeedFailed();
0061 
0062 private:
0063     bool searchIncludesEntry(const Entry &entry) const;
0064     QUrl downloadUrl(SortMode mode) const;
0065     Entry::List installedEntries() const;
0066 
0067     // map of download urls to their feed name
0068     QMap<QString, QUrl> mDownloadUrls;
0069     QUrl mUploadUrl;
0070     QUrl mNoUploadUrl;
0071 
0072     // cache of all entries known from this provider so far, mapped by their id
0073     Entry::List mCachedEntries;
0074     QMap<Provider::SortMode, XmlLoader *> mFeedLoaders;
0075     Provider::SearchRequest mCurrentRequest;
0076     QString mId;
0077     bool mInitialized;
0078 
0079     Q_DISABLE_COPY(StaticXmlProvider)
0080 };
0081 
0082 }
0083 
0084 #endif