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 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 45 fRevertButton = new BButton("revert", B_TRANSLATE("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(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); 64 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); 69 70 BTabView* tabView = new BTabView("tabview", B_WIDTH_FROM_LABEL); 71 tabView->SetBorder(B_NO_BORDER); 72 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); 77 78 tabView->AddTab(fRemoteDevices); 79 // tabView->AddTab(fConnChan); 80 tabView->AddTab(fSettingsView); 81 82 fRevertButton->SetEnabled(false); 83 84 BLayoutBuilder::Group<>(this, B_VERTICAL, 0) 85 .SetInsets(0) 86 .Add(fMenubar) 87 .AddStrut(B_USE_HALF_ITEM_SPACING) 88 .Add(tabView) 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) 94 .Add(fDefaultsButton) 95 .Add(fRevertButton) 96 .AddGlue() 97 .End() 98 .End(); 99 } 100 101 102 void 103 BluetoothWindow::MessageReceived(BMessage* message) 104 { 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); 111 */ break; 112 113 case kMsgRevert: 114 /* fColorsView -> MessageReceived(new BMessage(REVERT_SETTINGS)); 115 fAntialiasingSettings->Revert(); 116 fDefaultsButton->SetEnabled(fColorsView->IsDefaultable() 117 || fAntialiasingSettings->IsDefaultable()); 118 fRevertButton->SetEnabled(false); 119 */ break; 120 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)); 125 } 126 break; 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)); 131 } 132 break; 133 134 case kMsgAddToRemoteList: 135 PostMessage(message, fRemoteDevices); 136 break; 137 case kMsgRefresh: 138 fSettingsView->MessageReceived(message); 139 break; 140 case B_ABOUT_REQUESTED: 141 be_app->PostMessage(message); 142 break; 143 default: 144 BWindow::MessageReceived(message); 145 break; 146 } 147 } 148 149 150 bool 151 BluetoothWindow::QuitRequested() 152 { 153 be_app->PostMessage(B_QUIT_REQUESTED); 154 return true; 155 } 156