From 623f4e65349f7cd2c6387ca43f20aea9302de409 Mon Sep 17 00:00:00 2001 From: Oliver Ruiz Dorantes Date: Sat, 28 Feb 2009 20:48:27 +0000 Subject: [PATCH] - Implement a suitable BListItem(me) for bluetooth Devices - Add functionality to the Menu starting or shutting down the server(Monni) - Add the desired device after the inquiry to the RemoveDevices List (Monni & me) git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@29361 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/preferences/bluetooth/BluetoothMain.cpp | 75 ++++---- src/preferences/bluetooth/BluetoothMain.h | 1 + src/preferences/bluetooth/BluetoothWindow.cpp | 21 +++ src/preferences/bluetooth/DeviceListItem.cpp | 172 +++++++++++------- src/preferences/bluetooth/DeviceListItem.h | 33 +++- src/preferences/bluetooth/InquiryPanel.cpp | 35 ++-- .../bluetooth/RemoteDevicesView.cpp | 62 ++++--- src/preferences/bluetooth/RemoteDevicesView.h | 6 +- src/preferences/bluetooth/defs.h | 2 + 9 files changed, 259 insertions(+), 148 deletions(-) diff --git a/src/preferences/bluetooth/BluetoothMain.cpp b/src/preferences/bluetooth/BluetoothMain.cpp index b57813ec34..6a2463d0f0 100644 --- a/src/preferences/bluetooth/BluetoothMain.cpp +++ b/src/preferences/bluetooth/BluetoothMain.cpp @@ -24,45 +24,48 @@ void BluetoothApplication::AboutRequested() { - (new BAlert("about", "Haiku Bluetooth System, (ARCE) - -Created by Oliver Ruiz Dorantes - -With support of: - - Mika Lindqvist - - Maksym Yevmenkin - -Thanks to the individuals who helped... - -Shipping/donating hardware: - - Henry Jair Abril Florez(el Colombian) - & Stefanie Bartolich - - Dennis d'Entremont - - Luroh - - Pieter Panman - -Economically: - - Karl von Dorf, Andrea Bernardi (OSDrawer), - - Matt M, Doug F, Hubert H, - - Sebastian B, Andrew M, Jared E, - - Frederik H, Tom S, Ferry B, - - Greg G, David F, Richard S, Martin W: - -With patches: - - Fredrik Ekdahl - - Andreas Färber - -Testing: - - Petter H. Juliussen - - Raynald Lesieur - - Adrien Destugues - - Jörg Meyer - -Who gave me all the knowledge: - - the yellowTAB team", "OK"))->Go(); + (new BAlert("about", "Haiku Bluetooth System, (ARCE)\n\n" + "Created by Oliver Ruiz Dorantes\n\n" + "With support of:\n" + " - Mika Lindqvist\n" + " - Maksym Yevmenkin\n\n" + "Thanks to the individuals who helped...\n\n" + "Shipping/donating hardware:\n" + " - Henry Jair Abril Florez(el Colombian)\n" + " & Stefanie Bartolich\n" + " - Dennis d'Entremont\n" + " - Luroh\n" + " - Pieter Panman\n\n" + "Economically:\n" + " - Karl von Dorf, Andrea Bernardi (OSDrawer),\n" + " - Matt M, Doug F, Hubert H,\n" + " - Sebastian B, Andrew M, Jared E,\n" + " - Frederik H, Tom S, Ferry B,\n" + " - Greg G, David F, Richard S, Martin W:\n\n" + "With patches:\n" + " - Fredrik Ekdahl\n" + " - Andreas Färber\n\n" + "Testing:\n" + " - Petter H. Juliussen\n" + " - Raynald Lesieur\n" + " - Adrien Destugues\n" + " - Jörg Meyer\n\n" + "Who gave me all the knowledge:\n" + " - the yellowTAB team", "OK"))->Go(); } +void +BluetoothApplication::MessageReceived(BMessage *message) +{ + switch (message->what) { + case kMsgAddToRemoteList: + fWindow->PostMessage(message); + break; + default: + BApplication::MessageReceived(message); + } +} int main(int, char**) diff --git a/src/preferences/bluetooth/BluetoothMain.h b/src/preferences/bluetooth/BluetoothMain.h index 61ffe0e360..b756e22f49 100644 --- a/src/preferences/bluetooth/BluetoothMain.h +++ b/src/preferences/bluetooth/BluetoothMain.h @@ -14,6 +14,7 @@ class BluetoothApplication : public BApplication public: BluetoothApplication(void); + virtual void MessageReceived(BMessage*); virtual void AboutRequested(); private: diff --git a/src/preferences/bluetooth/BluetoothWindow.cpp b/src/preferences/bluetooth/BluetoothWindow.cpp index ed47faf77a..9f9edf2028 100644 --- a/src/preferences/bluetooth/BluetoothWindow.cpp +++ b/src/preferences/bluetooth/BluetoothWindow.cpp @@ -10,6 +10,8 @@ #include #include #include +#include +#include #include #include "RemoteDevicesView.h" @@ -105,6 +107,25 @@ BluetoothWindow::MessageReceived(BMessage *message) || fAntialiasingSettings->IsDefaultable()); fRevertButton->SetEnabled(false); */ break; + case kMsgStartServices: + printf("kMsgStartServices\n"); + if (!be_roster->IsRunning("application/x-vnd.Be-bluetooth_server")) + { + printf("kMsgStopServices: %s\n", strerror(be_roster->Launch("application/x-vnd.Be-bluetooth_server"))); + } + break; + case kMsgStopServices: + printf("kMsgStopServices\n"); + if (be_roster->IsRunning("application/x-vnd.Be-bluetooth_server")) + { + printf("kMsgStopServices: %s\n", strerror(BMessenger("application/x-vnd.Be-bluetooth_server").SendMessage(B_QUIT_REQUESTED))); + } + break; + case kMsgAddToRemoteList: + { + PostMessage(message, fRemoteDevices); + } + break; case B_ABOUT_REQUESTED: be_app->PostMessage(message); break; diff --git a/src/preferences/bluetooth/DeviceListItem.cpp b/src/preferences/bluetooth/DeviceListItem.cpp index ade5904733..b1a399b6e2 100644 --- a/src/preferences/bluetooth/DeviceListItem.cpp +++ b/src/preferences/bluetooth/DeviceListItem.cpp @@ -2,86 +2,126 @@ * Copyright 2009, Oliver Ruiz Dorantes, * All rights reserved. Distributed under the terms of the MIT License. */ -#include "DeviceListItem.h" -#include - #include #include -namespace bluetooth { +#include +#include -RangeItem::RangeItem(uint32 lowAddress, uint32 highAddress, const char* name) - : BListItem(), - fLowAddress(lowAddress), - fHighAddress(highAddress) -{ - fName = strdup(name); -} -RangeItem::~RangeItem() -{ - delete fName; -} +#include "DeviceListItem.h" + + +#define PIXELS_FOR_ICON 32 +#define INSETS 2 +#define TEXT_ROWS 2 + +namespace Bluetooth { + +DeviceListItem::DeviceListItem(BluetoothDevice* bDevice) + : BListItem(), + fDevice(bDevice) +{ + SetDevice(fDevice); +} + + +DeviceListItem::DeviceListItem(bdaddr_t bdaddr, DeviceClass dClass, int32 rssi = 0) + : BListItem(), + fDevice(NULL), + fAddress(bdaddr), + fClass(dClass), + fName("unknown"), + fRSSI(rssi) +{ + +} + -/*********************************************************** - * DrawItem - ***********************************************************/ void -RangeItem::DrawItem(BView *owner, BRect itemRect, bool complete) +DeviceListItem::SetDevice(BluetoothDevice* bDevice) { - 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(); - - owner->SetHighColor(color); - owner->SetLowColor(color); - owner->FillRect(itemRect); - owner->SetHighColor(kBlack); - - } else { - owner->SetLowColor(owner->ViewColor()); - } - - BFont font = be_plain_font; - font_height finfo; - font.GetHeight(&finfo); - - BPoint point = BPoint(itemRect.left + 17, itemRect.bottom - finfo.descent + 1); - owner->SetFont(be_fixed_font); - owner->SetHighColor(kBlack); - owner->MovePenTo(point); - -/* if (fLowAddress >= 0) { - char string[255]; - sprintf(string, "0x%04lx - 0x%04lx", fLowAddress, fHighAddress); - owner->DrawString(string); - } - point += BPoint(174, 0);*/ - owner->SetFont(be_plain_font); - owner->MovePenTo(point); - owner->DrawString(fName); + fAddress = bDevice->GetBluetoothAddress(); + fClass = bDevice->GetDeviceClass(); + fName = bDevice->GetFriendlyName(); + // AKAIR rssi can only be got at inquiry time... } -int -RangeItem::Compare(const void *firstArg, const void *secondArg) + +DeviceListItem::~DeviceListItem() +{ + +} + + +/*********************************************************** + * DrawItem + ***********************************************************/ +void +DeviceListItem::DrawItem(BView *owner, BRect itemRect, bool complete) +{ + 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(); + + owner->SetHighColor(color); + owner->SetLowColor(color); + owner->FillRect(itemRect); + owner->SetHighColor(kBlack); + + } else { + owner->SetLowColor(owner->ViewColor()); + } + + font_height finfo; + be_plain_font->GetHeight(&finfo); + + BPoint point = BPoint(itemRect.left + PIXELS_FOR_ICON + INSETS, itemRect.bottom - finfo.descent + 1); + owner->SetFont(be_fixed_font); + owner->SetHighColor(kBlack); + owner->MovePenTo(point); + + owner->DrawString(bdaddrUtils::ToString(fAddress)); + + point -= BPoint(0, (finfo.ascent + finfo.descent + finfo.leading)); + + owner->SetFont(be_plain_font); + owner->MovePenTo(point); + owner->DrawString(fName.String()); + + // TODO: Stroke icon + + // TODO: Draw rssi +} + + +void +DeviceListItem::Update(BView *owner, const BFont *font) { - const RangeItem *item1 = *static_cast(firstArg); - const RangeItem *item2 = *static_cast(secondArg); + BListItem::Update(owner,font); + + font_height height; + font->GetHeight(&height); + //SetHeight(finfo.leading*TEXT_ROWS + TEXT_ROWS*INSETS + 50); + SetHeight((height.ascent + height.descent + height.leading) * TEXT_ROWS + TEXT_ROWS*INSETS); - if (item1->fLowAddress < item2->fLowAddress) { - return -1; - } else if (item1->fLowAddress > item2->fLowAddress) { - return 1; - } else - return 0; } + +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); +} } diff --git a/src/preferences/bluetooth/DeviceListItem.h b/src/preferences/bluetooth/DeviceListItem.h index 404e473db9..ca2298e5d6 100644 --- a/src/preferences/bluetooth/DeviceListItem.h +++ b/src/preferences/bluetooth/DeviceListItem.h @@ -6,20 +6,37 @@ #define DEVICELISTITEM_H_ #include +#include -namespace bluetooth { +#include +#include -// TODO: Implement a BluetoothDeviceListItem class, this one is stolen from somewhere ..... -class RangeItem : public BListItem +class BluetoothDevice; + +namespace Bluetooth { + +class DeviceListItem : public BListItem { public: - RangeItem(uint32 lowAddress, uint32 highAddress, const char* name); - ~RangeItem(); - virtual void DrawItem(BView *, BRect, bool = false); + 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); + private: - char* fName; - uint32 fLowAddress, fHighAddress; + void SetDevice(BluetoothDevice* bDevice); + + BluetoothDevice* fDevice; + bdaddr_t fAddress; + DeviceClass fClass; + BString fName; + int32 fRSSI; + }; } diff --git a/src/preferences/bluetooth/InquiryPanel.cpp b/src/preferences/bluetooth/InquiryPanel.cpp index b291f16bd5..e23e6ae5cc 100644 --- a/src/preferences/bluetooth/InquiryPanel.cpp +++ b/src/preferences/bluetooth/InquiryPanel.cpp @@ -21,8 +21,9 @@ #include "InquiryPanel.h" #include "DeviceListItem.h" +#include "defs.h" -using namespace bluetooth; +using Bluetooth::DeviceListItem; // private funcionaility provided by kit extern uint8 GetInquiryTime(); @@ -34,7 +35,6 @@ static const uint32 kMsgShowDebug = 'ShDG'; static const uint32 kMsgInquiry = 'iQbt'; static const uint32 kMsgAddListDevice = 'aDdv'; -static const uint32 kMsgAddToRemoteList = 'aDdL'; static const uint32 kMsgSecond = 'sCMs'; @@ -52,7 +52,8 @@ public: DeviceDiscovered(RemoteDevice* btDevice, DeviceClass cod) { BMessage* message = new BMessage(kMsgAddListDevice); - message->AddPointer("remote", btDevice); + + message->AddPointer("remoteItem", new DeviceListItem(btDevice->GetBluetoothAddress(), cod)); fInquiryPanel->PostMessage(message); } @@ -85,18 +86,17 @@ InquiryPanel::InquiryPanel(BRect frame, LocalDevice* lDevice) B_ALL_WORKSPACES ), fScanning(false) , fLocalDevice(lDevice) { - BRect iDontCare(0,0,0,0); +// BRect iDontCare(0,0,0,0); SetLayout(new BGroupLayout(B_HORIZONTAL)); - fScanProgress = new BStatusBar(iDontCare, "status", "Scanning progress", ""); + fScanProgress = new BStatusBar("status", "Scanning progress", ""); activeColor = fScanProgress->BarColor(); if (fLocalDevice == NULL) fLocalDevice = LocalDevice::GetLocalDevice(); - fMessage = new BTextView(iDontCare, "description", - iDontCare, B_FOLLOW_NONE, B_WILL_DRAW | B_SUPPORTS_LAYOUT); + fMessage = new BTextView("description", B_WILL_DRAW); fMessage->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); fMessage->SetLowColor(fMessage->ViewColor()); fMessage->MakeEditable(false); @@ -167,11 +167,24 @@ InquiryPanel::MessageReceived(BMessage *message) case kMsgAddListDevice: { - RemoteDevice* rDevice; + DeviceListItem* listItem; - message->FindPointer("remote", (void **)&rDevice); + message->FindPointer("remoteItem", (void **)&listItem); - fRemoteList->AddItem(new RangeItem(0,1,bdaddrUtils::ToString(rDevice->GetBluetoothAddress()))); + fRemoteList->AddItem(listItem); + } + break; + + case kMsgAddToRemoteList: + { + message->PrintToStream(); + int32 index = fRemoteList->CurrentSelection(0); + DeviceListItem* item = (DeviceListItem*) fRemoteList->ItemAt(index); + + BMessage message(kMsgAddToRemoteList); + message.AddPointer("device", item); + + be_app->PostMessage(&message); } break; @@ -205,7 +218,7 @@ InquiryPanel::MessageReceived(BMessage *message) scanningTime = scanningTime + 1; } - if (fRemoteList->CurrentSelection() < 0) + if (fRemoteList->CurrentSelection() < 0 || fScanning) fAddButton->SetEnabled(false); else fAddButton->SetEnabled(true); diff --git a/src/preferences/bluetooth/RemoteDevicesView.cpp b/src/preferences/bluetooth/RemoteDevicesView.cpp index 4947d6faa1..126a4736a4 100644 --- a/src/preferences/bluetooth/RemoteDevicesView.cpp +++ b/src/preferences/bluetooth/RemoteDevicesView.cpp @@ -21,36 +21,39 @@ #include "RemoteDevicesView.h" static const uint32 kMsgAddDevices = 'ddDv'; - +static const uint32 kMsgRemoveDevice = 'rmDv'; +static const uint32 kMsgTrustDevice = 'trDv'; +static const uint32 kMsgBlockDevice = 'blDv'; +static const uint32 kMsgRefreshDevices = 'rfDv'; RemoteDevicesView::RemoteDevicesView(const char *name, uint32 flags) : BView(name, flags) { SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); - addButton = new BButton(BRect(5,5,5,5), "add", "Add" B_UTF8_ELLIPSIS, - new BMessage(kMsgAddDevices), B_FOLLOW_RIGHT); + addButton = new BButton("add", "Add" B_UTF8_ELLIPSIS, + new BMessage(kMsgAddDevices)); - BButton* removeButton = new BButton(BRect(5,5,5,5), "remove", "Remove", - new BMessage(kMsgAddDevices), B_FOLLOW_RIGHT); + removeButton = new BButton("remove", "Remove", + new BMessage(kMsgRemoveDevice)); - BButton* trustButton = new BButton(BRect(5,5,5,5), "trust", "As Trusted", - new BMessage(kMsgAddDevices), B_FOLLOW_RIGHT); + trustButton = new BButton("trust", "As Trusted", + new BMessage(kMsgTrustDevice)); - BButton* blockButton = new BButton(BRect(5,5,5,5), "trust", "As Blocked", - new BMessage(kMsgAddDevices), B_FOLLOW_RIGHT); + blockButton = new BButton("trust", "As Blocked", + new BMessage(kMsgBlockDevice)); - BButton* availButton = new BButton(BRect(5,5,5,5), "check", "Refresh" B_UTF8_ELLIPSIS, - new BMessage(kMsgAddDevices), B_FOLLOW_RIGHT); + availButton = new BButton("check", "Refresh" B_UTF8_ELLIPSIS, + new BMessage(kMsgRefreshDevices)); - // Set up list of color attributes - fAttrList = new BListView("AttributeList", B_SINGLE_SELECTION_LIST); + // Set up device list + fDeviceList = new BListView("DeviceList", B_SINGLE_SELECTION_LIST); - fScrollView = new BScrollView("ScrollView", fAttrList, 0, false, true); + fScrollView = new BScrollView("ScrollView", fDeviceList, 0, false, true); fScrollView->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); SetLayout(new BGroupLayout(B_VERTICAL)); @@ -74,7 +77,7 @@ RemoteDevicesView::RemoteDevicesView(const char *name, uint32 flags) .SetInsets(5, 5, 5, 100) ); - fAttrList->SetSelectionMessage(NULL); + fDeviceList->SetSelectionMessage(NULL); } RemoteDevicesView::~RemoteDevicesView(void) @@ -85,25 +88,21 @@ RemoteDevicesView::~RemoteDevicesView(void) void RemoteDevicesView::AttachedToWindow(void) { - fAttrList->SetTarget(this); + fDeviceList->SetTarget(this); addButton->SetTarget(this); + removeButton->SetTarget(this); + trustButton->SetTarget(this); + blockButton->SetTarget(this); + availButton->SetTarget(this); LoadSettings(); - fAttrList->Select(0); + fDeviceList->Select(0); } void RemoteDevicesView::MessageReceived(BMessage *msg) { - if (msg->WasDropped()) { - rgb_color *color; - ssize_t size; - - if (msg->FindData("RGBColor", (type_code)'RGBC', (const void**)&color, &size) == B_OK) { - - } - } - + printf("what = %ld\n", msg->what); switch(msg->what) { case kMsgAddDevices: { @@ -111,6 +110,17 @@ RemoteDevicesView::MessageReceived(BMessage *msg) iPanel->Show(); } break; + case kMsgRemoveDevice: + printf("kMsgRemoveDevice: %ld\n", fDeviceList->CurrentSelection(0)); + fDeviceList->RemoveItem(fDeviceList->CurrentSelection(0)); + break; + case kMsgAddToRemoteList: + { + BListItem* device; + msg->FindPointer("device", (void**)&device); + fDeviceList->AddItem(device); + } + break; default: BView::MessageReceived(msg); break; diff --git a/src/preferences/bluetooth/RemoteDevicesView.h b/src/preferences/bluetooth/RemoteDevicesView.h index af6bb3051a..1443cd0381 100644 --- a/src/preferences/bluetooth/RemoteDevicesView.h +++ b/src/preferences/bluetooth/RemoteDevicesView.h @@ -40,7 +40,11 @@ protected: void UpdateAllColors(); BButton* addButton; - BListView* fAttrList; + BButton* removeButton; + BButton* trustButton; + BButton* blockButton; + BButton* availButton; + BListView* fDeviceList; BScrollView* fScrollView; diff --git a/src/preferences/bluetooth/defs.h b/src/preferences/bluetooth/defs.h index 5a825c3430..8289567129 100644 --- a/src/preferences/bluetooth/defs.h +++ b/src/preferences/bluetooth/defs.h @@ -26,6 +26,8 @@ const uint32 kBorderSpace = 10; const uint32 kItemSpace = 7; +static const uint32 kMsgAddToRemoteList = 'aDdL'; + extern LocalDevice* ActiveLocalDevice; #endif