xref: /haiku/src/apps/devices/DevicesApplication.cpp (revision 9760dcae2038d47442f4658c2575844c6cf92c40)
1 /*
2  * Copyright 2008-2009 Haiku Inc. All rights reserved.
3  * Distributed under the terms of the MIT license.
4  *
5  * Authors:
6  *		Pieter Panman
7  */
8 
9 #include <Alert.h>
10 #include <Application.h>
11 #include <TextView.h>
12 
13 #include "DevicesView.h"
14 
15 
16 class DevicesApplication : public BApplication {
17 public:
18 								DevicesApplication();
19 	virtual	void				AboutRequested();
20 	static	void				ShowAbout();
21 };
22 
23 
24 class DevicesWindow : public BWindow {
25 public:
26 								DevicesWindow();
27 	virtual	void				MessageReceived(BMessage* message);
28 private:
29 			DevicesView*		fDevicesView;
30 };
31 
32 
33 DevicesApplication::DevicesApplication()
34 	:
35 	BApplication("application/x-vnd.Haiku-Devices")
36 {
37 	DevicesWindow* window = new DevicesWindow();
38 	window->CenterOnScreen();
39 	window->Show();
40 }
41 
42 
43 void
44 DevicesApplication::AboutRequested()
45 {
46 	ShowAbout();
47 }
48 
49 
50 void
51 DevicesApplication::ShowAbout()
52 {
53 	BAlert* alert = new BAlert("about", "Devices\n"
54 		"\twritten by Pieter Panman\n"
55 		"\n"
56 		"\tBased on listdev by Jérôme Duval\n"
57 		"\tand the previous Devices preference\n"
58 		"\tby Jérôme Duval and Sikosis\n"
59 		"\tCopyright 2009, Haiku, Inc.\n", "OK");
60 	BTextView* view = alert->TextView();
61 	BFont font;
62 
63 	view->SetStylable(true);
64 
65 	view->GetFont(&font);
66 	font.SetSize(18);
67 	font.SetFace(B_BOLD_FACE);
68 	view->SetFontAndColor(0, 7, &font);
69 
70 	alert->Go();
71 }
72 
73 
74 DevicesWindow::DevicesWindow()
75 	:
76 	BWindow(BRect(50, 50, 750, 550), "Devices", B_TITLED_WINDOW,
77 		B_ASYNCHRONOUS_CONTROLS | B_AUTO_UPDATE_SIZE_LIMITS
78 			| B_QUIT_ON_WINDOW_CLOSE)
79 {
80 	float minWidth;
81 	float maxWidth;
82 	float minHeight;
83 	float maxHeight;
84 	GetSizeLimits(&minWidth, &maxWidth, &minHeight, &maxHeight);
85 	minWidth = 600;
86 	minHeight = 300;
87 	SetSizeLimits(minWidth, maxWidth, minHeight, maxHeight);
88 	fDevicesView = new DevicesView(Bounds());
89 	AddChild(fDevicesView);
90 }
91 
92 
93 void
94 DevicesWindow::MessageReceived(BMessage* message)
95 {
96 	switch (message->what) {
97 		case kMsgRefresh:
98 		case kMsgReportCompatibility:
99 		case kMsgGenerateSysInfo:
100 		case kMsgSelectionChanged:
101 		case kMsgOrderCategory:
102 		case kMsgOrderConnection:
103 			fDevicesView->MessageReceived(message);
104 			break;
105 
106 		default:
107 			BWindow::MessageReceived(message);
108 			break;
109 	}
110 }
111 
112 
113 int
114 main()
115 {
116 	DevicesApplication app;
117 	app.Run();
118 	return 0;
119 }
120