btrfs: Attempt to fix GCC2 build.
[haiku.git] / src / apps / diskusage / StatusView.cpp
blobe1aa911df62cc3bdaefe5d04b53b7700c4838598
1 /*
2 * Copyright (c) 2010 Philippe St-Pierre <stpere@gmail.com>. All rights reserved.
3 * Copyright (c) 2008 Stephan Aßmus <superstippi@gmx.de>. All rights reserved.
4 * Distributed under the terms of the MIT/X11 license.
6 * Copyright (c) 1999 Mike Steed. You are free to use and distribute this software
7 * as long as it is accompanied by it's documentation and this copyright notice.
8 * The software comes with no warranty, etc.
9 */
12 #include "StatusView.h"
14 #include <math.h>
15 #include <stdio.h>
17 #include <Catalog.h>
18 #include <Box.h>
19 #include <Button.h>
20 #include <MessageFormat.h>
21 #include <Node.h>
22 #include <String.h>
23 #include <StringForSize.h>
24 #include <StringView.h>
26 #include <LayoutBuilder.h>
28 #include "DiskUsage.h"
29 #include "Scanner.h"
31 #undef B_TRANSLATION_CONTEXT
32 #define B_TRANSLATION_CONTEXT "Status View"
34 StatusView::StatusView()
36 BView(NULL, B_WILL_DRAW),
37 fCurrentFileInfo(NULL)
39 SetViewColor(kPieBGColor);
40 SetLowColor(kPieBGColor);
42 fSizeView = new BStringView(NULL, kEmptyStr);
43 fSizeView->SetExplicitMinSize(BSize(StringWidth("9999.99 GiB"),
44 B_SIZE_UNSET));
45 fSizeView->SetExplicitMaxSize(BSize(StringWidth("9999.99 GiB"),
46 B_SIZE_UNSET));
48 char testLabel[256];
49 snprintf(testLabel, sizeof(testLabel), B_TRANSLATE_COMMENT("%d files",
50 "For UI layouting only, use the longest plural form for your language"),
51 999999);
53 fCountView = new BStringView(NULL, kEmptyStr);
54 float width, height;
55 fCountView->GetPreferredSize(&width, &height);
56 fCountView->SetExplicitMinSize(BSize(StringWidth(testLabel),
57 B_SIZE_UNSET));
58 fCountView->SetExplicitMaxSize(BSize(B_SIZE_UNLIMITED, height));
60 fPathView = new BStringView(NULL, kEmptyStr);
61 fPathView->GetPreferredSize(&width, &height);
62 fPathView->SetExplicitMaxSize(BSize(B_SIZE_UNLIMITED, height));
64 fRefreshBtn = new BButton(NULL, B_TRANSLATE("Scan"),
65 new BMessage(kBtnRescan));
67 fRefreshBtn->SetExplicitMaxSize(BSize(B_SIZE_UNSET, B_SIZE_UNLIMITED));
69 BBox* divider1 = new BBox(BRect(), B_EMPTY_STRING, B_FOLLOW_ALL_SIDES,
70 B_WILL_DRAW | B_FRAME_EVENTS, B_FANCY_BORDER);
72 BBox* divider2 = new BBox(BRect(), B_EMPTY_STRING, B_FOLLOW_ALL_SIDES,
73 B_WILL_DRAW | B_FRAME_EVENTS, B_FANCY_BORDER);
75 divider1->SetExplicitMaxSize(BSize(B_SIZE_UNLIMITED, 1));
76 divider2->SetExplicitMaxSize(BSize(1, B_SIZE_UNLIMITED));
78 SetLayout(new BGroupLayout(B_VERTICAL));
80 AddChild(BLayoutBuilder::Group<>(B_HORIZONTAL, 0)
81 .AddGroup(B_VERTICAL, 0)
82 .Add(fPathView)
83 .Add(divider1)
84 .AddGroup(B_HORIZONTAL, 0)
85 .Add(fCountView)
86 .Add(divider2)
87 .Add(fSizeView)
88 .End()
89 .End()
90 .AddStrut(kSmallHMargin)
91 .Add(fRefreshBtn)
92 .SetInsets(kSmallVMargin, kSmallVMargin, kSmallVMargin, kSmallVMargin)
97 StatusView::~StatusView()
102 void
103 StatusView::EnableRescan()
105 fRefreshBtn->SetLabel(B_TRANSLATE("Rescan"));
106 fRefreshBtn->SetMessage(new BMessage(kBtnRescan));
110 void
111 StatusView::EnableCancel()
113 fRefreshBtn->SetLabel(B_TRANSLATE("Abort"));
114 fRefreshBtn->SetMessage(new BMessage(kBtnCancel));
118 void
119 StatusView::ShowInfo(const FileInfo* info)
121 if (info == fCurrentFileInfo)
122 return;
124 fCurrentFileInfo = info;
126 if (info == NULL) {
127 fPathView->SetText(kEmptyStr);
128 fSizeView->SetText(kEmptyStr);
129 fCountView->SetText(kEmptyStr);
130 return;
133 if (!info->pseudo) {
134 BNode node(&info->ref);
135 if (node.InitCheck() != B_OK) {
136 fPathView->SetText(B_TRANSLATE("file unavailable"));
137 fSizeView->SetText(kEmptyStr);
138 fCountView->SetText(kEmptyStr);
139 return;
143 float viewWidth = fPathView->Bounds().Width();
144 string path;
145 info->GetPath(path);
146 BString pathLabel = path.c_str();
147 be_plain_font->TruncateString(&pathLabel, B_TRUNCATE_BEGINNING, viewWidth);
148 fPathView->SetText(pathLabel.String());
150 char label[B_PATH_NAME_LENGTH];
151 string_for_size(info->size, label, sizeof(label));
152 fSizeView->SetText(label);
154 if (info->count > 0) {
155 static BMessageFormat format(B_TRANSLATE("{0, plural, "
156 "one{# file} other{# files}}"));
157 BString label;
158 format.Format(label, info->count);
159 fCountView->SetText(label);
160 } else {
161 fCountView->SetText(kEmptyStr);