diff --git a/headers/private/bluetooth/ConnectionIncoming.h b/headers/private/bluetooth/ConnectionIncoming.h new file mode 100644 index 0000000000..be470a611f --- /dev/null +++ b/headers/private/bluetooth/ConnectionIncoming.h @@ -0,0 +1,51 @@ +/* + * Copyright 2007-2008 Oliver Ruiz Dorantes, oliver.ruiz.dorantes_at_gmail.com + * + * All rights reserved. Distributed under the terms of the MIT License. + * + */ + +#ifndef _CONNECTION_INCOMING_H_ +#define _CONNECTION_INCOMING_H_ + + +//----------------------- Global includes ---------------------- +#include +#include +#include +#include +#include +#include + +class RemoteDevice; + +class ConnectionView + : public BView +{ +public: + ConnectionView(BRect frame, const char *name, uint32 resizeMask, uint32 flags); + ~ConnectionView(); + virtual void MessageReceived(BMessage *message); + void Draw(BRect update); + void Pulse(); + +private: + + +}; + + +class ConnectionIncoming + : public BWindow +{ +public: + ConnectionIncoming(RemoteDevice* rDevice); + ~ConnectionIncoming(); + virtual void MessageReceived(BMessage *message); + virtual bool QuitRequested(); + +private: + ConnectionView* _ConnectionView; +}; + +#endif diff --git a/headers/private/bluetooth/PincodeWindow.h b/headers/private/bluetooth/PincodeWindow.h new file mode 100644 index 0000000000..11d655ae40 --- /dev/null +++ b/headers/private/bluetooth/PincodeWindow.h @@ -0,0 +1,61 @@ +/* + * Copyright 2007-2008 Oliver Ruiz Dorantes, oliver.ruiz.dorantes_at_gmail.com + * + * All rights reserved. Distributed under the terms of the MIT License. + * + */ + +#ifndef _PINCODE_REQUEST_WINDOW_H +#define _PINCODE_REQUEST_WINDOW_H + + +#include +#include + +#include + +class BStringView; +class BButton; +class BTextControls; + +namespace Bluetooth { + +class RemoteDevice; + +class PincodeView : public BView +{ + public: + /* Constructors & Destructor*/ + PincodeView(BRect rect); + + void SetBDaddr(const char* address); + + BStringView* fMessage; + BStringView* fRemoteInfo; + BButton* fAcceptButton; + BButton* fCancelButton; + BTextControl* fPincodeText; + +}; + +class PincodeWindow : public BWindow +{ + public: + PincodeWindow(RemoteDevice* rDevice); + virtual void MessageReceived(BMessage *msg); + virtual bool QuitRequested(); + + private: + PincodeView* fView; + bdaddr_t bdaddr; + RemoteDevice* fRemoteDevice; + BMessenger* fMessenger; +}; + +} + +#ifndef _BT_USE_EXPLICIT_NAMESPACE +using Bluetooth::PincodeWindow; +#endif + +#endif \ No newline at end of file diff --git a/src/kits/bluetooth/UI/ConnectionIncoming.cpp b/src/kits/bluetooth/UI/ConnectionIncoming.cpp new file mode 100644 index 0000000000..c2865338c1 --- /dev/null +++ b/src/kits/bluetooth/UI/ConnectionIncoming.cpp @@ -0,0 +1,91 @@ +/* + * Copyright 2007-2008 Oliver Ruiz Dorantes, oliver.ruiz.dorantes_at_gmail.com + * + * All rights reserved. Distributed under the terms of the MIT License. + * + */ + +#include + +#define B_PULSES_BY_SECOND(x) (2*x) + + +ConnectionView::ConnectionView(BRect frame, const char *name, uint32 resizeMask, uint32 flags) + : BView(BRect(0, 0, 400, 400), "MyViewName", B_FOLLOW_LEFT | B_FOLLOW_TOP, + B_WILL_DRAW | B_PULSE_NEEDED) +{ + + SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); + +} + +ConnectionView::~ConnectionView() +{ + +} + + +void ConnectionView::MessageReceived(BMessage *message) +{ + switch(message->what) + { + default: + + break; + } +} + + +void ConnectionView::Draw(BRect update) +{ + +} + + +void ConnectionView::Pulse() +{ + static int a = 0; + if (a++ == B_PULSES_BY_SECOND(5)) + Window()->QuitRequested(); + +} + + + +//--------------------------------------------------------------- +//--------------------------------------------------------------- +//--------------------------------------------------------------- +ConnectionIncoming::ConnectionIncoming(RemoteDevice* rDevice) + : BWindow(BRect(700, 100, 900, 150), "Incomming Connection", + B_FLOATING_WINDOW_LOOK, B_NORMAL_WINDOW_FEEL, + B_NOT_ZOOMABLE | B_NOT_RESIZABLE) +{ +_ConnectionView = new ConnectionView(BRect(0, 0, 400, 400),"mViewName", B_FOLLOW_TOP | B_FOLLOW_LEFT, B_WILL_DRAW); + +AddChild(_ConnectionView); +} + +//--------------------------------------------------------------- +ConnectionIncoming::~ConnectionIncoming() +{ + +} + +//--------------------------------------------------------------- +void ConnectionIncoming::MessageReceived(BMessage *message) +{ + switch(message->what) + { + default: + + break; + } +} + +//--------------------------------------------------------------- +bool ConnectionIncoming::QuitRequested() +{ + Quit(); + return BWindow::QuitRequested(); +} + diff --git a/src/kits/bluetooth/UI/PincodeWindow.cpp b/src/kits/bluetooth/UI/PincodeWindow.cpp new file mode 100644 index 0000000000..35f51cf919 --- /dev/null +++ b/src/kits/bluetooth/UI/PincodeWindow.cpp @@ -0,0 +1,203 @@ + +/* + * Copyright 2007-2008 Oliver Ruiz Dorantes, oliver.ruiz.dorantes_at_gmail.com + * + * All rights reserved. Distributed under the terms of the MIT License. + * + */ + +#include +#include +#include + +#include +#include +#include + +#include +#include +#include +#include + +#include +#include +#include +#include + +#include +#include + +#include +#include +#include + +#define MSG_ACCEPT_BUTTON 'acCp' +#define MSG_CANCEL_BUTTON 'mVch' + +#define H_SEPARATION 15 +#define V_SEPARATION 10 +#define BD_ADDR_LABEL "BD_ADDR: " + +namespace Bluetooth { + +PincodeView::PincodeView(BRect rect) : BView(rect,"View", B_FOLLOW_NONE, B_WILL_DRAW ), fMessage(NULL) +{ + BRect rect; + BRect rect2; + + SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); + + fMessage = new BStringView(BRect(0,0,5,5),"Pincode","Please enter the pincode ...", B_FOLLOW_ALL_SIDES); + fMessage->SetFont(be_bold_font); + fMessage->ResizeToPreferred(); + fMessage->MoveBy(20, 20); + rect = fMessage->Frame(); + + fRemoteInfo = new BStringView(BRect(rect.left, rect.bottom + V_SEPARATION , 0 , 0), + "bdaddr","BD_ADDR: ", B_FOLLOW_ALL_SIDES); + fRemoteInfo->ResizeToPreferred(); + rect = fRemoteInfo->Frame(); + + // TODO: IT CANNOT BE MORE THAN 16 BYTES + fPincodeText = new BTextControl(BRect(rect.left, rect.bottom + V_SEPARATION , 0, 0), + "pincode TextControl","PIN code:", "", NULL); + fPincodeText->ResizeToPreferred(); + rect = fPincodeText->Frame(); + + fAcceptButton = new BButton(BRect(rect.left , rect.bottom + V_SEPARATION ,0, 0 ), + "fAcceptButton","Pair",new BMessage(MSG_ACCEPT_BUTTON)); + fAcceptButton->ResizeToPreferred(); + rect = fAcceptButton->Frame(); + + fCancelButton = new BButton(BRect(rect.right + H_SEPARATION , rect.top , 0 , 0 ), + "fCancelButton","Cancel",new BMessage(MSG_CANCEL_BUTTON)); + fCancelButton->ResizeToPreferred(); + rect = fCancelButton->Frame(); + + this->AddChild(fMessage); + this->AddChild(fPincodeText); + this->AddChild(fAcceptButton); + this->AddChild(fCancelButton); + + this->AddChild(fRemoteInfo); + + // Now resize the the view according all what we found here + rect = fMessage->Frame(); + rect2 = fCancelButton->Frame(); + ResizeTo(rect.right + 15 , rect2.bottom +15 ); + +} + +void PincodeView::SetBDaddr(const char* address){ + + 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(RemoteDevice* rDevice) : + BWindow(BRect(700, 100, 900, 150), "Pincode Request", B_MODAL_WINDOW_LOOK, B_FLOATING_ALL_WINDOW_FEEL, + B_WILL_ACCEPT_FIRST_CLICK | B_NOT_RESIZABLE , + B_ALL_WORKSPACES), fRemoteDevice(rDevice) +{ + fView = new PincodeView(Bounds()); + AddChild(fView); + // readapt ourselves to what the view needs + ResizeTo( fView->Bounds().right , fView->Bounds().bottom ); + + // TODO: Get more info about device" ote name/features/encry/auth... etc + fView->SetBDaddr( bdaddrUtils::ToString(rDevice->GetBluetoothAddress()) ); +}; + +void PincodeWindow::MessageReceived(BMessage *msg) +{ +// status_t err = B_OK; + + switch(msg->what) + { + case MSG_ACCEPT_BUTTON: + { + BMessage request(BT_MSG_HANDLE_SIMPLE_REQUEST); + BMessage reply; + size_t size; + int8 bt_status = BT_ERROR; + + void* command = buildPinCodeRequestReply(fRemoteDevice->GetBluetoothAddress(), strlen(fView->fPincodeText->Text()), + (char[16])fView->fPincodeText->Text(), &size); + + if (command == NULL) { + break; + } + + request.AddInt32("hci_id", (fRemoteDevice->GetLocalDeviceOwner())->GetID()); + request.AddData("raw command", B_ANY_TYPE, command, size); + request.AddInt16("eventExpected", HCI_EVENT_CMD_COMPLETE); + request.AddInt16("opcodeExpected", PACK_OPCODE(OGF_LINK_CONTROL, OCF_PIN_CODE_REPLY)); + + if (fMessenger->SendMessage(&request, &reply) == B_OK) { + if (reply.FindInt8("status", &bt_status ) == B_OK ) { + break; + } + // TODO: something failed here + } + + QuitRequested(); + } + break; + + + case MSG_CANCEL_BUTTON: + { + BMessage request(BT_MSG_HANDLE_SIMPLE_REQUEST); + BMessage reply; + size_t size; + int8 bt_status = BT_ERROR; + + void* command = buildPinCodeRequestNegativeReply(fRemoteDevice->GetBluetoothAddress(), &size); + + if (command == NULL) { + break; + } + + request.AddInt32("hci_id", (fRemoteDevice->GetLocalDeviceOwner())->GetID()); + request.AddData("raw command", B_ANY_TYPE, command, size); + request.AddInt16("eventExpected", HCI_EVENT_CMD_COMPLETE); + request.AddInt16("opcodeExpected", PACK_OPCODE(OGF_LINK_CONTROL, OCF_PIN_CODE_NEG_REPLY)); + + if (fMessenger->SendMessage(&request, &reply) == B_OK) { + if (reply.FindInt8("status", &bt_status ) == B_OK ) { + break; + } + // TODO: something failed here + } + + QuitRequested(); + } + break; + + default: + BWindow::MessageReceived(msg); + break; + } +} + + + +bool PincodeWindow::QuitRequested() +{ + Lock(); + Quit(); + return (true); +}; + +} +