File indexing completed on 2024-11-17 04:55:39
0001 /* 0002 * SPDX-FileCopyrightText: 2014 Aleix Pol Gonzalez <aleixpol@blue-systems.com> 0003 * SPDX-FileCopyrightText: 2017 Jan Grulich <jgrulich@redhat.com> 0004 * 0005 * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL 0006 */ 0007 0008 #pragma once 0009 0010 #include <QStack> 0011 #include <QStandardItemModel> 0012 #include <functional> 0013 #include <resources/AbstractSourcesBackend.h> 0014 0015 #include "flatpak-helper.h" 0016 0017 class DiscoverAction; 0018 class FlatpakResource; 0019 class FlatpakSourcesBackend : public AbstractSourcesBackend 0020 { 0021 Q_OBJECT 0022 public: 0023 explicit FlatpakSourcesBackend(const QVector<FlatpakInstallation *> &installations, AbstractResourcesBackend *parent); 0024 ~FlatpakSourcesBackend() override; 0025 0026 enum Roles { 0027 IconUrlRole = LastRole + 1, 0028 PrioRole, 0029 }; 0030 0031 QAbstractItemModel *sources() override; 0032 bool addSource(const QString &id) override; 0033 bool removeSource(const QString &id) override; 0034 QString idDescription() override; 0035 QVariantList actions() const override; 0036 bool supportsAdding() const override 0037 { 0038 return true; 0039 } 0040 bool canFilterSources() const override 0041 { 0042 return true; 0043 } 0044 0045 FlatpakRemote *installSource(FlatpakResource *resource); 0046 bool canMoveSources() const override 0047 { 0048 return true; 0049 } 0050 0051 bool moveSource(const QString &sourceId, int delta) override; 0052 int originIndex(const QString &sourceId) const; 0053 QStandardItem *sourceByUrl(const QString &url) const; 0054 QStandardItem *sourceById(const QString &sourceId) const; 0055 DiscoverAction *inlineAction() const override 0056 { 0057 return m_saveAction; 0058 } 0059 0060 void cancel() override; 0061 void proceed() override; 0062 0063 void save(); 0064 void addRemote(FlatpakRemote *remote, FlatpakInstallation *installation); 0065 0066 private: 0067 FlatpakInstallation *m_preferredInstallation; 0068 QStandardItemModel *m_sources; 0069 DiscoverAction *const m_flathubAction; 0070 DiscoverAction *const m_saveAction; 0071 QStandardItem *m_noSourcesItem; 0072 QStack<std::function<void()>> m_proceedFunctions; 0073 };