diff --git a/linphone-desktop/src/components/notifier/Notifier.cpp b/linphone-desktop/src/components/notifier/Notifier.cpp index 9db372499..57d9f5a47 100644 --- a/linphone-desktop/src/components/notifier/Notifier.cpp +++ b/linphone-desktop/src/components/notifier/Notifier.cpp @@ -44,7 +44,7 @@ #define NOTIFICATION_TIMEOUT_RECEIVED_MESSAGE 10000 #define NOTIFICATION_TIMEOUT_RECEIVED_FILE_MESSAGE 10000 -#define NOTIFICATION_TIMEOUT_RECEIVED_CALL 10000 +#define NOTIFICATION_TIMEOUT_RECEIVED_CALL 30000 // Arbitrary hardcoded values. #define NOTIFICATION_SPACING 10 @@ -135,47 +135,55 @@ QObject *Notifier::createNotification (Notifier::NotificationType type) { } void Notifier::showNotification (QObject *notification, int timeout) { - if (timeout > MAX_TIMEOUT) { - timeout = MAX_TIMEOUT; - } - // Display notification. - QMetaObject::invokeMethod( - notification, NOTIFICATION_SHOW_METHOD_NAME, - Qt::DirectConnection - ); + 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); + timer->setInterval(timeout > MAX_TIMEOUT ? MAX_TIMEOUT : timeout); + timer->setSingleShot(true); + notification->setProperty("__timer", QVariant::fromValue(timer)); + + // Destroy it after timeout. + QObject::connect( + timer, &QTimer::timeout, this, [this, notification]() { + notification->property("__timer").value()->stop(); + deleteNotification(notification); + } + ); + // Called explicitly (by a click on notification for example) // or when single shot happen and if notification is visible. QObject::connect( - window, &QQuickWindow::visibleChanged, [this](const bool &visible) { + window, &QQuickWindow::visibilityChanged, [this, notification](QWindow::Visibility visibility) { + if (visibility != QWindow::Visibility::Hidden) + return; + qInfo() << "Update notifications counter, hidden notification detected."; - - if (visible) - qWarning("A notification cannot be visible twice!"); - - m_mutex.lock(); - - m_n_instances--; - - if (m_n_instances == 0) - m_offset = 0; - - m_mutex.unlock(); + notification->property("__timer").value()->stop(); + deleteNotification(notification); } ); - // Destroy it after timeout. - QTimer::singleShot( - timeout, this, [notification]() { - delete notification; - } - ); + timer->start(); +} + +// ----------------------------------------------------------------------------- + +void Notifier::deleteNotification (QObject *notification) { + m_mutex.lock(); + + m_n_instances--; + + if (m_n_instances == 0) + m_offset = 0; + + m_mutex.unlock(); + + notification->deleteLater(); } // ----------------------------------------------------------------------------- diff --git a/linphone-desktop/src/components/notifier/Notifier.hpp b/linphone-desktop/src/components/notifier/Notifier.hpp index 31f966049..1fc3ef546 100644 --- a/linphone-desktop/src/components/notifier/Notifier.hpp +++ b/linphone-desktop/src/components/notifier/Notifier.hpp @@ -52,8 +52,8 @@ public: private: QObject *createNotification (NotificationType type); - void handleNotificationHidden (); 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 223ab74c7..c5bf62425 100644 --- a/linphone-desktop/ui/modules/Linphone/Notifications/Notification.qml +++ b/linphone-desktop/ui/modules/Linphone/Notifications/Notification.qml @@ -24,6 +24,16 @@ DesktopPopup { // --------------------------------------------------------------------------- + function _close (cb) { + window.visibility = Window.Hidden + + if (cb) { + cb() + } + } + + // --------------------------------------------------------------------------- + flags: Qt.Popup Component.onCompleted: { diff --git a/linphone-desktop/ui/modules/Linphone/Notifications/NotificationReceivedCall.qml b/linphone-desktop/ui/modules/Linphone/Notifications/NotificationReceivedCall.qml index 61c8bbb5b..b97e59c6a 100644 --- a/linphone-desktop/ui/modules/Linphone/Notifications/NotificationReceivedCall.qml +++ b/linphone-desktop/ui/modules/Linphone/Notifications/NotificationReceivedCall.qml @@ -18,13 +18,6 @@ Notification { // --------------------------------------------------------------------------- - function _close (cb) { - notification.window.setVisible(false) - cb() - } - - // --------------------------------------------------------------------------- - Rectangle { color: NotificationReceivedCallStyle.color height: NotificationReceivedCallStyle.height diff --git a/linphone-desktop/ui/modules/Linphone/Notifications/NotificationReceivedFileMessage.qml b/linphone-desktop/ui/modules/Linphone/Notifications/NotificationReceivedFileMessage.qml index 5213f15f8..54a9b7cf4 100644 --- a/linphone-desktop/ui/modules/Linphone/Notifications/NotificationReceivedFileMessage.qml +++ b/linphone-desktop/ui/modules/Linphone/Notifications/NotificationReceivedFileMessage.qml @@ -70,10 +70,9 @@ Notification { cursorShape: containsMouse ? Qt.PointingHandCursor : Qt.ArrowCursor hoverEnabled: true - onClicked: { - notification.window.setVisible(false) + onClicked: notification._close(function () { Qt.openUrlExternally('file://' + Utils.dirname(notification._fileUri)) - } + }) } } } diff --git a/linphone-desktop/ui/modules/Linphone/Notifications/NotificationReceivedMessage.qml b/linphone-desktop/ui/modules/Linphone/Notifications/NotificationReceivedMessage.qml index b489cf28a..66e3fee72 100644 --- a/linphone-desktop/ui/modules/Linphone/Notifications/NotificationReceivedMessage.qml +++ b/linphone-desktop/ui/modules/Linphone/Notifications/NotificationReceivedMessage.qml @@ -89,12 +89,11 @@ Notification { cursorShape: containsMouse ? Qt.PointingHandCursor : Qt.ArrowCursor hoverEnabled: true - onClicked: { - notification.window.setVisible(false) + onClicked: notification._close(function () { notification.notificationData.window.setView('Conversation', { sipAddress: notification._sipAddress }) - } + }) } } }