- Add authentication checkbox to force authenticate connections
- Implement Pair button for allowing Haiku initiate the connection git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@36448 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -10,7 +10,6 @@
|
|||||||
#include <bluetooth/BluetoothDevice.h>
|
#include <bluetooth/BluetoothDevice.h>
|
||||||
/*#include "../media/iconfile.h"*/
|
/*#include "../media/iconfile.h"*/
|
||||||
|
|
||||||
|
|
||||||
#include "DeviceListItem.h"
|
#include "DeviceListItem.h"
|
||||||
|
|
||||||
#define INSETS 5
|
#define INSETS 5
|
||||||
@@ -19,23 +18,14 @@
|
|||||||
namespace Bluetooth {
|
namespace Bluetooth {
|
||||||
|
|
||||||
DeviceListItem::DeviceListItem(BluetoothDevice* bDevice)
|
DeviceListItem::DeviceListItem(BluetoothDevice* bDevice)
|
||||||
: BListItem(),
|
:
|
||||||
fDevice(bDevice)
|
BListItem(),
|
||||||
{
|
fDevice(bDevice),
|
||||||
SetDevice(fDevice);
|
fName("unknown")
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
DeviceListItem::DeviceListItem(bdaddr_t bdaddr, DeviceClass dClass, int32 rssi)
|
|
||||||
: BListItem(),
|
|
||||||
fDevice(NULL),
|
|
||||||
fAddress(bdaddr),
|
|
||||||
fClass(dClass),
|
|
||||||
fName("unknown"),
|
|
||||||
fRSSI(rssi)
|
|
||||||
{
|
{
|
||||||
|
fAddress = bDevice->GetBluetoothAddress();
|
||||||
}
|
fClass = bDevice->GetDeviceClass();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
@@ -44,28 +34,28 @@ DeviceListItem::SetDevice(BluetoothDevice* bDevice)
|
|||||||
fAddress = bDevice->GetBluetoothAddress();
|
fAddress = bDevice->GetBluetoothAddress();
|
||||||
fClass = bDevice->GetDeviceClass();
|
fClass = bDevice->GetDeviceClass();
|
||||||
fName = bDevice->GetFriendlyName();
|
fName = bDevice->GetFriendlyName();
|
||||||
// AKAIR rssi can only be got at inquiry time...
|
// AKAIR rssi we can just have it @ inquiry time...
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
DeviceListItem::~DeviceListItem()
|
DeviceListItem::~DeviceListItem()
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
DeviceListItem::DrawItem(BView* owner, BRect itemRect, bool complete)
|
DeviceListItem::DrawItem(BView* owner, BRect itemRect, bool complete)
|
||||||
{
|
{
|
||||||
rgb_color kBlack = { 0,0,0,0 };
|
rgb_color kBlack = { 0, 0, 0, 0 };
|
||||||
rgb_color kHighlight = { 156,154,156,0 };
|
rgb_color kHighlight = { 156, 154, 156, 0 };
|
||||||
|
|
||||||
if (IsSelected() || complete) {
|
if (IsSelected() || complete) {
|
||||||
rgb_color color;
|
rgb_color color;
|
||||||
if (IsSelected())
|
if (IsSelected())
|
||||||
color = kHighlight;
|
color = kHighlight;
|
||||||
else
|
else
|
||||||
color = owner->ViewColor();
|
color = owner->ViewColor();
|
||||||
|
|
||||||
owner->SetHighColor(color);
|
owner->SetHighColor(color);
|
||||||
owner->SetLowColor(color);
|
owner->SetLowColor(color);
|
||||||
@@ -79,7 +69,8 @@ DeviceListItem::DrawItem(BView* owner, BRect itemRect, bool complete)
|
|||||||
font_height finfo;
|
font_height finfo;
|
||||||
be_plain_font->GetHeight(&finfo);
|
be_plain_font->GetHeight(&finfo);
|
||||||
|
|
||||||
BPoint point = BPoint(itemRect.left + DeviceClass::PixelsForIcon + 2*INSETS, itemRect.bottom - finfo.descent + 1);
|
BPoint point = BPoint(itemRect.left + DeviceClass::PixelsForIcon
|
||||||
|
+ 2 * INSETS, itemRect.bottom - finfo.descent + 1);
|
||||||
owner->SetFont(be_fixed_font);
|
owner->SetFont(be_fixed_font);
|
||||||
owner->SetHighColor(kBlack);
|
owner->SetHighColor(kBlack);
|
||||||
owner->MovePenTo(point);
|
owner->MovePenTo(point);
|
||||||
@@ -90,66 +81,78 @@ DeviceListItem::DrawItem(BView* owner, BRect itemRect, bool complete)
|
|||||||
fClass.GetMajorDeviceClass(secondLine);
|
fClass.GetMajorDeviceClass(secondLine);
|
||||||
secondLine << " / ";
|
secondLine << " / ";
|
||||||
fClass.GetMinorDeviceClass(secondLine);
|
fClass.GetMinorDeviceClass(secondLine);
|
||||||
|
|
||||||
owner->DrawString(secondLine.String());
|
|
||||||
|
|
||||||
point -= BPoint(0, (finfo.ascent + finfo.descent + finfo.leading) + INSETS);
|
owner->DrawString(secondLine.String());
|
||||||
|
|
||||||
|
point -= BPoint(0, (finfo.ascent + finfo.descent + finfo.leading) + INSETS);
|
||||||
|
|
||||||
owner->SetFont(be_plain_font);
|
owner->SetFont(be_plain_font);
|
||||||
owner->MovePenTo(point);
|
owner->MovePenTo(point);
|
||||||
owner->DrawString(fName.String());
|
owner->DrawString(fName.String());
|
||||||
|
|
||||||
fClass.Draw(owner, BPoint(itemRect.left, itemRect.top));
|
fClass.Draw(owner, BPoint(itemRect.left, itemRect.top));
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
switch (fClass.GetMajorDeviceClass()) {
|
switch (fClass.GetMajorDeviceClass()) {
|
||||||
case 1:
|
case 1:
|
||||||
{
|
{
|
||||||
BRect iconRect(0,0,15,15);
|
BRect iconRect(0, 0, 15, 15);
|
||||||
BBitmap *icon=new BBitmap(iconRect, B_CMAP8);
|
BBitmap* icon = new BBitmap(iconRect, B_CMAP8);
|
||||||
icon->SetBits(kTVBits, kTVWidth*kTVHeight, 0, kTVColorSpace);
|
icon->SetBits(kTVBits, kTVWidth * kTVHeight, 0, kTVColorSpace);
|
||||||
owner->DrawBitmap(icon, iconRect,BRect(itemRect.left + INSETS, itemRect.top + INSETS,
|
owner->DrawBitmap(icon, iconRect, BRect(itemRect.left + INSETS,
|
||||||
itemRect.left + INSETS + PIXELS_FOR_ICON, itemRect.top + INSETS + PIXELS_FOR_ICON));
|
itemRect.top + INSETS, itemRect.left + INSETS + PIXELS_FOR_ICON,
|
||||||
|
itemRect.top + INSETS + PIXELS_FOR_ICON));
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
break;
|
|
||||||
case 4:
|
case 4:
|
||||||
{
|
{
|
||||||
BRect iconRect(0,0,15,15);
|
BRect iconRect(0, 0, 15, 15);
|
||||||
BBitmap *icon=new BBitmap(iconRect, B_CMAP8);
|
BBitmap* icon = new BBitmap(iconRect, B_CMAP8);
|
||||||
icon->SetBits(kMixerBits, kMixerWidth*kMixerHeight, 0, kMixerColorSpace);
|
icon->SetBits(kMixerBits, kMixerWidth * kMixerHeight, 0, kMixerColorSpace);
|
||||||
owner->DrawBitmap(icon, iconRect,BRect(itemRect.left + INSETS, itemRect.top + INSETS,
|
owner->DrawBitmap(icon, iconRect, BRect(itemRect.left + INSETS,
|
||||||
itemRect.left + INSETS + PIXELS_FOR_ICON, itemRect.top + INSETS + PIXELS_FOR_ICON));
|
itemRect.top + INSETS, itemRect.left + INSETS + PIXELS_FOR_ICON,
|
||||||
|
itemRect.top + INSETS + PIXELS_FOR_ICON));
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
break;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
owner->SetHighColor(kBlack);
|
owner->SetHighColor(kBlack);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
DeviceListItem::Update(BView *owner, const BFont *font)
|
DeviceListItem::Update(BView* owner, const BFont* font)
|
||||||
{
|
{
|
||||||
BListItem::Update(owner,font);
|
BListItem::Update(owner, font);
|
||||||
|
|
||||||
font_height height;
|
font_height height;
|
||||||
font->GetHeight(&height);
|
font->GetHeight(&height);
|
||||||
SetHeight(MAX((height.ascent + height.descent + height.leading) * TEXT_ROWS +
|
SetHeight(MAX((height.ascent + height.descent + height.leading) * TEXT_ROWS
|
||||||
(TEXT_ROWS+1)*INSETS, DeviceClass::PixelsForIcon + 2 * INSETS));
|
+ (TEXT_ROWS + 1)*INSETS, DeviceClass::PixelsForIcon + 2 * INSETS));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
|
||||||
DeviceListItem::Compare(const void *firstArg, const void *secondArg)
|
int
|
||||||
{
|
DeviceListItem::Compare(const void *firstArg, const void *secondArg)
|
||||||
const DeviceListItem *item1 = *static_cast<const DeviceListItem * const *>(firstArg);
|
{
|
||||||
const DeviceListItem *item2 = *static_cast<const DeviceListItem * const *>(secondArg);
|
const DeviceListItem* item1 = *static_cast<const DeviceListItem* const *>
|
||||||
|
(firstArg);
|
||||||
return (int)bdaddrUtils::Compare((bdaddr_t*)&item1->fAddress, (bdaddr_t*)&item2->fAddress);
|
const DeviceListItem* item2 = *static_cast<const DeviceListItem* const *>
|
||||||
}
|
(secondArg);
|
||||||
|
|
||||||
|
return (int)bdaddrUtils::Compare((bdaddr_t*)&item1->fAddress,
|
||||||
|
(bdaddr_t*)&item2->fAddress);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
BluetoothDevice*
|
||||||
|
DeviceListItem::Device() const
|
||||||
|
{
|
||||||
|
return fDevice;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,15 +19,15 @@ class DeviceListItem : public BListItem
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
DeviceListItem(BluetoothDevice* bDevice);
|
DeviceListItem(BluetoothDevice* bDevice);
|
||||||
DeviceListItem(bdaddr_t bdaddr, DeviceClass dClass, int32 rssi = 0);
|
|
||||||
|
|
||||||
~DeviceListItem();
|
~DeviceListItem();
|
||||||
|
|
||||||
void DrawItem(BView *, BRect, bool = false);
|
void DrawItem(BView*, BRect, bool = false);
|
||||||
void Update(BView *owner, const BFont *font);
|
void Update(BView* owner, const BFont* font);
|
||||||
|
|
||||||
static int Compare(const void *firstArg, const void *secondArg);
|
static int Compare(const void* firstArg, const void* secondArg);
|
||||||
void SetDevice(BluetoothDevice* bDevice);
|
void SetDevice(BluetoothDevice* bDevice);
|
||||||
|
BluetoothDevice* Device() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
BluetoothDevice* fDevice;
|
BluetoothDevice* fDevice;
|
||||||
|
|||||||
@@ -18,34 +18,40 @@
|
|||||||
|
|
||||||
#define TR_CONTEXT "Extended local device view"
|
#define TR_CONTEXT "Extended local device view"
|
||||||
|
|
||||||
ExtendedLocalDeviceView::ExtendedLocalDeviceView(BRect frame, LocalDevice* bDevice, uint32 resizingMode, uint32 flags)
|
ExtendedLocalDeviceView::ExtendedLocalDeviceView(BRect frame,
|
||||||
: BView(frame,"ExtendedLocalDeviceView", resizingMode, flags | B_WILL_DRAW),
|
LocalDevice* bDevice, uint32 resizingMode, uint32 flags)
|
||||||
|
:
|
||||||
|
BView(frame,"ExtendedLocalDeviceView", resizingMode, flags | B_WILL_DRAW),
|
||||||
fDevice(bDevice),
|
fDevice(bDevice),
|
||||||
fScanMode(0)
|
fScanMode(0)
|
||||||
{
|
{
|
||||||
SetViewColor(B_TRANSPARENT_COLOR);
|
SetViewColor(B_TRANSPARENT_COLOR);
|
||||||
SetLowColor(0,0,0);
|
SetLowColor(0, 0, 0);
|
||||||
BRect iDontCare(0,0,0,0);
|
BRect iDontCare(0, 0, 0, 0);
|
||||||
|
|
||||||
SetLayout(new BGroupLayout(B_HORIZONTAL));
|
SetLayout(new BGroupLayout(B_HORIZONTAL));
|
||||||
|
|
||||||
fDeviceView = new BluetoothDeviceView(BRect(0,0,5,5), bDevice);
|
fDeviceView = new BluetoothDeviceView(BRect(0, 0, 5, 5), bDevice);
|
||||||
|
|
||||||
fDiscoverable = new BCheckBox(iDontCare, "Discoverable", TR("Discoverable"),
|
fDiscoverable = new BCheckBox(iDontCare, "Discoverable", TR("Discoverable"),
|
||||||
new BMessage(SET_DISCOVERABLE));
|
new BMessage(SET_DISCOVERABLE));
|
||||||
fVisible = new BCheckBox(iDontCare, "Visible", TR("Show name"), new BMessage(SET_VISIBLE));
|
fVisible = new BCheckBox(iDontCare, "Visible", TR("Show name"),
|
||||||
|
new BMessage(SET_VISIBLE));
|
||||||
|
fAuthentication = new BCheckBox(iDontCare, "Authenticate", TR("Authenticate"),
|
||||||
|
new BMessage(SET_AUTHENTICATION));
|
||||||
|
|
||||||
fDiscoverable->SetEnabled(false);
|
fDiscoverable->SetEnabled(false);
|
||||||
fVisible->SetEnabled(false);
|
fVisible->SetEnabled(false);
|
||||||
|
|
||||||
AddChild(BGroupLayoutBuilder(B_VERTICAL, 0)
|
AddChild(BGroupLayoutBuilder(B_VERTICAL, 0)
|
||||||
.Add(fDeviceView)
|
.Add(fDeviceView)
|
||||||
.Add(BGroupLayoutBuilder(B_HORIZONTAL)
|
.Add(BGroupLayoutBuilder(B_HORIZONTAL)
|
||||||
.AddGlue()
|
.AddGlue()
|
||||||
.Add(fDiscoverable)
|
.Add(fDiscoverable)
|
||||||
.Add(fVisible)
|
.Add(fVisible)
|
||||||
.SetInsets(5, 5, 5, 5)
|
.SetInsets(5, 5, 5, 5)
|
||||||
)
|
)
|
||||||
|
.Add(fAuthentication)
|
||||||
.Add(BSpaceLayoutItem::CreateVerticalStrut(0))
|
.Add(BSpaceLayoutItem::CreateVerticalStrut(0))
|
||||||
.SetInsets(5, 5, 5, 5)
|
.SetInsets(5, 5, 5, 5)
|
||||||
);
|
);
|
||||||
@@ -64,7 +70,7 @@ ExtendedLocalDeviceView::SetLocalDevice(LocalDevice* lDevice)
|
|||||||
{
|
{
|
||||||
if (lDevice != NULL) {
|
if (lDevice != NULL) {
|
||||||
fDevice = lDevice;
|
fDevice = lDevice;
|
||||||
SetName(lDevice->GetFriendlyName().String());
|
SetName(lDevice->GetFriendlyName().String());
|
||||||
fDeviceView->SetBluetoothDevice(lDevice);
|
fDeviceView->SetBluetoothDevice(lDevice);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -73,26 +79,27 @@ ExtendedLocalDeviceView::SetLocalDevice(LocalDevice* lDevice)
|
|||||||
void
|
void
|
||||||
ExtendedLocalDeviceView::AttachedToWindow()
|
ExtendedLocalDeviceView::AttachedToWindow()
|
||||||
{
|
{
|
||||||
fDiscoverable->SetTarget(this);
|
fDiscoverable->SetTarget(this);
|
||||||
fVisible->SetTarget(this);
|
fVisible->SetTarget(this);
|
||||||
|
fAuthentication->SetTarget(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
ExtendedLocalDeviceView::SetTarget(BHandler *tgt)
|
ExtendedLocalDeviceView::SetTarget(BHandler* target)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
ExtendedLocalDeviceView::MessageReceived(BMessage *msg)
|
ExtendedLocalDeviceView::MessageReceived(BMessage* message)
|
||||||
{
|
{
|
||||||
if(msg->WasDropped()) {
|
if (message->WasDropped()) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
switch(msg->what)
|
switch (message->what)
|
||||||
{
|
{
|
||||||
case SET_DISCOVERABLE:
|
case SET_DISCOVERABLE:
|
||||||
case SET_VISIBLE:
|
case SET_VISIBLE:
|
||||||
@@ -111,10 +118,13 @@ ExtendedLocalDeviceView::MessageReceived(BMessage *msg)
|
|||||||
if (fDevice != NULL)
|
if (fDevice != NULL)
|
||||||
fDevice->SetDiscoverable(fScanMode);
|
fDevice->SetDiscoverable(fScanMode);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
case SET_AUTHENTICATION:
|
||||||
|
fDevice->SetAuthentication(fAuthentication->Value());
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
BView::MessageReceived(msg);
|
BView::MessageReceived(message);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,21 +22,22 @@ class BCheckBox;
|
|||||||
class ExtendedLocalDeviceView : public BView
|
class ExtendedLocalDeviceView : public BView
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
ExtendedLocalDeviceView(BRect frame, LocalDevice* bDevice,
|
ExtendedLocalDeviceView(BRect frame, LocalDevice* bDevice,
|
||||||
uint32 resizingMode = B_FOLLOW_LEFT | B_FOLLOW_TOP,
|
uint32 resizingMode = B_FOLLOW_LEFT | B_FOLLOW_TOP,
|
||||||
uint32 flags = B_WILL_DRAW);
|
uint32 flags = B_WILL_DRAW);
|
||||||
~ExtendedLocalDeviceView(void);
|
~ExtendedLocalDeviceView(void);
|
||||||
|
|
||||||
void SetLocalDevice(LocalDevice* lDevice);
|
void SetLocalDevice(LocalDevice* lDevice);
|
||||||
|
|
||||||
|
|
||||||
virtual void MessageReceived(BMessage *msg);
|
virtual void MessageReceived(BMessage* message);
|
||||||
virtual void AttachedToWindow();
|
virtual void AttachedToWindow();
|
||||||
virtual void SetTarget(BHandler *tgt);
|
virtual void SetTarget(BHandler* target);
|
||||||
virtual void SetEnabled(bool value);
|
virtual void SetEnabled(bool value);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
LocalDevice* fDevice;
|
LocalDevice* fDevice;
|
||||||
|
BCheckBox* fAuthentication;
|
||||||
BCheckBox* fDiscoverable;
|
BCheckBox* fDiscoverable;
|
||||||
BCheckBox* fVisible;
|
BCheckBox* fVisible;
|
||||||
BluetoothDeviceView* fDeviceView;
|
BluetoothDeviceView* fDeviceView;
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2008-2009, Oliver Ruiz Dorantes, <oliver.ruiz.dorantes_at_gmail.com>
|
* Copyright 2008-09, 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.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -17,14 +17,14 @@
|
|||||||
#include <TextView.h>
|
#include <TextView.h>
|
||||||
#include <TabView.h>
|
#include <TabView.h>
|
||||||
|
|
||||||
|
#include <bluetooth/bdaddrUtils.h>
|
||||||
#include <bluetooth/DiscoveryAgent.h>
|
#include <bluetooth/DiscoveryAgent.h>
|
||||||
#include <bluetooth/DiscoveryListener.h>
|
#include <bluetooth/DiscoveryListener.h>
|
||||||
#include <bluetooth/LocalDevice.h>
|
#include <bluetooth/LocalDevice.h>
|
||||||
#include <bluetooth/bdaddrUtils.h>
|
|
||||||
|
|
||||||
#include "InquiryPanel.h"
|
|
||||||
#include "DeviceListItem.h"
|
|
||||||
#include "defs.h"
|
#include "defs.h"
|
||||||
|
#include "DeviceListItem.h"
|
||||||
|
#include "InquiryPanel.h"
|
||||||
|
|
||||||
#define TR_CONTEXT "Inquiry panel"
|
#define TR_CONTEXT "Inquiry panel"
|
||||||
|
|
||||||
@@ -49,7 +49,10 @@ class PanelDiscoveryListener : public DiscoveryListener {
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
PanelDiscoveryListener(InquiryPanel* iPanel) : DiscoveryListener() , fInquiryPanel(iPanel)
|
PanelDiscoveryListener(InquiryPanel* iPanel)
|
||||||
|
:
|
||||||
|
DiscoveryListener(),
|
||||||
|
fInquiryPanel(iPanel)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -59,9 +62,9 @@ public:
|
|||||||
DeviceDiscovered(RemoteDevice* btDevice, DeviceClass cod)
|
DeviceDiscovered(RemoteDevice* btDevice, DeviceClass cod)
|
||||||
{
|
{
|
||||||
BMessage* message = new BMessage(kMsgAddListDevice);
|
BMessage* message = new BMessage(kMsgAddListDevice);
|
||||||
|
|
||||||
message->AddPointer("remoteItem", new DeviceListItem(btDevice->GetBluetoothAddress(), cod));
|
message->AddPointer("remoteItem", new DeviceListItem(btDevice));
|
||||||
|
|
||||||
fInquiryPanel->PostMessage(message);
|
fInquiryPanel->PostMessage(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -88,13 +91,14 @@ private:
|
|||||||
|
|
||||||
|
|
||||||
InquiryPanel::InquiryPanel(BRect frame, LocalDevice* lDevice)
|
InquiryPanel::InquiryPanel(BRect frame, LocalDevice* lDevice)
|
||||||
: BWindow(frame, "Bluetooth", B_FLOATING_WINDOW,
|
:
|
||||||
B_NOT_ZOOMABLE | B_AUTO_UPDATE_SIZE_LIMITS,
|
BWindow(frame, "Bluetooth", B_FLOATING_WINDOW,
|
||||||
B_ALL_WORKSPACES ), fMessenger(this)
|
B_NOT_ZOOMABLE | B_AUTO_UPDATE_SIZE_LIMITS, B_ALL_WORKSPACES ),
|
||||||
, fScanning(false)
|
fMessenger(this),
|
||||||
, fRetrieving(false)
|
fScanning(false),
|
||||||
, fLocalDevice(lDevice)
|
fRetrieving(false),
|
||||||
|
fLocalDevice(lDevice)
|
||||||
|
|
||||||
{
|
{
|
||||||
SetLayout(new BGroupLayout(B_HORIZONTAL));
|
SetLayout(new BGroupLayout(B_HORIZONTAL));
|
||||||
|
|
||||||
@@ -109,12 +113,12 @@ InquiryPanel::InquiryPanel(BRect frame, LocalDevice* lDevice)
|
|||||||
fMessage->SetLowColor(fMessage->ViewColor());
|
fMessage->SetLowColor(fMessage->ViewColor());
|
||||||
fMessage->MakeEditable(false);
|
fMessage->MakeEditable(false);
|
||||||
fMessage->MakeSelectable(false);
|
fMessage->MakeSelectable(false);
|
||||||
|
|
||||||
fInquiryButton = new BButton("Inquiry", TR("Inquiry"),
|
fInquiryButton = new BButton("Inquiry", TR("Inquiry"),
|
||||||
new BMessage(kMsgInquiry), B_WILL_DRAW);
|
new BMessage(kMsgInquiry), B_WILL_DRAW);
|
||||||
|
|
||||||
fAddButton = new BButton("add", TR("Add device to list"),
|
fAddButton = new BButton("add", TR("Add device to list"),
|
||||||
new BMessage(kMsgAddToRemoteList), B_WILL_DRAW);
|
new BMessage(kMsgAddToRemoteList), B_WILL_DRAW);
|
||||||
fAddButton->SetEnabled(false);
|
fAddButton->SetEnabled(false);
|
||||||
|
|
||||||
fRemoteList = new BListView("AttributeList", B_SINGLE_SELECTION_LIST);
|
fRemoteList = new BListView("AttributeList", B_SINGLE_SELECTION_LIST);
|
||||||
@@ -123,20 +127,21 @@ InquiryPanel::InquiryPanel(BRect frame, LocalDevice* lDevice)
|
|||||||
fScrollView = new BScrollView("ScrollView", fRemoteList, 0, false, true);
|
fScrollView = new BScrollView("ScrollView", fRemoteList, 0, false, true);
|
||||||
fScrollView->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
|
fScrollView->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
|
||||||
|
|
||||||
if (fLocalDevice != NULL) {
|
if (fLocalDevice != NULL) {
|
||||||
fMessage->SetText(TR("Check that the Bluetooth capabilities of your remote device"
|
fMessage->SetText(TR("Check that the Bluetooth capabilities of your"
|
||||||
" are activated. Press 'Inquiry' to start scanning. The needed time"
|
" remote device are activated. Press 'Inquiry' to start scanning."
|
||||||
" for the retrieval of the names is unknown, although should not"
|
" The needed time for the retrieval of the names is unknown, "
|
||||||
" take more than 3 seconds per device. Afterwards you will be able"
|
"although should not take more than 3 seconds per device. "
|
||||||
" to add them to your main list, where you will be able to pair with them."));
|
"Afterwards you will be able to add them to your main list,"
|
||||||
|
" where you will be able to pair with them."));
|
||||||
fInquiryButton->SetEnabled(true);
|
fInquiryButton->SetEnabled(true);
|
||||||
fDiscoveryAgent = fLocalDevice->GetDiscoveryAgent();
|
fDiscoveryAgent = fLocalDevice->GetDiscoveryAgent();
|
||||||
fDiscoveryListener = new PanelDiscoveryListener(this);
|
fDiscoveryListener = new PanelDiscoveryListener(this);
|
||||||
|
|
||||||
|
|
||||||
SetTitle((const char*)(fLocalDevice->GetFriendlyName().String()));
|
SetTitle((const char*)(fLocalDevice->GetFriendlyName().String()));
|
||||||
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
fMessage->SetText(TR("There isn't any Bluetooth LocalDevice registered"
|
fMessage->SetText(TR("There isn't any Bluetooth LocalDevice registered"
|
||||||
" on the system."));
|
" on the system."));
|
||||||
@@ -145,7 +150,7 @@ InquiryPanel::InquiryPanel(BRect frame, LocalDevice* lDevice)
|
|||||||
|
|
||||||
fRetrieveMessage = new BMessage(kMsgRetrieve);
|
fRetrieveMessage = new BMessage(kMsgRetrieve);
|
||||||
fSecondsMessage = new BMessage(kMsgSecond);
|
fSecondsMessage = new BMessage(kMsgSecond);
|
||||||
|
|
||||||
|
|
||||||
AddChild(BGroupLayoutBuilder(B_VERTICAL, 10)
|
AddChild(BGroupLayoutBuilder(B_VERTICAL, 10)
|
||||||
.Add(fMessage)
|
.Add(fMessage)
|
||||||
@@ -165,30 +170,31 @@ InquiryPanel::InquiryPanel(BRect frame, LocalDevice* lDevice)
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
InquiryPanel::MessageReceived(BMessage *message)
|
InquiryPanel::MessageReceived(BMessage* message)
|
||||||
{
|
{
|
||||||
static float timer = 0; // expected time of the inquiry process
|
static float timer = 0; // expected time of the inquiry process
|
||||||
static float scanningTime = 0;
|
static float scanningTime = 0;
|
||||||
static int32 retrievalIndex = 0;
|
static int32 retrievalIndex = 0;
|
||||||
static bool labelPlaced = false;
|
static bool labelPlaced = false;
|
||||||
|
|
||||||
switch (message->what) {
|
switch (message->what) {
|
||||||
case kMsgInquiry:
|
case kMsgInquiry:
|
||||||
|
|
||||||
fDiscoveryAgent->StartInquiry(BT_GIAC, fDiscoveryListener, GetInquiryTime());
|
fDiscoveryAgent->StartInquiry(BT_GIAC, fDiscoveryListener, GetInquiryTime());
|
||||||
|
|
||||||
timer = BT_BASE_INQUIRY_TIME * GetInquiryTime() + 1;
|
timer = BT_BASE_INQUIRY_TIME * GetInquiryTime() + 1;
|
||||||
fScanProgress->SetMaxValue(timer); // does it works as expected?
|
// does it works as expected?
|
||||||
|
fScanProgress->SetMaxValue(timer);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case kMsgAddListDevice:
|
case kMsgAddListDevice:
|
||||||
{
|
{
|
||||||
DeviceListItem* listItem;
|
DeviceListItem* listItem;
|
||||||
|
|
||||||
message->FindPointer("remoteItem", (void **)&listItem);
|
message->FindPointer("remoteItem", (void **)&listItem);
|
||||||
|
|
||||||
fRemoteList->AddItem(listItem);
|
fRemoteList->AddItem(listItem);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@@ -197,7 +203,7 @@ InquiryPanel::MessageReceived(BMessage *message)
|
|||||||
message->PrintToStream();
|
message->PrintToStream();
|
||||||
int32 index = fRemoteList->CurrentSelection(0);
|
int32 index = fRemoteList->CurrentSelection(0);
|
||||||
DeviceListItem* item = (DeviceListItem*) fRemoteList->RemoveItem(index);;
|
DeviceListItem* item = (DeviceListItem*) fRemoteList->RemoveItem(index);;
|
||||||
|
|
||||||
BMessage message(kMsgAddToRemoteList);
|
BMessage message(kMsgAddToRemoteList);
|
||||||
message.AddPointer("device", item);
|
message.AddPointer("device", item);
|
||||||
|
|
||||||
@@ -205,7 +211,7 @@ InquiryPanel::MessageReceived(BMessage *message)
|
|||||||
// TODO: all others listitems can be deleted
|
// TODO: all others listitems can be deleted
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case kMsgSelected:
|
case kMsgSelected:
|
||||||
UpdateListStatus();
|
UpdateListStatus();
|
||||||
break;
|
break;
|
||||||
@@ -222,7 +228,7 @@ InquiryPanel::MessageReceived(BMessage *message)
|
|||||||
|
|
||||||
BMessageRunner::StartSending(fMessenger, fSecondsMessage, 1000000, timer);
|
BMessageRunner::StartSending(fMessenger, fSecondsMessage, 1000000, timer);
|
||||||
|
|
||||||
scanningTime = 1;
|
scanningTime = 1;
|
||||||
fScanning = true;
|
fScanning = true;
|
||||||
|
|
||||||
break;
|
break;
|
||||||
@@ -232,20 +238,21 @@ InquiryPanel::MessageReceived(BMessage *message)
|
|||||||
retrievalIndex = 0;
|
retrievalIndex = 0;
|
||||||
fScanning = false;
|
fScanning = false;
|
||||||
fRetrieving = true;
|
fRetrieving = true;
|
||||||
labelPlaced = false;
|
labelPlaced = false;
|
||||||
fScanProgress->SetTo(100);
|
fScanProgress->SetTo(100);
|
||||||
fScanProgress->SetTrailingText(TR("Retrieving names..."));
|
fScanProgress->SetTrailingText(TR("Retrieving names..."));
|
||||||
BMessageRunner::StartSending(fMessenger, fRetrieveMessage, 1000000, 1);
|
BMessageRunner::StartSending(fMessenger, fRetrieveMessage, 1000000, 1);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case kMsgSecond:
|
case kMsgSecond:
|
||||||
if (fScanning && scanningTime < timer) {
|
if (fScanning && scanningTime < timer) {
|
||||||
// TODO time formatting could use Locale Kit
|
// TODO time formatting could use Locale Kit
|
||||||
BString elapsedTime = TR("Remaining ");
|
BString elapsedTime = TR("Remaining ");
|
||||||
|
|
||||||
fScanProgress->SetTo(scanningTime*100/timer); // TODO should not be needed if SetMaxValue works...
|
// TODO should not be needed if SetMaxValue works...
|
||||||
|
fScanProgress->SetTo(scanningTime * 100 / timer);
|
||||||
|
|
||||||
elapsedTime << (int)(timer - scanningTime) << TR(" seconds");
|
elapsedTime << (int)(timer - scanningTime) << TR(" seconds");
|
||||||
fScanProgress->SetTrailingText(elapsedTime.String());
|
fScanProgress->SetTrailingText(elapsedTime.String());
|
||||||
|
|
||||||
@@ -254,37 +261,39 @@ InquiryPanel::MessageReceived(BMessage *message)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case kMsgRetrieve:
|
case kMsgRetrieve:
|
||||||
|
|
||||||
if (fRetrieving) {
|
if (fRetrieving) {
|
||||||
|
|
||||||
if (retrievalIndex < fDiscoveryAgent->RetrieveDevices(0).CountItems()) {
|
if (retrievalIndex < fDiscoveryAgent->RetrieveDevices(0).CountItems()) {
|
||||||
|
|
||||||
if (!labelPlaced) {
|
if (!labelPlaced) {
|
||||||
|
|
||||||
labelPlaced = true;
|
labelPlaced = true;
|
||||||
BString progressText = TR("Retrieving name of ");
|
BString progressText = TR("Retrieving name of ");
|
||||||
progressText << bdaddrUtils::ToString(fDiscoveryAgent->RetrieveDevices(0).ItemAt(
|
progressText << bdaddrUtils::ToString(fDiscoveryAgent
|
||||||
retrievalIndex)->GetBluetoothAddress());
|
->RetrieveDevices(0).ItemAt(retrievalIndex)
|
||||||
fScanProgress->SetTrailingText(progressText.String());
|
->GetBluetoothAddress());
|
||||||
|
fScanProgress->SetTrailingText(progressText.String());
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
// Really erally expensive operation should be done in a separate thread
|
// Really erally expensive operation should be done in a separate thread
|
||||||
// once Haiku gets a BarberPole in API replacing the progress bar
|
// once Haiku gets a BarberPole in API replacing the progress bar
|
||||||
((DeviceListItem*)fRemoteList->ItemAt(retrievalIndex))->SetDevice((BluetoothDevice*)
|
((DeviceListItem*)fRemoteList->ItemAt(retrievalIndex))
|
||||||
fDiscoveryAgent->RetrieveDevices(0).ItemAt(retrievalIndex));
|
->SetDevice((BluetoothDevice*) fDiscoveryAgent
|
||||||
|
->RetrieveDevices(0).ItemAt(retrievalIndex));
|
||||||
fRemoteList->InvalidateItem(retrievalIndex);
|
fRemoteList->InvalidateItem(retrievalIndex);
|
||||||
|
|
||||||
retrievalIndex++;
|
retrievalIndex++;
|
||||||
labelPlaced = false;
|
labelPlaced = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
BMessageRunner::StartSending(fMessenger, fRetrieveMessage, 500000, 1);
|
BMessageRunner::StartSending(fMessenger, fRetrieveMessage, 500000, 1);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
fRetrieving = false;
|
fRetrieving = false;
|
||||||
retrievalIndex = 0;
|
retrievalIndex = 0;
|
||||||
|
|
||||||
fScanProgress->SetBarColor(ui_color(B_PANEL_BACKGROUND_COLOR));
|
fScanProgress->SetBarColor(ui_color(B_PANEL_BACKGROUND_COLOR));
|
||||||
fScanProgress->SetTrailingText(TR("Scanning completed."));
|
fScanProgress->SetTrailingText(TR("Scanning completed."));
|
||||||
fInquiryButton->SetEnabled(true);
|
fInquiryButton->SetEnabled(true);
|
||||||
|
|||||||
@@ -18,11 +18,12 @@
|
|||||||
#include <SpaceLayoutItem.h>
|
#include <SpaceLayoutItem.h>
|
||||||
|
|
||||||
#include <PincodeWindow.h>
|
#include <PincodeWindow.h>
|
||||||
|
#include <bluetooth/RemoteDevice.h>
|
||||||
|
|
||||||
#include "defs.h"
|
|
||||||
#include "InquiryPanel.h"
|
|
||||||
#include "BluetoothWindow.h"
|
#include "BluetoothWindow.h"
|
||||||
|
#include "defs.h"
|
||||||
|
#include "DeviceListItem.h"
|
||||||
|
#include "InquiryPanel.h"
|
||||||
#include "RemoteDevicesView.h"
|
#include "RemoteDevicesView.h"
|
||||||
|
|
||||||
#define TR_CONTEXT "Remote devices"
|
#define TR_CONTEXT "Remote devices"
|
||||||
@@ -33,27 +34,29 @@ static const uint32 kMsgPairDevice = 'trDv';
|
|||||||
static const uint32 kMsgBlockDevice = 'blDv';
|
static const uint32 kMsgBlockDevice = 'blDv';
|
||||||
static const uint32 kMsgRefreshDevices = 'rfDv';
|
static const uint32 kMsgRefreshDevices = 'rfDv';
|
||||||
|
|
||||||
RemoteDevicesView::RemoteDevicesView(const char *name, uint32 flags)
|
using namespace Bluetooth;
|
||||||
|
|
||||||
|
RemoteDevicesView::RemoteDevicesView(const char* name, uint32 flags)
|
||||||
: BView(name, flags)
|
: BView(name, flags)
|
||||||
{
|
{
|
||||||
SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
|
SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
|
||||||
|
|
||||||
addButton = new BButton("add", TR("Add" B_UTF8_ELLIPSIS),
|
addButton = new BButton("add", TR("Add" B_UTF8_ELLIPSIS),
|
||||||
new BMessage(kMsgAddDevices));
|
new BMessage(kMsgAddDevices));
|
||||||
|
|
||||||
removeButton = new BButton("remove", TR("Remove"),
|
removeButton = new BButton("remove", TR("Remove"),
|
||||||
new BMessage(kMsgRemoveDevice));
|
new BMessage(kMsgRemoveDevice));
|
||||||
|
|
||||||
pairButton = new BButton("pair", TR("Pair" B_UTF8_ELLIPSIS),
|
pairButton = new BButton("pair", TR("Pair" B_UTF8_ELLIPSIS),
|
||||||
new BMessage(kMsgPairDevice));
|
new BMessage(kMsgPairDevice));
|
||||||
|
|
||||||
|
|
||||||
blockButton = new BButton("block", TR("As blocked"),
|
blockButton = new BButton("block", TR("As blocked"),
|
||||||
new BMessage(kMsgBlockDevice));
|
new BMessage(kMsgBlockDevice));
|
||||||
|
|
||||||
|
|
||||||
availButton = new BButton("check", TR("Refresh" B_UTF8_ELLIPSIS),
|
availButton = new BButton("check", TR("Refresh" B_UTF8_ELLIPSIS),
|
||||||
new BMessage(kMsgRefreshDevices));
|
new BMessage(kMsgRefreshDevices));
|
||||||
|
|
||||||
// Set up device list
|
// Set up device list
|
||||||
fDeviceList = new BListView("DeviceList", B_SINGLE_SELECTION_LIST);
|
fDeviceList = new BListView("DeviceList", B_SINGLE_SELECTION_LIST);
|
||||||
@@ -68,27 +71,29 @@ RemoteDevicesView::RemoteDevicesView(const char *name, uint32 flags)
|
|||||||
.Add(fScrollView)
|
.Add(fScrollView)
|
||||||
//.Add(BSpaceLayoutItem::CreateHorizontalStrut(5))
|
//.Add(BSpaceLayoutItem::CreateHorizontalStrut(5))
|
||||||
.Add(BGroupLayoutBuilder(B_VERTICAL)
|
.Add(BGroupLayoutBuilder(B_VERTICAL)
|
||||||
.Add(addButton)
|
.Add(addButton)
|
||||||
.Add(removeButton)
|
.Add(removeButton)
|
||||||
.AddGlue()
|
.AddGlue()
|
||||||
.Add(availButton)
|
.Add(availButton)
|
||||||
.AddGlue()
|
.AddGlue()
|
||||||
.Add(pairButton)
|
.Add(pairButton)
|
||||||
.Add(blockButton)
|
.Add(blockButton)
|
||||||
.AddGlue()
|
.AddGlue()
|
||||||
.SetInsets(0, 15, 0, 15)
|
.SetInsets(0, 15, 0, 15)
|
||||||
)
|
)
|
||||||
.SetInsets(5, 5, 5, 100)
|
.SetInsets(5, 5, 5, 100)
|
||||||
);
|
);
|
||||||
|
|
||||||
fDeviceList->SetSelectionMessage(NULL);
|
fDeviceList->SetSelectionMessage(NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
RemoteDevicesView::~RemoteDevicesView(void)
|
RemoteDevicesView::~RemoteDevicesView(void)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
RemoteDevicesView::AttachedToWindow(void)
|
RemoteDevicesView::AttachedToWindow(void)
|
||||||
{
|
{
|
||||||
@@ -103,15 +108,16 @@ RemoteDevicesView::AttachedToWindow(void)
|
|||||||
fDeviceList->Select(0);
|
fDeviceList->Select(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
RemoteDevicesView::MessageReceived(BMessage *msg)
|
RemoteDevicesView::MessageReceived(BMessage* message)
|
||||||
{
|
{
|
||||||
printf("what = %ld\n", msg->what);
|
switch (message->what) {
|
||||||
switch(msg->what) {
|
|
||||||
case kMsgAddDevices:
|
case kMsgAddDevices:
|
||||||
{
|
{
|
||||||
InquiryPanel* iPanel = new InquiryPanel(BRect(100,100,450,450), ActiveLocalDevice);
|
InquiryPanel* inquiryPanel = new InquiryPanel(BRect(100, 100, 450, 450),
|
||||||
iPanel->Show();
|
ActiveLocalDevice);
|
||||||
|
inquiryPanel->Show();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -122,7 +128,7 @@ RemoteDevicesView::MessageReceived(BMessage *msg)
|
|||||||
case kMsgAddToRemoteList:
|
case kMsgAddToRemoteList:
|
||||||
{
|
{
|
||||||
BListItem* device;
|
BListItem* device;
|
||||||
msg->FindPointer("device", (void**)&device);
|
message->FindPointer("device", (void**)&device);
|
||||||
fDeviceList->AddItem(device);
|
fDeviceList->AddItem(device);
|
||||||
fDeviceList->Invalidate();
|
fDeviceList->Invalidate();
|
||||||
break;
|
break;
|
||||||
@@ -130,30 +136,29 @@ RemoteDevicesView::MessageReceived(BMessage *msg)
|
|||||||
|
|
||||||
case kMsgPairDevice:
|
case kMsgPairDevice:
|
||||||
{
|
{
|
||||||
bdaddr_t address;
|
DeviceListItem* device = static_cast<DeviceListItem*>(fDeviceList
|
||||||
address.b[5] = 0x55;
|
->ItemAt(fDeviceList->CurrentSelection(0)));
|
||||||
address.b[4] = 0x44;
|
RemoteDevice* remote = dynamic_cast<RemoteDevice*>(device->Device());
|
||||||
address.b[3] = 0x33;
|
|
||||||
address.b[2] = 0x22;
|
if (remote != NULL)
|
||||||
address.b[1] = 0x11;
|
remote->Authenticate();
|
||||||
address.b[0] = 0x00;
|
|
||||||
|
|
||||||
PincodeWindow* iPincode = new PincodeWindow(address, 0);
|
|
||||||
iPincode->Show();
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
BView::MessageReceived(msg);
|
BView::MessageReceived(message);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void RemoteDevicesView::LoadSettings(void)
|
void RemoteDevicesView::LoadSettings(void)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool RemoteDevicesView::IsDefaultable(void)
|
bool RemoteDevicesView::IsDefaultable(void)
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -19,6 +19,7 @@
|
|||||||
|
|
||||||
#define SET_VISIBLE 'sVis'
|
#define SET_VISIBLE 'sVis'
|
||||||
#define SET_DISCOVERABLE 'sDis'
|
#define SET_DISCOVERABLE 'sDis'
|
||||||
|
#define SET_AUTHENTICATION 'sAth'
|
||||||
|
|
||||||
#define SET_UI_COLORS 'suic'
|
#define SET_UI_COLORS 'suic'
|
||||||
#define PREFS_CHOSEN 'prch'
|
#define PREFS_CHOSEN 'prch'
|
||||||
|
|||||||
Reference in New Issue
Block a user