author | harlekin <harlekin> | 2002-06-16 20:21:06 (UTC) |
---|---|---|
committer | harlekin <harlekin> | 2002-06-16 20:21:06 (UTC) |
commit | 5c098847f0fd716c4fe697e5eb314111a4ae5df1 (patch) (side-by-side diff) | |
tree | 590ed709442bf6ba4a28eb242840dcf1de6da756 | |
parent | 8dde6abcd14717bd362248c365fe140efe0f0386 (diff) | |
download | opie-5c098847f0fd716c4fe697e5eb314111a4ae5df1.zip opie-5c098847f0fd716c4fe697e5eb314111a4ae5df1.tar.gz opie-5c098847f0fd716c4fe697e5eb314111a4ae5df1.tar.bz2 |
remoteDevice not removeDevices
-rw-r--r-- | noncore/net/opietooth/lib/manager.cc | 12 | ||||
-rw-r--r-- | noncore/net/opietooth/lib/manager.h | 6 | ||||
-rw-r--r-- | noncore/net/opietooth/lib/remotedevice.cc | 22 | ||||
-rw-r--r-- | noncore/net/opietooth/lib/remotedevice.h | 16 | ||||
-rw-r--r-- | noncore/net/opietooth/manager/bluebase.h | 2 | ||||
-rw-r--r-- | noncore/net/opietooth/manager/scandialog.cpp | 3 | ||||
-rw-r--r-- | noncore/net/opietooth/manager/scandialog.h | 4 |
7 files changed, 33 insertions, 32 deletions
diff --git a/noncore/net/opietooth/lib/manager.cc b/noncore/net/opietooth/lib/manager.cc index 40c1f0a..c454588 100644 --- a/noncore/net/opietooth/lib/manager.cc +++ b/noncore/net/opietooth/lib/manager.cc @@ -1,213 +1,213 @@ #include <opie/oprocess.h> #include "manager.h" using namespace OpieTooth; Manager::Manager( const QString& dev ) : QObject() { qWarning("created"); m_device = dev; m_hcitool = 0; m_sdp = 0; } Manager::Manager( Device* dev ) : QObject() { m_hcitool = 0; m_sdp = 0; } Manager::Manager() : QObject() { m_hcitool = 0; m_sdp = 0; } Manager::~Manager(){ delete m_hcitool; delete m_sdp; } void Manager::setDevice( const QString& dev ){ m_device = dev; } void Manager::setDevice( Device* dev ){ } void Manager::isConnected( const QString& device ){ OProcess* l2ping = new OProcess(); l2ping->setName( device.latin1() ); *l2ping << "l2ping" << "-c1" << device; connect(l2ping, SIGNAL(processExited(OProcess* ) ), this, SLOT(slotProcessExited(OProcess*) ) ); if (!l2ping->start() ) { emit connected( device, false ); delete l2ping; } } void Manager::isConnected( Device* dev ){ } void Manager::searchDevices( const QString& device ){ qWarning("search devices"); OProcess* hcitool = new OProcess(); hcitool->setName( device.isEmpty() ? "hci0" : device.latin1() ); *hcitool << "hcitool" << "scan"; connect( hcitool, SIGNAL(processExited(OProcess*) ) , this, SLOT(slotHCIExited(OProcess* ) ) ); connect( hcitool, SIGNAL(receivedStdout(OProcess*, char*, int ) ), this, SLOT(slotHCIOut(OProcess*, char*, int ) ) ); if (!hcitool->start(OProcess::NotifyOnExit, OProcess::AllOutput) ) { qWarning("could not start"); - RemoteDevices::ValueList list; + 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() ); 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) ) { delete m_sdp; Services::ValueList list; emit foundServices( remDevice, list ); } } -void Manager::searchServices( const RemoteDevices& dev){ +void Manager::searchServices( const RemoteDevice& dev){ searchServices( dev.mac() ); } QString Manager::toDevice( const QString& mac ){ } QString Manager::toMac( const QString &device ){ } void Manager::slotProcessExited(OProcess* proc ) { bool conn= false; if (proc->normalExit() && proc->exitStatus() == 0 ) conn = true; QString name = QString::fromLatin1(proc->name() ); emit connected( name, conn ); delete proc; } void Manager::slotSDPOut(OProcess* proc, char* ch, int len) { QCString str(ch, len+1 ); QMap<QString, QString>::Iterator it; it = m_out.find(proc->name() ); if ( it != m_out.end() ) { QString string = it.data(); string.append( str ); m_out.replace( proc->name(), string ); } } void Manager::slotSDPExited( OProcess* proc) { Services::ValueList list; if (proc->normalExit() ) { QMap<QString, QString>::Iterator it = m_out.find( proc->name() ); if ( it != m_out.end() ) { 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; return list; } void Manager::slotHCIExited(OProcess* proc ) { qWarning("process exited"); - RemoteDevices::ValueList list; + 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 ); } -RemoteDevices::ValueList Manager::parseHCIOutput(const QString& output ) { +RemoteDevice::ValueList Manager::parseHCIOutput(const QString& output ) { qWarning("parseHCI %s", output.latin1() ); - RemoteDevices::ValueList list; + 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() ); - RemoteDevices rem( mac , str.stripWhiteSpace() ); + RemoteDevice rem( mac , str.stripWhiteSpace() ); list.append( rem ); } } return list; } diff --git a/noncore/net/opietooth/lib/manager.h b/noncore/net/opietooth/lib/manager.h index 95e4306..aba70f7 100644 --- a/noncore/net/opietooth/lib/manager.h +++ b/noncore/net/opietooth/lib/manager.h @@ -1,131 +1,131 @@ #ifndef OpieToothManager_H #define OpieToothManager_H #include <qobject.h> #include <qstring.h> #include <qmap.h> #include <qvaluelist.h> #include "remotedevice.h" #include "services.h" class OProcess; namespace OpieTooth { class Device; /** Manager manages a blueZ device (hci0 for example) * with 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 isConnected(const QString& device= QString::null ); /** * same as above */ void isConnected(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 RemoteDevices& ); + void searchServices( const RemoteDevice& ); /*static*/ QString toDevice( const QString& mac ); /*static*/ QString toMac( const QString &device ); signals: // device either mac or dev name // the first device is the device which you access void connected( 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, RemoteDevices::ValueList ); + void foundDevices( const QString& device, RemoteDevice::ValueList ); private slots: void slotProcessExited(OProcess* ); void slotSDPExited(OProcess*); void slotSDPOut(OProcess*, char*, int); void slotHCIExited(OProcess* ); void slotHCIOut(OProcess*, char*, int ); private: Services::ValueList parseSDPOutput( const QString& ); - RemoteDevices::ValueList parseHCIOutput( const QString& ); + RemoteDevice::ValueList parseHCIOutput( const QString& ); OProcess *m_hcitool; OProcess *m_sdp; // not only one QString m_device; QMap<QString, QString> m_out; QMap<QString, QString> m_devices; }; }; #endif diff --git a/noncore/net/opietooth/lib/remotedevice.cc b/noncore/net/opietooth/lib/remotedevice.cc index 0045904..08fb397 100644 --- a/noncore/net/opietooth/lib/remotedevice.cc +++ b/noncore/net/opietooth/lib/remotedevice.cc @@ -1,48 +1,48 @@ #include "remotedevice.h" using namespace OpieTooth; -bool operator==(const RemoteDevices& rem1, const RemoteDevices& rem2){ +bool operator==(const RemoteDevice& rem1, const RemoteDevice& rem2){ if( ( rem1.mac() == rem2.mac() ) && (rem1.name() == rem2.name() ) ) return true; return false; } -RemoteDevices::RemoteDevices(){ +RemoteDevice::RemoteDevice(){ } -RemoteDevices::RemoteDevices(const RemoteDevices& ole ){ +RemoteDevice::RemoteDevice(const RemoteDevice& ole ){ (*this) = ole; } -RemoteDevices::RemoteDevices(const QString &mac, const QString& name ){ +RemoteDevice::RemoteDevice(const QString &mac, const QString& name ){ m_mac = mac; m_name = name; } -RemoteDevices::~RemoteDevices(){ +RemoteDevice::~RemoteDevice(){ } -bool RemoteDevices::isEmpty() const { +bool RemoteDevice::isEmpty() const { if( m_name.isEmpty() && m_mac.isEmpty() ) return true; return false; }; -RemoteDevices& RemoteDevices::operator=( const RemoteDevices& rem1){ +RemoteDevice& RemoteDevice::operator=( const RemoteDevice& rem1){ m_name = rem1.m_name; m_mac = rem1.m_mac; return *this; } -QString RemoteDevices::mac() const { +QString RemoteDevice::mac() const { return m_mac; } -void RemoteDevices::setMac( const QString& mac ){ +void RemoteDevice::setMac( const QString& mac ){ m_mac = mac; } -QString RemoteDevices::name() const{ +QString RemoteDevice::name() const{ return m_name; } -void RemoteDevices::setName( const QString& name ){ +void RemoteDevice::setName( const QString& name ){ m_name = name; } diff --git a/noncore/net/opietooth/lib/remotedevice.h b/noncore/net/opietooth/lib/remotedevice.h index 96a27de..23f98bd 100644 --- a/noncore/net/opietooth/lib/remotedevice.h +++ b/noncore/net/opietooth/lib/remotedevice.h @@ -1,28 +1,28 @@ #ifndef OpieToothRemoteDevice #define OpieToothRemoteDevice #include <qvaluelist.h> namespace OpieTooth{ - class RemoteDevices { + class RemoteDevice { public: - typedef QValueList<RemoteDevices> ValueList; - RemoteDevices(); - RemoteDevices(const RemoteDevices& ); - RemoteDevices(const QString &mac, const QString &name ); - ~RemoteDevices(); - friend bool operator==(const RemoteDevices&, const RemoteDevices&); - RemoteDevices &operator=(const RemoteDevices& ); + typedef QValueList<RemoteDevice> ValueList; + RemoteDevice(); + RemoteDevice(const RemoteDevice& ); + RemoteDevice(const QString &mac, const QString &name ); + ~RemoteDevice(); + friend bool operator==(const RemoteDevice&, const RemoteDevice&); + RemoteDevice &operator=(const RemoteDevice& ); bool isEmpty()const; QString mac()const; void setMac(const QString& mac ); QString name()const; void setName( const QString& name ); private: QString m_name; QString m_mac; }; }; #endif diff --git a/noncore/net/opietooth/manager/bluebase.h b/noncore/net/opietooth/manager/bluebase.h index ae5ce67..5364e51 100644 --- a/noncore/net/opietooth/manager/bluebase.h +++ b/noncore/net/opietooth/manager/bluebase.h @@ -1,61 +1,63 @@ #ifndef BLUEBASE_H #define BLUEBASE_H #include <qvariant.h> #include <qwidget.h> #include <qscrollview.h> #include <qsplitter.h> #include <qlist.h> #include "bluetoothbase.h" +#include <remotedevice.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(); QString getStatus(); void initGui(); QString deviceName; QString defaultPasskey; int useEncryption; int enableAuthentification; int enablePagescan; int enableInquiryscan; private slots: void addSearchedDevices( QList<RemoteDevices> &newDevices ); void applyConfigChanges(); }; } #endif diff --git a/noncore/net/opietooth/manager/scandialog.cpp b/noncore/net/opietooth/manager/scandialog.cpp index 70ea77a..8a7ea01 100644 --- a/noncore/net/opietooth/manager/scandialog.cpp +++ b/noncore/net/opietooth/manager/scandialog.cpp @@ -1,170 +1,169 @@ /* main.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 "scandialog.h" #include <qframe.h> #include <qheader.h> #include <qlabel.h> #include <qlistview.h> #include <qpushbutton.h> #include <qlayout.h> #include <qvariant.h> #include <qtooltip.h> #include <qwhatsthis.h> #include <qprogressbar.h> #include <qlist.h> #include <manager.h> #include <device.h> namespace OpieTooth { #include <remotedevice.h> /* */ ScanDialog::ScanDialog( QWidget* parent, const char* name, bool modal, WFlags fl ) : QDialog( parent, name, modal, fl ) { if ( !name ) setName( "ScanDialog" ); resize( 240, 320 ); setCaption( tr( "Scan for devices" ) ); Frame7 = new QFrame( this, "Frame7" ); Frame7->setGeometry( QRect( 0, 0, 240, 331 ) ); Frame7->setFrameShape( QFrame::StyledPanel ); Frame7->setFrameShadow( QFrame::Raised ); QWidget* privateLayoutWidget = new QWidget( Frame7, "Layout11" ); privateLayoutWidget->setGeometry( QRect( 10, 9, 221, 280 ) ); Layout11 = new QVBoxLayout( privateLayoutWidget ); Layout11->setSpacing( 6 ); Layout11->setMargin( 0 ); progress = new QProgressBar(privateLayoutWidget, "progbar"); progress->setTotalSteps(20); QFrame *buttonFrame = new QFrame(Frame7, ""); StartButton = new QPushButton( buttonFrame, "StartButton" ); StartButton->setText( tr( "Start scan" ) ); StopButton = new QPushButton( buttonFrame, "StopButton" ); StopButton->setText( tr( "Cancel scan" ) ); QHBoxLayout *buttonLayout = new QHBoxLayout(buttonFrame); buttonLayout->addWidget(StartButton); buttonLayout->addWidget(StopButton); ListView1 = new QListView( privateLayoutWidget, "ListView1" ); //ListView1->addColumn( tr( "Add" ) ); ListView1->addColumn( tr( "Add Device" ) ); //ListView1->addColumn( tr( "Type" ) ); Layout11->addWidget( ListView1); Layout11->addWidget(progress); Layout11->addWidget( buttonFrame); localDevice = new Manager( "hci0" ); connect( (QObject*)StartButton, SIGNAL( clicked() ), this, SLOT( startSearch() ) ); connect( (QObject*)StopButton, SIGNAL( clicked() ), this, SLOT( stopSearch() ) ); connect( (QObject*)localDevice, SIGNAL( foundDevices( const QString& , RemoteDevices::ValueList ) ), this, SLOT(fillList(const QString& , RemoteDevices::ValueList ) ) ) ; progressStat = 0; } // hack, make cleaner later void ScanDialog::progressTimer() { progressStat++; if (progressStat++ < 20) { QTimer::singleShot( 1000, this, SLOT(progressTimer() ) ); } progress->setProgress(progressStat++); } void ScanDialog::startSearch() { progress->setProgress(0); progressStat = 0; QCheckListItem *deviceItem2 = new QCheckListItem( ListView1, "Test1", QCheckListItem::CheckBox ); deviceItem2->setText(1, "BLAH" ); progressTimer(); // when finished, it emmite foundDevices() // checken ob initialisiert , qcop ans applet. localDevice->searchDevices(); } void ScanDialog::stopSearch() { } void ScanDialog::fillList(const QString& device, RemoteDevices::ValueList deviceList) { QCheckListItem * deviceItem; RemoteDevices::ValueList::Iterator it; for( it = deviceList.begin(); it != deviceList.end(); ++it ) { deviceItem = new QCheckListItem( ListView1, (*it).name() ); deviceItem->setText(1, (*it).mac() ); } - } /* * Iterates trough the items, and collects the checked items. * Then it emits it, so the manager can connect to the signal to fill the listing. */ void ScanDialog::emitToManager() { if (!ListView1) { return; } QList<RemoteDevices> *deviceList = new QList<RemoteDevices>; QListViewItemIterator it( ListView1 ); for ( ; it.current(); ++it ) { - if ( it.current()->isSelected() ) { + if ( ((QCheckListItem*)it.current())->isOn() ) { RemoteDevices* device = new RemoteDevices( it.current()->text(1), it.current()->text(0)); deviceList->append( device ); } } emit selectedDevices( *deviceList ); } /* * Cleanup */ ScanDialog::~ScanDialog() { emitToManager(); delete localDevice; } } diff --git a/noncore/net/opietooth/manager/scandialog.h b/noncore/net/opietooth/manager/scandialog.h index 4785a62..0ca302a 100644 --- a/noncore/net/opietooth/manager/scandialog.h +++ b/noncore/net/opietooth/manager/scandialog.h @@ -1,77 +1,77 @@ /* main.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. * * * ***************************************************************************/ #ifndef SCANDIALOG_H #define SCANDIALOG_H #include <qvariant.h> #include <qdialog.h> #include <qlist.h> - +#include <remotedevice.h> class QVBoxLayout; class QHBoxLayout; class QGridLayout; class QFrame; class QLabel; class QListView; class QListViewItem; class QPushButton; class QProgressBar; namespace OpieTooth { -#include <remotedevices.h> + class Manager; class Device; class ScanDialog : public QDialog { Q_OBJECT public: ScanDialog( QWidget* parent = 0, const char* name = 0, bool modal = FALSE, WFlags fl = 0 ); ~ScanDialog(); QFrame* Frame7; QProgressBar* progress; QPushButton* StartButton; QPushButton* StopButton; QListView* ListView1; protected: QVBoxLayout* Layout11; private slots: void stopSearch(); void startSearch(); void progressTimer(); void fillList(const QString& device, RemoteDevices::ValueList list); private: void emitToManager(); Manager *localDevice; int progressStat; signals: void selectedDevices(QList<RemoteDevices>&); }; } #endif // SCANDIALOG_H |