1/* 2 * Copyright 2001-2010, 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#include <String.h> 13#include <SystemCatalog.h> 14 15#include "ZombieReplicantView.h" 16 17#include <stdio.h> 18#include <stdlib.h> 19#include <string.h> 20#include <new> 21 22using BPrivate::gSystemCatalog; 23 24#undef B_TRANSLATION_CONTEXT 25#define B_TRANSLATION_CONTEXT "ZombieReplicantView" 26 27#undef B_TRANSLATE 28#define B_TRANSLATE(str) \ 29 gSystemCatalog.GetString(B_TRANSLATE_MARK(str), "ZombieReplicantView") 30 31 32_BZombieReplicantView_::_BZombieReplicantView_(BRect frame, status_t error) 33 : 34 BBox(frame, "<Zombie>", B_FOLLOW_NONE, B_WILL_DRAW), 35 fError(error) 36{ 37 BFont font(be_bold_font); 38 font.SetSize(9.0f); // TODO 39 SetFont(&font); 40 SetViewColor(kZombieColor); 41} 42 43 44_BZombieReplicantView_::~_BZombieReplicantView_() 45{ 46} 47 48 49void 50_BZombieReplicantView_::MessageReceived(BMessage* msg) 51{ 52 switch (msg->what) { 53 case B_ABOUT_REQUESTED: 54 { 55 const char* addOn = NULL; 56 BString error; 57 if (fArchive->FindString("add_on", &addOn) == B_OK) { 58 char description[B_MIME_TYPE_LENGTH] = ""; 59 BMimeType type(addOn); 60 type.GetShortDescription(description); 61 error = B_TRANSLATE("Cannot create the replicant for " 62 "\"%description\".\n%error"); 63 error.ReplaceFirst("%description", description); 64 } else 65 error = B_TRANSLATE("Cannot locate the application for the " 66 "replicant. No application signature supplied.\n%error"); 67 68 error.ReplaceFirst("%error", strerror(fError)); 69 70 BAlert* alert = new (std::nothrow) BAlert(B_TRANSLATE("Error"), 71 error.String(), B_TRANSLATE("OK"), NULL, NULL, 72 B_WIDTH_AS_USUAL, B_STOP_ALERT); 73 if (alert != NULL) { 74 alert->SetFlags(alert->Flags() | B_CLOSE_ON_ESCAPE); 75 alert->Go(); 76 } 77 78 break; 79 } 80 default: 81 BView::MessageReceived(msg); 82 } 83} 84 85 86void 87_BZombieReplicantView_::Draw(BRect updateRect) 88{ 89 BRect bounds(Bounds()); 90 font_height fh; 91 92 GetFontHeight(&fh); 93 94 DrawChar('?', BPoint(bounds.Width() / 2.0f - StringWidth("?") / 2.0f, 95 bounds.Height() / 2.0f - fh.ascent / 2.0f)); 96 97 BBox::Draw(updateRect); 98} 99 100 101void 102_BZombieReplicantView_::MouseDown(BPoint) 103{ 104} 105 106 107status_t 108_BZombieReplicantView_::Archive(BMessage* archive, bool) const 109{ 110 *archive = *fArchive; 111 112 return B_OK; 113} 114 115 116void 117_BZombieReplicantView_::SetArchive(BMessage* archive) 118{ 119 fArchive = archive; 120} 121