diff --git a/linphone-desktop/src/components/notifier/Notifier.cpp b/linphone-desktop/src/components/notifier/Notifier.cpp index 9c0f9d9ba..c8bac5a3a 100644 --- a/linphone-desktop/src/components/notifier/Notifier.cpp +++ b/linphone-desktop/src/components/notifier/Notifier.cpp @@ -140,11 +140,7 @@ void Notifier::showNotification (QObject *notification, int timeout) { // Display notification. QMetaObject::invokeMethod(notification, NOTIFICATION_SHOW_METHOD_NAME, Qt::DirectConnection); - QQuickWindow *window = notification->findChild(); - if (!window) - qFatal("Cannot found a `QQuickWindow` instance in `notification`."); - - QTimer *timer = new QTimer(window); + QTimer *timer = new QTimer(notification); timer->setInterval(timeout > MAX_TIMEOUT ? MAX_TIMEOUT : timeout); timer->setSingleShot(true); notification->setProperty(NOTIFICATION_PROPERTY_TIMER, QVariant::fromValue(timer)); @@ -152,30 +148,24 @@ void Notifier::showNotification (QObject *notification, int timeout) { // Destroy it after timeout. QObject::connect( timer, &QTimer::timeout, this, [this, notification]() { - notification->property(NOTIFICATION_PROPERTY_TIMER).value()->stop(); - deleteNotification(notification); + deleteNotification(QVariant::fromValue(notification)); } ); // Called explicitly (by a click on notification for example) // or when single shot happen and if notification is visible. - QObject::connect( - window, &QQuickWindow::visibilityChanged, [this, notification](QWindow::Visibility visibility) { - if (visibility != QWindow::Visibility::Hidden) - return; - - qInfo() << "Update notifications counter, hidden notification detected."; - notification->property(NOTIFICATION_PROPERTY_TIMER).value()->stop(); - deleteNotification(notification); - } - ); + QObject::connect(notification, SIGNAL(deleteNotification(QVariant)), this, SLOT(deleteNotification(QVariant))); timer->start(); } // ----------------------------------------------------------------------------- -void Notifier::deleteNotification (QObject *notification) { +void Notifier::deleteNotification (QVariant notification) { + QObject *instance = notification.value(); + + instance->property(NOTIFICATION_PROPERTY_TIMER).value()->stop(); + m_mutex.lock(); m_n_instances--; @@ -185,7 +175,7 @@ void Notifier::deleteNotification (QObject *notification) { m_mutex.unlock(); - notification->deleteLater(); + instance->deleteLater(); } // ----------------------------------------------------------------------------- diff --git a/linphone-desktop/src/components/notifier/Notifier.hpp b/linphone-desktop/src/components/notifier/Notifier.hpp index 1fc3ef546..55f7ac704 100644 --- a/linphone-desktop/src/components/notifier/Notifier.hpp +++ b/linphone-desktop/src/components/notifier/Notifier.hpp @@ -50,10 +50,12 @@ public: void notifyReceivedFileMessage (const std::shared_ptr &message); void notifyReceivedCall (const std::shared_ptr &call); +public slots: + void deleteNotification (QVariant notification); + private: QObject *createNotification (NotificationType type); void showNotification (QObject *notification, int timeout); - void deleteNotification (QObject *notification); QQmlComponent *m_components[MaxNbTypes]; diff --git a/linphone-desktop/ui/modules/Linphone/Notifications/Notification.qml b/linphone-desktop/ui/modules/Linphone/Notifications/Notification.qml index c5bf62425..cdd303a0c 100644 --- a/linphone-desktop/ui/modules/Linphone/Notifications/Notification.qml +++ b/linphone-desktop/ui/modules/Linphone/Notifications/Notification.qml @@ -24,12 +24,14 @@ DesktopPopup { // --------------------------------------------------------------------------- - function _close (cb) { - window.visibility = Window.Hidden + signal deleteNotification (var notification) + function _close (cb) { if (cb) { cb() } + + deleteNotification(notification) } // ---------------------------------------------------------------------------