- Use Layout manager
- Styling git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@32870 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -1,12 +1,9 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2007-2008 Oliver Ruiz Dorantes, oliver.ruiz.dorantes_at_gmail.com
|
* Copyright 2007-2008 Oliver Ruiz Dorantes, oliver.ruiz.dorantes_at_gmail.com
|
||||||
*
|
* All rights reserved. Distributed under the terms of the MIT License.
|
||||||
* All rights reserved. Distributed under the terms of the MIT License.
|
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
|
#ifndef _PINCODE_REQUEST_WINDOW_H
|
||||||
#ifndef _PINCODE_REQUEST_WINDOW_H
|
#define _PINCODE_REQUEST_WINDOW_H
|
||||||
#define _PINCODE_REQUEST_WINDOW_H
|
|
||||||
|
|
||||||
|
|
||||||
#include <View.h>
|
#include <View.h>
|
||||||
@@ -18,44 +15,45 @@ class BStringView;
|
|||||||
class BButton;
|
class BButton;
|
||||||
class BTextControls;
|
class BTextControls;
|
||||||
|
|
||||||
namespace Bluetooth {
|
namespace Bluetooth {
|
||||||
|
|
||||||
class RemoteDevice;
|
class RemoteDevice;
|
||||||
|
|
||||||
class PincodeView : public BView
|
class PincodeView : public BView
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
/* Constructors & Destructor*/
|
|
||||||
PincodeView(BRect rect);
|
PincodeView(BRect rect);
|
||||||
|
|
||||||
void SetBDaddr(const char* address);
|
void SetBDaddr(const char* address);
|
||||||
|
|
||||||
BStringView* fMessage;
|
BStringView* fMessage;
|
||||||
BStringView* fRemoteInfo;
|
BStringView* fRemoteInfo;
|
||||||
BButton* fAcceptButton;
|
BButton* fAcceptButton;
|
||||||
BButton* fCancelButton;
|
BButton* fCancelButton;
|
||||||
BTextControl* fPincodeText;
|
BTextControl* fPincodeText;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class PincodeWindow : public BWindow
|
class PincodeWindow : public BWindow
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
PincodeWindow(bdaddr_t address, hci_id hid);
|
PincodeWindow(bdaddr_t address, hci_id hid);
|
||||||
virtual void MessageReceived(BMessage *msg);
|
PincodeWindow(RemoteDevice* rDevice);
|
||||||
virtual bool QuitRequested();
|
virtual void MessageReceived(BMessage *msg);
|
||||||
|
virtual bool QuitRequested();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
PincodeView* fView;
|
PincodeView* fView;
|
||||||
bdaddr_t bdaddr;
|
bdaddr_t bdaddr;
|
||||||
bdaddr_t fBdaddr;
|
bdaddr_t fBdaddr;
|
||||||
hci_id fHid;
|
hci_id fHid;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef _BT_USE_EXPLICIT_NAMESPACE
|
#ifndef _BT_USE_EXPLICIT_NAMESPACE
|
||||||
using Bluetooth::PincodeWindow;
|
using Bluetooth::PincodeWindow;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -1,9 +1,6 @@
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright 2007-2008 Oliver Ruiz Dorantes, oliver.ruiz.dorantes_at_gmail.com
|
* Copyright 2007-2008 Oliver Ruiz Dorantes, oliver.ruiz.dorantes_at_gmail.com
|
||||||
*
|
|
||||||
* All rights reserved. Distributed under the terms of the MIT License.
|
* All rights reserved. Distributed under the terms of the MIT License.
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
@@ -15,7 +12,9 @@
|
|||||||
#include <Application.h>
|
#include <Application.h>
|
||||||
|
|
||||||
#include <Button.h>
|
#include <Button.h>
|
||||||
|
#include <GroupLayoutBuilder.h>
|
||||||
#include <InterfaceDefs.h>
|
#include <InterfaceDefs.h>
|
||||||
|
#include <SpaceLayoutItem.h>
|
||||||
#include <StringView.h>
|
#include <StringView.h>
|
||||||
#include <TextControl.h>
|
#include <TextControl.h>
|
||||||
|
|
||||||
@@ -31,71 +30,66 @@
|
|||||||
#include <bluetoothserver_p.h>
|
#include <bluetoothserver_p.h>
|
||||||
#include <CommandManager.h>
|
#include <CommandManager.h>
|
||||||
|
|
||||||
#define MSG_ACCEPT_BUTTON 'acCp'
|
|
||||||
#define MSG_CANCEL_BUTTON 'mVch'
|
|
||||||
|
|
||||||
#define H_SEPARATION 15
|
#define H_SEPARATION 15
|
||||||
#define V_SEPARATION 10
|
#define V_SEPARATION 10
|
||||||
#define BD_ADDR_LABEL "BD_ADDR: "
|
#define BD_ADDR_LABEL "BD_ADDR: "
|
||||||
|
|
||||||
|
static const uint32 skMessageAcceptButton = 'acCp';
|
||||||
|
static const uint32 skMessageCancelButton = 'mVch';
|
||||||
|
|
||||||
|
|
||||||
namespace Bluetooth {
|
namespace Bluetooth {
|
||||||
|
|
||||||
PincodeView::PincodeView(BRect rect) : BView(rect,"View", B_FOLLOW_NONE, B_WILL_DRAW ), fMessage(NULL)
|
PincodeView::PincodeView(BRect rect)
|
||||||
|
: BView(rect,"View", B_FOLLOW_NONE, B_WILL_DRAW )
|
||||||
{
|
{
|
||||||
BRect rect1;
|
|
||||||
BRect rect2;
|
|
||||||
|
|
||||||
SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
|
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 = new BStringView("Pincode", "Please enter the pincode ...",
|
||||||
|
B_FOLLOW_ALL_SIDES);
|
||||||
fMessage->SetFont(be_bold_font);
|
fMessage->SetFont(be_bold_font);
|
||||||
fMessage->ResizeToPreferred();
|
|
||||||
fMessage->MoveBy(20, 20);
|
|
||||||
rect1 = fMessage->Frame();
|
|
||||||
|
|
||||||
fRemoteInfo = new BStringView(BRect(rect1.left, rect1.bottom + V_SEPARATION , 0 , 0),
|
fRemoteInfo = new BStringView("bdaddr","BD_ADDR: ", B_FOLLOW_ALL_SIDES);
|
||||||
"bdaddr","BD_ADDR: ", B_FOLLOW_ALL_SIDES);
|
|
||||||
fRemoteInfo->ResizeToPreferred();
|
|
||||||
rect1 = fRemoteInfo->Frame();
|
|
||||||
|
|
||||||
// TODO: IT CANNOT BE MORE THAN 16 BYTES
|
// TODO: Pincode cannot be more than 16 bytes
|
||||||
fPincodeText = new BTextControl(BRect(rect1.left, rect1.bottom + V_SEPARATION , rect1.right, rect1.bottom + V_SEPARATION + 20),
|
fPincodeText = new BTextControl("pincode TextControl", "PIN code:", "5555", NULL);
|
||||||
"pincode TextControl","PIN code:", "5555", NULL);
|
|
||||||
fPincodeText->ResizeToPreferred();
|
|
||||||
rect1 = fPincodeText->Frame();
|
|
||||||
|
|
||||||
fAcceptButton = new BButton(BRect(rect1.left , rect1.bottom + V_SEPARATION ,0, 0 ),
|
fAcceptButton = new BButton("fAcceptButton", "Pair",
|
||||||
"fAcceptButton","Pair",new BMessage(MSG_ACCEPT_BUTTON));
|
new BMessage(skMessageAcceptButton));
|
||||||
fAcceptButton->ResizeToPreferred();
|
|
||||||
rect1 = fAcceptButton->Frame();
|
|
||||||
|
|
||||||
fCancelButton = new BButton(BRect(rect1.right + H_SEPARATION , rect1.top , 0 , 0 ),
|
fCancelButton = new BButton("fCancelButton", "Cancel",
|
||||||
"fCancelButton","Cancel",new BMessage(MSG_CANCEL_BUTTON));
|
new BMessage(skMessageCancelButton));
|
||||||
fCancelButton->ResizeToPreferred();
|
|
||||||
|
SetLayout(new BGroupLayout(B_HORIZONTAL));
|
||||||
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
|
|
||||||
rect1 = fMessage->Frame();
|
|
||||||
rect2 = fCancelButton->Frame();
|
|
||||||
ResizeTo(rect1.right + 15 , rect2.bottom +15 );
|
|
||||||
|
|
||||||
|
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;
|
void PincodeView::SetBDaddr(const char* address)
|
||||||
|
{
|
||||||
label << BD_ADDR_LABEL << address;
|
BString label;
|
||||||
printf("++ %s\n",label.String());
|
|
||||||
fRemoteInfo->SetText(label.String());
|
label << BD_ADDR_LABEL << address;
|
||||||
fRemoteInfo->ResizeToPreferred();
|
printf("++ %s\n",label.String());
|
||||||
Invalidate();
|
fRemoteInfo->SetText(label.String());
|
||||||
|
fRemoteInfo->ResizeToPreferred();
|
||||||
|
Invalidate();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -103,20 +97,38 @@ void PincodeView::SetBDaddr(const char* address){
|
|||||||
#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(700, 100, 900, 150), "Pincode Request",
|
||||||
B_FLOATING_WINDOW_LOOK, B_NORMAL_WINDOW_FEEL,
|
B_FLOATING_WINDOW_LOOK, B_NORMAL_WINDOW_FEEL,
|
||||||
B_WILL_ACCEPT_FIRST_CLICK | B_NOT_ZOOMABLE | B_NOT_RESIZABLE,
|
B_WILL_ACCEPT_FIRST_CLICK | B_NOT_ZOOMABLE | B_NOT_RESIZABLE,
|
||||||
B_ALL_WORKSPACES), fBdaddr(address), fHid(hid)
|
B_ALL_WORKSPACES), fBdaddr(address), fHid(hid)
|
||||||
{
|
{
|
||||||
fView = new PincodeView(Bounds());
|
fView = new PincodeView(Bounds());
|
||||||
AddChild(fView);
|
AddChild(fView);
|
||||||
// readapt ourselves to what the view needs
|
// Readapt ourselves to what the view needs
|
||||||
ResizeTo( fView->Bounds().right , fView->Bounds().bottom );
|
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) );
|
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)
|
void PincodeWindow::MessageReceived(BMessage *msg)
|
||||||
{
|
{
|
||||||
@@ -124,16 +136,17 @@ void PincodeWindow::MessageReceived(BMessage *msg)
|
|||||||
|
|
||||||
switch(msg->what)
|
switch(msg->what)
|
||||||
{
|
{
|
||||||
case MSG_ACCEPT_BUTTON:
|
case skMessageAcceptButton:
|
||||||
{
|
{
|
||||||
BMessage request(BT_MSG_HANDLE_SIMPLE_REQUEST);
|
BMessage request(BT_MSG_HANDLE_SIMPLE_REQUEST);
|
||||||
BMessage reply;
|
BMessage reply;
|
||||||
size_t size;
|
size_t size;
|
||||||
int8 bt_status = BT_ERROR;
|
int8 bt_status = BT_ERROR;
|
||||||
|
|
||||||
void* command = buildPinCodeRequestReply(fBdaddr, strlen(fView->fPincodeText->Text()),
|
void* command = buildPinCodeRequestReply(fBdaddr,
|
||||||
(char*)fView->fPincodeText->Text(), &size);
|
strlen(fView->fPincodeText->Text()),
|
||||||
|
(char*)fView->fPincodeText->Text(), &size);
|
||||||
|
|
||||||
if (command == NULL) {
|
if (command == NULL) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -141,27 +154,26 @@ void PincodeWindow::MessageReceived(BMessage *msg)
|
|||||||
request.AddInt32("hci_id", fHid);
|
request.AddInt32("hci_id", fHid);
|
||||||
request.AddData("raw command", B_ANY_TYPE, command, size);
|
request.AddData("raw command", B_ANY_TYPE, command, size);
|
||||||
request.AddInt16("eventExpected", HCI_EVENT_CMD_COMPLETE);
|
request.AddInt16("eventExpected", HCI_EVENT_CMD_COMPLETE);
|
||||||
request.AddInt16("opcodeExpected", PACK_OPCODE(OGF_LINK_CONTROL, OCF_PIN_CODE_REPLY));
|
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 (be_app_messenger.SendMessage(&request, &reply) == B_OK) {
|
||||||
if (reply.FindInt8("status", &bt_status ) == B_OK ) {
|
if (reply.FindInt8("status", &bt_status ) == B_OK ) {
|
||||||
PostMessage(B_QUIT_REQUESTED);
|
PostMessage(B_QUIT_REQUESTED);
|
||||||
}
|
}
|
||||||
// TODO: something failed here
|
// TODO: something failed here
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
}
|
}
|
||||||
break;
|
|
||||||
|
case skMessageCancelButton:
|
||||||
|
|
||||||
case MSG_CANCEL_BUTTON:
|
|
||||||
{
|
{
|
||||||
BMessage request(BT_MSG_HANDLE_SIMPLE_REQUEST);
|
BMessage request(BT_MSG_HANDLE_SIMPLE_REQUEST);
|
||||||
BMessage reply;
|
BMessage reply;
|
||||||
size_t size;
|
size_t size;
|
||||||
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) {
|
||||||
@@ -171,17 +183,17 @@ void PincodeWindow::MessageReceived(BMessage *msg)
|
|||||||
request.AddInt32("hci_id", fHid);
|
request.AddInt32("hci_id", fHid);
|
||||||
request.AddData("raw command", B_ANY_TYPE, command, size);
|
request.AddData("raw command", B_ANY_TYPE, command, size);
|
||||||
request.AddInt16("eventExpected", HCI_EVENT_CMD_COMPLETE);
|
request.AddInt16("eventExpected", HCI_EVENT_CMD_COMPLETE);
|
||||||
request.AddInt16("opcodeExpected", PACK_OPCODE(OGF_LINK_CONTROL, OCF_PIN_CODE_NEG_REPLY));
|
request.AddInt16("opcodeExpected", PACK_OPCODE(OGF_LINK_CONTROL,
|
||||||
|
OCF_PIN_CODE_NEG_REPLY));
|
||||||
|
|
||||||
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 ) {
|
||||||
PostMessage(B_QUIT_REQUESTED);
|
PostMessage(B_QUIT_REQUESTED);
|
||||||
}
|
}
|
||||||
// TODO: something failed here
|
// TODO: something failed here
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
default:
|
||||||
BWindow::MessageReceived(msg);
|
BWindow::MessageReceived(msg);
|
||||||
@@ -190,12 +202,9 @@ void PincodeWindow::MessageReceived(BMessage *msg)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
bool PincodeWindow::QuitRequested()
|
bool PincodeWindow::QuitRequested()
|
||||||
{
|
{
|
||||||
|
|
||||||
return BWindow::QuitRequested();
|
return BWindow::QuitRequested();
|
||||||
};
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user