From cbdd108a09ab47c523a6debd679eddbe35d1b15c Mon Sep 17 00:00:00 2001 From: Alex Wilson Date: Sat, 14 Jan 2012 21:12:35 +0000 Subject: [PATCH] In NotificationWindow, delete AppGroupViews when closed. This is preferable to having them kick around for as long as the server is running. They don't yet close when all of the notifications for the view time out, that's coming next. --- src/servers/notification/AppGroupView.cpp | 21 +++++++-------- src/servers/notification/AppGroupView.h | 2 ++ .../notification/NotificationWindow.cpp | 27 ++++++++++++++++--- src/servers/notification/NotificationWindow.h | 3 +++ 4 files changed, 38 insertions(+), 15 deletions(-) diff --git a/src/servers/notification/AppGroupView.cpp b/src/servers/notification/AppGroupView.cpp index 5779b59223..5029808350 100644 --- a/src/servers/notification/AppGroupView.cpp +++ b/src/servers/notification/AppGroupView.cpp @@ -156,10 +156,7 @@ AppGroupView::Draw(BRect updateRect) void AppGroupView::MouseDown(BPoint point) { - bool changed = false; if (fCloseRect.Contains(point)) { - changed = true; - int32 children = fInfo.size(); for (int32 i = 0; i < children; i++) { GetLayout()->RemoveView(fInfo[i]); @@ -169,7 +166,7 @@ AppGroupView::MouseDown(BPoint point) fInfo.clear(); // Remove ourselves from the parent view - BMessage message(kRemoveView); + BMessage message(kRemoveGroupView); message.AddPointer("view", this); fParent->PostMessage(&message); } @@ -188,17 +185,10 @@ AppGroupView::MouseDown(BPoint point) fInfo[i]->Show(); } } - changed = true; + Invalidate(); // Need to redraw the collapse indicator and title - - BMessage message(kRemoveView); - // Do not actually remive anything, but update size - fParent->PostMessage(&message); } - if (changed) { - _ResizeViews(); - } } @@ -266,6 +256,13 @@ AppGroupView::AddInfo(NotificationView* view) } +const BString& +AppGroupView::Group() const +{ + return fLabel; +} + + void AppGroupView::_ResizeViews() { diff --git a/src/servers/notification/AppGroupView.h b/src/servers/notification/AppGroupView.h index 551bc4fa14..deb9d09c87 100644 --- a/src/servers/notification/AppGroupView.h +++ b/src/servers/notification/AppGroupView.h @@ -32,6 +32,8 @@ public: void AddInfo(NotificationView* view); + const BString& Group() const; + private: void _ResizeViews(); diff --git a/src/servers/notification/NotificationWindow.cpp b/src/servers/notification/NotificationWindow.cpp index 690ef934a6..e37e735d63 100644 --- a/src/servers/notification/NotificationWindow.cpp +++ b/src/servers/notification/NotificationWindow.cpp @@ -10,8 +10,6 @@ * Mikael Eiman, mikael@eiman.tv * Pier Luigi Fiorini, pierluigi.fiorini@gmail.com */ - - #include "NotificationWindow.h" #include @@ -21,7 +19,6 @@ #include #include #include -#include #include #include #include @@ -31,6 +28,7 @@ #include "AppGroupView.h" #include "AppUsage.h" + #undef B_TRANSLATE_CONTEXT #define B_TRANSLATE_CONTEXT "NotificationWindow" @@ -216,6 +214,29 @@ NotificationWindow::MessageReceived(BMessage* message) _ResizeAll(); break; } + case kRemoveGroupView: + { + AppGroupView* view = NULL; + if (message->FindPointer("view", (void**)&view) != B_OK) + return; + + // It's possible that between sending this message, and us receiving + // it, the view has become used again, in which case we shouldn't + // delete it. + if (view->HasChildren()) + return; + + // this shouldn't happen + if (fAppViews.erase(view->Group()) < 1) + break; + + if (GetLayout()->RemoveView(view)) + delete view; + + if (fAppViews.size() == 0) + Hide(); + break; + } default: BWindow::MessageReceived(message); } diff --git a/src/servers/notification/NotificationWindow.h b/src/servers/notification/NotificationWindow.h index 41fc457216..b55adf85cc 100644 --- a/src/servers/notification/NotificationWindow.h +++ b/src/servers/notification/NotificationWindow.h @@ -37,6 +37,9 @@ extern const float kCloseSize; extern const float kExpandSize; extern const float kPenSize; +const uint32 kRemoveGroupView = 'RGVi'; + + class NotificationWindow : public BWindow { public: NotificationWindow();