Merge view class in the window object
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@33471 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -10,44 +10,35 @@
|
|||||||
#include <Window.h>
|
#include <Window.h>
|
||||||
|
|
||||||
#include <bluetooth/bluetooth.h>
|
#include <bluetooth/bluetooth.h>
|
||||||
|
#include <bluetooth/HCI/btHCI.h>
|
||||||
|
|
||||||
class BStringView;
|
class BStringView;
|
||||||
class BButton;
|
class BButton;
|
||||||
class BTextControls;
|
class BTextControl;
|
||||||
|
|
||||||
namespace Bluetooth {
|
namespace Bluetooth {
|
||||||
|
|
||||||
class RemoteDevice;
|
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;
|
||||||
BStringView* fMessage;
|
BButton* fAcceptButton;
|
||||||
BStringView* fRemoteInfo;
|
BButton* fCancelButton;
|
||||||
BButton* fAcceptButton;
|
BTextControl* fPincodeText;
|
||||||
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;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -41,99 +41,78 @@ static const uint32 skMessageCancelButton = 'mVch';
|
|||||||
|
|
||||||
namespace Bluetooth {
|
namespace Bluetooth {
|
||||||
|
|
||||||
PincodeView::PincodeView(BRect rect)
|
|
||||||
: BView(rect,"View", B_FOLLOW_NONE, B_WILL_DRAW )
|
|
||||||
{
|
|
||||||
|
|
||||||
SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
|
|
||||||
|
|
||||||
fMessage = new BStringView("Pincode", "Please enter the pincode ...",
|
|
||||||
B_FOLLOW_ALL_SIDES);
|
|
||||||
fMessage->SetFont(be_bold_font);
|
|
||||||
|
|
||||||
fRemoteInfo = new BStringView("bdaddr","BD_ADDR: ", B_FOLLOW_ALL_SIDES);
|
|
||||||
|
|
||||||
// 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)
|
|
||||||
.Add(fMessage)
|
|
||||||
.Add(fRemoteInfo)
|
|
||||||
.Add(fPincodeText)
|
|
||||||
.Add(BGroupLayoutBuilder(B_HORIZONTAL)
|
|
||||||
.AddGlue()
|
|
||||||
.Add(fCancelButton)
|
|
||||||
.Add(fAcceptButton)
|
|
||||||
.SetInsets(5, 5, 5, 5)
|
|
||||||
)
|
|
||||||
.Add(BSpaceLayoutItem::CreateVerticalStrut(0))
|
|
||||||
.SetInsets(5, 5, 5, 5)
|
|
||||||
);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
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
|
#if 0
|
||||||
#pragma mark -
|
#pragma mark -
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
PincodeWindow::PincodeWindow(bdaddr_t address, hci_id hid)
|
PincodeWindow::PincodeWindow(bdaddr_t address, hci_id hid)
|
||||||
: BWindow(BRect(700, 100, 900, 150), "Pincode Request",
|
: BWindow(BRect(800, 200, 900, 300), "Pincode Request",
|
||||||
B_FLOATING_WINDOW_LOOK, B_NORMAL_WINDOW_FEEL,
|
B_FLOATING_WINDOW,
|
||||||
B_WILL_ACCEPT_FIRST_CLICK | B_NOT_ZOOMABLE | B_NOT_RESIZABLE,
|
B_WILL_ACCEPT_FIRST_CLICK | B_NOT_RESIZABLE| B_NOT_ZOOMABLE
|
||||||
|
| B_AUTO_UPDATE_SIZE_LIMITS,
|
||||||
B_ALL_WORKSPACES), fBdaddr(address), fHid(hid)
|
B_ALL_WORKSPACES), fBdaddr(address), fHid(hid)
|
||||||
{
|
{
|
||||||
fView = new PincodeView(Bounds());
|
InitUI();
|
||||||
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
|
// TODO: Get more info about device" ote name/features/encry/auth... etc
|
||||||
fView->SetBDaddr(bdaddrUtils::ToString(fBdaddr));
|
SetBDaddr(bdaddrUtils::ToString(fBdaddr));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
PincodeWindow::PincodeWindow(RemoteDevice* rDevice)
|
PincodeWindow::PincodeWindow(RemoteDevice* rDevice)
|
||||||
: BWindow(BRect(700, 100, 900, 150), "Pincode Request",
|
: BWindow(BRect(800, 200, 900, 300), "Pincode Request",
|
||||||
B_FLOATING_WINDOW_LOOK, B_NORMAL_WINDOW_FEEL,
|
B_FLOATING_WINDOW,
|
||||||
B_WILL_ACCEPT_FIRST_CLICK | B_NOT_ZOOMABLE | B_NOT_RESIZABLE,
|
B_WILL_ACCEPT_FIRST_CLICK | B_NOT_ZOOMABLE | B_NOT_RESIZABLE
|
||||||
|
| B_AUTO_UPDATE_SIZE_LIMITS,
|
||||||
B_ALL_WORKSPACES)
|
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
|
// TODO: Get more info about device" ote name/features/encry/auth... etc
|
||||||
fView->SetBDaddr(bdaddrUtils::ToString(rDevice->GetBluetoothAddress()));
|
SetBDaddr(bdaddrUtils::ToString(rDevice->GetBluetoothAddress()));
|
||||||
fHid = (rDevice->GetLocalDeviceOwner())->ID();
|
fHid = (rDevice->GetLocalDeviceOwner())->ID();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void PincodeWindow::MessageReceived(BMessage *msg)
|
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: ");
|
||||||
|
|
||||||
|
// 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));
|
||||||
|
|
||||||
|
AddChild(BGroupLayoutBuilder(B_VERTICAL, 10)
|
||||||
|
.Add(fMessage)
|
||||||
|
.Add(fRemoteInfo)
|
||||||
|
.Add(fPincodeText)
|
||||||
|
.Add(BGroupLayoutBuilder(B_HORIZONTAL, 10)
|
||||||
|
.AddGlue()
|
||||||
|
.Add(fCancelButton)
|
||||||
|
.Add(fAcceptButton)
|
||||||
|
.SetInsets(5, 5, 5, 5)
|
||||||
|
)
|
||||||
|
.SetInsets(15, 15, 15, 15)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
PincodeWindow::MessageReceived(BMessage *msg)
|
||||||
{
|
{
|
||||||
// status_t err = B_OK;
|
// status_t err = B_OK;
|
||||||
|
|
||||||
switch(msg->what)
|
switch(msg->what)
|
||||||
{
|
{
|
||||||
case skMessageAcceptButton:
|
case skMessageAcceptButton:
|
||||||
@@ -142,10 +121,10 @@ void PincodeWindow::MessageReceived(BMessage *msg)
|
|||||||
BMessage reply;
|
BMessage reply;
|
||||||
size_t size;
|
size_t size;
|
||||||
int8 bt_status = BT_ERROR;
|
int8 bt_status = BT_ERROR;
|
||||||
|
|
||||||
void* command = buildPinCodeRequestReply(fBdaddr,
|
void* command = buildPinCodeRequestReply(fBdaddr,
|
||||||
strlen(fView->fPincodeText->Text()),
|
strlen(fPincodeText->Text()),
|
||||||
(char*)fView->fPincodeText->Text(), &size);
|
(char*)fPincodeText->Text(), &size);
|
||||||
|
|
||||||
if (command == NULL) {
|
if (command == NULL) {
|
||||||
break;
|
break;
|
||||||
@@ -156,7 +135,7 @@ void PincodeWindow::MessageReceived(BMessage *msg)
|
|||||||
request.AddInt16("eventExpected", HCI_EVENT_CMD_COMPLETE);
|
request.AddInt16("eventExpected", HCI_EVENT_CMD_COMPLETE);
|
||||||
request.AddInt16("opcodeExpected", PACK_OPCODE(OGF_LINK_CONTROL,
|
request.AddInt16("opcodeExpected", PACK_OPCODE(OGF_LINK_CONTROL,
|
||||||
OCF_PIN_CODE_REPLY));
|
OCF_PIN_CODE_REPLY));
|
||||||
|
|
||||||
// we reside in the server
|
// we reside in the server
|
||||||
if (be_app_messenger.SendMessage(&request, &reply) == B_OK) {
|
if (be_app_messenger.SendMessage(&request, &reply) == B_OK) {
|
||||||
if (reply.FindInt8("status", &bt_status ) == B_OK ) {
|
if (reply.FindInt8("status", &bt_status ) == B_OK ) {
|
||||||
@@ -166,7 +145,7 @@ void PincodeWindow::MessageReceived(BMessage *msg)
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case skMessageCancelButton:
|
case skMessageCancelButton:
|
||||||
{
|
{
|
||||||
BMessage request(BT_MSG_HANDLE_SIMPLE_REQUEST);
|
BMessage request(BT_MSG_HANDLE_SIMPLE_REQUEST);
|
||||||
@@ -175,7 +154,7 @@ void PincodeWindow::MessageReceived(BMessage *msg)
|
|||||||
int8 bt_status = BT_ERROR;
|
int8 bt_status = BT_ERROR;
|
||||||
|
|
||||||
void* command = buildPinCodeRequestNegativeReply(fBdaddr, &size);
|
void* command = buildPinCodeRequestNegativeReply(fBdaddr, &size);
|
||||||
|
|
||||||
if (command == NULL) {
|
if (command == NULL) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -197,7 +176,7 @@ void PincodeWindow::MessageReceived(BMessage *msg)
|
|||||||
|
|
||||||
default:
|
default:
|
||||||
BWindow::MessageReceived(msg);
|
BWindow::MessageReceived(msg);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -207,4 +186,18 @@ bool PincodeWindow::QuitRequested()
|
|||||||
return BWindow::QuitRequested();
|
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();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user