1f75a7bf5SStephan Aßmus /* 2*dde4ac43SPhilippe Saint-Pierre * Copyright (c) 2010 Philippe St-Pierre <stpere@gmail.com>. All rights reserved. 3f75a7bf5SStephan Aßmus * Copyright (c) 2008 Stephan Aßmus <superstippi@gmx.de>. All rights reserved. 4f75a7bf5SStephan Aßmus * Distributed under the terms of the MIT/X11 license. 5f75a7bf5SStephan Aßmus * 6f75a7bf5SStephan Aßmus * Copyright (c) 1999 Mike Steed. You are free to use and distribute this software 7f75a7bf5SStephan Aßmus * as long as it is accompanied by it's documentation and this copyright notice. 8f75a7bf5SStephan Aßmus * The software comes with no warranty, etc. 9f75a7bf5SStephan Aßmus */ 1015676f3aSWim van der Meer 1115676f3aSWim van der Meer 12f75a7bf5SStephan Aßmus #include "StatusView.h" 13f75a7bf5SStephan Aßmus 14f75a7bf5SStephan Aßmus #include <math.h> 15f75a7bf5SStephan Aßmus #include <stdio.h> 16f75a7bf5SStephan Aßmus 17f75a7bf5SStephan Aßmus #include <Box.h> 18*dde4ac43SPhilippe Saint-Pierre #include <Button.h> 19f75a7bf5SStephan Aßmus #include <Node.h> 20f75a7bf5SStephan Aßmus #include <String.h> 21f75a7bf5SStephan Aßmus #include <StringView.h> 22f75a7bf5SStephan Aßmus 23*dde4ac43SPhilippe Saint-Pierre #include <LayoutBuilder.h> 24*dde4ac43SPhilippe Saint-Pierre 25f75a7bf5SStephan Aßmus #include "Common.h" 26f75a7bf5SStephan Aßmus #include "Scanner.h" 27f75a7bf5SStephan Aßmus 28f75a7bf5SStephan Aßmus 29*dde4ac43SPhilippe Saint-Pierre StatusView::StatusView() 3015676f3aSWim van der Meer : 31*dde4ac43SPhilippe Saint-Pierre BView(NULL, B_WILL_DRAW), 32f75a7bf5SStephan Aßmus fCurrentFileInfo(NULL) 33f75a7bf5SStephan Aßmus { 34*dde4ac43SPhilippe Saint-Pierre SetViewColor(kPieBGColor); 35*dde4ac43SPhilippe Saint-Pierre SetLowColor(kPieBGColor); 36f75a7bf5SStephan Aßmus 37*dde4ac43SPhilippe Saint-Pierre fSizeView = new BStringView(NULL, kEmptyStr); 38*dde4ac43SPhilippe Saint-Pierre fSizeView->SetExplicitMinSize(BSize(StringWidth("9999.99 GB"), 39*dde4ac43SPhilippe Saint-Pierre B_SIZE_UNSET)); 40*dde4ac43SPhilippe Saint-Pierre fSizeView->SetExplicitMaxSize(BSize(StringWidth("9999.99 GB"), 41*dde4ac43SPhilippe Saint-Pierre B_SIZE_UNSET)); 42f75a7bf5SStephan Aßmus 43f75a7bf5SStephan Aßmus char testLabel[256]; 44f75a7bf5SStephan Aßmus sprintf(testLabel, kManyFiles, 999999); 45f75a7bf5SStephan Aßmus 46*dde4ac43SPhilippe Saint-Pierre fCountView = new BStringView(NULL, kEmptyStr); 47*dde4ac43SPhilippe Saint-Pierre fCountView->SetExplicitMinSize(BSize(StringWidth(testLabel), B_SIZE_UNSET)); 48*dde4ac43SPhilippe Saint-Pierre fCountView->SetExplicitMaxSize(BSize(B_SIZE_UNLIMITED, B_SIZE_UNSET)); 49f75a7bf5SStephan Aßmus 50*dde4ac43SPhilippe Saint-Pierre fPathView = new BStringView(NULL, kEmptyStr); 51*dde4ac43SPhilippe Saint-Pierre fPathView->SetExplicitMaxSize(BSize(B_SIZE_UNLIMITED, B_SIZE_UNSET)); 52f75a7bf5SStephan Aßmus 53*dde4ac43SPhilippe Saint-Pierre fRefreshBtn = new BButton(NULL, kStrScan, new BMessage(kBtnRescan)); 54*dde4ac43SPhilippe Saint-Pierre 55*dde4ac43SPhilippe Saint-Pierre fRefreshBtn->SetExplicitMaxSize(BSize(B_SIZE_UNSET, B_SIZE_UNLIMITED)); 56*dde4ac43SPhilippe Saint-Pierre 57*dde4ac43SPhilippe Saint-Pierre BBox* divider1 = new BBox(BRect(), B_EMPTY_STRING, B_FOLLOW_ALL_SIDES, 58*dde4ac43SPhilippe Saint-Pierre B_WILL_DRAW | B_FRAME_EVENTS, B_FANCY_BORDER); 59*dde4ac43SPhilippe Saint-Pierre 60*dde4ac43SPhilippe Saint-Pierre BBox* divider2 = new BBox(BRect(), B_EMPTY_STRING, B_FOLLOW_ALL_SIDES, 61*dde4ac43SPhilippe Saint-Pierre B_WILL_DRAW | B_FRAME_EVENTS, B_FANCY_BORDER); 62*dde4ac43SPhilippe Saint-Pierre 63*dde4ac43SPhilippe Saint-Pierre divider1->SetExplicitMaxSize(BSize(B_SIZE_UNLIMITED, 1)); 64*dde4ac43SPhilippe Saint-Pierre divider2->SetExplicitMaxSize(BSize(1, B_SIZE_UNLIMITED)); 65*dde4ac43SPhilippe Saint-Pierre 66*dde4ac43SPhilippe Saint-Pierre SetLayout(new BGroupLayout(B_VERTICAL)); 67*dde4ac43SPhilippe Saint-Pierre 68*dde4ac43SPhilippe Saint-Pierre AddChild(BLayoutBuilder::Group<>(B_HORIZONTAL) 69*dde4ac43SPhilippe Saint-Pierre .AddGroup(B_VERTICAL) 70*dde4ac43SPhilippe Saint-Pierre .Add(fPathView) 71*dde4ac43SPhilippe Saint-Pierre .Add(divider1) 72*dde4ac43SPhilippe Saint-Pierre .AddGroup(B_HORIZONTAL) 73*dde4ac43SPhilippe Saint-Pierre .Add(fCountView) 74*dde4ac43SPhilippe Saint-Pierre .Add(divider2) 75*dde4ac43SPhilippe Saint-Pierre .Add(fSizeView) 76*dde4ac43SPhilippe Saint-Pierre .End() 77*dde4ac43SPhilippe Saint-Pierre .End() 78*dde4ac43SPhilippe Saint-Pierre .AddStrut(kSmallHMargin) 79*dde4ac43SPhilippe Saint-Pierre .Add(fRefreshBtn) 80*dde4ac43SPhilippe Saint-Pierre .SetInsets(kSmallHMargin, kSmallVMargin, kSmallVMargin, kSmallVMargin) 81*dde4ac43SPhilippe Saint-Pierre ); 82f75a7bf5SStephan Aßmus } 83f75a7bf5SStephan Aßmus 84f75a7bf5SStephan Aßmus 85f75a7bf5SStephan Aßmus StatusView::~StatusView() 86f75a7bf5SStephan Aßmus { 87f75a7bf5SStephan Aßmus } 88f75a7bf5SStephan Aßmus 89f75a7bf5SStephan Aßmus 90f75a7bf5SStephan Aßmus void 91*dde4ac43SPhilippe Saint-Pierre StatusView::SetRescanEnabled(bool enabled) 92*dde4ac43SPhilippe Saint-Pierre { 93*dde4ac43SPhilippe Saint-Pierre fRefreshBtn->SetEnabled(enabled); 94*dde4ac43SPhilippe Saint-Pierre } 95*dde4ac43SPhilippe Saint-Pierre 96*dde4ac43SPhilippe Saint-Pierre 97*dde4ac43SPhilippe Saint-Pierre void 98*dde4ac43SPhilippe Saint-Pierre StatusView::SetBtnLabel(const char* label) 99*dde4ac43SPhilippe Saint-Pierre { 100*dde4ac43SPhilippe Saint-Pierre fRefreshBtn->SetLabel(label); 101*dde4ac43SPhilippe Saint-Pierre } 102*dde4ac43SPhilippe Saint-Pierre 103*dde4ac43SPhilippe Saint-Pierre 104*dde4ac43SPhilippe Saint-Pierre void 1054b920fd0SOliver Tappe StatusView::ShowInfo(const FileInfo* info) 106f75a7bf5SStephan Aßmus { 107f75a7bf5SStephan Aßmus if (info == fCurrentFileInfo) 108f75a7bf5SStephan Aßmus return; 109f75a7bf5SStephan Aßmus 110f75a7bf5SStephan Aßmus fCurrentFileInfo = info; 111f75a7bf5SStephan Aßmus 112f75a7bf5SStephan Aßmus if (info == NULL) { 113f75a7bf5SStephan Aßmus fPathView->SetText(kEmptyStr); 114f75a7bf5SStephan Aßmus fSizeView->SetText(kEmptyStr); 115f75a7bf5SStephan Aßmus fCountView->SetText(kEmptyStr); 116f75a7bf5SStephan Aßmus return; 117f75a7bf5SStephan Aßmus } 118f75a7bf5SStephan Aßmus 119f75a7bf5SStephan Aßmus if (!info->pseudo) { 120f75a7bf5SStephan Aßmus BNode node(&info->ref); 121f75a7bf5SStephan Aßmus if (node.InitCheck() != B_OK) { 122f75a7bf5SStephan Aßmus fPathView->SetText(kStrUnavail); 123f75a7bf5SStephan Aßmus fSizeView->SetText(kEmptyStr); 124f75a7bf5SStephan Aßmus fCountView->SetText(kEmptyStr); 125f75a7bf5SStephan Aßmus return; 126f75a7bf5SStephan Aßmus } 127f75a7bf5SStephan Aßmus } 128f75a7bf5SStephan Aßmus 129f75a7bf5SStephan Aßmus float viewWidth = fPathView->Bounds().Width(); 130f75a7bf5SStephan Aßmus string path; 131f75a7bf5SStephan Aßmus info->GetPath(path); 132f75a7bf5SStephan Aßmus BString pathLabel = path.c_str(); 133f75a7bf5SStephan Aßmus be_plain_font->TruncateString(&pathLabel, B_TRUNCATE_BEGINNING, viewWidth); 134f75a7bf5SStephan Aßmus fPathView->SetText(pathLabel.String()); 135f75a7bf5SStephan Aßmus 136f75a7bf5SStephan Aßmus char label[B_PATH_NAME_LENGTH]; 137f75a7bf5SStephan Aßmus size_to_string(info->size, label); 138f75a7bf5SStephan Aßmus fSizeView->SetText(label); 139f75a7bf5SStephan Aßmus 140f75a7bf5SStephan Aßmus if (info->count > 0) { 141f75a7bf5SStephan Aßmus char label[256]; 142f75a7bf5SStephan Aßmus sprintf(label, (info->count == 1) ? kOneFile : kManyFiles, info->count); 143f75a7bf5SStephan Aßmus fCountView->SetText(label); 144f75a7bf5SStephan Aßmus } else { 145f75a7bf5SStephan Aßmus fCountView->SetText(kEmptyStr); 146f75a7bf5SStephan Aßmus } 147f75a7bf5SStephan Aßmus } 148