Commit 2e6c1f83 authored by Devin Lin's avatar Devin Lin 🎨
Browse files

homescreen: Collapse library into mobileshell and containment

parent 6047c703
Pipeline #160154 passed with stages
in 1 minute and 6 seconds
......@@ -3,5 +3,4 @@
# SPDX-License-Identifier: GPL-2.0-or-later
add_subdirectory(mmplugin)
add_subdirectory(mobilehomescreencomponents)
add_subdirectory(mobileshell)
# SPDX-FileCopyrightText: 2021 Devin Lin <devin@kde.org>
# SPDX-FileCopyrightText: 2021 Marco Martin <mart@kde.org>
# SPDX-FileCopyrightText: 2021 Aleix Pol <apol@kde.org>
# SPDX-License-Identifier: GPL-2.0-or-later
set(mobilehomescreencomponentsplugin_SRCS
mobilehomescreencomponentsplugin.cpp
applicationlistmodel.cpp
favoritesmodel.cpp
homescreenutils.cpp
)
add_library(mobilehomescreencomponentsplugin ${mobilehomescreencomponentsplugin_SRCS})
target_link_libraries(mobilehomescreencomponentsplugin
PUBLIC
Qt::Core
PRIVATE
Qt::Qml
Qt::Quick
KF5::KIOGui
KF5::Plasma
KF5::Notifications
KF5::PlasmaQuick
KF5::WaylandClient
)
install(TARGETS mobilehomescreencomponentsplugin DESTINATION ${KDE_INSTALL_QMLDIR}/org/kde/plasma/private/mobilehomescreencomponents)
install(DIRECTORY qml/ DESTINATION ${KDE_INSTALL_QMLDIR}/org/kde/plasma/private/mobilehomescreencomponents)
/*
* SPDX-FileCopyrightText: 2019 by Marco Martin <mart@kde.org>
*
* SPDX-License-Identifier: GPL-2.0-or-later
*/
#include "mobilehomescreencomponentsplugin.h"
#include <QQmlContext>
#include <QQuickItem>
#include "applicationlistmodel.h"
#include "favoritesmodel.h"
#include "homescreenutils.h"
void MobileHomeScreenComponentsPlugin::registerTypes(const char *uri)
{
Q_ASSERT(QLatin1String(uri) == QLatin1String("org.kde.plasma.private.mobilehomescreencomponents"));
qmlRegisterSingletonType<HomeScreenUtils>(uri, 0, 1, "HomeScreenUtils",
[](QQmlEngine *, QJSEngine *) {
return new HomeScreenUtils{};
});
qmlRegisterSingletonType<ApplicationListModel>(uri, 0, 1, "ApplicationListModel",
[](QQmlEngine *, QJSEngine *) {
return new ApplicationListModel{};
});
qmlRegisterSingletonType<FavoritesModel>(uri, 0, 1, "FavoritesModel",
[](QQmlEngine *, QJSEngine *) {
return new FavoritesModel{};
});
// qmlProtectModule(uri, 1);
}
//#include "moc_mobilehomescreencomponentplugin.cpp"
/*
* SPDX-FileCopyrightText: 2019 by Marco Martin <mart@kde.org>
*
* SPDX-License-Identifier: GPL-2.0-or-later
*/
#pragma once
#include <QUrl>
#include <QQmlEngine>
#include <QQmlExtensionPlugin>
class MobileHomeScreenComponentsPlugin : public QQmlExtensionPlugin
{
Q_OBJECT
Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QQmlExtensionInterface")
public:
void registerTypes(const char *uri) override;
};
# SPDX-FileCopyrightText: 2021 Devin Lin <devin@kde.org>
# SPDX-FileCopyrightText: 2021 Marco Martin <mart@kde.org>
# SPDX-License-Identifier: GPL-2.0-or-later
module org.kde.plasma.private.mobilehomescreencomponents
plugin mobilehomescreencomponentsplugin
AbstractAppDrawer 0.1 appdrawer/AbstractAppDrawer.qml
AppDrawerHeader 0.1 appdrawer/AppDrawerHeader.qml
AppDrawerLoader 0.1 appdrawer/AppDrawerLoader.qml
DrawerGridDelegate 0.1 appdrawer/DrawerGridDelegate.qml
DrawerListDelegate 0.1 appdrawer/DrawerListDelegate.qml
GridViewAppDrawer 0.1 appdrawer/GridViewAppDrawer.qml
ListViewAppDrawer 0.1 appdrawer/ListViewAppDrawer.qml
FavoriteStrip 0.1 FavoriteStrip.qml
FlickContainer 0.1 FlickContainer.qml
HomeDelegate 0.1 HomeDelegate.qml
HomeScreen 0.1 HomeScreen.qml
HomeScreenContents 0.1 HomeScreenContents.qml
HomeScreenPages 0.1 HomeScreenPages.qml
HomeScreenState 0.1 HomeScreenState.qml
LauncherContainer 0.1 LauncherContainer.qml
LauncherDragManager 0.1 LauncherDragManager.qml
LauncherGrid 0.1 LauncherGrid.qml
LauncherRepeater 0.1 LauncherRepeater.qml
MobileAppletContainer 0.1 MobileAppletContainer.qml
......@@ -14,6 +14,9 @@ set(mobileshellplugin_SRCS
shellutil.cpp
notifications/notificationthumbnailer.cpp
notifications/notificationfilemenu.cpp
homescreen/applicationlistmodel.cpp
homescreen/favoritesmodel.cpp
homescreen/homescreenutils.cpp
taskswitcher/displaysmodel.cpp
)
......
/*
* SPDX-FileCopyrightText: 2014 Antonis Tsiapaliokas <antonis.tsiapaliokas@kde.org>
* SPDX-FileCopyrightText: 2022 Devin Lin <devin@kde.org>
*
* SPDX-License-Identifier: GPL-2.0-or-later
*/
......@@ -9,9 +10,9 @@
// Qt
#include <QByteArray>
#include <QDebug>
#include <QModelIndex>
#include <QProcess>
#include <QDebug>
#include <QQuickItem>
#include <QQuickWindow>
......@@ -35,10 +36,9 @@ constexpr int MAX_FAVOURITES = 5;
ApplicationListModel::ApplicationListModel(QObject *parent)
: QAbstractListModel(parent)
//m_applet(parent)
// m_applet(parent)
{
connect(KSycoca::self(), qOverload<const QStringList &>(&KSycoca::databaseChanged),
this, &ApplicationListModel::sycocaDbChanged);
connect(KSycoca::self(), qOverload<const QStringList &>(&KSycoca::databaseChanged), this, &ApplicationListModel::sycocaDbChanged);
loadSettings();
initWayland();
......@@ -67,22 +67,20 @@ void ApplicationListModel::loadSettings()
++i;
}
//loadApplications();
// loadApplications();
}
QHash<int, QByteArray> ApplicationListModel::roleNames() const
{
return {
{ApplicationNameRole, QByteArrayLiteral("applicationName")},
{ApplicationIconRole, QByteArrayLiteral("applicationIcon")},
{ApplicationStorageIdRole, QByteArrayLiteral("applicationStorageId")},
{ApplicationEntryPathRole, QByteArrayLiteral("applicationEntryPath")},
{ApplicationOriginalRowRole, QByteArrayLiteral("applicationOriginalRow")},
{ApplicationStartupNotifyRole, QByteArrayLiteral("applicationStartupNotify")},
{ApplicationLocationRole, QByteArrayLiteral("applicationLocation")},
{ApplicationRunningRole, QByteArrayLiteral("applicationRunning")},
{ApplicationUniqueIdRole, QByteArrayLiteral("applicationUniqueId")}
};
return {{ApplicationNameRole, QByteArrayLiteral("applicationName")},
{ApplicationIconRole, QByteArrayLiteral("applicationIcon")},
{ApplicationStorageIdRole, QByteArrayLiteral("applicationStorageId")},
{ApplicationEntryPathRole, QByteArrayLiteral("applicationEntryPath")},
{ApplicationOriginalRowRole, QByteArrayLiteral("applicationOriginalRow")},
{ApplicationStartupNotifyRole, QByteArrayLiteral("applicationStartupNotify")},
{ApplicationLocationRole, QByteArrayLiteral("applicationLocation")},
{ApplicationRunningRole, QByteArrayLiteral("applicationRunning")},
{ApplicationUniqueIdRole, QByteArrayLiteral("applicationUniqueId")}};
}
void ApplicationListModel::sycocaDbChanged(const QStringList &changes)
......@@ -114,39 +112,36 @@ void ApplicationListModel::initWayland()
}
auto *registry = new Registry(this);
registry->create(connection);
connect(registry, &Registry::plasmaWindowManagementAnnounced, this,
[this, registry] (quint32 name, quint32 version) {
m_windowManagement = registry->createPlasmaWindowManagement(name, version, this);
qRegisterMetaType<QVector<int> >("QVector<int>");
connect(m_windowManagement, &KWayland::Client::PlasmaWindowManagement::windowCreated,
this, [this] (KWayland::Client::PlasmaWindow *window) {
if (window->appId() == QStringLiteral("org.kde.plasmashell")) {
return;
}
int idx = 0;
for (auto i = m_applicationList.begin(); i != m_applicationList.end(); i++) {
if ((*i).storageId == window->appId() + QStringLiteral(".desktop")) {
(*i).window = window;
emit dataChanged(index(idx, 0), index(idx, 0));
connect(window, &KWayland::Client::PlasmaWindow::unmapped, this, [this, window] () {
int idx = 0;
for (auto i = m_applicationList.begin(); i != m_applicationList.end(); i++) {
if ((*i).storageId == window->appId() + QStringLiteral(".desktop")) {
(*i).window = nullptr;
emit dataChanged(index(idx, 0), index(idx, 0));
break;
}
idx++;
connect(registry, &Registry::plasmaWindowManagementAnnounced, this, [this, registry](quint32 name, quint32 version) {
m_windowManagement = registry->createPlasmaWindowManagement(name, version, this);
qRegisterMetaType<QVector<int>>("QVector<int>");
connect(m_windowManagement, &KWayland::Client::PlasmaWindowManagement::windowCreated, this, [this](KWayland::Client::PlasmaWindow *window) {
if (window->appId() == QStringLiteral("org.kde.plasmashell")) {
return;
}
int idx = 0;
for (auto i = m_applicationList.begin(); i != m_applicationList.end(); i++) {
if ((*i).storageId == window->appId() + QStringLiteral(".desktop")) {
(*i).window = window;
emit dataChanged(index(idx, 0), index(idx, 0));
connect(window, &KWayland::Client::PlasmaWindow::unmapped, this, [this, window]() {
int idx = 0;
for (auto i = m_applicationList.begin(); i != m_applicationList.end(); i++) {
if ((*i).storageId == window->appId() + QStringLiteral(".desktop")) {
(*i).window = nullptr;
emit dataChanged(index(idx, 0), index(idx, 0));
break;
}
});
break;
}
idx++;
idx++;
}
});
break;
}
});
}
);
idx++;
}
});
});
registry->setup();
connection->roundtrip();
......@@ -270,7 +265,7 @@ Qt::ItemFlags ApplicationListModel::flags(const QModelIndex &index) const
{
if (!index.isValid())
return {};
return Qt::ItemIsDragEnabled|QAbstractListModel::flags(index);
return Qt::ItemIsDragEnabled | QAbstractListModel::flags(index);
}
int ApplicationListModel::rowCount(const QModelIndex &parent) const
......@@ -282,7 +277,7 @@ int ApplicationListModel::rowCount(const QModelIndex &parent) const
return m_applicationList.count();
}
void ApplicationListModel::moveRow(const QModelIndex& /* sourceParent */, int sourceRow, const QModelIndex& /* destinationParent */, int destinationChild)
void ApplicationListModel::moveRow(const QModelIndex & /* sourceParent */, int sourceRow, const QModelIndex & /* destinationParent */, int destinationChild)
{
moveItem(sourceRow, destinationChild);
}
......@@ -301,8 +296,7 @@ void ApplicationListModel::setLocation(int row, LauncherLocation location)
if (location == Favorites) {
qWarning() << "favoriting" << row << data.name;
// Deny favorites when full
if (row >= m_maxFavoriteCount || m_favorites.count() >= m_maxFavoriteCount ||
m_favorites.contains(data.uniqueId)) {
if (row >= m_maxFavoriteCount || m_favorites.count() >= m_maxFavoriteCount || m_favorites.contains(data.uniqueId)) {
return;
}
......@@ -313,8 +307,8 @@ void ApplicationListModel::setLocation(int row, LauncherLocation location)
}
emit favoriteCountChanged();
// Out of favorites
} else if (data.location == Favorites) {
// Out of favorites
} else if (data.location == Favorites) {
m_favorites.removeAll(data.uniqueId);
if (m_applet) {
m_applet->applet()->config().writeEntry("Favorites", m_favorites);
......@@ -329,8 +323,8 @@ void ApplicationListModel::setLocation(int row, LauncherLocation location)
m_applet->applet()->config().writeEntry("DesktopItems", m_desktopItems.values());
}
// Out of Desktop
} else if (data.location == Desktop) {
// Out of Desktop
} else if (data.location == Desktop) {
m_desktopItems.remove(data.uniqueId);
if (m_applet) {
m_applet->applet()->config().writeEntry(QStringLiteral("DesktopItems"), m_desktopItems.values());
......@@ -346,8 +340,7 @@ void ApplicationListModel::setLocation(int row, LauncherLocation location)
void ApplicationListModel::moveItem(int row, int destination)
{
if (row < 0 || destination < 0 || row >= m_applicationList.length() ||
destination >= m_applicationList.length() || row == destination) {
if (row < 0 || destination < 0 || row >= m_applicationList.length() || destination >= m_applicationList.length() || row == destination) {
return;
}
if (destination > row) {
......@@ -365,7 +358,6 @@ void ApplicationListModel::moveItem(int row, int destination)
m_applicationList.insert(destination, data);
}
m_appOrder.clear();
m_appPositions.clear();
int i = 0;
......@@ -481,7 +473,7 @@ void ApplicationListModel::setMinimizedDelegate(int row, QQuickItem *delegate)
return;
}
QRect rect = delegate->mapRectToScene(QRectF(0,0, delegate->width(), delegate->height())).toRect();
QRect rect = delegate->mapRectToScene(QRectF(0, 0, delegate->width(), delegate->height())).toRect();
window->setMinimizedGeometry(surface, rect);
}
......@@ -512,6 +504,3 @@ void ApplicationListModel::unsetMinimizedDelegate(int row, QQuickItem *delegate)
window->unsetMinimizedGeometry(surface);
}
#include "moc_applicationlistmodel.cpp"
/*
* SPDX-FileCopyrightText: 2014 Antonis Tsiapaliokas <antonis.tsiapaliokas@kde.org>
* SPDX-FileCopyrightText: 2022 Devin Lin <devin@kde.org>
*
* SPDX-License-Identifier: GPL-2.0-or-later
*/
#ifndef APPLICATIONLISTMODEL_H
#define APPLICATIONLISTMODEL_H
#pragma once
// Qt
#include <QObject>
#include <QAbstractListModel>
#include <QList>
#include <QObject>
#include <QSet>
#include "homescreenutils.h"
......@@ -33,7 +33,8 @@ class AppletQuickItem;
class ApplicationListModel;
class ApplicationListModel : public QAbstractListModel {
class ApplicationListModel : public QAbstractListModel
{
Q_OBJECT
Q_PROPERTY(PlasmaQuick::AppletQuickItem *applet READ applet WRITE setApplet NOTIFY appletChanged)
......@@ -43,11 +44,7 @@ class ApplicationListModel : public QAbstractListModel {
Q_PROPERTY(int maxFavoriteCount READ maxFavoriteCount WRITE setMaxFavoriteCount NOTIFY maxFavoriteCountChanged)
public:
enum LauncherLocation {
Grid = 0,
Favorites,
Desktop
};
enum LauncherLocation { Grid = 0, Favorites, Desktop };
Q_ENUM(LauncherLocation)
struct ApplicationData {
......@@ -76,14 +73,26 @@ public:
ApplicationListModel(QObject *parent = nullptr);
~ApplicationListModel() override;
static ApplicationListModel *instance()
{
static ApplicationListModel *model = new ApplicationListModel;
return model;
}
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(); }
int favoriteCount() const { return m_favorites.count();}
int count() const
{
return m_applicationList.count();
}
int favoriteCount() const
{
return m_favorites.count();
}
int maxFavoriteCount() const;
void setMaxFavoriteCount(int count);
......@@ -109,7 +118,7 @@ public:
Q_INVOKABLE void unsetMinimizedDelegate(int row, QQuickItem *delegate);
public Q_SLOTS:
void sycocaDbChanged(const QStringList &change);
void sycocaDbChanged(const QStringList &change);
Q_SIGNALS:
void countChanged();
......@@ -131,5 +140,3 @@ protected:
QSet<QString> m_desktopItems;
QHash<QString, int> m_appPositions;
};
#endif // APPLICATIONLISTMODEL_H
......@@ -9,8 +9,8 @@
// Qt
#include <QByteArray>
#include <QModelIndex>
#include <QDebug>
#include <QModelIndex>
// KDE
#include <KService>
......@@ -28,7 +28,6 @@ FavoritesModel::FavoritesModel(QObject *parent)
FavoritesModel::~FavoritesModel() = default;
QString FavoritesModel::storageToUniqueId(const QString &storageId) const
{
if (storageId.isEmpty()) {
......@@ -54,10 +53,8 @@ QString FavoritesModel::uniqueToStorageId(const QString &uniqueId) const
return uniqueId.split(QLatin1Char('-')).first();
}
void FavoritesModel::loadApplications()
{
beginResetModel();
m_applicationList.clear();
......@@ -97,7 +94,7 @@ void FavoritesModel::loadApplications()
}
m_desktopItems.remove(uniqueId);
}
endResetModel();
emit countChanged();
......@@ -185,4 +182,3 @@ void FavoritesModel::removeFavorite(int row)
}
#include "moc_favoritesmodel.cpp"
......@@ -7,13 +7,13 @@
#pragma once
// Qt
#include <QObject>
#include <QAbstractListModel>
#include <QList>
#include <QObject>
#include <QSet>
#include "homescreenutils.h"
#include "applicationlistmodel.h"
#include "homescreenutils.h"
class QString;
......@@ -28,13 +28,19 @@ class PlasmaWindow;
class FavoritesModel;
class FavoritesModel : public ApplicationListModel {
class FavoritesModel : public ApplicationListModel
{
Q_OBJECT
public:
FavoritesModel(QObject *parent = nullptr);
~FavoritesModel() override;
static FavoritesModel *instance()
{
static FavoritesModel *model = new FavoritesModel;
return model;
}
QString storageToUniqueId(const QString &storageId) const;
QString uniqueToStorageId(const QString &uniqueId) const;
......@@ -43,7 +49,4 @@ public:
Q_INVOKABLE void removeFavorite(int row);
Q_INVOKABLE void loadApplications() override;
};
......@@ -6,14 +6,13 @@
#include "homescreenutils.h"
#include "favoritesmodel.h"
#include <QtQml>
#include <QDebug>
#include <QQuickItem>
#include <QtQml>
HomeScreenUtils::HomeScreenUtils(QObject *parent)
: QObject(parent)
{
}
HomeScreenUtils::~HomeScreenUtils() = default;
......@@ -36,5 +35,4 @@ void HomeScreenUtils::stackAfter(QQuickItem *item1, QQuickItem *item2)
item1->stackAfter(item2);
}
#include "moc_homescreenutils.cpp"
......@@ -6,7 +6,6 @@
#pragma once
#include <QObject>
class QQuickItem;
......@@ -17,16 +16,21 @@ class HomeScreenUtils : public QObject
Q_OBJECT
public:
HomeScreenUtils( QObject *parent = 0);
HomeScreenUtils(QObject *parent = 0);
~HomeScreenUtils() override;
static HomeScreenUtils *instance()
{
static HomeScreenUtils *model = new HomeScreenUtils;
return model;
}
Q_INVOKABLE void stackBefore(QQuickItem *item1, QQuickItem *item2);
Q_INVOKABLE void stackAfter(QQuickItem *item1, QQuickItem *item2);
protected:
// void configChanged() override;
// void configChanged() override;
private:
bool m_showAllApps = false;
};
......@@ -12,6 +12,10 @@
#include "notifications/notificationfilemenu.h"
#include "notifications/notificationthumbnailer.h"
#include "homescreen/applicationlistmodel.h"
#include "homescreen/favoritesmodel.h"
#include "homescreen/homescreenutils.h"
#include "mobileshellsettings.h"
#include "quicksetting.h"
#include "quicksettingsmodel.h"
......@@ -40,8 +44,20 @@ void MobileShellPlugin::registerTypes(const char *uri)
qmlRegisterType<SavedQuickSettings>(uri, 1, 0, "SavedQuickSettings");
qmlRegisterType<SavedQuickSettingsModel>(uri, 1, 0, "SavedQuickSettingsModel");
// taskswitcher
qmlRegisterType<DisplaysModel>(uri, 1, 0, "DisplaysModel");
// homescreen
qmlRegisterSingletonType<ApplicationListModel>(uri, 1, 0, "ApplicationListModel", [](QQmlEngine *, QJSEngine *) -> QObject * {
return ApplicationListModel::instance();
});