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