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 static const uint32 kMsgShowDebug = 'ShDG'; 34 35 LocalDevice* ActiveLocalDevice = NULL; 36 37 38 BluetoothWindow::BluetoothWindow(BRect frame) 39 : 40 BWindow(frame, B_TRANSLATE_SYSTEM_NAME("Bluetooth"), B_TITLED_WINDOW, 41 B_NOT_ZOOMABLE | B_AUTO_UPDATE_SIZE_LIMITS) 42 { 43 fDefaultsButton = new BButton("defaults", B_TRANSLATE("Defaults"), 44 new BMessage(kMsgSetDefaults), B_WILL_DRAW); 45 46 fRevertButton = new BButton("revert", B_TRANSLATE("Revert"), 47 new BMessage(kMsgRevert), B_WILL_DRAW); 48 49 // Add the menu bar 50 fMenubar = new BMenuBar(Bounds(), "menu_bar"); 51 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); 68 69 menu = new BMenu(B_TRANSLATE("Help")); 70 menu->AddItem(new BMenuItem(B_TRANSLATE("About Bluetooth" B_UTF8_ELLIPSIS), 71 new BMessage(B_ABOUT_REQUESTED), 0)); 72 fMenubar->AddItem(menu); 73 74 BTabView* tabView = new BTabView("tabview", B_WIDTH_FROM_LABEL); 75 tabView->SetBorder(B_NO_BORDER); 76 77 fSettingsView = new BluetoothSettingsView(B_TRANSLATE("Settings")); 78 // fConnChan = new ConnChanView("Connections & Channels", B_WILL_DRAW); 79 fRemoteDevices = new RemoteDevicesView( 80 B_TRANSLATE("Remote devices"), B_WILL_DRAW); 81 82 tabView->AddTab(fRemoteDevices); 83 // tabView->AddTab(fConnChan); 84 tabView->AddTab(fSettingsView); 85 86 fRevertButton->SetEnabled(false); 87 88 BLayoutBuilder::Group<>(this, B_VERTICAL, 0) 89 .SetInsets(0) 90 .Add(fMenubar) 91 .AddStrut(B_USE_HALF_ITEM_SPACING) 92 .Add(tabView) 93 .AddStrut(B_USE_HALF_ITEM_SPACING) 94 .Add(new BSeparatorView(B_HORIZONTAL)) 95 .AddGroup(B_HORIZONTAL) 96 .SetInsets(B_USE_WINDOW_SPACING, B_USE_DEFAULT_SPACING, 97 B_USE_WINDOW_SPACING, B_USE_WINDOW_SPACING) 98 .AddGlue() 99 .Add(fDefaultsButton) 100 .Add(fRevertButton) 101 .End() 102 .End(); 103 } 104 105 106 void 107 BluetoothWindow::MessageReceived(BMessage* message) 108 { 109 switch (message->what) { 110 case kMsgSetDefaults: 111 /* fColorsView -> MessageReceived(new BMessage(DEFAULT_SETTINGS)); 112 fAntialiasingSettings->SetDefaults(); 113 fDefaultsButton->SetEnabled(false); 114 fRevertButton->SetEnabled(true); 115 */ break; 116 117 case kMsgRevert: 118 /* fColorsView -> MessageReceived(new BMessage(REVERT_SETTINGS)); 119 fAntialiasingSettings->Revert(); 120 fDefaultsButton->SetEnabled(fColorsView->IsDefaultable() 121 || fAntialiasingSettings->IsDefaultable()); 122 fRevertButton->SetEnabled(false); 123 */ break; 124 case kMsgStartServices: 125 printf("kMsgStartServices\n"); 126 if (!be_roster->IsRunning(BLUETOOTH_SIGNATURE)) { 127 status_t error = be_roster->Launch(BLUETOOTH_SIGNATURE); 128 printf("kMsgStartServices: %s\n", strerror(error)); 129 } 130 break; 131 132 case kMsgStopServices: 133 printf("kMsgStopServices\n"); 134 if (be_roster->IsRunning(BLUETOOTH_SIGNATURE)) { 135 status_t error = BMessenger(BLUETOOTH_SIGNATURE).SendMessage(B_QUIT_REQUESTED); 136 printf("kMsgStopServices: %s\n", strerror(error)); 137 } 138 break; 139 140 case kMsgAddToRemoteList: 141 PostMessage(message, fRemoteDevices); 142 break; 143 case kMsgRefresh: 144 fSettingsView->MessageReceived(message); 145 break; 146 case B_ABOUT_REQUESTED: 147 be_app->PostMessage(message); 148 break; 149 default: 150 BWindow::MessageReceived(message); 151 break; 152 } 153 } 154 155 156 bool 157 BluetoothWindow::QuitRequested() 158 { 159 be_app->PostMessage(B_QUIT_REQUESTED); 160 return true; 161 } 162