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 #include "applicationfolder.h" 0008 0009 #include <QAbstractListModel> 0010 #include <QList> 0011 #include <QObject> 0012 #include <QQuickItem> 0013 #include <QSet> 0014 0015 #include <Plasma/Applet> 0016 0017 #include <KWayland/Client/connection_thread.h> 0018 #include <KWayland/Client/plasmawindowmanagement.h> 0019 #include <KWayland/Client/registry.h> 0020 #include <KWayland/Client/surface.h> 0021 0022 /** 0023 * @short The applications and folders model on the main page. 0024 */ 0025 class PinnedModel : public QAbstractListModel 0026 { 0027 Q_OBJECT 0028 Q_PROPERTY(Plasma::Applet *applet READ applet WRITE setApplet NOTIFY appletChanged) 0029 0030 public: 0031 enum Roles { IsFolderRole = Qt::UserRole + 1, ApplicationRole, FolderRole }; 0032 0033 PinnedModel(QObject *parent = nullptr); 0034 ~PinnedModel() override; 0035 static PinnedModel *self(); 0036 0037 int rowCount(const QModelIndex &parent = QModelIndex()) const override; 0038 QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; 0039 QHash<int, QByteArray> roleNames() const override; 0040 0041 Q_INVOKABLE void addApp(const QString &storageId, int row); 0042 Q_INVOKABLE void addFolder(QString name, int row); 0043 Q_INVOKABLE void removeEntry(int row); 0044 Q_INVOKABLE void moveEntry(int fromRow, int toRow); 0045 0046 Q_INVOKABLE void createFolderFromApps(int sourceAppRow, int draggedAppRow); 0047 Q_INVOKABLE void addAppToFolder(int appRow, int folderRow); 0048 0049 void save(); 0050 0051 Plasma::Applet *applet(); 0052 void setApplet(Plasma::Applet *applet); 0053 0054 public Q_SLOTS: 0055 void addAppFromFolder(const QString &storageId); 0056 0057 Q_SIGNALS: 0058 void appletChanged(); 0059 0060 private: 0061 void load(); 0062 0063 QList<Application *> m_applications; 0064 QList<ApplicationFolder *> m_folders; 0065 0066 Plasma::Applet *m_applet; 0067 };