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
This commit is contained in:
parent
e7f30b57e8
commit
80ebe3f29d
7 changed files with 286 additions and 18 deletions
|
|
@ -30,6 +30,7 @@
|
|||
#include "CommunitiesList.h"
|
||||
#include "Community.h"
|
||||
#include "MatrixClient.h"
|
||||
#include "notifications/Manager.h"
|
||||
|
||||
class OverlayModal;
|
||||
class QuickSwitcher;
|
||||
|
|
@ -42,6 +43,7 @@ class TopRoomBar;
|
|||
class TypingDisplay;
|
||||
class UserInfoWidget;
|
||||
class UserSettings;
|
||||
class NotificationsManager;
|
||||
|
||||
namespace dialogs {
|
||||
class ReadReceipts;
|
||||
|
|
@ -140,6 +142,13 @@ signals:
|
|||
void syncTopBar(const std::map<QString, RoomInfo> &updates);
|
||||
void dropToLoginPageCb(const QString &msg);
|
||||
|
||||
void notifyMessage(const QString &roomid,
|
||||
const QString &eventid,
|
||||
const QString &roomname,
|
||||
const QString &sender,
|
||||
const QString &message,
|
||||
const QImage &icon);
|
||||
|
||||
private slots:
|
||||
void showUnreadMessageNotification(int count);
|
||||
void updateTopBarAvatar(const QString &roomid, const QPixmap &img);
|
||||
|
|
@ -238,6 +247,8 @@ private:
|
|||
|
||||
// Global user settings.
|
||||
QSharedPointer<UserSettings> userSettings_;
|
||||
|
||||
NotificationsManager notificationsManager;
|
||||
};
|
||||
|
||||
template<class Collection>
|
||||
|
|
|
|||
|
|
@ -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
|
||||
{
|
||||
public:
|
||||
static void postNotification(const QString &room,
|
||||
const QString &user,
|
||||
const QString &message);
|
||||
QString roomId;
|
||||
QString eventId;
|
||||
};
|
||||
|
||||
class NotificationsManager : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue