- 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:
parent
214f370653
commit
a53e31dde4
@ -1,12 +1,9 @@
|
||||
/*
|
||||
* 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
|
||||
#define _PINCODE_REQUEST_WINDOW_H
|
||||
#ifndef _PINCODE_REQUEST_WINDOW_H
|
||||
#define _PINCODE_REQUEST_WINDOW_H
|
||||
|
||||
|
||||
#include <View.h>
|
||||
@ -18,44 +15,45 @@ class BStringView;
|
||||
class BButton;
|
||||
class BTextControls;
|
||||
|
||||
namespace Bluetooth {
|
||||
namespace Bluetooth {
|
||||
|
||||
class RemoteDevice;
|
||||
|
||||
class PincodeView : public BView
|
||||
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;
|
||||
|
||||
BStringView* fMessage;
|
||||
BStringView* fRemoteInfo;
|
||||
BButton* fAcceptButton;
|
||||
BButton* fCancelButton;
|
||||
BTextControl* fPincodeText;
|
||||
|
||||
};
|
||||
|
||||
class PincodeWindow : public BWindow
|
||||
class PincodeWindow : public BWindow
|
||||
{
|
||||
public:
|
||||
PincodeWindow(bdaddr_t address, hci_id hid);
|
||||
virtual void MessageReceived(BMessage *msg);
|
||||
virtual bool QuitRequested();
|
||||
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 bdaddr;
|
||||
bdaddr_t fBdaddr;
|
||||
hci_id fHid;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#ifndef _BT_USE_EXPLICIT_NAMESPACE
|
||||
#ifndef _BT_USE_EXPLICIT_NAMESPACE
|
||||
using Bluetooth::PincodeWindow;
|
||||
#endif
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
@ -1,9 +1,6 @@
|
||||
|
||||
/*
|
||||
* Copyright 2007-2008 Oliver Ruiz Dorantes, oliver.ruiz.dorantes_at_gmail.com
|
||||
*
|
||||
* All rights reserved. Distributed under the terms of the MIT License.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
@ -15,7 +12,9 @@
|
||||
#include <Application.h>
|
||||
|
||||
#include <Button.h>
|
||||
#include <GroupLayoutBuilder.h>
|
||||
#include <InterfaceDefs.h>
|
||||
#include <SpaceLayoutItem.h>
|
||||
#include <StringView.h>
|
||||
#include <TextControl.h>
|
||||
|
||||
@ -31,71 +30,66 @@
|
||||
#include <bluetoothserver_p.h>
|
||||
#include <CommandManager.h>
|
||||
|
||||
#define MSG_ACCEPT_BUTTON 'acCp'
|
||||
#define MSG_CANCEL_BUTTON 'mVch'
|
||||
|
||||
#define H_SEPARATION 15
|
||||
#define V_SEPARATION 10
|
||||
#define BD_ADDR_LABEL "BD_ADDR: "
|
||||
|
||||
static const uint32 skMessageAcceptButton = 'acCp';
|
||||
static const uint32 skMessageCancelButton = 'mVch';
|
||||
|
||||
|
||||
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));
|
||||
|
||||
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->ResizeToPreferred();
|
||||
fMessage->MoveBy(20, 20);
|
||||
rect1 = fMessage->Frame();
|
||||
|
||||
fRemoteInfo = new BStringView(BRect(rect1.left, rect1.bottom + V_SEPARATION , 0 , 0),
|
||||
"bdaddr","BD_ADDR: ", B_FOLLOW_ALL_SIDES);
|
||||
fRemoteInfo->ResizeToPreferred();
|
||||
rect1 = fRemoteInfo->Frame();
|
||||
fRemoteInfo = new BStringView("bdaddr","BD_ADDR: ", B_FOLLOW_ALL_SIDES);
|
||||
|
||||
// TODO: IT CANNOT BE MORE THAN 16 BYTES
|
||||
fPincodeText = new BTextControl(BRect(rect1.left, rect1.bottom + V_SEPARATION , rect1.right, rect1.bottom + V_SEPARATION + 20),
|
||||
"pincode TextControl","PIN code:", "5555", NULL);
|
||||
fPincodeText->ResizeToPreferred();
|
||||
rect1 = fPincodeText->Frame();
|
||||
// TODO: Pincode cannot be more than 16 bytes
|
||||
fPincodeText = new BTextControl("pincode TextControl", "PIN code:", "5555", NULL);
|
||||
|
||||
fAcceptButton = new BButton(BRect(rect1.left , rect1.bottom + V_SEPARATION ,0, 0 ),
|
||||
"fAcceptButton","Pair",new BMessage(MSG_ACCEPT_BUTTON));
|
||||
fAcceptButton->ResizeToPreferred();
|
||||
rect1 = fAcceptButton->Frame();
|
||||
fAcceptButton = new BButton("fAcceptButton", "Pair",
|
||||
new BMessage(skMessageAcceptButton));
|
||||
|
||||
fCancelButton = new BButton(BRect(rect1.right + H_SEPARATION , rect1.top , 0 , 0 ),
|
||||
"fCancelButton","Cancel",new BMessage(MSG_CANCEL_BUTTON));
|
||||
fCancelButton->ResizeToPreferred();
|
||||
|
||||
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 );
|
||||
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();
|
||||
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();
|
||||
|
||||
}
|
||||
|
||||
@ -103,20 +97,38 @@ void PincodeView::SetBDaddr(const char* address){
|
||||
#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)
|
||||
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().right , fView->Bounds().bottom );
|
||||
// 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) );
|
||||
};
|
||||
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)
|
||||
{
|
||||
@ -124,16 +136,17 @@ void PincodeWindow::MessageReceived(BMessage *msg)
|
||||
|
||||
switch(msg->what)
|
||||
{
|
||||
case MSG_ACCEPT_BUTTON:
|
||||
case skMessageAcceptButton:
|
||||
{
|
||||
BMessage request(BT_MSG_HANDLE_SIMPLE_REQUEST);
|
||||
BMessage reply;
|
||||
size_t size;
|
||||
int8 bt_status = BT_ERROR;
|
||||
size_t size;
|
||||
int8 bt_status = BT_ERROR;
|
||||
|
||||
void* command = buildPinCodeRequestReply(fBdaddr, strlen(fView->fPincodeText->Text()),
|
||||
(char*)fView->fPincodeText->Text(), &size);
|
||||
|
||||
void* command = buildPinCodeRequestReply(fBdaddr,
|
||||
strlen(fView->fPincodeText->Text()),
|
||||
(char*)fView->fPincodeText->Text(), &size);
|
||||
|
||||
if (command == NULL) {
|
||||
break;
|
||||
}
|
||||
@ -141,27 +154,26 @@ void PincodeWindow::MessageReceived(BMessage *msg)
|
||||
request.AddInt32("hci_id", fHid);
|
||||
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));
|
||||
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 ) {
|
||||
PostMessage(B_QUIT_REQUESTED);
|
||||
}
|
||||
// TODO: something failed here
|
||||
}
|
||||
|
||||
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
case MSG_CANCEL_BUTTON:
|
||||
|
||||
case skMessageCancelButton:
|
||||
{
|
||||
BMessage request(BT_MSG_HANDLE_SIMPLE_REQUEST);
|
||||
BMessage reply;
|
||||
size_t size;
|
||||
int8 bt_status = BT_ERROR;
|
||||
|
||||
size_t size;
|
||||
int8 bt_status = BT_ERROR;
|
||||
|
||||
void* command = buildPinCodeRequestNegativeReply(fBdaddr, &size);
|
||||
|
||||
if (command == NULL) {
|
||||
@ -171,17 +183,17 @@ void PincodeWindow::MessageReceived(BMessage *msg)
|
||||
request.AddInt32("hci_id", fHid);
|
||||
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));
|
||||
|
||||
request.AddInt16("opcodeExpected", PACK_OPCODE(OGF_LINK_CONTROL,
|
||||
OCF_PIN_CODE_NEG_REPLY));
|
||||
|
||||
if (be_app_messenger.SendMessage(&request, &reply) == B_OK) {
|
||||
if (reply.FindInt8("status", &bt_status ) == B_OK ) {
|
||||
PostMessage(B_QUIT_REQUESTED);
|
||||
}
|
||||
// TODO: something failed here
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
BWindow::MessageReceived(msg);
|
||||
@ -190,12 +202,9 @@ void PincodeWindow::MessageReceived(BMessage *msg)
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool PincodeWindow::QuitRequested()
|
||||
{
|
||||
|
||||
return BWindow::QuitRequested();
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user