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.
12 #include "StatusView.h"
20 #include <MessageFormat.h>
23 #include <StringForSize.h>
24 #include <StringView.h>
26 #include <LayoutBuilder.h>
28 #include "DiskUsage.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"),
45 fSizeView
->SetExplicitMaxSize(BSize(StringWidth("9999.99 GiB"),
49 snprintf(testLabel
, sizeof(testLabel
), B_TRANSLATE_COMMENT("%d files",
50 "For UI layouting only, use the longest plural form for your language"),
53 fCountView
= new BStringView(NULL
, kEmptyStr
);
55 fCountView
->GetPreferredSize(&width
, &height
);
56 fCountView
->SetExplicitMinSize(BSize(StringWidth(testLabel
),
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)
84 .AddGroup(B_HORIZONTAL
, 0)
90 .AddStrut(kSmallHMargin
)
92 .SetInsets(kSmallVMargin
, kSmallVMargin
, kSmallVMargin
, kSmallVMargin
)
97 StatusView::~StatusView()
103 StatusView::EnableRescan()
105 fRefreshBtn
->SetLabel(B_TRANSLATE("Rescan"));
106 fRefreshBtn
->SetMessage(new BMessage(kBtnRescan
));
111 StatusView::EnableCancel()
113 fRefreshBtn
->SetLabel(B_TRANSLATE("Abort"));
114 fRefreshBtn
->SetMessage(new BMessage(kBtnCancel
));
119 StatusView::ShowInfo(const FileInfo
* info
)
121 if (info
== fCurrentFileInfo
)
124 fCurrentFileInfo
= info
;
127 fPathView
->SetText(kEmptyStr
);
128 fSizeView
->SetText(kEmptyStr
);
129 fCountView
->SetText(kEmptyStr
);
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
);
143 float viewWidth
= fPathView
->Bounds().Width();
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}}"));
158 format
.Format(label
, info
->count
);
159 fCountView
->SetText(label
);
161 fCountView
->SetText(kEmptyStr
);