- Use static MessageRunners,
- Banlance the process of retrieving the remote names, which is blocks the Window Looper, as get remote name is an expensive operation. Now it waits half second between each operation which gives a better feeling(without using extra thread, that will come when there is an standard barberpole) git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@29403 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -38,6 +38,7 @@ static const uint32 kMsgAddListDevice = 'aDdv';
|
|||||||
|
|
||||||
static const uint32 kMsgSelected = 'isLt';
|
static const uint32 kMsgSelected = 'isLt';
|
||||||
static const uint32 kMsgSecond = 'sCMs';
|
static const uint32 kMsgSecond = 'sCMs';
|
||||||
|
static const uint32 kMsgRetrieve = 'IrEt';
|
||||||
|
|
||||||
|
|
||||||
class PanelDiscoveryListener : public DiscoveryListener {
|
class PanelDiscoveryListener : public DiscoveryListener {
|
||||||
@@ -85,12 +86,12 @@ private:
|
|||||||
InquiryPanel::InquiryPanel(BRect frame, LocalDevice* lDevice)
|
InquiryPanel::InquiryPanel(BRect frame, LocalDevice* lDevice)
|
||||||
: BWindow(frame, "Bluetooth", B_FLOATING_WINDOW,
|
: BWindow(frame, "Bluetooth", B_FLOATING_WINDOW,
|
||||||
B_NOT_ZOOMABLE | B_AUTO_UPDATE_SIZE_LIMITS,
|
B_NOT_ZOOMABLE | B_AUTO_UPDATE_SIZE_LIMITS,
|
||||||
B_ALL_WORKSPACES ), fScanning(false)
|
B_ALL_WORKSPACES ), fMessenger(this)
|
||||||
|
, fScanning(false)
|
||||||
, fRetrieving(false)
|
, fRetrieving(false)
|
||||||
, fLocalDevice(lDevice)
|
, fLocalDevice(lDevice)
|
||||||
{
|
|
||||||
// BRect iDontCare(0,0,0,0);
|
|
||||||
|
|
||||||
|
{
|
||||||
SetLayout(new BGroupLayout(B_HORIZONTAL));
|
SetLayout(new BGroupLayout(B_HORIZONTAL));
|
||||||
|
|
||||||
fScanProgress = new BStatusBar("status", "Scanning progress", "");
|
fScanProgress = new BStatusBar("status", "Scanning progress", "");
|
||||||
@@ -135,7 +136,8 @@ InquiryPanel::InquiryPanel(BRect frame, LocalDevice* lDevice)
|
|||||||
fInquiryButton->SetEnabled(false);
|
fInquiryButton->SetEnabled(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
fRunner = new BMessageRunner(BMessenger(this), new BMessage(kMsgSecond), 1000000L);
|
fRetrieveMessage = new BMessage(kMsgRetrieve);
|
||||||
|
fSecondsMessage = new BMessage(kMsgSecond);
|
||||||
|
|
||||||
|
|
||||||
AddChild(BGroupLayoutBuilder(B_VERTICAL, 10)
|
AddChild(BGroupLayoutBuilder(B_VERTICAL, 10)
|
||||||
@@ -161,13 +163,14 @@ 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;
|
||||||
|
|
||||||
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();
|
timer = BT_BASE_INQUIRY_TIME * GetInquiryTime() + 1;
|
||||||
fScanProgress->SetMaxValue(timer); // does it works as expected?
|
fScanProgress->SetMaxValue(timer); // does it works as expected?
|
||||||
|
|
||||||
break;
|
break;
|
||||||
@@ -203,24 +206,34 @@ InquiryPanel::MessageReceived(BMessage *message)
|
|||||||
case kMsgStart:
|
case kMsgStart:
|
||||||
fRemoteList->MakeEmpty();
|
fRemoteList->MakeEmpty();
|
||||||
fScanProgress->Reset();
|
fScanProgress->Reset();
|
||||||
scanningTime = 0;
|
fScanProgress->SetTo(1);
|
||||||
|
fScanProgress->SetTrailingText("Starting scan...");
|
||||||
|
fScanProgress->SetBarColor(activeColor);
|
||||||
|
|
||||||
|
fAddButton->SetEnabled(false);
|
||||||
|
fInquiryButton->SetEnabled(false);
|
||||||
|
|
||||||
|
BMessageRunner::StartSending(fMessenger, fSecondsMessage, 1000000, timer);
|
||||||
|
|
||||||
|
scanningTime = 1;
|
||||||
fScanning = true;
|
fScanning = true;
|
||||||
|
|
||||||
UpdateUIStatus();
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case kMsgFinish:
|
case kMsgFinish:
|
||||||
|
|
||||||
retrievalIndex = 0;
|
retrievalIndex = 0;
|
||||||
fScanning = false;
|
fScanning = false;
|
||||||
fRetrieving = true;
|
fRetrieving = true;
|
||||||
|
labelPlaced = false;
|
||||||
|
fScanProgress->SetTo(100);
|
||||||
|
fScanProgress->SetTrailingText("Retrieving names...");
|
||||||
|
BMessageRunner::StartSending(fMessenger, fRetrieveMessage, 1000000, 1);
|
||||||
|
|
||||||
UpdateListStatus();
|
|
||||||
UpdateUIStatus();
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case kMsgSecond:
|
case kMsgSecond:
|
||||||
{
|
if (fScanning && scanningTime < timer) {
|
||||||
if (fScanning) {
|
|
||||||
BString elapsedTime = "Remaining ";
|
BString elapsedTime = "Remaining ";
|
||||||
|
|
||||||
fScanProgress->SetTo(scanningTime*100/timer); // TODO should not be needed if SetMaxValue works...
|
fScanProgress->SetTo(scanningTime*100/timer); // TODO should not be needed if SetMaxValue works...
|
||||||
@@ -230,16 +243,34 @@ InquiryPanel::MessageReceived(BMessage *message)
|
|||||||
|
|
||||||
scanningTime = scanningTime + 1;
|
scanningTime = scanningTime + 1;
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case kMsgRetrieve:
|
||||||
|
|
||||||
if (fRetrieving) {
|
if (fRetrieving) {
|
||||||
|
|
||||||
if (retrievalIndex < fDiscoveryAgent->RetrieveDevices(0).CountItems()) {
|
if (retrievalIndex < fDiscoveryAgent->RetrieveDevices(0).CountItems()) {
|
||||||
|
|
||||||
((DeviceListItem*)fRemoteList->ItemAt(retrievalIndex))->
|
if (!labelPlaced) {
|
||||||
SetDevice((BluetoothDevice*)fDiscoveryAgent->RetrieveDevices(0).ItemAt(retrievalIndex));
|
|
||||||
|
|
||||||
fRemoteList->Invalidate();
|
labelPlaced = true;
|
||||||
retrievalIndex++;
|
BString progressText = "Retrieving name of ";
|
||||||
|
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));
|
||||||
|
fRemoteList->InvalidateItem(retrievalIndex);
|
||||||
|
|
||||||
|
retrievalIndex++;
|
||||||
|
labelPlaced = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
BMessageRunner::StartSending(fMessenger, fRetrieveMessage, 500000, 1);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
@@ -247,12 +278,12 @@ InquiryPanel::MessageReceived(BMessage *message)
|
|||||||
retrievalIndex = 0;
|
retrievalIndex = 0;
|
||||||
|
|
||||||
fScanProgress->SetBarColor(ui_color(B_PANEL_BACKGROUND_COLOR));
|
fScanProgress->SetBarColor(ui_color(B_PANEL_BACKGROUND_COLOR));
|
||||||
fScanProgress->SetTrailingText("Scanning completed ...");
|
fScanProgress->SetTrailingText("Scanning completed.");
|
||||||
|
fInquiryButton->SetEnabled(true);
|
||||||
|
UpdateListStatus();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
UpdateUIStatus();
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
@@ -262,25 +293,6 @@ InquiryPanel::MessageReceived(BMessage *message)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
InquiryPanel::UpdateUIStatus(void)
|
|
||||||
{
|
|
||||||
if (fScanning) {
|
|
||||||
fAddButton->SetEnabled(false);
|
|
||||||
fInquiryButton->SetEnabled(false);
|
|
||||||
fScanProgress->SetBarColor(activeColor);
|
|
||||||
fAddButton->SetEnabled(false);
|
|
||||||
|
|
||||||
} else if (fRetrieving) {
|
|
||||||
fInquiryButton->SetEnabled(true);
|
|
||||||
fScanProgress->SetTo(100);
|
|
||||||
fScanProgress->SetTrailingText("Retrieving names ...");
|
|
||||||
} else {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
InquiryPanel::UpdateListStatus(void)
|
InquiryPanel::UpdateListStatus(void)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -34,7 +34,9 @@ private:
|
|||||||
BTextView* fMessage;
|
BTextView* fMessage;
|
||||||
BListView* fRemoteList;
|
BListView* fRemoteList;
|
||||||
BScrollView* fScrollView;
|
BScrollView* fScrollView;
|
||||||
BMessageRunner* fRunner;
|
BMessage* fRetrieveMessage;
|
||||||
|
BMessage* fSecondsMessage;
|
||||||
|
BMessenger fMessenger;
|
||||||
|
|
||||||
bool fScanning;
|
bool fScanning;
|
||||||
bool fRetrieving;
|
bool fRetrieving;
|
||||||
@@ -42,8 +44,6 @@ private:
|
|||||||
DiscoveryAgent* fDiscoveryAgent;
|
DiscoveryAgent* fDiscoveryAgent;
|
||||||
DiscoveryListener* fDiscoveryListener;
|
DiscoveryListener* fDiscoveryListener;
|
||||||
|
|
||||||
|
|
||||||
void UpdateUIStatus(void);
|
|
||||||
void UpdateListStatus(void);
|
void UpdateListStatus(void);
|
||||||
|
|
||||||
rgb_color activeColor;
|
rgb_color activeColor;
|
||||||
|
|||||||
Reference in New Issue
Block a user