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 <TabView.h> 16 17 #include <stdio.h> 18 19 #include <bluetooth/LocalDevice.h> 20 21 #include "defs.h" 22 23 24 #undef B_TRANSLATION_CONTEXT 25 #define B_TRANSLATION_CONTEXT "Window" 26 27 static const uint32 kMsgSetDefaults = 'dflt'; 28 static const uint32 kMsgRevert = 'rvrt'; 29 30 static const uint32 kMsgStartServices = 'SrSR'; 31 static const uint32 kMsgStopServices = 'StST'; 32 static const uint32 kMsgShowDebug = 'ShDG'; 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("Show bluetooth console" B_UTF8_ELLIPSIS), 62 new BMessage(kMsgStartServices), 0)); 63 menu->AddItem(new BMenuItem( 64 B_TRANSLATE("Refresh LocalDevices" B_UTF8_ELLIPSIS), 65 new BMessage(kMsgRefresh), 0)); 66 fMenubar->AddItem(menu); 67 68 menu = new BMenu(B_TRANSLATE("View")); 69 menu->AddItem(new BMenuItem( 70 B_TRANSLATE("Connections & channels" B_UTF8_ELLIPSIS), NULL, 0)); 71 menu->AddItem(new BMenuItem( 72 B_TRANSLATE("Remote devices list" B_UTF8_ELLIPSIS), NULL, 0)); 73 fMenubar->AddItem(menu); 74 75 menu = new BMenu(B_TRANSLATE("Help")); 76 menu->AddItem(new BMenuItem(B_TRANSLATE("About Bluetooth" B_UTF8_ELLIPSIS), 77 new BMessage(B_ABOUT_REQUESTED), 0)); 78 fMenubar->AddItem(menu); 79 80 BTabView* tabView = new BTabView("tabview", B_WIDTH_FROM_LABEL); 81 82 fSettingsView = new BluetoothSettingsView(B_TRANSLATE("Settings")); 83 // fConnChan = new ConnChanView("Connections & Channels", B_WILL_DRAW); 84 fRemoteDevices = new RemoteDevicesView( 85 B_TRANSLATE("Remote devices"), B_WILL_DRAW); 86 87 tabView->AddTab(fRemoteDevices); 88 // tabView->AddTab(fConnChan); 89 tabView->AddTab(fSettingsView); 90 91 fRevertButton->SetEnabled(false); 92 93 BLayoutBuilder::Group<>(this, B_VERTICAL, 0) 94 .SetInsets(0) 95 .Add(fMenubar) 96 .AddStrut(B_USE_HALF_ITEM_SPACING) 97 .Add(tabView) 98 .AddGroup(B_HORIZONTAL, B_USE_HALF_ITEM_SPACING) 99 .AddGlue() 100 .Add(fDefaultsButton) 101 .Add(fRevertButton) 102 .End() 103 .End(); 104 } 105 106 107 void 108 BluetoothWindow::MessageReceived(BMessage* message) 109 { 110 switch (message->what) { 111 case kMsgSetDefaults: 112 /* fColorsView -> MessageReceived(new BMessage(DEFAULT_SETTINGS)); 113 fAntialiasingSettings->SetDefaults(); 114 fDefaultsButton->SetEnabled(false); 115 fRevertButton->SetEnabled(true); 116 */ break; 117 118 case kMsgRevert: 119 /* fColorsView -> MessageReceived(new BMessage(REVERT_SETTINGS)); 120 fAntialiasingSettings->Revert(); 121 fDefaultsButton->SetEnabled(fColorsView->IsDefaultable() 122 || fAntialiasingSettings->IsDefaultable()); 123 fRevertButton->SetEnabled(false); 124 */ break; 125 case kMsgStartServices: 126 printf("kMsgStartServices\n"); 127 if (!be_roster->IsRunning(BLUETOOTH_SIGNATURE)) { 128 status_t error = be_roster->Launch(BLUETOOTH_SIGNATURE); 129 printf("kMsgStartServices: %s\n", strerror(error)); 130 } 131 break; 132 133 case kMsgStopServices: 134 printf("kMsgStopServices\n"); 135 if (be_roster->IsRunning(BLUETOOTH_SIGNATURE)) { 136 status_t error = BMessenger(BLUETOOTH_SIGNATURE).SendMessage(B_QUIT_REQUESTED); 137 printf("kMsgStopServices: %s\n", strerror(error)); 138 } 139 break; 140 141 case kMsgAddToRemoteList: 142 PostMessage(message, fRemoteDevices); 143 break; 144 case kMsgRefresh: 145 fSettingsView->MessageReceived(message); 146 break; 147 case B_ABOUT_REQUESTED: 148 be_app->PostMessage(message); 149 break; 150 default: 151 BWindow::MessageReceived(message); 152 break; 153 } 154 } 155 156 157 bool 158 BluetoothWindow::QuitRequested() 159 { 160 be_app->PostMessage(B_QUIT_REQUESTED); 161 return true; 162 } 163