File indexing completed on 2024-04-28 15:29:03

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