From f2028c506a5f71706fd689140fa8c068a7fca7cd Mon Sep 17 00:00:00 2001 From: Palakis Date: Fri, 21 Apr 2017 15:59:32 +0200 Subject: [PATCH] UI: System tray notification on new connections --- Utils.cpp | 21 +++++++++++++++++++++ Utils.h | 4 ++++ WSEvents.cpp | 3 +-- WSEvents.h | 2 +- WSServer.cpp | 4 ++++ 5 files changed, 31 insertions(+), 3 deletions(-) diff --git a/Utils.cpp b/Utils.cpp index 70d0fafe..6ed5c87e 100644 --- a/Utils.cpp +++ b/Utils.cpp @@ -384,3 +384,24 @@ const char* Utils::OBSVersionString() { return result; } + +QSystemTrayIcon* Utils::GetTrayIcon() +{ + QMainWindow* main = (QMainWindow*)obs_frontend_get_main_window(); + + QSystemTrayIcon* trayIcon = main->findChildren().first(); + blog(LOG_INFO, "tray icon : %s", trayIcon); + + return trayIcon; +} + +void Utils::SysTrayNotify(QString &text, QSystemTrayIcon::MessageIcon icon, QString title) +{ + if (!QSystemTrayIcon::supportsMessages()) + return; + + QSystemTrayIcon* trayIcon = GetTrayIcon(); + + if (trayIcon) + trayIcon->showMessage(title, text, icon); +} \ No newline at end of file diff --git a/Utils.h b/Utils.h index d7e0b0a2..c0e39398 100644 --- a/Utils.h +++ b/Utils.h @@ -23,6 +23,7 @@ with this program. If not, see #include #include #include +#include #include #include @@ -62,6 +63,9 @@ class Utils static void TransitionToProgram(); static const char* OBSVersionString(); + + static QSystemTrayIcon* GetTrayIcon(); + static void SysTrayNotify(QString &text, QSystemTrayIcon::MessageIcon n, QString title = QString("obs-websocket")); }; #endif // UTILS_H diff --git a/WSEvents.cpp b/WSEvents.cpp index 90fc617a..d586297c 100644 --- a/WSEvents.cpp +++ b/WSEvents.cpp @@ -234,8 +234,6 @@ void WSEvents::connectTransitionSignals(obs_source_t* transition) void WSEvents::connectSceneSignals(obs_source_t* scene) { - // TODO : connect to all scenes, not just the current one. - if (scene_handler) { signal_handler_disconnect(scene_handler, "reorder", OnSceneReordered, this); @@ -244,6 +242,7 @@ void WSEvents::connectSceneSignals(obs_source_t* scene) signal_handler_disconnect(scene_handler, "item_visible", OnSceneItemVisibilityChanged, this); } + // TODO : connect to all scenes, not just the current one. scene_handler = obs_source_get_signal_handler(scene); signal_handler_connect(scene_handler, "reorder", OnSceneReordered, this); signal_handler_connect(scene_handler, "item_add", OnSceneItemAdd, this); diff --git a/WSEvents.h b/WSEvents.h index 5e9d02bf..aaf0af5d 100644 --- a/WSEvents.h +++ b/WSEvents.h @@ -63,7 +63,7 @@ class WSEvents : public QObject uint64_t _lastBytesSentTime; void broadcastUpdate(const char *updateType, obs_data_t *additionalFields); - + void OnSceneChange(); void OnSceneListChange(); void OnSceneCollectionChange(); diff --git a/WSServer.cpp b/WSServer.cpp index b0449c77..10a27d6b 100644 --- a/WSServer.cpp +++ b/WSServer.cpp @@ -24,6 +24,7 @@ with this program. If not, see #include "WSServer.h" #include "obs-websocket.h" #include "Config.h" +#include "Utils.h" QT_USE_NAMESPACE @@ -114,6 +115,9 @@ void WSServer::onNewConnection() QByteArray client_ip = pSocket->peerAddress().toString().toUtf8(); blog(LOG_INFO, "new client connection from %s:%d", client_ip.constData(), pSocket->peerPort()); + + QString msg = QString("Client IP: ") + pSocket->peerAddress().toString(); + Utils::SysTrayNotify(msg, QSystemTrayIcon::Information, QString("New WebSocket connection")); } }