xref: /haiku/src/kits/interface/ZombieReplicantView.cpp (revision 1e36cfc2721ef13a187c6f7354dc9cbc485e89d3)
1 /*
2  * Copyright 2001-2006, Haiku.
3  * Distributed under the terms of the MIT License.
4  *
5  * Authors:
6  *		Marc Flerackers (mflerackers@androme.be)
7  */
8 
9 #include <Alert.h>
10 #include <Message.h>
11 #include <MimeType.h>
12 
13 #include <ZombieReplicantView.h>
14 
15 #include <stdio.h>
16 #include <stdlib.h>
17 #include <string.h>
18 #include <new>
19 
20 
21 const static rgb_color kZombieColor = {220, 220, 220, 255};
22 
23 
24 _BZombieReplicantView_::_BZombieReplicantView_(BRect frame, status_t error)
25 	:
26 	BBox(frame, "<Zombie>", B_FOLLOW_NONE, B_WILL_DRAW),
27 	fError(error)
28 {
29 	BFont font(be_bold_font);
30 	font.SetSize(9.0f); // TODO
31 	SetFont(&font);
32 	SetViewColor(kZombieColor);
33 }
34 
35 
36 _BZombieReplicantView_::~_BZombieReplicantView_()
37 {
38 }
39 
40 
41 void
42 _BZombieReplicantView_::MessageReceived(BMessage *msg)
43 {
44 	switch (msg->what) {
45 		case B_ABOUT_REQUESTED:
46 		{
47 			const char *addOn = NULL;
48 			char description[B_MIME_TYPE_LENGTH];
49 
50 			if (fArchive->FindString("add_on", &addOn) == B_OK) {
51 				BMimeType type(addOn);
52 				type.GetShortDescription(description);
53 			}
54 
55 			char error[1024];
56 			snprintf(error, sizeof(error),
57 				"Can't create the \"%s\" replicant because the library is in the Trash. (%s)",
58 				description, strerror(fError));
59 
60 			BAlert *alert = new (std::nothrow) BAlert("Error", error, "OK", NULL, NULL,
61 								B_WIDTH_AS_USUAL, B_STOP_ALERT);
62 			if (alert != NULL)
63 				alert->Go();
64 
65 			break;
66 		}
67 		default:
68 			BView::MessageReceived(msg);
69 	}
70 }
71 
72 
73 void
74 _BZombieReplicantView_::Draw(BRect updateRect)
75 {
76 	BRect bounds(Bounds());
77 	font_height fh;
78 
79 	GetFontHeight(&fh);
80 
81 	DrawChar('?', BPoint(bounds.Width() / 2.0f - StringWidth("?") / 2.0f,
82 		bounds.Height() / 2.0f - fh.ascent / 2.0f));
83 
84 	BBox::Draw(updateRect);
85 }
86 
87 
88 void
89 _BZombieReplicantView_::MouseDown(BPoint)
90 {
91 }
92 
93 
94 void
95 _BZombieReplicantView_::SetArchive(BMessage *archive)
96 {
97 	fArchive = archive;
98 }
99