-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add DBus desktop notification support.
This is nicer than the Qt built-in tray notifications. It only works on Linux. On other systems, tray notifications are pretty ok.
- Loading branch information
Showing
67 changed files
with
1,002 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,57 @@ | ||
/* SPDX-License-Identifier: GPL-3.0-or-later | ||
* Copyright © 2019 by The qTox Project Contributors | ||
* Copyright © 2024 The TokTok team. | ||
*/ | ||
|
||
#include "desktopnotify.h" | ||
|
||
#include "src/persistence/settings.h" | ||
#include "desktopnotifybackend.h" | ||
#include "src/persistence/inotificationsettings.h" | ||
|
||
#include <QSystemTrayIcon> | ||
|
||
DesktopNotify::DesktopNotify(Settings& settings, QSystemTrayIcon* icon) | ||
: settings_{settings} | ||
, icon_{icon} | ||
struct DesktopNotify::Private | ||
{ | ||
if (icon_) { | ||
connect(icon_, &QSystemTrayIcon::messageClicked, this, &DesktopNotify::notificationClosed); | ||
INotificationSettings& settings; | ||
QSystemTrayIcon* icon; | ||
DesktopNotifyBackend* dbus; | ||
}; | ||
|
||
DesktopNotify::DesktopNotify(INotificationSettings& settings, QObject* parent) | ||
: QObject(parent) | ||
, d{std::make_unique<Private>(Private{ | ||
settings, | ||
nullptr, | ||
new DesktopNotifyBackend(this), | ||
})} | ||
{ | ||
connect(d->dbus, &DesktopNotifyBackend::messageClicked, this, &DesktopNotify::notificationClosed); | ||
if (d->icon) { | ||
connect(d->icon, &QSystemTrayIcon::messageClicked, this, &DesktopNotify::notificationClosed); | ||
} | ||
} | ||
|
||
DesktopNotify::~DesktopNotify() = default; | ||
|
||
void DesktopNotify::setIcon(QSystemTrayIcon* icon) | ||
{ | ||
d->icon = icon; | ||
} | ||
|
||
void DesktopNotify::notifyMessage(const NotificationData& notificationData) | ||
{ | ||
if (!(settings_.getNotify() && settings_.getDesktopNotify())) { | ||
if (!(d->settings.getNotify() && d->settings.getDesktopNotify())) { | ||
return; | ||
} | ||
|
||
if (icon_) { | ||
icon_->showMessage(notificationData.title, notificationData.message, notificationData.pixmap); | ||
// Try system-backends first. | ||
if (d->settings.getNotifySystemBackend()) { | ||
if (d->dbus->showMessage(notificationData.title, notificationData.message, notificationData.pixmap)) { | ||
return; | ||
} | ||
} | ||
|
||
// Fallback to QSystemTrayIcon. | ||
if (d->icon) { | ||
d->icon->showMessage(notificationData.title, notificationData.message, notificationData.pixmap); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* SPDX-License-Identifier: GPL-3.0-or-later | ||
* Copyright © 2024 The TokTok team. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <QObject> | ||
|
||
#include <memory> | ||
|
||
class DesktopNotifyBackend : public QObject | ||
{ | ||
Q_OBJECT | ||
|
||
public: | ||
explicit DesktopNotifyBackend(QObject* parent); | ||
~DesktopNotifyBackend(); | ||
|
||
bool showMessage(const QString& title, const QString& message, const QPixmap& pixmap); | ||
|
||
signals: | ||
void messageClicked(); | ||
|
||
private slots: | ||
void notificationActionInvoked(QString actionKey, QString actionValue); | ||
void notificationActionInvoked(uint actionKey, QString actionValue); | ||
|
||
private: | ||
struct Private; | ||
const std::unique_ptr<Private> d; | ||
}; |
Oops, something went wrong.