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); 432824c5d3SAdrien Destugues fSizeView->SetExplicitMinSize(BSize(StringWidth("9999.99 GiB"), 44dde4ac43SPhilippe Saint-Pierre B_SIZE_UNSET)); 452824c5d3SAdrien Destugues fSizeView->SetExplicitMaxSize(BSize(StringWidth("9999.99 GiB"), 46dde4ac43SPhilippe Saint-Pierre B_SIZE_UNSET)); 47f75a7bf5SStephan Aßmus 48f75a7bf5SStephan Aßmus char testLabel[256]; 49*03ad73fcSAdrien Destugues snprintf(testLabel, sizeof(testLabel), B_TRANSLATE_COMMENT("%d files", 50*03ad73fcSAdrien Destugues "For UI layouting only, use the longest plural form for your language"), 518d779aa8SPhilippe Saint-Pierre 999999); 52f75a7bf5SStephan Aßmus 53dde4ac43SPhilippe Saint-Pierre fCountView = new BStringView(NULL, kEmptyStr); 54471b5ec4SPhilippe Saint-Pierre float width, height; 55471b5ec4SPhilippe Saint-Pierre fCountView->GetPreferredSize(&width, &height); 568d779aa8SPhilippe Saint-Pierre fCountView->SetExplicitMinSize(BSize(StringWidth(testLabel), 578d779aa8SPhilippe Saint-Pierre B_SIZE_UNSET)); 58471b5ec4SPhilippe Saint-Pierre fCountView->SetExplicitMaxSize(BSize(B_SIZE_UNLIMITED, height)); 59f75a7bf5SStephan Aßmus 60dde4ac43SPhilippe Saint-Pierre fPathView = new BStringView(NULL, kEmptyStr); 61471b5ec4SPhilippe Saint-Pierre fPathView->GetPreferredSize(&width, &height); 62471b5ec4SPhilippe Saint-Pierre fPathView->SetExplicitMaxSize(BSize(B_SIZE_UNLIMITED, height)); 63f75a7bf5SStephan Aßmus 648d779aa8SPhilippe Saint-Pierre fRefreshBtn = new BButton(NULL, B_TRANSLATE("Scan"), 658d779aa8SPhilippe Saint-Pierre new BMessage(kBtnRescan)); 66dde4ac43SPhilippe Saint-Pierre 67dde4ac43SPhilippe Saint-Pierre fRefreshBtn->SetExplicitMaxSize(BSize(B_SIZE_UNSET, B_SIZE_UNLIMITED)); 68dde4ac43SPhilippe Saint-Pierre 69dde4ac43SPhilippe Saint-Pierre BBox* divider1 = new BBox(BRect(), B_EMPTY_STRING, B_FOLLOW_ALL_SIDES, 70dde4ac43SPhilippe Saint-Pierre B_WILL_DRAW | B_FRAME_EVENTS, B_FANCY_BORDER); 71dde4ac43SPhilippe Saint-Pierre 72dde4ac43SPhilippe Saint-Pierre BBox* divider2 = new BBox(BRect(), B_EMPTY_STRING, B_FOLLOW_ALL_SIDES, 73dde4ac43SPhilippe Saint-Pierre B_WILL_DRAW | B_FRAME_EVENTS, B_FANCY_BORDER); 74dde4ac43SPhilippe Saint-Pierre 75dde4ac43SPhilippe Saint-Pierre divider1->SetExplicitMaxSize(BSize(B_SIZE_UNLIMITED, 1)); 76dde4ac43SPhilippe Saint-Pierre divider2->SetExplicitMaxSize(BSize(1, B_SIZE_UNLIMITED)); 77dde4ac43SPhilippe Saint-Pierre 78dde4ac43SPhilippe Saint-Pierre SetLayout(new BGroupLayout(B_VERTICAL)); 79dde4ac43SPhilippe Saint-Pierre 80471b5ec4SPhilippe Saint-Pierre AddChild(BLayoutBuilder::Group<>(B_HORIZONTAL, 0) 81471b5ec4SPhilippe Saint-Pierre .AddGroup(B_VERTICAL, 0) 82dde4ac43SPhilippe Saint-Pierre .Add(fPathView) 83dde4ac43SPhilippe Saint-Pierre .Add(divider1) 84471b5ec4SPhilippe Saint-Pierre .AddGroup(B_HORIZONTAL, 0) 85dde4ac43SPhilippe Saint-Pierre .Add(fCountView) 86dde4ac43SPhilippe Saint-Pierre .Add(divider2) 87dde4ac43SPhilippe Saint-Pierre .Add(fSizeView) 88dde4ac43SPhilippe Saint-Pierre .End() 89dde4ac43SPhilippe Saint-Pierre .End() 90dde4ac43SPhilippe Saint-Pierre .AddStrut(kSmallHMargin) 91dde4ac43SPhilippe Saint-Pierre .Add(fRefreshBtn) 92471b5ec4SPhilippe Saint-Pierre .SetInsets(kSmallVMargin, kSmallVMargin, kSmallVMargin, kSmallVMargin) 93dde4ac43SPhilippe Saint-Pierre ); 94f75a7bf5SStephan Aßmus } 95f75a7bf5SStephan Aßmus 96f75a7bf5SStephan Aßmus 97f75a7bf5SStephan Aßmus StatusView::~StatusView() 98f75a7bf5SStephan Aßmus { 99f75a7bf5SStephan Aßmus } 100f75a7bf5SStephan Aßmus 101f75a7bf5SStephan Aßmus 102f75a7bf5SStephan Aßmus void 1033e52a3d5SPhilippe Saint-Pierre StatusView::EnableRescan() 104dde4ac43SPhilippe Saint-Pierre { 1053e52a3d5SPhilippe Saint-Pierre fRefreshBtn->SetLabel(B_TRANSLATE("Rescan")); 1063e52a3d5SPhilippe Saint-Pierre fRefreshBtn->SetMessage(new BMessage(kBtnRescan)); 107dde4ac43SPhilippe Saint-Pierre } 108dde4ac43SPhilippe Saint-Pierre 109dde4ac43SPhilippe Saint-Pierre 110dde4ac43SPhilippe Saint-Pierre void 1113e52a3d5SPhilippe Saint-Pierre StatusView::EnableCancel() 112dde4ac43SPhilippe Saint-Pierre { 1133e52a3d5SPhilippe Saint-Pierre fRefreshBtn->SetLabel(B_TRANSLATE("Abort")); 1143e52a3d5SPhilippe Saint-Pierre fRefreshBtn->SetMessage(new BMessage(kBtnCancel)); 115dde4ac43SPhilippe Saint-Pierre } 116dde4ac43SPhilippe Saint-Pierre 117dde4ac43SPhilippe Saint-Pierre 118dde4ac43SPhilippe Saint-Pierre void 1194b920fd0SOliver Tappe StatusView::ShowInfo(const FileInfo* info) 120f75a7bf5SStephan Aßmus { 121f75a7bf5SStephan Aßmus if (info == fCurrentFileInfo) 122f75a7bf5SStephan Aßmus return; 123f75a7bf5SStephan Aßmus 124f75a7bf5SStephan Aßmus fCurrentFileInfo = info; 125f75a7bf5SStephan Aßmus 126f75a7bf5SStephan Aßmus if (info == NULL) { 127f75a7bf5SStephan Aßmus fPathView->SetText(kEmptyStr); 128f75a7bf5SStephan Aßmus fSizeView->SetText(kEmptyStr); 129f75a7bf5SStephan Aßmus fCountView->SetText(kEmptyStr); 130f75a7bf5SStephan Aßmus return; 131f75a7bf5SStephan Aßmus } 132f75a7bf5SStephan Aßmus 133f75a7bf5SStephan Aßmus if (!info->pseudo) { 134f75a7bf5SStephan Aßmus BNode node(&info->ref); 135f75a7bf5SStephan Aßmus if (node.InitCheck() != B_OK) { 136973f8e21SSiarzhuk Zharski fPathView->SetText(B_TRANSLATE("file unavailable")); 137f75a7bf5SStephan Aßmus fSizeView->SetText(kEmptyStr); 138f75a7bf5SStephan Aßmus fCountView->SetText(kEmptyStr); 139f75a7bf5SStephan Aßmus return; 140f75a7bf5SStephan Aßmus } 141f75a7bf5SStephan Aßmus } 142f75a7bf5SStephan Aßmus 143f75a7bf5SStephan Aßmus float viewWidth = fPathView->Bounds().Width(); 144f75a7bf5SStephan Aßmus string path; 145f75a7bf5SStephan Aßmus info->GetPath(path); 146f75a7bf5SStephan Aßmus BString pathLabel = path.c_str(); 147f75a7bf5SStephan Aßmus be_plain_font->TruncateString(&pathLabel, B_TRUNCATE_BEGINNING, viewWidth); 148f75a7bf5SStephan Aßmus fPathView->SetText(pathLabel.String()); 149f75a7bf5SStephan Aßmus 150f75a7bf5SStephan Aßmus char label[B_PATH_NAME_LENGTH]; 151fffc0e2aSPhilippe Saint-Pierre string_for_size(info->size, label, sizeof(label)); 152f75a7bf5SStephan Aßmus fSizeView->SetText(label); 153f75a7bf5SStephan Aßmus 154f75a7bf5SStephan Aßmus if (info->count > 0) { 155961fdd8cSAdrien Destugues static BMessageFormat format(B_TRANSLATE("{0, plural, " 156d6bd8338SAdrien Destugues "one{# file} other{# files}}")); 157be930298SAdrien Destugues BString label; 158961fdd8cSAdrien Destugues format.Format(label, info->count); 159f75a7bf5SStephan Aßmus fCountView->SetText(label); 160f75a7bf5SStephan Aßmus } else { 161f75a7bf5SStephan Aßmus fCountView->SetText(kEmptyStr); 162f75a7bf5SStephan Aßmus } 163f75a7bf5SStephan Aßmus } 164