2014-10-28 12:27:54 +00:00
|
|
|
/*
|
2021-03-01 20:03:25 +00:00
|
|
|
* SPDX-FileCopyrightText: 2014 Antonis Tsiapaliokas <antonis.tsiapaliokas@kde.org>
|
2014-10-28 12:27:54 +00:00
|
|
|
*
|
2021-03-01 20:03:25 +00:00
|
|
|
* SPDX-License-Identifier: GPL-2.0-or-later
|
2014-10-28 12:27:54 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#ifndef APPLICATIONLISTMODEL_H
|
|
|
|
|
#define APPLICATIONLISTMODEL_H
|
|
|
|
|
|
|
|
|
|
// Qt
|
2021-03-18 14:07:33 +00:00
|
|
|
#include <QObject>
|
2019-09-18 11:55:07 +00:00
|
|
|
#include <QAbstractListModel>
|
2014-10-28 12:27:54 +00:00
|
|
|
#include <QList>
|
2019-12-06 21:04:33 +00:00
|
|
|
#include <QSet>
|
2014-10-28 12:27:54 +00:00
|
|
|
|
2021-03-18 14:07:33 +00:00
|
|
|
#include "homescreenutils.h"
|
2019-09-04 16:39:31 +00:00
|
|
|
|
2014-10-28 12:27:54 +00:00
|
|
|
class QString;
|
|
|
|
|
|
2020-07-28 11:24:13 +00:00
|
|
|
namespace KWayland
|
|
|
|
|
{
|
|
|
|
|
namespace Client
|
|
|
|
|
{
|
|
|
|
|
class PlasmaWindowManagement;
|
|
|
|
|
class PlasmaWindow;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-18 14:07:33 +00:00
|
|
|
namespace PlasmaQuick
|
|
|
|
|
{
|
|
|
|
|
class AppletQuickItem;
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-04 16:39:31 +00:00
|
|
|
class ApplicationListModel;
|
|
|
|
|
|
2021-03-18 14:07:33 +00:00
|
|
|
class ApplicationListModel : public QAbstractListModel {
|
2014-10-28 12:27:54 +00:00
|
|
|
Q_OBJECT
|
|
|
|
|
|
2021-03-18 14:07:33 +00:00
|
|
|
Q_PROPERTY(PlasmaQuick::AppletQuickItem *applet READ applet WRITE setApplet NOTIFY appletChanged)
|
|
|
|
|
|
2014-10-28 12:27:54 +00:00
|
|
|
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)
|
2014-10-28 12:27:54 +00:00
|
|
|
|
|
|
|
|
public:
|
2019-09-04 16:39:31 +00:00
|
|
|
enum LauncherLocation {
|
2020-03-21 01:59:49 +00:00
|
|
|
Grid = 0,
|
|
|
|
|
Favorites,
|
2021-03-18 14:07:33 +00:00
|
|
|
Desktop
|
2019-09-04 16:39:31 +00:00
|
|
|
};
|
|
|
|
|
Q_ENUM(LauncherLocation)
|
|
|
|
|
|
2020-03-21 11:48:45 +00:00
|
|
|
struct ApplicationData {
|
2021-02-15 10:44:48 +00:00
|
|
|
QString uniqueId;
|
2020-03-21 11:48:45 +00:00
|
|
|
QString name;
|
|
|
|
|
QString icon;
|
|
|
|
|
QString storageId;
|
|
|
|
|
QString entryPath;
|
|
|
|
|
LauncherLocation location = LauncherLocation::Grid;
|
|
|
|
|
bool startupNotify = true;
|
2020-07-28 11:24:13 +00:00
|
|
|
KWayland::Client::PlasmaWindow *window = nullptr;
|
2020-03-21 11:48:45 +00:00
|
|
|
};
|
|
|
|
|
|
2019-09-04 16:39:31 +00:00
|
|
|
enum Roles {
|
2019-09-18 11:55:07 +00:00
|
|
|
ApplicationNameRole = Qt::UserRole + 1,
|
|
|
|
|
ApplicationIconRole,
|
|
|
|
|
ApplicationStorageIdRole,
|
|
|
|
|
ApplicationEntryPathRole,
|
|
|
|
|
ApplicationOriginalRowRole,
|
|
|
|
|
ApplicationStartupNotifyRole,
|
2020-07-28 11:24:13 +00:00
|
|
|
ApplicationLocationRole,
|
2021-02-15 10:44:48 +00:00
|
|
|
ApplicationRunningRole,
|
2021-03-18 14:07:33 +00:00
|
|
|
ApplicationUniqueIdRole
|
2019-09-04 16:39:31 +00:00
|
|
|
};
|
|
|
|
|
|
2021-03-18 14:07:33 +00:00
|
|
|
ApplicationListModel(QObject *parent = nullptr);
|
2018-12-31 03:13:55 +00:00
|
|
|
~ApplicationListModel() override;
|
2014-10-28 12:27:54 +00:00
|
|
|
|
2019-09-16 17:13:52 +00:00
|
|
|
void loadSettings();
|
|
|
|
|
|
2019-09-18 11:55:07 +00:00
|
|
|
int rowCount(const QModelIndex &parent = QModelIndex()) const Q_DECL_OVERRIDE;
|
|
|
|
|
|
|
|
|
|
void moveRow(const QModelIndex &sourceParent, int sourceRow, const QModelIndex &destinationParent, int destinationChild);
|
|
|
|
|
|
2021-03-18 14:07:33 +00:00
|
|
|
int count() const { return m_applicationList.count(); }
|
|
|
|
|
int favoriteCount() const { return m_favorites.count();}
|
2019-09-04 16:39:31 +00:00
|
|
|
|
|
|
|
|
int maxFavoriteCount() const;
|
|
|
|
|
void setMaxFavoriteCount(int count);
|
2014-10-28 12:27:54 +00:00
|
|
|
|
2021-03-18 14:07:33 +00:00
|
|
|
void setApplet(PlasmaQuick::AppletQuickItem *applet);
|
|
|
|
|
PlasmaQuick::AppletQuickItem *applet() const;
|
2021-02-15 10:44:48 +00:00
|
|
|
|
2014-10-28 12:27:54 +00:00
|
|
|
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
|
|
|
|
2014-10-28 12:27:54 +00:00
|
|
|
QHash<int, QByteArray> roleNames() const Q_DECL_OVERRIDE;
|
|
|
|
|
|
2020-03-21 01:59:49 +00:00
|
|
|
Q_INVOKABLE void setLocation(int row, LauncherLocation location);
|
2015-03-18 13:34:05 +00:00
|
|
|
|
2020-03-20 00:08:59 +00:00
|
|
|
Q_INVOKABLE void moveItem(int row, int destination);
|
2015-03-05 12:37:39 +00:00
|
|
|
|
2014-10-28 12:27:54 +00:00
|
|
|
Q_INVOKABLE void runApplication(const QString &storageId);
|
|
|
|
|
|
2021-02-15 10:44:48 +00:00
|
|
|
Q_INVOKABLE virtual void loadApplications();
|
2019-09-18 11:55:07 +00:00
|
|
|
|
2020-07-30 15:20:07 +00:00
|
|
|
Q_INVOKABLE void setMinimizedDelegate(int row, QQuickItem *delegate);
|
2020-07-31 09:11:26 +00:00
|
|
|
Q_INVOKABLE void unsetMinimizedDelegate(int row, QQuickItem *delegate);
|
2020-07-30 15:20:07 +00:00
|
|
|
|
2015-03-18 13:57:54 +00:00
|
|
|
public Q_SLOTS:
|
2021-03-18 14:07:33 +00:00
|
|
|
void sycocaDbChanged(const QStringList &change);
|
2015-03-18 13:57:54 +00:00
|
|
|
|
2014-10-28 12:27:54 +00:00
|
|
|
Q_SIGNALS:
|
|
|
|
|
void countChanged();
|
2019-09-04 16:39:31 +00:00
|
|
|
void favoriteCountChanged();
|
|
|
|
|
void maxFavoriteCountChanged();
|
2021-03-18 14:07:33 +00:00
|
|
|
void appletChanged();
|
2021-09-13 12:22:47 +00:00
|
|
|
void launchError(const QString &msg);
|
2014-10-28 12:27:54 +00:00
|
|
|
|
2021-02-15 10:44:48 +00:00
|
|
|
protected:
|
2020-07-28 11:24:13 +00:00
|
|
|
void initWayland();
|
|
|
|
|
|
2019-09-18 11:55:07 +00:00
|
|
|
QList<ApplicationData> m_applicationList;
|
|
|
|
|
|
2020-07-28 11:24:13 +00:00
|
|
|
KWayland::Client::PlasmaWindowManagement *m_windowManagement = nullptr;
|
2021-03-18 14:07:33 +00:00
|
|
|
PlasmaQuick::AppletQuickItem *m_applet = nullptr;
|
2019-09-04 16:39:31 +00:00
|
|
|
int m_maxFavoriteCount = 0;
|
2015-03-18 13:34:05 +00:00
|
|
|
QStringList m_appOrder;
|
2019-09-04 16:39:31 +00:00
|
|
|
QStringList m_favorites;
|
|
|
|
|
QSet<QString> m_desktopItems;
|
2015-03-18 13:34:05 +00:00
|
|
|
QHash<QString, int> m_appPositions;
|
2014-10-28 12:27:54 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#endif // APPLICATIONLISTMODEL_H
|