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 #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, B_TRANSLATE("Bluetooth"), B_TITLED_WINDOW, 37 B_NOT_ZOOMABLE | B_AUTO_UPDATE_SIZE_LIMITS) 38 { 39 SetLayout(new BGroupLayout(B_HORIZONTAL)); 40 41 fDefaultsButton = new BButton("defaults", B_TRANSLATE("Defaults"), 42 new BMessage(kMsgSetDefaults), B_WILL_DRAW); 43 44 fRevertButton = new BButton("revert", B_TRANSLATE("Revert"), 45 new BMessage(kMsgRevert), B_WILL_DRAW); 46 47 // Add the menu bar 48 fMenubar = new BMenuBar(Bounds(), "menu_bar"); 49 50 // Add File menu to menu bar 51 BMenu* menu = new BMenu(B_TRANSLATE("Server")); 52 menu->AddItem(new BMenuItem( 53 B_TRANSLATE("Start bluetooth services" B_UTF8_ELLIPSIS), 54 new BMessage(kMsgStartServices), 0)); 55 menu->AddItem(new BMenuItem( 56 B_TRANSLATE("Stop bluetooth services" B_UTF8_ELLIPSIS), 57 new BMessage(kMsgStopServices), 0)); 58 menu->AddSeparatorItem(); 59 menu->AddItem(new BMenuItem( 60 B_TRANSLATE("Show bluetooth console" B_UTF8_ELLIPSIS), 61 new BMessage(kMsgStartServices), 0)); 62 menu->AddItem(new BMenuItem( 63 B_TRANSLATE("Refresh LocalDevices" B_UTF8_ELLIPSIS), 64 new BMessage(kMsgRefresh), 0)); 65 fMenubar->AddItem(menu); 66 67 menu = new BMenu(B_TRANSLATE("View")); 68 menu->AddItem(new BMenuItem( 69 B_TRANSLATE("Connections & channels" B_UTF8_ELLIPSIS), NULL, 0)); 70 menu->AddItem(new BMenuItem( 71 B_TRANSLATE("Remote devices list" B_UTF8_ELLIPSIS), NULL, 0)); 72 fMenubar->AddItem(menu); 73 74 menu = new BMenu(B_TRANSLATE("Help")); 75 menu->AddItem(new BMenuItem(B_TRANSLATE("About Bluetooth" B_UTF8_ELLIPSIS), 76 new BMessage(B_ABOUT_REQUESTED), 0)); 77 fMenubar->AddItem(menu); 78 79 BTabView* tabView = new BTabView("tabview", B_WIDTH_FROM_LABEL); 80 81 fSettingsView = new BluetoothSettingsView(B_TRANSLATE("Settings")); 82 // fConnChan = new ConnChanView("Connections & Channels", B_WILL_DRAW); 83 fRemoteDevices = new RemoteDevicesView( 84 B_TRANSLATE("Remote devices"), B_WILL_DRAW); 85 86 tabView->AddTab(fRemoteDevices); 87 // tabView->AddTab(fConnChan); 88 tabView->AddTab(fSettingsView); 89 90 91 fRevertButton->SetEnabled(false); 92 93 AddChild(BGroupLayoutBuilder(B_VERTICAL, 0) 94 .Add(fMenubar) 95 .Add(BSpaceLayoutItem::CreateVerticalStrut(5)) 96 .Add(tabView) 97 .Add(BSpaceLayoutItem::CreateVerticalStrut(5)) 98 .Add(BGroupLayoutBuilder(B_HORIZONTAL, 0) 99 .Add(fRevertButton) 100 .AddGlue() 101 .Add(fDefaultsButton) 102 ) 103 .SetInsets(5, 5, 5, 5) 104 ); 105 } 106 107 108 void 109 BluetoothWindow::MessageReceived(BMessage* message) 110 { 111 switch (message->what) { 112 case kMsgSetDefaults: 113 /* fColorsView -> MessageReceived(new BMessage(DEFAULT_SETTINGS)); 114 fAntialiasingSettings->SetDefaults(); 115 fDefaultsButton->SetEnabled(false); 116 fRevertButton->SetEnabled(true); 117 */ break; 118 119 case kMsgRevert: 120 /* fColorsView -> MessageReceived(new BMessage(REVERT_SETTINGS)); 121 fAntialiasingSettings->Revert(); 122 fDefaultsButton->SetEnabled(fColorsView->IsDefaultable() 123 || fAntialiasingSettings->IsDefaultable()); 124 fRevertButton->SetEnabled(false); 125 */ break; 126 case kMsgStartServices: 127 printf("kMsgStartServices\n"); 128 if (!be_roster->IsRunning(BLUETOOTH_SIGNATURE)) { 129 status_t error; 130 131 error = be_roster->Launch(BLUETOOTH_SIGNATURE); 132 printf("kMsgStartServices: %s\n", strerror(error)); 133 } 134 break; 135 136 case kMsgStopServices: 137 printf("kMsgStopServices\n"); 138 if (be_roster->IsRunning(BLUETOOTH_SIGNATURE)) { 139 status_t error; 140 141 error = BMessenger(BLUETOOTH_SIGNATURE).SendMessage(B_QUIT_REQUESTED); 142 printf("kMsgStopServices: %s\n", strerror(error)); 143 } 144 break; 145 146 case kMsgAddToRemoteList: 147 PostMessage(message, fRemoteDevices); 148 break; 149 case kMsgRefresh: 150 fSettingsView->MessageReceived(message); 151 break; 152 case B_ABOUT_REQUESTED: 153 be_app->PostMessage(message); 154 break; 155 default: 156 BWindow::MessageReceived(message); 157 break; 158 } 159 } 160 161 162 bool 163 BluetoothWindow::QuitRequested(void) 164 { 165 be_app->PostMessage(B_QUIT_REQUESTED); 166 return true; 167 } 168