mirror of
https://invent.kde.org/marcoa/shift-shell.git
synced 2026-08-03 02:04:45 +00:00
homescreens/halcyon: Add folder backend
This commit is contained in:
parent
ef45546127
commit
8438027d8b
6 changed files with 85 additions and 8 deletions
|
|
@ -15,6 +15,9 @@
|
||||||
#include <KWayland/Client/registry.h>
|
#include <KWayland/Client/registry.h>
|
||||||
#include <KWayland/Client/surface.h>
|
#include <KWayland/Client/surface.h>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @short Object that represents an application.
|
||||||
|
*/
|
||||||
class Application : public QObject
|
class Application : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,9 @@
|
||||||
|
|
||||||
#include <QJsonArray>
|
#include <QJsonArray>
|
||||||
|
|
||||||
ApplicationFolder::ApplicationFolder(QObject *parent)
|
ApplicationFolder::ApplicationFolder(QObject *parent, QString name)
|
||||||
|
: QObject{parent}
|
||||||
|
, m_name{name}
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -19,8 +21,7 @@ ApplicationFolder *ApplicationFolder::fromJson(QJsonObject &obj, QObject *parent
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ApplicationFolder *folder = new ApplicationFolder(parent);
|
ApplicationFolder *folder = new ApplicationFolder(parent, name);
|
||||||
folder->setName(name);
|
|
||||||
folder->setApplications(apps);
|
folder->setApplications(apps);
|
||||||
return folder;
|
return folder;
|
||||||
}
|
}
|
||||||
|
|
@ -50,6 +51,7 @@ void ApplicationFolder::setName(QString &name)
|
||||||
{
|
{
|
||||||
m_name = name;
|
m_name = name;
|
||||||
Q_EMIT nameChanged();
|
Q_EMIT nameChanged();
|
||||||
|
Q_EMIT saveRequested();
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<Application *> ApplicationFolder::applications()
|
QList<Application *> ApplicationFolder::applications()
|
||||||
|
|
@ -61,4 +63,31 @@ void ApplicationFolder::setApplications(QList<Application *> applications)
|
||||||
{
|
{
|
||||||
m_applications = applications;
|
m_applications = applications;
|
||||||
Q_EMIT applicationsChanged();
|
Q_EMIT applicationsChanged();
|
||||||
|
Q_EMIT saveRequested();
|
||||||
|
}
|
||||||
|
|
||||||
|
void ApplicationFolder::addApp(const QString &storageId, int row)
|
||||||
|
{
|
||||||
|
if (row < 0 || row > m_applications.size()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (KService::Ptr service = KService::serviceByStorageId(storageId)) {
|
||||||
|
Application *app = new Application(this, service);
|
||||||
|
m_applications.insert(row, app);
|
||||||
|
Q_EMIT applicationsChanged();
|
||||||
|
Q_EMIT saveRequested();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ApplicationFolder::removeApp(int row)
|
||||||
|
{
|
||||||
|
if (row < 0 || row >= m_applications.size()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
m_applications[row]->deleteLater();
|
||||||
|
m_applications.removeAt(row);
|
||||||
|
Q_EMIT applicationsChanged();
|
||||||
|
Q_EMIT saveRequested();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,9 @@
|
||||||
#include <KWayland/Client/registry.h>
|
#include <KWayland/Client/registry.h>
|
||||||
#include <KWayland/Client/surface.h>
|
#include <KWayland/Client/surface.h>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @short Object that represents an application folder on the main page.
|
||||||
|
*/
|
||||||
class ApplicationFolder : public QObject
|
class ApplicationFolder : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
@ -22,7 +25,7 @@ class ApplicationFolder : public QObject
|
||||||
Q_PROPERTY(QList<Application *> applications READ applications NOTIFY applicationsChanged)
|
Q_PROPERTY(QList<Application *> applications READ applications NOTIFY applicationsChanged)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ApplicationFolder(QObject *parent = nullptr);
|
ApplicationFolder(QObject *parent = nullptr, QString name = QString{});
|
||||||
|
|
||||||
static ApplicationFolder *fromJson(QJsonObject &obj, QObject *parent);
|
static ApplicationFolder *fromJson(QJsonObject &obj, QObject *parent);
|
||||||
QJsonObject toJson();
|
QJsonObject toJson();
|
||||||
|
|
@ -33,9 +36,13 @@ public:
|
||||||
QList<Application *> applications();
|
QList<Application *> applications();
|
||||||
void setApplications(QList<Application *> applications);
|
void setApplications(QList<Application *> applications);
|
||||||
|
|
||||||
|
Q_INVOKABLE void addApp(const QString &storageId, int row);
|
||||||
|
Q_INVOKABLE void removeApp(int row);
|
||||||
|
|
||||||
Q_SIGNALS:
|
Q_SIGNALS:
|
||||||
void nameChanged();
|
void nameChanged();
|
||||||
void applicationsChanged();
|
void applicationsChanged();
|
||||||
|
void saveRequested();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QString m_name;
|
QString m_name;
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,7 @@
|
||||||
#include <QSet>
|
#include <QSet>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @short The base application list, used directly by the app drawer.
|
* @short The base application list, used directly by the full app list page.
|
||||||
*/
|
*/
|
||||||
class ApplicationListModel : public QAbstractListModel
|
class ApplicationListModel : public QAbstractListModel
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -44,7 +44,7 @@ QHash<int, QByteArray> PinnedModel::roleNames() const
|
||||||
|
|
||||||
void PinnedModel::addApp(const QString &storageId, int row)
|
void PinnedModel::addApp(const QString &storageId, int row)
|
||||||
{
|
{
|
||||||
if (row < 0 && row > m_applications.size()) {
|
if (row < 0 || row > m_applications.size()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -53,7 +53,7 @@ void PinnedModel::addApp(const QString &storageId, int row)
|
||||||
|
|
||||||
beginInsertRows(QModelIndex(), row, row);
|
beginInsertRows(QModelIndex(), row, row);
|
||||||
m_applications.insert(row, app);
|
m_applications.insert(row, app);
|
||||||
m_folders.insert(0, nullptr); // maintain indicies
|
m_folders.insert(row, nullptr); // maintain indicies
|
||||||
endInsertRows();
|
endInsertRows();
|
||||||
|
|
||||||
save();
|
save();
|
||||||
|
|
@ -62,7 +62,7 @@ void PinnedModel::addApp(const QString &storageId, int row)
|
||||||
|
|
||||||
void PinnedModel::removeApp(int row)
|
void PinnedModel::removeApp(int row)
|
||||||
{
|
{
|
||||||
if (row < 0 && row >= m_applications.size()) {
|
if (row < 0 || row >= m_applications.size()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -75,6 +75,37 @@ void PinnedModel::removeApp(int row)
|
||||||
save();
|
save();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void PinnedModel::addFolder(QString name, int row)
|
||||||
|
{
|
||||||
|
if (row < 0 || row > m_applications.size()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ApplicationFolder *folder = new ApplicationFolder(this, name);
|
||||||
|
connect(folder, &ApplicationFolder::saveRequested, this, &PinnedModel::save);
|
||||||
|
|
||||||
|
beginInsertRows(QModelIndex(), row, row);
|
||||||
|
m_applications.insert(row, nullptr);
|
||||||
|
m_folders.insert(row, folder);
|
||||||
|
endInsertRows();
|
||||||
|
|
||||||
|
save();
|
||||||
|
}
|
||||||
|
|
||||||
|
void PinnedModel::removeFolder(int row)
|
||||||
|
{
|
||||||
|
if (row < 0 || row >= m_applications.size()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
beginRemoveRows(QModelIndex(), row, row);
|
||||||
|
m_applications.removeAt(row);
|
||||||
|
m_folders.removeAt(row);
|
||||||
|
endRemoveRows();
|
||||||
|
|
||||||
|
save();
|
||||||
|
}
|
||||||
|
|
||||||
void PinnedModel::load()
|
void PinnedModel::load()
|
||||||
{
|
{
|
||||||
if (!m_applet) {
|
if (!m_applet) {
|
||||||
|
|
@ -99,6 +130,8 @@ void PinnedModel::load()
|
||||||
} else if (obj[QStringLiteral("type")].toString() == "folder") {
|
} else if (obj[QStringLiteral("type")].toString() == "folder") {
|
||||||
// read folder
|
// read folder
|
||||||
ApplicationFolder *folder = ApplicationFolder::fromJson(obj, this);
|
ApplicationFolder *folder = ApplicationFolder::fromJson(obj, this);
|
||||||
|
connect(folder, &ApplicationFolder::saveRequested, this, &PinnedModel::save);
|
||||||
|
|
||||||
if (folder) {
|
if (folder) {
|
||||||
m_applications.append(nullptr);
|
m_applications.append(nullptr);
|
||||||
m_folders.append(folder);
|
m_folders.append(folder);
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,9 @@
|
||||||
#include <KWayland/Client/registry.h>
|
#include <KWayland/Client/registry.h>
|
||||||
#include <KWayland/Client/surface.h>
|
#include <KWayland/Client/surface.h>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @short The applications and folders model on the main page.
|
||||||
|
*/
|
||||||
class PinnedModel : public QAbstractListModel
|
class PinnedModel : public QAbstractListModel
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
@ -35,6 +38,8 @@ public:
|
||||||
|
|
||||||
Q_INVOKABLE void addApp(const QString &storageId, int row);
|
Q_INVOKABLE void addApp(const QString &storageId, int row);
|
||||||
Q_INVOKABLE void removeApp(int row);
|
Q_INVOKABLE void removeApp(int row);
|
||||||
|
Q_INVOKABLE void addFolder(QString name, int row);
|
||||||
|
Q_INVOKABLE void removeFolder(int row);
|
||||||
|
|
||||||
Q_INVOKABLE void load();
|
Q_INVOKABLE void load();
|
||||||
void save();
|
void save();
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue