- Patch by Michael Weirauch, Finally a deskbar addon for bluetooth
- Functionality to stop services, start preferences, and show debug console - Cleanups in signatures -This line, and those below, will be ignored-- M headers/private/bluetooth/bluetoothserver_p.h M src/servers/bluetooth/BluetoothServer.h A src/servers/bluetooth/DeskbarReplicant.cpp A src/servers/bluetooth/DeskbarReplicant.h M src/servers/bluetooth/Jamfile M src/servers/bluetooth/BluetoothServer.cpp M src/preferences/bluetooth/BluetoothMain.cpp M src/preferences/bluetooth/Jamfile M src/preferences/bluetooth/defs.h M src/preferences/bluetooth/BluetoothWindow.cpp git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@31508 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
|
||||
|
||||
#define BLUETOOTH_SIGNATURE "application/x-vnd.Be-bluetooth_server"
|
||||
#define BLUETOOTH_APP_SIGNATURE "application/x-vnd.haiku-BluetoothPrefs"
|
||||
|
||||
/* Kit Comunication */
|
||||
|
||||
@@ -21,5 +22,7 @@
|
||||
#define BT_MSG_INQUIRY_ERROR 'IqER'
|
||||
#define BT_MSG_INQUIRY_DEVICE 'IqDE'
|
||||
|
||||
// Server
|
||||
#define BT_MSG_SERVER_SHOW_CONSOLE 'btsc'
|
||||
|
||||
#endif
|
||||
|
||||
@@ -44,9 +44,10 @@ BluetoothApplication::AboutRequested()
|
||||
" - Frederik H, Tom S, Ferry B,\n"
|
||||
" - Greg G, David F, Richard S, Martin W:\n\n"
|
||||
"With patches:\n"
|
||||
" - Michael Weirauch\n"
|
||||
" - Fredrik Ekdahl\n"
|
||||
" - Raynald Lesieur\n"
|
||||
" - Andreas Färber\n\n"
|
||||
" - Andreas Färber\n"
|
||||
" - Jörg Meyer\n"
|
||||
"Testing:\n"
|
||||
" - Petter H. Juliussen\n"
|
||||
|
||||
@@ -110,16 +110,16 @@ BluetoothWindow::MessageReceived(BMessage *message)
|
||||
*/ break;
|
||||
case kMsgStartServices:
|
||||
printf("kMsgStartServices\n");
|
||||
if (!be_roster->IsRunning("application/x-vnd.Be-bluetooth_server"))
|
||||
if (!be_roster->IsRunning(BLUETOOTH_SIGNATURE))
|
||||
{
|
||||
printf("kMsgStopServices: %s\n", strerror(be_roster->Launch("application/x-vnd.Be-bluetooth_server")));
|
||||
printf("kMsgStopServices: %s\n", strerror(be_roster->Launch(BLUETOOTH_SIGNATURE)));
|
||||
}
|
||||
break;
|
||||
case kMsgStopServices:
|
||||
printf("kMsgStopServices\n");
|
||||
if (be_roster->IsRunning("application/x-vnd.Be-bluetooth_server"))
|
||||
if (be_roster->IsRunning(BLUETOOTH_SIGNATURE))
|
||||
{
|
||||
printf("kMsgStopServices: %s\n", strerror(BMessenger("application/x-vnd.Be-bluetooth_server").SendMessage(B_QUIT_REQUESTED)));
|
||||
printf("kMsgStopServices: %s\n", strerror(BMessenger(BLUETOOTH_SIGNATURE).SendMessage(B_QUIT_REQUESTED)));
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
SubDir HAIKU_TOP src preferences bluetooth ;
|
||||
|
||||
UsePrivateHeaders bluetooth ;
|
||||
UsePrivateHeaders shared ;
|
||||
|
||||
AddResources Bluetooth : bluetooth-pref.rdef ;
|
||||
|
||||
@@ -3,7 +3,8 @@
|
||||
|
||||
#include <bluetooth/LocalDevice.h>
|
||||
|
||||
#define BLUETOOTH_APP_SIGNATURE "application/x-vnd.haiku-BluetoothPrefs"
|
||||
#include <bluetoothserver_p.h>
|
||||
|
||||
|
||||
#define APPLY_SETTINGS 'aply'
|
||||
#define REVERT_SETTINGS 'rvrt'
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
#include <unistd.h>
|
||||
|
||||
#include <Entry.h>
|
||||
#include <Deskbar.h>
|
||||
#include <Directory.h>
|
||||
#include <Message.h>
|
||||
#include <Path.h>
|
||||
@@ -22,8 +23,9 @@
|
||||
#include <bluetooth/HCI/btHCI_command.h>
|
||||
#include <bluetooth/bluetooth_util.h>
|
||||
|
||||
#include "LocalDeviceImpl.h"
|
||||
#include "BluetoothServer.h"
|
||||
#include "DeskbarReplicant.h"
|
||||
#include "LocalDeviceImpl.h"
|
||||
#include "Output.h"
|
||||
|
||||
|
||||
@@ -60,15 +62,11 @@ BluetoothServer::BluetoothServer() : BApplication(BLUETOOTH_SIGNATURE)
|
||||
Output::Instance()->AddTab("Device Manager", BLACKBOARD_DEVICEMANAGER);
|
||||
Output::Instance()->AddTab("Kit", BLACKBOARD_KIT);
|
||||
|
||||
ShowWindow(Output::Instance());
|
||||
|
||||
fDeviceManager = new DeviceManager();
|
||||
fLocalDevicesList.MakeEmpty();
|
||||
|
||||
fEventListener2 = new BluetoothPortListener(BT_USERLAND_PORT_NAME,
|
||||
(BluetoothPortListener::port_listener_func)&DispatchEvent);
|
||||
|
||||
|
||||
}
|
||||
|
||||
bool BluetoothServer::QuitRequested(void)
|
||||
@@ -82,6 +80,8 @@ bool BluetoothServer::QuitRequested(void)
|
||||
!= NULL)
|
||||
delete lDeviceImpl;
|
||||
|
||||
_RemoveDeskbarIcon();
|
||||
|
||||
printf("Accepting quitting of the application\n");
|
||||
return BApplication::QuitRequested();
|
||||
}
|
||||
@@ -109,6 +109,9 @@ void BluetoothServer::ReadyToRun(void)
|
||||
else
|
||||
Output::Instance()->Post("Bluetooth server Ready\n", BLACKBOARD_GENERAL);
|
||||
|
||||
ShowWindow(Output::Instance());
|
||||
|
||||
_InstallDeskbarIcon();
|
||||
}
|
||||
|
||||
|
||||
@@ -190,6 +193,10 @@ void BluetoothServer::MessageReceived(BMessage *message)
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
case BT_MSG_SERVER_SHOW_CONSOLE:
|
||||
ShowWindow(Output::Instance());
|
||||
break;
|
||||
|
||||
default:
|
||||
BApplication::MessageReceived(message);
|
||||
@@ -434,6 +441,35 @@ BluetoothServer::ShowWindow(BWindow* pWindow)
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
BluetoothServer::_InstallDeskbarIcon()
|
||||
{
|
||||
app_info appInfo;
|
||||
be_app->GetAppInfo(&appInfo);
|
||||
|
||||
BDeskbar deskbar;
|
||||
|
||||
if (deskbar.HasItem(kDeskbarItemName)) {
|
||||
_RemoveDeskbarIcon();
|
||||
}
|
||||
|
||||
status_t res = deskbar.AddItem(&appInfo.ref);
|
||||
if (res != B_OK) {
|
||||
printf("Failed adding deskbar icon: %ld\n", res);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
BluetoothServer::_RemoveDeskbarIcon()
|
||||
{
|
||||
BDeskbar deskbar;
|
||||
status_t res = deskbar.RemoveItem(kDeskbarItemName);
|
||||
if (res != B_OK) {
|
||||
printf("Failed removing Deskbar icon: %ld: \n", res);
|
||||
}
|
||||
}
|
||||
|
||||
#if 0
|
||||
#pragma mark -
|
||||
#endif
|
||||
|
||||
@@ -72,6 +72,9 @@ private:
|
||||
|
||||
void ShowWindow(BWindow* pWindow);
|
||||
|
||||
void _InstallDeskbarIcon();
|
||||
void _RemoveDeskbarIcon();
|
||||
|
||||
LocalDevicesList fLocalDevicesList;
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,272 @@
|
||||
/*
|
||||
* Copyright 2009, Haiku, Inc. All Rights Reserved.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*
|
||||
* Authors:
|
||||
* Michael Weirauch, [email protected]
|
||||
*/
|
||||
|
||||
|
||||
#include "DeskbarReplicant.h"
|
||||
|
||||
#include <Alert.h>
|
||||
#include <Application.h>
|
||||
#include <Bitmap.h>
|
||||
#include <Deskbar.h>
|
||||
#include <IconUtils.h>
|
||||
#include <MenuItem.h>
|
||||
#include <Message.h>
|
||||
#include <PopUpMenu.h>
|
||||
#include <Resources.h>
|
||||
#include <Roster.h>
|
||||
#include <String.h>
|
||||
|
||||
#include <bluetoothserver_p.h>
|
||||
|
||||
extern "C" _EXPORT BView *instantiate_deskbar_item(void);
|
||||
status_t our_image(image_info& image);
|
||||
|
||||
const uint32 kMsgShowBluetoothServerConsole = 'sbtc';
|
||||
const uint32 kMsgOpenBluetoothPreferences = 'obtp';
|
||||
const uint32 kMsgQuitBluetoothServer = 'qbts';
|
||||
|
||||
const char* kDeskbarItemName = "BluetoothServerReplicant";
|
||||
const char* kClassName = "DeskbarReplicant";
|
||||
|
||||
// #pragma mark -
|
||||
|
||||
|
||||
DeskbarReplicant::DeskbarReplicant(BRect frame, int32 resizingMode)
|
||||
: BView(frame, kDeskbarItemName, resizingMode,
|
||||
B_WILL_DRAW | B_FRAME_EVENTS)
|
||||
{
|
||||
_Init();
|
||||
}
|
||||
|
||||
|
||||
DeskbarReplicant::DeskbarReplicant(BMessage* archive)
|
||||
: BView(archive)
|
||||
{
|
||||
_Init();
|
||||
}
|
||||
|
||||
|
||||
DeskbarReplicant::~DeskbarReplicant()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
DeskbarReplicant::_Init()
|
||||
{
|
||||
fIcon = NULL;
|
||||
|
||||
image_info info;
|
||||
if (our_image(info) != B_OK)
|
||||
return;
|
||||
|
||||
BFile file(info.name, B_READ_ONLY);
|
||||
if (file.InitCheck() < B_OK)
|
||||
return;
|
||||
|
||||
BResources resources(&file);
|
||||
#ifdef HAIKU_TARGET_PLATFORM_HAIKU
|
||||
if (resources.InitCheck() < B_OK)
|
||||
return;
|
||||
#endif
|
||||
|
||||
size_t size;
|
||||
const void* data = resources.LoadResource(B_VECTOR_ICON_TYPE,
|
||||
"BEOS:ICON", &size);
|
||||
if (data != NULL) {
|
||||
BBitmap* icon = new BBitmap(Bounds(), B_RGBA32);
|
||||
if (icon->InitCheck() == B_OK
|
||||
&& BIconUtils::GetVectorIcon((const uint8 *)data,
|
||||
size, icon) == B_OK) {
|
||||
fIcon = icon;
|
||||
} else
|
||||
delete icon;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
DeskbarReplicant *
|
||||
DeskbarReplicant::Instantiate(BMessage* archive)
|
||||
{
|
||||
if (!validate_instantiation(archive, kClassName))
|
||||
return NULL;
|
||||
|
||||
return new DeskbarReplicant(archive);
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
DeskbarReplicant::Archive(BMessage* archive, bool deep) const
|
||||
{
|
||||
status_t status = BView::Archive(archive, deep);
|
||||
if (status == B_OK)
|
||||
status = archive->AddString("add_on", BLUETOOTH_SIGNATURE);
|
||||
if (status == B_OK)
|
||||
status = archive->AddString("class", kClassName);
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
DeskbarReplicant::AttachedToWindow()
|
||||
{
|
||||
BView::AttachedToWindow();
|
||||
if (Parent())
|
||||
SetViewColor(Parent()->ViewColor());
|
||||
else
|
||||
SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
|
||||
|
||||
SetLowColor(ViewColor());
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
DeskbarReplicant::Draw(BRect updateRect)
|
||||
{
|
||||
if (!fIcon) {
|
||||
/* At least display something... */
|
||||
rgb_color lowColor = LowColor();
|
||||
SetLowColor(0, 113, 187, 255);
|
||||
FillRoundRect(Bounds().InsetBySelf(3.f, 0.f), 5.f, 7.f, B_SOLID_LOW);
|
||||
SetLowColor(lowColor);
|
||||
} else {
|
||||
SetDrawingMode(B_OP_ALPHA);
|
||||
DrawBitmap(fIcon);
|
||||
SetDrawingMode(B_OP_COPY);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
DeskbarReplicant::MessageReceived(BMessage* msg)
|
||||
{
|
||||
switch (msg->what) {
|
||||
case kMsgShowBluetoothServerConsole:
|
||||
_ShowBluetoothServerConsole();
|
||||
break;
|
||||
|
||||
case kMsgOpenBluetoothPreferences:
|
||||
_OpenBluetoothPreferences();
|
||||
break;
|
||||
|
||||
case kMsgQuitBluetoothServer:
|
||||
_QuitBluetoothServer();
|
||||
break;
|
||||
|
||||
default:
|
||||
BView::MessageReceived(msg);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
DeskbarReplicant::MouseDown(BPoint where)
|
||||
{
|
||||
BPoint point;
|
||||
uint32 buttons;
|
||||
GetMouse(&point, &buttons);
|
||||
if (!(buttons & B_SECONDARY_MOUSE_BUTTON)) {
|
||||
return;
|
||||
}
|
||||
|
||||
BPopUpMenu* menu = new BPopUpMenu(B_EMPTY_STRING, false, false);
|
||||
|
||||
menu->AddItem(new BMenuItem("Open Preferences"B_UTF8_ELLIPSIS,
|
||||
new BMessage(kMsgOpenBluetoothPreferences)));
|
||||
|
||||
// TODO show list of known/paired devices
|
||||
|
||||
/* The code below is for development purposes only, but doesn't
|
||||
* hurt to be enabled as long as in alpha state.
|
||||
*/
|
||||
menu->AddSeparatorItem();
|
||||
|
||||
menu->AddItem(new BMenuItem("Show Server Console" B_UTF8_ELLIPSIS,
|
||||
new BMessage(kMsgShowBluetoothServerConsole)));
|
||||
|
||||
menu->AddItem(new BMenuItem("Stop Server",
|
||||
new BMessage(kMsgQuitBluetoothServer)));
|
||||
|
||||
menu->SetTargetForItems(this);
|
||||
ConvertToScreen(&point);
|
||||
menu->Go(point, true, true, true);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
DeskbarReplicant::_OpenBluetoothPreferences()
|
||||
{
|
||||
status_t status = be_roster->Launch(BLUETOOTH_APP_SIGNATURE);
|
||||
if (status < B_OK) {
|
||||
_ShowErrorAlert("Launching the Bluetooth preflet failed.", status);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
DeskbarReplicant::_ShowBluetoothServerConsole()
|
||||
{
|
||||
if (!be_roster->IsRunning(BLUETOOTH_SIGNATURE)) {
|
||||
return;
|
||||
}
|
||||
status_t status = BMessenger(BLUETOOTH_SIGNATURE).SendMessage(
|
||||
BT_MSG_SERVER_SHOW_CONSOLE);
|
||||
if (status < B_OK) {
|
||||
_ShowErrorAlert("Showing the Bluetooth Server Console failed.", status);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
DeskbarReplicant::_QuitBluetoothServer()
|
||||
{
|
||||
if (!be_roster->IsRunning(BLUETOOTH_SIGNATURE)) {
|
||||
return;
|
||||
}
|
||||
status_t status = BMessenger(BLUETOOTH_SIGNATURE).SendMessage(
|
||||
B_QUIT_REQUESTED);
|
||||
if (status < B_OK) {
|
||||
_ShowErrorAlert("Stopping the Bluetooth Server failed.", status);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
DeskbarReplicant::_ShowErrorAlert(BString msg, status_t status)
|
||||
{
|
||||
msg << "\n\nError: " << strerror(status);
|
||||
BAlert* alert = new BAlert("Bluetooth Error", msg.String(), "Ok");
|
||||
alert->Go(NULL);
|
||||
}
|
||||
|
||||
// #pragma mark -
|
||||
|
||||
|
||||
extern "C" _EXPORT BView *
|
||||
instantiate_deskbar_item(void)
|
||||
{
|
||||
return new DeskbarReplicant(BRect(0, 0, 15, 15),
|
||||
B_FOLLOW_LEFT | B_FOLLOW_TOP);
|
||||
}
|
||||
|
||||
// #pragma mark -
|
||||
|
||||
|
||||
status_t
|
||||
our_image(image_info& image)
|
||||
{
|
||||
int32 cookie = 0;
|
||||
while (get_next_image_info(B_CURRENT_TEAM, &cookie, &image) == B_OK) {
|
||||
if ((char *)our_image >= (char *)image.text
|
||||
&& (char *)our_image <= (char *)image.text + image.text_size)
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
return B_ERROR;
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* Copyright 2009, Haiku, Inc. All Rights Reserved.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*
|
||||
* Authors:
|
||||
* Michael Weirauch, [email protected]
|
||||
*/
|
||||
#ifndef DESKBAR_REPLICANT_H
|
||||
#define DESKBAR_REPLICANT_H
|
||||
|
||||
|
||||
#include <View.h>
|
||||
|
||||
|
||||
extern const char* kDeskbarItemName;
|
||||
|
||||
|
||||
class DeskbarReplicant : public BView {
|
||||
public:
|
||||
DeskbarReplicant(BRect frame, int32 resizingMode);
|
||||
DeskbarReplicant(BMessage* archive);
|
||||
virtual ~DeskbarReplicant();
|
||||
|
||||
static DeskbarReplicant* Instantiate(BMessage* archive);
|
||||
virtual status_t Archive(BMessage* archive, bool deep = true) const;
|
||||
|
||||
virtual void AttachedToWindow();
|
||||
|
||||
virtual void Draw(BRect updateRect);
|
||||
|
||||
virtual void MessageReceived(BMessage* message);
|
||||
virtual void MouseDown(BPoint where);
|
||||
|
||||
private:
|
||||
void _Init();
|
||||
void _OpenBluetoothPreferences();
|
||||
|
||||
void _ShowBluetoothServerConsole();
|
||||
void _QuitBluetoothServer();
|
||||
|
||||
void _ShowErrorAlert(BString msg, status_t status);
|
||||
|
||||
BBitmap* fIcon;
|
||||
};
|
||||
|
||||
#endif // DESKBAR_REPLICANT_H
|
||||
@@ -3,12 +3,14 @@ SubDir HAIKU_TOP src servers bluetooth ;
|
||||
SetSubDirSupportedPlatformsBeOSCompatible ;
|
||||
|
||||
UsePrivateHeaders shared bluetooth net kernel ;
|
||||
UseLibraryHeaders icon ;
|
||||
|
||||
AddResources bluetooth_server : server-bluetooth.rdef ;
|
||||
|
||||
Server bluetooth_server
|
||||
:
|
||||
BluetoothServer.cpp
|
||||
DeskbarReplicant.cpp
|
||||
DeviceManager.cpp
|
||||
HCIControllerAccessor.cpp
|
||||
HCITransportAccessor.cpp
|
||||
|
||||
Reference in New Issue
Block a user