From c876913201745e3fa7d3a91d6b7a4b1539f412d5 Mon Sep 17 00:00:00 2001 From: Gaelle Braud Date: Wed, 25 Mar 2026 15:02:33 +0100 Subject: [PATCH] exemple notif --- Linphone/CMakeLists.txt | 25 ++++++++++++++---------- Linphone/core/App.cpp | 42 +++++++++++++++++++++++++++++++++++++++-- Linphone/core/App.hpp | 2 ++ 3 files changed, 57 insertions(+), 12 deletions(-) diff --git a/Linphone/CMakeLists.txt b/Linphone/CMakeLists.txt index 3c2b5a4d3..ea5bd3d42 100644 --- a/Linphone/CMakeLists.txt +++ b/Linphone/CMakeLists.txt @@ -26,8 +26,12 @@ set(QT_PACKAGES Quick Qml Widgets Svg Test NetworkAuth Concurrent)# Search Core if (UNIX AND NOT APPLE) list(APPEND QT_PACKAGES DBus) endif() -find_package(Qt6 REQUIRED COMPONENTS Core) -find_package(Qt6 REQUIRED COMPONENTS ${QT_PACKAGES}) +# foreach(package ${Qt_PACKAGES}) +# find_package(Qt6 REQUIRED COMPONENTS ${package}) +# endforeach() + +find_package(Qt6 REQUIRED COMPONENTS Core DBus Svg Test NetworkAuth Concurrent) +find_package(Qt6 REQUIRED COMPONENTS) find_package(Qt6 REQUIRED COMPONENTS LinguistTools) find_package(ECM REQUIRED NO_MODULE) @@ -230,11 +234,12 @@ foreach(T ${APP_TARGETS}) endforeach() target_link_libraries(${TARGET_NAME} PRIVATE Qt6::Core) +target_link_libraries(${TARGET_NAME} PRIVATE Qt6::DBus) foreach(T ${QT_PACKAGES}) target_link_libraries(${TARGET_NAME} PRIVATE Qt6::${T}) endforeach() - +target_link_libraries(${TARGET_NAME} PRIVATE KF6::Notifications) configure_file("${CMAKE_CURRENT_SOURCE_DIR}/config.h.cmake" "${CMAKE_CURRENT_BINARY_DIR}/config.h") @@ -248,13 +253,13 @@ if (WIN32) endif() if(UNIX AND NOT APPLE) - # Linux : /usr/share/knotifications6/ ET ~/.local/share/knotifications6/ - install(FILES linphone.notifyrc DESTINATION ${KDE_INSTALL_KNOTIFYRCDIR}) - install(FILES linphone.notifyrc DESTINATION "$ENV{HOME}/.local/share/knotifications6/") + # Linux : /usr/share/knotifications6/ ET ~/.local/share/knotifications6/ + install(FILES linphone.notifyrc DESTINATION ${KDE_INSTALL_KNOTIFYRCDIR}) + install(FILES linphone.notifyrc DESTINATION "$ENV{HOME}/.local/share/knotifications6/") elseif(WIN32) - # Windows : AppData/Local + AppData/Roaming - install(FILES linphone.notifyrc DESTINATION "data/knotifications6/" TYPE BIN) + # Windows : AppData/Local + AppData/Roaming + install(FILES linphone.notifyrc DESTINATION "data/knotifications6/" TYPE BIN) elseif(APPLE) - # macOS : ~/Library/Application Support/linphone/knotifications6/ - install(FILES linphone.notifyrc DESTINATION "linphone/knotifications6/" TYPE BIN) + # macOS : ~/Library/Application Support/linphone/knotifications6/ + install(FILES linphone.notifyrc DESTINATION "linphone/knotifications6/") endif() diff --git a/Linphone/core/App.cpp b/Linphone/core/App.cpp index 831c5c0e9..c5dc90f67 100644 --- a/Linphone/core/App.cpp +++ b/Linphone/core/App.cpp @@ -21,8 +21,10 @@ #include "tool/LinphoneEnums.hpp" #include "App.hpp" - +#include #include +#include +#include #include #include #include @@ -279,6 +281,34 @@ void App::setAutoStart(bool enabled) { #endif // ifdef Q_OS_LINUX +void App::sendNotification(const QString &title, const QString &message) { + QDBusConnection bus = QDBusConnection::sessionBus(); + if (!bus.isConnected()) { + lDebug() << "DBus sessionBus non connecté"; + return; + } + lDebug() << "dbus conected"; + + QDBusInterface iface("org.freedesktop.Notifications", "/org/freedesktop/Notifications", + "org.freedesktop.Notifications", bus); + + if (!iface.isValid()) { + lDebug() << "Interface DBus invalide"; + return; + } + + QList args; + args << QStringLiteral("linphone") << quint32(0) << QString() << title << message << QStringList() << QVariantMap() + << int(5000); + + QDBusMessage reply = iface.callWithArgumentList(QDBus::AutoDetect, QStringLiteral("Notify"), args); + if (reply.type() == QDBusMessage::ErrorMessage) { + lDebug() << "Erreur Notify:" << reply.errorMessage(); + } else { + lDebug() << "Notification envoyée"; + } +} + // ----------------------------------------------------------------------------- // End Autostart // ----------------------------------------------------------------------------- @@ -559,7 +589,7 @@ void App::setSelf(QSharedPointer(me)) { }); mCoreModelConnection->makeConnectToCore(&App::lForceOidcTimeout, [this] { qDebug() << "App: force oidc timeout"; - mCoreModelConnection->invokeToModel([this] { emit CoreModel::getInstance() -> forceOidcTimeout(); }); + mCoreModelConnection->invokeToModel([this] { emit CoreModel::getInstance()->forceOidcTimeout(); }); }); mCoreModelConnection->makeConnectToModel(&CoreModel::timeoutTimerStarted, [this]() { qDebug() << "App: oidc timer started"; @@ -862,9 +892,17 @@ void App::initCore() { } if (mSettings->autoCheckForUpdateOnStart()) checkForUpdate(); setIsRestarting(false); + lDebug() << "test notif"; + auto *n = new KNotification("call"); + n->setTitle("Test"); + n->setText("Bonjour"); + n->sendEvent(); window->show(); window->requestActivate(); + lDebug() << "test notif dbus"; + sendNotification("Notif dbus", "Message dbus"); + //--------------------------------------------------------------------------------------------- lDebug() << log().arg("Creating KeyboardShortcuts"); KeyboardShortcuts::create(getMainWindow()); diff --git a/Linphone/core/App.hpp b/Linphone/core/App.hpp index 0681e9028..41d46b236 100644 --- a/Linphone/core/App.hpp +++ b/Linphone/core/App.hpp @@ -68,6 +68,8 @@ public: static Thread *getLinphoneThread(); Notifier *getNotifier() const; + void sendNotification(const QString &title, const QString &message); + EventCountNotifier *getEventCountNotifier(); int getEventCount() const;