xref: /haiku/src/preferences/bluetooth/BluetoothWindow.cpp (revision 9c1a9b926aa0b1890a011a44398379d1c47f09c1)
1 /*
2  * Copyright 2008-09, Oliver Ruiz Dorantes, <oliver.ruiz.dorantes_at_gmail.com>
3  * All rights reserved. Distributed under the terms of the MIT License.
4  */
5 #include "BluetoothWindow.h"
6 
7 
8 #include <Button.h>
9 #include <Catalog.h>
10 #include <GroupLayoutBuilder.h>
11 #include <Locale.h>
12 #include <Messenger.h>
13 #include <SpaceLayoutItem.h>
14 #include <TabView.h>
15 #include <Roster.h>
16 #include <stdio.h>
17 
18 #include <bluetooth/LocalDevice.h>
19 #include "RemoteDevicesView.h"
20 
21 #include "defs.h"
22 
23 #define TR_CONTEXT "Window"
24 
25 static const uint32 kMsgSetDefaults = 'dflt';
26 static const uint32 kMsgRevert = 'rvrt';
27 
28 static const uint32 kMsgStartServices = 'SrSR';
29 static const uint32 kMsgStopServices = 'StST';
30 static const uint32 kMsgShowDebug = 'ShDG';
31 
32 LocalDevice* ActiveLocalDevice = NULL;
33 
34 
35 BluetoothWindow::BluetoothWindow(BRect frame)
36  :	BWindow(frame, TR("Bluetooth"), B_TITLED_WINDOW,
37  		B_NOT_ZOOMABLE | B_AUTO_UPDATE_SIZE_LIMITS,
38  		B_ALL_WORKSPACES)
39 {
40 	SetLayout(new BGroupLayout(B_HORIZONTAL));
41 
42 	fDefaultsButton = new BButton("defaults", TR("Defaults"),
43 		new BMessage(kMsgSetDefaults), B_WILL_DRAW);
44 
45 	fRevertButton = new BButton("revert", TR("Revert"),
46 		new BMessage(kMsgRevert), B_WILL_DRAW);
47 
48 	// Add the menu bar
49 	fMenubar = new BMenuBar(Bounds(), "menu_bar");
50 
51 	// Add File menu to menu bar
52 	BMenu *menu = new BMenu(TR("Server"));
53 	menu->AddItem(new BMenuItem(TR("Start bluetooth services" B_UTF8_ELLIPSIS), new BMessage(kMsgStartServices), 0));
54 	menu->AddItem(new BMenuItem(TR("Stop bluetooth services" B_UTF8_ELLIPSIS), new BMessage(kMsgStopServices), 0));
55 	menu->AddSeparatorItem();
56 	menu->AddItem(new BMenuItem(TR("Show bluetooth console" B_UTF8_ELLIPSIS), new BMessage(kMsgStartServices), 0));
57 	menu->AddItem(new BMenuItem(TR("Refresh LocalDevices" B_UTF8_ELLIPSIS), new BMessage(kMsgRefresh), 0));
58 	fMenubar->AddItem(menu);
59 
60 	menu = new BMenu(TR("View"));
61 	menu->AddItem(new BMenuItem(TR("Connections & channels list" B_UTF8_ELLIPSIS), NULL, 0));
62 	menu->AddItem(new BMenuItem(TR("Remote devices list" B_UTF8_ELLIPSIS), NULL, 0));
63 	fMenubar->AddItem(menu);
64 
65 	menu = new BMenu(TR("Help"));
66 	menu->AddItem(new BMenuItem(TR("About" B_UTF8_ELLIPSIS), new BMessage(B_ABOUT_REQUESTED), 0));
67 	fMenubar->AddItem(menu);
68 
69 	BTabView* tabView = new BTabView("tabview", B_WIDTH_FROM_LABEL);
70 
71 	fSettingsView = new BluetoothSettingsView(TR("Settings"));
72 //	fConnChan = new ConnChanView("Connections & Channels", B_WILL_DRAW);
73 	fRemoteDevices = new RemoteDevicesView(TR("Remote devices"), B_WILL_DRAW);
74 
75 	tabView->AddTab(fRemoteDevices);
76 //	tabView->AddTab(fConnChan);
77 	tabView->AddTab(fSettingsView);
78 
79 
80 	fRevertButton->SetEnabled(false);
81 
82 	AddChild(BGroupLayoutBuilder(B_VERTICAL, 0)
83 		.Add(fMenubar)
84 		.Add(BSpaceLayoutItem::CreateVerticalStrut(5))
85 		.Add(tabView)
86 		.Add(BSpaceLayoutItem::CreateVerticalStrut(5))
87 		.Add(BGroupLayoutBuilder(B_HORIZONTAL, 0)
88 			.Add(fRevertButton)
89 			.AddGlue()
90 			.Add(fDefaultsButton)
91 		)
92 		.SetInsets(5, 5, 5, 5)
93 	);
94 }
95 
96 
97 void
98 BluetoothWindow::MessageReceived(BMessage *message)
99 {
100 	switch (message->what) {
101 		case kMsgSetDefaults:
102 /*			fColorsView -> MessageReceived(new BMessage(DEFAULT_SETTINGS));
103 			fAntialiasingSettings->SetDefaults();
104 			fDefaultsButton->SetEnabled(false);
105 			fRevertButton->SetEnabled(true);
106 */			break;
107 
108 		case kMsgRevert:
109 /*			fColorsView -> MessageReceived(new BMessage(REVERT_SETTINGS));
110 			fAntialiasingSettings->Revert();
111 			fDefaultsButton->SetEnabled(fColorsView->IsDefaultable()
112 								|| fAntialiasingSettings->IsDefaultable());
113 			fRevertButton->SetEnabled(false);
114 */			break;
115 		case kMsgStartServices:
116 			printf("kMsgStartServices\n");
117 			if (!be_roster->IsRunning(BLUETOOTH_SIGNATURE))
118 			{
119 				printf("kMsgStopServices: %s\n", strerror(be_roster->Launch(BLUETOOTH_SIGNATURE)));
120 			}
121 			break;
122 		case kMsgStopServices:
123 			printf("kMsgStopServices\n");
124 			if (be_roster->IsRunning(BLUETOOTH_SIGNATURE))
125 			{
126 				printf("kMsgStopServices: %s\n", strerror(BMessenger(BLUETOOTH_SIGNATURE).SendMessage(B_QUIT_REQUESTED)));
127 			}
128 			break;
129 
130 		case kMsgAddToRemoteList:
131 			PostMessage(message, fRemoteDevices);
132 			break;
133 		case kMsgRefresh:
134 			fSettingsView->MessageReceived(message);
135 			break;
136 		case B_ABOUT_REQUESTED:
137 			be_app->PostMessage(message);
138 			break;
139 		default:
140 			BWindow::MessageReceived(message);
141 			break;
142 	}
143 }
144 
145 
146 
147 bool
148 BluetoothWindow::QuitRequested(void)
149 {
150 	be_app->PostMessage(B_QUIT_REQUESTED);
151 	return true;
152 }
153