File indexing completed on 2024-11-17 04:55:40
0001 /* 0002 * SPDX-FileCopyrightText: 2012 Aleix Pol Gonzalez <aleixpol@blue-systems.com> 0003 * 0004 * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL 0005 */ 0006 0007 #pragma once 0008 0009 #include <KNSCore/EngineBase> 0010 #include <KNSCore/Entry> 0011 #include <KNSCore/ErrorCode> 0012 0013 #include "Transaction/AddonList.h" 0014 #include "discovercommon_export.h" 0015 #include <resources/AbstractResourcesBackend.h> 0016 0017 class KNSReviews; 0018 class KNSResource; 0019 class KNSResultsStream; 0020 class StandardBackendUpdater; 0021 0022 class DISCOVERCOMMON_EXPORT KNSBackend : public AbstractResourcesBackend 0023 { 0024 Q_OBJECT 0025 public: 0026 explicit KNSBackend(QObject *parent, const QString &iconName, const QString &knsrc); 0027 ~KNSBackend() override; 0028 0029 Transaction *removeApplication(AbstractResource *app) override; 0030 Transaction *installApplication(AbstractResource *app) override; 0031 Transaction *installApplication(AbstractResource *app, const AddonList &addons) override; 0032 int updatesCount() const override; 0033 AbstractReviewsBackend *reviewsBackend() const override; 0034 AbstractBackendUpdater *backendUpdater() const override; 0035 bool isFetching() const override; 0036 ResultsStream *search(const AbstractResourcesBackend::Filters &filter) override; 0037 ResultsStream *findResourceByPackageName(const QUrl &search); 0038 0039 QVector<Category *> category() const override 0040 { 0041 return m_rootCategories; 0042 } 0043 bool hasApplications() const override 0044 { 0045 return m_hasApplications; 0046 } 0047 0048 bool isValid() const override; 0049 0050 bool extends(const QString &id) const override 0051 { 0052 return m_extends.contains(id); 0053 } 0054 0055 QStringList extends() const 0056 { 0057 return m_extends; 0058 } 0059 0060 QString iconName() const 0061 { 0062 return m_iconName; 0063 } 0064 0065 KNSCore::EngineBase *engine() const 0066 { 0067 return m_engine; 0068 } 0069 0070 void checkForUpdates() override; 0071 0072 QString displayName() const override; 0073 KNSResource *resourceForEntry(const KNSCore::Entry &entry); 0074 0075 Q_SIGNALS: 0076 void initialized(); 0077 0078 public Q_SLOTS: 0079 void statusChanged(const KNSCore::Entry &entry); 0080 void detailsLoaded(const KNSCore::Entry &entry); 0081 void slotErrorCode(const KNSCore::ErrorCode::ErrorCode &errorCode, const QString &message, const QVariant &metadata); 0082 void slotEntryEvent(const KNSCore::Entry &entry, KNSCore::Entry::EntryEvent event); 0083 0084 private: 0085 void fetchInstalled(); 0086 void setFetching(bool f); 0087 void markInvalid(const QString &message); 0088 KNSResultsStream *searchStream(const QString &searchText); 0089 0090 bool m_fetching; 0091 bool m_isValid; 0092 KNSCore::EngineBase *m_engine; 0093 QHash<QString, AbstractResource *> m_resourcesByName; 0094 KNSReviews *const m_reviews; 0095 QString m_name; 0096 const QString m_iconName; 0097 StandardBackendUpdater *const m_updater; 0098 QStringList m_extends; 0099 QStringList m_categories; 0100 QVector<Category *> m_rootCategories; 0101 QString m_displayName; 0102 bool m_initialized = false; 0103 bool m_hasApplications = false; 0104 };