Set the about window object to NULL on close or quit.

Pass the BHandler object that opened the about window to BAboutWindow.
When the window closes, send a kAboutWindowClosed message back to the
handler. This allows the handler to set the variable to NULL.

Implement the new about dialog constructor in all apps that use it.
Remove the old constructor. This now works reliably for all cases I
tested without crashing and does the right thing on close. The setup
and teardown is a bit more complicated than I wanted though.
Unfortunately this seems to be necessary when not using a BAlert.

Fetching the app icon does not work reliably yet. This is because for
replicants the app may not be running. I may have to pass the icon in
instead of grabbing it from the signature.
This commit is contained in:
John Scipione
2012-11-12 23:57:26 -05:00
parent 5b0cd98792
commit 3fdab58446
8 changed files with 120 additions and 96 deletions
+5 -5
View File
@@ -11,16 +11,16 @@
#include <View.h>
const int32 kAboutWindowClosed = 'abwc';
class AboutView;
class BPoint;
class BHandler;
class BAboutWindow : public BWindow {
public:
BAboutWindow(const char* appName,
int32 firstCopyrightYear,
const char** authors = NULL,
const char* extraInfo = NULL);
BAboutWindow(const char* appName,
BAboutWindow(BHandler* handler,
const char* appName,
const char* signature);
virtual ~BAboutWindow();
+16 -5
View File
@@ -601,7 +601,9 @@ ActivityView::~ActivityView()
delete fOffscreen;
delete fSystemInfoHandler;
fAboutWindow->Quit();
// replicant deleted, destroy the about window
if (fAboutWindow != NULL)
fAboutWindow->Quit();
}
@@ -618,9 +620,6 @@ ActivityView::_Init(const BMessage* settings)
#endif
SetViewColor(B_TRANSPARENT_COLOR);
fAboutWindow = new BAboutWindow(kAppName, kSignature);
fAboutWindow->AddCopyright(2008, "Haiku, Inc.");
fLastRefresh = 0;
fDrawResolution = 1;
fZooming = false;
@@ -648,6 +647,8 @@ 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;
}
@@ -1111,7 +1112,17 @@ ActivityView::MessageReceived(BMessage* message)
switch (message->what) {
case B_ABOUT_REQUESTED:
fAboutWindow->Show();
if (fAboutWindow == NULL) {
fAboutWindow = new BAboutWindow(this, kAppName, kSignature);
fAboutWindow->AddCopyright(2008, "Haiku, Inc.");
fAboutWindow->Show();
} else
fAboutWindow->Activate();
break;
case kAboutWindowClosed:
fAboutWindow = NULL;
break;
case kMsgUpdateResolution:
+22 -12
View File
@@ -184,7 +184,9 @@ CalcView::~CalcView()
delete fOptions;
free(fKeypadDescription);
fAboutWindow->Quit();
// replicant deleted, destroy the about window
if (fAboutWindow != NULL)
fAboutWindow->Quit();
}
@@ -268,7 +270,24 @@ CalcView::MessageReceived(BMessage* message)
// (replicant) about box requested
case B_ABOUT_REQUESTED:
fAboutWindow->Show();
if (fAboutWindow == NULL) {
// create the about window
const char* extraCopyrights[] = {
"1997, 1998 R3 Software Ltd.",
NULL
};
fAboutWindow = new BAboutWindow(this, kAppName, kSignature);
fAboutWindow->AddCopyright(2006, "Haiku, Inc.",
extraCopyrights);
fAboutWindow->Show();
} else
fAboutWindow->Activate();
break;
case kAboutWindowClosed:
fAboutWindow = NULL;
break;
case MSG_UNFLASH_KEY:
@@ -971,16 +990,6 @@ CalcView::SetKeypadMode(uint8 mode)
void
CalcView::_Init(BMessage* settings)
{
// create the about window
const char* extraCopyrights[] = {
"1997, 1998 R3 Software Ltd.",
NULL
};
fAboutWindow = new BAboutWindow(kAppName, kSignature);
fAboutWindow->AddCopyright(2006, "Haiku, Inc.",
extraCopyrights);
// create expression text view
fExpressionTextView = new ExpressionTextView(_ExpressionRect(), this);
AddChild(fExpressionTextView);
@@ -991,6 +1000,7 @@ CalcView::_Init(BMessage* settings)
// fetch the calc icon for compact view
_FetchAppIcon(fCalcIcon);
fAboutWindow = NULL;
}
+1 -3
View File
@@ -50,9 +50,7 @@ class CalcView : public BView {
CalcView(BRect frame,
rgb_color rgbBaseColor,
BMessage* settings);
CalcView(BMessage* archive);
virtual ~CalcView();
virtual void AttachedToWindow();
@@ -62,7 +60,7 @@ class CalcView : public BView {
virtual void MouseUp(BPoint point);
virtual void KeyDown(const char* bytes, int32 numBytes);
virtual void MakeFocus(bool focused = true);
virtual void ResizeTo(float width, float height);
virtual void ResizeTo(float width, float height);
virtual void FrameResized(float width, float height);
// Archive this view.
@@ -204,6 +204,10 @@ ProcessController::~ProcessController()
delete fMessageRunner;
gPCView = NULL;
// replicant deleted, destroy the about window
if (fAboutWindow != NULL)
fAboutWindow->Quit();
}
@@ -217,10 +221,11 @@ ProcessController::Init()
memset(fCPUTimes, 0, sizeof(fCPUTimes));
memset(fPrevActive, 0, sizeof(fPrevActive));
fPrevTime = 0;
fAboutWindow = NULL;
}
ProcessController *
ProcessController*
ProcessController::Instantiate(BMessage *data)
{
if (!validate_instantiation(data, kClassName))
@@ -421,7 +426,29 @@ ProcessController::MessageReceived(BMessage *message)
}
case B_ABOUT_REQUESTED:
AboutRequested();
if (fAboutWindow == NULL) {
const char* extraCopyrights[] = {
"1997-2001 Georges-Edouard Berenger",
NULL
};
const char* authors[] = {
"Georges-Edouard Berenger",
NULL
};
fAboutWindow = new BAboutWindow(this,
B_TRANSLATE_SYSTEM_NAME("ProcessController"), kSignature);
fAboutWindow->AddCopyright(2007, "Haiku, Inc.", extraCopyrights);
fAboutWindow->AddAuthors(authors);
fAboutWindow->Show();
} else
fAboutWindow->Activate();
break;
case kAboutWindowClosed:
fAboutWindow = NULL;
break;
default:
@@ -430,21 +457,6 @@ ProcessController::MessageReceived(BMessage *message)
}
void
ProcessController::AboutRequested()
{
const char* authors[] = {
"Georges-Edouard Berenger",
NULL
};
BAboutWindow about(B_TRANSLATE_SYSTEM_NAME("ProcessController"), 2007, authors,
"Copyright 1997-2001\n"
"Georges-Edouard Berenger.");
about.Show();
}
void
ProcessController::DefaultColors()
{
@@ -25,6 +25,7 @@
#include <View.h>
class BAboutWindow;
class BMessageRunner;
class ThreadBarMenu;
@@ -44,7 +45,6 @@ class ProcessController : public BView {
static ProcessController* Instantiate(BMessage* data);
virtual status_t Archive(BMessage *data, bool deep = true) const;
void AboutRequested();
void Update();
void DefaultColors();
@@ -58,6 +58,7 @@ class ProcessController : public BView {
private:
void Init();
BAboutWindow* fAboutWindow;
bool fTemp;
float fMemoryUsage;
float fLastBarHeight[B_MAX_CPU_COUNT];
+14 -34
View File
@@ -208,27 +208,15 @@ AboutView::AppIcon(const char* signature)
if (signature == NULL)
return NULL;
app_info appInfo;
if (be_roster->GetAppInfo(signature, &appInfo) != B_OK)
entry_ref ref;
if (be_roster->FindApp(signature, &ref) != B_OK)
return NULL;
BFile file(&appInfo.ref, B_READ_ONLY);
BAppFileInfo appMime(&file);
if (appMime.InitCheck() != B_OK)
return NULL;
// fetch the app icon
BBitmap* icon = new BBitmap(BRect(0.0, 0.0, 127.0, 127.0), B_RGBA32);
if (appMime.GetIcon(icon, B_LARGE_ICON) == B_OK)
return icon;
// couldn't find the app icon
// fetch the generic 3 boxes icon
BMimeType defaultAppMime;
defaultAppMime.SetTo(B_APP_MIME_TYPE);
if (defaultAppMime.GetIcon(icon, B_LARGE_ICON) == B_OK)
if (BNodeInfo::GetTrackerIcon(&ref, icon) == B_OK)
return icon;
delete icon;
return NULL;
}
@@ -236,23 +224,11 @@ AboutView::AppIcon(const char* signature)
// #pragma mark -
BAboutWindow::BAboutWindow(const char* appName, int32 firstCopyrightYear,
const char** authors, const char* extraInfo)
: BWindow(BRect(0.0, 0.0, 200.0, 140.0), appName, B_TITLED_WINDOW,
B_ASYNCHRONOUS_CONTROLS | B_NOT_ZOOMABLE | B_NOT_RESIZABLE
| B_AUTO_UPDATE_SIZE_LIMITS)
{
_Init(appName, NULL);
AddCopyright(firstCopyrightYear, "Haiku, Inc.", NULL);
AddAuthors(authors);
AddExtraInfo(extraInfo);
}
BAboutWindow::BAboutWindow(const char* appName, const char* signature)
BAboutWindow::BAboutWindow(BHandler* handler, const char* appName, const char* signature)
: BWindow(BRect(0.0, 0.0, 310.0, 140.0), appName, B_TITLED_WINDOW,
B_ASYNCHRONOUS_CONTROLS | B_NOT_ZOOMABLE | B_NOT_RESIZABLE
| B_AUTO_UPDATE_SIZE_LIMITS)
| B_AUTO_UPDATE_SIZE_LIMITS),
fCaller(handler)
{
_Init(appName, signature);
}
@@ -269,10 +245,14 @@ BAboutWindow::~BAboutWindow()
bool
BAboutWindow::QuitRequested()
{
while (!IsHidden())
Hide();
if (fCaller != NULL) {
status_t status;
BMessenger messenger(fCaller, NULL, &status);
if (status == B_OK && messenger.IsValid())
messenger.SendMessage(new BMessage(kAboutWindowClosed));
}
return false;
return true;
}
+31 -19
View File
@@ -21,6 +21,7 @@
#define B_TRANSLATION_CONTEXT "Locale Preflet"
const char* kAppName = B_TRANSLATE("Locale");
const char* kSignature = "application/x-vnd.Haiku-Locale";
@@ -29,13 +30,13 @@ class LocalePreflet : public BApplication {
LocalePreflet();
virtual ~LocalePreflet();
virtual void AboutRequested();
virtual void MessageReceived(BMessage* message);
private:
status_t _RestartApp(const char* signature) const;
LocaleWindow* fLocaleWindow;
BAboutWindow* fAboutWindow;
};
@@ -44,30 +45,19 @@ private:
LocalePreflet::LocalePreflet()
:
BApplication(kSignature)
BApplication(kSignature),
fLocaleWindow(new LocaleWindow()),
fAboutWindow(NULL)
{
fLocaleWindow = new LocaleWindow();
fLocaleWindow->Show();
}
LocalePreflet::~LocalePreflet()
{
}
void
LocalePreflet::AboutRequested()
{
const char* authors[] = {
"Axel Dörfler",
"Adrien Destugues",
"Oliver Tappe",
NULL
};
BAboutWindow about(B_TRANSLATE("Locale"), 2005, authors);
about.Show();
// replicant deleted, destroy the about window
if (fAboutWindow != NULL)
fAboutWindow->Quit();
}
@@ -81,7 +71,29 @@ LocalePreflet::MessageReceived(BMessage* message)
_RestartApp("application/x-vnd.Be-TSKB");
}
break;
case B_ABOUT_REQUESTED:
if (fAboutWindow == NULL) {
const char* authors[] = {
"Axel Dörfler",
"Adrien Destugues",
"Oliver Tappe",
NULL
};
fAboutWindow = new BAboutWindow(this, kAppName, kSignature);
fAboutWindow->AddCopyright(2005, "Haiku, Inc.");
fAboutWindow->AddAuthors(authors);
fAboutWindow->Show();
} else
fAboutWindow->Activate();
break;
case kAboutWindowClosed:
fAboutWindow = NULL;
break;
default:
BApplication::MessageReceived(message);
break;