From a8a83855b0627f6a2d588885764803ed32ba1313 Mon Sep 17 00:00:00 2001 From: Ryan Leavengood Date: Mon, 11 Jun 2007 00:14:32 +0000 Subject: [PATCH] Initial implementation of the common BAboutWindow class. Of course I just realized that calling it a window may not be strictly correct since it isn't a decendent of BWindow, but just uses a BAlert. Oh well, it can be changed if need be. I'm also checking in the first use of it, in ShowImage. Since ShowImage can still be compiled for R5 I've added a #ifdef around the new BAboutWindow related code. I'm open for suggestions for the interface for this class, well mostly the constructor. I'm not a big fan of having to specify the number of authors. For now I'm making the header private, but I don't think it would be a big deal to expose it publically. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@21389 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- headers/private/interface/AboutWindow.h | 28 +++++++++++ src/apps/showimage/Jamfile | 2 +- src/apps/showimage/ShowImageApp.cpp | 14 ++++++ src/kits/interface/AboutWindow.cpp | 64 +++++++++++++++++++++++++ src/kits/interface/Jamfile | 1 + 5 files changed, 108 insertions(+), 1 deletion(-) create mode 100644 headers/private/interface/AboutWindow.h create mode 100644 src/kits/interface/AboutWindow.cpp diff --git a/headers/private/interface/AboutWindow.h b/headers/private/interface/AboutWindow.h new file mode 100644 index 0000000000..7b731fcca8 --- /dev/null +++ b/headers/private/interface/AboutWindow.h @@ -0,0 +1,28 @@ +/* + * Copyright 2007 Haiku, Inc. + * Distributed under the terms of the MIT License. + * + * Authors: + * Ryan Leavengood, leavengood@gmail.com + */ +#ifndef B_ABOUT_WINDOW_H +#define B_ABOUT_WINDOW_H + + +#include + + +class BAboutWindow { + public: + BAboutWindow(char *appName, int32 firstCopyrightYear, + int32 numAuthors, const char **authors, char *extraInfo = NULL); + virtual ~BAboutWindow(); + + void Show(); + + private: + BString* fAppName; + BString* fText; +}; + +#endif // B_ABOUT_WINDOW_H diff --git a/src/apps/showimage/Jamfile b/src/apps/showimage/Jamfile index dbcd86020e..87d24a0219 100644 --- a/src/apps/showimage/Jamfile +++ b/src/apps/showimage/Jamfile @@ -1,6 +1,6 @@ SubDir HAIKU_TOP src apps showimage ; -UsePrivateHeaders tracker ; +UsePrivateHeaders tracker interface ; SetSubDirSupportedPlatformsBeOSCompatible ; diff --git a/src/apps/showimage/ShowImageApp.cpp b/src/apps/showimage/ShowImageApp.cpp index cb7cf539e1..f924541103 100644 --- a/src/apps/showimage/ShowImageApp.cpp +++ b/src/apps/showimage/ShowImageApp.cpp @@ -14,6 +14,9 @@ #include "ShowImageConstants.h" #include "ShowImageWindow.h" +#ifdef HAIKU_TARGET_PLATFORM_HAIKU +#include +#endif #include #include #include @@ -44,9 +47,20 @@ ShowImageApp::~ShowImageApp() void ShowImageApp::AboutRequested() { +#ifdef HAIKU_TARGET_PLATFORM_HAIKU + const char *authors[] = { + "Fernando F. Oliveira", + "Michael Wilber", + "Michael Pfeiffer", + "Ryan Leavengood" + }; + BAboutWindow about("ShowImage", 2003, 4, authors); + about.Show(); +#else BAlert* alert = new BAlert("About ShowImage", "Haiku ShowImage\n\nby Fernando F. Oliveira, Michael Wilber, Michael Pfeiffer and Ryan Leavengood", "OK"); alert->Go(); +#endif } diff --git a/src/kits/interface/AboutWindow.cpp b/src/kits/interface/AboutWindow.cpp new file mode 100644 index 0000000000..3a0ff59358 --- /dev/null +++ b/src/kits/interface/AboutWindow.cpp @@ -0,0 +1,64 @@ +/* + * Copyright 2007 Haiku, Inc. + * Distributed under the terms of the MIT License. + * + * Authors: + * Ryan Leavengood, leavengood@gmail.com + */ + +#include +#include +#include +#include +#include + +#include + + +BAboutWindow::BAboutWindow(char *appName, int32 firstCopyrightYear, + int32 numAuthors, const char **authors, char *extraInfo) +{ + fAppName = new BString(appName); + fText = new BString(); + + // Get current year + time_t tp; + time(&tp); + char currentYear[5]; + strftime(currentYear, 5, "%Y", localtime(&tp)); + + // Build the text to display + BString text(appName); + text << "\n\nCopyright " B_UTF8_COPYRIGHT " "; + text << firstCopyrightYear << "-" << currentYear << " Haiku, Inc.\n\n"; + text << "Written by:\n"; + for (int32 i = 0; i < numAuthors; i++) { + text << " " << authors[i] << "\n"; + } + if (extraInfo != NULL) { + text << "\n" << extraInfo << "\n"; + } + fText->Adopt(text); +} + + +BAboutWindow::~BAboutWindow() +{ + delete fText; +} + + +void +BAboutWindow::Show() +{ + BAlert *alert = new BAlert("About...", fText->String(), "Close"); + BTextView *view = alert->TextView(); + BFont font; + view->SetStylable(true); + view->GetFont(&font); + font.SetFace(B_BOLD_FACE); + font.SetSize(font.Size() * 1.7); + view->SetFontAndColor(0, fAppName->Length(), &font); + alert->Go(); +} + diff --git a/src/kits/interface/Jamfile b/src/kits/interface/Jamfile index abdfbd6c2f..cfc948f434 100644 --- a/src/kits/interface/Jamfile +++ b/src/kits/interface/Jamfile @@ -37,6 +37,7 @@ SEARCH_SOURCE += [ FDirName $(SUBDIR) textview_support ] ; SEARCH_SOURCE += [ FDirName $(SUBDIR) layouter ] ; MergeObject interface_kit.o : + AboutWindow.cpp AbstractLayoutItem.cpp Alert.cpp Alignment.cpp