matrixion/src/notifications/Manager.h

71 lines
1.9 KiB
C
Raw Normal View History

2021-03-05 02:35:15 +03:00
// SPDX-FileCopyrightText: 2021 Nheko Contributors
//
// SPDX-License-Identifier: GPL-3.0-or-later
2018-05-05 22:40:24 +03:00
#pragma once
#include <QImage>
#include <QObject>
2018-05-05 22:40:24 +03:00
#include <QString>
#include <mtx/responses/notifications.hpp>
#if defined(Q_OS_LINUX) || defined(Q_OS_FREEBSD) || defined(Q_OS_HAIKU)
#include <QtDBus/QDBusArgument>
#include <QtDBus/QDBusInterface>
#endif
struct roomEventId
2018-05-05 22:40:24 +03:00
{
QString roomId;
QString eventId;
};
2020-04-09 21:52:50 +03:00
inline bool
operator==(const roomEventId &a, const roomEventId &b)
{
return a.roomId == b.roomId && a.eventId == b.eventId;
}
class NotificationsManager : public QObject
{
Q_OBJECT
2018-05-05 22:40:24 +03:00
public:
NotificationsManager(QObject *parent = nullptr);
void postNotification(const mtx::responses::Notification &notification, const QImage &icon);
signals:
void notificationClicked(const QString roomId, const QString eventId);
void sendNotificationReply(const QString roomId, const QString eventId, const QString body);
2020-04-09 21:52:50 +03:00
public slots:
void removeNotification(const QString &roomId, const QString &eventId);
#if defined(Q_OS_LINUX) || defined(Q_OS_FREEBSD) || defined(Q_OS_HAIKU)
2020-04-09 21:52:50 +03:00
public:
void closeNotifications(QString roomId);
private:
QDBusInterface dbus;
2020-04-09 21:52:50 +03:00
void closeNotification(uint id);
// notification ID to (room ID, event ID)
QMap<uint, roomEventId> notificationIds;
#endif
// these slots are platform specific (D-Bus only)
// but Qt slot declarations can not be inside an ifdef!
private slots:
void actionInvoked(uint id, QString action);
void notificationClosed(uint id, uint reason);
void notificationReplied(uint id, QString reply);
2018-05-05 22:40:24 +03:00
};
#if defined(Q_OS_LINUX) || defined(Q_OS_FREEBSD) || defined(Q_OS_HAIKU)
QDBusArgument &
operator<<(QDBusArgument &arg, const QImage &image);
const QDBusArgument &
operator>>(const QDBusArgument &arg, QImage &);
#endif