1f75a7bf5SStephan Aßmus /* 2dde4ac43SPhilippe 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 17973f8e21SSiarzhuk Zharski #include <Catalog.h> 18f75a7bf5SStephan Aßmus #include <Box.h> 19dde4ac43SPhilippe Saint-Pierre #include <Button.h> 20be930298SAdrien Destugues #include <MessageFormat.h> 21f75a7bf5SStephan Aßmus #include <Node.h> 22f75a7bf5SStephan Aßmus #include <String.h> 23fffc0e2aSPhilippe Saint-Pierre #include <StringForSize.h> 24f75a7bf5SStephan Aßmus #include <StringView.h> 25f75a7bf5SStephan Aßmus 26dde4ac43SPhilippe Saint-Pierre #include <LayoutBuilder.h> 27dde4ac43SPhilippe Saint-Pierre 28973f8e21SSiarzhuk Zharski #include "DiskUsage.h" 29f75a7bf5SStephan Aßmus #include "Scanner.h" 30f75a7bf5SStephan Aßmus 31546208a5SOliver Tappe #undef B_TRANSLATION_CONTEXT 32546208a5SOliver Tappe #define B_TRANSLATION_CONTEXT "Status View" 33f75a7bf5SStephan Aßmus 34dde4ac43SPhilippe Saint-Pierre StatusView::StatusView() 3515676f3aSWim van der Meer : 36dde4ac43SPhilippe Saint-Pierre BView(NULL, B_WILL_DRAW), 37f75a7bf5SStephan Aßmus fCurrentFileInfo(NULL) 38f75a7bf5SStephan Aßmus { 39dde4ac43SPhilippe Saint-Pierre SetViewColor(kPieBGColor); 40dde4ac43SPhilippe Saint-Pierre SetLowColor(kPieBGColor); 41f75a7bf5SStephan Aßmus 42dde4ac43SPhilippe Saint-Pierre fSizeView = new BStringView(NULL, kEmptyStr); 43*2824c5d3SAdrien Destugues fSizeView->SetExplicitMinSize(BSize(StringWidth("9999.99 GiB"), 44dde4ac43SPhilippe Saint-Pierre B_SIZE_UNSET)); 45*2824c5d3SAdrien Destugues fSizeView->SetExplicitMaxSize(BSize(StringWidth("9999.99 GiB"), 46dde4ac43SPhilippe Saint-Pierre B_SIZE_UNSET)); 47f75a7bf5SStephan Aßmus 48f75a7bf5SStephan Aßmus char testLabel[256]; 498d779aa8SPhilippe Saint-Pierre snprintf(testLabel, sizeof(testLabel), B_TRANSLATE("%d files"), 508d779aa8SPhilippe Saint-Pierre 999999); 51f75a7bf5SStephan Aßmus 52dde4ac43SPhilippe Saint-Pierre fCountView = new BStringView(NULL, kEmptyStr); 53471b5ec4SPhilippe Saint-Pierre float width, height; 54471b5ec4SPhilippe Saint-Pierre fCountView->GetPreferredSize(&width, &height); 558d779aa8SPhilippe Saint-Pierre fCountView->SetExplicitMinSize(BSize(StringWidth(testLabel), 568d779aa8SPhilippe Saint-Pierre B_SIZE_UNSET)); 57471b5ec4SPhilippe Saint-Pierre fCountView->SetExplicitMaxSize(BSize(B_SIZE_UNLIMITED, height)); 58f75a7bf5SStephan Aßmus 59dde4ac43SPhilippe Saint-Pierre fPathView = new BStringView(NULL, kEmptyStr); 60471b5ec4SPhilippe Saint-Pierre fPathView->GetPreferredSize(&width, &height); 61471b5ec4SPhilippe Saint-Pierre fPathView->SetExplicitMaxSize(BSize(B_SIZE_UNLIMITED, height)); 62f75a7bf5SStephan Aßmus 638d779aa8SPhilippe Saint-Pierre fRefreshBtn = new BButton(NULL, B_TRANSLATE("Scan"), 648d779aa8SPhilippe Saint-Pierre new BMessage(kBtnRescan)); 65dde4ac43SPhilippe Saint-Pierre 66dde4ac43SPhilippe Saint-Pierre fRefreshBtn->SetExplicitMaxSize(BSize(B_SIZE_UNSET, B_SIZE_UNLIMITED)); 67dde4ac43SPhilippe Saint-Pierre 68dde4ac43SPhilippe Saint-Pierre BBox* divider1 = new BBox(BRect(), B_EMPTY_STRING, B_FOLLOW_ALL_SIDES, 69dde4ac43SPhilippe Saint-Pierre B_WILL_DRAW | B_FRAME_EVENTS, B_FANCY_BORDER); 70dde4ac43SPhilippe Saint-Pierre 71dde4ac43SPhilippe Saint-Pierre BBox* divider2 = new BBox(BRect(), B_EMPTY_STRING, B_FOLLOW_ALL_SIDES, 72dde4ac43SPhilippe Saint-Pierre B_WILL_DRAW | B_FRAME_EVENTS, B_FANCY_BORDER); 73dde4ac43SPhilippe Saint-Pierre 74dde4ac43SPhilippe Saint-Pierre divider1->SetExplicitMaxSize(BSize(B_SIZE_UNLIMITED, 1)); 75dde4ac43SPhilippe Saint-Pierre divider2->SetExplicitMaxSize(BSize(1, B_SIZE_UNLIMITED)); 76dde4ac43SPhilippe Saint-Pierre 77dde4ac43SPhilippe Saint-Pierre SetLayout(new BGroupLayout(B_VERTICAL)); 78dde4ac43SPhilippe Saint-Pierre 79471b5ec4SPhilippe Saint-Pierre AddChild(BLayoutBuilder::Group<>(B_HORIZONTAL, 0) 80471b5ec4SPhilippe Saint-Pierre .AddGroup(B_VERTICAL, 0) 81dde4ac43SPhilippe Saint-Pierre .Add(fPathView) 82dde4ac43SPhilippe Saint-Pierre .Add(divider1) 83471b5ec4SPhilippe Saint-Pierre .AddGroup(B_HORIZONTAL, 0) 84dde4ac43SPhilippe Saint-Pierre .Add(fCountView) 85dde4ac43SPhilippe Saint-Pierre .Add(divider2) 86dde4ac43SPhilippe Saint-Pierre .Add(fSizeView) 87dde4ac43SPhilippe Saint-Pierre .End() 88dde4ac43SPhilippe Saint-Pierre .End() 89dde4ac43SPhilippe Saint-Pierre .AddStrut(kSmallHMargin) 90dde4ac43SPhilippe Saint-Pierre .Add(fRefreshBtn) 91471b5ec4SPhilippe Saint-Pierre .SetInsets(kSmallVMargin, kSmallVMargin, kSmallVMargin, kSmallVMargin) 92dde4ac43SPhilippe Saint-Pierre ); 93f75a7bf5SStephan Aßmus } 94f75a7bf5SStephan Aßmus 95f75a7bf5SStephan Aßmus 96f75a7bf5SStephan Aßmus StatusView::~StatusView() 97f75a7bf5SStephan Aßmus { 98f75a7bf5SStephan Aßmus } 99f75a7bf5SStephan Aßmus 100f75a7bf5SStephan Aßmus 101f75a7bf5SStephan Aßmus void 1023e52a3d5SPhilippe Saint-Pierre StatusView::EnableRescan() 103dde4ac43SPhilippe Saint-Pierre { 1043e52a3d5SPhilippe Saint-Pierre fRefreshBtn->SetLabel(B_TRANSLATE("Rescan")); 1053e52a3d5SPhilippe Saint-Pierre fRefreshBtn->SetMessage(new BMessage(kBtnRescan)); 106dde4ac43SPhilippe Saint-Pierre } 107dde4ac43SPhilippe Saint-Pierre 108dde4ac43SPhilippe Saint-Pierre 109dde4ac43SPhilippe Saint-Pierre void 1103e52a3d5SPhilippe Saint-Pierre StatusView::EnableCancel() 111dde4ac43SPhilippe Saint-Pierre { 1123e52a3d5SPhilippe Saint-Pierre fRefreshBtn->SetLabel(B_TRANSLATE("Abort")); 1133e52a3d5SPhilippe Saint-Pierre fRefreshBtn->SetMessage(new BMessage(kBtnCancel)); 114dde4ac43SPhilippe Saint-Pierre } 115dde4ac43SPhilippe Saint-Pierre 116dde4ac43SPhilippe Saint-Pierre 117dde4ac43SPhilippe Saint-Pierre void 1184b920fd0SOliver Tappe StatusView::ShowInfo(const FileInfo* info) 119f75a7bf5SStephan Aßmus { 120f75a7bf5SStephan Aßmus if (info == fCurrentFileInfo) 121f75a7bf5SStephan Aßmus return; 122f75a7bf5SStephan Aßmus 123f75a7bf5SStephan Aßmus fCurrentFileInfo = info; 124f75a7bf5SStephan Aßmus 125f75a7bf5SStephan Aßmus if (info == NULL) { 126f75a7bf5SStephan Aßmus fPathView->SetText(kEmptyStr); 127f75a7bf5SStephan Aßmus fSizeView->SetText(kEmptyStr); 128f75a7bf5SStephan Aßmus fCountView->SetText(kEmptyStr); 129f75a7bf5SStephan Aßmus return; 130f75a7bf5SStephan Aßmus } 131f75a7bf5SStephan Aßmus 132f75a7bf5SStephan Aßmus if (!info->pseudo) { 133f75a7bf5SStephan Aßmus BNode node(&info->ref); 134f75a7bf5SStephan Aßmus if (node.InitCheck() != B_OK) { 135973f8e21SSiarzhuk Zharski fPathView->SetText(B_TRANSLATE("file unavailable")); 136f75a7bf5SStephan Aßmus fSizeView->SetText(kEmptyStr); 137f75a7bf5SStephan Aßmus fCountView->SetText(kEmptyStr); 138f75a7bf5SStephan Aßmus return; 139f75a7bf5SStephan Aßmus } 140f75a7bf5SStephan Aßmus } 141f75a7bf5SStephan Aßmus 142f75a7bf5SStephan Aßmus float viewWidth = fPathView->Bounds().Width(); 143f75a7bf5SStephan Aßmus string path; 144f75a7bf5SStephan Aßmus info->GetPath(path); 145f75a7bf5SStephan Aßmus BString pathLabel = path.c_str(); 146f75a7bf5SStephan Aßmus be_plain_font->TruncateString(&pathLabel, B_TRUNCATE_BEGINNING, viewWidth); 147f75a7bf5SStephan Aßmus fPathView->SetText(pathLabel.String()); 148f75a7bf5SStephan Aßmus 149f75a7bf5SStephan Aßmus char label[B_PATH_NAME_LENGTH]; 150fffc0e2aSPhilippe Saint-Pierre string_for_size(info->size, label, sizeof(label)); 151f75a7bf5SStephan Aßmus fSizeView->SetText(label); 152f75a7bf5SStephan Aßmus 153f75a7bf5SStephan Aßmus if (info->count > 0) { 154961fdd8cSAdrien Destugues static BMessageFormat format(B_TRANSLATE("{0, plural, " 155d6bd8338SAdrien Destugues "one{# file} other{# files}}")); 156be930298SAdrien Destugues BString label; 157961fdd8cSAdrien Destugues format.Format(label, info->count); 158f75a7bf5SStephan Aßmus fCountView->SetText(label); 159f75a7bf5SStephan Aßmus } else { 160f75a7bf5SStephan Aßmus fCountView->SetText(kEmptyStr); 161f75a7bf5SStephan Aßmus } 162f75a7bf5SStephan Aßmus } 163