xref: /haiku/src/apps/diskusage/VolumeView.cpp (revision b46615c55ad2c8fe6de54412055a0713da3d610a)
1 /*
2  * Copyright (c) 2010 Philippe Saint-Pierre, stpere@gmail.com
3  * All rights reserved. Distributed under the terms of the MIT license.
4  *
5  * Copyright (c) 1999 Mike Steed. You are free to use and distribute this software
6  * as long as it is accompanied by it's documentation and this copyright notice.
7  * The software comes with no warranty, etc.
8  */
9 
10 
11 #include <Catalog.h>
12 #include <Box.h>
13 #include <Button.h>
14 #include <StringView.h>
15 #include <Volume.h>
16 #include <Path.h>
17 
18 #include <LayoutBuilder.h>
19 
20 #include "DiskUsage.h"
21 #include "MainWindow.h"
22 #include "PieView.h"
23 #include "StatusView.h"
24 
25 #include "VolumeView.h"
26 
27 #undef B_TRANSLATE_CONTEXT
28 #define B_TRANSLATE_CONTEXT "Volume View"
29 
30 const float kMinWinSize = 275.0;
31 
32 VolumeView::VolumeView(const char* name, BVolume* volume)
33 	: BView(name, B_WILL_DRAW)
34 {
35 	SetLayout(new BGroupLayout(B_HORIZONTAL));
36 	fPieView = new PieView(volume);
37 
38 	fPieView->SetExplicitMinSize(BSize(kMinWinSize, kMinWinSize));
39 
40 	fStatusView = new StatusView();
41 
42 	AddChild(BLayoutBuilder::Group<>(B_VERTICAL, 2)
43 		.Add(fPieView)
44 		.Add(fStatusView)
45 	);
46 }
47 
48 
49 VolumeView::~VolumeView()
50 {
51 }
52 
53 
54 void
55 VolumeView::SetRescanEnabled(bool enabled)
56 {
57 	fStatusView->SetRescanEnabled(enabled);
58 }
59 
60 
61 void
62 VolumeView::SetPath(BPath path)
63 {
64 	fPieView->SetPath(path);
65 	fStatusView->SetBtnLabel(B_TRANSLATE("Rescan"));
66 }
67 
68 
69 void
70 VolumeView::MessageReceived(BMessage* msg)
71 {
72 	switch(msg->what) {
73 		case kBtnRescan:
74 			fPieView->MessageReceived(msg);
75 			fStatusView->SetBtnLabel(B_TRANSLATE("Rescan"));
76 			break;
77 
78 		default:
79 			BView::MessageReceived(msg);
80 	}
81 }
82 
83 
84 void
85 VolumeView::ShowInfo(const FileInfo* info)
86 {
87 	fStatusView->ShowInfo(info);
88 }
89