1 /* 2 * SPDX-FileCopyrightText: 2012 Aleix Pol Gonzalez <aleixpol@blue-systems.com> 3 * 4 * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL 5 */ 6 7 #ifndef KNSBACKEND_H 8 #define KNSBACKEND_H 9 10 #include <KNSCore/EntryInternal> 11 #include <KNSCore/ErrorCode> 12 13 #include "Transaction/AddonList.h" 14 #include "discovercommon_export.h" 15 #include <resources/AbstractResourcesBackend.h> 16 17 class KNSReviews; 18 class KNSResource; 19 class StandardBackendUpdater; 20 21 namespace KNSCore 22 { 23 class Engine; 24 } 25 26 class DISCOVERCOMMON_EXPORT KNSBackend : public AbstractResourcesBackend 27 { 28 Q_OBJECT 29 public: 30 explicit KNSBackend(QObject *parent, const QString &iconName, const QString &knsrc); 31 ~KNSBackend() override; 32 33 Transaction *removeApplication(AbstractResource *app) override; 34 Transaction *installApplication(AbstractResource *app) override; 35 Transaction *installApplication(AbstractResource *app, const AddonList &addons) override; 36 int updatesCount() const override; 37 AbstractReviewsBackend *reviewsBackend() const override; 38 AbstractBackendUpdater *backendUpdater() const override; 39 bool isFetching() const override; 40 ResultsStream *search(const AbstractResourcesBackend::Filters &filter) override; 41 ResultsStream *findResourceByPackageName(const QUrl &search); 42 category()43 QVector<Category *> category() const override 44 { 45 return m_rootCategories; 46 } hasApplications()47 bool hasApplications() const override 48 { 49 return m_hasApplications; 50 } 51 52 bool isValid() const override; 53 extends()54 QStringList extends() const override 55 { 56 return m_extends; 57 } 58 iconName()59 QString iconName() const 60 { 61 return m_iconName; 62 } 63 engine()64 KNSCore::Engine *engine() const 65 { 66 return m_engine; 67 } 68 69 void checkForUpdates() override; 70 71 QString displayName() const override; 72 73 Q_SIGNALS: 74 void receivedResources(const QVector<AbstractResource *> &resources); 75 void searchFinished(); 76 void startingSearch(); 77 void availableForQueries(); 78 void initialized(); 79 80 public Q_SLOTS: 81 void receivedEntries(const KNSCore::EntryInternal::List &entries); 82 void statusChanged(const KNSCore::EntryInternal &entry); 83 void detailsLoaded(const KNSCore::EntryInternal &entry); 84 void slotErrorCode(const KNSCore::ErrorCode &errorCode, const QString &message, const QVariant &metadata); 85 void slotEntryEvent(const KNSCore::EntryInternal &entry, KNSCore::EntryInternal::EntryEvent event); 86 87 private: 88 void fetchInstalled(); 89 KNSResource *resourceForEntry(const KNSCore::EntryInternal &entry); 90 void setFetching(bool f); 91 void markInvalid(const QString &message); 92 void searchStream(ResultsStream *stream, const QString &searchText); 93 void fetchMore(); 94 95 bool m_onePage = false; 96 bool m_responsePending = false; 97 bool m_fetching; 98 bool m_isValid; 99 KNSCore::Engine *m_engine; 100 QHash<QString, AbstractResource *> m_resourcesByName; 101 KNSReviews *const m_reviews; 102 QString m_name; 103 QString m_iconName; 104 StandardBackendUpdater *const m_updater; 105 QStringList m_extends; 106 QStringList m_categories; 107 QVector<Category *> m_rootCategories; 108 QString m_displayName; 109 bool m_initialized = false; 110 bool m_hasApplications = false; 111 }; 112 113 #endif // KNSBACKEND_H 114