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