author | zecke <zecke> | 2002-07-12 17:14:58 (UTC) |
---|---|---|
committer | zecke <zecke> | 2002-07-12 17:14:58 (UTC) |
commit | 89dce758480cc90502ad14b6c4cf80774e6c1845 (patch) (side-by-side diff) | |
tree | 2ff4e635c8aa86385dfd896084f5cd419efd0840 | |
parent | 716211b5e06bb25145cfbcf62a11a7c52c79dde5 (diff) | |
download | opie-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
-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 | 82 | ||||
-rw-r--r-- | noncore/net/opietooth/manager/bluebase.h | 11 | ||||
-rw-r--r-- | noncore/net/opietooth/manager/btlistitem.cpp | 52 | ||||
-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, 104 insertions, 143 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 @@ -5,3 +5,3 @@ using namespace OpieTooth; -Connection::Connection() { +ConnectionState::ConnectionState() { m_direction = Incoming; @@ -12,3 +12,3 @@ Connection::Connection() { -Connection::Connection( const Connection& con1 ) { +ConnectionState::ConnectionState( const ConnectionState& con1 ) { (*this) = con1; @@ -17,3 +17,3 @@ Connection::Connection( const Connection& con1 ) { -Connection::Connection( bool in, +ConnectionState::ConnectionState( bool in, const QString& conType, @@ -32,3 +32,3 @@ Connection::Connection( bool in, -void Connection::setDirection( bool incoming ) { +void ConnectionState::setDirection( bool incoming ) { m_direction = incoming; @@ -36,3 +36,3 @@ void Connection::setDirection( bool incoming ) { -bool Connection::direction() const { +bool ConnectionState::direction() const { return m_direction; @@ -40,3 +40,3 @@ bool Connection::direction() const { -void Connection::setConnectionMode( const QString& conType ) { +void ConnectionState::setConnectionMode( const QString& conType ) { m_contype = conType; @@ -44,3 +44,3 @@ void Connection::setConnectionMode( const QString& conType ) { -QString Connection::connectionMode() const { +QString ConnectionState::connectionMode() const { return m_contype; @@ -48,3 +48,3 @@ QString Connection::connectionMode() const { -void Connection::setMac( const QString& mac ) { +void ConnectionState::setMac( const QString& mac ) { m_mac = mac; @@ -52,3 +52,3 @@ void Connection::setMac( const QString& mac ) { -QString Connection::mac() const{ +QString ConnectionState::mac() const{ return m_mac; @@ -56,3 +56,3 @@ QString Connection::mac() const{ -void Connection::setHandle( int handle ) { +void ConnectionState::setHandle( int handle ) { m_handle = handle; @@ -60,3 +60,3 @@ void Connection::setHandle( int handle ) { -int Connection::handle() const{ +int ConnectionState::handle() const{ return m_handle; @@ -64,3 +64,3 @@ int Connection::handle() const{ -void Connection::setState( int state ) { +void ConnectionState::setState( int state ) { m_state = state; @@ -68,3 +68,3 @@ void Connection::setState( int state ) { -int Connection::state()const { +int ConnectionState::state()const { return m_state; @@ -72,3 +72,3 @@ int Connection::state()const { -void Connection::setLinkMode( int linkMode ) { +void ConnectionState::setLinkMode( int linkMode ) { m_linkMode = linkMode; @@ -76,3 +76,3 @@ void Connection::setLinkMode( int linkMode ) { -int Connection::linkMode()const{ +int ConnectionState::linkMode()const{ return m_linkMode; @@ -80,3 +80,3 @@ int Connection::linkMode()const{ -Connection &Connection::operator=( const Connection& con1 ) { +ConnectionState &ConnectionState::operator=( const ConnectionState& con1 ) { m_direction = con1.m_direction; 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 @@ -19,3 +19,3 @@ namespace OpieTooth { - class Connection { + class ConnectionState { public: @@ -25,3 +25,3 @@ namespace OpieTooth { */ - typedef QValueList<Connection> ValueList; + typedef QValueList<ConnectionState> ValueList; @@ -30,3 +30,3 @@ namespace OpieTooth { */ - Connection( const Connection& ); + ConnectionState( const ConnectionState& ); @@ -46,3 +46,3 @@ namespace OpieTooth { */ - Connection( bool in, + ConnectionState( bool in, const QString& conType, @@ -57,3 +57,3 @@ namespace OpieTooth { */ - Connection(); + ConnectionState(); @@ -133,7 +133,7 @@ namespace OpieTooth { */ - Connection &operator=( const Connection& ); + ConnectionState &operator=( const ConnectionState& ); private: - class ConnectionPrivate; - ConnectionPrivate *d; + class ConnectionStatePrivate; + ConnectionStatePrivate *d; bool m_direction : 1; 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 @@ -256,3 +256,3 @@ void Manager::searchConnections() { if (!proc->start(OProcess::NotifyOnExit, OProcess::AllOutput) ) { - Connection::ValueList list; + ConnectionState::ValueList list; emit connections( list ); @@ -263,3 +263,3 @@ void Manager::slotConnectionExited( OProcess* /*proc*/ ) { qWarning("exited"); - Connection::ValueList list; + ConnectionState::ValueList list; list = parseConnections( m_hcitoolCon ); @@ -272,4 +272,4 @@ void Manager::slotConnectionOutput(OProcess* proc, char* cha, int len) { } -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 ); @@ -288,3 +288,3 @@ Connection::ValueList Manager::parseConnections( const QString& out ) { qWarning("8: %s", value[8].latin1() ); - Connection con; + ConnectionState con; con.setDirection( value[0] == QString::fromLatin1("<") ? Outgoing : Incoming ); 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 @@ -139,3 +139,3 @@ namespace OpieTooth { void foundDevices( const QString& device, RemoteDevice::ValueList ); - void connections( Connection::ValueList ); + void connections( ConnectionState::ValueList ); @@ -155,3 +155,3 @@ private slots: RemoteDevice::ValueList parseHCIOutput( const QString& ); - Connection::ValueList parseConnections( const QString& ); + ConnectionState::ValueList parseConnections( const QString& ); OProcess *m_hcitool; 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 @@ -46,2 +46,4 @@ +#include "btconnectionitem.h" + using namespace OpieTooth; @@ -89,6 +91,9 @@ using namespace OpieTooth; - 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 ); @@ -186,9 +191,15 @@ using namespace OpieTooth; 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() ); } @@ -247,3 +258,3 @@ using namespace OpieTooth; void BlueBase::addSearchedDevices( const QValueList<RemoteDevice> &newDevices ) { - BTListItem * deviceItem; + BTDeviceItem * deviceItem; QValueList<RemoteDevice>::ConstIterator it; @@ -251,3 +262,4 @@ using namespace OpieTooth; 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 ); @@ -328,6 +340,6 @@ void BlueBase::startServiceActionHold( QListViewItem * item, const QPoint & poin */ - 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 ); @@ -346,14 +358,13 @@ void BlueBase::startServiceActionHold( QListViewItem * item, const QPoint & poin - 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 ) { + it = m_deviceList.find( device ); + if( it == m_deviceList.end() ) + return; deviceItem = it.data(); - } - } QValueList<OpieTooth::Services>::Iterator it2; - BTListItem * serviceItem; + BTServiceItem * serviceItem; @@ -362,3 +373,3 @@ void BlueBase::startServiceActionHold( QListViewItem * item, const QPoint & poin 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() ) ); @@ -366,4 +377,8 @@ void BlueBase::startServiceActionHold( QListViewItem * item, const QPoint & poin } 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 ); } @@ -380,5 +395,5 @@ void BlueBase::startServiceActionHold( QListViewItem * item, const QPoint & poin - 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; @@ -387,6 +402,8 @@ void BlueBase::startServiceActionHold( QListViewItem * item, const QPoint & poin 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 ); } @@ -402,2 +419,3 @@ void BlueBase::startServiceActionHold( QListViewItem * item, const QPoint & poin // 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() ); @@ -413,11 +431,10 @@ void BlueBase::startServiceActionHold( QListViewItem * item, const QPoint & poin - 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(); - } - } @@ -428,2 +445,3 @@ void BlueBase::startServiceActionHold( QListViewItem * item, const QPoint & poin } + m_deviceList.remove( it ); } 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 @@ -12,3 +12,6 @@ #include "bluetoothbase.h" -#include "btlistitem.h" + +#include "btserviceitem.h" +#include "btdeviceitem.h" + #include "bticonloader.h" @@ -53,3 +56,3 @@ namespace OpieTooth { Manager *m_localDevice; - QMap<QString,BTListItem*> m_deviceList; + QMap<QString,BTDeviceItem*> m_deviceList; @@ -71,6 +74,6 @@ namespace OpieTooth { 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 ); 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 @@ -3,3 +3,3 @@ -namespace OpieTooth { +using namespace OpieTooth; @@ -11,51 +11 @@ namespace OpieTooth { } - - - // 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() { - } - -}; 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 @@ -8,23 +8,8 @@ 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; }; 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 @@ -3,4 +3,4 @@ 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 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,2 +1,4 @@ +#include "stdpopups.h" + #include "popuphelper.h" @@ -14,3 +16,3 @@ void PopupHelper::insert( int id, popupFactory fact ) { } -QPopupMenu* PopupHelper::find( int id ) { +QPopupMenu* PopupHelper::find( int id, const Services& ser, QListViewItem* item ) { FactoryMap::Iterator it = m_map.find(id ); @@ -18,3 +20,3 @@ QPopupMenu* PopupHelper::find( int id ) { popupFactory fact = it.data(); - return (*fact)(); + return (*fact)(ser, item); } @@ -23,3 +25,4 @@ QPopupMenu* PopupHelper::find( int id ) { 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 @@ -4,2 +4,3 @@ +#include <qlistview.h> #include <qpopupmenu.h> @@ -7,5 +8,6 @@ +#include <services.h> namespace OpieTooth { - typedef QPopupMenu* (*popupFactory)(void); + typedef QPopupMenu* (*popupFactory)(const Services&, QListViewItem*); typedef QMap<int, popupFactory> FactoryMap; @@ -16,3 +18,3 @@ namespace OpieTooth { void insert( int id, popupFactory fact ); - QPopupMenu* find( int id ); + QPopupMenu* find( int id, const Services&, QListViewItem* ); private: |