From 9a134ab03890d942d53b4121e31e2d37859fa42c Mon Sep 17 00:00:00 2001 From: wimpie Date: Tue, 04 Jan 2005 01:44:52 +0000 Subject: New bluetooth library OT2 (loosely based on kbluetooth) --- diff --git a/noncore/settings/networksettings2/opietooth2/OTManageGUI.ui b/noncore/settings/networksettings2/opietooth2/OTManageGUI.ui new file mode 100644 index 0000000..6f4db07 --- a/dev/null +++ b/noncore/settings/networksettings2/opietooth2/OTManageGUI.ui @@ -0,0 +1,198 @@ + +OTManageGUI + + QWidget + + name + OTManageGUI + + + geometry + + 0 + 0 + 203 + 390 + + + + caption + Manage local devices + + + layoutMargin + + + layoutSpacing + + + + margin + 0 + + + spacing + 3 + + + QListView + + + text + Device + + + clickable + true + + + resizeable + true + + + + + text + New Column + + + clickable + true + + + resizeable + true + + + + name + AllDrivers_LV + + + allColumnsShowFocus + true + + + rootIsDecorated + true + + + + QLayoutWidget + + name + Layout11 + + + + margin + 0 + + + spacing + 6 + + + QCheckBox + + name + DriverIsUp_CB + + + sizePolicy + + 7 + 0 + + + + text + Is Up + + + + QLabel + + name + TextLabel3 + + + sizePolicy + + 1 + 1 + + + + text + Auto refresh + + + + QSpinBox + + name + RefreshTimer_SB + + + maximumSize + + 60 + 32767 + + + + margin + 0 + + + suffix + s + + + specialValueText + Default + + + buttonSymbols + PlusMinus + + + maxValue + 10 + + + + + + + + + DriverIsUp_CB + toggled(bool) + OTManageGUI + SLOT_UpDriver( bool) + + + RefreshTimer_SB + valueChanged(int) + OTManageGUI + SLOT_SetRefreshTimer( int ) + + + AllDrivers_LV + currentChanged(QListViewItem*) + OTManageGUI + SLOT_ShowDriver( QListViewItem *) + + + AllDrivers_LV + clicked(QListViewItem*) + OTManageGUI + SLOT_ShowDriver( QListViewItem *) + + SLOT_SetRefreshTimer( int ) + SLOT_ShowDriver( QListViewItem *) + SLOT_UpDriver( bool) + + diff --git a/noncore/settings/networksettings2/opietooth2/OTPairingGUI.ui b/noncore/settings/networksettings2/opietooth2/OTPairingGUI.ui new file mode 100644 index 0000000..2a010f0 --- a/dev/null +++ b/noncore/settings/networksettings2/opietooth2/OTPairingGUI.ui @@ -0,0 +1,158 @@ + +OTPairingGUI + + QWidget + + name + OTPairingGUI + + + geometry + + 0 + 0 + 285 + 230 + + + + caption + Manage pairing + + + layoutMargin + + + layoutSpacing + + + + margin + 3 + + + spacing + 3 + + + QListView + + + text + From + + + clickable + true + + + resizeable + true + + + + + text + To + + + clickable + true + + + resizeable + true + + + + name + Pairs_LV + + + allColumnsShowFocus + true + + + showSortIndicator + false + + + rootIsDecorated + true + + + + QLayoutWidget + + name + Layout5 + + + + margin + 0 + + + spacing + 6 + + + + name + Spacer1 + + + orientation + Horizontal + + + sizeType + Expanding + + + sizeHint + + 20 + 20 + + + + + QLabel + + name + Unpair_LBL + + + text + Disable Bluetooth to break pairings + + + + QPushButton + + name + Unpair_But + + + text + Break + + + + + + + + + Unpair_But + clicked() + OTPairingGUI + SLOT_Unpair() + + SLOT_SetRefreshTimer( int ) + SLOT_ShowDriver( QListViewItem *) + SLOT_UpDriver( bool) + SLOT_Unpair() + + diff --git a/noncore/settings/networksettings2/opietooth2/OTPeer.cpp b/noncore/settings/networksettings2/opietooth2/OTPeer.cpp new file mode 100644 index 0000000..0d7e943 --- a/dev/null +++ b/noncore/settings/networksettings2/opietooth2/OTPeer.cpp @@ -0,0 +1,366 @@ +//-*-c++-*- +/*************************************************************************** + * Copyright (C) 2003 by Fred Schaettgen * + * kdebluetooth@schaettgen.de * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + ***************************************************************************/ + +#include +#include +#include + +#include +#include +#include + +#include + +#include +#include +#include +#include +#include +#include + +using namespace Opietooth2; + +OTPeer::OTPeer( OTGateway * _OT ) { + OT = _OT; + State = Peer_Unknown; + ConnectedTo = 0; +} + +OTPeer::OTPeer( QTextStream & TS, OTGateway * _OT ) { + OT = _OT; + State = Peer_Unknown; + ConnectedTo = 0; + + load( TS ); +} + +OTPeer::~OTPeer( ) { + +} + +void OTPeer::updateServices( void ) { + sdp_session_t *session; + + serviceList.clear(); + + owarn << "Get services from " << Addr.toString() << oendl; + + session = sdp_connect( &(OTDeviceAddress::any.getBDAddr()), + &(Addr.getBDAddr()), + 0); + + if (!session) { + owarn << "sdp_connect(" + << Addr.toString() + << ") failed" + << oendl; + return; // error + } + + uint32_t range = 0x0000ffff; + sdp_list_t* attrId = sdp_list_append(0, &range); + + // search all public features + uuid_t grp; + sdp_uuid16_create( &grp, PUBLIC_BROWSE_GROUP ); + sdp_list_t * search = sdp_list_append(0, &grp ); + + // get data from peer + sdp_list_t* seq; + if (sdp_service_search_attr_req( session, + search, + SDP_ATTR_REQ_RANGE, + attrId, + &seq ) ) { + owarn << "Service Search failed" << oendl; + sdp_close(session); + return; + } + + sdp_list_free(attrId, 0); + sdp_list_free(search, 0); + + // process result + sdp_list_t* next = NULL; + + for (; seq; seq = next) { + sdp_record_t *rec = (sdp_record_t *) seq->data; + + sdp_list_t* attrlist = rec->attrlist; + AttributeVector alist; + OTSDPService * service; + + service = new OTSDPService(); + + for (; attrlist; attrlist = attrlist->next) { + int attrID = ((sdp_data_t*)(attrlist->data))->attrId; + service->addAttribute( + attrID, + new OTSDPAttribute( (sdp_data_t*)(attrlist->data) ) + ); + } + + serviceList.resize( serviceList.size() + 1 ); + serviceList.insert( serviceList.size() - 1, service ); + + next = seq->next; + free(seq); + sdp_record_free(rec); + } + sdp_close(session); +} + +bool OTPeer::hasServiceClassID( const OTUUID & uuid) { + for( unsigned int i = 0; + i < serviceList.count(); + i ++ ) { + if( serviceList[i]->hasClassID(uuid)) + return true; + } + return false; +} +/** Get a vector of Rfcomm channels of the services having "uuid" in the class ID List*/ +QArray OTPeer::rfcommList( const OTUUID & uuid) { + + QArray rfcommList; + unsigned int channel; + + for( unsigned int i = 0; + i < serviceList.count(); + i ++ ) { + if( serviceList[i]->hasClassID(uuid)) { + if( serviceList[i]->rfcommChannel(channel) ) { + rfcommList.resize( rfcommList.size()+1 ); + rfcommList[rfcommList.size()-1] = channel; + } + } + } + return rfcommList; +} + +void OTPeer::save( QTextStream & TS ) { + TS << "bdaddr " << address().toString() << endl; + TS << "name " << name() << endl; + TS << "class " << deviceClass() << endl; +} + +void OTPeer::load( QTextStream & TS ) { + QString S; + S = TS.readLine(); + setAddress( OTDeviceAddress( S.mid( 7 ) ) ); + + S = TS.readLine(); + setName( S.mid( 5 ) ); + + S = TS.readLine(); + setDeviceClass( S.mid( 6 ).toLong() ); +} + +#define MAGICNR -99999 +#define POLLDELAY 1000 +#define PREMAGICNR (MAGICNR+POLLDELAY) + +void OTPeer::findOutState( int timeoutInSec, bool Force ) { + ProbeFD = -1; + if( Force && ConnectedTo == 0 ) { + State = OTPeer::Peer_Unknown; + } // else keep state or is connected to us + + if( State == OTPeer::Peer_Unknown ) { + ProbePhase = 0; + ProbeTimeout = timeoutInSec*1000; + owarn << "Ping " << address().toString() << oendl; + startTimer( POLLDELAY ); + } else { + ProbeTimeout = 0; + startTimer( 0 ); + } +} + +#define PINGSIZE 20 +void OTPeer::timerEvent( QTimerEvent * ev ) { + + ProbeTimeout -= POLLDELAY; + + if( State == OTPeer::Peer_Unknown ) { + switch( ProbePhase ) { + case 0 : // connect nonblock + { struct sockaddr_l2 addr; + + if (( ProbeFD = ::socket(PF_BLUETOOTH, SOCK_RAW, BTPROTO_L2CAP)) < 0) { + ProbeTimeout = 0; + break; + } + + memset(&addr, 0, sizeof(addr)); + + addr.l2_family = AF_BLUETOOTH; + addr.l2_bdaddr = OTDeviceAddress::any.getBDAddr(); + + if( ::bind( ProbeFD, (struct sockaddr *) &addr, sizeof(addr)) < 0) { + ProbeTimeout = 0; + break; + } + + // non blocking + if( ::fcntl( ProbeFD, F_SETFL, O_NONBLOCK ) < 0 ) { + ProbeTimeout = 0; + break; + } + + // to this peer + addr.l2_bdaddr = address().getBDAddr(); + if( ::connect( ProbeFD, (struct sockaddr *) &addr, sizeof(addr)) < 0) { + if( errno != EAGAIN && errno != EINPROGRESS ) { + ProbeTimeout = 0; + break; + } // wait for connect to fail or succeed + } + } + ProbePhase = 1; // wait for connect + break; + case 1 : + { struct pollfd pf[1]; + char buf[L2CAP_CMD_HDR_SIZE + PINGSIZE + 20]; + int n; + + pf[0].fd = ProbeFD; + pf[0].events = POLLOUT; + if( (n = ::poll(pf, 1, 0)) < 0 ) { + owarn << address().toString() + << " : errno " + << errno + << " " + << strerror(errno)< try again + break; + } + + // send ping + for( unsigned int i = L2CAP_CMD_HDR_SIZE; i < sizeof(buf); i++) + buf[i] = (i % 40) + 'A'; + + l2cap_cmd_hdr *cmd = (l2cap_cmd_hdr *) buf; + + /* Build command header */ + cmd->code = L2CAP_ECHO_REQ; + cmd->ident = *(char *)this; // get some byte + cmd->len = PINGSIZE; + + /* Send Echo Request */ + if( ::send(ProbeFD, buf, PINGSIZE + L2CAP_CMD_HDR_SIZE, 0) <= 0) { + if( errno == EACCES ) { + // permission denied means that we could not + // connect because the device does not allow us + // but it is UP + owarn << address().toString() + << " good send error " + << errno + << " " + << strerror( errno) + << oendl; + State = OTPeer::Peer_Up; + ProbeTimeout = 0; + break; + } else if( errno != EBUSY ) { + owarn << address().toString() + << " : errno " + << errno + << " " + << strerror(errno) + << oendl; + ProbeTimeout = 0; + break; + } // else want some more + } + + ProbePhase = 2; // wait for ping reply + } + break; + case 2 : // wait for reply + { struct pollfd pf[1]; + char buf[L2CAP_CMD_HDR_SIZE + PINGSIZE + 20]; + l2cap_cmd_hdr *cmd = (l2cap_cmd_hdr *) buf; + int n; + + pf[0].fd = ProbeFD; + pf[0].events = POLLIN; + if( (n = ::poll(pf, 1, 0)) < 0 ) { + owarn << address().toString() + << " : errno " + << errno + << " " + << strerror(errno) + < try again + break; + } + + if( (n = ::recv( ProbeFD, buf, sizeof(buf), 0)) < 0) { + owarn << address().toString() + << "errno " + << errno + << " " + << strerror(errno) + << oendl; + ProbeTimeout = 0; + break; + } + + /* Check for our id */ + if( cmd->ident != *(char *)this ) + // not our reply + break; + + owarn << "reply from " + << address().toString() + << oendl; + // whatever reply we get is a valid reply + State = OTPeer::Peer_Up; + ProbeTimeout = 0; + } + break; + } + + if( State != OTPeer::Peer_Unknown ) { + ProbeTimeout = 0; + } + } + + if( ProbeTimeout <= 0 ) { + // regular timeout + emit peerStateReport( this ); + if( State == Peer_Unknown ) { + State = Peer_Down; + } + if( ProbeFD >= 0 ) { + // requested to stop by caller -> stop probing + ::close( ProbeFD ); + } + // no more waiting + killTimer( ev->timerId() ); + } // else sleep some more +} + +void OTPeer::stopFindingOutState( void ) { + ProbeTimeout = PREMAGICNR; +} + diff --git a/noncore/settings/networksettings2/opietooth2/OTPeer.h b/noncore/settings/networksettings2/opietooth2/OTPeer.h new file mode 100644 index 0000000..c09af15 --- a/dev/null +++ b/noncore/settings/networksettings2/opietooth2/OTPeer.h @@ -0,0 +1,135 @@ +//-*-c++-*- +/*************************************************************************** + * Copyright (C) 2003 by Fred Schaettgen * + * kdebluetooth@0xF.de * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + ***************************************************************************/ + +#ifndef OTPEER_H +#define OTPEER_H + +#include +#include +#include +#include +#include + +class QTextStream; +class QTimerEvent; + +namespace Opietooth2 { + +class OTGateway; + +class OTDriver; +class OTSDPService; +class OTSDPAttribute; +class OTUUID; +typedef QVector ServiceVector; + +class OTPeer : public QObject { + + Q_OBJECT; + +public : + + typedef enum PeerState_E { + Peer_Unknown = -1, + Peer_Down = 0, + Peer_Up = 1 + } PeerState_t; + + OTPeer( OTGateway * _OT ); + OTPeer( QTextStream & TS, OTGateway * _TS ); + ~OTPeer(); + + inline OTGateway * gateway() const + { return OT; } + + inline int deviceClass( void ) const + { return Class; } + inline void setDeviceClass( int cls ) + { Class = cls; } + + void setAddress( const OTDeviceAddress & A ) + { Addr = A; } + + const OTDeviceAddress & address( void ) + { return Addr; } + + inline QString name( void ) const + { return Name; } + inline void setName( const QString & n ) + { Name = n; } + + ServiceVector & services( bool Force = 0 ) + { if( Force || serviceList.count() == 0 ) { + updateServices(); + } + return serviceList; + } + + /* Returns TRUE if the device has at least a service + with inside the required class Id.*/ + bool hasServiceClassID( const OTUUID & uuid); + + /* Get a vector of Rfcomm channels of the services + having "uuid" in the class ID List */ + QArray rfcommList( const OTUUID & uuid ); + + inline void setState( PeerState_t S) + { State = S; } + inline PeerState_t state( void ) + { return State; } + + // go and find out state + // will report back with signal + void findOutState( int timeoutInSec = 1, bool Force = 0 ); + void stopFindingOutState( void ); + + // return driver to which this peer is connected to + // if it is connected + inline OTDriver * connectedTo( void ) const + { return ConnectedTo; } + inline void setConnectedTo( OTDriver * D ) + { ConnectedTo = D; } + + void save( QTextStream& TS ); + void load( QTextStream& TS ); + +signals : + + // report back state + void peerStateReport( OTPeer *); + void error( const QString & ); + +protected : + + // while polling for result of ping + void timerEvent( QTimerEvent * ev ); + +private: + + void updateServices(); + + OTGateway * OT; + OTDeviceAddress Addr; + QString Name; + int Class; + ServiceVector serviceList; + // -1 : don't know, 0 no, 1 yes + PeerState_t State; + OTDriver * ConnectedTo; + + int ProbeFD; + int ProbePhase; // see OTDriver + long ProbeTimeout; +}; + +} + +#endif diff --git a/noncore/settings/networksettings2/opietooth2/OTSDPAttribute.cpp b/noncore/settings/networksettings2/opietooth2/OTSDPAttribute.cpp new file mode 100644 index 0000000..9069c09 --- a/dev/null +++ b/noncore/settings/networksettings2/opietooth2/OTSDPAttribute.cpp @@ -0,0 +1,329 @@ +//-*-c++-*- +/*************************************************************************** + * Copyright (C) 2003 by Fred Schaettgen * + * kdebluetooth@schaettgen.de * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + ***************************************************************************/ + +#include +#include +#include + +#include +#include + +using namespace Opietooth2; + +OTSDPAttribute::OTSDPAttribute() { + type = INVALID; + memset( &Value, 0, sizeof( Value ) ); +} + +OTSDPAttribute::~OTSDPAttribute() { + if( type == INT ) { + delete Value.intVal; + } else if( type == UUID ) { + delete Value.uuidVal; + } else if( type == UINT ) { + delete Value.uintVal; + } else if( type == STRING || + type == URL + ) { + delete Value.stringVal; + } else if( type == ALTERNATIVE || + type == SEQUENCE + ) { + delete Value.sequenceVal; + } +} + +OTSDPAttribute::OTSDPAttribute( sdp_data_t * attrib ) { + setNil(); + switch( attrib->dtd ) { + case SDP_DATA_NIL: // Nil type + { setNil(); + break; + } + case SDP_UINT8: // Unsigned integer + setUInt(attrib->val.uint8); + break; + case SDP_UINT16: // Unsigned integer + setUInt(attrib->val.uint16); + break; + case SDP_UINT32: // Unsigned integer + setUInt(attrib->val.uint32); + break; + case SDP_UINT64: // Unsigned integer + setUInt(attrib->val.uint64); + break; + case SDP_UINT128: // Unsigned integer + // setUInt(attrib->val.uint16); + assert(false); // BUG/TODO: uint128 integers not supported + break; + case SDP_INT8: // Unsigned integer + setInt(attrib->val.int8); + break; + case SDP_INT16: // Unsigned integer + setInt(attrib->val.int16); + break; + case SDP_INT32: // Unsigned integer + setInt(attrib->val.int32); + break; + case SDP_INT64: // Unsigned integer + setInt(attrib->val.int64); + break; + case SDP_INT128: // Unsigned integer + // newAttr.setInt(attrib->val.uint16); + assert(false); // BUG/TODO: uint128 integers not supported + break; + case SDP_UUID16: + { OTUUID id; + ::uuid_t uuidVal = attrib->val.uuid; + id.setUUID32(uuidVal.value.uuid16); + setUUID(id ); + } + break; + case SDP_UUID32: + { OTUUID id; + ::uuid_t uuidVal = attrib->val.uuid; + id.setUUID32(uuidVal.value.uuid32); + setUUID(id ); + } + break; + case SDP_UUID128: + { OTUUID id; + ::uuid_t uuidVal = attrib->val.uuid; + uint64_t* v128; + v128 = reinterpret_cast(&(uuidVal.value.uuid128)); + id.setUUID128(v128[0], v128[1]); + setUUID(id ); + } + break; + case SDP_TEXT_STR_UNSPEC : + case SDP_TEXT_STR8 : + case SDP_TEXT_STR16 : + case SDP_TEXT_STR32 : + setString( QString(attrib->val.str) ); + break; + case SDP_URL_STR_UNSPEC : + case SDP_URL_STR8 : + case SDP_URL_STR16 : + case SDP_URL_STR32 : + setURL( QString(attrib->val.str) ); + break; + case SDP_BOOL: + setBool( attrib->val.int8 != 0); + break; + case SDP_SEQ_UNSPEC : + case SDP_SEQ8 : + case SDP_SEQ16 : + case SDP_SEQ32 : + case SDP_ALT_UNSPEC : + case SDP_ALT8 : + case SDP_ALT16 : + case SDP_ALT32 : + { AttributeVector subAttribs; + OTSDPAttribute * Attr; + sdp_data_t* subAttrib = attrib->val.dataseq; + + for (; subAttrib; subAttrib = subAttrib->next) { + + Attr = new OTSDPAttribute(subAttrib); + subAttribs.resize( subAttribs.size() + 1 ); + subAttribs.insert( subAttribs.size() - 1, Attr ); + } + + if( attrib->dtd == SDP_ALT_UNSPEC || + attrib->dtd == SDP_ALT8 || + attrib->dtd == SDP_ALT16 || + attrib->dtd == SDP_ALT32 ) { + setAlternative(subAttribs); + } else { + setSequence(subAttribs); + } + break; + } + } // end case +} + +QString OTSDPAttribute::toString( void ) { + QString S; + switch( type ) { + case INVALID : + S = "invalid"; + break; + case NIL : + S = "NIL"; + break; + case UINT : + S = Value.uintVal->toString(); + break; + case INT : + S = Value.intVal->toString(); + break; + case UUID : + S = Value.uuidVal->toString(); + break; + case BOOLEAN : + S = (Value.boolVal) ? "true" : "false"; + break; + case STRING : + S = *(Value.stringVal); + break; + case URL : + S = *(Value.stringVal); + break; + case SEQUENCE : + S.sprintf( "Sequence(%d)", Value.sequenceVal->count() ); + break; + case ALTERNATIVE : + S.sprintf( "Alternative(%d)", Value.sequenceVal->count() ); + break; + case UNKNOWN : + S = "unknown"; + break; + } + return S; +} + +void OTSDPAttribute::setNil() { + type = NIL; +} + +void OTSDPAttribute::setInt(const OTSDPAttribute::int128_t & val) { + type = INT; + Value.intVal = new int128_t( val ); +} + +void OTSDPAttribute::setUInt(const uint128_t & val) { + type = UINT; + Value.uintVal = new uint128_t(val); +} + +void OTSDPAttribute::setUUID(const OTUUID & val) { + type = UUID; + Value.uuidVal = new OTUUID( val ); +} + +void OTSDPAttribute::setBool(bool val) { + type = BOOLEAN; + Value.boolVal = val; +} + +void OTSDPAttribute::setString( const QString & val) { + type = STRING; + Value.stringVal = new QString( val ); +} + +void OTSDPAttribute::setURL( const QString & val) { + type = URL; + Value.stringVal = new QString(val); +} + +void OTSDPAttribute::setSequence(const AttributeVector& val) { + type = SEQUENCE; + Value.sequenceVal = new AttributeVector(); + Value.sequenceVal->setAutoDelete( TRUE ); + *Value.sequenceVal = val; +} + +void OTSDPAttribute::setAlternative(const AttributeVector& val) { + type = ALTERNATIVE; + Value.sequenceVal = new AttributeVector(); + Value.sequenceVal->setAutoDelete( TRUE ); + *Value.sequenceVal = val; +} + +QString OTSDPAttribute::getString() { + assert(type == STRING); + return *Value.stringVal; +} + +QString OTSDPAttribute::getURL() { + assert(type == URL); + return *Value.stringVal; +} + +const OTSDPAttribute::int128_t & OTSDPAttribute::getInt() { + assert(type == INT); + return *Value.intVal; +} + + +const OTSDPAttribute::uint128_t & OTSDPAttribute::getUInt() { + assert(type == UINT); + return *Value.uintVal; +} + +const OTUUID & OTSDPAttribute::getUUID() { + assert(type == UUID); + return *Value.uuidVal; +} + +bool OTSDPAttribute::getBool() { + assert(type == BOOLEAN); + return Value.boolVal; +} + +AttributeVector * OTSDPAttribute::getSequence() { + assert(type == SEQUENCE); + return Value.sequenceVal; +} + +AttributeVector * OTSDPAttribute::getAlternative() { + assert(type == ALTERNATIVE); + return Value.sequenceVal; +} + +UUIDVector OTSDPAttribute::getAllUUIDs() { + + UUIDVector uuids; + + if (getType() == UUID) { + uuids.resize( uuids.size()+1 ); + uuids[uuids.size()-1] = getUUID(); + } else { + AttributeVector * subAttributes = 0 ; + + if (getType() == SEQUENCE) { + subAttributes = getSequence(); + } else if (getType() == ALTERNATIVE) { + subAttributes = getAlternative(); + } + + int os; + for( unsigned int i = 0; i < subAttributes->count(); i++ ) { + UUIDVector subUUIDs = (*subAttributes)[i]->getAllUUIDs(); + + os = uuids.size(); + uuids.resize( uuids.size()+subUUIDs.count() ); + + for( unsigned int k = 0; k < subUUIDs.count(); k++ ) { + uuids[os + k] = subUUIDs[k]; + } + } + } + return uuids; +} + +static char * Attr2String[] = { + "Invalid", + "Nil", + "UInt", + "int", + "UUID", + "Boolean", + "String", + "Sequence", + "Alternative", + "URL", + "Unknown" +}; + +const char * OTSDPAttribute::getTypeString() { + return Attr2String[type]; +} diff --git a/noncore/settings/networksettings2/opietooth2/OTSDPAttribute.h b/noncore/settings/networksettings2/opietooth2/OTSDPAttribute.h new file mode 100644 index 0000000..e79e33d --- a/dev/null +++ b/noncore/settings/networksettings2/opietooth2/OTSDPAttribute.h @@ -0,0 +1,140 @@ +//-*-c++-*- +/*************************************************************************** + * Copyright (C) 2003 by Fred Schaettgen * + * kdebluetooth@schaettgen.de * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + ***************************************************************************/ + +#ifndef OTATTRIBUTE_H +#define OTATTRIBUTE_H + +#include +#include +#include +#include +#include +#include + +namespace Opietooth2 { + +class OTSDPAttribute; +class OTUUID; + +typedef QVector AttributeVector; + +/** +@author Fred Schaettgen +*/ +class OTSDPAttribute { + +public: + + enum AttrType { + INVALID = 0, + NIL = 1, + UINT = 2, + INT = 3, + UUID = 4, + BOOLEAN = 5, + STRING = 6, + SEQUENCE = 7, + ALTERNATIVE = 8, + URL = 9, + UNKNOWN = 10 + }; + + class int128_t { + public : + int128_t(int64_t l=0, int64_t h=0) { + hi = h; + lo = l; + } + int128_t(const OTSDPAttribute::int128_t & l) { + hi = l.hi; + lo = l.lo; + } + QString toString() const { + char Buf[50]; + sprintf( Buf, "%lld%lld", hi, lo ); + return QString( Buf ); + } + int64_t hi; + int64_t lo; + }; + + class uint128_t { + public : + uint128_t( uint64_t l=0, uint64_t h=0) { + hi = h; + lo = l; + } + uint128_t( const OTSDPAttribute::uint128_t & l) { + hi = l.hi; + lo = l.lo; + } + QString toString() const { + char Buf[50]; + sprintf( Buf, "%llu%llu", hi, lo ); + return QString( Buf ); + } + uint64_t hi; + uint64_t lo; + }; + +public: + + OTSDPAttribute(); + OTSDPAttribute( sdp_data_t * D ); + ~OTSDPAttribute(); + + QString toString( void ); + + void setNil(); + void setInt(const OTSDPAttribute::int128_t & val); + void setUInt(const OTSDPAttribute::uint128_t & val); + void setUUID( const OTUUID & val); + void setBool(bool val); + void setString(const QString & val); + void setURL(const QString & val); + void setSequence(const AttributeVector& val); + void setAlternative(const AttributeVector& val); + + QString getString(); + QString getURL(); + const OTSDPAttribute::int128_t & getInt(); + const OTSDPAttribute::uint128_t & getUInt(); + const OTUUID & getUUID(); + bool getBool(); + AttributeVector * getSequence(); + AttributeVector * getAlternative(); + + UUIDVector getAllUUIDs(); + + inline AttrType getType() + { return type; } + + //QString getValString(); + const char * getTypeString(); + +private: + + AttrType type; + + union { + OTSDPAttribute::int128_t * intVal; + OTSDPAttribute::uint128_t * uintVal; + OTUUID * uuidVal; + bool boolVal; + QString * stringVal; // strings and urls + AttributeVector * sequenceVal; // sequences and alternatives + } Value; + +}; + +} + +#endif diff --git a/noncore/settings/networksettings2/opietooth2/OTSDPService.cpp b/noncore/settings/networksettings2/opietooth2/OTSDPService.cpp new file mode 100644 index 0000000..07b505c --- a/dev/null +++ b/noncore/settings/networksettings2/opietooth2/OTSDPService.cpp @@ -0,0 +1,189 @@ +/*************************************************************************** + * Copyright (C) 2003 by Fred Schaettgen * + * kdebluetooth@schaettgen.de * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + ***************************************************************************/ + +#include + +#include +#include + +using namespace Opietooth2; + +OTSDPService::OTSDPService() : attributeList() { +} + +OTSDPService::~OTSDPService() { + for (unsigned int n=0; n < attributeList.count(); ++n) { + delete attributeList[n].attr; + } +} + +void OTSDPService::addAttribute(int id, OTSDPAttribute * attr) { + attributeList.resize( attributeList.size() + 1 ); + + attributeList[attributeList.size() - 1].id = id; + attributeList[attributeList.size() - 1].attr = attr; +} + +const OTSDPAttribute & OTSDPService::attribute(int index) { + return *(attributeList[index].attr); +} + +int OTSDPService::attributeID(int index) { + return attributeList[index].id; + +} + +OTSDPAttribute * OTSDPService::attributeByID(int id) { + + for (unsigned int n=0; n < attributeList.count(); ++n) { + if (attributeList[n].id == id) { + return attributeList[n].attr; + } + } + return 0; +} + +bool OTSDPService::recordHandle(uint32_t *handle) { + OTSDPAttribute * attrib; + attrib = attributeByID(0x00); + if( attrib && attrib->getType() == OTSDPAttribute::UINT) { + *handle = (uint32_t)attrib->getUInt().lo; + return true; + } + return false; +} + +QString OTSDPService::name(void) { + QString S; + OTSDPAttribute * attrib; + attrib = attributeByID(0x100); + if( attrib && attrib->getType() == OTSDPAttribute::STRING) { + S = attrib->getString(); + } + return S; +} + +QString OTSDPService::description() { + QString S; + OTSDPAttribute * attrib; + attrib = attributeByID(0x101); + if ( attrib && attrib->getType() == OTSDPAttribute::STRING) { + S = attrib->getString(); + } + return S; +} + +UUIDVector OTSDPService::allUUIDs() { + UUIDVector uuidList; + + for ( unsigned int i = 0; + i < attributeList.count(); + i ++ ) { + int os; + UUIDVector subList = attributeList[i].attr->getAllUUIDs(); + os = uuidList.size(); + uuidList.resize( uuidList.size()+subList.count() ); + + for( unsigned int k = 0; k < subList.count(); k++ ) { + uuidList[os + k] = subList[k]; + } + } + return uuidList; +} + +bool OTSDPService::rfcommChannel(unsigned int &n) { + // Get the rfcomm channel + OTSDPAttribute * protoDescAttr; + // Get the the protocol descriptor list attribute (0x04) + protoDescAttr = attributeByID(0x04); + if( ! protoDescAttr ) { + return false; + } + + AttributeVector & protoDescList = *(protoDescAttr->getSequence()); + + for( unsigned int i = 0; + i < protoDescList.count(); + i ++ ) { + AttributeVector & attrList = *(protoDescList[i]->getSequence()); + + //The List must have at least 2 Attributes + //Example: + // UUID16 : 0x0003 - RFCOMM + // Channel/Port (Integer) : 0x6 + if(attrList.size() >= 2) { + // The first Attribute of the list must be an UUID + if( attrList[0]->getType() != OTSDPAttribute::UUID) + continue; + // The UUID must have the value of "0x0003" that's the RFCOMM UUID + OTUUID rfcommUUID( "0x0003" ); + if( attrList[0]->getUUID() != rfcommUUID) //RFCOMM UUID + continue; + //If the UUID is ok we get the rfcomm channel number + if( attrList[1]->getType() != OTSDPAttribute::UINT) + continue; + + n = attrList[1]->getUInt().lo; + + return true; + } + } + // If we're here, we haven't found a correct Rfcomm channel, so we return false + return false; +} + +bool OTSDPService::hasClassID(const OTUUID & uuid) { + OTSDPAttribute * ClassIDAttr; + + // Get the the ClassID descriptor list attribute (0x01) + ClassIDAttr = attributeByID( 0x01); + if( ! ClassIDAttr ) { + return false; + } + + AttributeVector & ClassIDList = *(ClassIDAttr->getSequence()); + for( unsigned int i = 0 ; + i < ClassIDList.count() ; + i ++ ) { + if( ClassIDList[i]->getType() != OTSDPAttribute::UUID) + continue; + if( ClassIDList[i]->getUUID() == uuid) + return true; + } + return false; +} + +/** Get a vector of UUID of the services class Id List */ +UUIDVector OTSDPService::classIDList( void ) { + + UUIDVector uuidList; + OTSDPAttribute * ClassIDAttr; + + // Get the the ClassID descriptor list attribute (0x01) + ClassIDAttr = attributeByID( 0x01); + if( ! ClassIDAttr ) { + return uuidList; + } + + AttributeVector & ClassIDList = *(ClassIDAttr->getSequence()); + + for( unsigned int i = 0 ; + i < ClassIDList.count() ; + i ++ ) { + if( ClassIDList[i]->getType() != OTSDPAttribute::UUID) + continue; + + uuidList.resize( uuidList.size() + 1 ); + uuidList[ uuidList.size() - 1 ] = ClassIDList[i]->getUUID(); + } + + return uuidList; +} + diff --git a/noncore/settings/networksettings2/opietooth2/OTSDPService.h b/noncore/settings/networksettings2/opietooth2/OTSDPService.h new file mode 100644 index 0000000..4831df0 --- a/dev/null +++ b/noncore/settings/networksettings2/opietooth2/OTSDPService.h @@ -0,0 +1,75 @@ +//-*-c++-*- +/*************************************************************************** + * Copyright (C) 2003 by Fred Schaettgen * + * kdebluetooth@schaettgen.de * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + ***************************************************************************/ + +#ifndef SDPSERVICE_H +#define SDPSERVICE_H + +#include +#include +#include + +namespace Opietooth2 { + +/** +@author Fred Schaettgen +*/ +class OTSDPService { + +public: + + OTSDPService(); + virtual ~OTSDPService(); + + void addAttribute(int id, OTSDPAttribute * attr); + + const OTSDPAttribute & attribute( int index ); + int attributeID( int index ); + + AttributeVector subAttributes( OTSDPAttribute * attr); + OTSDPAttribute * attributeByID( int id ); + + // See Bluetooth Core Spec Sec. 5.1 + bool recordHandle(uint32_t *handle); // 0x00 + + //bool getServiceClassIDList(vector *classIDList); // 0x01 + //bool getServiceRecordState(uint32_t *state); // 0x02 + //bool getServiceID(uuid_t *id); // 0x03; + //bool getProtocolDescriptorList(SDP::Attribute *attribute); // 0x04 + //bool getBrowseGroupList(vector *browseGroupList); // 0x05 + QString name(void); // langBase + 0x00 + QString description(void); // langBase + 0x01 + + UUIDVector allUUIDs(); + + // return list of classes this service belongs to + UUIDVector classIDList(); + + /** Retrieves the Rfcomm channel. + This function is provided just for conveniance. + @param n The Rfcomm channel. + @ret true if an rfcomm channel was found, false otherwise. */ + bool rfcommChannel(unsigned int &n); + + bool hasClassID(const OTUUID & uuid); + +private: + + struct AttributeEntry { + int id; + OTSDPAttribute * attr; + }; + + QArray attributeList; +}; + +} + +#endif diff --git a/noncore/settings/networksettings2/opietooth2/OTScanGUI.ui b/noncore/settings/networksettings2/opietooth2/OTScanGUI.ui new file mode 100644 index 0000000..66c19e6 --- a/dev/null +++ b/noncore/settings/networksettings2/opietooth2/OTScanGUI.ui @@ -0,0 +1,387 @@ + +OTScanGUI + + QWidget + + name + Form3 + + + geometry + + 0 + 0 + 333 + 580 + + + + caption + Scanning + + + layoutMargin + + + layoutSpacing + + + + margin + 0 + + + spacing + 3 + + + QListView + + + text + Attribute + + + clickable + true + + + resizeable + true + + + + + text + Value + + + clickable + true + + + resizeable + true + + + + name + DetectedPeers_LV + + + sizePolicy + + 7 + 7 + + + + allColumnsShowFocus + true + + + rootIsDecorated + true + + + + QLayoutWidget + + name + Layout16 + + + layoutSpacing + + + + margin + 0 + + + spacing + 3 + + + QPushButton + + name + Cleanup_But + + + text + Cleanup + + + + + name + Spacer1 + + + orientation + Horizontal + + + sizeType + Expanding + + + sizeHint + + 20 + 20 + + + + + QPushButton + + name + Detect_But + + + sizePolicy + + 1 + 0 + + + + text + Scan + + + toggleButton + true + + + autoResize + true + + + toggleButton + true + + + + + + QGroupBox + + name + Peer_GB + + + title + GroupBox1 + + + layoutMargin + + + layoutSpacing + + + + margin + 3 + + + spacing + 3 + + + QLayoutWidget + + name + Layout4 + + + + margin + 0 + + + spacing + 6 + + + QFrame + + name + State_Frm + + + sizePolicy + + 7 + 5 + + + + frameShape + NoFrame + + + frameShadow + Raised + + + + QPushButton + + name + RefreshServices_But + + + text + Services + + + + QPushButton + + name + RefreshState_But + + + text + State + + + + + + QLabel + + name + Address_LBL + + + sizePolicy + + 7 + 0 + + + + frameShape + Panel + + + frameShadow + Plain + + + lineWidth + 1 + + + text + + + + indent + 1 + + + + QLabel + + name + TextLabel1 + + + sizePolicy + + 1 + 1 + + + + text + Address + + + + QLabel + + name + TextLabel2 + + + text + Signal strength + + + + QProgressBar + + name + Strength_PB + + + centerIndicator + true + + + indicatorFollowsStyle + false + + + + + + + + + RefreshServices_But + clicked() + Form3 + SLOT_RefreshServices() + + + Detect_But + toggled(bool) + Form3 + SLOT_DoScan( bool ) + + + Cleanup_But + clicked() + Form3 + SLOT_CleanupOld() + + + RefreshState_But + clicked() + Form3 + SLOT_RefreshState() + + + DetectedPeers_LV + clicked(QListViewItem*) + Form3 + SLOT_Show(QListViewItem *) + + + DetectedPeers_LV + currentChanged(QListViewItem*) + Form3 + SLOT_Show(QListViewItem *) + + + DetectedPeers_LV + doubleClicked(QListViewItem*) + Form3 + SLOT_Selected(QListViewItem*) + + SLOT_CleanupOld() + SLOT_DoScan( bool ) + SLOT_RefreshServices() + SLOT_RefreshState() + SLOT_Selected(QListViewItem*) + SLOT_Show(QListViewItem *) + + diff --git a/noncore/settings/networksettings2/opietooth2/OTUUID.cpp b/noncore/settings/networksettings2/opietooth2/OTUUID.cpp new file mode 100644 index 0000000..4b05a7a --- a/dev/null +++ b/noncore/settings/networksettings2/opietooth2/OTUUID.cpp @@ -0,0 +1,162 @@ +//-*-c++-*- +/*************************************************************************** + * Copyright (C) 2003 by Fred Schaettgen * + * kdebluetooth@schaettgen.de * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + ***************************************************************************/ + +#include +#include +#include + +#include + +using namespace Opietooth2; + +OTUUID::OTUUID(QString s) { + fromString(s); +} + +OTUUID::OTUUID(uint64_t l, uint64_t h) { + this->hi = h; + this->lo = l; +} + +OTUUID::OTUUID( const OTUUID & O ) { + this->hi = O.hi; + this->lo = O.lo; +} + +OTUUID & OTUUID::operator =( const OTUUID & O ) { + hi = O.hi; + lo = O.lo; + return *this; +} + +bool OTUUID::fromString(QString s) { + + // Strip leading "0x" + if (s.startsWith("0x")) + { + s = s.right(s.length()-2); + } + // Remove separators + s.replace( QRegExp(":"), "" ); + + bool bOk = false; + if( s.length() == 4 || s.length() == 8) { + + uint32_t u32 = s.toUInt(&bOk, 16); + setUUID32(u32); + return bOk; + + } else if (s.length() == 32) { + +#if (QT_VERSION >= 0x030200) + uint64_t u64hi = s.left(16).toULongLong(&bOk, 16); +#else + uint64_t u64hi = s.left(16).toULong(&bOk, 16); +#endif + if (!bOk) + return false; + +#if (QT_VERSION >= 0x030200) + uint64_t u64lo = s.right(16).toULongLong(&bOk, 16); +#else + uint64_t u64lo = s.right(16).toULong(&bOk, 16); +#endif + if (!bOk) + return false; + hi = u64hi; + lo = u64lo; + return true; + + } else { + hi = 0; + lo = 0; + return true; + } +} + +void OTUUID::setUUID32(uint32_t v) { + + hi = uint64_t(0x1000) | (uint64_t(v) << 32); + // see BT 1.1 Core spec p2.7.1 + lo = (uint64_t(0x80000080) << 32) | uint64_t(0x5F9B34FB); + +} + +void OTUUID::setUUID128(uint64_t _hi, uint64_t _lo) { + hi = _hi; + lo = _lo; +} + +QString OTUUID::toString() const { + QString ret; + uint32_t v1 = uint32_t(hi >> 32); + uint32_t v2 = uint32_t(hi & 0xFFFFFFFF); + uint32_t v3 = uint32_t(lo >> 32); + uint32_t v4 = uint32_t(lo & 0xFFFFFFFF); + ret.sprintf("0x%08lx:%08lx:%08lx:%08lx", + (unsigned long)v1, (unsigned long)v2, + (unsigned long)v3, (unsigned long)v4); + + return ret; +} + +OTUUID::operator QString() const { + return toString(); +} + +OTUUID::operator ::uuid_t() const { + + //kdDebug() << "uuid_t() -> " << QString(*this) << endl; + ::uuid_t ret; + if ((lo == (uint64_t(0x80000080) << 32) | uint64_t(0x5F9B34FB)) && + ((hi&0xFFFFFFFF) == 0x1000)) { + uint32_t uuid32val = uint32_t(hi >> 32); + if (uuid32val > 0xFFFF) { + ret.type = SDP_UUID16; + ret.value.uuid16 = uint16_t(uuid32val); + } else { + ret.type = SDP_UUID32; + ret.value.uuid32 = uuid32val; + } + } else { + ret.value.uuid128.data[0] = (lo >> 0) && 0xFF; + ret.value.uuid128.data[1] = (lo >> 8) && 0xFF; + ret.value.uuid128.data[2] = (lo >> 16) && 0xFF; + ret.value.uuid128.data[3] = (lo >> 24) && 0xFF; + ret.value.uuid128.data[4] = (lo >> 32) && 0xFF; + ret.value.uuid128.data[5] = (lo >> 40) && 0xFF; + ret.value.uuid128.data[6] = (lo >> 48) && 0xFF; + ret.value.uuid128.data[7] = (lo >> 56) && 0xFF; + + ret.value.uuid128.data[8] = (hi >> 0) && 0xFF; + ret.value.uuid128.data[9] = (hi >> 8) && 0xFF; + ret.value.uuid128.data[10] = (hi >> 16) && 0xFF; + ret.value.uuid128.data[11] = (hi >> 24) && 0xFF; + ret.value.uuid128.data[12] = (hi >> 32) && 0xFF; + ret.value.uuid128.data[13] = (hi >> 40) && 0xFF; + ret.value.uuid128.data[14] = (hi >> 48) && 0xFF; + ret.value.uuid128.data[15] = (hi >> 56) && 0xFF; + + ret.type = SDP_UUID128; + } + return ret; +} + +bool OTUUID::operator<(const OTUUID & other) const { + if (hi != other.hi) + return hi < other.hi; + + return lo +#include +#include + +namespace Opietooth2 { + +class OTUUID; + +typedef QArray UUIDVector; + +class OTUUID { + +public : + + OTUUID( QString s ); + OTUUID( uint64_t l=0, uint64_t h=0); + OTUUID( const OTUUID & O ); + + bool fromString(QString s); + + void setUUID128(uint64_t hi, uint64_t lo); + + void setUUID32(uint32_t v); + + uint16_t toShort() + { return ((hi>>32) & 0xffff); } + uint32_t toLong() + { return ((hi>>32) & 0xffffffff); } + uint64_t toLongLong() + { return hi; } + + QString toString() const ; + operator QString() const; + operator ::uuid_t() const; + + OTUUID & operator=( const OTUUID & other ) ; + bool operator<( const OTUUID & other ) const; + bool operator==(const OTUUID & uuid) const; + + uint64_t hi; + uint64_t lo; +}; +} +#endif diff --git a/noncore/settings/networksettings2/opietooth2/Opietooth.cpp b/noncore/settings/networksettings2/opietooth2/Opietooth.cpp new file mode 100644 index 0000000..8d71f32 --- a/dev/null +++ b/noncore/settings/networksettings2/opietooth2/Opietooth.cpp @@ -0,0 +1,1003 @@ +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +using namespace Opietooth2; + +namespace Opietooth2 { + +class PeerLVI : public QListViewItem { + +public : + + PeerLVI( OTPeer * P, QListView * it ) : QListViewItem (it) { + Peer = P; + } + ~PeerLVI( void ) { + } + + inline OTPeer * peer( void ) + { return Peer; } + +private : + + OTPeer * Peer; +}; + +class ChannelLVI : public QListViewItem { + +public : + + ChannelLVI( int Ch, QListViewItem * it ) : QListViewItem (it) { + Channel = Ch; + } + ~ChannelLVI( void ) { + } + + inline int channel( void ) + { return Channel; } + +private : + + int Channel; +}; + +class DriverLVI : public QListViewItem { + +public : + + DriverLVI( OTDriver * P, QListView * it ) : QListViewItem (it) { + Driver = P; + } + ~DriverLVI( void ) { + } + + inline OTDriver * driver( void ) + { return Driver; } + +private : + + OTDriver * Driver; +}; + +class LinkKeyLVI : public QListViewItem { + +public : + + LinkKeyLVI( int Ch, QListView * it ) : QListViewItem (it) { + LinkKey = Ch; + } + ~LinkKeyLVI( void ) { + } + + inline int index( void ) + { return LinkKey; } + +private : + + int LinkKey; +}; +}; + +// +// +// +// +// + +OTPairing::OTPairing( QWidget * parent, OTIcons * _IC ) : + OTPairingGUI( parent ) { + + OT = OTGateway::getOTGateway(); + Icons = (_IC ) ? _IC : new OTIcons(); + MyIcons = (_IC == 0 ); + + // unpairing can only be done if bluetooth is disabled + Unpair_But->setEnabled( ! OT->isEnabled() ); + if( ! OT->isEnabled() ) { + Unpair_LBL->hide(); + } else { + Unpair_LBL->show(); + } + + // open linkkey file and load pairs + LinkKeyArray Keys = OT->getLinkKeys(); + LinkKeyLVI * it; + OTPeer * P; + OTDriver * D; + + for( unsigned int i = 0 ; + i < Keys.count(); + i ++ ) { + + it = new LinkKeyLVI( i, Pairs_LV ); + + P = 0; + D = OT->findDriver( Keys[i].from() ); + + if( D ) { + it->setText( 0, D->devname() ); + + // we are source + P = OT->findPeer( Keys[i].to() ); + + if( P ) { + // put name + it->setText( 1, P->name() ); + } else { + // unknown + it->setText( 1, Keys[i].to().toString() ); + } + + // and put address as sub + QListViewItem * Sub = new QListViewItem( it ); + Sub->setText( 0, D->address().toString() ); + Sub->setText( 1, Keys[i].to().toString() ); + } else { + // perhaps we are destination + D = OT->findDriver( Keys[i].to() ); + + if( D ) { + it->setText( 1, D->devname() ); + + // we are source + P = OT->findPeer( Keys[i].from() ); + + if( P ) { + // put name + it->setText( 0, P->name() ); + } else { + // unknown + it->setText( 0, Keys[i].from().toString() ); + } + + // and put address as sub + QListViewItem * Sub = new QListViewItem( it ); + Sub->setText( 0, Keys[i].from().toString() ); + Sub->setText( 1, D->address().toString() ); + } else { + // nor source nor destination -> unknown + it->setText( 0, Keys[i].from().toString() ); + it->setText( 1, Keys[i].to().toString() ); + } + } + } +} + + +OTPairing::~OTPairing() { + if( MyIcons ) + delete Icons; + OTGateway::releaseOTGateway(); +} + +void OTPairing::SLOT_Unpair( ) { + // find selected pair + + QListViewItem * it = Pairs_LV->firstChild(); + while( it ) { + if( it->isSelected() ) { + // confirm ? + if( QMessageBox::warning(0, + tr("Break pairing"), + tr("Sure ?"), + tr("Yes, break"), + tr("No, don't break") ) == 0 ) { + LinkKeyLVI * KPIt = (LinkKeyLVI *)it; + // break + OT->removeLinkKey( KPIt->index() ); + delete KPIt; + } + return; + } + it= it->nextSibling(); + } +} + +// +// +// +// +// + +OTScan::OTScan( QWidget * parent, OTIcons * _IC ) : + OTScanGUI( parent ), Filter() { + + OT = OTGateway::getOTGateway(); + Icons = (_IC ) ? _IC : new OTIcons(); + MyIcons = (_IC == 0 ); + DetectedPeers_LV->header()->hide(); + Current = 0; + SelectedPeer = 0; + SelectedChannel = 0; + + StrengthTimer = new QTimer( this ); + connect( StrengthTimer, + SIGNAL( timeout()), + this, + SLOT( SLOT_UpdateStrength()) + ); + + connect( OT, + SIGNAL( detectedPeer( OTPeer *, bool )), + this, + SLOT( SLOT_NewPeer( OTPeer *, bool )) + ); + connect( OT, + SIGNAL( finishedDetecting()), + this, + SLOT( SLOT_FinishedDetecting()) + ); + + // populate with peers we already know about + const PeerVector & P = OT->peers(); + for( unsigned int i = 0; + i < P.count(); + i ++ ) { + SLOT_NewPeer( P[i], TRUE ); + } + + // populate State fram + { QHBoxLayout * H =new QHBoxLayout( State_Frm ); + + Paired_Led = new OLedBox( green, State_Frm ); + QLabel * L1 = new QLabel( tr( "Paired" ), State_Frm ); + + H->addWidget( Paired_Led ); + H->addWidget( L1 ); + H->addStretch( 1 ); + } +} + +OTScan::~OTScan() { + if( MyIcons ) + delete Icons; + OTGateway::releaseOTGateway(); + + // send all peers that we do not care about states + QListViewItem * Lit = DetectedPeers_LV->firstChild(); + while( Lit ) { + ((PeerLVI *)Lit)->peer()->stopFindingOutState( ); + Lit = Lit->nextSibling(); + } +} + +// static scan dialog function +int OTScan::getDevice( OTPeer *& Peer, + int & Channel, + OTGateway * OT, + const UUIDVector & Filter, + QWidget* Parent ) { + bool IsUp = 0; + unsigned int i; + + // check if bluetooth is up + OTDriverList & DL = OT->getDriverList(); + for( i = 0; + i < DL.count(); + i ++ ) { + if( DL[i]->isUp() ) { + // one device that is up found + IsUp = 1; + break; + } + } + + // use this driver + OT->setScanWith( OT->driver(i) ); + + // create dialog + QDialog * Dlg = new QDialog( Parent, 0, TRUE ); + QVBoxLayout * V = new QVBoxLayout( Dlg ); + OTScan * Scn = new OTScan( Dlg ); + + connect( Scn, + SIGNAL( selected() ), + Dlg, + SLOT( accept() ) + ); + + if( Filter ) { + Scn->setScanFilter( Filter ); + } + + V->addWidget( Scn ); + Dlg->setCaption( tr("Scan Neighbourhood" ) ); + Dlg->showMaximized(); + int rv = Dlg->exec(); + + if( rv == QDialog::Accepted ) { + // get peer + Peer = Scn->selectedPeer(); + if( Peer == 0 ) { + // no peer selected + rv = QDialog::Rejected; + } else { + Channel = Scn->selectedChannel(); + } + } + + delete Dlg; + + return rv; +} + +void OTScan::setScanFilter( const UUIDVector & V ) { + Filter = V; +} + +void OTScan::resetScanFilter( void ) { + Filter.truncate(0); +} + +void OTScan::SLOT_DoScan( bool DoIt ) { + if( DoIt ) { + OT->scanNeighbourhood(); + } else { + OT->stopScanOfNeighbourhood(); + } + + scanMode( DoIt ); +} + +// double clicked on a device +void OTScan::SLOT_Selected( QListViewItem * it ) { + if( ! it ) + return; + + if( Filter.count() > 0 ) { + // filter on service + if( it->depth() == 0 ) { + // select a service and not a device + return; + } + + // store result + SelectedPeer = ((PeerLVI *)it->parent())->peer(); + SelectedChannel = ((ChannelLVI *)it)->channel(); + } else { + // click on device + if( it->depth() != 0 ) { + return; + } + + SelectedPeer = ((PeerLVI *)it)->peer(); + SelectedChannel = 0; + } + owarn << "Selected " << SelectedPeer->address().toString() << + " Channel " << SelectedChannel << oendl; + emit selected(); +} + +void OTScan::SLOT_FinishedDetecting( ) { + scanMode( false ); +} + +void OTScan::SLOT_CleanupOld( ) { + + // iterate over all peers and find those that + // are down and have no pairing info + OTPeer * TheP; + const LinkKeyArray & Keys = OT->getLinkKeys(); + + QListViewItem * Lit = DetectedPeers_LV->firstChild(); + while( Lit ) { + TheP = ((PeerLVI *)Lit)->peer(); + if( TheP->state() == OTPeer::Peer_Down ) { + unsigned int k; + + // what about linkkeys ? + for( k = 0; k < Keys.count(); k ++ ) { + if( TheP->address() == Keys[k].to() || + TheP->address() == Keys[k].from() + ) { + // part of linkkey + owarn << "LINKKEY " << TheP->address().toString() << oendl; + break; + } + } + + if( k == Keys.count() ) { + owarn << "RM LINKKEY " << TheP->address().toString() << oendl; + // not found -> remember to remove this peer + QListViewItem * Nit; + OT->removePeer( TheP ); + Nit = Lit->nextSibling(); + delete Lit; + Lit = Nit; + continue; + } + } else { + owarn << "NODOWN " << TheP->address().toString() << oendl; + } + + Lit = Lit->nextSibling(); + } +} + +void OTScan::SLOT_NewPeer( OTPeer * P, bool IsNew ){ + PeerLVI * it = 0; + + if( IsNew ) { + it = new PeerLVI( P, DetectedPeers_LV ); + } else { + // find peer in table + QListViewItem * Lit = DetectedPeers_LV->firstChild(); + while( Lit ) { + if( ((PeerLVI *)Lit)->peer() == P ) { + // this item + it = (PeerLVI *)Lit; + break; + } + Lit = Lit->nextSibling(); + } + + if( ! it ) { + owarn << "Should not occur" << oendl; + return; + } + } + + // update/show info + it->setText( 0, P->name() ); + it->setPixmap(0, Icons->deviceIcon( + OT->deviceTypeToName( P->deviceClass() ) ) ); + + // tell peer to report its state async + connect( P, + SIGNAL( peerStateReport( OTPeer *)), + this, + SLOT( SLOT_PeerState( OTPeer *)) + ); + + if( IsNew ) { + // find state + refreshState( (PeerLVI *)it, 1 ); + } else { + // update staet + SLOT_PeerState( P ); + } +} + +void OTScan::SLOT_PeerState( OTPeer * P ) { + PeerLVI * it = (PeerLVI *)DetectedPeers_LV->firstChild(); + while( it ) { + if( it->peer() == P ) { + break; + } + it = (PeerLVI * )it->nextSibling(); + } + + if( ! it ) + return; + + switch( P->state() ) { + case OTPeer::Peer_Unknown : + case OTPeer::Peer_Down : + it->setPixmap( 1, 0 ); + break; + case OTPeer::Peer_Up : + it->setPixmap( 1, Icons->loadPixmap( + ( P->connectedTo() ) ? "connected" : "notconnected" ) ); + if( it == Current && ! StrengthTimer->isActive() ) { + // start showing strength + StrengthTimer->start( 1000, FALSE ); + SLOT_UpdateStrength(); + } + break; + } +} + +void OTScan::SLOT_RefreshState( void ) { + + QListViewItem * it = DetectedPeers_LV->firstChild(); + while( it ) { + if( it->isSelected() ) { + break; + } + it = it->nextSibling(); + } + + if( ! it ) + return; + + refreshState( (PeerLVI *)it, 1 ); +} + +void OTScan::refreshState( PeerLVI * it, bool Force ) { + it->setPixmap( 1, Icons->loadPixmap( "find" ) ); + it->peer()->findOutState( 30, Force ); +} + +void OTScan::SLOT_Show( QListViewItem * it ) { + + if( ! it || it->depth() > 0 ) + return; + + QString S; + + Current = (PeerLVI *)it; + + Strength_PB->setProgress( 0 ); // reset + Address_LBL->setText( Current->peer()->address().toString() ); + Peer_GB->setTitle( Current->peer()->name() ); + + const LinkKeyArray & Keys = OT->getLinkKeys(); + + Paired_Led->setOn( FALSE ); + for( unsigned int i = 0; + i < Keys.count(); + i ++ ) { + if( Current->peer()->address() == Keys[i].to() ) { + Paired_Led->setOn( TRUE ); + break; + } + } + + if( Current->peer()->state() == OTPeer::Peer_Up ) { + RefreshServices_But->setEnabled( TRUE ); + StrengthTimer->start( 1000, FALSE ); + SLOT_UpdateStrength(); + } else { + RefreshServices_But->setEnabled( FALSE ); + } + +} + +void OTScan::SLOT_UpdateStrength( void ) { + OTDriver * D = Current->peer()->connectedTo(); + + if( D ) { + long Q = D->getLinkQuality( Current->peer()->address() ); + Strength_PB->setProgress( Q ); + if( ! Q ) { + // no quality + Strength_PB->setEnabled( TRUE ); + StrengthTimer->stop(); + } + } else { + Strength_PB->setEnabled( FALSE ); + Strength_PB->setProgress( 0 ); + // no point in continuing + StrengthTimer->stop(); + } +} + +void OTScan::SLOT_RefreshServices( void ) { + + QListViewItem * it = DetectedPeers_LV->firstChild(); + while( it ) { + if( it->isSelected() ) { + break; + } + it = it->nextSibling(); + } + + if( ! it ) + return; + + QString S; + PeerLVI * PI = (PeerLVI *)it; + + scanMode( true ); + qApp->processEvents(0); + + ServiceVector & V = PI->peer()->services(); + + while( PI->firstChild() ) { + // remove children + delete PI->firstChild(); + } + + for( unsigned int i = 0 ; + i < V.count(); + i ++ ) { + QString S; + S = V[i]->name(); + + if( S.isEmpty() ) { + continue; + } + + { QListViewItem * SIt; + UUIDVector UIDV; + QPixmap Pm; + bool Done = 0; + bool R; + short ID; + + SIt = 0; + + UIDV = V[i]->classIDList(); + // first all UUID ! 1200 12ff (Genericprofiles) + for( unsigned int j = 0; + j < UIDV.count(); + j ++ ) { + + if( Filter.count() ) { + bool FilterOut = 1; + // filter out if not in list + for( unsigned int ff = 0; + ff < Filter.count(); + ff ++ ) { + if( UIDV[j] == Filter[ff] ) { + FilterOut = 0; + break; + } + } + + if( FilterOut ) { + // not in filter list + continue; + } + } // else show + + ID = UIDV[j].toShort(); + if( ID < 0x1200 || ID > 0x12ff ) { + // use this profile + if( R ) { + unsigned int ch; + bool has; + has = V[i]->rfcommChannel( ch ); + SIt = new ChannelLVI( (has) ? (int)ch : -1 , PI ); + SIt->setText(0, V[i]->name() ); + + Pm = Icons->serviceIcon( ID, R ); + SIt->setPixmap(0, Pm ); + Done = 1; + break; + } + } + } + + if( ! Done ) { + // check other range too + for( unsigned int j = 0; + j < UIDV.count(); + j ++ ) { + + if( Filter.count() ) { + bool FilterOut = 1; + // filter out if not in list + for( unsigned int ff = 0; + ff < Filter.count(); + ff ++ ) { + if( UIDV[j] == Filter[ff] ) { + FilterOut = 0; + break; + } + } + + if( FilterOut ) { + // not in filter list + continue; + } + } // else show + + ID = UIDV[j].toShort(); + if( ID >= 0x1200 && ID <= 0x12ff ) { + // use this profile + unsigned int ch; + bool has; + has = V[i]->rfcommChannel( ch ); + SIt = new ChannelLVI( (has) ? (int)ch : -1 , PI ); + SIt->setText(0, V[i]->name() ); + + Pm = Icons->serviceIcon( ID, R ); + SIt->setPixmap(0, Pm ); + + break; + } + } + } + + } + } + + scanMode( false ); +} + +void OTScan::scanMode( bool M ) { + // avoid infinite loop because it triggers DoScan + Detect_But->blockSignals( TRUE ); + Detect_But->setOn( M ); + Detect_But->setText( (M) ? tr("Scanning") : tr("Scan") ); + Detect_But->blockSignals( FALSE ); +} + +// +// +// +// +// + +OTManage::OTManage( QWidget * parent, OTIcons * _IC ) : + OTManageGUI( parent ) { + + OT = OTGateway::getOTGateway(); + + Icons = (_IC ) ? _IC : new OTIcons(); + MyIcons = (_IC == 0 ); + AllDrivers_LV->setSorting(-1); + + connect( OT, + SIGNAL( driverListChanged() ), + this, + SLOT( SLOT_DriverListChanged() ) + ); + connect( OT, + SIGNAL( stateChange( OTDriver *, bool ) ), + this, + SLOT( SLOT_StateChange( OTDriver *, bool ) ) + ); + + SLOT_DriverListChanged(); + + AllDrivers_LV->header()->hide(); +} + +OTManage::~OTManage() { + if( MyIcons ) + delete Icons; + OTGateway::releaseOTGateway(); +} + +void OTManage::SLOT_ShowDriver( QListViewItem * It ) { + if( It == 0 || It->depth() > 0 ) + // not toplevel + return; + + DriverLVI * it = (DriverLVI *) It; + DriverIsUp_CB->setChecked( it->driver()->isUp() ); +} + +void OTManage::SLOT_UpDriver( bool Up ) { + QListViewItem * it = AllDrivers_LV->firstChild(); + while( it ) { + if( it->isSelected() ) { + OTDriver * D = ((DriverLVI *)it)->driver(); + owarn << "UP driver " << D->devname() << oendl; + // this + D->setUp( Up ); + return; + } + it = it->nextSibling(); + } +} + +void OTManage::SLOT_StateChange( OTDriver * D, bool Up ) { + QListViewItem * it = AllDrivers_LV->firstChild(); + while( it ) { + if( ((DriverLVI *)it)->driver() == D ) { + it->setPixmap( 0, + Icons->loadPixmap( ( Up ) ? "bluezon" : "bluezoff" ) ); + return; + } + it = it->nextSibling(); + } +} + +void OTManage::SLOT_DriverListChanged( ) { + DriverLVI * It; + QListViewItem * Sub; + QListViewItem * First = 0; + OTDriver* D; + OTDriverList & DL = OT->getDriverList(); + + AllDrivers_LV->clear(); + for( unsigned int i = 0; + i < DL.count(); + i ++ ) { + D = DL[i]; + It = new DriverLVI( D, AllDrivers_LV ); + + if( ! First ) + First = It; + + It->setText( 0, D->devname() ); + It->setPixmap( 0, + Icons->loadPixmap( (D->isUp()) ? + "bluezon" : "bluezoff" ) ); + + Sub = new QListViewItem( It ); + Sub->setText( 0, tr( "Name" ) ); + Sub->setText( 1, D->name() ); + + Sub = new QListViewItem( It ); + Sub->setText( 0, tr( "Address" ) ); + Sub->setText( 1, D->address().toString() ); + + Sub = new QListViewItem( It ); + Sub->setText( 0, tr( "Revision" ) ); + Sub->setText( 1, D->revision() ); + + Sub = new QListViewItem( It ); + Sub->setText( 0, tr( "Manufacturer" ) ); + Sub->setText( 1, D->manufacturer() ); + + QString Service, Device; + D->getClass( Service, Device ); + + Sub = new QListViewItem( It ); + Sub->setText( 0, tr( "Service classes" ) ); + Sub->setText( 1, Service ); + Sub = new QListViewItem( It ); + Sub->setText( 0, tr( "Device class" ) ); + Sub->setText( 1, Device ); + } + + if( DL.count() ) { + AllDrivers_LV->setCurrentItem( First ); + DriverIsUp_CB->setEnabled( TRUE ); + } else { + DriverIsUp_CB->setChecked( FALSE ); + DriverIsUp_CB->setEnabled( FALSE ); + } +} + +void OTManage::SLOT_SetRefreshTimer( int v ) { + OT->setRefreshTimer( v * 1000 ); +} + +// +// +// +// +// + +OTMain::OTMain( QWidget * parent ) : OTMainGUI( parent ) { + + Icons = new OTIcons(); + OT = OTGateway::getOTGateway(); + + connect( OT, + SIGNAL( deviceEnabled( bool ) ), + this, + SLOT( SLOT_DeviceIsEnabled( bool ) ) + ); + connect( OT, + SIGNAL( driverListChanged() ), + this, + SLOT( SLOT_DriverListChanged() ) + ); + connect( OT, + SIGNAL( stateChange( OTDriver *, bool ) ), + this, + SLOT( SLOT_StateChange( OTDriver *, bool ) ) + ); + + if( ! OT->needsEnabling() ) { + MustBeEnabled_CB->hide(); + } else { + // detect current state + MustBeEnabled_CB->setChecked( + OT->isEnabled() ); + } + + SLOT_DriverListChanged(); +} + +OTMain::~OTMain() { + OTGateway::releaseOTGateway(); + delete Icons; +} + +void OTMain::SLOT_DriverListChanged() { + OTDriver * D; + OTDriverList & DL = OT->getDriverList(); + + DeviceList_CB->clear(); + for( unsigned int i = 0; + i < DL.count(); + i ++ ) { + D = DL[i]; + DeviceList_CB->insertItem( + Icons->loadPixmap( (D->isUp()) ? + "bluezon" : "bluezoff" ), + D->devname() ); + if( D == OT->scanWith() ) { + DeviceList_CB->setCurrentItem( i ); + } + } + + Scan_But->setEnabled( OT->getDriverList().count() > 0 ); + DeviceList_CB->setEnabled( OT->getDriverList().count() > 0 ); +} + +void OTMain::SLOT_EnableBluetooth( bool Up ) { + OT->SLOT_SetEnabled( Up ); +} + +void OTMain::SLOT_DeviceIsEnabled( bool Up ) { + MustBeEnabled_CB->blockSignals( TRUE ); + MustBeEnabled_CB->setChecked( Up ); + MustBeEnabled_CB->blockSignals( FALSE ); +} + +void OTMain::SLOT_Manage( void ) { + QDialog * Dlg = new QDialog( this, 0, TRUE ); + QVBoxLayout * V = new QVBoxLayout( Dlg ); + OTManage * Mng = new OTManage( Dlg, Icons ); + + V->addWidget( Mng ); + + Dlg->setCaption( tr("Manage local devices" ) ); + Dlg->showMaximized(); + Dlg->exec(); + delete Dlg; +} + +void OTMain::SLOT_Scan( void ) { + OTDriverList & DL = OT->getDriverList(); + for( unsigned int i = 0; + i < DL.count(); + i ++ ) { + if( DL[i]->isUp() && + DL[i]->devname() == DeviceList_CB->currentText() + ) { + QDialog * Dlg = new QDialog( this, 0, TRUE ); + QVBoxLayout * V = new QVBoxLayout( Dlg ); + OTScan * Scn = new OTScan( Dlg, Icons ); + + OT->setScanWith( OT->driver(i) ); + V->addWidget( Scn ); + Dlg->setCaption( tr("Scan Neighbourhood" ) ); + Dlg->showMaximized(); + Dlg->exec(); + + delete Dlg; + return; + } + } + +} + +void OTMain::SLOT_StateChange( OTDriver * D, bool Up ) { + for( int i = 0; + i < DeviceList_CB->count(); + i ++ ) { + if( DeviceList_CB->text(i) == D->devname() ) { + DeviceList_CB->changeItem( + Icons->loadPixmap( (Up) ? "bluezon" : "bluezoff" ), + D->devname(), + i ); + return; + } + } +} + +void OTMain::SLOT_Pairing( void ) { + QDialog * Dlg = new QDialog( this, 0, TRUE ); + QVBoxLayout * V = new QVBoxLayout( Dlg ); + OTPairing * Pair = new OTPairing( Dlg, Icons ); + + V->addWidget( Pair ); + Dlg->showMaximized(); + Dlg->setCaption( tr("Manage pairing" ) ); + Dlg->exec(); + + delete Dlg; +} diff --git a/noncore/settings/networksettings2/opietooth2/Opietooth.h b/noncore/settings/networksettings2/opietooth2/Opietooth.h new file mode 100644 index 0000000..9e53fcb --- a/dev/null +++ b/noncore/settings/networksettings2/opietooth2/Opietooth.h @@ -0,0 +1,194 @@ +#ifndef OPIETOOTH_H +#define OPIETOOTH_H + +#include + +#include +class OLedBox; + +namespace Opietooth2 { + +class OTGateway; +class OTDriver; +class OTInquiry; +class OTPeer; +class PeerLVI; + +class OTPairing : public OTPairingGUI { + + Q_OBJECT + +public : + + OTPairing( QWidget * parent, + OTIcons * _Ic = 0 ); + ~OTPairing(); + +private slots : + + void SLOT_Unpair( void ); + +signals : + +protected : + +private : + + bool MyIcons; + OTIcons * Icons; + OTGateway * OT; +}; +}; + +#include + +namespace Opietooth2 { + +class OTGateway; +class OTDriver; +class OTInquiry; +class OTPeer; + +class OTScan : public OTScanGUI { + + Q_OBJECT + +public : + + OTScan( QWidget * parent, + OTIcons * _Ic = 0 ); + ~OTScan(); + + // static function to return a device and a channel + static int getDevice( OTPeer *& Peer, + int & Channel, + OTGateway * OT, + const UUIDVector & Filter = 0, + QWidget* Parent = 0); + + // show only services that match any of the filter + void setScanFilter( const UUIDVector & Filter ); + void resetScanFilter( void ); + + inline OTPeer * selectedPeer( void ) + { return SelectedPeer; } + inline int selectedChannel( void ) + { return SelectedChannel; } + +public slots : + +private slots : + + void SLOT_DoScan( bool ); + void SLOT_NewPeer( OTPeer *, bool ); + void SLOT_FinishedDetecting(); + void SLOT_Show( QListViewItem *); + void SLOT_RefreshServices( void ); + void SLOT_RefreshState( void ); + void SLOT_CleanupOld( void ); + void SLOT_UpdateStrength( void ); + void SLOT_PeerState( OTPeer * ); + void SLOT_Selected( QListViewItem * ); + +signals : + + void selected( void ); + +protected : + +private : + + void refreshState( PeerLVI *, bool ); + void scanMode( bool ); + + // load scanned devices + + bool MyIcons; + OTIcons * Icons; + OTGateway * OT; + OTInquiry * Scanning; + UUIDVector Filter; + + OLedBox * Paired_Led; + QTimer * StrengthTimer; + PeerLVI * Current; + + OTPeer * SelectedPeer; + int SelectedChannel; +}; +}; + +#include +namespace Opietooth2 { + +class OTManage : public OTManageGUI { + + Q_OBJECT + +public : + + OTManage( QWidget * parent, + OTIcons * _IC = 0 ); + ~OTManage(); + +public slots : + +private slots : + + void SLOT_ShowDriver( QListViewItem * ); + void SLOT_UpDriver( bool ); + void SLOT_StateChange( OTDriver * , bool ); + void SLOT_DriverListChanged(); + void SLOT_SetRefreshTimer( int ); + +signals : + +protected : + +private : + + // load scanned devices + + bool MyIcons; + OTIcons * Icons; + OTGateway * OT; + OTInquiry * Scanning; +}; +}; + +#include + +namespace Opietooth2 { +class OTMain : public OTMainGUI { + + Q_OBJECT + +public : + + OTMain( QWidget * parent ); + ~OTMain(); + +public slots : + +private slots : + + void SLOT_Pairing( void ); + void SLOT_Manage( void ); + void SLOT_Scan( void ); + void SLOT_EnableBluetooth( bool ); + void SLOT_DriverListChanged(); + void SLOT_DeviceIsEnabled( bool ); + void SLOT_StateChange( OTDriver * , bool ); + +signals : + +protected : + +private : + + // load scanned devices + OTIcons * Icons; + OTGateway * OT; +}; +}; +#endif diff --git a/noncore/settings/networksettings2/opietooth2/bluezlib.h b/noncore/settings/networksettings2/opietooth2/bluezlib.h new file mode 100644 index 0000000..c431574 --- a/dev/null +++ b/noncore/settings/networksettings2/opietooth2/bluezlib.h @@ -0,0 +1,28 @@ +#ifndef BLUEZLIB_H +#define BLUEZLIB_H + +#include +#include +#include +#include +#include +#include +#include + +extern "C" { +#include +#include +#include +#include +#include +#include +#include +#include +} + +#define BT_DISABLED 0 +#define BT_ENABLED 1 +#define BT_UNKNOWN 2 +#define BTVALUE(x) ((x)?BT_ENABLED:BT_DISABLED) + +#endif diff --git a/noncore/settings/networksettings2/opietooth2/config.in b/noncore/settings/networksettings2/opietooth2/config.in new file mode 100644 index 0000000..720f49a --- a/dev/null +++ b/noncore/settings/networksettings2/opietooth2/config.in @@ -0,0 +1,5 @@ +config NS2OPIETOOTH + boolean "opie-networksettings2 bluetooth library" + default "y" + depends ( LIBQPE || LIBQPE-X11 ) && LIBOPIE2CORE + diff --git a/noncore/settings/networksettings2/opietooth2/libopietooth2.control b/noncore/settings/networksettings2/opietooth2/libopietooth2.control new file mode 100644 index 0000000..fd01fb5 --- a/dev/null +++ b/noncore/settings/networksettings2/opietooth2/libopietooth2.control @@ -0,0 +1,9 @@ +Package: libopietooth2 +Files: lib/libopietooth2.so.* apps/Settings/opietooth-manager.desktop pics/opietooth/*.png pics/opietooth/icons/*.png +Priority: optional +Section: opie/system +Maintainer: wim delvaux +Architecture: arm +Version: $QPE_VERSION$EXTRAVERSION +Depends: task-opie-minimal, libbluetooth1, opie-bluepin | opie-multiauth-bluepingplugin, bluez-utils-nodbus +Description: Opie bluetooth support library version 2 diff --git a/noncore/settings/networksettings2/opietooth2/libopietooth2.postinst b/noncore/settings/networksettings2/opietooth2/libopietooth2.postinst new file mode 100755 index 0000000..cd605c2 --- a/dev/null +++ b/noncore/settings/networksettings2/opietooth2/libopietooth2.postinst @@ -0,0 +1,10 @@ +#!/bin/sh + +QTPB=/opt/QtPalmtop/bin + +[ ! -L ${QTPB}/networksettings2-opietooth ] && ln -sf ${QTPB}/networksettings2 ${QTPB}/networksettings2-opietooth + +# qcop QPE/Taskbar "linkChanged(opietooth)" +qcop QPE/Taskbar "reloadApps()" + +exit 0 diff --git a/noncore/settings/networksettings2/opietooth2/opietooth2.pro b/noncore/settings/networksettings2/opietooth2/opietooth2.pro new file mode 100644 index 0000000..590b656 --- a/dev/null +++ b/noncore/settings/networksettings2/opietooth2/opietooth2.pro @@ -0,0 +1,37 @@ +TEMPLATE = lib +CONFIG += qt warn_on release +#CONFIG += qt warn_on debug +DESTDIR = $(OPIEDIR)/lib$(PROJMAK) +HEADERS = OTDevice.h \ + OTDriver.h \ + OTGateway.h \ + OTHCISocket.h \ + OTInquiry.h \ + OTDeviceAddress.h \ + OTIcons.h \ + OTUUID.h \ + OTSDPAttribute.h \ + OTSDPService.h \ + OTPeer.h \ + Opietooth.h +SOURCES = OTDevice.cpp \ + OTDriver.cpp \ + OTDriverList.cpp \ + OTHCISocket.cpp \ + OTInquiry.cpp \ + OTDeviceAddress.cpp \ + OTUUID.cpp \ + OTSDPAttribute.cpp \ + OTSDPService.cpp \ + OTIcons.cpp \ + OTPeer.cpp \ + OTGateway.cpp \ + Opietooth.cpp +INCLUDEPATH += $(OPIEDIR)/include +DEPENDPATH += $(OPIEDIR)/include +LIBS += -lqpe -lopiecore2 -lbluetooth +INTERFACES = OTMainGUI.ui OTScanGUI.ui OTManageGUI.ui OTPairingGUI.ui +TARGET = opietooth2 +VERSION = 1.0.0 + +include ( $(OPIEDIR)/include.pro ) -- cgit v0.9.0.2