2013-08-13 23:09:46 +01:00
|
|
|
/**
|
2020-08-17 10:48:10 +01:00
|
|
|
* SPDX-FileCopyrightText: 2013 Albert Vaca <albertvaka@gmail.com>
|
2013-08-13 23:09:46 +01:00
|
|
|
*
|
2020-08-17 10:48:10 +01:00
|
|
|
* SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
|
2013-08-13 23:09:46 +01:00
|
|
|
*/
|
|
|
|
|
2023-07-21 19:22:59 +01:00
|
|
|
#pragma once
|
2013-08-13 23:09:46 +01:00
|
|
|
|
2014-06-14 15:34:00 +01:00
|
|
|
#include <core/kdeconnectplugin.h>
|
2016-05-31 16:16:01 +01:00
|
|
|
|
2020-10-15 03:03:05 +01:00
|
|
|
#include "notification.h"
|
|
|
|
|
2018-03-04 19:48:51 +00:00
|
|
|
#define PACKET_TYPE_NOTIFICATION_REQUEST QStringLiteral("kdeconnect.notification.request")
|
|
|
|
#define PACKET_TYPE_NOTIFICATION_REPLY QStringLiteral("kdeconnect.notification.reply")
|
2019-02-08 22:47:41 +00:00
|
|
|
#define PACKET_TYPE_NOTIFICATION_ACTION QStringLiteral("kdeconnect.notification.action")
|
|
|
|
|
2022-09-10 22:23:52 +01:00
|
|
|
class NotificationsPlugin : public KdeConnectPlugin
|
2013-08-13 23:09:46 +01:00
|
|
|
{
|
|
|
|
Q_OBJECT
|
2020-10-15 03:03:05 +01:00
|
|
|
Q_CLASSINFO("D-Bus Interface", "org.kde.kdeconnect.device.notifications")
|
2013-08-13 23:09:46 +01:00
|
|
|
|
|
|
|
public:
|
2022-09-10 22:23:52 +01:00
|
|
|
explicit NotificationsPlugin(QObject *parent, const QVariantList &args);
|
2018-03-18 11:42:15 +00:00
|
|
|
|
2022-09-10 22:23:52 +01:00
|
|
|
bool receivePacket(const NetworkPacket &np) override;
|
2016-06-20 08:05:02 +01:00
|
|
|
void connected() override;
|
2020-10-15 03:03:05 +01:00
|
|
|
QString dbusPath() const override;
|
|
|
|
|
|
|
|
void clearNotifications();
|
2022-09-10 22:23:52 +01:00
|
|
|
void dismissRequested(const QString ¬ification);
|
|
|
|
void replyRequested(Notification *noti);
|
|
|
|
void addNotification(Notification *noti);
|
2020-10-15 03:03:05 +01:00
|
|
|
|
|
|
|
public Q_SLOTS:
|
|
|
|
Q_SCRIPTABLE QStringList activeNotifications();
|
2022-09-10 22:23:52 +01:00
|
|
|
Q_SCRIPTABLE void sendReply(const QString &replyId, const QString &message);
|
|
|
|
Q_SCRIPTABLE void sendAction(const QString &key, const QString &action);
|
2020-10-15 03:03:05 +01:00
|
|
|
|
|
|
|
Q_SIGNALS:
|
2022-09-10 22:23:52 +01:00
|
|
|
Q_SCRIPTABLE void notificationPosted(const QString &publicId);
|
|
|
|
Q_SCRIPTABLE void notificationRemoved(const QString &publicId);
|
|
|
|
Q_SCRIPTABLE void notificationUpdated(const QString &publicId);
|
2020-10-15 03:03:05 +01:00
|
|
|
Q_SCRIPTABLE void allNotificationsRemoved();
|
|
|
|
|
|
|
|
private:
|
2022-09-10 22:23:52 +01:00
|
|
|
void removeNotification(const QString &internalId);
|
|
|
|
QString newId(); // Generates successive identifiers to use as public ids
|
2020-10-15 03:03:05 +01:00
|
|
|
void notificationReady();
|
|
|
|
|
|
|
|
QHash<QString, QPointer<Notification>> m_notifications;
|
|
|
|
QHash<QString, QString> m_internalIdToPublicId;
|
|
|
|
int m_lastId = 0;
|
2013-08-13 23:09:46 +01:00
|
|
|
};
|