Fix BAboutWindow lifecycle

BAboutWindow returned false in QuitRequested in order to hide instead of closing.
Not only this keeps a BLooper running for a rarely used window, but it also
prevents quitting an application in the window was not destroyed first.

 * Remove aforementioned QuitRequested method,
 * Add a static GetWindow method that returns the existing about window, if there
is one, or creates one if there is not. A boolean can be set to tell the caller
what happened,
 * Adjust all callers to use that new method, instead of managing the window themselves.
This commit is contained in:
Adrien Destugues
2013-04-30 21:50:24 +02:00
parent 3a12979db2
commit fd19c7366d
16 changed files with 135 additions and 155 deletions
+4 -3
View File
@@ -18,7 +18,6 @@
class AboutView;
class BBitmap;
class BPoint;
class BHandler;
class BAboutWindow : public BWindow {
public:
@@ -26,7 +25,6 @@ class BAboutWindow : public BWindow {
const char* signature);
virtual ~BAboutWindow();
virtual bool QuitRequested();
virtual void Show();
BPoint AboutPosition(float width, float height);
@@ -48,9 +46,12 @@ class BAboutWindow : public BWindow {
const char* Version();
void SetVersion(const char* version);
static BAboutWindow* GetWindow(const char* appName,
const char* signature, bool* needsInit = NULL);
private:
AboutView* fAboutView;
BHandler* fCaller;
static BAboutWindow* sAboutWindow;
};
#endif // B_ABOUT_WINDOW_H
+13 -15
View File
@@ -600,10 +600,6 @@ ActivityView::~ActivityView()
{
delete fOffscreen;
delete fSystemInfoHandler;
// replicant deleted, destroy the about window
if (fAboutWindow != NULL && fAboutWindow->Lock())
fAboutWindow->Quit();
}
@@ -647,8 +643,6 @@ ActivityView::_Init(const BMessage* settings)
const char* name;
for (int32 i = 0; settings->FindString("source", i, &name) == B_OK; i++)
AddDataSource(DataSource::FindSource(name), settings);
fAboutWindow = NULL;
}
@@ -1112,22 +1106,26 @@ ActivityView::MessageReceived(BMessage* message)
switch (message->what) {
case B_ABOUT_REQUESTED:
if (fAboutWindow == NULL) {
{
bool needsInit;
BAboutWindow* window = BAboutWindow::GetWindow(kAppName, kSignature,
&needsInit);
if (needsInit) {
const char* authors[] = {
"Axel Dörfler",
NULL
};
fAboutWindow = new BAboutWindow(kAppName, kSignature);
fAboutWindow->AddCopyright(2008, "Haiku, Inc.");
fAboutWindow->AddAuthors(authors);
fAboutWindow->Show();
} else if (fAboutWindow->IsHidden())
fAboutWindow->Show();
else
fAboutWindow->Activate();
window->AddCopyright(2008, "Haiku, Inc.");
window->AddAuthors(authors);
}
if (window->IsHidden())
window->Show();
window->Activate();
break;
}
case kMsgUpdateResolution:
{
-3
View File
@@ -17,7 +17,6 @@
#include "DataSource.h"
class BAboutWindow;
class BBitmap;
class BMessageRunner;
class Scale;
@@ -146,8 +145,6 @@ private:
int32 fOriginalResolution;
SystemInfoHandler* fSystemInfoHandler;
std::map<scale_type, ::Scale*> fScales;
BAboutWindow* fAboutWindow;
};
#endif // ACTIVITY_VIEW_H
+14 -16
View File
@@ -183,10 +183,6 @@ CalcView::~CalcView()
delete fKeypad;
delete fOptions;
free(fKeypadDescription);
// replicant deleted, destroy the about window
if (fAboutWindow != NULL && fAboutWindow->Lock())
fAboutWindow->Quit();
}
@@ -270,7 +266,12 @@ CalcView::MessageReceived(BMessage* message)
// (replicant) about box requested
case B_ABOUT_REQUESTED:
if (fAboutWindow == NULL) {
{
bool needsInit;
BAboutWindow* window = BAboutWindow::GetWindow(kAppName,
kSignature, &needsInit);
if (needsInit) {
// create the about window
const char* extraCopyrights[] = {
"1997, 1998 R3 Software Ltd.",
@@ -285,17 +286,16 @@ CalcView::MessageReceived(BMessage* message)
NULL
};
fAboutWindow = new BAboutWindow(kAppName, kSignature);
fAboutWindow->AddCopyright(2006, "Haiku, Inc.",
extraCopyrights);
fAboutWindow->AddAuthors(authors);
fAboutWindow->Show();
} else if (fAboutWindow->IsHidden())
fAboutWindow->Show();
else
fAboutWindow->Activate();
window->AddCopyright(2006, "Haiku, Inc.", extraCopyrights);
window->AddAuthors(authors);
}
if (window->IsHidden())
window->Show();
window->Activate();
break;
}
case MSG_UNFLASH_KEY:
{
@@ -1006,8 +1006,6 @@ CalcView::_Init(BMessage* settings)
// fetch the calc icon for compact view
_FetchAppIcon(fCalcIcon);
fAboutWindow = NULL;
}
-4
View File
@@ -31,7 +31,6 @@ static const float kMaximumWidthBasic = 400.0f;
static const float kMinimumHeightBasic = 130.0f;
static const float kMaximumHeightBasic = 400.0f;
class BAboutWindow;
class BString;
class BMenuItem;
class BMessage;
@@ -161,9 +160,6 @@ class CalcView : public BView {
// calculator options.
CalcOptions* fOptions;
// about window for replicant
BAboutWindow* fAboutWindow;
};
#endif // _CALC_VIEW_H
+12 -14
View File
@@ -139,16 +139,12 @@ NetworkStatusView::NetworkStatusView(BMessage* archive)
NetworkStatusView::~NetworkStatusView()
{
if (fAboutWindow != NULL && fAboutWindow->Lock())
fAboutWindow->Quit();
}
void
NetworkStatusView::_Init()
{
fAboutWindow = NULL;
for (int i = 0; i < kStatusCount; i++) {
fTrayIcons[i] = NULL;
fNotifyIcons[i] = NULL;
@@ -508,22 +504,24 @@ NetworkStatusView::MouseDown(BPoint point)
void
NetworkStatusView::_AboutRequested()
{
if (fAboutWindow == NULL) {
bool needsInit;
BAboutWindow* window = BAboutWindow::GetWindow(
B_TRANSLATE_SYSTEM_NAME("NetworkStatus"), kSignature, &needsInit);
if (needsInit) {
const char* authors[] = {
"Axel Dörfler",
"Hugo Santos",
NULL
};
fAboutWindow = new BAboutWindow(
B_TRANSLATE_SYSTEM_NAME("NetworkStatus"), kSignature);
fAboutWindow->AddCopyright(2007, "Haiku, Inc.");
fAboutWindow->AddAuthors(authors);
fAboutWindow->Show();
} else if (fAboutWindow->IsHidden())
fAboutWindow->Show();
else
fAboutWindow->Activate();
window->AddCopyright(2007, "Haiku, Inc.");
window->AddAuthors(authors);
}
if (window->IsHidden())
window->Show();
window->Activate();
}
@@ -17,7 +17,6 @@
#include <map>
class BAboutWindow;
class BMessageRunner;
class BNetworkInterface;
@@ -66,7 +65,6 @@ class NetworkStatusView : public BView {
std::map<BString, int32>
fInterfaceStatuses;
BAboutWindow* fAboutWindow;
bool fInDeskbar;
BBitmap* fTrayIcons[kStatusCount];
BBitmap* fNotifyIcons[kStatusCount];
+12 -17
View File
@@ -77,8 +77,6 @@ PowerStatusView::PowerStatusView(BMessage* archive)
PowerStatusView::~PowerStatusView()
{
if (fAboutWindow != NULL && fAboutWindow->Lock())
fAboutWindow->Quit();
}
@@ -98,8 +96,6 @@ PowerStatusView::_Init()
{
SetViewColor(B_TRANSPARENT_COLOR);
fAboutWindow = NULL;
fShowLabel = true;
fShowTime = false;
fShowStatusIcon = true;
@@ -514,9 +510,6 @@ PowerStatusReplicant::~PowerStatusReplicant()
fDriverInterface->Disconnect();
fDriverInterface->ReleaseReference();
if (fAboutWindow != NULL)
fAboutWindow->Quit();
_SaveSettings();
}
@@ -627,7 +620,11 @@ PowerStatusReplicant::MouseDown(BPoint point)
void
PowerStatusReplicant::_AboutRequested()
{
if (fAboutWindow == NULL) {
bool needsInit;
BAboutWindow* window = BAboutWindow::GetWindow(
B_TRANSLATE_SYSTEM_NAME("PowerStatus"), kSignature, &needsInit);
if (needsInit) {
const char* authors[] = {
"Axel Dörfler",
"Alexander von Gluck",
@@ -635,15 +632,13 @@ PowerStatusReplicant::_AboutRequested()
NULL
};
fAboutWindow = new BAboutWindow(
B_TRANSLATE_SYSTEM_NAME("PowerStatus"), kSignature);
fAboutWindow->AddCopyright(2006, "Haiku, Inc.");
fAboutWindow->AddAuthors(authors);
fAboutWindow->Show();
} else if (fAboutWindow->IsHidden())
fAboutWindow->Show();
else
fAboutWindow->Activate();
window->AddCopyright(2006, "Haiku, Inc.");
window->AddAuthors(authors);
}
if (window->IsHidden())
window->Show();
window->Activate();
}
-2
View File
@@ -15,7 +15,6 @@
#include "DriverInterface.h"
class BAboutWindow;
class BFile;
@@ -54,7 +53,6 @@ private:
protected:
PowerStatusDriverInterface* fDriverInterface;
BAboutWindow* fAboutWindow;
bool fShowLabel;
bool fShowTime;
@@ -204,10 +204,6 @@ ProcessController::~ProcessController()
delete fMessageRunner;
gPCView = NULL;
// replicant deleted, destroy the about window
if (fAboutWindow != NULL && fAboutWindow->Lock())
fAboutWindow->Quit();
}
@@ -221,7 +217,6 @@ ProcessController::Init()
memset(fCPUTimes, 0, sizeof(fCPUTimes));
memset(fPrevActive, 0, sizeof(fPrevActive));
fPrevTime = 0;
fAboutWindow = NULL;
}
@@ -438,7 +433,11 @@ ProcessController::MessageReceived(BMessage *message)
void
ProcessController::AboutRequested()
{
if (fAboutWindow == NULL) {
bool needsInit;
BAboutWindow* window = BAboutWindow::GetWindow(
B_TRANSLATE_SYSTEM_NAME("ProcessController"), kSignature, &needsInit);
if (needsInit) {
const char* extraCopyrights[] = {
"2004 beunited.org",
"1997-2001 Georges-Edouard Berenger",
@@ -450,15 +449,13 @@ ProcessController::AboutRequested()
NULL
};
fAboutWindow = new BAboutWindow(
B_TRANSLATE_SYSTEM_NAME("ProcessController"), kSignature);
fAboutWindow->AddCopyright(2007, "Haiku, Inc.", extraCopyrights);
fAboutWindow->AddAuthors(authors);
fAboutWindow->Show();
} else if (fAboutWindow->IsHidden())
fAboutWindow->Show();
else
fAboutWindow->Activate();
window->AddCopyright(2007, "Haiku, Inc.", extraCopyrights);
window->AddAuthors(authors);
}
if (window->IsHidden())
window->Show();
window->Activate();
}
@@ -26,7 +26,6 @@
#include <View.h>
class BAboutWindow;
class BMessageRunner;
class ThreadBarMenu;
@@ -60,7 +59,6 @@ class ProcessController : public BView {
private:
void Init();
BAboutWindow* fAboutWindow;
bool fTemp;
float fMemoryUsage;
float fLastBarHeight[B_MAX_CPU_COUNT];
+13 -15
View File
@@ -77,7 +77,6 @@ BrowserApp::BrowserApp()
fCookieJar(NULL),
fDownloadWindow(NULL),
fSettingsWindow(NULL),
fAboutWindow(NULL)
{
}
@@ -88,16 +87,17 @@ BrowserApp::~BrowserApp()
delete fSettings;
delete fCookies;
delete fCookieJar;
if (fAboutWindow != NULL && fAboutWindow->Lock())
fAboutWindow->Quit();
}
void
BrowserApp::AboutRequested()
{
if (fAboutWindow == NULL) {
bool needsInit;
BAboutWindow window = BAboutWindow::GetWindow(kApplicationName,
kApplicationSignature, &needsInit);
if (needsInit) {
// create the about window
const char* authors[] = {
@@ -117,16 +117,14 @@ BrowserApp::AboutRequested()
aboutText << "\nWebKit " << WebKitInfo::WebKitVersion();
aboutText << " (" << WebKitInfo::WebKitRevision() << ")";
fAboutWindow = new BAboutWindow(kApplicationName,
kApplicationSignature);
fAboutWindow->AddCopyright(2007, "Haiku, Inc.");
fAboutWindow->AddAuthors(authors);
fAboutWindow->AddExtraInfo(aboutText.String());
fAboutWindow->Show();
} else if (fAboutWindow->IsHidden())
fAboutWindow->Show();
else
fAboutWindow->Activate();
window->AddCopyright(2007, "Haiku, Inc.");
window->AddAuthors(authors);
window->AddExtraInfo(aboutText.String());
}
if (window->IsHidden())
window->Show();
window->Activate();
}
-3
View File
@@ -34,7 +34,6 @@
#include <Rect.h>
class BAboutWindow;
class BNetworkCookieJar;
class DownloadWindow;
class BrowserWindow;
@@ -79,8 +78,6 @@ private:
DownloadWindow* fDownloadWindow;
SettingsWindow* fSettingsWindow;
BAboutWindow* fAboutWindow;
};
+15 -18
View File
@@ -119,7 +119,6 @@ class WorkspacesView : public BView {
BView* fParentWhichDrawsOnChildren;
BRect fCurrentFrame;
BAboutWindow* fAboutWindow;
};
class WorkspacesWindow : public BWindow {
@@ -342,8 +341,7 @@ WorkspacesView::WorkspacesView(BRect frame, bool showDragger=true)
BView(frame, kDeskbarItemName, B_FOLLOW_ALL,
kWorkspacesViewFlag | B_FRAME_EVENTS),
fParentWhichDrawsOnChildren(NULL),
fCurrentFrame(frame),
fAboutWindow(NULL)
fCurrentFrame(frame)
{
if(showDragger) {
frame.OffsetTo(B_ORIGIN);
@@ -360,8 +358,7 @@ WorkspacesView::WorkspacesView(BMessage* archive)
:
BView(archive),
fParentWhichDrawsOnChildren(NULL),
fCurrentFrame(Frame()),
fAboutWindow(NULL)
fCurrentFrame(Frame())
{
// Just in case we are instantiated from an older archive...
SetFlags(Flags() | B_FRAME_EVENTS);
@@ -374,8 +371,6 @@ WorkspacesView::WorkspacesView(BMessage* archive)
WorkspacesView::~WorkspacesView()
{
if (fAboutWindow != NULL && fAboutWindow->Lock())
fAboutWindow->Quit();
}
@@ -405,7 +400,11 @@ WorkspacesView::Archive(BMessage* archive, bool deep) const
void
WorkspacesView::_AboutRequested()
{
if (fAboutWindow == NULL) {
bool needsInit;
BAboutWindow* window = BAboutWindow::GetWindow(
B_TRANSLATE_SYSTEM_NAME("Workspaces"), kSignature, &needsInit);
if (needsInit) {
const char* authors[] = {
"Axel Dörfler",
"Oliver \"Madison\" Kohl",
@@ -422,17 +421,15 @@ WorkspacesView::_AboutRequested()
const char* extraInfo = "Send windows behind using the Option key. "
"Move windows to front using the Control key.\n";
fAboutWindow = new BAboutWindow(
B_TRANSLATE_SYSTEM_NAME("Workspaces"), kSignature);
fAboutWindow->AddCopyright(2002, "Haiku, Inc.",
window->AddCopyright(2002, "Haiku, Inc.",
extraCopyrights);
fAboutWindow->AddAuthors(authors);
fAboutWindow->AddExtraInfo(extraInfo);
fAboutWindow->Show();
} else if (fAboutWindow->IsHidden())
fAboutWindow->Show();
else
fAboutWindow->Activate();
window->AddAuthors(authors);
window->AddExtraInfo(extraInfo);
}
if (window->IsHidden())
window->Show();
window->Activate();
}
+24 -11
View File
@@ -356,13 +356,15 @@ BAboutWindow::BAboutWindow(const char* appName, const char* signature)
B_ASYNCHRONOUS_CONTROLS | B_NOT_ZOOMABLE | B_NOT_RESIZABLE
| B_AUTO_UPDATE_SIZE_LIMITS | B_CLOSE_ON_ESCAPE)
{
sAboutWindow = this;
SetLayout(new BGroupLayout(B_VERTICAL));
const char* about = B_TRANSLATE_MARK("About");
const char* about = B_TRANSLATE_MARK("About %app%");
about = gSystemCatalog.GetString(about, "AboutWindow");
BString title(about);
title << " " << appName;
title.ReplaceFirst("%app%", appName);
SetTitle(title.String());
fAboutView = new AboutView(appName, signature);
@@ -374,6 +376,8 @@ BAboutWindow::BAboutWindow(const char* appName, const char* signature)
BAboutWindow::~BAboutWindow()
{
sAboutWindow = NULL;
fAboutView->RemoveSelf();
delete fAboutView;
fAboutView = NULL;
@@ -383,15 +387,6 @@ BAboutWindow::~BAboutWindow()
// #pragma mark - BAboutWindow virtual methods
bool
BAboutWindow::QuitRequested()
{
Hide();
return false;
}
void
BAboutWindow::Show()
{
@@ -617,3 +612,21 @@ BAboutWindow::SetIcon(BBitmap* icon)
{
fAboutView->SetIcon(icon);
}
/* static */ BAboutWindow*
BAboutWindow::GetWindow(const char* appName, const char* signature,
bool* needsInit)
{
if(needsInit != NULL)
*needsInit = (sAboutWindow == NULL);
if(sAboutWindow == NULL) {
new BAboutWindow(appName, signature);
}
return sAboutWindow;
}
/* static */ BAboutWindow*
BAboutWindow::sAboutWindow = NULL;
+16 -15
View File
@@ -36,7 +36,6 @@ private:
status_t _RestartApp(const char* signature) const;
LocaleWindow* fLocaleWindow;
BAboutWindow* fAboutWindow;
};
@@ -46,8 +45,7 @@ private:
LocalePreflet::LocalePreflet()
:
BApplication(kSignature),
fLocaleWindow(new LocaleWindow()),
fAboutWindow(NULL)
fLocaleWindow(new LocaleWindow())
{
fLocaleWindow->Show();
}
@@ -55,9 +53,6 @@ LocalePreflet::LocalePreflet()
LocalePreflet::~LocalePreflet()
{
// replicant deleted, destroy the about window
if (fAboutWindow != NULL)
fAboutWindow->Quit();
}
@@ -78,7 +73,12 @@ LocalePreflet::MessageReceived(BMessage* message)
break;
case B_ABOUT_REQUESTED:
if (fAboutWindow == NULL) {
{
bool needsInit;
BAboutWindow* window = BAboutWindow::GetWindow(kAppName,
kSignature, &needsInit);
if (needsInit) {
const char* authors[] = {
"Axel Dörfler",
"Adrien Destugues",
@@ -86,16 +86,17 @@ LocalePreflet::MessageReceived(BMessage* message)
NULL
};
fAboutWindow = new BAboutWindow(kAppName, kSignature);
fAboutWindow->AddCopyright(2005, "Haiku, Inc.");
fAboutWindow->AddAuthors(authors);
fAboutWindow->Show();
} else if (fAboutWindow->IsHidden())
fAboutWindow->Show();
else
fAboutWindow->Activate();
window = new BAboutWindow(kAppName, kSignature);
window->AddCopyright(2005, "Haiku, Inc.");
window->AddAuthors(authors);
}
if (window->IsHidden())
window->Show();
window->Activate();
break;
}
default:
BApplication::MessageReceived(message);