1 /* 2 * Copyright (c) 2008 Stephan Aßmus <superstippi@gmx.de>. All rights reserved. 3 * Distributed under the terms of the MIT/X11 license. 4 * 5 * Copyright (c) 1999 Mike Steed. You are free to use and distribute this software 6 * as long as it is accompanied by it's documentation and this copyright notice. 7 * The software comes with no warranty, etc. 8 */ 9 10 11 #include "StatusView.h" 12 13 #include <math.h> 14 #include <stdio.h> 15 16 #include <Box.h> 17 #include <Node.h> 18 #include <String.h> 19 #include <StringView.h> 20 21 #include "Common.h" 22 #include "Scanner.h" 23 24 25 StatusView::StatusView(BRect rect) 26 : 27 BView(rect, NULL, B_FOLLOW_LEFT_RIGHT | B_FOLLOW_BOTTOM, B_WILL_DRAW), 28 fCurrentFileInfo(NULL) 29 { 30 SetViewColor(kWindowColor); 31 32 struct font_height fh; 33 be_plain_font->GetHeight(&fh); 34 float plainHeight = ceilf(fh.ascent) + ceilf(fh.descent) 35 + ceilf(fh.leading); 36 float fixedHeight = ceilf(fh.ascent) + ceilf(fh.descent) 37 + ceilf(fh.leading); 38 ResizeTo(Bounds().Width(), 39 2.0 * kSmallVMargin + max_c(plainHeight, fixedHeight)); 40 41 BRect r = Bounds(); 42 r.top += kSmallVMargin; 43 44 // Size display 45 r.right -= kSmallHMargin; 46 r.left = r.right - StringWidth("9999.99 GB"); 47 fSizeView = new BStringView(r, NULL, kEmptyStr, 48 B_FOLLOW_RIGHT | B_FOLLOW_TOP_BOTTOM); 49 AddChild(fSizeView); 50 51 // Vertical divider 52 r.right = r.left - kSmallHMargin; 53 r.left = r.right - 1.0; 54 AddChild(new BBox(r.InsetByCopy(0, -5), NULL, 55 B_FOLLOW_RIGHT | B_FOLLOW_TOP_BOTTOM)); 56 57 // Count display 58 char testLabel[256]; 59 sprintf(testLabel, kManyFiles, 999999); 60 r.right = r.left - kSmallHMargin; 61 r.left = r.right - (StringWidth(testLabel) + kSmallHMargin); 62 fCountView = new BStringView(r, NULL, kEmptyStr, 63 B_FOLLOW_RIGHT|B_FOLLOW_TOP_BOTTOM); 64 AddChild(fCountView); 65 66 // Vertical divider 67 r.right = r.left - kSmallHMargin; 68 r.left = r.right - 1.0; 69 AddChild(new BBox(r.InsetByCopy(0, -5), NULL, 70 B_FOLLOW_RIGHT | B_FOLLOW_TOP_BOTTOM)); 71 72 // Path display 73 r.right = r.left - kSmallHMargin; 74 r.left = kSmallHMargin; 75 fPathView = new BStringView(r, NULL, kEmptyStr, 76 B_FOLLOW_LEFT_RIGHT|B_FOLLOW_TOP_BOTTOM); 77 AddChild(fPathView); 78 79 // Horizontal divider 80 r = Bounds(); 81 r.bottom = r.top + 1.0; 82 AddChild(new BBox(r.InsetByCopy(-5, 0), NULL, 83 B_FOLLOW_LEFT_RIGHT | B_FOLLOW_BOTTOM, B_WILL_DRAW)); 84 } 85 86 87 StatusView::~StatusView() 88 { 89 } 90 91 92 void 93 StatusView::ShowInfo(const FileInfo* info) 94 { 95 if (info == fCurrentFileInfo) 96 return; 97 98 fCurrentFileInfo = info; 99 100 if (info == NULL) { 101 fPathView->SetText(kEmptyStr); 102 fSizeView->SetText(kEmptyStr); 103 fCountView->SetText(kEmptyStr); 104 return; 105 } 106 107 if (!info->pseudo) { 108 BNode node(&info->ref); 109 if (node.InitCheck() != B_OK) { 110 fPathView->SetText(kStrUnavail); 111 fSizeView->SetText(kEmptyStr); 112 fCountView->SetText(kEmptyStr); 113 return; 114 } 115 } 116 117 float viewWidth = fPathView->Bounds().Width(); 118 string path; 119 info->GetPath(path); 120 BString pathLabel = path.c_str(); 121 be_plain_font->TruncateString(&pathLabel, B_TRUNCATE_BEGINNING, viewWidth); 122 fPathView->SetText(pathLabel.String()); 123 124 char label[B_PATH_NAME_LENGTH]; 125 size_to_string(info->size, label); 126 fSizeView->SetText(label); 127 128 if (info->count > 0) { 129 char label[256]; 130 sprintf(label, (info->count == 1) ? kOneFile : kManyFiles, info->count); 131 fCountView->SetText(label); 132 } else { 133 fCountView->SetText(kEmptyStr); 134 } 135 } 136