xref: /haiku/src/apps/diskusage/MainWindow.cpp (revision b46615c55ad2c8fe6de54412055a0713da3d610a)
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 <Catalog.h>
14 #include <Node.h>
15 #include <Roster.h>
16 #include <Screen.h>
17 
18 #include <LayoutBuilder.h>
19 
20 #include "DiskUsage.h"
21 #include "ControlsView.h"
22 
23 #undef B_TRANSLATE_CONTEXT
24 #define B_TRANSLATE_CONTEXT "MainWindow"
25 
26 MainWindow::MainWindow(BRect pieRect)
27 	:
28 	BWindow(pieRect, B_TRANSLATE_SYSTEM_NAME("DiskUsage"), B_TITLED_WINDOW,
29 		B_ASYNCHRONOUS_CONTROLS | B_QUIT_ON_WINDOW_CLOSE
30 		| B_AUTO_UPDATE_SIZE_LIMITS)
31 {
32 	fControlsView = new ControlsView();
33 
34 	SetLayout(new BGroupLayout(B_VERTICAL));
35 
36 	AddChild(BLayoutBuilder::Group<>(B_VERTICAL)
37 		.Add(fControlsView)
38 		.SetInsets(5, 5, 5, 5)
39 	);
40 	float maxHeight = BScreen(this).Frame().Height() - 12;
41 	fControlsView->SetExplicitMaxSize(BSize(maxHeight, maxHeight));
42 }
43 
44 
45 MainWindow::~MainWindow()
46 {
47 }
48 
49 
50 void
51 MainWindow::MessageReceived(BMessage* message)
52 {
53 	switch (message->what) {
54 		case kBtnRescan:
55 			fControlsView->MessageReceived(message);
56 			break;
57 		case B_SIMPLE_DATA:
58 		case B_REFS_RECEIVED:
59 			fControlsView->MessageReceived(message);
60 			break;
61 
62 		case kBtnHelp:
63 			if (helpFileWasFound)
64 				be_roster->Launch(&helpFileRef);
65 			break;
66 
67 		default:
68 			BWindow::MessageReceived(message);
69 			break;
70 	}
71 }
72 
73 
74 bool
75 MainWindow::QuitRequested()
76 {
77 	be_app->PostMessage(B_QUIT_REQUESTED);
78 	return true;
79 }
80 
81 
82 // #pragma mark -
83 
84 
85 void
86 MainWindow::SetRescanEnabled(bool enabled)
87 {
88 	fControlsView->SetRescanEnabled(enabled);
89 }
90 
91 
92 void
93 MainWindow::ShowInfo(const FileInfo* info)
94 {
95 	fControlsView->ShowInfo(info);
96 }
97 
98 
99 BVolume*
100 MainWindow::FindDeviceFor(dev_t device, bool invoke)
101 {
102 	return fControlsView->FindDeviceFor(device, invoke);
103 }
104