shift-shell/containments/homescreen/applicationlistmodel.h

127 lines
3.3 KiB
C
Raw Normal View History

/*
2021-03-01 20:03:25 +00:00
* SPDX-FileCopyrightText: 2014 Antonis Tsiapaliokas <antonis.tsiapaliokas@kde.org>
*
2021-03-01 20:03:25 +00:00
* SPDX-License-Identifier: GPL-2.0-or-later
*/
#ifndef APPLICATIONLISTMODEL_H
#define APPLICATIONLISTMODEL_H
// Qt
#include <QObject>
#include <QAbstractListModel>
#include <QList>
#include <QSet>
2019-09-04 16:39:31 +00:00
#include "homescreen.h"
class QString;
namespace KWayland
{
namespace Client
{
class PlasmaWindowManagement;
class PlasmaWindow;
}
}
2019-09-04 16:39:31 +00:00
class ApplicationListModel;
class ApplicationListModel : public QAbstractListModel {
Q_OBJECT
Q_PROPERTY(int count READ count NOTIFY countChanged)
2019-09-04 16:39:31 +00:00
Q_PROPERTY(int favoriteCount READ favoriteCount NOTIFY favoriteCountChanged)
Q_PROPERTY(int maxFavoriteCount READ maxFavoriteCount WRITE setMaxFavoriteCount NOTIFY maxFavoriteCountChanged)
public:
2019-09-04 16:39:31 +00:00
enum LauncherLocation {
Grid = 0,
Favorites,
Desktop
2019-09-04 16:39:31 +00:00
};
Q_ENUM(LauncherLocation)
struct ApplicationData {
QString uniqueId;
QString name;
QString icon;
QString storageId;
QString entryPath;
LauncherLocation location = LauncherLocation::Grid;
bool startupNotify = true;
KWayland::Client::PlasmaWindow *window = nullptr;
};
2019-09-04 16:39:31 +00:00
enum Roles {
ApplicationNameRole = Qt::UserRole + 1,
ApplicationIconRole,
ApplicationStorageIdRole,
ApplicationEntryPathRole,
ApplicationOriginalRowRole,
ApplicationStartupNotifyRole,
ApplicationLocationRole,
ApplicationRunningRole,
ApplicationUniqueIdRole
2019-09-04 16:39:31 +00:00
};
ApplicationListModel(HomeScreen *parent = nullptr);
2018-12-31 03:13:55 +00:00
~ApplicationListModel() override;
void loadSettings();
int rowCount(const QModelIndex &parent = QModelIndex()) const Q_DECL_OVERRIDE;
void moveRow(const QModelIndex &sourceParent, int sourceRow, const QModelIndex &destinationParent, int destinationChild);
int count() const { return m_applicationList.count(); }
2019-09-04 16:39:31 +00:00
int favoriteCount() const { return m_favorites.count();}
int maxFavoriteCount() const;
void setMaxFavoriteCount(int count);
void setApplet(Plasma::Applet *applet);
Plasma::Applet *applet() const;
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const Q_DECL_OVERRIDE;
2018-12-31 03:13:55 +00:00
Qt::ItemFlags flags(const QModelIndex &index) const override;
2015-04-21 12:14:33 +00:00
QHash<int, QByteArray> roleNames() const Q_DECL_OVERRIDE;
Q_INVOKABLE void setLocation(int row, LauncherLocation location);
2020-03-20 00:08:59 +00:00
Q_INVOKABLE void moveItem(int row, int destination);
Q_INVOKABLE void runApplication(const QString &storageId);
Q_INVOKABLE virtual void loadApplications();
Q_INVOKABLE void setMinimizedDelegate(int row, QQuickItem *delegate);
Q_INVOKABLE void unsetMinimizedDelegate(int row, QQuickItem *delegate);
public Q_SLOTS:
void sycocaDbChanged(const QStringList &change);
Q_SIGNALS:
void countChanged();
2019-09-04 16:39:31 +00:00
void favoriteCountChanged();
void maxFavoriteCountChanged();
protected:
void initWayland();
QList<ApplicationData> m_applicationList;
KWayland::Client::PlasmaWindowManagement *m_windowManagement = nullptr;
Plasma::Applet *m_applet = nullptr;
2019-09-04 16:39:31 +00:00
int m_maxFavoriteCount = 0;
QStringList m_appOrder;
2019-09-04 16:39:31 +00:00
QStringList m_favorites;
QSet<QString> m_desktopItems;
QHash<QString, int> m_appPositions;
};
#endif // APPLICATIONLISTMODEL_H