File indexing completed on 2024-12-29 05:06:05
0001 // SPDX-FileCopyrightText: 2022 Devin Lin <devin@kde.org> 0002 // SPDX-License-Identifier: GPL-2.0-or-later 0003 0004 #pragma once 0005 0006 #include "application.h" 0007 0008 #include <QAbstractListModel> 0009 #include <QObject> 0010 #include <QString> 0011 0012 #include <KService> 0013 0014 #include <KWayland/Client/connection_thread.h> 0015 #include <KWayland/Client/plasmawindowmanagement.h> 0016 #include <KWayland/Client/registry.h> 0017 #include <KWayland/Client/surface.h> 0018 0019 /** 0020 * @short Object that represents an application folder on the main page. 0021 */ 0022 0023 class ApplicationFolderModel; 0024 class ApplicationFolder : public QObject 0025 { 0026 Q_OBJECT 0027 Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged) 0028 Q_PROPERTY(QList<Application *> appPreviews READ appPreviews NOTIFY applicationsChanged) 0029 Q_PROPERTY(ApplicationFolderModel *applications READ applications NOTIFY applicationsReset) 0030 0031 public: 0032 ApplicationFolder(QObject *parent = nullptr, QString name = QString{}); 0033 0034 static ApplicationFolder *fromJson(QJsonObject &obj, QObject *parent); 0035 QJsonObject toJson(); 0036 0037 QString name() const; 0038 void setName(QString &name); 0039 0040 QList<Application *> appPreviews(); 0041 0042 ApplicationFolderModel *applications(); 0043 void setApplications(QList<Application *> applications); 0044 0045 Q_INVOKABLE void moveEntry(int fromRow, int toRow); 0046 Q_INVOKABLE void addApp(const QString &storageId, int row); 0047 Q_INVOKABLE void removeApp(int row); 0048 Q_INVOKABLE void moveAppOut(int row); // moves app to main page 0049 0050 Q_SIGNALS: 0051 void nameChanged(); 0052 void saveRequested(); 0053 void moveAppOutRequested(const QString &storageId); 0054 void applicationsChanged(); 0055 void applicationsReset(); 0056 0057 private: 0058 QString m_name; 0059 QList<Application *> m_applications; 0060 ApplicationFolderModel *m_applicationFolderModel; 0061 0062 friend class ApplicationFolderModel; 0063 }; 0064 0065 class ApplicationFolderModel : public QAbstractListModel 0066 { 0067 Q_OBJECT 0068 0069 public: 0070 enum Roles { ApplicationRole = Qt::UserRole + 1 }; 0071 ApplicationFolderModel(ApplicationFolder *folder); 0072 0073 int rowCount(const QModelIndex &parent = QModelIndex()) const override; 0074 QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; 0075 QHash<int, QByteArray> roleNames() const override; 0076 0077 void moveEntry(int fromRow, int toRow); 0078 void addApp(const QString &storageId, int row); 0079 void removeApp(int row); 0080 0081 private: 0082 ApplicationFolder *m_folder; 0083 0084 friend class ApplicationFolder; 0085 };