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.
7 #include "BluetoothWindow.h"
8 #include "RemoteDevicesView.h"
12 #include <LayoutBuilder.h>
13 #include <Messenger.h>
15 #include <SeparatorView.h>
20 #include <bluetooth/LocalDevice.h>
25 #undef B_TRANSLATION_CONTEXT
26 #define B_TRANSLATION_CONTEXT "Window"
28 static const uint32 kMsgSetDefaults
= 'dflt';
29 static const uint32 kMsgRevert
= 'rvrt';
31 static const uint32 kMsgStartServices
= 'SrSR';
32 static const uint32 kMsgStopServices
= 'StST';
34 LocalDevice
* ActiveLocalDevice
= NULL
;
37 BluetoothWindow::BluetoothWindow(BRect frame
)
39 BWindow(frame
, B_TRANSLATE_SYSTEM_NAME("Bluetooth"), B_TITLED_WINDOW
,
40 B_NOT_ZOOMABLE
| B_AUTO_UPDATE_SIZE_LIMITS
)
42 fDefaultsButton
= new BButton("defaults", B_TRANSLATE("Defaults"),
43 new BMessage(kMsgSetDefaults
), B_WILL_DRAW
);
45 fRevertButton
= new BButton("revert", B_TRANSLATE("Revert"),
46 new BMessage(kMsgRevert
), B_WILL_DRAW
);
49 fMenubar
= new BMenuBar(Bounds(), "menu_bar");
51 // Add File menu to menu bar
52 BMenu
* menu
= new BMenu(B_TRANSLATE("Server"));
53 menu
->AddItem(new BMenuItem(
54 B_TRANSLATE("Start bluetooth services" B_UTF8_ELLIPSIS
),
55 new BMessage(kMsgStartServices
), 0));
56 menu
->AddItem(new BMenuItem(
57 B_TRANSLATE("Stop bluetooth services" B_UTF8_ELLIPSIS
),
58 new BMessage(kMsgStopServices
), 0));
59 menu
->AddSeparatorItem();
60 menu
->AddItem(new BMenuItem(
61 B_TRANSLATE("Refresh local devices" B_UTF8_ELLIPSIS
),
62 new BMessage(kMsgRefresh
), 0));
63 fMenubar
->AddItem(menu
);
65 menu
= new BMenu(B_TRANSLATE("Help"));
66 menu
->AddItem(new BMenuItem(B_TRANSLATE("About Bluetooth" B_UTF8_ELLIPSIS
),
67 new BMessage(B_ABOUT_REQUESTED
), 0));
68 fMenubar
->AddItem(menu
);
70 BTabView
* tabView
= new BTabView("tabview", B_WIDTH_FROM_LABEL
);
71 tabView
->SetBorder(B_NO_BORDER
);
73 fSettingsView
= new BluetoothSettingsView(B_TRANSLATE("Settings"));
74 // fConnChan = new ConnChanView("Connections & Channels", B_WILL_DRAW);
75 fRemoteDevices
= new RemoteDevicesView(
76 B_TRANSLATE("Remote devices"), B_WILL_DRAW
);
78 tabView
->AddTab(fRemoteDevices
);
79 // tabView->AddTab(fConnChan);
80 tabView
->AddTab(fSettingsView
);
82 fRevertButton
->SetEnabled(false);
84 BLayoutBuilder::Group
<>(this, B_VERTICAL
, 0)
87 .AddStrut(B_USE_HALF_ITEM_SPACING
)
89 .AddStrut(B_USE_HALF_ITEM_SPACING
)
90 .Add(new BSeparatorView(B_HORIZONTAL
))
91 .AddGroup(B_HORIZONTAL
)
92 .SetInsets(B_USE_WINDOW_SPACING
, B_USE_DEFAULT_SPACING
,
93 B_USE_WINDOW_SPACING
, B_USE_WINDOW_SPACING
)
103 BluetoothWindow::MessageReceived(BMessage
* message
)
105 switch (message
->what
) {
106 case kMsgSetDefaults
:
107 /* fColorsView -> MessageReceived(new BMessage(DEFAULT_SETTINGS));
108 fAntialiasingSettings->SetDefaults();
109 fDefaultsButton->SetEnabled(false);
110 fRevertButton->SetEnabled(true);
114 /* fColorsView -> MessageReceived(new BMessage(REVERT_SETTINGS));
115 fAntialiasingSettings->Revert();
116 fDefaultsButton->SetEnabled(fColorsView->IsDefaultable()
117 || fAntialiasingSettings->IsDefaultable());
118 fRevertButton->SetEnabled(false);
121 case kMsgStartServices
:
122 if (!be_roster
->IsRunning(BLUETOOTH_SIGNATURE
)) {
123 status_t error
= be_roster
->Launch(BLUETOOTH_SIGNATURE
);
124 printf("kMsgStartServices: %s\n", strerror(error
));
127 case kMsgStopServices
:
128 if (be_roster
->IsRunning(BLUETOOTH_SIGNATURE
)) {
129 status_t error
= BMessenger(BLUETOOTH_SIGNATURE
).SendMessage(B_QUIT_REQUESTED
);
130 printf("kMsgStopServices: %s\n", strerror(error
));
134 case kMsgAddToRemoteList
:
135 PostMessage(message
, fRemoteDevices
);
138 fSettingsView
->MessageReceived(message
);
140 case B_ABOUT_REQUESTED
:
141 be_app
->PostMessage(message
);
144 BWindow::MessageReceived(message
);
151 BluetoothWindow::QuitRequested()
153 be_app
->PostMessage(B_QUIT_REQUESTED
);