Verified Commit b856b787 authored by Jonah Brüchert's avatar Jonah Brüchert 🌳
Browse files

Open and close StartupFeedback using KStartupInfo

parent f3ab3c0a
......@@ -34,6 +34,7 @@ find_package(KF5 ${KF5_MIN_VERSION} REQUIRED COMPONENTS
PlasmaQuick
Service
Notifications
WindowSystem
)
find_package(KF5Wayland CONFIG)
set_package_properties(KF5Wayland PROPERTIES
......
set(homescreen_SRCS
homescreen.cpp
applicationlistmodel.cpp
colouraverage.cpp
)
add_library(plasma_containment_phone_homescreen MODULE ${homescreen_SRCS})
......@@ -17,6 +16,7 @@ target_link_libraries(plasma_containment_phone_homescreen
KF5::Service
KF5::KIOGui
KF5::Notifications
KF5::WindowSystem
)
......
......@@ -39,12 +39,31 @@ constexpr int MAX_FAVOURITES = 5;
ApplicationListModel::ApplicationListModel(HomeScreen *parent)
: QAbstractListModel(parent),
m_homeScreen(parent)
m_homeScreen(parent),
m_startupInfo(new KStartupInfo(0, this))
{
connect(KSycoca::self(), qOverload<const QStringList &>(&KSycoca::databaseChanged),
this, &ApplicationListModel::sycocaDbChanged);
connect(m_startupInfo, &KStartupInfo::gotRemoveStartup,
this, &ApplicationListModel::applicationExited);
connect(m_startupInfo, &KStartupInfo::gotNewStartup,
this, [=](const KStartupInfoId &, const KStartupInfoData &data) {
applicationStarted(data.name(), data.icon());
});
loadSettings();
// Debug
connect(this, &ApplicationListModel::applicationStarted, this, [=](const QString &name, const QString &icon) {
qDebug() << "Opening startup feedback for" << name << icon;
});
connect(this, &ApplicationListModel::applicationExited, this, []() {
qDebug() << "Removing startup feedback";
});
}
ApplicationListModel::~ApplicationListModel() = default;
......@@ -116,7 +135,8 @@ void ApplicationListModel::loadApplications()
m_applicationList.clear();
KServiceGroup::Ptr group = KServiceGroup::root();
if (!group || !group->isValid()) return;
if (!group || !group->isValid())
return;
KServiceGroup::List subGroupList = group->entries(true);
QMap<int, ApplicationData> orderedList;
......
......@@ -26,6 +26,9 @@
#include <QList>
#include <QSet>
// KDE
#include <KStartupInfo>
#include "homescreen.h"
class QString;
......@@ -102,6 +105,8 @@ Q_SIGNALS:
void countChanged();
void favoriteCountChanged();
void maxFavoriteCountChanged();
void applicationStarted(const QString &name, const QString &icon);
void applicationExited();
private:
QList<ApplicationData> m_applicationList;
......@@ -112,6 +117,7 @@ private:
QStringList m_favorites;
QSet<QString> m_desktopItems;
QHash<QString, int> m_appPositions;
KStartupInfo *m_startupInfo;
};
#endif // APPLICATIONLISTMODEL_H
/***************************************************************************
* Copyright (C) 2019 Carson Black <uhhadd@gmail.com> *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . *
***************************************************************************/
#include <QObject>
#include <QColor>
#include <QImage>
#include <QDebug>
#include "colouraverage.h"
ColourAverage::ColourAverage(QObject *parent) : QObject(parent)
{
}
QColor ColourAverage::averageColour(const QImage &img) {
int r = 0;
int g = 0;
int b = 0;
int c = 0;
for (int i = 0; i < img.width(); i++) {
for (int ii = 0; ii < img.height(); ii++) {
QRgb pix = img.pixel(i, ii);
if (pix == 0)
continue;
c++;
r += qRed(pix);
g += qGreen(pix);
b += qBlue(pix);
}
}
r = r / c;
g = g / c;
b = b / c;
QColor color = QColor::fromRgb(r,g,b);
color.setHsv(color.hue(), color.saturation() / 4, color.value());
return color;
}
/***************************************************************************
* Copyright (C) 2019 Carson Black <uhhadd@gmail.com> *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . *
***************************************************************************/
#pragma once
#include <QObject>
#include <QColor>
#include <QImage>
class ColourAverage : public QObject
{
Q_OBJECT
public:
explicit ColourAverage(QObject *parent = nullptr);
Q_INVOKABLE QColor averageColour(const QImage &img);
};
......@@ -19,7 +19,6 @@
#include "homescreen.h"
#include "applicationlistmodel.h"
#include "colouraverage.h"
#include <QtQml>
#include <QDebug>
......@@ -29,9 +28,6 @@ HomeScreen::HomeScreen(QObject *parent, const QVariantList &args)
: Plasma::Containment(parent, args)
{
qmlRegisterUncreatableType<ApplicationListModel>("org.kde.phone.homescreen", 1, 0, "ApplicationListModel", QStringLiteral("Cannot create item of type ApplicationListModel"));
qmlRegisterSingletonType<ColourAverage>("org.kde.phone.homescreen", 1, 0, "ColourAverage", [](QQmlEngine *, QJSEngine *) -> QObject * {
return new ColourAverage();
});
setHasConfigurationInterface(true);
}
......
......@@ -92,11 +92,7 @@ ContainmentLayoutManager.ItemContainer {
}
contentItem: MouseArea {
onClicked: {
delegate.launch(delegate.x + (units.smallSpacing * 2), delegate.y + (units.smallSpacing * 2), icon.source, modelData.applicationName)
plasmoid.nativeInterface.applicationListModel.runApplication(modelData.applicationStorageId);
}
onClicked: plasmoid.nativeInterface.applicationListModel.runApplication(modelData.applicationStorageId);
//preventStealing: true
ColumnLayout {
......
......@@ -24,7 +24,7 @@ import org.kde.plasma.plasmoid 2.0
import org.kde.plasma.core 2.0 as PlasmaCore
import org.kde.plasma.components 2.0 as PlasmaComponents
import org.kde.kquickcontrolsaddons 2.0
import org.kde.kirigami 2.10 as Kirigami
import org.kde.kirigami 2.13 as Kirigami
import org.kde.plasma.private.containmentlayoutmanager 1.0 as ContainmentLayoutManager
import org.kde.plasma.private.nanoshell 2.0 as NanoShell
......@@ -41,6 +41,20 @@ LauncherContainer {
frame.width: width
Connections {
target: plasmoid.nativeInterface.applicationListModel
onApplicationExited: NanoShell.StartupFeedback.close()
onApplicationStarted: (name, icon) => {
NanoShell.StartupFeedback.open(
icon,
name,
root.width * 0.5,
root.height * 0.5,
root.width * 0.2
);
}
}
Repeater {
parent: root.flow
model: plasmoid.nativeInterface.applicationListModel
......@@ -65,17 +79,6 @@ LauncherContainer {
appletsLayout.restoreItem(delegate);
}
}
onLaunch: (x, y, icon, title) => {
delegate.grabToImage((img) => {
NanoShell.StartupFeedback.open(
icon,
title,
delegate.iconItem.Kirigami.ScenePosition.x + delegate.iconItem.width/2,
delegate.iconItem.Kirigami.ScenePosition.y + delegate.iconItem.height/2,
Math.min(delegate.iconItem.width, delegate.iconItem.height),
ColourAverage.averageColour(img.image));
});
}
onParentFromLocationChanged: {
if (!launcherDragManager.active && parent != parentFromLocation) {
parent = parentFromLocation;
......
......@@ -58,13 +58,6 @@ ColumnLayout {
} else if (model.toggleFunction) {
root[model.toggleFunction]();
} else if (model.settingsCommand) {
NanoShell.StartupFeedback.open(
model.icon,
model.text,
icon.Kirigami.ScenePosition.x + icon.width/2,
icon.Kirigami.ScenePosition.y + icon.height/2,
Math.min(icon.width, icon.height),
theme.textColor);
plasmoid.nativeInterface.executeCommand(model.settingsCommand);
root.closeRequested();
}
......@@ -105,13 +98,6 @@ ColumnLayout {
anchors.fill: parent
onClicked: {
if (model.settingsCommand) {
NanoShell.StartupFeedback.open(
model.icon,
model.text,
icon.Kirigami.ScenePosition.x + icon.width/2,
icon.Kirigami.ScenePosition.y + icon.height/2,
Math.min(icon.width, icon.height),
theme.textColor);
//plasmoid.nativeInterface.executeCommand(model.settingsCommand);
closeRequested();
} else if (model.toggleFunction) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment