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.
5 #include "BluetoothWindow.h"
10 #include <GroupLayoutBuilder.h>
11 #include <Messenger.h>
12 #include <SpaceLayoutItem.h>
17 #include <bluetooth/LocalDevice.h>
18 #include "RemoteDevicesView.h"
23 #undef B_TRANSLATION_CONTEXT
24 #define B_TRANSLATION_CONTEXT "Window"
26 static const uint32 kMsgSetDefaults
= 'dflt';
27 static const uint32 kMsgRevert
= 'rvrt';
29 static const uint32 kMsgStartServices
= 'SrSR';
30 static const uint32 kMsgStopServices
= 'StST';
31 static const uint32 kMsgShowDebug
= 'ShDG';
33 LocalDevice
* ActiveLocalDevice
= NULL
;
36 BluetoothWindow::BluetoothWindow(BRect frame
)
38 BWindow(frame
, B_TRANSLATE_SYSTEM_NAME("Bluetooth"), B_TITLED_WINDOW
,
39 B_NOT_ZOOMABLE
| B_AUTO_UPDATE_SIZE_LIMITS
)
41 SetLayout(new BGroupLayout(B_HORIZONTAL
));
43 fDefaultsButton
= new BButton("defaults", B_TRANSLATE("Defaults"),
44 new BMessage(kMsgSetDefaults
), B_WILL_DRAW
);
46 fRevertButton
= new BButton("revert", B_TRANSLATE("Revert"),
47 new BMessage(kMsgRevert
), B_WILL_DRAW
);
50 fMenubar
= new BMenuBar(Bounds(), "menu_bar");
52 // Add File menu to menu bar
53 BMenu
* menu
= new BMenu(B_TRANSLATE("Server"));
54 menu
->AddItem(new BMenuItem(
55 B_TRANSLATE("Start bluetooth services" B_UTF8_ELLIPSIS
),
56 new BMessage(kMsgStartServices
), 0));
57 menu
->AddItem(new BMenuItem(
58 B_TRANSLATE("Stop bluetooth services" B_UTF8_ELLIPSIS
),
59 new BMessage(kMsgStopServices
), 0));
60 menu
->AddSeparatorItem();
61 menu
->AddItem(new BMenuItem(
62 B_TRANSLATE("Show bluetooth console" B_UTF8_ELLIPSIS
),
63 new BMessage(kMsgStartServices
), 0));
64 menu
->AddItem(new BMenuItem(
65 B_TRANSLATE("Refresh LocalDevices" B_UTF8_ELLIPSIS
),
66 new BMessage(kMsgRefresh
), 0));
67 fMenubar
->AddItem(menu
);
69 menu
= new BMenu(B_TRANSLATE("View"));
70 menu
->AddItem(new BMenuItem(
71 B_TRANSLATE("Connections & channels" B_UTF8_ELLIPSIS
), NULL
, 0));
72 menu
->AddItem(new BMenuItem(
73 B_TRANSLATE("Remote devices list" B_UTF8_ELLIPSIS
), NULL
, 0));
74 fMenubar
->AddItem(menu
);
76 menu
= new BMenu(B_TRANSLATE("Help"));
77 menu
->AddItem(new BMenuItem(B_TRANSLATE("About Bluetooth" B_UTF8_ELLIPSIS
),
78 new BMessage(B_ABOUT_REQUESTED
), 0));
79 fMenubar
->AddItem(menu
);
81 BTabView
* tabView
= new BTabView("tabview", B_WIDTH_FROM_LABEL
);
83 fSettingsView
= new BluetoothSettingsView(B_TRANSLATE("Settings"));
84 // fConnChan = new ConnChanView("Connections & Channels", B_WILL_DRAW);
85 fRemoteDevices
= new RemoteDevicesView(
86 B_TRANSLATE("Remote devices"), B_WILL_DRAW
);
88 tabView
->AddTab(fRemoteDevices
);
89 // tabView->AddTab(fConnChan);
90 tabView
->AddTab(fSettingsView
);
92 fRevertButton
->SetEnabled(false);
94 AddChild(BGroupLayoutBuilder(B_VERTICAL
, 0)
96 .Add(BSpaceLayoutItem::CreateVerticalStrut(5))
98 .Add(BSpaceLayoutItem::CreateVerticalStrut(5))
99 .Add(BGroupLayoutBuilder(B_HORIZONTAL
, 0)
102 .Add(fDefaultsButton
)
104 .SetInsets(5, 5, 5, 5)
110 BluetoothWindow::MessageReceived(BMessage
* message
)
112 switch (message
->what
) {
113 case kMsgSetDefaults
:
114 /* fColorsView -> MessageReceived(new BMessage(DEFAULT_SETTINGS));
115 fAntialiasingSettings->SetDefaults();
116 fDefaultsButton->SetEnabled(false);
117 fRevertButton->SetEnabled(true);
121 /* fColorsView -> MessageReceived(new BMessage(REVERT_SETTINGS));
122 fAntialiasingSettings->Revert();
123 fDefaultsButton->SetEnabled(fColorsView->IsDefaultable()
124 || fAntialiasingSettings->IsDefaultable());
125 fRevertButton->SetEnabled(false);
127 case kMsgStartServices
:
128 printf("kMsgStartServices\n");
129 if (!be_roster
->IsRunning(BLUETOOTH_SIGNATURE
)) {
132 error
= be_roster
->Launch(BLUETOOTH_SIGNATURE
);
133 printf("kMsgStartServices: %s\n", strerror(error
));
137 case kMsgStopServices
:
138 printf("kMsgStopServices\n");
139 if (be_roster
->IsRunning(BLUETOOTH_SIGNATURE
)) {
142 error
= BMessenger(BLUETOOTH_SIGNATURE
).SendMessage(B_QUIT_REQUESTED
);
143 printf("kMsgStopServices: %s\n", strerror(error
));
147 case kMsgAddToRemoteList
:
148 PostMessage(message
, fRemoteDevices
);
151 fSettingsView
->MessageReceived(message
);
153 case B_ABOUT_REQUESTED
:
154 be_app
->PostMessage(message
);
157 BWindow::MessageReceived(message
);
164 BluetoothWindow::QuitRequested(void)
166 be_app
->PostMessage(B_QUIT_REQUESTED
);