summary refs log tree commit diff
path: root/include/notifications
diff options
context:
space:
mode:
authorMax Sandholm <max@sandholm.org>2018-07-11 17:33:02 +0300
committermujx <mujx@users.noreply.github.com>2018-07-11 17:33:02 +0300
commit80ebe3f29debb7f2020757252d1e2b4ae8a45869 (patch)
tree07a9bb42e559503787fbde1fd4eec7922bbafed0 /include/notifications
parentUse QSharedPointer::data to be compatible with Qt < 5.11 (diff)
downloadnheko-80ebe3f29debb7f2020757252d1e2b4ae8a45869.tar.xz
Working D-Bus desktop notifications (#361)
* Working D-Bus desktop notifications

* Remove return type on constructor

* Fix the Windows placeholder class

* Fix wrong variable name

* Fix windows and macOS versions of notificationsmanager
Diffstat (limited to 'include/notifications')
-rw-r--r--include/notifications/Manager.h51
1 files changed, 47 insertions, 4 deletions
diff --git a/include/notifications/Manager.h b/include/notifications/Manager.h

index 4ee4cb98..4ac60097 100644 --- a/include/notifications/Manager.h +++ b/include/notifications/Manager.h
@@ -1,12 +1,55 @@ #pragma once #include <QImage> +#include <QObject> #include <QString> -class NotificationsManager +#if defined(Q_OS_LINUX) +#include <QtDBus/QDBusArgument> +#include <QtDBus/QDBusInterface> +#endif + +struct roomEventId { + QString roomId; + QString eventId; +}; + +class NotificationsManager : public QObject +{ + Q_OBJECT public: - static void postNotification(const QString &room, - const QString &user, - const QString &message); + NotificationsManager(QObject *parent = nullptr); + + void postNotification(const QString &roomId, + const QString &eventId, + const QString &roomName, + const QString &senderName, + const QString &text, + const QImage &icon); + +signals: + void notificationClicked(const QString roomId, const QString eventId); + +#if defined(Q_OS_LINUX) +private: + QDBusInterface dbus; + uint showNotification(const QString summary, const QString text, const QImage image); + + // 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); }; + +#if defined(Q_OS_LINUX) +QDBusArgument & +operator<<(QDBusArgument &arg, const QImage &image); +const QDBusArgument & +operator>>(const QDBusArgument &arg, QImage &); +#endif