xref: /haiku/src/apps/aboutsystem/AboutSystem.cpp (revision d9cebac2b77547b7064f22497514eecd2d047160)
1 /*
2  * Copyright (c) 2005-2007, Haiku, Inc.
3  * Distributed under the terms of the MIT license.
4  *
5  * Author:
6  *		DarkWyrm <bpmagic@columbus.rr.com>
7  */
8 
9 
10 #include <AppFileInfo.h>
11 #include <Application.h>
12 #include <Bitmap.h>
13 #include <File.h>
14 #include <FindDirectory.h>
15 #include <Font.h>
16 #include <MessageRunner.h>
17 #include <Messenger.h>
18 #include <OS.h>
19 #include <Path.h>
20 #include <Resources.h>
21 #include <Screen.h>
22 #include <ScrollView.h>
23 #include <String.h>
24 #include <TextView.h>
25 #include <TranslationUtils.h>
26 #include <StringView.h>
27 #include <View.h>
28 #include <Window.h>
29 
30 #include <cpu_type.h>
31 
32 #include <stdio.h>
33 #include <time.h>
34 #include <sys/utsname.h>
35 
36 
37 #define SCROLL_CREDITS_VIEW 'mviv'
38 
39 
40 static const char *UptimeToString(char string[], size_t size);
41 static const char *MemUsageToString(char string[], size_t size);
42 
43 
44 class AboutApp : public BApplication {
45 	public:
46 		AboutApp(void);
47 };
48 
49 class AboutWindow : public BWindow {
50 	public:
51 				AboutWindow(void);
52 		bool	QuitRequested(void);
53 };
54 
55 class AboutView : public BView {
56 	public:
57 				AboutView(const BRect &r);
58 				~AboutView(void);
59 
60 		virtual void AttachedToWindow();
61 		virtual void Pulse();
62 
63 		virtual void FrameResized(float width, float height);
64 		virtual void Draw(BRect update);
65 		virtual void MessageReceived(BMessage *msg);
66 		virtual void MouseDown(BPoint pt);
67 
68 	private:
69 		BStringView		*fMemView;
70 		BStringView		*fUptimeView;
71 		BView			*fInfoView;
72 		BTextView		*fCreditsView;
73 
74 		BBitmap			*fLogo;
75 
76 		BPoint			fDrawPoint;
77 
78 		bigtime_t		fLastActionTime;
79 		BMessageRunner	*fScrollRunner;
80 };
81 
82 
83 //	#pragma mark -
84 
85 
86 AboutApp::AboutApp(void)
87 	: BApplication("application/x-vnd.Haiku-About")
88 {
89 	AboutWindow *window = new AboutWindow();
90 	window->Show();
91 }
92 
93 
94 //	#pragma mark -
95 
96 
97 AboutWindow::AboutWindow()
98 	: BWindow(BRect(0, 0, 500, 300), "About This System", B_TITLED_WINDOW,
99 			B_NOT_RESIZABLE | B_NOT_ZOOMABLE)
100 {
101 	AddChild(new AboutView(Bounds()));
102 
103 	MoveTo((BScreen().Frame().Width() - Bounds().Width()) / 2,
104 		(BScreen().Frame().Height() - Bounds().Height()) / 2 );
105 }
106 
107 
108 bool
109 AboutWindow::QuitRequested()
110 {
111 	be_app->PostMessage(B_QUIT_REQUESTED);
112 	return true;
113 }
114 
115 
116 AboutView::AboutView(const BRect &rect)
117 	: BView(rect, "aboutview", B_FOLLOW_ALL, B_WILL_DRAW | B_PULSE_NEEDED),
118 	fLastActionTime(system_time()),
119 	fScrollRunner(NULL)
120 {
121 	fLogo = BTranslationUtils::GetBitmap('PNG ', "haikulogo.png");
122 	if (fLogo) {
123 		fDrawPoint.x = (225-fLogo->Bounds().Width()) / 2;
124 		fDrawPoint.y = 0;
125 	}
126 
127 	// Begin Construction of System Information controls
128 
129 	font_height height;
130 	float labelHeight, textHeight;
131 
132 	system_info systemInfo;
133 	get_system_info(&systemInfo);
134 
135 	be_plain_font->GetHeight(&height);
136 	textHeight = height.ascent + height.descent + height.leading;
137 
138 	be_bold_font->GetHeight(&height);
139 	labelHeight = height.ascent + height.descent + height.leading;
140 
141 	BRect r(0, 0, 225, Bounds().bottom);
142 	if (fLogo)
143 		r.OffsetBy(0, fLogo->Bounds().Height());
144 
145 	fInfoView = new BView(r, "infoview", B_FOLLOW_LEFT | B_FOLLOW_TOP_BOTTOM, B_WILL_DRAW);
146 	fInfoView->SetViewColor(235, 235, 235);
147 	AddChild(fInfoView);
148 
149 	// Add all the various labels for system infomation
150 
151 	BStringView *stringView;
152 
153 	// OS Version
154 	r.Set(5, 5, 224, labelHeight + 5);
155 	stringView = new BStringView(r, "oslabel", "Version:");
156 	stringView->SetFont(be_bold_font);
157 	fInfoView->AddChild(stringView);
158 	stringView->ResizeToPreferred();
159 
160 	// we update "labelHeight" to the actual height of the string view
161 	labelHeight = stringView->Bounds().Height();
162 
163 	r.OffsetBy(0, labelHeight);
164 	r.bottom = r.top + textHeight;
165 
166 	char string[256];
167 	strcpy(string, "Unknown");
168 
169 	// the version is stored in the BEOS:APP_VERSION attribute of libbe.so
170 	BPath path;
171 	if (find_directory(B_BEOS_LIB_DIRECTORY, &path) == B_OK) {
172 		path.Append("libbe.so");
173 
174 		BAppFileInfo appFileInfo;
175 		version_info versionInfo;
176 		BFile file;
177 		if (file.SetTo(path.Path(), B_READ_ONLY) == B_OK
178 			&& appFileInfo.SetTo(&file) == B_OK
179 			&& appFileInfo.GetVersionInfo(&versionInfo, B_APP_VERSION_KIND) == B_OK
180 			&& versionInfo.short_info[0] != '\0')
181 			strcpy(string, versionInfo.short_info);
182 	}
183 
184 	// Add revision from uname() info
185 	utsname unameInfo;
186 	if (uname(&unameInfo) == 0) {
187 		long revision;
188 		if (sscanf(unameInfo.version, "r%ld", &revision) == 1) {
189 			char version[16];
190 			snprintf(version, sizeof(version), "%ld", revision);
191 			strlcat(string, " (Revision ", sizeof(string));
192 			strlcat(string, version, sizeof(string));
193 			strlcat(string, ")", sizeof(string));
194 		}
195 	}
196 
197 	stringView = new BStringView(r, "ostext", string);
198 	fInfoView->AddChild(stringView);
199 	stringView->ResizeToPreferred();
200 
201 	// CPU count, type and clock speed
202 	r.OffsetBy(0, textHeight * 1.5);
203 	r.bottom = r.top + labelHeight;
204 
205 	if (systemInfo.cpu_count > 1)
206 		sprintf(string, "%ld Processors:", systemInfo.cpu_count);
207 	else
208 		strcpy(string, "Processor:");
209 
210 	stringView = new BStringView(r, "cpulabel", string);
211 	stringView->SetFont(be_bold_font);
212 	fInfoView->AddChild(stringView);
213 	stringView->ResizeToPreferred();
214 
215 
216 	BString cpuType;
217 	cpuType << get_cpu_vendor_string(systemInfo.cpu_type)
218 		<< " " << get_cpu_model_string(&systemInfo);
219 
220 	r.OffsetBy(0, labelHeight);
221 	r.bottom = r.top + textHeight;
222 	stringView = new BStringView(r, "cputext", cpuType.String());
223 	fInfoView->AddChild(stringView);
224 	stringView->ResizeToPreferred();
225 
226 	r.OffsetBy(0, textHeight);
227 	r.bottom = r.top + textHeight;
228 
229 	int32 clockSpeed = get_rounded_cpu_speed();
230 	if (clockSpeed < 1000)
231 		sprintf(string,"%ld MHz", clockSpeed);
232 	else
233 		sprintf(string,"%.2f GHz", clockSpeed / 1000.0f);
234 
235 	stringView = new BStringView(r, "mhztext", string);
236 	fInfoView->AddChild(stringView);
237 	stringView->ResizeToPreferred();
238 
239 	// RAM
240 	r.OffsetBy(0, textHeight * 1.5);
241 	r.bottom = r.top + labelHeight;
242 	stringView = new BStringView(r, "ramlabel", "Memory:");
243 	stringView->SetFont(be_bold_font);
244 	fInfoView->AddChild(stringView);
245 	stringView->ResizeToPreferred();
246 
247 	r.OffsetBy(0, labelHeight);
248 	r.bottom = r.top + textHeight;
249 
250 	fMemView = new BStringView(r, "ramtext", "");
251 	fInfoView->AddChild(fMemView);
252 	//fMemView->ResizeToPreferred();
253 
254 	fMemView->SetText(MemUsageToString(string, sizeof(string)));
255 
256 	// Kernel build time/date
257 	r.OffsetBy(0, textHeight * 1.5);
258 	r.bottom = r.top + labelHeight;
259 	stringView = new BStringView(r, "kernellabel", "Kernel:");
260 	stringView->SetFont(be_bold_font);
261 	fInfoView->AddChild(stringView);
262 	stringView->ResizeToPreferred();
263 
264 	r.OffsetBy(0, labelHeight);
265 	r.bottom = r.top + textHeight;
266 
267 	snprintf(string, sizeof(string), "%s %s",
268 		systemInfo.kernel_build_date, systemInfo.kernel_build_time);
269 
270 	stringView = new BStringView(r, "kerneltext", string);
271 	fInfoView->AddChild(stringView);
272 	stringView->ResizeToPreferred();
273 
274 	// Uptime
275 	r.OffsetBy(0, textHeight * 1.5);
276 	r.bottom = r.top + labelHeight;
277 	stringView = new BStringView(r, "uptimelabel", "Time Running:");
278 	stringView->SetFont(be_bold_font);
279 	fInfoView->AddChild(stringView);
280 	stringView->ResizeToPreferred();
281 
282 	r.OffsetBy(0, labelHeight);
283 	r.bottom = r.top + textHeight;
284 
285 	fUptimeView = new BStringView(r, "uptimetext", "");
286 	fInfoView->AddChild(fUptimeView);
287 	// string width changes, so we don't do ResizeToPreferred()
288 
289 	fUptimeView->SetText(UptimeToString(string, sizeof(string)));
290 
291 	// Begin construction of the credits view
292 	r = Bounds();
293 	r.left += fInfoView->Bounds().right + 1;
294 	r.right -= B_V_SCROLL_BAR_WIDTH;
295 
296 	fCreditsView = new BTextView(r, "credits",
297 		r.OffsetToCopy(0, 0).InsetByCopy(5, 5), B_FOLLOW_ALL);
298 	fCreditsView->SetFlags(fCreditsView->Flags() | B_FRAME_EVENTS );
299 	fCreditsView->SetStylable(true);
300 	fCreditsView->MakeEditable(false);
301 	fCreditsView->SetWordWrap(true);
302 
303 	BScrollView *creditsScroller = new BScrollView("creditsScroller",
304 		fCreditsView, B_FOLLOW_ALL, B_WILL_DRAW | B_FRAME_EVENTS, false, true, B_PLAIN_BORDER);
305 	AddChild(creditsScroller);
306 
307 	rgb_color darkgrey = { 100, 100, 100, 255 };
308 	rgb_color haikuGreen = { 42, 131, 36, 255 };
309 	rgb_color haikuOrange = { 255, 69, 0, 255 };
310 	rgb_color haikuYellow = { 255, 176, 0, 255 };
311 	rgb_color linkBlue = { 80, 80, 200, 255 };
312 
313 	BFont font(be_bold_font);
314 	font.SetSize(font.Size() + 4);
315 
316 	fCreditsView->SetFontAndColor(&font, B_FONT_ALL, &haikuGreen);
317 	fCreditsView->Insert("Haiku\n");
318 
319 	font.SetSize(be_bold_font->Size());
320 	font.SetFace(B_BOLD_FACE | B_ITALIC_FACE);
321 
322 	time_t time = ::time(NULL);
323 	struct tm* tm = localtime(&time);
324 	int32 year = tm->tm_year + 1900;
325 	if (year < 2007)
326 		year = 2007;
327 	snprintf(string, sizeof(string),
328 		"Copyright " B_UTF8_COPYRIGHT "2001-%ld Haiku, Inc.\n", year);
329 
330 	fCreditsView->SetFontAndColor(be_plain_font, B_FONT_ALL, &darkgrey);
331 	fCreditsView->Insert(string);
332 
333 	fCreditsView->SetFontAndColor(be_plain_font, B_FONT_ALL, &linkBlue);
334 	fCreditsView->Insert("http://haiku-os.org\n\n");
335 
336 	fCreditsView->SetFontAndColor(&font, B_FONT_ALL, &haikuOrange);
337 	fCreditsView->Insert("Team Leads:\n");
338 
339 	fCreditsView->SetFontAndColor(be_plain_font, B_FONT_ALL, &darkgrey);
340 	fCreditsView->Insert(
341 		"Axel Dörfler\n"
342 		"Phil Greenway\n"
343 		"Philippe Houdoin\n"
344 		"Waldemar Kornewald\n"
345 		"Marcus Overhagen\n"
346 		"Ingo Weinhold\n"
347 		"Jonathan Yoder\n"
348 		"\n");
349 
350 	fCreditsView->SetFontAndColor(&font, B_FONT_ALL, &haikuOrange);
351 	fCreditsView->Insert("Developers:\n");
352 
353 	fCreditsView->SetFontAndColor(be_plain_font, B_FONT_ALL, &darkgrey);
354 	fCreditsView->Insert(
355 		"Ithamar R. Adema\n"
356 		"Stephan Aßmus\n"
357 		"Andrew Bachmann\n"
358 		"Stefano Ceccherini\n"
359 		"Rudolf Cornelissen\n"
360 		"Jérôme Duval\n"
361 		"Waldemar Kornewald\n"
362 		"Ryan Leavengood\n"
363 		"Michael Lotz\n"
364 		"Michael Pfeiffer\n"
365 		"Niels Reedijk\n"
366 		"François Revol\n"
367 		"Hugo Santos\n"
368 		"Bryan Varner\n"
369 		"Siarzhuk Zharski\n"
370 		"\n");
371 
372 	fCreditsView->SetFontAndColor(&font, B_FONT_ALL, &haikuOrange);
373 	fCreditsView->Insert("Contributors:\n");
374 
375 	fCreditsView->SetFontAndColor(be_plain_font, B_FONT_ALL, &darkgrey);
376 	fCreditsView->Insert(
377 		"Bruno G. Albuquerque\n"
378 		"Andrea Anzani\n"
379 		"Bruce Cameron\n"
380 		"Greg Crain\n"
381 		"Tyler Dauwalder\n"
382 		"Oliver Ruiz Dorantes\n"
383 		"John Drinkwater\n"
384 		"Cian Duffy\n"
385 		"Marc Flerackers\n"
386 		"Daniel Furrer\n"
387 		"Troeglazov Gerasim\n"
388 		"Matthijs Hollemans\n"
389 		"Morgan Howe\n"
390 		"Erik Jaesler\n"
391 		"Carwyn Jones\n"
392 		"Vasilis Kaoutsis\n"
393 		"Euan Kirkhope\n"
394 		"Jan Klötzke\n"
395 		"Marcin Konicki\n"
396 		"Kurtis Kopf\n"
397 		"Tomáš Kučera\n"
398 		"Luboš Kulič\n"
399 		"Thomas Kurschel\n"
400 		"Elad Lahav\n"
401 		"Santiago Lema\n"
402 		"Oscar Lesta\n"
403 		"Jerome Leveque\n"
404 		"Graham MacDonald\n"
405 		"Jan Matějek\n"
406 		"Brian Matzon\n"
407 		"Christopher ML Zumwalt May\n"
408 		"Andrew McCall\n"
409 		"David McPaul\n"
410 		"Michele (zuMi)\n"
411 		"Misza\n"
412 		"MrSiggler\n"
413 		"Alan Murta\n"
414 		"Frans Van Nispen\n"
415 		"Adi Oanca\n"
416 		"Pahtz\n"
417 		"Michael Paine\n"
418 		"Michael Phipps\n"
419 		"Jeremy Rand\n"
420 		"Hartmut Reh\n"
421 		"David Reid\n"
422 		"Daniel Reinhold\n"
423 		"Samuel Rodriguez Perez\n"
424 		"Thomas Roell\n"
425 		"Rafael Romo\n"
426 		"Reznikov Sergei\n"
427 		"Zousar Shaker\n"
428 		"Jonas Sundström\n"
429 		"Daniel Switkin\n"
430 		"Atsushi Takamatsu\n"
431 		"Oliver Tappe\n"
432 		"Jason Vandermark\n"
433 		"Sandor Vroemisse\n"
434 		"Nathan Whitehorn\n"
435 		"Michael Wilber\n"
436 		"Ulrich Wimboeck\n"
437 		"Gabe Yoder\n"
438 		"Gerald Zajac\n"
439 		"Łukasz Zemczak\n"
440 		"JiSheng Zhang\n"
441 		"\n" B_UTF8_ELLIPSIS " and probably some more we forgot to mention (sorry!)"
442 		"\n\n");
443 
444 	fCreditsView->SetFontAndColor(&font, B_FONT_ALL, &haikuOrange);
445 	fCreditsView->Insert("Special Thanks To:\n");
446 
447 	fCreditsView->SetFontAndColor(be_plain_font, B_FONT_ALL, &darkgrey);
448 	fCreditsView->Insert("Travis Geiselbrecht (and his NewOS kernel)\n");
449 	fCreditsView->Insert("Michael Phipps (project founder)\n\n");
450 
451 	font.SetSize(be_bold_font->Size() + 4);
452 	font.SetFace(B_BOLD_FACE);
453 	fCreditsView->SetFontAndColor(&font, B_FONT_ALL, &haikuGreen);
454 	fCreditsView->Insert("\nCopyrights\n\n");
455 
456 	font.SetSize(be_bold_font->Size());
457 	font.SetFace(B_BOLD_FACE | B_ITALIC_FACE);
458 
459 	// GNU copyrights
460 	fCreditsView->SetFontAndColor(&font, B_FONT_ALL, &haikuYellow);
461 	fCreditsView->Insert("The GNU Project\n");
462 	fCreditsView->SetFontAndColor(be_plain_font, B_FONT_ALL, &darkgrey);
463 	fCreditsView->Insert("Contains software from the GNU Project, "
464 		"released under the GPL and LGPL licences:\n");
465 	fCreditsView->Insert("	- GNU C Library,\n");
466 	fCreditsView->Insert("	- GNU coretools, diffutils, findutils, gawk, bison, m4, make,\n");
467 	fCreditsView->Insert("	- Bourne Again Shell.\n");
468 	fCreditsView->Insert("Copyright " B_UTF8_COPYRIGHT " The Free Software Foundation.\n");
469 	fCreditsView->SetFontAndColor(be_plain_font, B_FONT_ALL, &linkBlue);
470 	fCreditsView->Insert("www.gnu.org\n\n");
471 
472 	// FFMpeg copyrights
473 	fCreditsView->SetFontAndColor(&font, B_FONT_ALL, &haikuYellow);
474 	fCreditsView->Insert("FFMpeg libavcodec\n");
475 	fCreditsView->SetFontAndColor(be_plain_font, B_FONT_ALL, &darkgrey);
476 	fCreditsView->Insert("Copyright " B_UTF8_COPYRIGHT " 2000-2007 Fabrice Bellard, et al.\n");
477 	fCreditsView->SetFontAndColor(be_plain_font, B_FONT_ALL, &linkBlue);
478 	fCreditsView->Insert("www.ffmpeg.org\n\n");
479 
480 	// AGG copyrights
481 	fCreditsView->SetFontAndColor(&font, B_FONT_ALL, &haikuYellow);
482 	fCreditsView->Insert("AntiGrain Geometry\n");
483 	fCreditsView->SetFontAndColor(be_plain_font, B_FONT_ALL, &darkgrey);
484 	fCreditsView->Insert("Copyright " B_UTF8_COPYRIGHT " 2002-2006 Maxim Shemanarev (McSeem).\n");
485 	fCreditsView->SetFontAndColor(be_plain_font, B_FONT_ALL, &linkBlue);
486 	fCreditsView->Insert("www.antigrain.com\n\n");
487 
488 	// PDFLib copyrights
489 	fCreditsView->SetFontAndColor(&font, B_FONT_ALL, &haikuYellow);
490 	fCreditsView->Insert("PDFLib\n");
491 	fCreditsView->SetFontAndColor(be_plain_font, B_FONT_ALL, &darkgrey);
492 	fCreditsView->Insert(
493 		"Copyright " B_UTF8_COPYRIGHT " 1997-2006 PDFlib GmbH and Thomas Merz. "
494 		"All rights reserved.\n"
495 		"PDFlib and the PDFlib logo are registered trademarks of PDFlib GmbH.\n");
496 	fCreditsView->SetFontAndColor(be_plain_font, B_FONT_ALL, &linkBlue);
497 	fCreditsView->Insert("www.pdflib.com\n\n");
498 
499 	// FreeType copyrights
500 	fCreditsView->SetFontAndColor(&font, B_FONT_ALL, &haikuYellow);
501 	fCreditsView->Insert("FreeType2\n");
502 	fCreditsView->SetFontAndColor(be_plain_font, B_FONT_ALL, &darkgrey);
503 	fCreditsView->Insert("Portions of this software are copyright " B_UTF8_COPYRIGHT " 1996-2006 The FreeType"
504 		" Project.  All rights reserved.\n");
505 	fCreditsView->SetFontAndColor(be_plain_font, B_FONT_ALL, &linkBlue);
506 	fCreditsView->Insert("www.freetype.org\n\n");
507 
508 	// Mesa3D (http://www.mesa3d.org) copyrights
509 	fCreditsView->SetFontAndColor(&font, B_FONT_ALL, &haikuYellow);
510 	fCreditsView->Insert("Mesa\n");
511 	fCreditsView->SetFontAndColor(be_plain_font, B_FONT_ALL, &darkgrey);
512 	fCreditsView->Insert(
513 		"Copyright " B_UTF8_COPYRIGHT " 1999-2006 Brian Paul. "
514 		"Mesa3D project.  All rights reserved.\n");
515 	fCreditsView->SetFontAndColor(be_plain_font, B_FONT_ALL, &linkBlue);
516 	fCreditsView->Insert("www.mesa3d.org\n\n");
517 
518 	// SGI's GLU implementation copyrights
519 	fCreditsView->SetFontAndColor(&font, B_FONT_ALL, &haikuYellow);
520 	fCreditsView->Insert("GLU\n");
521 	fCreditsView->SetFontAndColor(be_plain_font, B_FONT_ALL, &darkgrey);
522 	fCreditsView->Insert(
523 		"Copyright " B_UTF8_COPYRIGHT " 1991-2000 Silicon Graphics, Inc. "
524 		"SGI's Software FreeB license.  All rights reserved.\n\n");
525 
526 	// GLUT implementation copyrights
527 	fCreditsView->SetFontAndColor(&font, B_FONT_ALL, &haikuYellow);
528 	fCreditsView->Insert("GLUT\n");
529 	fCreditsView->SetFontAndColor(be_plain_font, B_FONT_ALL, &darkgrey);
530 	fCreditsView->Insert(
531 		"Copyright " B_UTF8_COPYRIGHT " 1994-1997 Mark Kilgard. "
532 		"All rights reserved.\n"
533 		"Copyright " B_UTF8_COPYRIGHT " 1997 Be Inc.\n"
534 		"Copyright " B_UTF8_COPYRIGHT " 1999 Jake Hamby. \n\n");
535 
536 	// OpenGroup & DEC (BRegion backend) copyright
537 	fCreditsView->SetFontAndColor(&font, B_FONT_ALL, &haikuYellow);
538 	fCreditsView->Insert("BRegion backend (XFree86)\n");
539 	fCreditsView->SetFontAndColor(be_plain_font, B_FONT_ALL, &darkgrey);
540 	fCreditsView->Insert(
541 		"Copyright " B_UTF8_COPYRIGHT " 1987, 1988, 1998  The Open Group.\n"
542 		"Copyright " B_UTF8_COPYRIGHT " 1987, 1988 Digital Equipment Corporation, Maynard, Massachusetts.\n"
543 		"All rights reserved.\n\n");
544 
545 	// Konatu font
546 	fCreditsView->SetFontAndColor(&font, B_FONT_ALL, &haikuYellow);
547 	fCreditsView->Insert("Konatu font\n");
548 	fCreditsView->SetFontAndColor(be_plain_font, B_FONT_ALL, &darkgrey);
549 	fCreditsView->Insert(
550 		"Copyright " B_UTF8_COPYRIGHT " 2002- MASUDA mitiya.\n"
551 		"MIT license. All rights reserved.\n\n");
552 
553 	// expat copyrights
554 	fCreditsView->SetFontAndColor(&font, B_FONT_ALL, &haikuYellow);
555 	fCreditsView->Insert("expat\n");
556 	fCreditsView->SetFontAndColor(be_plain_font, B_FONT_ALL, &darkgrey);
557 	fCreditsView->Insert(
558 		"Copyright " B_UTF8_COPYRIGHT " 1998, 1999, 2000 Thai Open Source Software Center Ltd and Clark Cooper.\n"
559 		"Copyright " B_UTF8_COPYRIGHT " 2001, 2002, 2003 Expat maintainers.\n\n");
560 
561 	// zlib copyrights
562 	fCreditsView->SetFontAndColor(&font, B_FONT_ALL, &haikuYellow);
563 	fCreditsView->Insert("zlib\n");
564 	fCreditsView->SetFontAndColor(be_plain_font, B_FONT_ALL, &darkgrey);
565 	fCreditsView->Insert(
566 		"Copyright " B_UTF8_COPYRIGHT " 1995-2004 Jean-loup Gailly and Mark Adler.\n\n");
567 
568 	// zip copyrights
569 	fCreditsView->SetFontAndColor(&font, B_FONT_ALL, &haikuYellow);
570 	fCreditsView->Insert("Info-ZIP\n");
571 	fCreditsView->SetFontAndColor(be_plain_font, B_FONT_ALL, &darkgrey);
572 	fCreditsView->Insert(
573 		"Copyright " B_UTF8_COPYRIGHT " 1990-2002 Info-ZIP. All rights reserved.\n\n");
574 
575 	// bzip2 copyrights
576 	fCreditsView->SetFontAndColor(&font, B_FONT_ALL, &haikuYellow);
577 	fCreditsView->Insert("bzip2\n");
578 	fCreditsView->SetFontAndColor(be_plain_font, B_FONT_ALL, &darkgrey);
579 	fCreditsView->Insert(
580 		"Copyright " B_UTF8_COPYRIGHT " 1996-2005 Julian R Seward. All rights reserved.\n\n");
581 
582 	// VIM copyrights
583 	fCreditsView->SetFontAndColor(&font, B_FONT_ALL, &haikuYellow);
584 	fCreditsView->Insert("Vi IMproved\n");
585 	fCreditsView->SetFontAndColor(be_plain_font, B_FONT_ALL, &darkgrey);
586 	fCreditsView->Insert(
587 		"Copyright " B_UTF8_COPYRIGHT " Bram Moolenaar et al.\n\n");
588 
589 }
590 
591 
592 AboutView::~AboutView(void)
593 {
594 	delete fScrollRunner;
595 }
596 
597 
598 void
599 AboutView::AttachedToWindow(void)
600 {
601 	BView::AttachedToWindow();
602 	Window()->SetPulseRate(500000);
603 	SetEventMask(B_POINTER_EVENTS);
604 }
605 
606 
607 void
608 AboutView::MouseDown(BPoint pt)
609 {
610 	BRect r(92, 26, 105, 31);
611 	if (r.Contains(pt))
612 		printf("Easter Egg\n");
613 
614 	if (Bounds().Contains(pt)) {
615 		fLastActionTime = system_time();
616 		delete fScrollRunner;
617 		fScrollRunner = NULL;
618 	}
619 }
620 
621 
622 void
623 AboutView::FrameResized(float width, float height)
624 {
625 	BRect r = fCreditsView->Bounds();
626 	r.OffsetTo(B_ORIGIN);
627 	r.InsetBy(3, 3);
628 	fCreditsView->SetTextRect(r);
629 }
630 
631 
632 void
633 AboutView::Draw(BRect update)
634 {
635 	if (fLogo)
636 		DrawBitmap(fLogo, fDrawPoint);
637 }
638 
639 
640 void
641 AboutView::Pulse(void)
642 {
643 	char string[255];
644 
645 	fUptimeView->SetText(UptimeToString(string, sizeof(string)));
646 	fMemView->SetText(MemUsageToString(string, sizeof(string)));
647 
648 	if (fScrollRunner == NULL && (system_time() > fLastActionTime + 10000000)) {
649 		BMessage message(SCROLL_CREDITS_VIEW);
650 		//fScrollRunner = new BMessageRunner(this, &message, 300000, -1);
651 	}
652 }
653 
654 
655 void
656 AboutView::MessageReceived(BMessage *msg)
657 {
658 	switch (msg->what) {
659 		case SCROLL_CREDITS_VIEW:
660 		{
661 			BScrollBar *scrollBar = fCreditsView->ScrollBar(B_VERTICAL);
662 			if (scrollBar == NULL)
663 				break;
664 			float max, min;
665 			scrollBar->GetRange(&min, &max);
666 			if (scrollBar->Value() < max)
667 				fCreditsView->ScrollBy(0, 5);
668 
669 			break;
670 		}
671 
672 		default:
673 			BView::MessageReceived(msg);
674 			break;
675 	}
676 }
677 
678 
679 //	#pragma mark -
680 
681 
682 static const char *
683 MemUsageToString(char string[], size_t size)
684 {
685 	system_info systemInfo;
686 
687 	if (get_system_info(&systemInfo) < B_OK)
688 		return "Unknown";
689 
690 	snprintf(string, size, "%d MB total, %d MB used (%d%%)",
691 			int(systemInfo.max_pages / 256.0f + 0.5f),
692 			int(systemInfo.used_pages / 256.0f + 0.5f),
693 			int(100 * systemInfo.used_pages / systemInfo.max_pages));
694 
695 	return string;
696 }
697 
698 
699 static const char *
700 UptimeToString(char string[], size_t size)
701 {
702 	int64 days, hours, minutes, seconds, remainder;
703 	int64 systime = system_time();
704 
705 	days = systime / 86400000000LL;
706 	remainder = systime % 86400000000LL;
707 
708 	hours = remainder / 3600000000LL;
709 	remainder = remainder % 3600000000LL;
710 
711 	minutes = remainder / 60000000;
712 	remainder = remainder % 60000000;
713 
714 	seconds = remainder / 1000000;
715 
716 	char *str = string;
717 	if (days) {
718 		str += snprintf(str, size, "%lld day%s",days, days > 1 ? "s" : "");
719 	}
720 	if (hours) {
721 		str += snprintf(str, size - strlen(string), "%s%lld hour%s",
722 				str != string ? ", " : "",
723 				hours, hours > 1 ? "s" : "");
724 	}
725 	if (minutes) {
726 		str += snprintf(str, size - strlen(string), "%s%lld minute%s",
727 				str != string ? ", " : "",
728 				minutes, minutes > 1 ? "s" : "");
729 	}
730 
731 	if (seconds || str == string) {
732 		// Haiku would be well-known to boot very fast.
733 		// Let's be ready to handle below minute uptime, zero second included ;-)
734 		str += snprintf(str, size - strlen(string), "%s%lld second%s",
735 				str != string ? ", " : "",
736 				seconds, seconds > 1 ? "s" : "");
737 	}
738 
739 	return string;
740 }
741 
742 
743 int
744 main()
745 {
746 	AboutApp app;
747 	app.Run();
748 	return 0;
749 }
750 
751