From eabf97d25da5af06033807c2697fd687fc48d2e7 Mon Sep 17 00:00:00 2001 From: Manuel Nickschas Date: Thu, 10 Sep 2009 21:21:46 +0200 Subject: [PATCH] Simplify code, fix potential crash --- src/qtui/qtui.cpp | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/src/qtui/qtui.cpp b/src/qtui/qtui.cpp index 7be5bd4d..3774acbe 100644 --- a/src/qtui/qtui.cpp +++ b/src/qtui/qtui.cpp @@ -109,7 +109,7 @@ const QList &QtUi::notificationBackends() { uint QtUi::invokeNotification(BufferId bufId, AbstractNotificationBackend::NotificationType type, const QString &sender, const QString &text) { static int notificationId = 0; - //notificationId++; + AbstractNotificationBackend::Notification notification(++notificationId, bufId, type, sender, text); _notifications.append(notification); foreach(AbstractNotificationBackend *backend, _notificationBackends) @@ -120,11 +120,10 @@ uint QtUi::invokeNotification(BufferId bufId, AbstractNotificationBackend::Notif void QtUi::closeNotification(uint notificationId) { QList::iterator i = _notifications.begin(); while(i != _notifications.end()) { - if((*i).notificationId == notificationId) { + if(i->notificationId == notificationId) { foreach(AbstractNotificationBackend *backend, _notificationBackends) backend->close(notificationId); i = _notifications.erase(i); - break; } else ++i; } } @@ -132,9 +131,9 @@ void QtUi::closeNotification(uint notificationId) { void QtUi::closeNotifications(BufferId bufferId) { QList::iterator i = _notifications.begin(); while(i != _notifications.end()) { - if(!bufferId.isValid() || (*i).bufferId == bufferId) { + if(!bufferId.isValid() || i->bufferId == bufferId) { foreach(AbstractNotificationBackend *backend, _notificationBackends) - backend->close((*i).notificationId); + backend->close(i->notificationId); i = _notifications.erase(i); } else ++i; } @@ -148,17 +147,16 @@ void QtUi::notificationActivated(uint notificationId) { if(notificationId != 0) { QList::iterator i = _notifications.begin(); while(i != _notifications.end()) { - if((*i).notificationId == notificationId) { - BufferId bufId = (*i).bufferId; + if(i->notificationId == notificationId) { + BufferId bufId = i->bufferId; if(bufId.isValid()) Client::bufferModel()->switchToBuffer(bufId); - foreach(AbstractNotificationBackend *backend, _notificationBackends) - backend->close(notificationId); - _notifications.erase(i); break; - } else ++i; + } + ++i; } } + closeNotification(notificationId); mainWindow()->forceActivated(); } -- 2.20.1