From 3733cb7e3c0932ee281fce64c153c7c1fc0f18f9 Mon Sep 17 00:00:00 2001 From: "Javier S. Pedro" Date: Tue, 8 Nov 2011 23:26:14 +0100 Subject: fix display of mail notifications when there are already unread mails --- libsowatch/watchserver.cpp | 25 ++++++++++++++++++++----- libsowatch/watchserver.h | 2 ++ 2 files changed, 22 insertions(+), 5 deletions(-) (limited to 'libsowatch') diff --git a/libsowatch/watchserver.cpp b/libsowatch/watchserver.cpp index 4675809..9d7859d 100644 --- a/libsowatch/watchserver.cpp +++ b/libsowatch/watchserver.cpp @@ -195,6 +195,7 @@ void WatchServer::postNotification(Notification *notification) { const Notification::Type type = notification->type(); _notifications[type].append(notification); + _notificationCounts[notification] = notification->count(); connect(notification, SIGNAL(changed()), SLOT(notificationChanged())); connect(notification, SIGNAL(dismissed()), SLOT(notificationDismissed())); @@ -247,15 +248,13 @@ void WatchServer::notificationChanged() if (obj) { Notification* n = static_cast(obj); const Notification::Type type = n->type(); + const uint lastCount = _notificationCounts[n]; + _notificationCounts[n] = n->count(); qDebug() << "notification changed" << n->title() << "(" << n->count() << ")"; _watch->updateNotificationCount(type, getNotificationCount(type)); - if (!_pendingNotifications.isEmpty() && _pendingNotifications.head() == n) { - // This is the notification that is being currently signaled on the watch - // Therefore, show it again - nextNotification(); - } + if (type == Notification::WeatherNotification) { WeatherNotification* w = static_cast(n); if (!_weather || _weather->dateTime() < w->dateTime()) { @@ -267,6 +266,21 @@ void WatchServer::notificationChanged() // Therefore, update the displayed information _watch->updateWeather(w); } + return; // Do not display it the usual way + } + + if (!_pendingNotifications.isEmpty() && _pendingNotifications.head() == n) { + // This is the notification that is being currently signaled on the watch + // Therefore, show it again no matter what. + nextNotification(); + } else if (n->count() > lastCount) { + // This notification now contains an additional "item"; redisplay it. + if (_pendingNotifications.isEmpty()) { + _pendingNotifications.enqueue(n); + nextNotification(); + } else { + _pendingNotifications.enqueue(n); + } } } } @@ -278,6 +292,7 @@ void WatchServer::notificationDismissed() Notification* n = static_cast(obj); const Notification::Type type = n->type(); _notifications[type].removeOne(n); + _notificationCounts.remove(n); qDebug() << "notification dismissed" << n->title() << "(" << n->count() << ")"; diff --git a/libsowatch/watchserver.h b/libsowatch/watchserver.h index 53c1a70..f86d224 100644 --- a/libsowatch/watchserver.h +++ b/libsowatch/watchserver.h @@ -64,6 +64,8 @@ private: QList _notifications[Notification::TypeCount]; /** A list of notifications that are yet to be shown to the user. */ QQueue _pendingNotifications; + /** Stores the count of notifications hidden between each notification object. */ + QMap _notificationCounts; /** We store a currently live weather forecast. */ WeatherNotification* _weather; -- cgit v1.2.3