Author: oruizdorantes Date: 2009-10-06 22:03:36 +0200 (Tue, 06 Oct 2009) New Revision: 33471 Changeset: http://dev.haiku-os.org/changeset/33471/haiku Modified: haiku/trunk/headers/private/bluetooth/PincodeWindow.h haiku/trunk/src/kits/bluetooth/UI/PincodeWindow.cpp Log: Merge view class in the window object Modified: haiku/trunk/headers/private/bluetooth/PincodeWindow.h =================================================================== --- haiku/trunk/headers/private/bluetooth/PincodeWindow.h 2009-10-06 17:08:24 UTC (rev 33470) +++ haiku/trunk/headers/private/bluetooth/PincodeWindow.h 2009-10-06 20:03:36 UTC (rev 33471) @@ -10,46 +10,37 @@ #include <Window.h> #include <bluetooth/bluetooth.h> +#include <bluetooth/HCI/btHCI.h> class BStringView; class BButton; -class BTextControls; +class BTextControl; namespace Bluetooth { class RemoteDevice; -class PincodeView : public BView +class PincodeWindow : public BWindow { - public: +public: + PincodeWindow(bdaddr_t address, hci_id hid); + PincodeWindow(RemoteDevice* rDevice); + virtual void MessageReceived(BMessage *msg); + virtual bool QuitRequested(); + void SetBDaddr(const char* address); - PincodeView(BRect rect); +private: + void InitUI(); + bdaddr_t fBdaddr; + hci_id fHid; - void SetBDaddr(const char* address); - - BStringView* fMessage; - BStringView* fRemoteInfo; - BButton* fAcceptButton; - BButton* fCancelButton; - BTextControl* fPincodeText; - + BStringView* fMessage; + BStringView* fRemoteInfo; + BButton* fAcceptButton; + BButton* fCancelButton; + BTextControl* fPincodeText; }; -class PincodeWindow : public BWindow -{ - public: - PincodeWindow(bdaddr_t address, hci_id hid); - PincodeWindow(RemoteDevice* rDevice); - virtual void MessageReceived(BMessage *msg); - virtual bool QuitRequested(); - - private: - PincodeView* fView; - bdaddr_t bdaddr; - bdaddr_t fBdaddr; - hci_id fHid; -}; - } #ifndef _BT_USE_EXPLICIT_NAMESPACE Modified: haiku/trunk/src/kits/bluetooth/UI/PincodeWindow.cpp =================================================================== --- haiku/trunk/src/kits/bluetooth/UI/PincodeWindow.cpp 2009-10-06 17:08:24 UTC (rev 33470) +++ haiku/trunk/src/kits/bluetooth/UI/PincodeWindow.cpp 2009-10-06 20:03:36 UTC (rev 33471) @@ -41,99 +41,78 @@ namespace Bluetooth { -PincodeView::PincodeView(BRect rect) - : BView(rect,"View", B_FOLLOW_NONE, B_WILL_DRAW ) + +#if 0 +#pragma mark - +#endif + +PincodeWindow::PincodeWindow(bdaddr_t address, hci_id hid) + : BWindow(BRect(800, 200, 900, 300), "Pincode Request", + B_FLOATING_WINDOW, + B_WILL_ACCEPT_FIRST_CLICK | B_NOT_RESIZABLE| B_NOT_ZOOMABLE + | B_AUTO_UPDATE_SIZE_LIMITS, + B_ALL_WORKSPACES), fBdaddr(address), fHid(hid) { + InitUI(); - SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); + // TODO: Get more info about device" ote name/features/encry/auth... etc + SetBDaddr(bdaddrUtils::ToString(fBdaddr)); - fMessage = new BStringView("Pincode", "Please enter the pincode ...", - B_FOLLOW_ALL_SIDES); +} + + +PincodeWindow::PincodeWindow(RemoteDevice* rDevice) + : BWindow(BRect(800, 200, 900, 300), "Pincode Request", + B_FLOATING_WINDOW, + B_WILL_ACCEPT_FIRST_CLICK | B_NOT_ZOOMABLE | B_NOT_RESIZABLE + | B_AUTO_UPDATE_SIZE_LIMITS, + B_ALL_WORKSPACES) +{ + // TODO: Get more info about device" ote name/features/encry/auth... etc + SetBDaddr(bdaddrUtils::ToString(rDevice->GetBluetoothAddress())); + fHid = (rDevice->GetLocalDeviceOwner())->ID(); +} + + +void +PincodeWindow::InitUI() +{ + SetLayout(new BGroupLayout(B_HORIZONTAL)); + + fMessage = new BStringView("Pincode", "Please enter the pincode ..."); fMessage->SetFont(be_bold_font); - - fRemoteInfo = new BStringView("bdaddr","BD_ADDR: ", B_FOLLOW_ALL_SIDES); - + + fRemoteInfo = new BStringView("bdaddr","BD_ADDR: "); + // TODO: Pincode cannot be more than 16 bytes fPincodeText = new BTextControl("pincode TextControl", "PIN code:", "5555", NULL); fAcceptButton = new BButton("fAcceptButton", "Pair", new BMessage(skMessageAcceptButton)); - + fCancelButton = new BButton("fCancelButton", "Cancel", new BMessage(skMessageCancelButton)); - - SetLayout(new BGroupLayout(B_HORIZONTAL)); - AddChild(BGroupLayoutBuilder(B_VERTICAL, 0) + AddChild(BGroupLayoutBuilder(B_VERTICAL, 10) .Add(fMessage) .Add(fRemoteInfo) .Add(fPincodeText) - .Add(BGroupLayoutBuilder(B_HORIZONTAL) + .Add(BGroupLayoutBuilder(B_HORIZONTAL, 10) .AddGlue() .Add(fCancelButton) .Add(fAcceptButton) .SetInsets(5, 5, 5, 5) ) - .Add(BSpaceLayoutItem::CreateVerticalStrut(0)) - .SetInsets(5, 5, 5, 5) + .SetInsets(15, 15, 15, 15) ); - } -void PincodeView::SetBDaddr(const char* address) +void +PincodeWindow::MessageReceived(BMessage *msg) { - BString label; - - label << BD_ADDR_LABEL << address; - printf("++ %s\n",label.String()); - fRemoteInfo->SetText(label.String()); - fRemoteInfo->ResizeToPreferred(); - Invalidate(); - -} - -#if 0 -#pragma mark - -#endif - -PincodeWindow::PincodeWindow(bdaddr_t address, hci_id hid) - : BWindow(BRect(700, 100, 900, 150), "Pincode Request", - B_FLOATING_WINDOW_LOOK, B_NORMAL_WINDOW_FEEL, - B_WILL_ACCEPT_FIRST_CLICK | B_NOT_ZOOMABLE | B_NOT_RESIZABLE, - B_ALL_WORKSPACES), fBdaddr(address), fHid(hid) -{ - fView = new PincodeView(Bounds()); - AddChild(fView); - // Readapt ourselves to what the view needs - ResizeTo(fView->Bounds().Width(), fView->Bounds().Height()); - - // TODO: Get more info about device" ote name/features/encry/auth... etc - fView->SetBDaddr(bdaddrUtils::ToString(fBdaddr)); -} - - -PincodeWindow::PincodeWindow(RemoteDevice* rDevice) - : BWindow(BRect(700, 100, 900, 150), "Pincode Request", - B_FLOATING_WINDOW_LOOK, B_NORMAL_WINDOW_FEEL, - B_WILL_ACCEPT_FIRST_CLICK | B_NOT_ZOOMABLE | B_NOT_RESIZABLE, - B_ALL_WORKSPACES) -{ - fView = new PincodeView(Bounds()); - AddChild(fView); - // Readapt ourselves to what the view needs - ResizeTo(fView->Bounds().Width(), fView->Bounds().Height()); - - // TODO: Get more info about device" ote name/features/encry/auth... etc - fView->SetBDaddr(bdaddrUtils::ToString(rDevice->GetBluetoothAddress())); - fHid = (rDevice->GetLocalDeviceOwner())->ID(); -} - - -void PincodeWindow::MessageReceived(BMessage *msg) -{ // status_t err = B_OK; - + switch(msg->what) { case skMessageAcceptButton: @@ -142,10 +121,10 @@ BMessage reply; size_t size; int8 bt_status = BT_ERROR; - + void* command = buildPinCodeRequestReply(fBdaddr, - strlen(fView->fPincodeText->Text()), - (char*)fView->fPincodeText->Text(), &size); + strlen(fPincodeText->Text()), + (char*)fPincodeText->Text(), &size); if (command == NULL) { break; @@ -156,7 +135,7 @@ request.AddInt16("eventExpected", HCI_EVENT_CMD_COMPLETE); request.AddInt16("opcodeExpected", PACK_OPCODE(OGF_LINK_CONTROL, OCF_PIN_CODE_REPLY)); - + // we reside in the server if (be_app_messenger.SendMessage(&request, &reply) == B_OK) { if (reply.FindInt8("status", &bt_status ) == B_OK ) { @@ -166,7 +145,7 @@ } break; } - + case skMessageCancelButton: { BMessage request(BT_MSG_HANDLE_SIMPLE_REQUEST); @@ -175,7 +154,7 @@ int8 bt_status = BT_ERROR; void* command = buildPinCodeRequestNegativeReply(fBdaddr, &size); - + if (command == NULL) { break; } @@ -197,7 +176,7 @@ default: BWindow::MessageReceived(msg); - break; + break; } } @@ -207,4 +186,18 @@ return BWindow::QuitRequested(); } + +void PincodeWindow::SetBDaddr(const char* address) +{ + BString label; + + label << BD_ADDR_LABEL << address; + printf("++ %s\n",label.String()); + fRemoteInfo->SetText(label.String()); + fRemoteInfo->ResizeToPreferred(); + //Invalidate(); + } + + +}