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