File indexing completed on 2024-05-05 17:33:20
0001 /* 0002 * SPDX-FileCopyrightText: 2014 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 "DiscoverAction.h" 0010 #include "discovercommon_export.h" 0011 #include <QObject> 0012 0013 class QAbstractItemModel; 0014 class AbstractResourcesBackend; 0015 0016 class DISCOVERCOMMON_EXPORT AbstractSourcesBackend : public QObject 0017 { 0018 Q_OBJECT 0019 Q_PROPERTY(AbstractResourcesBackend *resourcesBackend READ resourcesBackend CONSTANT) 0020 Q_PROPERTY(QAbstractItemModel *sources READ sources CONSTANT) 0021 Q_PROPERTY(QString idDescription READ idDescription CONSTANT) 0022 Q_PROPERTY(QVariantList actions READ actions CONSTANT) // TODO Make it a QVector<DiscoverAction*> again when we depend on newer than Qt 5.12 0023 Q_PROPERTY(DiscoverAction *inlineAction READ inlineAction CONSTANT) // TODO Make it a QVector<DiscoverAction*> again when we depend on newer than Qt 5.12 0024 Q_PROPERTY(bool supportsAdding READ supportsAdding CONSTANT) 0025 Q_PROPERTY(bool canMoveSources READ canMoveSources CONSTANT) 0026 Q_PROPERTY(bool canFilterSources READ canFilterSources CONSTANT) 0027 Q_PROPERTY(QString firstSourceId READ firstSourceId NOTIFY firstSourceIdChanged) 0028 Q_PROPERTY(QString lastSourceId READ lastSourceId NOTIFY lastSourceIdChanged) 0029 public: 0030 explicit AbstractSourcesBackend(AbstractResourcesBackend *parent); 0031 ~AbstractSourcesBackend() override; 0032 0033 enum Roles { 0034 IdRole = Qt::UserRole, 0035 LastRole, 0036 }; 0037 Q_ENUM(Roles) 0038 0039 virtual QString idDescription() = 0; 0040 0041 Q_SCRIPTABLE virtual bool addSource(const QString &id) = 0; 0042 Q_SCRIPTABLE virtual bool removeSource(const QString &id) = 0; 0043 0044 virtual QAbstractItemModel *sources() = 0; 0045 virtual QVariantList actions() const = 0; 0046 0047 virtual bool supportsAdding() const = 0; 0048 virtual DiscoverAction *inlineAction() const 0049 { 0050 return nullptr; 0051 } 0052 0053 AbstractResourcesBackend *resourcesBackend() const; 0054 0055 virtual bool canFilterSources() const 0056 { 0057 return false; 0058 } 0059 0060 virtual bool canMoveSources() const 0061 { 0062 return false; 0063 } 0064 Q_SCRIPTABLE virtual bool moveSource(const QString &sourceId, int delta); 0065 0066 QString firstSourceId() const; 0067 QString lastSourceId() const; 0068 0069 public Q_SLOTS: 0070 virtual void cancel() 0071 { 0072 } 0073 0074 virtual void proceed() 0075 { 0076 } 0077 0078 Q_SIGNALS: 0079 void firstSourceIdChanged(); 0080 void lastSourceIdChanged(); 0081 void passiveMessage(const QString &message); 0082 void proceedRequest(const QString &title, const QString &description); 0083 };