-rw-r--r-- | noncore/net/opietooth/lib/connection.cpp | 32 | ||||
-rw-r--r-- | noncore/net/opietooth/lib/connection.h | 16 | ||||
-rw-r--r-- | noncore/net/opietooth/lib/manager.cc | 10 | ||||
-rw-r--r-- | noncore/net/opietooth/lib/manager.h | 4 | ||||
-rw-r--r-- | noncore/net/opietooth/manager/bluebase.cpp | 84 | ||||
-rw-r--r-- | noncore/net/opietooth/manager/bluebase.h | 11 | ||||
-rw-r--r-- | noncore/net/opietooth/manager/btlistitem.cpp | 60 | ||||
-rw-r--r-- | noncore/net/opietooth/manager/btlistitem.h | 21 | ||||
-rw-r--r-- | noncore/net/opietooth/manager/manager.pro | 4 | ||||
-rw-r--r-- | noncore/net/opietooth/manager/popuphelper.cpp | 9 | ||||
-rw-r--r-- | noncore/net/opietooth/manager/popuphelper.h | 6 |
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 @@ -2,21 +2,21 @@ #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, @@ -29,57 +29,57 @@ Connection::Connection( bool in, 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; 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 @@ -16,20 +16,20 @@ namespace OpieTooth { * 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 @@ -43,9 +43,9 @@ namespace OpieTooth { * * < 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, @@ -54,9 +54,9 @@ namespace OpieTooth { /** * C'tor for compability with QValueList * QValueList needs this c'tor. */ - Connection(); + ConnectionState(); /** * Set if the connection is incoming or * outgoing @@ -130,13 +130,13 @@ namespace OpieTooth { /** * 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; 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 @@ -253,26 +253,26 @@ void Manager::searchConnections() { *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(); @@ -285,9 +285,9 @@ Connection::ValueList Manager::parseConnections( const QString& out ) { 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() ); 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 @@ -136,9 +136,9 @@ namespace OpieTooth { 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* ); @@ -152,9 +152,9 @@ private slots: 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; 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 @@ -43,8 +43,10 @@ #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 ) { @@ -86,12 +88,15 @@ using namespace OpieTooth; //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(); @@ -183,15 +188,21 @@ using namespace OpieTooth; * */ 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() ); } } @@ -244,13 +255,14 @@ using namespace OpieTooth; * 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) ); @@ -325,12 +337,12 @@ void BlueBase::startServiceActionHold( QListViewItem * item, const QPoint & poin /** * 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 ); } @@ -343,30 +355,33 @@ void BlueBase::startServiceActionHold( QListViewItem * item, const QPoint & poin */ 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 ); } /** @@ -377,19 +392,21 @@ void BlueBase::startServiceActionHold( QListViewItem * item, const QPoint & poin 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() ) ); @@ -399,8 +416,9 @@ void BlueBase::startServiceActionHold( QListViewItem * item, const QPoint & poin * 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() ); } /** @@ -410,23 +428,23 @@ void BlueBase::startServiceActionHold( QListViewItem * item, const QPoint & poin */ 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 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 @@ -9,9 +9,12 @@ #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> @@ -50,9 +53,9 @@ namespace OpieTooth { 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; @@ -68,12 +71,12 @@ namespace OpieTooth { 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(); 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 @@ -5,29 +5,14 @@ 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,9 +1,9 @@ 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 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,5 +1,7 @@ +#include "stdpopups.h" + #include "popuphelper.h" using namespace OpieTooth; @@ -11,15 +13,16 @@ 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,21 +1,23 @@ #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; |