Implement functionality to the InquiryPanel

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@29263 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Oliver Ruiz Dorantes 2009-02-20 17:32:48 +00:00
parent dae3adab03
commit b36b65f92c
7 changed files with 305 additions and 90 deletions

View File

@ -10,6 +10,8 @@
#include "BluetoothWindow.h"
#include "defs.h"
BluetoothApplication::BluetoothApplication(void)
: BApplication(BLUETOOTH_APP_SIGNATURE)
{

View File

@ -21,6 +21,7 @@
#include <bluetooth/LocalDevice.h>
#include "ExtendedLocalDeviceView.h"
#include "defs.h"
#include "BluetoothWindow.h"
static const int32 kMsgSetAntialiasing = 'anti';
@ -119,35 +120,13 @@ void
BluetoothSettingsView::MessageReceived(BMessage *msg)
{
switch (msg->what) {
case kMsgSetAntialiasing:
{
/* bool subpixelAntialiasing;
if (msg->FindBool("antialiasing", &subpixelAntialiasing) != B_OK
|| subpixelAntialiasing == fCurrentSubpixelAntialiasing)
break;
fCurrentSubpixelAntialiasing = subpixelAntialiasing;
fAverageWeightControl->SetEnabled(fCurrentSubpixelAntialiasing);
Window()->PostMessage(kMsgUpdate);
*/ break;
}
case kMsgSetHinting:
{
/* bool hinting;
if (msg->FindBool("hinting", &hinting) != B_OK
|| hinting == fCurrentHinting)
break;
fCurrentHinting = hinting;
Window()->PostMessage(kMsgUpdate);
*/ break;
}
case kMsgLocalSwitched:
{
LocalDevice* lDevice;
if (msg->FindPointer("LocalDevice", (void**) &lDevice) == B_OK) {
// Device integrity should be rechecked
fExtDeviceView->SetLocalDevice(lDevice);
fExtDeviceView->SetLocalDevice(lDevice);
ActiveLocalDevice = lDevice;
}
break;
}

View File

@ -11,10 +11,9 @@
#include <SpaceLayoutItem.h>
#include <TabView.h>
#include <bluetooth/LocalDevice.h>
#include "RemoteDevicesView.h"
//#include "ConnChanView.h"
#include "defs.h"
static const uint32 kMsgSetDefaults = 'dflt';
@ -24,6 +23,8 @@ static const uint32 kMsgStartServices = 'SrSR';
static const uint32 kMsgStopServices = 'StST';
static const uint32 kMsgShowDebug = 'ShDG';
LocalDevice* ActiveLocalDevice = NULL;
BluetoothWindow::BluetoothWindow(BRect frame)
: BWindow(frame, "Bluetooth", B_TITLED_WINDOW,

View File

@ -10,57 +10,225 @@
#include <SpaceLayoutItem.h>
#include <TextView.h>
#include <TabView.h>
#include <ListView.h>
#include <ListItem.h>
#include <MessageRunner.h>
#include <InquiryPanel.h>
#include "defs.h"
#include <bluetooth/DiscoveryAgent.h>
#include <bluetooth/DiscoveryListener.h>
#include <bluetooth/LocalDevice.h>
#include <bluetooth/bdaddrUtils.h>
static const uint32 kMsgUpdate = 'dflt';
static const uint32 kMsgRevert = 'rvrt';
#include "InquiryPanel.h"
static const uint32 kMsgStartServices = 'SrSR';
static const uint32 kMsgStopServices = 'StST';
// private funcionaility provided by kit
extern uint8 GetInquiryTime();
static const uint32 kMsgStart = 'InSt';
static const uint32 kMsgFinish = 'InFn';
static const uint32 kMsgShowDebug = 'ShDG';
static const uint32 kMsgInquiry = 'iQbt';
static const uint32 kMsgAddListDevice = 'aDdv';
InquiryPanel::InquiryPanel(BRect frame)
: BWindow(frame, "Bluetooth", B_TITLED_WINDOW,
B_NOT_ZOOMABLE | B_AUTO_UPDATE_SIZE_LIMITS,
B_ALL_WORKSPACES)
static const uint32 kMsgAddToRemoteList = 'aDdL';
static const uint32 kMsgSecond = 'sCMs';
// TODO: Implement a BluetoothDeviceListItem class, this one is stolen from somewhere .....
class RangeItem : public BListItem
{
public:
RangeItem(uint32 lowAddress, uint32 highAddress, const char* name);
~RangeItem();
virtual void DrawItem(BView *, BRect, bool = false);
static int Compare(const void *firstArg, const void *secondArg);
private:
char* fName;
uint32 fLowAddress, fHighAddress;
};
RangeItem::RangeItem(uint32 lowAddress, uint32 highAddress, const char* name)
: BListItem(),
fLowAddress(lowAddress),
fHighAddress(highAddress)
{
fName = strdup(name);
}
RangeItem::~RangeItem()
{
delete fName;
}
/***********************************************************
* DrawItem
***********************************************************/
void
RangeItem::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());
}
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);
}
int
RangeItem::Compare(const void *firstArg, const void *secondArg)
{
const RangeItem *item1 = *static_cast<const RangeItem * const *>(firstArg);
const RangeItem *item2 = *static_cast<const RangeItem * const *>(secondArg);
if (item1->fLowAddress < item2->fLowAddress) {
return -1;
} else if (item1->fLowAddress > item2->fLowAddress) {
return 1;
} else
return 0;
}
class PanelDiscoveryListener : public DiscoveryListener {
public:
PanelDiscoveryListener(InquiryPanel* iPanel) : DiscoveryListener() , fInquiryPanel(iPanel)
{
}
void
DeviceDiscovered(RemoteDevice* btDevice, DeviceClass cod)
{
BMessage* message = new BMessage(kMsgAddListDevice);
message->AddPointer("remote", btDevice);
fInquiryPanel->PostMessage(message);
}
void
InquiryCompleted(int discType)
{
BMessage* message = new BMessage(kMsgFinish);
fInquiryPanel->PostMessage(message);
}
void
InquiryStarted(status_t status)
{
BMessage* message = new BMessage(kMsgStart);
fInquiryPanel->PostMessage(message);
}
private:
InquiryPanel* fInquiryPanel;
};
InquiryPanel::InquiryPanel(BRect frame, LocalDevice* lDevice)
: BWindow(frame, "Bluetooth", B_FLOATING_WINDOW,
B_NOT_ZOOMABLE | B_NOT_RESIZABLE | B_AUTO_UPDATE_SIZE_LIMITS,
B_ALL_WORKSPACES ), fScanning(false)
, fLocalDevice(lDevice)
{
BRect iDontCare(0,0,0,0);
BRect iDontCareToo(0,0,5,5);
SetLayout(new BGroupLayout(B_HORIZONTAL));
fScanProgress = new BStatusBar(iDontCare, "status", "Scanning", "Scan time");
fScanProgress->SetMaxValue(52);
fScanProgress = new BStatusBar(iDontCare, "status", "Scanning progress", "");
activeColor = fScanProgress->BarColor();
if (fLocalDevice == NULL)
fLocalDevice = LocalDevice::GetLocalDevice();
fMessage = new BTextView(iDontCare, "description",
iDontCare2, B_FOLLOW_LEFT_RIGHT,
B_WILL_DRAW | B_FRAME_EVENTS);
iDontCare, B_FOLLOW_NONE, B_WILL_DRAW | B_SUPPORTS_LAYOUT);
fMessage->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
fMessage->SetLowColor(fMessage->ViewColor());
fMessage->MakeEditable(false);
fMessage->SetText("asdfdasas asdfas asdfasd a dfad asdf dfasdf a");
fMessage->MakeSelectable(false);
fInquiryButton = new BButton("Inquiry", "Inquiry",
new BMessage(kMsgRevert), B_WILL_DRAW);
new BMessage(kMsgInquiry), B_WILL_DRAW);
fAddButton = new BButton("ad", "Add device to list",
new BMessage(kMsgRevert), B_WILL_DRAW);
fAddButton = new BButton("add", "Add device to list",
new BMessage(kMsgAddToRemoteList), B_WILL_DRAW);
fAddButton->SetEnabled(false);
fRemoteList = new BListView("AttributeList", B_SINGLE_SELECTION_LIST);
AddChild(BGroupLayoutBuilder(B_VERTICAL, 0)
.Add(fScanProgress)
.Add(BSpaceLayoutItem::CreateVerticalStrut(5))
if (fLocalDevice != NULL) {
fMessage->SetText("Check that the bluetooth capabilities of your remote device"
" are activated. Press Inquiry to start scanning");
fInquiryButton->SetEnabled(true);
fDiscoveryAgent = fLocalDevice->GetDiscoveryAgent();
fDiscoveryListener = new PanelDiscoveryListener(this);
SetTitle((const char*)(fLocalDevice->GetFriendlyName().String()));
} else {
fMessage->SetText("There has not been found any bluetooth LocalDevice device registered"
" on the system");
fInquiryButton->SetEnabled(false);
}
fRunner = new BMessageRunner(BMessenger(this), new BMessage(kMsgSecond), 1000000L, -1);
AddChild(BGroupLayoutBuilder(B_VERTICAL, 10)
.Add(fMessage)
.Add(BSpaceLayoutItem::CreateVerticalStrut(5))
.Add(BGroupLayoutBuilder(B_HORIZONTAL, 0)
.Add(fScanProgress)
.Add(BSpaceLayoutItem::CreateVerticalStrut(5))
.Add(fRemoteList)
.Add(BSpaceLayoutItem::CreateVerticalStrut(5))
.Add(BGroupLayoutBuilder(B_HORIZONTAL, 10)
.Add(fAddButton)
.AddGlue()
.Add(fInquiryButton)
)
.SetInsets(5, 5, 5, 5)
.SetInsets(15, 25, 15, 15)
);
}
@ -68,34 +236,90 @@ InquiryPanel::InquiryPanel(BRect frame)
void
InquiryPanel::MessageReceived(BMessage *message)
{
static float timer = 0; // expected time of the inquiry process
static float scanningTime = 0;
switch (message->what) {
case kMsgUpdate:
/* fDefaultsButton->SetEnabled(fRemoteDevices->IsDefaultable()
|| fAntialiasingSettings->IsDefaultable());
case kMsgInquiry:
fDiscoveryAgent->StartInquiry(BT_GIAC, fDiscoveryListener, GetInquiryTime());
timer = BT_BASE_INQUIRY_TIME * GetInquiryTime();
fScanProgress->SetMaxValue(timer); // does it works as expected?
fRevertButton->SetEnabled(true);*/
break;
/* case kMsgSetDefaults:
fColorsView -> MessageReceived(new BMessage(DEFAULT_SETTINGS));
fAntialiasingSettings->SetDefaults();
fDefaultsButton->SetEnabled(false);
fRevertButton->SetEnabled(true);
break;
break;
case kMsgAddListDevice:
{
RemoteDevice* rDevice;
message->FindPointer("remote", (void **)&rDevice);
fRemoteList->AddItem(new RangeItem(0,1,bdaddrUtils::ToString(rDevice->GetBluetoothAddress())));
}
break;
case kMsgRevert:
fColorsView -> MessageReceived(new BMessage(REVERT_SETTINGS));
fAntialiasingSettings->Revert();
fDefaultsButton->SetEnabled(fColorsView->IsDefaultable()
|| fAntialiasingSettings->IsDefaultable());
fRevertButton->SetEnabled(false);
break;
*/ default:
case kMsgStart:
fRemoteList->MakeEmpty();
fScanProgress->Reset();
scanningTime = 0;
fScanning = true;
UpdateUIStatus();
break;
case kMsgFinish:
fScanning = false;
UpdateUIStatus();
break;
case kMsgSecond:
{
if (fScanning) {
BString elapsedTime = "Remaining ";
fScanProgress->SetTo(scanningTime*100/timer); // TODO should not be needed if SetMaxValue works...
elapsedTime << (int)(timer - scanningTime) << " seconds";
fScanProgress->SetTrailingText(elapsedTime.String());
scanningTime = scanningTime + 1;
}
if (fRemoteList->CurrentSelection() < 0)
fAddButton->SetEnabled(false);
else
fAddButton->SetEnabled(true);
}
break;
default:
BWindow::MessageReceived(message);
break;
}
}
void
InquiryPanel::UpdateUIStatus(void)
{
if (fScanning) {
fAddButton->SetEnabled(false);
fInquiryButton->SetEnabled(false);
fScanProgress->SetBarColor(activeColor);
} else {
fInquiryButton->SetEnabled(true);
fScanProgress->SetBarColor(ui_color(B_PANEL_BACKGROUND_COLOR));
fScanProgress->SetTo(100);
fScanProgress->SetText("Scan completed");
}
}
bool
InquiryPanel::QuitRequested(void)
{

View File

@ -14,20 +14,35 @@
class BStatusBar;
class BButton;
class BTextView;
class BListView;
class LocalDevice;
class DiscoveryAgent;
class DiscoveryListener;
class InquiryPanel : public BWindow
{
public:
InquiryPanel(BRect frame);
InquiryPanel(BRect frame, LocalDevice* lDevice = NULL);
bool QuitRequested(void);
void MessageReceived(BMessage *message);
private:
BStatusBar* fScanProgress;
BButton* fAddButton;
BButton* fInquiryButton;
BTextView* fMessage;
BStatusBar* fScanProgress;
BButton* fAddButton;
BButton* fInquiryButton;
BTextView* fMessage;
BListView* fRemoteList;
BMessageRunner* fRunner;
bool fScanning;
LocalDevice* fLocalDevice;
DiscoveryAgent* fDiscoveryAgent;
DiscoveryListener* fDiscoveryListener;
void UpdateUIStatus(void);
rgb_color activeColor;
};
#endif

View File

@ -2,7 +2,7 @@
* Copyright 2008-09, Oliver Ruiz Dorantes, <oliver.ruiz.dorantes_at_gmail.com>
* All rights reserved. Distributed under the terms of the MIT License.
*/
#include "RemoteDevicesView.h"
#include <stdio.h>
#include <Alert.h>
#include <Directory.h>
@ -13,17 +13,16 @@
#include <Path.h>
#include <SpaceLayoutItem.h>
#include <stdio.h>
#include "defs.h"
#include "InquiryPanel.h"
#include "BluetoothWindow.h"
#include "defs.h"
#include "RemoteDevicesView.h"
static const uint32 kMsgAddDevices = 'ddDv';
RemoteDevicesView::RemoteDevicesView(const char *name, uint32 flags)
: BView(name, flags)
{
@ -75,7 +74,7 @@ RemoteDevicesView::RemoteDevicesView(const char *name, uint32 flags)
.SetInsets(5, 5, 5, 100)
);
fAttrList->SetSelectionMessage(new BMessage(ATTRIBUTE_CHOSEN));
fAttrList->SetSelectionMessage(NULL);
}
RemoteDevicesView::~RemoteDevicesView(void)
@ -108,7 +107,7 @@ RemoteDevicesView::MessageReceived(BMessage *msg)
switch(msg->what) {
case kMsgAddDevices:
{
InquiryPanel* iPanel = new InquiryPanel(BRect(0,0,50,50));
InquiryPanel* iPanel = new InquiryPanel(BRect(100,100,400,400), ActiveLocalDevice);
iPanel->Show();
}
break;

View File

@ -1,14 +1,7 @@
#ifndef DEFS_H_
#define DEFS_H_
// If these paths are changed, ensure that they all end in a '/' character
/*
#define SETTINGS_DIR "/boot/home/config/settings/app_server/"
#define COLOR_SET_DIR "/boot/home/config/settings/color_sets/"
#define CURSOR_SET_DIR "/boot/home/config/settings/cursor_sets/"
#define DECORATORS_DIR "/boot/home/config/add-ons/decorators/"
#define COLOR_SETTINGS_NAME "system_colors"
*/
#include <bluetooth/LocalDevice.h>
#define BLUETOOTH_APP_SIGNATURE "application/x-vnd.haiku-BluetoothPrefs"
@ -33,4 +26,6 @@
const uint32 kBorderSpace = 10;
const uint32 kItemSpace = 7;
extern LocalDevice* ActiveLocalDevice;
#endif