-
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
66 changed files
with
997 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 "desktopnotify_dbus.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; | ||
DesktopNotifyDBus* dbus; | ||
}; | ||
|
||
DesktopNotify::DesktopNotify(INotificationSettings& settings, QObject* parent) | ||
: QObject(parent) | ||
, d{std::make_unique<Private>(Private{ | ||
settings, | ||
nullptr, | ||
new DesktopNotifyDBus(this), | ||
})} | ||
{ | ||
connect(d->dbus, &DesktopNotifyDBus::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
Oops, something went wrong.