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