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> 20f75a7bf5SStephan Aßmus #include <Node.h> 21f75a7bf5SStephan Aßmus #include <String.h> 22f75a7bf5SStephan Aßmus #include <StringView.h> 23f75a7bf5SStephan Aßmus 24dde4ac43SPhilippe Saint-Pierre #include <LayoutBuilder.h> 25dde4ac43SPhilippe Saint-Pierre 26973f8e21SSiarzhuk Zharski #include "DiskUsage.h" 27f75a7bf5SStephan Aßmus #include "Scanner.h" 28f75a7bf5SStephan Aßmus 29546208a5SOliver Tappe #undef B_TRANSLATION_CONTEXT 30546208a5SOliver Tappe #define B_TRANSLATION_CONTEXT "Status View" 31f75a7bf5SStephan Aßmus 32dde4ac43SPhilippe Saint-Pierre StatusView::StatusView() 3315676f3aSWim van der Meer : 34dde4ac43SPhilippe Saint-Pierre BView(NULL, B_WILL_DRAW), 35f75a7bf5SStephan Aßmus fCurrentFileInfo(NULL) 36f75a7bf5SStephan Aßmus { 37dde4ac43SPhilippe Saint-Pierre SetViewColor(kPieBGColor); 38dde4ac43SPhilippe Saint-Pierre SetLowColor(kPieBGColor); 39f75a7bf5SStephan Aßmus 40dde4ac43SPhilippe Saint-Pierre fSizeView = new BStringView(NULL, kEmptyStr); 41973f8e21SSiarzhuk Zharski fSizeView->SetExplicitMinSize(BSize(StringWidth(B_TRANSLATE("9999.99 GB")), 42dde4ac43SPhilippe Saint-Pierre B_SIZE_UNSET)); 43973f8e21SSiarzhuk Zharski fSizeView->SetExplicitMaxSize(BSize(StringWidth(B_TRANSLATE("9999.99 GB")), 44dde4ac43SPhilippe Saint-Pierre B_SIZE_UNSET)); 45f75a7bf5SStephan Aßmus 46f75a7bf5SStephan Aßmus char testLabel[256]; 478d779aa8SPhilippe Saint-Pierre snprintf(testLabel, sizeof(testLabel), B_TRANSLATE("%d files"), 488d779aa8SPhilippe Saint-Pierre 999999); 49f75a7bf5SStephan Aßmus 50dde4ac43SPhilippe Saint-Pierre fCountView = new BStringView(NULL, kEmptyStr); 51471b5ec4SPhilippe Saint-Pierre float width, height; 52471b5ec4SPhilippe Saint-Pierre fCountView->GetPreferredSize(&width, &height); 538d779aa8SPhilippe Saint-Pierre fCountView->SetExplicitMinSize(BSize(StringWidth(testLabel), 548d779aa8SPhilippe Saint-Pierre B_SIZE_UNSET)); 55471b5ec4SPhilippe Saint-Pierre fCountView->SetExplicitMaxSize(BSize(B_SIZE_UNLIMITED, height)); 56f75a7bf5SStephan Aßmus 57dde4ac43SPhilippe Saint-Pierre fPathView = new BStringView(NULL, kEmptyStr); 58471b5ec4SPhilippe Saint-Pierre fPathView->GetPreferredSize(&width, &height); 59471b5ec4SPhilippe Saint-Pierre fPathView->SetExplicitMaxSize(BSize(B_SIZE_UNLIMITED, height)); 60f75a7bf5SStephan Aßmus 618d779aa8SPhilippe Saint-Pierre fRefreshBtn = new BButton(NULL, B_TRANSLATE("Scan"), 628d779aa8SPhilippe Saint-Pierre new BMessage(kBtnRescan)); 63dde4ac43SPhilippe Saint-Pierre 64dde4ac43SPhilippe Saint-Pierre fRefreshBtn->SetExplicitMaxSize(BSize(B_SIZE_UNSET, B_SIZE_UNLIMITED)); 65dde4ac43SPhilippe Saint-Pierre 66dde4ac43SPhilippe Saint-Pierre BBox* divider1 = new BBox(BRect(), B_EMPTY_STRING, B_FOLLOW_ALL_SIDES, 67dde4ac43SPhilippe Saint-Pierre B_WILL_DRAW | B_FRAME_EVENTS, B_FANCY_BORDER); 68dde4ac43SPhilippe Saint-Pierre 69dde4ac43SPhilippe Saint-Pierre BBox* divider2 = 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 divider1->SetExplicitMaxSize(BSize(B_SIZE_UNLIMITED, 1)); 73dde4ac43SPhilippe Saint-Pierre divider2->SetExplicitMaxSize(BSize(1, B_SIZE_UNLIMITED)); 74dde4ac43SPhilippe Saint-Pierre 75dde4ac43SPhilippe Saint-Pierre SetLayout(new BGroupLayout(B_VERTICAL)); 76dde4ac43SPhilippe Saint-Pierre 77471b5ec4SPhilippe Saint-Pierre AddChild(BLayoutBuilder::Group<>(B_HORIZONTAL, 0) 78471b5ec4SPhilippe Saint-Pierre .AddGroup(B_VERTICAL, 0) 79dde4ac43SPhilippe Saint-Pierre .Add(fPathView) 80dde4ac43SPhilippe Saint-Pierre .Add(divider1) 81471b5ec4SPhilippe Saint-Pierre .AddGroup(B_HORIZONTAL, 0) 82dde4ac43SPhilippe Saint-Pierre .Add(fCountView) 83dde4ac43SPhilippe Saint-Pierre .Add(divider2) 84dde4ac43SPhilippe Saint-Pierre .Add(fSizeView) 85dde4ac43SPhilippe Saint-Pierre .End() 86dde4ac43SPhilippe Saint-Pierre .End() 87dde4ac43SPhilippe Saint-Pierre .AddStrut(kSmallHMargin) 88dde4ac43SPhilippe Saint-Pierre .Add(fRefreshBtn) 89471b5ec4SPhilippe Saint-Pierre .SetInsets(kSmallVMargin, kSmallVMargin, kSmallVMargin, kSmallVMargin) 90dde4ac43SPhilippe Saint-Pierre ); 91f75a7bf5SStephan Aßmus } 92f75a7bf5SStephan Aßmus 93f75a7bf5SStephan Aßmus 94f75a7bf5SStephan Aßmus StatusView::~StatusView() 95f75a7bf5SStephan Aßmus { 96f75a7bf5SStephan Aßmus } 97f75a7bf5SStephan Aßmus 98f75a7bf5SStephan Aßmus 99f75a7bf5SStephan Aßmus void 100*3e52a3d5SPhilippe Saint-Pierre StatusView::EnableRescan() 101dde4ac43SPhilippe Saint-Pierre { 102*3e52a3d5SPhilippe Saint-Pierre fRefreshBtn->SetLabel(B_TRANSLATE("Rescan")); 103*3e52a3d5SPhilippe Saint-Pierre fRefreshBtn->SetMessage(new BMessage(kBtnRescan)); 104dde4ac43SPhilippe Saint-Pierre } 105dde4ac43SPhilippe Saint-Pierre 106dde4ac43SPhilippe Saint-Pierre 107dde4ac43SPhilippe Saint-Pierre void 108*3e52a3d5SPhilippe Saint-Pierre StatusView::EnableCancel() 109dde4ac43SPhilippe Saint-Pierre { 110*3e52a3d5SPhilippe Saint-Pierre fRefreshBtn->SetLabel(B_TRANSLATE("Abort")); 111*3e52a3d5SPhilippe Saint-Pierre fRefreshBtn->SetMessage(new BMessage(kBtnCancel)); 112dde4ac43SPhilippe Saint-Pierre } 113dde4ac43SPhilippe Saint-Pierre 114dde4ac43SPhilippe Saint-Pierre 115dde4ac43SPhilippe Saint-Pierre void 1164b920fd0SOliver Tappe StatusView::ShowInfo(const FileInfo* info) 117f75a7bf5SStephan Aßmus { 118f75a7bf5SStephan Aßmus if (info == fCurrentFileInfo) 119f75a7bf5SStephan Aßmus return; 120f75a7bf5SStephan Aßmus 121f75a7bf5SStephan Aßmus fCurrentFileInfo = info; 122f75a7bf5SStephan Aßmus 123f75a7bf5SStephan Aßmus if (info == NULL) { 124f75a7bf5SStephan Aßmus fPathView->SetText(kEmptyStr); 125f75a7bf5SStephan Aßmus fSizeView->SetText(kEmptyStr); 126f75a7bf5SStephan Aßmus fCountView->SetText(kEmptyStr); 127f75a7bf5SStephan Aßmus return; 128f75a7bf5SStephan Aßmus } 129f75a7bf5SStephan Aßmus 130f75a7bf5SStephan Aßmus if (!info->pseudo) { 131f75a7bf5SStephan Aßmus BNode node(&info->ref); 132f75a7bf5SStephan Aßmus if (node.InitCheck() != B_OK) { 133973f8e21SSiarzhuk Zharski fPathView->SetText(B_TRANSLATE("file unavailable")); 134f75a7bf5SStephan Aßmus fSizeView->SetText(kEmptyStr); 135f75a7bf5SStephan Aßmus fCountView->SetText(kEmptyStr); 136f75a7bf5SStephan Aßmus return; 137f75a7bf5SStephan Aßmus } 138f75a7bf5SStephan Aßmus } 139f75a7bf5SStephan Aßmus 140f75a7bf5SStephan Aßmus float viewWidth = fPathView->Bounds().Width(); 141f75a7bf5SStephan Aßmus string path; 142f75a7bf5SStephan Aßmus info->GetPath(path); 143f75a7bf5SStephan Aßmus BString pathLabel = path.c_str(); 144f75a7bf5SStephan Aßmus be_plain_font->TruncateString(&pathLabel, B_TRUNCATE_BEGINNING, viewWidth); 145f75a7bf5SStephan Aßmus fPathView->SetText(pathLabel.String()); 146f75a7bf5SStephan Aßmus 147f75a7bf5SStephan Aßmus char label[B_PATH_NAME_LENGTH]; 1488d779aa8SPhilippe Saint-Pierre size_to_string(info->size, label, sizeof(label)); 149f75a7bf5SStephan Aßmus fSizeView->SetText(label); 150f75a7bf5SStephan Aßmus 151f75a7bf5SStephan Aßmus if (info->count > 0) { 152f75a7bf5SStephan Aßmus char label[256]; 1538d779aa8SPhilippe Saint-Pierre snprintf(label, sizeof(label), (info->count == 1) ? 1548d779aa8SPhilippe Saint-Pierre B_TRANSLATE("%d file") : B_TRANSLATE("%d files"), info->count); 155f75a7bf5SStephan Aßmus fCountView->SetText(label); 156f75a7bf5SStephan Aßmus } else { 157f75a7bf5SStephan Aßmus fCountView->SetText(kEmptyStr); 158f75a7bf5SStephan Aßmus } 159f75a7bf5SStephan Aßmus } 160