From f0564ad9d210cc68bfb1bfc6e56b86fa941ad830 Mon Sep 17 00:00:00 2001 From: "Javier S. Pedro" Date: Sat, 11 Aug 2012 01:10:25 +0200 Subject: more fixes --- libsowatch/watchserver.cpp | 40 ++++++++++++++++++++++++++++++++++++++++ libsowatch/watchserver.h | 1 + 2 files changed, 41 insertions(+) (limited to 'libsowatch') 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(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(i); + if (_notifications[type].contains(n)) { + _notifications[type].removeAll(n); + _watch->updateNotificationCount(type, getNotificationCount(type)); + + if (type == Notification::WeatherNotification) { + WeatherNotification* w = static_cast(n); + if (_weather == w) { + _weather = 0; + } + } + } + } + + if (!_pendingNotifications.isEmpty() && _pendingNotifications.head() == n) { + qDebug() << "removing top notification"; + _pendingNotifications.removeAll(n); + nextNotification(); + } else { + _pendingNotifications.removeAll(n); + } + } } } diff --git a/libsowatch/watchserver.h b/libsowatch/watchserver.h index c1e6ef0..edb4e1a 100644 --- a/libsowatch/watchserver.h +++ b/libsowatch/watchserver.h @@ -104,6 +104,7 @@ private slots: void handleNotificationChanged(); void handleNotificationDismissed(); + void handleNotificationDestroyed(); }; } -- cgit v1.2.3