diff --git a/headers/private/bluetooth/BluetoothIconView.h b/headers/private/bluetooth/BluetoothIconView.h new file mode 100644 index 0000000000..713c649038 --- /dev/null +++ b/headers/private/bluetooth/BluetoothIconView.h @@ -0,0 +1,33 @@ +/* + * Copyright 2021, Haiku, Inc. + * Distributed under the terms of the MIT License. + * + * Authors: + * Tri-Edge AI + */ + +#ifndef _BLUETOOTH_ICON_VIEW_H_ +#define _BLUETOOTH_ICON_VIEW_H_ + +#include +#include +#include +#include + +namespace Bluetooth { + +class BluetoothIconView : public BView { +public: + BluetoothIconView(); + ~BluetoothIconView(); + + void Draw(BRect rect); + +private: + static BBitmap* fBitmap; + static int32 fRefCount; +}; + +} + +#endif /* _BLUETOOTH_ICON_VIEW_H_ */ diff --git a/headers/private/bluetooth/ConnectionIncoming.h b/headers/private/bluetooth/ConnectionIncoming.h index f8292f892f..5924fed21c 100644 --- a/headers/private/bluetooth/ConnectionIncoming.h +++ b/headers/private/bluetooth/ConnectionIncoming.h @@ -1,52 +1,44 @@ /* - * Copyright 2007-2008 Oliver Ruiz Dorantes, oliver.ruiz.dorantes_at_gmail.com - * - * All rights reserved. Distributed under the terms of the MIT License. - * - */ +* Copyright 2021, Haiku, Inc. +* Distributed under the terms of the MIT License. +* +* Authors: +* Oliver Ruiz Dorantes +* Tri-Edge AI +*/ #ifndef _CONNECTION_INCOMING_H_ #define _CONNECTION_INCOMING_H_ - -//----------------------- Global includes ---------------------- -#include -#include -#include #include #include #include +#include +#include +#include + +#include +#include +#include + + namespace Bluetooth { class RemoteDevice; +class ConnectionView; -class ConnectionView - : public BView -{ +class ConnectionIncoming : public BWindow { public: - ConnectionView(BRect frame, const char *name); - ~ConnectionView(); - virtual void MessageReceived(BMessage *message); - void Draw(BRect update); - void Pulse(); - -private: - - -}; - - -class ConnectionIncoming : public BWindow -{ -public: - ConnectionIncoming(RemoteDevice* rDevice); + ConnectionIncoming(bdaddr_t address); + ConnectionIncoming(RemoteDevice* rDevice = NULL); ~ConnectionIncoming(); - virtual void MessageReceived(BMessage *message); + + virtual void MessageReceived(BMessage* message); virtual bool QuitRequested(); private: - ConnectionView* _ConnectionView; + ConnectionView* fView; }; } @@ -55,5 +47,4 @@ private: using Bluetooth::ConnectionIncoming; #endif - -#endif +#endif /* _CONNECTION_INCOMING_H_ */ diff --git a/headers/private/bluetooth/ConnectionView.h b/headers/private/bluetooth/ConnectionView.h new file mode 100644 index 0000000000..38e2b04cc1 --- /dev/null +++ b/headers/private/bluetooth/ConnectionView.h @@ -0,0 +1,44 @@ +/* + * Copyright 2021, Haiku, Inc. + * Distributed under the terms of the MIT License. + * + * Authors: + * Tri-Edge AI + * Oliver Ruiz Dorantes + */ + +#ifndef _CONNECTION_VIEW_H_ +#define _CONNECTION_VIEW_H_ + +#include +#include +#include +#include +#include +#include +#include + +namespace Bluetooth { + +class BluetoothIconView; + +class ConnectionView : public BView { +public: + ConnectionView(BRect frame, + BString device, BString address); + + void Pulse(); + +private: + BString strMessage; + BluetoothIconView* fIcon; + BStringView* fMessage; + BStringView* fDeviceLabel; + BStringView* fDeviceText; + BStringView* fAddressLabel; + BStringView* fAddressText; +}; + +} + +#endif /* _CONNECTION_VIEW_H_ */ diff --git a/headers/private/bluetooth/PincodeWindow.h b/headers/private/bluetooth/PincodeWindow.h index d39ad7b4db..169ab79124 100644 --- a/headers/private/bluetooth/PincodeWindow.h +++ b/headers/private/bluetooth/PincodeWindow.h @@ -1,9 +1,14 @@ /* - * Copyright 2007-2008 Oliver Ruiz Dorantes, oliver.ruiz.dorantes_at_gmail.com - * All rights reserved. Distributed under the terms of the MIT License. - */ -#ifndef _PINCODE_REQUEST_WINDOW_H -#define _PINCODE_REQUEST_WINDOW_H +* Copyright 2021, Haiku, Inc. +* Distributed under the terms of the MIT License. +* +* Authors: +* Oliver Ruiz Dorantes +* Tri-Edge AI +*/ + +#ifndef _PINCODE_REQUEST_WINDOW_H_ +#define _PINCODE_REQUEST_WINDOW_H_ #include @@ -12,20 +17,21 @@ #include #include +#include + class BStringView; class BButton; class BTextControl; -namespace Bluetooth { +namespace Bluetooth { class RemoteDevice; -class PincodeWindow : public BWindow -{ +class PincodeWindow : public BWindow { public: PincodeWindow(bdaddr_t address, hci_id hid); PincodeWindow(RemoteDevice* rDevice); - virtual void MessageReceived(BMessage *msg); + virtual void MessageReceived(BMessage* msg); virtual bool QuitRequested(); void SetBDaddr(BString address); @@ -39,6 +45,13 @@ private: BButton* fAcceptButton; BButton* fCancelButton; BTextControl* fPincodeText; + + BluetoothIconView* fIcon; + BStringView* fMessage2; + BStringView* fDeviceLabel; + BStringView* fDeviceText; + BStringView* fAddressLabel; + BStringView* fAddressText; }; } @@ -47,4 +60,4 @@ private: using Bluetooth::PincodeWindow; #endif -#endif +#endif /* _PINCODE_REQUEST_WINDOW_H_ */ diff --git a/src/kits/bluetooth/Jamfile b/src/kits/bluetooth/Jamfile index 7e364f5596..01d87277f3 100644 --- a/src/kits/bluetooth/Jamfile +++ b/src/kits/bluetooth/Jamfile @@ -25,6 +25,8 @@ for architectureObject in [ MultiArchSubDirSetup ] { #UI PincodeWindow.cpp ConnectionIncoming.cpp + ConnectionView.cpp + BluetoothIconView.cpp : be localestub [ TargetLibstdc++ ] ; diff --git a/src/kits/bluetooth/UI/BluetoothIconView.cpp b/src/kits/bluetooth/UI/BluetoothIconView.cpp new file mode 100644 index 0000000000..573d5c473b --- /dev/null +++ b/src/kits/bluetooth/UI/BluetoothIconView.cpp @@ -0,0 +1,59 @@ +/* + * Copyright 2021, Haiku, Inc. + * Distributed under the terms of the MIT License. + * + * Authors: + * Tri-Edge AI + */ + +#include + +#include + +namespace Bluetooth { + +BBitmap* BluetoothIconView::fBitmap = NULL; +int32 BluetoothIconView::fRefCount = 0; + +BluetoothIconView::BluetoothIconView() + : + BView(BRect(0, 0, 80, 80), "", B_FOLLOW_ALL, B_WILL_DRAW) +{ + if (fRefCount == 0) { + fBitmap = new BBitmap(BRect(0, 0, 64, 64), 0, B_RGBA32); + + uint8* tempIcon; + size_t tempSize; + + BMimeType mime("application/x-vnd.Haiku-bluetooth_server"); + mime.GetIcon(&tempIcon, &tempSize); + + BIconUtils::GetVectorIcon(tempIcon, tempSize, fBitmap); + + fRefCount++; + } else { + fRefCount++; + } + + SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); + SetDrawingMode(B_OP_ALPHA); + SetBlendingMode(B_CONSTANT_ALPHA, B_ALPHA_OVERLAY); +} + + +BluetoothIconView::~BluetoothIconView() +{ + fRefCount--; + + if (fRefCount <= 0) + delete fBitmap; +} + + +void +BluetoothIconView::Draw(BRect rect) +{ + this->DrawBitmap(fBitmap); +} + +} diff --git a/src/kits/bluetooth/UI/ConnectionIncoming.cpp b/src/kits/bluetooth/UI/ConnectionIncoming.cpp index c4ac1961a1..c76fc38818 100644 --- a/src/kits/bluetooth/UI/ConnectionIncoming.cpp +++ b/src/kits/bluetooth/UI/ConnectionIncoming.cpp @@ -1,66 +1,51 @@ /* - * Copyright 2007-2008 Oliver Ruiz Dorantes, oliver.ruiz.dorantes_at_gmail.com - * All rights reserved. Distributed under the terms of the MIT License. + * Copyright 2021, Haiku, Inc. + * Distributed under the terms of the MIT License. + * + * Authors: + * Oliver Ruiz Dorantes + * Tri-Edge AI */ #include +#include +namespace Bluetooth +{ -#define B_PULSES_BY_SECOND(x) (2*x) - - -namespace Bluetooth { - - -ConnectionView::ConnectionView(BRect frame, const char *name) +ConnectionIncoming::ConnectionIncoming(bdaddr_t address) : - BView(BRect(0, 0, 400, 400), "MyViewName", B_FOLLOW_LEFT | B_FOLLOW_TOP, - B_WILL_DRAW | B_PULSE_NEEDED) + BWindow(BRect(600, 100, 1000, 180), "Incoming Connection..", + B_FLOATING_WINDOW_LOOK, B_NORMAL_WINDOW_FEEL, + B_NOT_ZOOMABLE | B_NOT_RESIZABLE) + // 400x80 { - SetViewUIColor(B_PANEL_BACKGROUND_COLOR); + SetPulseRate(1 * 1000 * 1000); + // 1 second + fView = new ConnectionView(BRect(0, 0, 400, 80), "", + bdaddrUtils::ToString(address)); + AddChild(fView); } -ConnectionView::~ConnectionView() -{ -} - - -void ConnectionView::MessageReceived(BMessage *message) -{ -} - - -void ConnectionView::Draw(BRect update) -{ -} - - -void ConnectionView::Pulse() -{ - static int a = 0; - - if (a++ == B_PULSES_BY_SECOND(5)) { - // BUG: for some reason the window is not being removed... - Window()->PostMessage(B_QUIT_REQUESTED); - Window()->Quit(); - } -} - - -//#pragma mark - - - ConnectionIncoming::ConnectionIncoming(RemoteDevice* rDevice) : - BWindow(BRect(700, 100, 900, 150), "Connection completed", + BWindow(BRect(600, 100, 1000, 180), "Incoming Connection", B_FLOATING_WINDOW_LOOK, B_NORMAL_WINDOW_FEEL, B_NOT_ZOOMABLE | B_NOT_RESIZABLE) { - _ConnectionView = new ConnectionView(BRect(0, 0, 400, 400),"mViewName"); + SetPulseRate(1 * 1000 * 1000); + // 1 second - AddChild(_ConnectionView); + if (rDevice != NULL) + fView = new ConnectionView(BRect(0, 0, 400, 80), rDevice->GetFriendlyName(), + bdaddrUtils::ToString(rDevice->GetBluetoothAddress())); + else + fView = new ConnectionView(BRect(0, 0, 400, 80), "", + bdaddrUtils::ToString(bdaddrUtils::NullAddress())); + + AddChild(fView); } @@ -69,12 +54,14 @@ ConnectionIncoming::~ConnectionIncoming() } -void ConnectionIncoming::MessageReceived(BMessage *message) +void +ConnectionIncoming::MessageReceived(BMessage* message) { } -bool ConnectionIncoming::QuitRequested() +bool +ConnectionIncoming::QuitRequested() { return BWindow::QuitRequested(); } diff --git a/src/kits/bluetooth/UI/ConnectionView.cpp b/src/kits/bluetooth/UI/ConnectionView.cpp new file mode 100644 index 0000000000..ee39779905 --- /dev/null +++ b/src/kits/bluetooth/UI/ConnectionView.cpp @@ -0,0 +1,81 @@ +/* + * Copyright 2021, Haiku, Inc. + * Distributed under the terms of the MIT License. + * + * Authors: + * Tri-Edge AI + */ + +#include +#include + +namespace Bluetooth +{ + +ConnectionView::ConnectionView(BRect frame, BString device, BString address) + : + BView(frame, "ConnectionView", 0, B_PULSE_NEEDED) +{ + SetLayout(new BGroupLayout(B_HORIZONTAL)); + SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); + + fIcon = new BluetoothIconView(); + + strMessage = "A new connection is incoming.."; + + fMessage = new BStringView(frame, "", strMessage, B_FOLLOW_LEFT); + fMessage->SetAlignment(B_ALIGN_LEFT); + + fDeviceLabel = new BStringView(frame, "", "Device Name:", B_FOLLOW_LEFT); + fDeviceLabel->SetFont(be_bold_font); + + fDeviceText = new BStringView(frame, "", device, B_FOLLOW_RIGHT); + fDeviceText->SetAlignment(B_ALIGN_RIGHT); + + fAddressLabel = new BStringView(frame, "", "MAC Address:", B_FOLLOW_LEFT); + fAddressLabel->SetFont(be_bold_font); + + fAddressText = new BStringView(frame, "", address, B_FOLLOW_RIGHT); + fAddressText->SetAlignment(B_ALIGN_RIGHT); + + AddChild(BGroupLayoutBuilder(B_HORIZONTAL, 0) + .Add(BGroupLayoutBuilder(B_VERTICAL, 8) + .Add(fIcon) + ) + .Add(BGroupLayoutBuilder(B_VERTICAL, 0) + .Add(fMessage) + .AddGlue() + .Add(BGroupLayoutBuilder(B_HORIZONTAL, 10) + .Add(fDeviceLabel) + .AddGlue() + .Add(fDeviceText) + ) + .Add(BGroupLayoutBuilder(B_HORIZONTAL, 10) + .Add(fAddressLabel) + .AddGlue() + .Add(fAddressText) + ) + .AddGlue() + ) + .AddGlue() + .SetInsets(8, 8, 8, 8) + ); +} + + +void +ConnectionView::Pulse() +{ + static int pulses = 0; + + pulses++; + + if (pulses >= 5) { + Window()->PostMessage(B_QUIT_REQUESTED); + } else { + strMessage += "."; + fMessage->SetText(strMessage); + } +} + +} diff --git a/src/kits/bluetooth/UI/PincodeWindow.cpp b/src/kits/bluetooth/UI/PincodeWindow.cpp index 37d386c715..e911b20457 100644 --- a/src/kits/bluetooth/UI/PincodeWindow.cpp +++ b/src/kits/bluetooth/UI/PincodeWindow.cpp @@ -1,6 +1,10 @@ /* - * Copyright 2007-2008 Oliver Ruiz Dorantes, oliver.ruiz.dorantes_at_gmail.com - * All rights reserved. Distributed under the terms of the MIT License. + * Copyright 2021, Haiku, Inc. + * Distributed under the terms of the MIT License. + * + * Authors: + * Oliver Ruiz Dorantes + * Tri-Edge AI */ @@ -41,20 +45,15 @@ static const uint32 skMessageAcceptButton = 'acCp'; static const uint32 skMessageCancelButton = 'mVch'; -namespace Bluetooth { - - -#if 0 -#pragma mark - -#endif - +namespace Bluetooth +{ 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) + : BWindow(BRect(700, 200, 1000, 400), "PIN Code Request", + B_FLOATING_WINDOW_LOOK, B_NORMAL_WINDOW_FEEL, + B_NOT_ZOOMABLE | B_NOT_RESIZABLE), + fBdaddr(address), + fHid(hid) { InitUI(); @@ -65,12 +64,12 @@ PincodeWindow::PincodeWindow(bdaddr_t address, hci_id hid) 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) + : BWindow(BRect(700, 200, 1000, 400), "PIN Code Request", + B_FLOATING_WINDOW_LOOK, B_NORMAL_WINDOW_FEEL, + B_NOT_ZOOMABLE | B_NOT_RESIZABLE) { + InitUI(); + // TODO: Get more info about device" ote name/features/encry/auth... etc SetBDaddr(bdaddrUtils::ToString(rDevice->GetBluetoothAddress())); fHid = (rDevice->GetLocalDeviceOwner())->ID(); @@ -82,14 +81,24 @@ PincodeWindow::InitUI() { SetLayout(new BGroupLayout(B_HORIZONTAL)); - fMessage = new BStringView("Pincode", "Please enter the pincode ..."); - fMessage->SetFont(be_bold_font); + fIcon = new BluetoothIconView(); - fRemoteInfo = new BStringView("bdaddr","BD_ADDR: "); + fMessage = new BStringView("fMessage", "Input the PIN code to pair with"); + fMessage2 = new BStringView("fMessage2", "the following Bluetooth device."); - // TODO: Pincode cannot be more than 16 bytes - fPincodeText = new BTextControl("pincode TextControl", "PIN code:", - "5555", NULL); + fDeviceLabel = new BStringView("fDeviceLabel","Device Name: "); + fDeviceLabel->SetFont(be_bold_font); + + fDeviceText = new BStringView("fDeviceText", ""); + + fAddressLabel = new BStringView("fAddressLabel", "MAC Address: "); + fAddressLabel->SetFont(be_bold_font); + + fAddressText = new BStringView("fAddressText", ""); + + fPincodeText = new BTextControl("fPINCode", "PIN Code:", "0000", NULL); + fPincodeText->TextView()->SetMaxBytes(16 * sizeof(fPincodeText->Text()[0])); + fPincodeText->MakeFocus(); fAcceptButton = new BButton("fAcceptButton", "Pair", new BMessage(skMessageAcceptButton)); @@ -97,27 +106,44 @@ PincodeWindow::InitUI() fCancelButton = new BButton("fCancelButton", "Cancel", new BMessage(skMessageCancelButton)); - AddChild(BGroupLayoutBuilder(B_VERTICAL, 10) + AddChild(BGroupLayoutBuilder(B_VERTICAL, 0) + .Add(BGroupLayoutBuilder(B_HORIZONTAL, 0) + .Add(BGroupLayoutBuilder(B_HORIZONTAL, 8) + .Add(fIcon) + ) + .Add(BGroupLayoutBuilder(B_VERTICAL, 0) .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) + .Add(fMessage2) + .AddGlue() + ) + ) + .Add(BGroupLayoutBuilder(B_HORIZONTAL, 0) + .Add(fDeviceLabel) + .AddGlue() + .Add(fDeviceText) + ) + .Add(BGroupLayoutBuilder(B_HORIZONTAL, 0) + .Add(fAddressLabel) + .AddGlue() + .Add(fAddressText) + ) + .AddGlue() + .Add(fPincodeText) + .AddGlue() + .Add(BGroupLayoutBuilder(B_HORIZONTAL, 10) + .AddGlue() + .Add(fCancelButton) + .Add(fAcceptButton) + ) + .SetInsets(8, 8, 8, 8) ); } void -PincodeWindow::MessageReceived(BMessage *msg) +PincodeWindow::MessageReceived(BMessage* msg) { -// status_t err = B_OK; - - switch(msg->what) + switch (msg->what) { case skMessageAcceptButton: { @@ -142,7 +168,7 @@ PincodeWindow::MessageReceived(BMessage *msg) // we reside in the server 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); } // TODO: something failed here @@ -185,23 +211,17 @@ PincodeWindow::MessageReceived(BMessage *msg) } -bool PincodeWindow::QuitRequested() +bool +PincodeWindow::QuitRequested() { return BWindow::QuitRequested(); } -void PincodeWindow::SetBDaddr(BString address) +void +PincodeWindow::SetBDaddr(BString address) { - BString label; - - label << BD_ADDR_LABEL << address; - printf("++ %s\n",label.String()); - fRemoteInfo->SetText(label.String()); - fRemoteInfo->ResizeToPreferred(); - //Invalidate(); - + fAddressText->SetText(address); } - } /* end namespace Bluetooth */