xref: /haiku/src/apps/diskusage/MainWindow.cpp (revision b6b0567fbd186f8ce8a0c90bdc7a7b5b4c649678)
1 /*
2  * Copyright (c) 2008 Stephan Aßmus <superstippi@gmx.de>.
3  * Copyright (c) 2009 Philippe Saint-Pierre, stpere@gmail.com
4  * All rights reserved. Distributed under the terms of the MIT license.
5  *
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  */
10 #include "MainWindow.h"
11 
12 #include <Application.h>
13 #include <Node.h>
14 #include <Roster.h>
15 #include <Screen.h>
16 
17 #include "Common.h"
18 #include "ControlsView.h"
19 #include "PieView.h"
20 #include "StatusView.h"
21 
22 
23 const float kMinWinSize = 275.0;
24 
25 
26 MainWindow::MainWindow(BRect pieRect)
27 	: BWindow(pieRect, "DiskUsage", B_TITLED_WINDOW,
28 		B_ASYNCHRONOUS_CONTROLS | B_QUIT_ON_WINDOW_CLOSE)
29 {
30 	BRect r = Bounds();
31 	r.bottom = r.top + 1.0;
32 	fControlsView = new ControlsView(r);
33 	float cvHeight = fControlsView->Bounds().Height();
34 	AddChild(fControlsView);
35 
36 	r = Bounds();
37 	r.top = r.bottom - 1.0;
38 	fStatusView = new StatusView(r);
39 	float svHeight = fStatusView->Bounds().Height();
40 
41 	float winHeight = pieRect.Height() + cvHeight + svHeight;
42 	fStatusView->MoveTo(0.0, winHeight - svHeight);
43 	ResizeTo(r.Width(), winHeight);
44 
45 	AddChild(fStatusView);
46 
47 	r = fControlsView->Frame();
48 	r.top = r.bottom + 1.0;
49 	r.bottom = fStatusView->Frame().top - 1.0;
50 	fPieView = new PieView(r, this);
51 	AddChild(fPieView);
52 
53 	Show();
54 
55 	// Note: The following code is semi-broken because BScreen::Frame()
56 	// returns incorrect dimensions for the G200 in 1152x864 mode.  I reported
57 	// this bug, and Be said it's not a bug -- the Matrox driver actually uses
58 	// a resolution of 1152x900 in that mode.  Oh well.
59 	Lock();
60 	float extraHeight = fControlsView->Bounds().Height() + fStatusView->Bounds().Height();
61 	float minHeight = kMinWinSize + extraHeight;
62 	float maxHeight = BScreen(this).Frame().Height();
63 	float maxWidth = maxHeight - extraHeight;
64 	Unlock();
65 
66 	SetSizeLimits(kMinWinSize, maxWidth, minHeight, maxHeight);
67 }
68 
69 
70 MainWindow::~MainWindow()
71 {
72 }
73 
74 
75 void
76 MainWindow::MessageReceived(BMessage* message)
77 {
78 	switch (message->what) {
79 		case kBtnRescan:
80 		case kMenuSelectVol:
81 		case B_REFS_RECEIVED:
82 			fPieView->MessageReceived(message);
83 			break;
84 
85 		case kBtnHelp:
86 			be_roster->Launch(&kHelpFileRef);
87 			break;
88 
89 		default:
90 			BWindow::MessageReceived(message);
91 			break;
92 	}
93 }
94 
95 
96 bool
97 MainWindow::QuitRequested()
98 {
99 	be_app->PostMessage(B_QUIT_REQUESTED);
100 	return true;
101 }
102 
103 
104 // #pragma mark -
105 
106 
107 void
108 MainWindow::ShowInfo(const FileInfo* info)
109 {
110 	fStatusView->Show(info);
111 }
112 
113 
114 void
115 MainWindow::SetRescanEnabled(bool enabled)
116 {
117 	fControlsView->SetRescanEnabled(enabled);
118 }
119 
120 
121 BVolume*
122 MainWindow::FindDeviceFor(dev_t device, bool invoke)
123 {
124 	return fControlsView->FindDeviceFor(device, invoke);
125 }
126