File indexing completed on 2024-06-09 05:30:56
0001 /* 0002 SPDX-FileCopyrightText: 2015 Eike Hein <hein@kde.org> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #pragma once 0008 0009 #include "appentry.h" 0010 #include "forwardingmodel.h" 0011 0012 #include <QSortFilterProxyModel> 0013 #include <Solid/StorageAccess> 0014 0015 class SimpleFavoritesModel; 0016 0017 class QConcatenateTablesProxyModel; 0018 class KFilePlacesModel; 0019 0020 namespace Solid 0021 { 0022 class Device; 0023 } 0024 0025 class FilteredPlacesModel : public QSortFilterProxyModel 0026 { 0027 Q_OBJECT 0028 0029 public: 0030 explicit FilteredPlacesModel(QObject *parent = nullptr); 0031 ~FilteredPlacesModel() override; 0032 0033 QUrl url(const QModelIndex &index) const; 0034 bool isDevice(const QModelIndex &index) const; 0035 Solid::Device deviceForIndex(const QModelIndex &index) const; 0036 0037 protected: 0038 bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const override; 0039 bool lessThan(const QModelIndex &left, const QModelIndex &right) const override; 0040 0041 private: 0042 KFilePlacesModel *m_placesModel; 0043 }; 0044 0045 class RunCommandModel : public AbstractModel 0046 { 0047 Q_OBJECT 0048 0049 public: 0050 RunCommandModel(QObject *parent = nullptr); 0051 ~RunCommandModel() override; 0052 0053 QString description() const override; 0054 0055 QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; 0056 0057 int rowCount(const QModelIndex &parent = QModelIndex()) const override; 0058 0059 Q_INVOKABLE bool trigger(int row, const QString &actionId, const QVariant &argument) override; 0060 }; 0061 0062 class ComputerModel : public ForwardingModel 0063 { 0064 Q_OBJECT 0065 0066 Q_PROPERTY(int appNameFormat READ appNameFormat WRITE setAppNameFormat NOTIFY appNameFormatChanged) 0067 Q_PROPERTY(QObject *appletInterface READ appletInterface WRITE setAppletInterface NOTIFY appletInterfaceChanged) 0068 Q_PROPERTY(QStringList systemApplications READ systemApplications WRITE setSystemApplications NOTIFY systemApplicationsChanged) 0069 0070 public: 0071 explicit ComputerModel(QObject *parent = nullptr); 0072 ~ComputerModel() override; 0073 0074 QString description() const override; 0075 0076 int appNameFormat() const; 0077 void setAppNameFormat(int format); 0078 0079 QObject *appletInterface() const; 0080 void setAppletInterface(QObject *appletInterface); 0081 0082 QStringList systemApplications() const; 0083 void setSystemApplications(const QStringList &apps); 0084 0085 QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; 0086 0087 Q_INVOKABLE bool trigger(int row, const QString &actionId, const QVariant &argument) override; 0088 0089 Q_SIGNALS: 0090 void appNameFormatChanged() const; 0091 void appletInterfaceChanged() const; 0092 void systemApplicationsChanged() const; 0093 0094 private Q_SLOTS: 0095 void onSetupDone(Solid::ErrorType error, QVariant errorData, const QString &udi); 0096 0097 private: 0098 QConcatenateTablesProxyModel *m_concatProxy; 0099 RunCommandModel *m_runCommandModel; 0100 SimpleFavoritesModel *m_systemAppsModel; 0101 FilteredPlacesModel *m_filteredPlacesModel; 0102 AppEntry::NameFormat m_appNameFormat; 0103 QObject *m_appletInterface; 0104 };