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