summaryrefslogtreecommitdiff
path: root/libsowatch/watchserver.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'libsowatch/watchserver.cpp')
-rw-r--r--libsowatch/watchserver.cpp40
1 files changed, 40 insertions, 0 deletions
diff --git a/libsowatch/watchserver.cpp b/libsowatch/watchserver.cpp
index 2cadc98..35d2429 100644
--- a/libsowatch/watchserver.cpp
+++ b/libsowatch/watchserver.cpp
@@ -245,6 +245,7 @@ void WatchServer::postNotification(Notification *notification)
connect(notification, SIGNAL(changed()), SLOT(handleNotificationChanged()));
connect(notification, SIGNAL(dismissed()), SLOT(handleNotificationDismissed()));
+ connect(notification, SIGNAL(destroyed()), SLOT(handleNotificationDestroyed()));
qDebug() << "notification received" << notification->title() << "(" << notification->count() << ")";
@@ -360,5 +361,44 @@ void WatchServer::handleNotificationDismissed()
_weather = 0;
}
}
+
+ // No longer interested in this notification
+ disconnect(n, 0, this, 0);
+ }
+}
+
+void WatchServer::handleNotificationDestroyed()
+{
+ QObject *obj = sender();
+ if (obj) {
+ Notification* n = static_cast<Notification*>(obj);
+ // Cannot call any methods of n; it is a dangling pointer now.
+ if (_notificationCounts.contains(n)) {
+ qWarning() << "Notification destroyed without being dismissed!";
+ _notificationCounts.remove(n);
+
+ for (int i = 0; i < Notification::TypeCount; i++) {
+ Notification::Type type = static_cast<Notification::Type>(i);
+ if (_notifications[type].contains(n)) {
+ _notifications[type].removeAll(n);
+ _watch->updateNotificationCount(type, getNotificationCount(type));
+
+ if (type == Notification::WeatherNotification) {
+ WeatherNotification* w = static_cast<WeatherNotification*>(n);
+ if (_weather == w) {
+ _weather = 0;
+ }
+ }
+ }
+ }
+
+ if (!_pendingNotifications.isEmpty() && _pendingNotifications.head() == n) {
+ qDebug() << "removing top notification";
+ _pendingNotifications.removeAll(n);
+ nextNotification();
+ } else {
+ _pendingNotifications.removeAll(n);
+ }
+ }
}
}