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
+13 -22
View File
@@ -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);
PincodeView(BRect rect); PincodeWindow(RemoteDevice* rDevice);
virtual void MessageReceived(BMessage *msg);
virtual bool QuitRequested();
void SetBDaddr(const char* address); void SetBDaddr(const char* address);
private:
void InitUI();
bdaddr_t fBdaddr;
hci_id fHid;
BStringView* fMessage; BStringView* fMessage;
BStringView* fRemoteInfo; BStringView* fRemoteInfo;
BButton* fAcceptButton; BButton* fAcceptButton;
BButton* fCancelButton; BButton* fCancelButton;
BTextControl* fPincodeText; 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;
}; };
} }
+58 -65
View File
@@ -41,17 +41,48 @@ static const uint32 skMessageCancelButton = 'mVch';
namespace Bluetooth { namespace Bluetooth {
PincodeView::PincodeView(BRect rect)
: BView(rect,"View", B_FOLLOW_NONE, B_WILL_DRAW ) #if 0
#pragma mark -
#endif
PincodeWindow::PincodeWindow(bdaddr_t address, hci_id hid)
: 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)
{ {
InitUI();
SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); // TODO: Get more info about device" ote name/features/encry/auth... etc
SetBDaddr(bdaddrUtils::ToString(fBdaddr));
fMessage = new BStringView("Pincode", "Please enter the pincode ...", }
B_FOLLOW_ALL_SIDES);
PincodeWindow::PincodeWindow(RemoteDevice* rDevice)
: 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)
{
// TODO: Get more info about device" ote name/features/encry/auth... etc
SetBDaddr(bdaddrUtils::ToString(rDevice->GetBluetoothAddress()));
fHid = (rDevice->GetLocalDeviceOwner())->ID();
}
void
PincodeWindow::InitUI()
{
SetLayout(new BGroupLayout(B_HORIZONTAL));
fMessage = new BStringView("Pincode", "Please enter the pincode ...");
fMessage->SetFont(be_bold_font); fMessage->SetFont(be_bold_font);
fRemoteInfo = new BStringView("bdaddr","BD_ADDR: ", B_FOLLOW_ALL_SIDES); fRemoteInfo = new BStringView("bdaddr","BD_ADDR: ");
// TODO: Pincode cannot be more than 16 bytes // TODO: Pincode cannot be more than 16 bytes
fPincodeText = new BTextControl("pincode TextControl", "PIN code:", "5555", NULL); fPincodeText = new BTextControl("pincode TextControl", "PIN code:", "5555", NULL);
@@ -62,75 +93,23 @@ PincodeView::PincodeView(BRect rect)
fCancelButton = new BButton("fCancelButton", "Cancel", fCancelButton = new BButton("fCancelButton", "Cancel",
new BMessage(skMessageCancelButton)); new BMessage(skMessageCancelButton));
SetLayout(new BGroupLayout(B_HORIZONTAL)); AddChild(BGroupLayoutBuilder(B_VERTICAL, 10)
AddChild(BGroupLayoutBuilder(B_VERTICAL, 0)
.Add(fMessage) .Add(fMessage)
.Add(fRemoteInfo) .Add(fRemoteInfo)
.Add(fPincodeText) .Add(fPincodeText)
.Add(BGroupLayoutBuilder(B_HORIZONTAL) .Add(BGroupLayoutBuilder(B_HORIZONTAL, 10)
.AddGlue() .AddGlue()
.Add(fCancelButton) .Add(fCancelButton)
.Add(fAcceptButton) .Add(fAcceptButton)
.SetInsets(5, 5, 5, 5) .SetInsets(5, 5, 5, 5)
) )
.Add(BSpaceLayoutItem::CreateVerticalStrut(0)) .SetInsets(15, 15, 15, 15)
.SetInsets(5, 5, 5, 5)
); );
} }
void PincodeView::SetBDaddr(const char* address) void
{ PincodeWindow::MessageReceived(BMessage *msg)
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,
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());
// TODO: Get more info about device" ote name/features/encry/auth... etc
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)
{ {
// status_t err = B_OK; // status_t err = B_OK;
@@ -144,8 +123,8 @@ void PincodeWindow::MessageReceived(BMessage *msg)
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;
@@ -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();
}
} }