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> #include <View.h>
const int32 kAboutWindowClosed = 'abwc';
class AboutView; class AboutView;
class BPoint; class BPoint;
class BHandler;
class BAboutWindow : public BWindow { class BAboutWindow : public BWindow {
public: public:
BAboutWindow(const char* appName, BAboutWindow(BHandler* handler,
int32 firstCopyrightYear, const char* appName,
const char** authors = NULL,
const char* extraInfo = NULL);
BAboutWindow(const char* appName,
const char* signature); const char* signature);
virtual ~BAboutWindow(); virtual ~BAboutWindow();
+16 -5
View File
@@ -601,7 +601,9 @@ ActivityView::~ActivityView()
delete fOffscreen; delete fOffscreen;
delete fSystemInfoHandler; 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 #endif
SetViewColor(B_TRANSPARENT_COLOR); SetViewColor(B_TRANSPARENT_COLOR);
fAboutWindow = new BAboutWindow(kAppName, kSignature);
fAboutWindow->AddCopyright(2008, "Haiku, Inc.");
fLastRefresh = 0; fLastRefresh = 0;
fDrawResolution = 1; fDrawResolution = 1;
fZooming = false; fZooming = false;
@@ -648,6 +647,8 @@ ActivityView::_Init(const BMessage* settings)
const char* name; const char* name;
for (int32 i = 0; settings->FindString("source", i, &name) == B_OK; i++) for (int32 i = 0; settings->FindString("source", i, &name) == B_OK; i++)
AddDataSource(DataSource::FindSource(name), settings); AddDataSource(DataSource::FindSource(name), settings);
fAboutWindow = NULL;
} }
@@ -1111,7 +1112,17 @@ ActivityView::MessageReceived(BMessage* message)
switch (message->what) { switch (message->what) {
case B_ABOUT_REQUESTED: 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; break;
case kMsgUpdateResolution: case kMsgUpdateResolution:
+22 -12
View File
@@ -184,7 +184,9 @@ CalcView::~CalcView()
delete fOptions; delete fOptions;
free(fKeypadDescription); 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 // (replicant) about box requested
case B_ABOUT_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; break;
case MSG_UNFLASH_KEY: case MSG_UNFLASH_KEY:
@@ -971,16 +990,6 @@ CalcView::SetKeypadMode(uint8 mode)
void void
CalcView::_Init(BMessage* settings) 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 // create expression text view
fExpressionTextView = new ExpressionTextView(_ExpressionRect(), this); fExpressionTextView = new ExpressionTextView(_ExpressionRect(), this);
AddChild(fExpressionTextView); AddChild(fExpressionTextView);
@@ -991,6 +1000,7 @@ CalcView::_Init(BMessage* settings)
// fetch the calc icon for compact view // fetch the calc icon for compact view
_FetchAppIcon(fCalcIcon); _FetchAppIcon(fCalcIcon);
fAboutWindow = NULL;
} }
+1 -3
View File
@@ -50,9 +50,7 @@ class CalcView : public BView {
CalcView(BRect frame, CalcView(BRect frame,
rgb_color rgbBaseColor, rgb_color rgbBaseColor,
BMessage* settings); BMessage* settings);
CalcView(BMessage* archive); CalcView(BMessage* archive);
virtual ~CalcView(); virtual ~CalcView();
virtual void AttachedToWindow(); virtual void AttachedToWindow();
@@ -62,7 +60,7 @@ class CalcView : public BView {
virtual void MouseUp(BPoint point); virtual void MouseUp(BPoint point);
virtual void KeyDown(const char* bytes, int32 numBytes); virtual void KeyDown(const char* bytes, int32 numBytes);
virtual void MakeFocus(bool focused = true); 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); virtual void FrameResized(float width, float height);
// Archive this view. // Archive this view.
@@ -204,6 +204,10 @@ ProcessController::~ProcessController()
delete fMessageRunner; delete fMessageRunner;
gPCView = NULL; 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(fCPUTimes, 0, sizeof(fCPUTimes));
memset(fPrevActive, 0, sizeof(fPrevActive)); memset(fPrevActive, 0, sizeof(fPrevActive));
fPrevTime = 0; fPrevTime = 0;
fAboutWindow = NULL;
} }
ProcessController * ProcessController*
ProcessController::Instantiate(BMessage *data) ProcessController::Instantiate(BMessage *data)
{ {
if (!validate_instantiation(data, kClassName)) if (!validate_instantiation(data, kClassName))
@@ -421,7 +426,29 @@ ProcessController::MessageReceived(BMessage *message)
} }
case B_ABOUT_REQUESTED: 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; break;
default: 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 void
ProcessController::DefaultColors() ProcessController::DefaultColors()
{ {
@@ -25,6 +25,7 @@
#include <View.h> #include <View.h>
class BAboutWindow;
class BMessageRunner; class BMessageRunner;
class ThreadBarMenu; class ThreadBarMenu;
@@ -44,7 +45,6 @@ class ProcessController : public BView {
static ProcessController* Instantiate(BMessage* data); static ProcessController* Instantiate(BMessage* data);
virtual status_t Archive(BMessage *data, bool deep = true) const; virtual status_t Archive(BMessage *data, bool deep = true) const;
void AboutRequested();
void Update(); void Update();
void DefaultColors(); void DefaultColors();
@@ -58,6 +58,7 @@ class ProcessController : public BView {
private: private:
void Init(); void Init();
BAboutWindow* fAboutWindow;
bool fTemp; bool fTemp;
float fMemoryUsage; float fMemoryUsage;
float fLastBarHeight[B_MAX_CPU_COUNT]; float fLastBarHeight[B_MAX_CPU_COUNT];
+14 -34
View File
@@ -208,27 +208,15 @@ AboutView::AppIcon(const char* signature)
if (signature == NULL) if (signature == NULL)
return NULL; return NULL;
app_info appInfo; entry_ref ref;
if (be_roster->GetAppInfo(signature, &appInfo) != B_OK) if (be_roster->FindApp(signature, &ref) != B_OK)
return NULL; 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); BBitmap* icon = new BBitmap(BRect(0.0, 0.0, 127.0, 127.0), B_RGBA32);
if (appMime.GetIcon(icon, B_LARGE_ICON) == B_OK) if (BNodeInfo::GetTrackerIcon(&ref, 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)
return icon; return icon;
delete icon;
return NULL; return NULL;
} }
@@ -236,23 +224,11 @@ AboutView::AppIcon(const char* signature)
// #pragma mark - // #pragma mark -
BAboutWindow::BAboutWindow(const char* appName, int32 firstCopyrightYear, BAboutWindow::BAboutWindow(BHandler* handler, const char* appName, const char* signature)
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)
: BWindow(BRect(0.0, 0.0, 310.0, 140.0), appName, B_TITLED_WINDOW, : BWindow(BRect(0.0, 0.0, 310.0, 140.0), appName, B_TITLED_WINDOW,
B_ASYNCHRONOUS_CONTROLS | B_NOT_ZOOMABLE | B_NOT_RESIZABLE B_ASYNCHRONOUS_CONTROLS | B_NOT_ZOOMABLE | B_NOT_RESIZABLE
| B_AUTO_UPDATE_SIZE_LIMITS) | B_AUTO_UPDATE_SIZE_LIMITS),
fCaller(handler)
{ {
_Init(appName, signature); _Init(appName, signature);
} }
@@ -269,10 +245,14 @@ BAboutWindow::~BAboutWindow()
bool bool
BAboutWindow::QuitRequested() BAboutWindow::QuitRequested()
{ {
while (!IsHidden()) if (fCaller != NULL) {
Hide(); 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" #define B_TRANSLATION_CONTEXT "Locale Preflet"
const char* kAppName = B_TRANSLATE("Locale");
const char* kSignature = "application/x-vnd.Haiku-Locale"; const char* kSignature = "application/x-vnd.Haiku-Locale";
@@ -29,13 +30,13 @@ class LocalePreflet : public BApplication {
LocalePreflet(); LocalePreflet();
virtual ~LocalePreflet(); virtual ~LocalePreflet();
virtual void AboutRequested();
virtual void MessageReceived(BMessage* message); virtual void MessageReceived(BMessage* message);
private: private:
status_t _RestartApp(const char* signature) const; status_t _RestartApp(const char* signature) const;
LocaleWindow* fLocaleWindow; LocaleWindow* fLocaleWindow;
BAboutWindow* fAboutWindow;
}; };
@@ -44,30 +45,19 @@ private:
LocalePreflet::LocalePreflet() LocalePreflet::LocalePreflet()
: :
BApplication(kSignature) BApplication(kSignature),
fLocaleWindow(new LocaleWindow()),
fAboutWindow(NULL)
{ {
fLocaleWindow = new LocaleWindow();
fLocaleWindow->Show(); fLocaleWindow->Show();
} }
LocalePreflet::~LocalePreflet() LocalePreflet::~LocalePreflet()
{ {
} // replicant deleted, destroy the about window
if (fAboutWindow != NULL)
fAboutWindow->Quit();
void
LocalePreflet::AboutRequested()
{
const char* authors[] = {
"Axel Dörfler",
"Adrien Destugues",
"Oliver Tappe",
NULL
};
BAboutWindow about(B_TRANSLATE("Locale"), 2005, authors);
about.Show();
} }
@@ -81,7 +71,29 @@ LocalePreflet::MessageReceived(BMessage* message)
_RestartApp("application/x-vnd.Be-TSKB"); _RestartApp("application/x-vnd.Be-TSKB");
} }
break; 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: default:
BApplication::MessageReceived(message); BApplication::MessageReceived(message);
break; break;