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:
Oliver Ruiz Dorantes 2009-10-06 20:03:36 +00:00
parent b0488dca68
commit 515209e338
2 changed files with 89 additions and 105 deletions

View File

@ -10,44 +10,35 @@
#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;
};
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;
BStringView* fMessage;
BStringView* fRemoteInfo;
BButton* fAcceptButton;
BButton* fCancelButton;
BTextControl* fPincodeText;
};
}

View File

@ -41,99 +41,78 @@ static const uint32 skMessageCancelButton = 'mVch';
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
#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,
: 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)
{
fView = new PincodeView(Bounds());
AddChild(fView);
// Readapt ourselves to what the view needs
ResizeTo(fView->Bounds().Width(), fView->Bounds().Height());
InitUI();
// 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)
: 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,
: 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)
{
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()));
SetBDaddr(bdaddrUtils::ToString(rDevice->GetBluetoothAddress()));
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;
switch(msg->what)
{
case skMessageAcceptButton:
@ -142,10 +121,10 @@ void PincodeWindow::MessageReceived(BMessage *msg)
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 @@ void PincodeWindow::MessageReceived(BMessage *msg)
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 @@ void PincodeWindow::MessageReceived(BMessage *msg)
}
break;
}
case skMessageCancelButton:
{
BMessage request(BT_MSG_HANDLE_SIMPLE_REQUEST);
@ -175,7 +154,7 @@ void PincodeWindow::MessageReceived(BMessage *msg)
int8 bt_status = BT_ERROR;
void* command = buildPinCodeRequestNegativeReply(fBdaddr, &size);
if (command == NULL) {
break;
}
@ -197,7 +176,7 @@ void PincodeWindow::MessageReceived(BMessage *msg)
default:
BWindow::MessageReceived(msg);
break;
break;
}
}
@ -207,4 +186,18 @@ bool PincodeWindow::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();
}
}