exemple notif

This commit is contained in:
Gaelle Braud 2026-03-25 15:02:33 +01:00 committed by gaelle.braud
parent bf25a1c86e
commit c876913201
3 changed files with 57 additions and 12 deletions

View file

@ -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()

View file

@ -21,8 +21,10 @@
#include "tool/LinphoneEnums.hpp"
#include "App.hpp"
#include <KNotification>
#include <QCoreApplication>
#include <QDBusInterface>
#include <QDBusReply>
#include <QDirIterator>
#include <QFileSelector>
#include <QFontDatabase>
@ -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<QVariant> 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<App>(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());

View file

@ -68,6 +68,8 @@ public:
static Thread *getLinphoneThread();
Notifier *getNotifier() const;
void sendNotification(const QString &title, const QString &message);
EventCountNotifier *getEventCountNotifier();
int getEventCount() const;