summaryrefslogtreecommitdiff
authorzecke <zecke>2002-07-12 17:14:58 (UTC)
committer zecke <zecke>2002-07-12 17:14:58 (UTC)
commit89dce758480cc90502ad14b6c4cf80774e6c1845 (patch) (side-by-side diff)
tree2ff4e635c8aa86385dfd896084f5cd419efd0840
parent716211b5e06bb25145cfbcf62a11a7c52c79dde5 (diff)
downloadopie-89dce758480cc90502ad14b6c4cf80774e6c1845.zip
opie-89dce758480cc90502ad14b6c4cf80774e6c1845.tar.gz
opie-89dce758480cc90502ad14b6c4cf80774e6c1845.tar.bz2
- Connection -> ConnectionState
- Factory adjustments - Factory function - Refactoring the QListViewItem derived class BTListItem | - BTDeviceItem for RemoteDevices | - BTServiceItem for Services | - BTConnectionItem for ConnectionState - misc bug fixes
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/net/opietooth/lib/connection.cpp32
-rw-r--r--noncore/net/opietooth/lib/connection.h16
-rw-r--r--noncore/net/opietooth/lib/manager.cc10
-rw-r--r--noncore/net/opietooth/lib/manager.h4
-rw-r--r--noncore/net/opietooth/manager/bluebase.cpp84
-rw-r--r--noncore/net/opietooth/manager/bluebase.h11
-rw-r--r--noncore/net/opietooth/manager/btlistitem.cpp60
-rw-r--r--noncore/net/opietooth/manager/btlistitem.h21
-rw-r--r--noncore/net/opietooth/manager/manager.pro4
-rw-r--r--noncore/net/opietooth/manager/popuphelper.cpp9
-rw-r--r--noncore/net/opietooth/manager/popuphelper.h6
11 files changed, 109 insertions, 148 deletions
diff --git a/noncore/net/opietooth/lib/connection.cpp b/noncore/net/opietooth/lib/connection.cpp
index 1f9baaf..ef7d925 100644
--- a/noncore/net/opietooth/lib/connection.cpp
+++ b/noncore/net/opietooth/lib/connection.cpp
@@ -1,90 +1,90 @@
#include "connection.h"
using namespace OpieTooth;
-Connection::Connection() {
+ConnectionState::ConnectionState() {
m_direction = Incoming;
m_handle = -1;
m_state = -1;
m_linkMode = -1;
};
-Connection::Connection( const Connection& con1 ) {
+ConnectionState::ConnectionState( const ConnectionState& con1 ) {
(*this) = con1;
}
-Connection::Connection( bool in,
+ConnectionState::ConnectionState( bool in,
const QString& conType,
const QString& mac,
int handle,
int state,
int linkMode ) {
m_direction = in;
m_contype = conType;
m_mac = mac;
m_handle = handle;
m_state = state;
m_linkMode = linkMode;
}
-void Connection::setDirection( bool incoming ) {
+void ConnectionState::setDirection( bool incoming ) {
m_direction = incoming;
}
-bool Connection::direction() const {
+bool ConnectionState::direction() const {
return m_direction;
}
-void Connection::setConnectionMode( const QString& conType ) {
+void ConnectionState::setConnectionMode( const QString& conType ) {
m_contype = conType;
}
-QString Connection::connectionMode() const {
+QString ConnectionState::connectionMode() const {
return m_contype;
}
-void Connection::setMac( const QString& mac ) {
+void ConnectionState::setMac( const QString& mac ) {
m_mac = mac;
}
-QString Connection::mac() const{
+QString ConnectionState::mac() const{
return m_mac;
}
-void Connection::setHandle( int handle ) {
+void ConnectionState::setHandle( int handle ) {
m_handle = handle;
}
-int Connection::handle() const{
+int ConnectionState::handle() const{
return m_handle;
}
-void Connection::setState( int state ) {
+void ConnectionState::setState( int state ) {
m_state = state;
}
-int Connection::state()const {
+int ConnectionState::state()const {
return m_state;
}
-void Connection::setLinkMode( int linkMode ) {
+void ConnectionState::setLinkMode( int linkMode ) {
m_linkMode = linkMode;
}
-int Connection::linkMode()const{
+int ConnectionState::linkMode()const{
return m_linkMode;
}
-Connection &Connection::operator=( const Connection& con1 ) {
+ConnectionState &ConnectionState::operator=( const ConnectionState& con1 ) {
m_direction = con1.m_direction;
m_contype = con1.m_contype;
m_mac = con1.m_mac;
m_handle = con1.m_handle;
m_state = con1.m_state;
m_linkMode = con1.m_linkMode;
return (*this);
}
diff --git a/noncore/net/opietooth/lib/connection.h b/noncore/net/opietooth/lib/connection.h
index 37090ce..76e5dad 100644
--- a/noncore/net/opietooth/lib/connection.h
+++ b/noncore/net/opietooth/lib/connection.h
@@ -1,150 +1,150 @@
#ifndef OpieTooth_Connection_H
#define OpieTooth_Connection_H
#include <qstring.h>
#include <qvaluelist.h>
namespace OpieTooth {
enum LinkDirection { Incoming= true, Outgoing = false };
enum LinkMode { Master =0, Client };
/**
* The Connection class stores
* the output of hcitool con
* in a OO way
*/
- class Connection {
+ class ConnectionState {
public:
/**
* typedef for a list of
* Connections
*/
- typedef QValueList<Connection> ValueList;
+ typedef QValueList<ConnectionState> ValueList;
/**
* Copy c'tor.
*/
- Connection( const Connection& );
+ ConnectionState( const ConnectionState& );
/**
* Main c'tor
* Basicly it holds all values
* a blueZ connections can have
* @param in If the connection is either incoming or outgoing
* @param conType Either ACL or SCO for connection type
* @param mac The BD Address( mac ) of the peer
* @param handle the blueZ handle
* @param state the State of the connection
* @param linkMode the linkmode of the connection MASTER or not
*
* < ACL 00:02:C7:09:2B:53 handle 1 state 1 lm MASTER
*
*/
- Connection( bool in,
+ ConnectionState( bool in,
const QString& conType,
const QString& mac,
int handle,
int state,
int linkMode );
/**
* C'tor for compability with QValueList
* QValueList needs this c'tor.
*/
- Connection();
+ ConnectionState();
/**
* Set if the connection is incoming or
* outgoing
* @param in Whether or not the connection is ingoing or not.
* for param use either Incoming or Outgoing
*
*/
void setDirection( bool incoming = Incoming );
/**
* direction() will return Incoming( true )
* if the direction is incomoning or Outgoing( false)
* if outgoing
*/
bool direction() const;
/**
* sets the ConnectionMode
* @param comMode I know that SCO and ACL exists so far
*/
void setConnectionMode( const QString& comMode );
/**
* linkMode returns the linkMode
* MASTER for example
*/
QString connectionMode() const;
/**
* The Bluetooth Address or mac
* is set by this function
* @param mac the BluetoothAddress( mac)
*/
void setMac( const QString& mac);
/**
* returns the mac
*/
QString mac() const;
/**
* Set the handle of the bt connection
*/
void setHandle(int handle );
/**
* @return the handle of the connection
*/
int handle() const;
/**
* sets the state
*/
void setState( int state );
/**
* return the state
*/
int state() const;
/**
* Sets the link mode of the Connection
*/
void setLinkMode( int linkMode = Master );
/**
* returns the linkMode
*/
int linkMode()const;
/**
* copy c'tor
*/
- Connection &operator=( const Connection& );
+ ConnectionState &operator=( const ConnectionState& );
private:
- class ConnectionPrivate;
- ConnectionPrivate *d;
+ class ConnectionStatePrivate;
+ ConnectionStatePrivate *d;
bool m_direction : 1;
QString m_contype;
QString m_mac;
int m_handle;
int m_state;
int m_linkMode;
};
};
#endif
diff --git a/noncore/net/opietooth/lib/manager.cc b/noncore/net/opietooth/lib/manager.cc
index e07f9da..1281116 100644
--- a/noncore/net/opietooth/lib/manager.cc
+++ b/noncore/net/opietooth/lib/manager.cc
@@ -65,235 +65,235 @@ void Manager::searchDevices( const QString& device ){
connect( hcitool, SIGNAL(receivedStdout(OProcess*, char*, int ) ),
this, SLOT(slotHCIOut(OProcess*, char*, int ) ) );
if (!hcitool->start(OProcess::NotifyOnExit, OProcess::AllOutput) ) {
qWarning("could not start");
RemoteDevice::ValueList list;
emit foundDevices( device, list );
delete hcitool;
}
}
void Manager::searchDevices(Device* /*d*/ ){
}
void Manager::addService(const QString& name ){
OProcess proc;
proc << "sdptool" << "add" << name;
bool bo = true;
if (!proc.start(OProcess::DontCare ) )
bo = false;
emit addedService( name, bo );
}
void Manager::addServices(const QStringList& list){
QStringList::ConstIterator it;
for (it = list.begin(); it != list.end(); ++it )
addService( (*it) );
}
void Manager::removeService( const QString& name ){
OProcess prc;
prc << "sdptool" << "del" << name;
bool bo = true;
if (!prc.start(OProcess::DontCare ) )
bo = false;
emit removedService( name, bo );
}
void Manager::removeServices( const QStringList& list){
QStringList::ConstIterator it;
for (it = list.begin(); it != list.end(); ++it )
removeService( (*it) );
}
void Manager::searchServices( const QString& remDevice ){
OProcess *m_sdp =new OProcess();
*m_sdp << "sdptool" << "browse" << remDevice;
m_sdp->setName( remDevice.latin1() );
qWarning("search Services for %s", remDevice.latin1() );
connect(m_sdp, SIGNAL(processExited(OProcess*) ),
this, SLOT(slotSDPExited(OProcess* ) ) );
connect(m_sdp, SIGNAL(receivedStdout(OProcess*, char*, int ) ),
this, SLOT(slotSDPOut(OProcess*, char*, int) ) );
if (!m_sdp->start(OProcess::NotifyOnExit, OProcess::AllOutput) ) {
qWarning("could not start sdptool" );
delete m_sdp;
Services::ValueList list;
emit foundServices( remDevice, list );
}
}
void Manager::searchServices( const RemoteDevice& dev){
searchServices( dev.mac() );
}
QString Manager::toDevice( const QString& /*mac*/ ){
return QString::null;
}
QString Manager::toMac( const QString &/*device*/ ){
return QString::null;
}
void Manager::slotProcessExited(OProcess* proc ) {
bool conn= false;
if (proc->normalExit() && proc->exitStatus() == 0 )
conn = true;
QString name = QString::fromLatin1(proc->name() );
emit available( name, conn );
delete proc;
}
void Manager::slotSDPOut(OProcess* proc, char* ch, int len)
{
QCString str(ch, len+1 );
qWarning("SDP:%s", str.data() );
QMap<QString, QString>::Iterator it;
it = m_out.find(proc->name() );
QString string;
if ( it != m_out.end() ) {
string = it.data();
}
string.append( str );
m_out.replace( proc->name(), string );
}
void Manager::slotSDPExited( OProcess* proc)
{
qWarning("proc name %s", proc->name() );
Services::ValueList list;
if (proc->normalExit() ) {
QMap<QString, QString>::Iterator it = m_out.find( proc->name() );
if ( it != m_out.end() ) {
qWarning("found process" );
list = parseSDPOutput( it.data() );
m_out.remove( it );
}
}
emit foundServices( proc->name(), list );
delete proc;
}
Services::ValueList Manager::parseSDPOutput( const QString& out ) {
Services::ValueList list;
qWarning("parsing output" );
Parser parser( out );
list = parser.services();
return list;
}
void Manager::slotHCIExited(OProcess* proc ) {
qWarning("process exited");
RemoteDevice::ValueList list;
if (proc->normalExit() ) {
qWarning("normalExit %s", proc->name() );
QMap<QString, QString>::Iterator it = m_devices.find(proc->name() );
if (it != m_devices.end() ) {
qWarning("!= end ;)");
list = parseHCIOutput( it.data() );
m_devices.remove( it );
}
}
emit foundDevices( proc->name(), list );
delete proc;
}
void Manager::slotHCIOut(OProcess* proc, char* ch, int len) {
QCString str( ch, len+1 );
qWarning("hci: %s", str.data() );
QMap<QString, QString>::Iterator it;
it = m_devices.find( proc->name() );
qWarning("proc->name %s", proc->name() );
QString string;
if (it != m_devices.end() ) {
qWarning("slotHCIOut ");
string = it.data();
}
string.append( str );
m_devices.replace( proc->name(), string );
}
RemoteDevice::ValueList Manager::parseHCIOutput(const QString& output ) {
qWarning("parseHCI %s", output.latin1() );
RemoteDevice::ValueList list;
QStringList strList = QStringList::split('\n', output );
QStringList::Iterator it;
QString str;
for ( it = strList.begin(); it != strList.end(); ++it ) {
str = (*it).stripWhiteSpace();
qWarning("OpieTooth %s", str.latin1() );
int pos = str.findRev(':' );
if ( pos > 0 ) {
QString mac = str.left(17 );
str.remove( 0, 17 );
qWarning("mac %s", mac.latin1() );
qWarning("rest:%s", str.latin1() );
RemoteDevice rem( mac , str.stripWhiteSpace() );
list.append( rem );
}
}
return list;
}
////// hcitool cc and hcitool con
/**
* Create it on the stack as don't care
* so we don't need to care for it
* cause hcitool gets reparented
*/
void Manager::connectTo( const QString& mac) {
OProcess proc;
proc << "hcitool";
proc << "cc";
proc << mac;
proc.start(OProcess::DontCare); // the lib does not care at this point
}
void Manager::searchConnections() {
qWarning("searching connections?");
OProcess* proc = new OProcess();
m_hcitoolCon = QString::null;
connect(proc, SIGNAL(processExited(OProcess*) ),
this, SLOT(slotConnectionExited( OProcess*) ) );
connect(proc, SIGNAL(receivedStdout(OProcess*, char*, int) ),
this, SLOT(slotConnectionOutput(OProcess*, char*, int) ) );
*proc << "hcitool";
*proc << "con";
if (!proc->start(OProcess::NotifyOnExit, OProcess::AllOutput) ) {
- Connection::ValueList list;
+ ConnectionState::ValueList list;
emit connections( list );
delete proc;
}
}
void Manager::slotConnectionExited( OProcess* /*proc*/ ) {
qWarning("exited");
- Connection::ValueList list;
+ ConnectionState::ValueList list;
list = parseConnections( m_hcitoolCon );
emit connections(list );
}
void Manager::slotConnectionOutput(OProcess* proc, char* cha, int len) {
QCString str(cha, len );
m_hcitoolCon.append( str );
delete proc;
}
-Connection::ValueList Manager::parseConnections( const QString& out ) {
- Connection::ValueList list2;
+ConnectionState::ValueList Manager::parseConnections( const QString& out ) {
+ ConnectionState::ValueList list2;
QStringList list = QStringList::split('\n', out );
QStringList::Iterator it;
for (it = list.begin(); it != list.end(); ++it ) {
QString row = (*it).stripWhiteSpace();
QStringList value = QStringList::split(' ', row );
qWarning("0: %s", value[0].latin1() );
qWarning("1: %s", value[1].latin1() );
qWarning("2: %s", value[2].latin1() );
qWarning("3: %s", value[3].latin1() );
qWarning("4: %s", value[4].latin1() );
qWarning("5: %s", value[5].latin1() );
qWarning("6: %s", value[6].latin1() );
qWarning("7: %s", value[7].latin1() );
qWarning("8: %s", value[8].latin1() );
- Connection con;
+ ConnectionState con;
con.setDirection( value[0] == QString::fromLatin1("<") ? Outgoing : Incoming );
con.setConnectionMode( value[1] );
con.setMac( value[2] );
con.setHandle( value[4].toInt() );
con.setState( value[6].toInt() );
con.setLinkMode( value[8] == QString::fromLatin1("MASTER") ? Master : Client );
list2.append( con );
}
return list2;
}
diff --git a/noncore/net/opietooth/lib/manager.h b/noncore/net/opietooth/lib/manager.h
index b32327c..0ebe1b3 100644
--- a/noncore/net/opietooth/lib/manager.h
+++ b/noncore/net/opietooth/lib/manager.h
@@ -1,166 +1,166 @@
#ifndef OpieToothManager_H
#define OpieToothManager_H
#include <qobject.h>
#include <qstring.h>
#include <qmap.h>
#include <qvaluelist.h>
#include "connection.h"
#include "remotedevice.h"
#include "services.h"
class OProcess;
namespace OpieTooth {
class Device;
/** Manager manages a blueZ device (hci0 for example)
* without Manager you can control the things you
* could do from command line in a OO and asynchronus
* way.
*/
class Manager : public QObject {
Q_OBJECT
public:
/** c'tor whichs create a new Manager
* @param device is the device to use. Either a mac or blueZ device name
*
*/
Manager( const QString &device );
/** c'tor
* @param dev The Device to be managed
* We don't care of Device so you need to delete it
*/
Manager( Device* dev );
/**
* c'tor
*/
Manager();
~Manager();
/** Set the manager to control a new device
* @param device the new device to control (hci0 )
*/
void setDevice( const QString& device );
/**
* Convience functions for setting a new device
*/
void setDevice( Device *dev );
/**
* Wether or not a device is connected. The function
* is asynchron
* If device is empty it will take the currently managed
* device and see if it's up
* for Remote devices it will ping and see.
* @param either mac or hciX
*/
void isAvailable(const QString& device= QString::null );
/**
* same as above
*/
void isAvailable(Device *dev );
/** this searchs for devices reachable from the
* currently managed device
* or from device if @param device is not empty
*/
void searchDevices(const QString& device= QString::null );
/** same as above
*
*/
void searchDevices(Device *d );
/**
* This will add the service @param name
* to the sdpd daemon
* It will start the daemon if necessary
*/
void addService(const QString &name );
/**
* This will add the services @param names
* to the sdpd daemon
* It will start the daemon if necessary
*/
void addServices( const QStringList& names );
/**
* This removes a service from the sdps
*/
void removeService(const QString &name );
/**
* Removes a list from the sdpd
*/
void removeServices(const QStringList& );
/**
* search for services on a remote device
*
*/
void searchServices( const QString& remDevice );
/**
* search for services on a remote device
*/
void searchServices( const RemoteDevice& );
/**
* Starts to connect to the device
* in @param
*/
void connectTo(const QString& );
/**
* Searches for active connections
* the result is emitted with the
* connections signal
*/
void searchConnections();
//// not implemented yet
/*static*/ QString toDevice( const QString& mac );
/*static*/ QString toMac( const QString &device );
//// not implemented yet over
signals:
// device either mac or dev name
// the first device is the device which you access
void available( const QString& device, bool connected );
void addedService( const QString& service, bool added );
void removedService( const QString& service, bool removed );
void foundServices( const QString& device, Services::ValueList );
void foundDevices( const QString& device, RemoteDevice::ValueList );
- void connections( Connection::ValueList );
+ void connections( ConnectionState::ValueList );
private slots:
void slotProcessExited(OProcess* );
void slotSDPExited(OProcess*);
void slotSDPOut(OProcess*, char*, int);
void slotHCIExited(OProcess* );
void slotHCIOut(OProcess*, char*, int );
void slotConnectionExited(OProcess* );
void slotConnectionOutput(OProcess*, char*, int );
private:
Services::ValueList parseSDPOutput( const QString& );
RemoteDevice::ValueList parseHCIOutput( const QString& );
- Connection::ValueList parseConnections( const QString& );
+ ConnectionState::ValueList parseConnections( const QString& );
OProcess *m_hcitool;
OProcess *m_sdp; // not only one
QString m_device;
QMap<QString, QString> m_out;
QMap<QString, QString> m_devices;
QString m_hcitoolCon;
};
};
#endif
diff --git a/noncore/net/opietooth/manager/bluebase.cpp b/noncore/net/opietooth/manager/bluebase.cpp
index 85c6717..9cfeaa2 100644
--- a/noncore/net/opietooth/manager/bluebase.cpp
+++ b/noncore/net/opietooth/manager/bluebase.cpp
@@ -1,458 +1,476 @@
/*
* bluebase.cpp *
* ---------------------
*
* copyright : (c) 2002 by Maximilian Reiß
* email : max.reiss@gmx.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 "bluebase.h"
#include "scandialog.h"
#include "hciconfwrapper.h"
#include <qframe.h>
#include <qlabel.h>
#include <qpushbutton.h>
#include <qlayout.h>
#include <qvariant.h>
#include <qwhatsthis.h>
#include <qimage.h>
#include <qpixmap.h>
#include <qtabwidget.h>
#include <qscrollview.h>
#include <qvbox.h>
#include <qmessagebox.h>
#include <qcheckbox.h>
#include <qlineedit.h>
#include <qlistview.h>
#include <qdir.h>
#include <qpopupmenu.h>
#include <qtimer.h>
#include <qpe/resource.h>
#include <qpe/config.h>
#include <remotedevice.h>
#include <services.h>
+#include "btconnectionitem.h"
+
using namespace OpieTooth;
BlueBase::BlueBase( QWidget* parent, const char* name, WFlags fl )
: BluetoothBase( parent, name, fl ) {
m_localDevice = new Manager( "hci0" );
connect( PushButton2, SIGNAL( clicked() ), this, SLOT(startScan() ) );
connect( configApplyButton, SIGNAL(clicked() ), this, SLOT(applyConfigChanges() ) );
// not good since lib is async
// connect( ListView2, SIGNAL( expanded ( QListViewItem* ) ),
// this, SLOT( addServicesToDevice( QListViewItem * ) ) );
connect( ListView2, SIGNAL( clicked( QListViewItem* )),
this, SLOT( startServiceActionClicked( QListViewItem* ) ) );
connect( ListView2, SIGNAL( rightButtonClicked( QListViewItem *, const QPoint &, int ) ),
this, SLOT(startServiceActionHold( QListViewItem *, const QPoint &, int) ) );
connect( m_localDevice , SIGNAL( foundServices( const QString& , Services::ValueList ) ),
this, SLOT( addServicesToDevice( const QString& , Services::ValueList ) ) );
connect( m_localDevice, SIGNAL( available( const QString&, bool ) ),
this, SLOT( deviceActive( const QString& , bool ) ) );
connect( m_localDevice, SIGNAL( connections( Connection::ValueList ) ),
this, SLOT( addConnectedDevices( Connection::ValueList ) ) );
//Load all icons needed
m_offPix = Resource::loadPixmap( "editdelete" );
m_onPix = Resource::loadPixmap( "installed" );
QPalette pal = this->palette();
QColor col = pal.color( QPalette::Active, QColorGroup::Background );
pal.setColor( QPalette::Active, QColorGroup::Button, col );
pal.setColor( QPalette::Inactive, QColorGroup::Button, col );
pal.setColor( QPalette::Normal, QColorGroup::Button, col );
pal.setColor( QPalette::Disabled, QColorGroup::Button, col );
this->setPalette( pal );
setCaption( tr( "Bluetooth Manager" ) );
readConfig();
initGui();
//TESTING
ListView2->setRootIsDecorated(true);
- BTListItem *topLV2 = new BTListItem( ListView2, "Siemens S45", "", "device" );
+ BTDeviceItem *topLV2 = new BTDeviceItem( ListView2, RemoteDevice("xx:", "Siemens S45" ) );
topLV2->setPixmap( 1, m_onPix );
- (void) new BTListItem( topLV2, "Serial" ,"", "service" );
- (void) new BTListItem( topLV2, "BlueNiC" , "", "service" );
+ Services s1;
+ s1.setServiceName( "Serial" );
+ (void) new BTServiceItem( topLV2, s1 );
+ s1.setServiceName( "BlueNic" );
+ (void) new BTServiceItem( topLV2, s1 );
writeToHciConfig();
// search conncetions
addConnectedDevices();
m_iconLoader = new BTIconLoader();
}
/**
* Reads all options from the config file
*/
void BlueBase::readConfig() {
Config cfg( "bluetoothmanager" );
cfg.setGroup( "bluezsettings" );
m_deviceName = cfg.readEntry( "name" , "No name" ); // name the device should identify with
m_defaultPasskey = cfg.readEntryCrypt( "passkey" , "" ); // <- hmm, look up how good the trolls did that, maybe too weak
m_useEncryption = cfg.readBoolEntry( "useEncryption" , TRUE );
m_enableAuthentification = cfg.readBoolEntry( "enableAuthentification" , TRUE );
m_enablePagescan = cfg.readBoolEntry( "enablePagescan" , TRUE );
m_enableInquiryscan = cfg.readBoolEntry( "enableInquiryscan" , TRUE );
}
/**
* Writes all options to the config file
*/
void BlueBase::writeConfig() {
Config cfg( "bluetoothmanager" );
cfg.setGroup( "bluezsettings" );
cfg.writeEntry( "name" , m_deviceName );
cfg.writeEntryCrypt( "passkey" , m_defaultPasskey );
cfg.writeEntry( "useEncryption" , m_useEncryption );
cfg.writeEntry( "enableAuthentification" , m_enableAuthentification );
cfg.writeEntry( "enablePagescan" , m_enablePagescan );
cfg.writeEntry( "enableInquiryscan" , m_enableInquiryscan );
writeToHciConfig();
}
void BlueBase::writeToHciConfig() {
HciConfWrapper hciconf ( "/tmp/hcid.conf" );
hciconf.setPinHelper( "/bin/QtPalmtop/bin/blue-pin" );
// hciconf->setPinHelper( "/bin/QtPalmtop/bin/blue-pin" );
hciconf.setName( m_deviceName );
hciconf.setEncrypt( m_useEncryption );
hciconf.setAuth( m_enableAuthentification );
hciconf.setPscan( m_enablePagescan );
hciconf.setIscan( m_enableInquiryscan );
}
/**
* Read the list of allready known devices
*
*/
void BlueBase::readSavedDevices() {
QValueList<RemoteDevice> loadedDevices;
QDir deviceListSave( QDir::homeDirPath() + "/Settings/bluetooth/");
// list of .conf files
QStringList devicesFileList = deviceListSave.entryList();
// cut .conf of to get the mac and also read the name entry in it.
for ( QStringList::Iterator it = devicesFileList.begin(); it != devicesFileList.end(); ++it ) {
QString name;
QString mac;
qDebug((*it).latin1() );
Config conf((*it));
conf.setGroup("Info");
name = conf.readEntry("name", "Error");
qDebug("MAC: " + mac);
qDebug("NAME: " + name);
RemoteDevice currentDevice( mac , name );
loadedDevices.append( currentDevice );
}
addSearchedDevices( loadedDevices );
}
/**
* Write the list of allready known devices
*
*/
void BlueBase::writeSavedDevices() {
QListViewItemIterator it( ListView2 );
+ BTListItem* item;
+ BTDeviceItem* device;
for ( ; it.current(); ++it ) {
+ item = (BTListItem*)it.current();
+ if(item->typeId() != BTListItem::Device )
+ continue;
+ device = (BTDeviceItem*)item;
// seperate config file for each device, to store more information in future.
- qDebug( "/Settings/bluetooth/" + (((BTListItem*)it.current())->mac()) + ".conf");
- Config conf( QDir::homeDirPath() + "/Settings/bluetooth/" + (((BTListItem*)it.current())->mac()) + ".conf", Config::File );
+ qDebug( "/Settings/bluetooth/" + device->mac() + ".conf");
+ Config conf( QDir::homeDirPath() + "/Settings/bluetooth/" + device->mac() + ".conf", Config::File );
conf.setGroup( "Info" );
- conf.writeEntry( "name", ((BTListItem*)it.current())->name() );
+ conf.writeEntry( "name", device->name() );
}
}
/**
* Set up the gui
*/
void BlueBase::initGui() {
StatusLabel->setText( status() ); // maybe move it to getStatus()
cryptCheckBox->setChecked( m_useEncryption );
authCheckBox->setChecked( m_enableAuthentification );
pagescanCheckBox->setChecked( m_enablePagescan );
inquiryscanCheckBox->setChecked( m_enableInquiryscan );
deviceNameLine->setText( m_deviceName );
passkeyLine->setText( m_defaultPasskey );
// set info tab
setInfo();
}
/**
* Get the status informations and returns it
* @return QString the status informations gathered
*/
QString BlueBase::status()const{
QString infoString = tr( "<b>Device name : </b> Ipaq" );
infoString += QString( "<br><b>" + tr( "MAC adress: " ) +"</b> No idea" );
infoString += QString( "<br><b>" + tr( "Class" ) + "</b> PDA" );
return (infoString);
}
/**
* Read the current values from the gui and invoke writeConfig()
*/
void BlueBase::applyConfigChanges() {
m_deviceName = deviceNameLine->text();
m_defaultPasskey = passkeyLine->text();
m_useEncryption = cryptCheckBox->isChecked();
m_enableAuthentification = authCheckBox->isChecked();
m_enablePagescan = pagescanCheckBox->isChecked();
m_enableInquiryscan = inquiryscanCheckBox->isChecked();
writeConfig();
QMessageBox::information( this, tr("Test") , tr("Changes were applied.") );
}
/**
* Add fresh found devices from scan dialog to the listing
*
*/
void BlueBase::addSearchedDevices( const QValueList<RemoteDevice> &newDevices ) {
- BTListItem * deviceItem;
+ BTDeviceItem * deviceItem;
QValueList<RemoteDevice>::ConstIterator it;
for( it = newDevices.begin(); it != newDevices.end() ; ++it ) {
- deviceItem = new BTListItem( ListView2 , (*it).name(), (*it).mac(), "device" );
+
+ deviceItem = new BTDeviceItem( ListView2 , (*it) );
deviceItem->setExpandable ( true );
// look if device is avail. atm, async
deviceActive( (*it) );
// ggf auch hier?
addServicesToDevice( deviceItem );
}
}
/**
* Action that is toggled on entrys on click
*/
void BlueBase::startServiceActionClicked( QListViewItem */*item*/ ) {
}
/**
* Action that are toggled on hold (mostly QPopups i guess)
*/
void BlueBase::startServiceActionHold( QListViewItem * item, const QPoint & point, int /*column*/ ) {
QPopupMenu *menu = new QPopupMenu();
int ret=0;
if ( ((BTListItem*)item)->type() == "device") {
QPopupMenu *groups = new QPopupMenu();
menu->insertItem( tr("rescan sevices:"), 0);
menu->insertItem( tr("to group"), groups , 1);
menu->insertItem( tr("bound device"), 2);
menu->insertItem( tr("delete"), 3);
ret = menu->exec( point , 0);
switch(ret) {
case 0:
break;
case 1:
break;
case 2:
// make connection
break;
case 3:
// delete childs too
delete item;
break;
}
delete groups;
} else if ( ((BTListItem*)item)->type() == "service") {
menu->insertItem( tr("Test1:"), 0);
menu->insertItem( tr("connect"), 1);
menu->insertItem( tr("delete"), 2);
ret = menu->exec( point , 0);
switch(ret) {
case 0:
break;
case 1:
break;
case 2:
// delete childs too
delete item;
break;
}
}
delete menu;
}
/**
* Search and display avail. services for a device (on expand from device listing)
*
*/
- void BlueBase::addServicesToDevice( BTListItem * item ) {
+ void BlueBase::addServicesToDevice( BTDeviceItem * item ) {
qDebug("addServicesToDevice");
// row of mac adress text(3)
- RemoteDevice device( item->mac(), item->name() );
+ RemoteDevice device = item->remoteDevice();
m_deviceList.insert( item->mac() , item );
// and some time later I get a signal foundServices( const QString& device, Services::ValueList ); back
m_localDevice->searchServices( device );
}
/**
* Overloaded. This one it the one that is connected to the foundServices signal
* @param device the mac address of the remote device
* @param servicesList the list with the service the device has.
*/
void BlueBase::addServicesToDevice( const QString& device, Services::ValueList servicesList ) {
qDebug("fill services list");
- QMap<QString,BTListItem*>::Iterator it;
- BTListItem* deviceItem = 0;
+ QMap<QString,BTDeviceItem*>::Iterator it;
+ BTDeviceItem* deviceItem = 0;
// get the right devices which requested the search
- for( it = m_deviceList.begin(); it != m_deviceList.end(); ++it ) {
- if ( it.key() == device ) {
- deviceItem = it.data();
- }
- }
+ it = m_deviceList.find( device );
+ if( it == m_deviceList.end() )
+ return;
+ deviceItem = it.data();
QValueList<OpieTooth::Services>::Iterator it2;
- BTListItem * serviceItem;
+ BTServiceItem * serviceItem;
if (!servicesList.isEmpty() ) {
// add services
for( it2 = servicesList.begin(); it2 != servicesList.end(); ++it2 ) {
- serviceItem = new BTListItem( deviceItem , (*it2).serviceName() , "" , "service" );
+ serviceItem = new BTServiceItem( deviceItem , (*it2) );
serviceItem->setPixmap( 0, m_iconLoader->serviceIcon( (*it2).classIdList() ) );
}
} else {
- serviceItem = new BTListItem( deviceItem , tr("no services found"), "" , "service" );
+ Services s1;
+ s1.setServiceName( tr("no serives found") );
+ serviceItem = new BTServiceItem( deviceItem, s1 );
}
+ // now remove them from the list
+ m_deviceList.remove( it );
}
/**
* Add the existing connections (pairs) to the connections tab.
* This one triggers the search
*/
void BlueBase::addConnectedDevices() {
m_localDevice->searchConnections();
}
- void BlueBase::addConnectedDevices( Connection::ValueList connectionList ) {
- QValueList<OpieTooth::Connection>::Iterator it;
- BTListItem * connectionItem;
+ void BlueBase::addConnectedDevices( ConnectionState::ValueList connectionList ) {
+ QValueList<OpieTooth::ConnectionState>::Iterator it;
+ BTConnectionItem * connectionItem;
if ( !connectionList.isEmpty() ) {
for (it = connectionList.begin(); it != connectionList.end(); ++it) {
- connectionItem = new BTListItem( ListView4 , (*it).mac() , (*it).mac() , "connection" );
+ connectionItem = new BTConnectionItem( ListView4 , (*it) );
}
} else {
- connectionItem = new BTListItem( ListView4 , tr("No connections found"), "", "connection" );
+ ConnectionState con;
+ con.setMac( tr("No connections found") );
+ connectionItem = new BTConnectionItem( ListView4 , con );
}
// recall connection search after some time
QTimer::singleShot( 20000, this, SLOT( addConnectedDevices() ) );
}
/**
* Find out if a device can currently be reached
*/
void BlueBase::deviceActive( const RemoteDevice &device ) {
// search by mac, async, gets a signal back
+ // We should have a BTDeviceItem there or where does it get added to the map -zecke
m_localDevice->isAvailable( device.mac() );
}
/**
* The signal catcher. Set the avail. status on device.
* @param device - the mac address
* @param connected - if it is avail. or not
*/
void BlueBase::deviceActive( const QString& device, bool connected ) {
qDebug("deviceActive slot");
- QMap<QString,BTListItem*>::Iterator it;
- BTListItem* deviceItem = 0;
+ QMap<QString,BTDeviceItem*>::Iterator it;
+
+ it = m_deviceList.find( device );
+ if( it == m_deviceList.end() )
+ return;
+
+ BTDeviceItem* deviceItem = it.data();
- // get the right devices which requested the search
- for( it = m_deviceList.begin(); it != m_deviceList.end(); ++it ) {
- if ( it.key() == device ) {
- deviceItem = it.data();
- }
- }
if ( connected ) {
deviceItem->setPixmap( 1, m_onPix );
} else {
deviceItem->setPixmap( 1, m_offPix );
}
+ m_deviceList.remove( it );
}
/**
* Open the "scan for devices" dialog
*/
void BlueBase::startScan() {
ScanDialog *scan = new ScanDialog( this, "ScanDialog",
true, WDestructiveClose );
QObject::connect( scan, SIGNAL( selectedDevices( const QValueList<RemoteDevice>& ) ),
this, SLOT( addSearchedDevices( const QValueList<RemoteDevice>& ) ) );
scan->showMaximized();
}
/**
* Set the informations about the local device in information Tab
*/
void BlueBase::setInfo() {
StatusLabel->setText( status() );
}
/**
* Decontructor
*/
BlueBase::~BlueBase() {
writeSavedDevices();
delete m_iconLoader;
}
diff --git a/noncore/net/opietooth/manager/bluebase.h b/noncore/net/opietooth/manager/bluebase.h
index 73fac97..a8f4fe4 100644
--- a/noncore/net/opietooth/manager/bluebase.h
+++ b/noncore/net/opietooth/manager/bluebase.h
@@ -1,85 +1,88 @@
#ifndef BLUEBASE_H
#define BLUEBASE_H
#include <qvariant.h>
#include <qwidget.h>
#include <qscrollview.h>
#include <qsplitter.h>
#include <qlist.h>
#include <qpixmap.h>
#include "bluetoothbase.h"
-#include "btlistitem.h"
+
+#include "btserviceitem.h"
+#include "btdeviceitem.h"
+
#include "bticonloader.h"
#include <remotedevice.h>
#include <manager.h>
class QVBox;
class QHBoxLayout;
class QGridLayout;
class QFrame;
class QLabel;
class QPushButton;
class QTabWidget;
class QCheckBox;
namespace OpieTooth {
class BlueBase : public BluetoothBase {
Q_OBJECT
public:
BlueBase( QWidget* parent = 0, const char* name = 0, WFlags fl = 0 );
~BlueBase();
protected:
private slots:
void startScan();
private:
void readConfig();
void writeConfig();
void readSavedDevices();
void writeSavedDevices();
void writeToHciConfig();
QString status()const;
void initGui();
void setInfo();
Manager *m_localDevice;
- QMap<QString,BTListItem*> m_deviceList;
+ QMap<QString,BTDeviceItem*> m_deviceList;
void deviceActive( const RemoteDevice &device );
QString m_deviceName;
QString m_defaultPasskey;
bool m_useEncryption;
bool m_enableAuthentification;
bool m_enablePagescan;
bool m_enableInquiryscan;
QPixmap m_offPix;
QPixmap m_onPix;
BTIconLoader *m_iconLoader;
private slots:
void addSearchedDevices( const QValueList<RemoteDevice> &newDevices );
- void addServicesToDevice( BTListItem *item );
+ void addServicesToDevice( BTDeviceItem *item );
void addServicesToDevice( const QString& device, Services::ValueList );
void addConnectedDevices();
- void addConnectedDevices( Connection::ValueList );
+ void addConnectedDevices( ConnectionState::ValueList );
void startServiceActionClicked( QListViewItem *item );
void startServiceActionHold( QListViewItem *, const QPoint &, int );
void deviceActive( const QString& mac, bool connected );
void applyConfigChanges();
};
}
#endif
diff --git a/noncore/net/opietooth/manager/btlistitem.cpp b/noncore/net/opietooth/manager/btlistitem.cpp
index 82e7c00..36816f8 100644
--- a/noncore/net/opietooth/manager/btlistitem.cpp
+++ b/noncore/net/opietooth/manager/btlistitem.cpp
@@ -1,61 +1,11 @@
#include "btlistitem.h"
-namespace OpieTooth {
+using namespace OpieTooth;
- BTListItem::BTListItem( QListView * parent ) : QListViewItem( parent ) {
- }
+BTListItem::BTListItem( QListView * parent ) : QListViewItem( parent ) {
+}
- BTListItem::BTListItem( QListViewItem * parent ) : QListViewItem( parent ) {
- }
-
-
- // name, and then mac and then servicetype
- BTListItem::BTListItem( QListView * parent, const QString &name , const QString& mac, const QString& type )
- : QListViewItem( parent, name ){
-
- m_name = name;
- m_mac = mac;
- m_type = type;
-
- }
-
- BTListItem::BTListItem( QListViewItem * parent , const QString& name, const QString& mac, const QString& type )
- : QListViewItem( parent, name ){
-
- m_name = name;
- m_mac = mac;
- m_type = type;
- }
-
-
- void BTListItem::setMac( const QString& mac ) {
- m_mac = mac;
- }
-
- QString BTListItem::mac() const {
- return m_mac;
- }
-
- void BTListItem::setName( const QString& name ) {
- m_name = name;
- }
-
- QString BTListItem::name() const {
- return m_name;
- }
-
- void BTListItem::setType( const QString& type ) {
- m_type = type;
- }
-
- QString BTListItem::type() const {
- return m_type;
- }
-
-
- BTListItem::~BTListItem() {
- }
-
-};
+BTListItem::BTListItem( QListViewItem * parent ) : QListViewItem( parent ) {
+}
diff --git a/noncore/net/opietooth/manager/btlistitem.h b/noncore/net/opietooth/manager/btlistitem.h
index d7ce03b..6b529d1 100644
--- a/noncore/net/opietooth/manager/btlistitem.h
+++ b/noncore/net/opietooth/manager/btlistitem.h
@@ -1,33 +1,18 @@
#ifndef BTLISTITEM_H
#define BTLISTITEM_H
#include <qlistview.h>
namespace OpieTooth {
class BTListItem : public QListViewItem {
-
public:
+ enum Types { Device =0, Service, Connection };
BTListItem( QListView * parent );
BTListItem( QListViewItem * parent );
-
- // name, and then mac and then servicetype
- BTListItem( QListView * , const QString&, const QString&, const QString& );
- BTListItem( QListViewItem * parent , const QString&, const QString& , const QString& );
- ~BTListItem();
-
- void setMac( const QString& );
- QString mac()const;
- void setName( const QString& );
- QString name()const;
- void setType( const QString& );
- QString type()const;
- private:
- QString m_name;
- QString m_mac;
- QString m_type;
-
+ virtual QString type() const = 0;
+ virtual int typeId() const = 0;
};
};
#endif
diff --git a/noncore/net/opietooth/manager/manager.pro b/noncore/net/opietooth/manager/manager.pro
index 4f0ea60..d36b8df2 100644
--- a/noncore/net/opietooth/manager/manager.pro
+++ b/noncore/net/opietooth/manager/manager.pro
@@ -1,27 +1,27 @@
TEMPLATE = app
CONFIG = qt warn_on debug
#CONFIG = qt warn_on release
-HEADERS = popuphelper.h bluebase.h scandialog.h btlistitem.h hciconfwrapper.h bticonloader.h
-SOURCES = popuphelper.cpp main.cpp bluebase.cpp scandialog.cpp btlistitem.cpp hciconfwrapper.cpp bticonloader.cpp
+HEADERS = btconnectionitem.h btdeviceitem.h btserviceitem.h stdpopups.h popuphelper.h bluebase.h scandialog.h btlistitem.h hciconfwrapper.h bticonloader.h
+SOURCES = btconnectionitem.cpp btdeviceitem.cpp btserviceitem.h stdpopups.cpp popuphelper.cpp main.cpp bluebase.cpp scandialog.cpp btlistitem.cpp hciconfwrapper.cpp bticonloader.cpp
INCLUDEPATH += $(OPIEDIR)/include
INCLUDEPATH += $(OPIEDIR)/noncore/net/opietooth/lib
DEPENDPATH += $(OPIEDIR)/include
LIBS += -lqpe -lopietooth -lopie
INTERFACES = bluetoothbase.ui devicedialog.ui
DESTDIR = $(OPIEDIR)/bin
TARGET = bluetooth-manager
TRANSLATIONS = ../../../../i18n/de/bluetooth-manager.ts \
../../../../i18n/en/bluetooth-manager.ts \
../../../../i18n/es/bluetooth-manager.ts \
../../../../i18n/fr/bluetooth-manager.ts \
../../../../i18n/hu/bluetooth-manager.ts \
../../../../i18n/ja/bluetooth-manager.ts \
../../../../i18n/ko/bluetooth-manager.ts \
../../../../i18n/no/bluetooth-manager.ts \
../../../../i18n/pl/bluetooth-manager.ts \
../../../../i18n/pt/bluetooth-manager.ts \
../../../../i18n/pt_BR/bluetooth-manager.ts \
../../../../i18n/sl/bluetooth-manager.ts \
../../../../i18n/zh_CN/bluetooth-manager.ts \
../../../../i18n/zh_TW/bluetooth-manager.ts
diff --git a/noncore/net/opietooth/manager/popuphelper.cpp b/noncore/net/opietooth/manager/popuphelper.cpp
index 2a6dad0..d8404d6 100644
--- a/noncore/net/opietooth/manager/popuphelper.cpp
+++ b/noncore/net/opietooth/manager/popuphelper.cpp
@@ -1,25 +1,28 @@
+#include "stdpopups.h"
+
#include "popuphelper.h"
using namespace OpieTooth;
PopupHelper::PopupHelper() {
init();
}
PopupHelper::~PopupHelper() {
}
void PopupHelper::insert( int id, popupFactory fact ) {
m_map.insert(id, fact );
}
-QPopupMenu* PopupHelper::find( int id ) {
+QPopupMenu* PopupHelper::find( int id, const Services& ser, QListViewItem* item ) {
FactoryMap::Iterator it = m_map.find(id );
if ( it != m_map.end() ) {
popupFactory fact = it.data();
- return (*fact)();
+ return (*fact)(ser, item);
}
return 0l;
}
void PopupHelper::init() {
-
+ insert( 1, newRfcComPopup );
+ insert(2, newObexPushPopup );
}
diff --git a/noncore/net/opietooth/manager/popuphelper.h b/noncore/net/opietooth/manager/popuphelper.h
index 7485f71..7541ac5 100644
--- a/noncore/net/opietooth/manager/popuphelper.h
+++ b/noncore/net/opietooth/manager/popuphelper.h
@@ -1,25 +1,27 @@
#ifndef OPIE_TOOTH_POPUP_HELPER
#define OPIE_TOOTH_POPUP_HELPER
+#include <qlistview.h>
#include <qpopupmenu.h>
#include <qmap.h>
+#include <services.h>
namespace OpieTooth {
- typedef QPopupMenu* (*popupFactory)(void);
+ typedef QPopupMenu* (*popupFactory)(const Services&, QListViewItem*);
typedef QMap<int, popupFactory> FactoryMap;
class PopupHelper {
public:
PopupHelper();
~PopupHelper();
void insert( int id, popupFactory fact );
- QPopupMenu* find( int id );
+ QPopupMenu* find( int id, const Services&, QListViewItem* );
private:
void init();
FactoryMap m_map;
};
};
#endif