- Pointer not initialized for LocalDevice Menu (thanks Rene)

- Show Alert when bluetooth_server is not running (work in progress)
- Typos and Style



git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@34997 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Oliver Ruiz Dorantes
2010-01-10 22:53:00 +00:00
parent 9fe2b96342
commit d9e36ee1c2
5 changed files with 172 additions and 137 deletions
+79 -33
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright 2008-09, Oliver Ruiz Dorantes, <oliver.ruiz.dorantes_at_gmail.com> * Copyright 2008-10, 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.
*/ */
#include <stdio.h> #include <stdio.h>
@@ -7,6 +7,8 @@
#include <Alert.h> #include <Alert.h>
#include <Catalog.h> #include <Catalog.h>
#include <Locale.h> #include <Locale.h>
#include <MessageRunner.h>
#include <Roster.h>
#include "BluetoothMain.h" #include "BluetoothMain.h"
#include "BluetoothWindow.h" #include "BluetoothWindow.h"
@@ -19,9 +21,47 @@ BluetoothApplication::BluetoothApplication(void)
: BApplication(BLUETOOTH_APP_SIGNATURE) : BApplication(BLUETOOTH_APP_SIGNATURE)
{ {
be_locale->GetAppCatalog(&fCatalog); be_locale->GetAppCatalog(&fCatalog);
}
void
BluetoothApplication::ReadyToRun()
{
if (!be_roster->IsRunning(BLUETOOTH_SIGNATURE)) {
int32 choice = (new BAlert("bluetooth_server not running",
"bluetooth_server has not been found running on the system."
"Should be started, or stay offline", "Work offline",
"Quit", "Start please", B_WIDTH_AS_USUAL, B_WARNING_ALERT))->Go();
switch (choice) {
case 1:
PostMessage(B_QUIT_REQUESTED);
return;
case 2:
{
status_t error;
error = be_roster->Launch(BLUETOOTH_SIGNATURE);
printf("kMsgStartServices: %s\n", strerror(error));
// TODO: This is temporal
// BMessage handcheck: use the version of Launch()
// that includes a BMessage in that message include
// a BMessenger to yourself and the BT server could
// use that messenger to send back a reply indicating
// when it's ready and you could just create window
// when you get that
BMessageRunner::StartSending(be_app_messenger,
new BMessage('Xtmp'), 2 * 1000000, 1);
break;
}
default:
PostMessage(new BMessage('Xtmp'));
break;
}
}
fWindow = new BluetoothWindow(BRect(100, 100, 550, 420));
fWindow->Show();
} }
@@ -30,50 +70,56 @@ BluetoothApplication::AboutRequested()
{ {
(new BAlert("about", TR("Haiku Bluetooth system, (ARCE)\n\n" (new BAlert("about", TR("Haiku Bluetooth system, (ARCE)\n\n"
"Created by Oliver Ruiz Dorantes\n\n" "Created by Oliver Ruiz Dorantes\n\n"
"With support of:\n" "With support of:\n"
" - Mika Lindqvist\n" " - Mika Lindqvist\n"
" - Maksym Yevmenkin\n\n" " - Adrien Destugues\n"
"Thanks to the individuals who helped...\n\n" " - Maksym Yevmenkin\n\n"
"Shipping/donating hardware:\n" "Thanks to the individuals who helped...\n\n"
" - Henry Jair Abril Florez (el Colombian)\n" "Shipping/donating hardware:\n"
" & Stefanie Bartolich\n" " - Henry Jair Abril Florez (el Colombian)\n"
" - Edwin Erik Amsler\n" " & Stefanie Bartolich\n"
" - Dennis d'Entremont\n" " - Edwin Erik Amsler\n"
" - Luroh\n" " - Dennis d'Entremont\n"
" - Pieter Panman\n\n" " - Luroh\n"
"Economically:\n" " - Pieter Panman\n\n"
" - Karl vom Dorff, Andrea Bernardi (OSDrawer),\n" "Economically:\n"
" - Matt M, Doug F, Hubert H,\n" " - Karl vom Dorff, Andrea Bernardi (OSDrawer),\n"
" - Sebastian B, Andrew M, Jared E,\n" " - Matt M, Doug F, Hubert H,\n"
" - Frederik H, Tom S, Ferry B,\n" " - Sebastian B, Andrew M, Jared E,\n"
" - Greg G, David F, Richard S, Martin W:\n\n" " - Frederik H, Tom S, Ferry B,\n"
"With patches:\n" " - Greg G, David F, Richard S, Martin W:\n\n"
" - Michael Weirauch\n" "With patches:\n"
" - Fredrik Ekdahl\n" " - Michael Weirauch\n"
" - Raynald Lesieur\n" " - Fredrik Ekdahl\n"
" - Andreas Färber\n" " - Raynald Lesieur\n"
" - Joerg Meyer\n" " - Andreas Färber\n"
"Testing:\n" " - Joerg Meyer\n"
" - Petter H. Juliussen\n" "Testing:\n"
" - Adrien Destugues\n\n" " - Petter H. Juliussen\n"
"Who gave me all the knowledge:\n" "Who gave me all the knowledge:\n"
" - the yellowTAB team"), TR("OK")))->Go(); " - the yellowTAB team"), TR("OK")))->Go();
} }
void void
BluetoothApplication::MessageReceived(BMessage *message) BluetoothApplication::MessageReceived(BMessage* message)
{ {
switch (message->what) { switch (message->what) {
case kMsgAddToRemoteList: case kMsgAddToRemoteList:
fWindow->PostMessage(message); fWindow->PostMessage(message);
break; break;
case 'Xtmp':
fWindow = new BluetoothWindow(BRect(100, 100, 550, 420));
fWindow->Show();
break;
default: default:
BApplication::MessageReceived(message); BApplication::MessageReceived(message);
} }
} }
int int
main(int, char**) main(int, char**)
{ {
+3 -2
View File
@@ -14,12 +14,13 @@ class BluetoothApplication : public BApplication
public: public:
BluetoothApplication(void); BluetoothApplication(void);
virtual void ReadyToRun();
virtual void MessageReceived(BMessage*); virtual void MessageReceived(BMessage*);
virtual void AboutRequested(); virtual void AboutRequested();
private: private:
BluetoothWindow *fWindow; BluetoothWindow* fWindow;
BCatalog fCatalog; BCatalog fCatalog;
}; };
@@ -52,47 +52,47 @@ static const char* kPhoneLabel = TR_MARK("Smart phone");
// #pragma mark - // #pragma mark -
BluetoothSettingsView::BluetoothSettingsView(const char* name) BluetoothSettingsView::BluetoothSettingsView(const char* name)
: BView(name, 0) : BView(name, 0),
fLocalDevicesMenu(NULL)
{ {
// antialiasing menu
_BuildConnectionPolicy(); _BuildConnectionPolicy();
fAntialiasingMenuField = new BMenuField("antialiasing", fPolicyMenuField = new BMenuField("antialiasing",
TR("Incoming connections policy:"), fAntialiasingMenu, NULL); TR("Incoming connections policy:"), fPolicyMenu, NULL);
fAverageWeightControl = new BSlider("averageWeightControl", fInquiryTimeControl = new BSlider("time",
TR("Default inquiry time:"), new BMessage(kMsgSetAverageWeight), 0, 255, TR("Default inquiry time:"), new BMessage(kMsgSetAverageWeight), 0, 255,
B_HORIZONTAL); B_HORIZONTAL);
fAverageWeightControl->SetLimitLabels(TR("15 secs"), TR("61 secs")); fInquiryTimeControl->SetLimitLabels(TR("15 secs"), TR("61 secs"));
fAverageWeightControl->SetHashMarks(B_HASH_MARKS_BOTTOM); fInquiryTimeControl->SetHashMarks(B_HASH_MARKS_BOTTOM);
fAverageWeightControl->SetHashMarkCount(255 / 15); fInquiryTimeControl->SetHashMarkCount(255 / 15);
fAverageWeightControl->SetEnabled(true); fInquiryTimeControl->SetEnabled(true);
// hinting menu // hinting menu
_BuildHintingMenu(); _BuildClassMenu();
fHintingMenuField = new BMenuField("hinting", TR("Identify host as:"), fClassMenuField = new BMenuField("class", TR("Identify host as:"),
fHintingMenu, NULL); fClassMenu, NULL);
// localdevices menu // localdevices menu
_BuildLocalDevicesMenu(); _BuildLocalDevicesMenu();
fLocalDevicesMenuField = new BMenuField("devices", fLocalDevicesMenuField = new BMenuField("devices",
TR("Local devices found on system:"), fLocalDevicesMenu, NULL); TR("Local devices found on system:"), fLocalDevicesMenu, NULL);
fExtDeviceView = new ExtendedLocalDeviceView(BRect(0,0,5,5), NULL); fExtDeviceView = new ExtendedLocalDeviceView(BRect(0, 0, 5, 5), NULL);
SetLayout(new BGroupLayout(B_VERTICAL)); SetLayout(new BGroupLayout(B_VERTICAL));
// controls pane // controls pane
AddChild(BGridLayoutBuilder(10, 10) AddChild(BGridLayoutBuilder(10, 10)
.Add(fHintingMenuField->CreateLabelLayoutItem(), 0, 0) .Add(fClassMenuField->CreateLabelLayoutItem(), 0, 0)
.Add(fHintingMenuField->CreateMenuBarLayoutItem(), 1, 0) .Add(fClassMenuField->CreateMenuBarLayoutItem(), 1, 0)
.Add(fAntialiasingMenuField->CreateLabelLayoutItem(), 0, 1) .Add(fPolicyMenuField->CreateLabelLayoutItem(), 0, 1)
.Add(fAntialiasingMenuField->CreateMenuBarLayoutItem(), 1, 1) .Add(fPolicyMenuField->CreateMenuBarLayoutItem(), 1, 1)
.Add(BSpaceLayoutItem::CreateGlue(), 0, 2, 2) .Add(BSpaceLayoutItem::CreateGlue(), 0, 2, 2)
.Add(fAverageWeightControl, 0, 3, 2) .Add(fInquiryTimeControl, 0, 3, 2)
.Add(BSpaceLayoutItem::CreateGlue(), 0, 4, 2) .Add(BSpaceLayoutItem::CreateGlue(), 0, 4, 2)
.Add(fLocalDevicesMenuField->CreateLabelLayoutItem(), 0, 5) .Add(fLocalDevicesMenuField->CreateLabelLayoutItem(), 0, 5)
@@ -121,24 +121,24 @@ BluetoothSettingsView::AttachedToWindow()
else else
SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
fAntialiasingMenu->SetTargetForItems(this); fPolicyMenu->SetTargetForItems(this);
fHintingMenu->SetTargetForItems(this); fClassMenu->SetTargetForItems(this);
fLocalDevicesMenu->SetTargetForItems(this); fLocalDevicesMenu->SetTargetForItems(this);
fAverageWeightControl->SetTarget(this); fInquiryTimeControl->SetTarget(this);
} }
void void
BluetoothSettingsView::MessageReceived(BMessage *msg) BluetoothSettingsView::MessageReceived(BMessage* message)
{ {
DeviceClass devClass; DeviceClass devClass;
switch (msg->what) { switch (message->what) {
case kMsgLocalSwitched: case kMsgLocalSwitched:
{ {
LocalDevice* lDevice; LocalDevice* lDevice;
if (msg->FindPointer("LocalDevice", (void**) &lDevice) == B_OK) { if (message->FindPointer("LocalDevice", (void**) &lDevice) == B_OK) {
// Device integrity should be rechecked // Device integrity should be rechecked
fExtDeviceView->SetLocalDevice(lDevice); fExtDeviceView->SetLocalDevice(lDevice);
fExtDeviceView->SetEnabled(true); fExtDeviceView->SetEnabled(true);
@@ -187,7 +187,7 @@ BluetoothSettingsView::MessageReceived(BMessage *msg)
fLocalDevicesMenu->SetTargetForItems(this); fLocalDevicesMenu->SetTargetForItems(this);
break; break;
default: default:
BView::MessageReceived(msg); BView::MessageReceived(message);
} }
} }
@@ -195,56 +195,55 @@ BluetoothSettingsView::MessageReceived(BMessage *msg)
void void
BluetoothSettingsView::_BuildConnectionPolicy() BluetoothSettingsView::_BuildConnectionPolicy()
{ {
fAntialiasingMenu = new BPopUpMenu(TR("Policy...")); fPolicyMenu = new BPopUpMenu(TR("Policy..."));
BMessage* message = new BMessage(kMsgSetAntialiasing); BMessage* message = new BMessage(kMsgSetAntialiasing);
message->AddBool("antialiasing", false); message->AddBool("antialiasing", false);
BMenuItem* item = new BMenuItem(TR(kAllLabel), message); BMenuItem* item = new BMenuItem(TR(kAllLabel), message);
fAntialiasingMenu->AddItem(item); fPolicyMenu->AddItem(item);
message = new BMessage(kMsgSetAntialiasing); message = new BMessage(kMsgSetAntialiasing);
message->AddBool("antialiasing", true); message->AddBool("antialiasing", true);
item = new BMenuItem(TR(kTrustedLabel), message); item = new BMenuItem(TR(kTrustedLabel), message);
fAntialiasingMenu->AddItem(item); fPolicyMenu->AddItem(item);
BMenuItem* item2 = new BMenuItem(TR(kAlwaysLabel), NULL); BMenuItem* item2 = new BMenuItem(TR(kAlwaysLabel), NULL);
fAntialiasingMenu->AddItem(item2); fPolicyMenu->AddItem(item2);
} }
void void
BluetoothSettingsView::_BuildHintingMenu() BluetoothSettingsView::_BuildClassMenu()
{ {
fHintingMenu = new BPopUpMenu(TR("Identify us as...")); fClassMenu = new BPopUpMenu(TR("Identify us as..."));
BMessage* message; BMessage* message;
message = new BMessage(kMsgSetDeviceClassDesktop); message = new BMessage(kMsgSetDeviceClassDesktop);
BMenuItem* item = new BMenuItem(TR(kDesktopLabel), message); BMenuItem* item = new BMenuItem(TR(kDesktopLabel), message);
fHintingMenu->AddItem(item); fClassMenu->AddItem(item);
message = new BMessage(kMsgSetDeviceClassServer); message = new BMessage(kMsgSetDeviceClassServer);
item = new BMenuItem(TR(kServerLabel), message); item = new BMenuItem(TR(kServerLabel), message);
fHintingMenu->AddItem(item); fClassMenu->AddItem(item);
message = new BMessage(kMsgSetDeviceClassLaptop); message = new BMessage(kMsgSetDeviceClassLaptop);
item = new BMenuItem(TR(kLaptopLabel), message); item = new BMenuItem(TR(kLaptopLabel), message);
fHintingMenu->AddItem(item); fClassMenu->AddItem(item);
message = new BMessage(kMsgSetDeviceClassHandheld); message = new BMessage(kMsgSetDeviceClassHandheld);
item = new BMenuItem(TR(kHandheldLabel), message); item = new BMenuItem(TR(kHandheldLabel), message);
fHintingMenu->AddItem(item); fClassMenu->AddItem(item);
message = new BMessage(kMsgSetDeviceClassSmartPhone); message = new BMessage(kMsgSetDeviceClassSmartPhone);
item = new BMenuItem(TR(kPhoneLabel), message); item = new BMenuItem(TR(kPhoneLabel), message);
fHintingMenu->AddItem(item); fClassMenu->AddItem(item);
} }
@@ -257,20 +256,18 @@ BluetoothSettingsView::_BuildLocalDevicesMenu()
if (!fLocalDevicesMenu) if (!fLocalDevicesMenu)
fLocalDevicesMenu = new BPopUpMenu(TR("Pick LocalDevice...")); fLocalDevicesMenu = new BPopUpMenu(TR("Pick LocalDevice..."));
for (uint32 index = 0 ; index < LocalDevice::GetLocalDeviceCount() ; index++) { for (uint32 index = 0; index < LocalDevice::GetLocalDeviceCount(); index++) {
lDevice = LocalDevice::GetLocalDevice(); lDevice = LocalDevice::GetLocalDevice();
if (lDevice != NULL) { if (lDevice != NULL) {
// TODO Check if they already exists
// TODO Check if they already exists
BMessage* message = new BMessage(kMsgLocalSwitched); BMessage* message = new BMessage(kMsgLocalSwitched);
message->AddPointer("LocalDevice", lDevice); message->AddPointer("LocalDevice", lDevice);
BMenuItem* item = new BMenuItem((lDevice->GetFriendlyName().String()), message); BMenuItem* item = new BMenuItem((lDevice->GetFriendlyName().String()),
message);
fLocalDevicesMenu->AddItem(item); fLocalDevicesMenu->AddItem(item);
} }
} }
} }
@@ -26,32 +26,23 @@ public:
private: private:
void _BuildConnectionPolicy(); void _BuildConnectionPolicy();
void _SetCurrentAntialiasing(); void _BuildClassMenu();
void _BuildHintingMenu();
void _SetCurrentHinting();
void _SetCurrentAverageWeight();
void _BuildLocalDevicesMenu(); void _BuildLocalDevicesMenu();
protected: protected:
float fDivider; float fDivider;
BMenuField* fAntialiasingMenuField; BMenuField* fPolicyMenuField;
BPopUpMenu* fAntialiasingMenu; BPopUpMenu* fPolicyMenu;
BMenuField* fHintingMenuField; BMenuField* fClassMenuField;
BPopUpMenu* fHintingMenu; BPopUpMenu* fClassMenu;
BMenuField* fLocalDevicesMenuField; BMenuField* fLocalDevicesMenuField;
BPopUpMenu* fLocalDevicesMenu; BPopUpMenu* fLocalDevicesMenu;
ExtendedLocalDeviceView* fExtDeviceView; ExtendedLocalDeviceView* fExtDeviceView;
BSlider* fAverageWeightControl; BSlider* fInquiryTimeControl;
bool fSavedSubpixelAntialiasing;
bool fCurrentSubpixelAntialiasing;
bool fSavedHinting;
bool fCurrentHinting;
unsigned char fSavedAverageWeight;
unsigned char fCurrentAverageWeight;
}; };
#endif // ANTIALIASING_SETTINGS_VIEW_H #endif // ANTIALIASING_SETTINGS_VIEW_H
@@ -124,7 +124,7 @@ BluetoothWindow::MessageReceived(BMessage* message)
status_t error; status_t error;
error = be_roster->Launch(BLUETOOTH_SIGNATURE); error = be_roster->Launch(BLUETOOTH_SIGNATURE);
printf("kMsgStopServices: %s\n", strerror(error)); printf("kMsgStartServices: %s\n", strerror(error));
} }
break; break;