Advance Wayland and KDE package bring-up
Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
This commit is contained in:
@@ -0,0 +1,15 @@
|
||||
# SPDX-FileCopyrightText: 2021 Volker Krause <vkrause@kde.org>
|
||||
# SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
ecm_add_qml_module(knotificationqmlplugin URI org.kde.notification VERSION 1.0 GENERATE_PLUGIN_SOURCE)
|
||||
|
||||
target_sources(knotificationqmlplugin PRIVATE
|
||||
knotificationqmlplugin.cpp
|
||||
)
|
||||
|
||||
target_link_libraries(knotificationqmlplugin PRIVATE
|
||||
KF6Notifications
|
||||
Qt6::Qml
|
||||
)
|
||||
|
||||
ecm_finalize_qml_module(knotificationqmlplugin)
|
||||
@@ -0,0 +1,69 @@
|
||||
/*
|
||||
SPDX-FileCopyrightText: 2021 Volker Krause <vkrause@kde.org>
|
||||
|
||||
SPDX-License-Identifier: LGPL-2.0-or-later
|
||||
*/
|
||||
|
||||
#include "knotificationqmlplugin.h"
|
||||
|
||||
NotificationWrapper::NotificationWrapper(QObject *parent)
|
||||
: KNotification(QString(), KNotification::CloseOnTimeout, parent)
|
||||
{
|
||||
setAutoDelete(false);
|
||||
|
||||
m_actionsProperty = QQmlListProperty<KNotificationAction>(this,
|
||||
nullptr,
|
||||
&NotificationWrapper::appendAction,
|
||||
&NotificationWrapper::actionsCount,
|
||||
&NotificationWrapper::actionAt,
|
||||
&NotificationWrapper::clearActions);
|
||||
}
|
||||
|
||||
KNotificationReplyAction *NotificationWrapper::replyActionFactory()
|
||||
{
|
||||
if (!replyAction()) {
|
||||
setReplyAction(std::make_unique<KNotificationReplyAction>(QString()));
|
||||
}
|
||||
return replyAction();
|
||||
}
|
||||
|
||||
int NotificationWrapper::actionCount() const
|
||||
{
|
||||
return actions().count();
|
||||
}
|
||||
|
||||
KNotificationAction *NotificationWrapper::actionAt(qsizetype index)
|
||||
{
|
||||
return actions().at(index);
|
||||
}
|
||||
|
||||
QQmlListProperty<KNotificationAction> NotificationWrapper::actionsProperty() const
|
||||
{
|
||||
return m_actionsProperty;
|
||||
}
|
||||
|
||||
qsizetype NotificationWrapper::actionsCount(QQmlListProperty<KNotificationAction> *list)
|
||||
{
|
||||
return static_cast<NotificationWrapper *>(list->object)->actionCount();
|
||||
}
|
||||
|
||||
void NotificationWrapper::appendAction(QQmlListProperty<KNotificationAction> *list, KNotificationAction *value)
|
||||
{
|
||||
auto notification = static_cast<NotificationWrapper *>(list->object);
|
||||
auto actions = notification->actions();
|
||||
actions << value;
|
||||
notification->setActionsQml(actions);
|
||||
}
|
||||
|
||||
KNotificationAction *NotificationWrapper::actionAt(QQmlListProperty<KNotificationAction> *list, qsizetype index)
|
||||
{
|
||||
return static_cast<NotificationWrapper *>(list->object)->actionAt(index);
|
||||
}
|
||||
|
||||
void NotificationWrapper::clearActions(QQmlListProperty<KNotificationAction> *list)
|
||||
{
|
||||
auto notification = static_cast<KNotification *>(list->object);
|
||||
notification->clearActions();
|
||||
}
|
||||
|
||||
#include "moc_knotificationqmlplugin.cpp"
|
||||
@@ -0,0 +1,78 @@
|
||||
/*
|
||||
SPDX-FileCopyrightText: 2021 Volker Krause <vkrause@kde.org>
|
||||
|
||||
SPDX-License-Identifier: LGPL-2.0-or-later
|
||||
*/
|
||||
|
||||
#ifndef KNOTIFICATIONQMLPLUGIN_H
|
||||
#define KNOTIFICATIONQMLPLUGIN_H
|
||||
|
||||
#include <QQmlEngine>
|
||||
|
||||
#include <KNotification>
|
||||
#include <KNotificationPermission>
|
||||
#include <KNotificationReplyAction>
|
||||
|
||||
struct NotificationActionForeign {
|
||||
Q_GADGET
|
||||
QML_NAMED_ELEMENT(NotificationAction)
|
||||
QML_FOREIGN(KNotificationAction);
|
||||
};
|
||||
|
||||
struct NotificationReplyActionForeign {
|
||||
Q_GADGET
|
||||
QML_NAMED_ELEMENT(NotificationReplyAction)
|
||||
QML_UNCREATABLE("")
|
||||
QML_FOREIGN(KNotificationReplyAction);
|
||||
};
|
||||
|
||||
class NotificationWrapper : public KNotification
|
||||
{
|
||||
Q_OBJECT
|
||||
QML_NAMED_ELEMENT(Notification)
|
||||
Q_PROPERTY(KNotificationReplyAction *replyAction READ replyActionFactory CONSTANT)
|
||||
Q_PROPERTY(QQmlListProperty<KNotificationAction> actions READ actionsProperty NOTIFY actionsChanged)
|
||||
Q_PROPERTY(KNotificationAction *defaultAction READ defaultAction WRITE setDefaultActionQml NOTIFY defaultActionChanged)
|
||||
public:
|
||||
explicit NotificationWrapper(QObject *parent = nullptr);
|
||||
|
||||
KNotificationReplyAction *replyActionFactory();
|
||||
|
||||
int actionCount() const;
|
||||
|
||||
KNotificationAction *actionAt(qsizetype index);
|
||||
|
||||
QQmlListProperty<KNotificationAction> actionsProperty() const;
|
||||
|
||||
static qsizetype actionsCount(QQmlListProperty<KNotificationAction> *list);
|
||||
|
||||
static void appendAction(QQmlListProperty<KNotificationAction> *list, KNotificationAction *value);
|
||||
|
||||
static KNotificationAction *actionAt(QQmlListProperty<KNotificationAction> *list, qsizetype index);
|
||||
|
||||
static void clearActions(QQmlListProperty<KNotificationAction> *list);
|
||||
|
||||
private:
|
||||
QQmlListProperty<KNotificationAction> m_actionsProperty;
|
||||
};
|
||||
|
||||
class NotificationPermissionWrapper : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
QML_NAMED_ELEMENT(NotificationPermission)
|
||||
QML_SINGLETON
|
||||
public:
|
||||
Q_INVOKABLE bool checkPermission()
|
||||
{
|
||||
return KNotificationPermission::checkPermission() == Qt::PermissionStatus::Granted;
|
||||
}
|
||||
|
||||
Q_INVOKABLE void requestPermission(const QJSValue &callback)
|
||||
{
|
||||
KNotificationPermission::requestPermission(this, [callback](Qt::PermissionStatus status) {
|
||||
callback.call({status == Qt::PermissionStatus::Granted});
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
#endif // KNOTIFICATIONQMLPLUGIN_H
|
||||
Reference in New Issue
Block a user