Author: oruizdorantes Date: 2010-01-10 23:53:00 +0100 (Sun, 10 Jan 2010) New Revision: 34997 Changeset: http://dev.haiku-os.org/changeset/34997/haiku Modified: haiku/trunk/src/preferences/bluetooth/BluetoothMain.cpp haiku/trunk/src/preferences/bluetooth/BluetoothMain.h haiku/trunk/src/preferences/bluetooth/BluetoothSettingsView.cpp haiku/trunk/src/preferences/bluetooth/BluetoothSettingsView.h haiku/trunk/src/preferences/bluetooth/BluetoothWindow.cpp Log: - Pointer not initialized for LocalDevice Menu (thanks Rene) - Show Alert when bluetooth_server is not running (work in progress) - Typos and Style Modified: haiku/trunk/src/preferences/bluetooth/BluetoothMain.cpp =================================================================== --- haiku/trunk/src/preferences/bluetooth/BluetoothMain.cpp 2010-01-10 22:19:29 UTC (rev 34996) +++ haiku/trunk/src/preferences/bluetooth/BluetoothMain.cpp 2010-01-10 22:53:00 UTC (rev 34997) @@ -1,5 +1,5 @@ /* - * Copyright 2008-09, Oliver Ruiz Dorantes, <oliver.ruiz.dorantes_at_gmail.com> + * Copyright 2008-10, Oliver Ruiz Dorantes, <oliver.ruiz.dorantes_at_gmail.com> * All rights reserved. Distributed under the terms of the MIT License. */ #include <stdio.h> @@ -7,6 +7,8 @@ #include <Alert.h> #include <Catalog.h> #include <Locale.h> +#include <MessageRunner.h> +#include <Roster.h> #include "BluetoothMain.h" #include "BluetoothWindow.h" @@ -19,64 +21,108 @@ : BApplication(BLUETOOTH_APP_SIGNATURE) { be_locale->GetAppCatalog(&fCatalog); +} - fWindow = new BluetoothWindow(BRect(100, 100, 550, 420)); - fWindow->Show(); + +void +BluetoothApplication::ReadyToRun() +{ + if (!be_roster->IsRunning(BLUETOOTH_SIGNATURE)) { + + int32 choice = (new BAlert("bluetooth_server not running", + "bluetooth_server has not been found running on the system." + "Should be started, or stay offline", "Work offline", + "Quit", "Start please", B_WIDTH_AS_USUAL, B_WARNING_ALERT))->Go(); + + + switch (choice) { + case 1: + PostMessage(B_QUIT_REQUESTED); + return; + case 2: + { + status_t error; + error = be_roster->Launch(BLUETOOTH_SIGNATURE); + printf("kMsgStartServices: %s\n", strerror(error)); + // TODO: This is temporal + // BMessage handcheck: use the version of Launch() + // that includes a BMessage in that message include + // a BMessenger to yourself and the BT server could + // use that messenger to send back a reply indicating + // when it's ready and you could just create window + // when you get that + BMessageRunner::StartSending(be_app_messenger, + new BMessage('Xtmp'), 2 * 1000000, 1); + + break; + } + default: + PostMessage(new BMessage('Xtmp')); + break; + } + } + } void BluetoothApplication::AboutRequested() { - + (new BAlert("about", TR("Haiku Bluetooth system, (ARCE)\n\n" - "Created by Oliver Ruiz Dorantes\n\n" - "With support of:\n" - " - Mika Lindqvist\n" - " - Maksym Yevmenkin\n\n" - "Thanks to the individuals who helped...\n\n" - "Shipping/donating hardware:\n" - " - Henry Jair Abril Florez (el Colombian)\n" - " & Stefanie Bartolich\n" - " - Edwin Erik Amsler\n" - " - Dennis d'Entremont\n" - " - Luroh\n" - " - Pieter Panman\n\n" - "Economically:\n" - " - Karl vom Dorff, Andrea Bernardi (OSDrawer),\n" - " - Matt M, Doug F, Hubert H,\n" - " - Sebastian B, Andrew M, Jared E,\n" - " - Frederik H, Tom S, Ferry B,\n" - " - Greg G, David F, Richard S, Martin W:\n\n" - "With patches:\n" - " - Michael Weirauch\n" - " - Fredrik Ekdahl\n" - " - Raynald Lesieur\n" - " - Andreas Färber\n" - " - Joerg Meyer\n" - "Testing:\n" - " - Petter H. Juliussen\n" - " - Adrien Destugues\n\n" - "Who gave me all the knowledge:\n" - " - the yellowTAB team"), TR("OK")))->Go(); - + "Created by Oliver Ruiz Dorantes\n\n" + "With support of:\n" + " - Mika Lindqvist\n" + " - Adrien Destugues\n" + " - Maksym Yevmenkin\n\n" + "Thanks to the individuals who helped...\n\n" + "Shipping/donating hardware:\n" + " - Henry Jair Abril Florez (el Colombian)\n" + " & Stefanie Bartolich\n" + " - Edwin Erik Amsler\n" + " - Dennis d'Entremont\n" + " - Luroh\n" + " - Pieter Panman\n\n" + "Economically:\n" + " - Karl vom Dorff, Andrea Bernardi (OSDrawer),\n" + " - Matt M, Doug F, Hubert H,\n" + " - Sebastian B, Andrew M, Jared E,\n" + " - Frederik H, Tom S, Ferry B,\n" + " - Greg G, David F, Richard S, Martin W:\n\n" + "With patches:\n" + " - Michael Weirauch\n" + " - Fredrik Ekdahl\n" + " - Raynald Lesieur\n" + " - Andreas Färber\n" + " - Joerg Meyer\n" + "Testing:\n" + " - Petter H. Juliussen\n" + "Who gave me all the knowledge:\n" + " - the yellowTAB team"), TR("OK")))->Go(); + } + void -BluetoothApplication::MessageReceived(BMessage *message) +BluetoothApplication::MessageReceived(BMessage* message) { switch (message->what) { case kMsgAddToRemoteList: fWindow->PostMessage(message); break; + case 'Xtmp': + fWindow = new BluetoothWindow(BRect(100, 100, 550, 420)); + fWindow->Show(); + break; default: BApplication::MessageReceived(message); } } + int main(int, char**) -{ +{ BluetoothApplication myApplication; myApplication.Run(); Modified: haiku/trunk/src/preferences/bluetooth/BluetoothMain.h =================================================================== --- haiku/trunk/src/preferences/bluetooth/BluetoothMain.h 2010-01-10 22:19:29 UTC (rev 34996) +++ haiku/trunk/src/preferences/bluetooth/BluetoothMain.h 2010-01-10 22:53:00 UTC (rev 34997) @@ -9,17 +9,18 @@ class BluetoothWindow; -class BluetoothApplication : public BApplication +class BluetoothApplication : public BApplication { - + public: BluetoothApplication(void); + virtual void ReadyToRun(); virtual void MessageReceived(BMessage*); virtual void AboutRequested(); - + private: - BluetoothWindow *fWindow; - BCatalog fCatalog; + BluetoothWindow* fWindow; + BCatalog fCatalog; }; Modified: haiku/trunk/src/preferences/bluetooth/BluetoothSettingsView.cpp =================================================================== --- haiku/trunk/src/preferences/bluetooth/BluetoothSettingsView.cpp 2010-01-10 22:19:29 UTC (rev 34996) +++ haiku/trunk/src/preferences/bluetooth/BluetoothSettingsView.cpp 2010-01-10 22:53:00 UTC (rev 34997) @@ -27,7 +27,7 @@ #include "BluetoothWindow.h" #define TR_CONTEXT "Settings view" - + static const int32 kMsgSetAntialiasing = 'anti'; static const int32 kMsgSetDeviceClassDesktop = 'sDCd'; static const int32 kMsgSetDeviceClassServer = 'sDCs'; @@ -52,52 +52,52 @@ // #pragma mark - BluetoothSettingsView::BluetoothSettingsView(const char* name) - : BView(name, 0) + : BView(name, 0), + fLocalDevicesMenu(NULL) { - // antialiasing menu _BuildConnectionPolicy(); - fAntialiasingMenuField = new BMenuField("antialiasing", - TR("Incoming connections policy:"), fAntialiasingMenu, NULL); + fPolicyMenuField = new BMenuField("antialiasing", + TR("Incoming connections policy:"), fPolicyMenu, NULL); - fAverageWeightControl = new BSlider("averageWeightControl", + fInquiryTimeControl = new BSlider("time", TR("Default inquiry time:"), new BMessage(kMsgSetAverageWeight), 0, 255, B_HORIZONTAL); - fAverageWeightControl->SetLimitLabels(TR("15 secs"), TR("61 secs")); - fAverageWeightControl->SetHashMarks(B_HASH_MARKS_BOTTOM); - fAverageWeightControl->SetHashMarkCount(255 / 15); - fAverageWeightControl->SetEnabled(true); - + fInquiryTimeControl->SetLimitLabels(TR("15 secs"), TR("61 secs")); + fInquiryTimeControl->SetHashMarks(B_HASH_MARKS_BOTTOM); + fInquiryTimeControl->SetHashMarkCount(255 / 15); + fInquiryTimeControl->SetEnabled(true); + // hinting menu - _BuildHintingMenu(); - fHintingMenuField = new BMenuField("hinting", TR("Identify host as:"), - fHintingMenu, NULL); + _BuildClassMenu(); + fClassMenuField = new BMenuField("class", TR("Identify host as:"), + fClassMenu, NULL); // localdevices menu _BuildLocalDevicesMenu(); fLocalDevicesMenuField = new BMenuField("devices", TR("Local devices found on system:"), fLocalDevicesMenu, NULL); - fExtDeviceView = new ExtendedLocalDeviceView(BRect(0,0,5,5), NULL); + fExtDeviceView = new ExtendedLocalDeviceView(BRect(0, 0, 5, 5), NULL); SetLayout(new BGroupLayout(B_VERTICAL)); // controls pane AddChild(BGridLayoutBuilder(10, 10) - .Add(fHintingMenuField->CreateLabelLayoutItem(), 0, 0) - .Add(fHintingMenuField->CreateMenuBarLayoutItem(), 1, 0) + .Add(fClassMenuField->CreateLabelLayoutItem(), 0, 0) + .Add(fClassMenuField->CreateMenuBarLayoutItem(), 1, 0) - .Add(fAntialiasingMenuField->CreateLabelLayoutItem(), 0, 1) - .Add(fAntialiasingMenuField->CreateMenuBarLayoutItem(), 1, 1) - + .Add(fPolicyMenuField->CreateLabelLayoutItem(), 0, 1) + .Add(fPolicyMenuField->CreateMenuBarLayoutItem(), 1, 1) + .Add(BSpaceLayoutItem::CreateGlue(), 0, 2, 2) - - .Add(fAverageWeightControl, 0, 3, 2) + + .Add(fInquiryTimeControl, 0, 3, 2) .Add(BSpaceLayoutItem::CreateGlue(), 0, 4, 2) - + .Add(fLocalDevicesMenuField->CreateLabelLayoutItem(), 0, 5) .Add(fLocalDevicesMenuField->CreateMenuBarLayoutItem(), 1, 5) - + .Add(fExtDeviceView, 0, 6, 2) .Add(BSpaceLayoutItem::CreateGlue(), 0, 7, 2) @@ -121,73 +121,73 @@ else SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); - fAntialiasingMenu->SetTargetForItems(this); - fHintingMenu->SetTargetForItems(this); + fPolicyMenu->SetTargetForItems(this); + fClassMenu->SetTargetForItems(this); fLocalDevicesMenu->SetTargetForItems(this); - fAverageWeightControl->SetTarget(this); + fInquiryTimeControl->SetTarget(this); } void -BluetoothSettingsView::MessageReceived(BMessage *msg) +BluetoothSettingsView::MessageReceived(BMessage* message) { - + DeviceClass devClass; - - switch (msg->what) { + + switch (message->what) { case kMsgLocalSwitched: { LocalDevice* lDevice; - if (msg->FindPointer("LocalDevice", (void**) &lDevice) == B_OK) { + if (message->FindPointer("LocalDevice", (void**) &lDevice) == B_OK) { // Device integrity should be rechecked fExtDeviceView->SetLocalDevice(lDevice); fExtDeviceView->SetEnabled(true); - ActiveLocalDevice = lDevice; + ActiveLocalDevice = lDevice; } } break; - + case kMsgSetDeviceClassDesktop: - { + { devClass.SetRecord(1, 1, 0x72); ActiveLocalDevice->SetDeviceClass(devClass); break; } - + case kMsgSetDeviceClassServer: - { + { devClass.SetRecord(1, 2, 0x72); ActiveLocalDevice->SetDeviceClass(devClass); break; } - + case kMsgSetDeviceClassLaptop: - { + { devClass.SetRecord(1, 3, 0x72); ActiveLocalDevice->SetDeviceClass(devClass); break; } case kMsgSetDeviceClassHandheld: - { + { devClass.SetRecord(1, 4, 0x72); ActiveLocalDevice->SetDeviceClass(devClass); break; } - + case kMsgSetDeviceClassSmartPhone: - { + { devClass.SetRecord(2, 3, 0x72); ActiveLocalDevice->SetDeviceClass(devClass); break; - } + } case kMsgRefresh: _BuildLocalDevicesMenu(); fLocalDevicesMenu->SetTargetForItems(this); break; default: - BView::MessageReceived(msg); + BView::MessageReceived(message); } } @@ -195,57 +195,56 @@ void BluetoothSettingsView::_BuildConnectionPolicy() { - fAntialiasingMenu = new BPopUpMenu(TR("Policy...")); + fPolicyMenu = new BPopUpMenu(TR("Policy...")); BMessage* message = new BMessage(kMsgSetAntialiasing); message->AddBool("antialiasing", false); BMenuItem* item = new BMenuItem(TR(kAllLabel), message); - fAntialiasingMenu->AddItem(item); - + fPolicyMenu->AddItem(item); + message = new BMessage(kMsgSetAntialiasing); message->AddBool("antialiasing", true); item = new BMenuItem(TR(kTrustedLabel), message); - fAntialiasingMenu->AddItem(item); + fPolicyMenu->AddItem(item); BMenuItem* item2 = new BMenuItem(TR(kAlwaysLabel), NULL); - fAntialiasingMenu->AddItem(item2); + fPolicyMenu->AddItem(item2); } void -BluetoothSettingsView::_BuildHintingMenu() -{ +BluetoothSettingsView::_BuildClassMenu() +{ - fHintingMenu = new BPopUpMenu(TR("Identify us as...")); + fClassMenu = new BPopUpMenu(TR("Identify us as...")); BMessage* message; - + message = new BMessage(kMsgSetDeviceClassDesktop); BMenuItem* item = new BMenuItem(TR(kDesktopLabel), message); - fHintingMenu->AddItem(item); - + fClassMenu->AddItem(item); + message = new BMessage(kMsgSetDeviceClassServer); item = new BMenuItem(TR(kServerLabel), message); - fHintingMenu->AddItem(item); + fClassMenu->AddItem(item); message = new BMessage(kMsgSetDeviceClassLaptop); item = new BMenuItem(TR(kLaptopLabel), message); - fHintingMenu->AddItem(item); + fClassMenu->AddItem(item); message = new BMessage(kMsgSetDeviceClassHandheld); item = new BMenuItem(TR(kHandheldLabel), message); - fHintingMenu->AddItem(item); - + fClassMenu->AddItem(item); + message = new BMessage(kMsgSetDeviceClassSmartPhone); item = new BMenuItem(TR(kPhoneLabel), message); - fHintingMenu->AddItem(item); + fClassMenu->AddItem(item); - } @@ -257,20 +256,18 @@ if (!fLocalDevicesMenu) fLocalDevicesMenu = new BPopUpMenu(TR("Pick LocalDevice...")); - for (uint32 index = 0 ; index < LocalDevice::GetLocalDeviceCount() ; index++) { + for (uint32 index = 0; index < LocalDevice::GetLocalDeviceCount(); index++) { - lDevice = LocalDevice::GetLocalDevice(); - if (lDevice != NULL) { - // TODO Check if they already exists - + lDevice = LocalDevice::GetLocalDevice(); + if (lDevice != NULL) { + + // TODO Check if they already exists BMessage* message = new BMessage(kMsgLocalSwitched); message->AddPointer("LocalDevice", lDevice); - - BMenuItem* item = new BMenuItem((lDevice->GetFriendlyName().String()), message); + + BMenuItem* item = new BMenuItem((lDevice->GetFriendlyName().String()), + message); fLocalDevicesMenu->AddItem(item); - } + } } } - - - Modified: haiku/trunk/src/preferences/bluetooth/BluetoothSettingsView.h =================================================================== --- haiku/trunk/src/preferences/bluetooth/BluetoothSettingsView.h 2010-01-10 22:19:29 UTC (rev 34996) +++ haiku/trunk/src/preferences/bluetooth/BluetoothSettingsView.h 2010-01-10 22:53:00 UTC (rev 34997) @@ -26,32 +26,23 @@ private: void _BuildConnectionPolicy(); - void _SetCurrentAntialiasing(); - void _BuildHintingMenu(); - void _SetCurrentHinting(); - void _SetCurrentAverageWeight(); + void _BuildClassMenu(); void _BuildLocalDevicesMenu(); protected: float fDivider; - BMenuField* fAntialiasingMenuField; - BPopUpMenu* fAntialiasingMenu; - BMenuField* fHintingMenuField; - BPopUpMenu* fHintingMenu; + BMenuField* fPolicyMenuField; + BPopUpMenu* fPolicyMenu; + BMenuField* fClassMenuField; + BPopUpMenu* fClassMenu; BMenuField* fLocalDevicesMenuField; BPopUpMenu* fLocalDevicesMenu; - + ExtendedLocalDeviceView* fExtDeviceView; - - BSlider* fAverageWeightControl; - bool fSavedSubpixelAntialiasing; - bool fCurrentSubpixelAntialiasing; - bool fSavedHinting; - bool fCurrentHinting; - unsigned char fSavedAverageWeight; - unsigned char fCurrentAverageWeight; + BSlider* fInquiryTimeControl; + }; #endif // ANTIALIASING_SETTINGS_VIEW_H Modified: haiku/trunk/src/preferences/bluetooth/BluetoothWindow.cpp =================================================================== --- haiku/trunk/src/preferences/bluetooth/BluetoothWindow.cpp 2010-01-10 22:19:29 UTC (rev 34996) +++ haiku/trunk/src/preferences/bluetooth/BluetoothWindow.cpp 2010-01-10 22:53:00 UTC (rev 34997) @@ -59,14 +59,14 @@ menu->AddItem(new BMenuItem(TR("Refresh LocalDevices" B_UTF8_ELLIPSIS), new BMessage(kMsgRefresh), 0)); fMenubar->AddItem(menu); - + menu = new BMenu(TR("View")); menu->AddItem(new BMenuItem(TR("Connections & channels" B_UTF8_ELLIPSIS), NULL, 0)); menu->AddItem(new BMenuItem(TR("Remote devices list" B_UTF8_ELLIPSIS), NULL, 0)); fMenubar->AddItem(menu); - + menu = new BMenu(TR("Help")); menu->AddItem(new BMenuItem(TR("About Bluetooth" B_UTF8_ELLIPSIS), new BMessage(B_ABOUT_REQUESTED), 0)); @@ -122,9 +122,9 @@ printf("kMsgStartServices\n"); if (!be_roster->IsRunning(BLUETOOTH_SIGNATURE)) { status_t error; - + error = be_roster->Launch(BLUETOOTH_SIGNATURE); - printf("kMsgStopServices: %s\n", strerror(error)); + printf("kMsgStartServices: %s\n", strerror(error)); } break; @@ -132,12 +132,12 @@ printf("kMsgStopServices\n"); if (be_roster->IsRunning(BLUETOOTH_SIGNATURE)) { status_t error; - + error = BMessenger(BLUETOOTH_SIGNATURE).SendMessage(B_QUIT_REQUESTED); printf("kMsgStopServices: %s\n", strerror(error)); } break; - + case kMsgAddToRemoteList: PostMessage(message, fRemoteDevices); break;