mirror of
https://github.com/qTox/qTox.git
synced 2024-03-22 14:00:36 +08:00
feat(notify): add desktop notifications using snorenotify
This commit adds very basic support for desktop notifications on friend request, group invites, friend messages and group messages.
This commit is contained in:
parent
18b52ce568
commit
66e2c01029
|
@ -14,6 +14,7 @@ option(USE_CCACHE "Use ccache when available" ON)
|
||||||
option(SPELL_CHECK "Enable spell cheching support" ON)
|
option(SPELL_CHECK "Enable spell cheching support" ON)
|
||||||
option(SVGZ_ICON "Compress the SVG icon of qTox" ON)
|
option(SVGZ_ICON "Compress the SVG icon of qTox" ON)
|
||||||
option(ASAN "Compile with AddressSanitizer" OFF)
|
option(ASAN "Compile with AddressSanitizer" OFF)
|
||||||
|
option(DESKTOP_NOTIFICATIONS "Use snorenotify for desktop notifications" OFF)
|
||||||
|
|
||||||
# process generated files if cmake >= 3.10
|
# process generated files if cmake >= 3.10
|
||||||
if(POLICY CMP0071)
|
if(POLICY CMP0071)
|
||||||
|
@ -650,6 +651,17 @@ else()
|
||||||
message(STATUS "NOT using update check")
|
message(STATUS "NOT using update check")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
if (${DESKTOP_NOTIFICATIONS})
|
||||||
|
add_definitions(-DDESKTOP_NOTIFICATIONS=1)
|
||||||
|
set(${PROJECT_NAME}_SOURCES ${${PROJECT_NAME}_SOURCES}
|
||||||
|
src/platform/desktop_notifications/desktopnotify.cpp
|
||||||
|
src/platform/desktop_notifications/desktopnotify.h)
|
||||||
|
message(STATUS "using desktop notifications")
|
||||||
|
else()
|
||||||
|
add_definitions(-DDESKTOP_NOTIFICATIONS=0)
|
||||||
|
message(STATUS "not using desktop notifications")
|
||||||
|
endif()
|
||||||
|
|
||||||
if (MINGW)
|
if (MINGW)
|
||||||
STRING(TOLOWER "${CMAKE_BUILD_TYPE}" CMAKE_BUILD_TYPE_LOWER)
|
STRING(TOLOWER "${CMAKE_BUILD_TYPE}" CMAKE_BUILD_TYPE_LOWER)
|
||||||
if (CMAKE_BUILD_TYPE_LOWER MATCHES debug)
|
if (CMAKE_BUILD_TYPE_LOWER MATCHES debug)
|
||||||
|
|
12
INSTALL.md
12
INSTALL.md
|
@ -46,6 +46,7 @@
|
||||||
| [sqlcipher] | >= 3.2.0 | |
|
| [sqlcipher] | >= 3.2.0 | |
|
||||||
| [pkg-config] | >= 0.28 | |
|
| [pkg-config] | >= 0.28 | |
|
||||||
| [filteraudio] | >= 0.0.1 | optional dependency |
|
| [filteraudio] | >= 0.0.1 | optional dependency |
|
||||||
|
| [snorenotify] | >= 0.7.0 | optional dependency |
|
||||||
|
|
||||||
## Optional dependencies
|
## Optional dependencies
|
||||||
|
|
||||||
|
@ -116,6 +117,16 @@ Disabled by default.
|
||||||
|
|
||||||
To enable: `-DENABLE_APPINDICATOR=True`
|
To enable: `-DENABLE_APPINDICATOR=True`
|
||||||
|
|
||||||
|
#### Snorenotify desktop notification backend
|
||||||
|
|
||||||
|
Disabled by default
|
||||||
|
|
||||||
|
| Name | Version |
|
||||||
|
|-------------------|-----------|
|
||||||
|
| [snorenotify] | >= 0.7.0 |
|
||||||
|
|
||||||
|
To enable: `-DDESKTOP_NOTIFICATIONS=True`
|
||||||
|
|
||||||
|
|
||||||
## Linux
|
## Linux
|
||||||
### Simple install
|
### Simple install
|
||||||
|
@ -829,3 +840,4 @@ Switches:
|
||||||
[toxcore]: https://github.com/TokTok/c-toxcore/
|
[toxcore]: https://github.com/TokTok/c-toxcore/
|
||||||
[filteraudio]: https://github.com/irungentoo/filter_audio
|
[filteraudio]: https://github.com/irungentoo/filter_audio
|
||||||
[sonnet]: https://github.com/KDE/sonnet
|
[sonnet]: https://github.com/KDE/sonnet
|
||||||
|
[snorenotify]: https://techbase.kde.org/Projects/Snorenotify
|
||||||
|
|
|
@ -221,6 +221,12 @@ if (PLATFORM_EXTENSIONS)
|
||||||
endif()
|
endif()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
if (${DESKTOP_NOTIFICATIONS})
|
||||||
|
# snorenotify does only provide a cmake find module
|
||||||
|
find_package(LibsnoreQt5 0.7.0 REQUIRED)
|
||||||
|
set(ALL_LIBRARIES ${ALL_LIBRARIES} Snore::Libsnore)
|
||||||
|
endif()
|
||||||
|
|
||||||
add_definitions(
|
add_definitions(
|
||||||
-DLOG_TO_FILE=1
|
-DLOG_TO_FILE=1
|
||||||
)
|
)
|
||||||
|
|
81
src/platform/desktop_notifications/desktopnotify.cpp
Normal file
81
src/platform/desktop_notifications/desktopnotify.cpp
Normal file
|
@ -0,0 +1,81 @@
|
||||||
|
#include "desktopnotify.h"
|
||||||
|
|
||||||
|
#include <libsnore/snore.h>
|
||||||
|
|
||||||
|
#include <QDebug>
|
||||||
|
|
||||||
|
DesktopNotify::DesktopNotify()
|
||||||
|
: notifyCore{Snore::SnoreCore::instance()}
|
||||||
|
, snoreIcon{":/img/icons/qtox.svg"}
|
||||||
|
{
|
||||||
|
|
||||||
|
notifyCore.loadPlugins(Snore::SnorePlugin::Backend);
|
||||||
|
qDebug() << "primary notification backend:" << notifyCore.primaryNotificationBackend();
|
||||||
|
|
||||||
|
snoreApp = Snore::Application("qTox", snoreIcon);
|
||||||
|
|
||||||
|
notifyCore.registerApplication(snoreApp);
|
||||||
|
}
|
||||||
|
|
||||||
|
DesktopNotify::NotificationPtr DesktopNotify::createNotification(const QString& title,
|
||||||
|
const QString& text,
|
||||||
|
Snore::Notification* old)
|
||||||
|
{
|
||||||
|
if (old == nullptr) {
|
||||||
|
return NotificationPtr(
|
||||||
|
new Snore::Notification(snoreApp, Snore::Alert(), title, text, snoreIcon));
|
||||||
|
} else {
|
||||||
|
return NotificationPtr(new Snore::Notification(*old, title, text, snoreIcon));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void DesktopNotify::notifyGroupMessage()
|
||||||
|
{
|
||||||
|
const QString text{};
|
||||||
|
const QString title = tr("New group message received");
|
||||||
|
NotificationPtr newNote = createNotification(title, text);
|
||||||
|
if (!newNote) {
|
||||||
|
qDebug() << "Failed to allocate group message notification";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
groupInvite = std::move(newNote);
|
||||||
|
}
|
||||||
|
|
||||||
|
void DesktopNotify::notifyFriendRequest()
|
||||||
|
{
|
||||||
|
const QString title = tr("New friend request received");
|
||||||
|
const QString text{};
|
||||||
|
NotificationPtr newNote = createNotification(title, text);
|
||||||
|
if (!newNote) {
|
||||||
|
qDebug() << "Failed to allocate friend message notification";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
friendMessage = std::move(newNote);
|
||||||
|
notifyCore.broadcastNotification(*friendMessage);
|
||||||
|
}
|
||||||
|
|
||||||
|
void DesktopNotify::notifyGroupInvite()
|
||||||
|
{
|
||||||
|
const QString title = tr("New group invite received");
|
||||||
|
const QString text{};
|
||||||
|
NotificationPtr newNote = createNotification(title, text);
|
||||||
|
if (!newNote) {
|
||||||
|
qDebug() << "Failed to allocate friend message notification";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
friendMessage = std::move(newNote);
|
||||||
|
notifyCore.broadcastNotification(*friendMessage);
|
||||||
|
}
|
||||||
|
|
||||||
|
void DesktopNotify::notifyFriendMessage()
|
||||||
|
{
|
||||||
|
const QString title = tr("New message received");
|
||||||
|
const QString text{};
|
||||||
|
NotificationPtr newNote = createNotification(title, text);
|
||||||
|
if (!newNote) {
|
||||||
|
qDebug() << "Failed to allocate friend message notification";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
friendMessage = std::move(newNote);
|
||||||
|
notifyCore.broadcastNotification(*friendMessage);
|
||||||
|
}
|
37
src/platform/desktop_notifications/desktopnotify.h
Normal file
37
src/platform/desktop_notifications/desktopnotify.h
Normal file
|
@ -0,0 +1,37 @@
|
||||||
|
#ifndef DESKTOPNOTIFY_H
|
||||||
|
#define DESKTOPNOTIFY_H
|
||||||
|
|
||||||
|
#include <libsnore/snore.h>
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
|
class DesktopNotify : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
DesktopNotify();
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
void notifyFriendMessage();
|
||||||
|
void notifyGroupMessage();
|
||||||
|
void notifyFriendRequest();
|
||||||
|
void notifyGroupInvite();
|
||||||
|
|
||||||
|
private:
|
||||||
|
using NotificationPtr = std::unique_ptr<Snore::Notification>;
|
||||||
|
|
||||||
|
NotificationPtr createNotification(const QString& title, const QString& text,
|
||||||
|
Snore::Notification* old = nullptr);
|
||||||
|
|
||||||
|
private:
|
||||||
|
Snore::SnoreCore& notifyCore;
|
||||||
|
NotificationPtr groupInvite = {nullptr};
|
||||||
|
NotificationPtr groupMessage = {nullptr};
|
||||||
|
NotificationPtr friendRequest = {nullptr};
|
||||||
|
NotificationPtr friendMessage = {nullptr};
|
||||||
|
Snore::Application snoreApp;
|
||||||
|
Snore::Icon snoreIcon;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // DESKTOPNOTIFY_H
|
|
@ -1357,6 +1357,9 @@ bool Widget::newFriendMessageAlert(int friendId, bool sound)
|
||||||
f->setEventFlag(true);
|
f->setEventFlag(true);
|
||||||
widget->updateStatusLight();
|
widget->updateStatusLight();
|
||||||
ui->friendList->trackWidget(widget);
|
ui->friendList->trackWidget(widget);
|
||||||
|
#if DESKTOP_NOTIFICATIONS
|
||||||
|
notifier.notifyFriendMessage();
|
||||||
|
#endif
|
||||||
|
|
||||||
if (contentDialog == nullptr) {
|
if (contentDialog == nullptr) {
|
||||||
if (hasActive) {
|
if (hasActive) {
|
||||||
|
@ -1394,6 +1397,9 @@ bool Widget::newGroupMessageAlert(int groupId, bool notify)
|
||||||
|
|
||||||
g->setEventFlag(true);
|
g->setEventFlag(true);
|
||||||
widget->updateStatusLight();
|
widget->updateStatusLight();
|
||||||
|
#if DESKTOP_NOTIFICATIONS
|
||||||
|
notifier.notifyGroupMessage();
|
||||||
|
#endif
|
||||||
|
|
||||||
if (contentDialog == nullptr) {
|
if (contentDialog == nullptr) {
|
||||||
if (hasActive) {
|
if (hasActive) {
|
||||||
|
@ -1462,6 +1468,9 @@ void Widget::onFriendRequestReceived(const ToxPk& friendPk, const QString& messa
|
||||||
if (addFriendForm->addFriendRequest(friendPk.toString(), message)) {
|
if (addFriendForm->addFriendRequest(friendPk.toString(), message)) {
|
||||||
friendRequestsUpdate();
|
friendRequestsUpdate();
|
||||||
newMessageAlert(window(), isActiveWindow(), true, true);
|
newMessageAlert(window(), isActiveWindow(), true, true);
|
||||||
|
#if DESKTOP_NOTIFICATIONS
|
||||||
|
notifier.notifyFriendRequest();
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1706,6 +1715,9 @@ void Widget::onGroupInviteReceived(const GroupInvite& inviteInfo)
|
||||||
++unreadGroupInvites;
|
++unreadGroupInvites;
|
||||||
groupInvitesUpdate();
|
groupInvitesUpdate();
|
||||||
newMessageAlert(window(), isActiveWindow(), true, true);
|
newMessageAlert(window(), isActiveWindow(), true, true);
|
||||||
|
#if DESKTOP_NOTIFICATIONS
|
||||||
|
notifier.notifyGroupInvite();
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
qWarning() << "onGroupInviteReceived: Unknown groupchat type:" << confType;
|
qWarning() << "onGroupInviteReceived: Unknown groupchat type:" << confType;
|
||||||
|
|
|
@ -32,6 +32,9 @@
|
||||||
#include "src/core/core.h"
|
#include "src/core/core.h"
|
||||||
#include "src/core/toxfile.h"
|
#include "src/core/toxfile.h"
|
||||||
#include "src/core/toxid.h"
|
#include "src/core/toxid.h"
|
||||||
|
#if DESKTOP_NOTIFICATIONS
|
||||||
|
#include "src/platform/desktop_notifications/desktopnotify.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
#define PIXELS_TO_ACT 7
|
#define PIXELS_TO_ACT 7
|
||||||
|
|
||||||
|
@ -298,7 +301,7 @@ private:
|
||||||
MaskablePixmapWidget* profilePicture;
|
MaskablePixmapWidget* profilePicture;
|
||||||
bool notify(QObject* receiver, QEvent* event);
|
bool notify(QObject* receiver, QEvent* event);
|
||||||
bool autoAwayActive = false;
|
bool autoAwayActive = false;
|
||||||
QTimer *timer;
|
QTimer* timer;
|
||||||
QRegExp nameMention, sanitizedNameMention;
|
QRegExp nameMention, sanitizedNameMention;
|
||||||
bool eventFlag;
|
bool eventFlag;
|
||||||
bool eventIcon;
|
bool eventIcon;
|
||||||
|
@ -317,6 +320,10 @@ private:
|
||||||
QMap<uint32_t, std::shared_ptr<GroupChatroom>> groupChatrooms;
|
QMap<uint32_t, std::shared_ptr<GroupChatroom>> groupChatrooms;
|
||||||
QMap<uint32_t, QSharedPointer<GroupChatForm>> groupChatForms;
|
QMap<uint32_t, QSharedPointer<GroupChatForm>> groupChatForms;
|
||||||
|
|
||||||
|
#if DESKTOP_NOTIFICATIONS
|
||||||
|
DesktopNotify notifier;
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef Q_OS_MAC
|
#ifdef Q_OS_MAC
|
||||||
QAction* fileMenu;
|
QAction* fileMenu;
|
||||||
QAction* editMenu;
|
QAction* editMenu;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user