Commit 2ef80f31 authored by Ronan Abhamon's avatar Ronan Abhamon

feat(src/components/notifier/Notifier): use custom signal to close notification

parent 353eac81
...@@ -140,11 +140,7 @@ void Notifier::showNotification (QObject *notification, int timeout) { ...@@ -140,11 +140,7 @@ void Notifier::showNotification (QObject *notification, int timeout) {
// Display notification. // Display notification.
QMetaObject::invokeMethod(notification, NOTIFICATION_SHOW_METHOD_NAME, Qt::DirectConnection); QMetaObject::invokeMethod(notification, NOTIFICATION_SHOW_METHOD_NAME, Qt::DirectConnection);
QQuickWindow *window = notification->findChild<QQuickWindow *>(); QTimer *timer = new QTimer(notification);
if (!window)
qFatal("Cannot found a `QQuickWindow` instance in `notification`.");
QTimer *timer = new QTimer(window);
timer->setInterval(timeout > MAX_TIMEOUT ? MAX_TIMEOUT : timeout); timer->setInterval(timeout > MAX_TIMEOUT ? MAX_TIMEOUT : timeout);
timer->setSingleShot(true); timer->setSingleShot(true);
notification->setProperty(NOTIFICATION_PROPERTY_TIMER, QVariant::fromValue(timer)); notification->setProperty(NOTIFICATION_PROPERTY_TIMER, QVariant::fromValue(timer));
...@@ -152,30 +148,24 @@ void Notifier::showNotification (QObject *notification, int timeout) { ...@@ -152,30 +148,24 @@ void Notifier::showNotification (QObject *notification, int timeout) {
// Destroy it after timeout. // Destroy it after timeout.
QObject::connect( QObject::connect(
timer, &QTimer::timeout, this, [this, notification]() { timer, &QTimer::timeout, this, [this, notification]() {
notification->property(NOTIFICATION_PROPERTY_TIMER).value<QTimer *>()->stop(); deleteNotification(QVariant::fromValue(notification));
deleteNotification(notification);
} }
); );
// Called explicitly (by a click on notification for example) // Called explicitly (by a click on notification for example)
// or when single shot happen and if notification is visible. // or when single shot happen and if notification is visible.
QObject::connect( QObject::connect(notification, SIGNAL(deleteNotification(QVariant)), this, SLOT(deleteNotification(QVariant)));
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<QTimer *>()->stop();
deleteNotification(notification);
}
);
timer->start(); timer->start();
} }
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
void Notifier::deleteNotification (QObject *notification) { void Notifier::deleteNotification (QVariant notification) {
QObject *instance = notification.value<QObject *>();
instance->property(NOTIFICATION_PROPERTY_TIMER).value<QTimer *>()->stop();
m_mutex.lock(); m_mutex.lock();
m_n_instances--; m_n_instances--;
...@@ -185,7 +175,7 @@ void Notifier::deleteNotification (QObject *notification) { ...@@ -185,7 +175,7 @@ void Notifier::deleteNotification (QObject *notification) {
m_mutex.unlock(); m_mutex.unlock();
notification->deleteLater(); instance->deleteLater();
} }
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
......
...@@ -50,10 +50,12 @@ public: ...@@ -50,10 +50,12 @@ public:
void notifyReceivedFileMessage (const std::shared_ptr<linphone::ChatMessage> &message); void notifyReceivedFileMessage (const std::shared_ptr<linphone::ChatMessage> &message);
void notifyReceivedCall (const std::shared_ptr<linphone::Call> &call); void notifyReceivedCall (const std::shared_ptr<linphone::Call> &call);
public slots:
void deleteNotification (QVariant notification);
private: private:
QObject *createNotification (NotificationType type); QObject *createNotification (NotificationType type);
void showNotification (QObject *notification, int timeout); void showNotification (QObject *notification, int timeout);
void deleteNotification (QObject *notification);
QQmlComponent *m_components[MaxNbTypes]; QQmlComponent *m_components[MaxNbTypes];
......
...@@ -24,12 +24,14 @@ DesktopPopup { ...@@ -24,12 +24,14 @@ DesktopPopup {
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
function _close (cb) { signal deleteNotification (var notification)
window.visibility = Window.Hidden
function _close (cb) {
if (cb) { if (cb) {
cb() cb()
} }
deleteNotification(notification)
} }
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment