From c4f82599db775f52c7e04cce09c7c45ecc89ccfd Mon Sep 17 00:00:00 2001 From: korovkin Date: Sat, 25 Mar 2006 18:10:13 +0000 Subject: Added RFCOMM binding table functionality. --- (limited to 'noncore') diff --git a/noncore/net/opietooth/manager/TODO.txt b/noncore/net/opietooth/manager/TODO.txt index e6bd9b1..76fae68 100644 --- a/noncore/net/opietooth/manager/TODO.txt +++ b/noncore/net/opietooth/manager/TODO.txt @@ -1,5 +1,4 @@ -1. Make bind table edit /etc/bluetooth/rfcomm.conf file. -2. Add an rfcomm port number to the connection dialog. -3. Collect requirements from others. +1. Add an rfcomm port number to the connection dialog. +2. Collect requirements from others. //eof diff --git a/noncore/net/opietooth/manager/btdeviceitem.cpp b/noncore/net/opietooth/manager/btdeviceitem.cpp index fb1b1c1..c112463 100644 --- a/noncore/net/opietooth/manager/btdeviceitem.cpp +++ b/noncore/net/opietooth/manager/btdeviceitem.cpp @@ -7,7 +7,7 @@ using namespace OpieTooth; BTDeviceItem::BTDeviceItem( QListView* parent, const RemoteDevice& dev ) : BTListItem( parent ) { - setText( 0, dev.name() ); + setText( 0, dev.name().utf8() ); m_device = dev; }; BTDeviceItem::~BTDeviceItem() { diff --git a/noncore/net/opietooth/manager/rfcommassigndialogimpl.cpp b/noncore/net/opietooth/manager/rfcommassigndialogimpl.cpp index be720b8..7943deb 100644 --- a/noncore/net/opietooth/manager/rfcommassigndialogimpl.cpp +++ b/noncore/net/opietooth/manager/rfcommassigndialogimpl.cpp @@ -1,3 +1,13 @@ +/* $Id$ */ +/* RFCOMM binding table edit dialog */ +/*************************************************************************** + * * + * 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 "rfcommassigndialogimpl.h" #include "rfcommassigndialogitem.h" @@ -22,17 +32,16 @@ using namespace OpieTooth; RfcommAssignDialog::RfcommAssignDialog( QWidget* parent, const char* name, bool modal, WFlags fl ) : RfcommAssignDialogBase( parent, name, modal, fl ) { - m_range = 5; - m_scrollView = new QScrollView( this ); + m_scrollView = new QScrollView(this); m_scrollView->setResizePolicy( QScrollView::AutoOneFit ); m_scrollView->setHScrollBarMode( QScrollView::AlwaysOff ); - RfcommAssignDialogBaseLayout->addWidget( m_scrollView ); + RfcommAssignDialogBaseLayout->addWidget(m_scrollView); - m_box = new QVBox( m_scrollView->viewport() ); - m_scrollView->addChild( m_box ); + m_box = new QVBox(m_scrollView->viewport()); + m_scrollView->addChild(m_box); confHandler = new RfCommConfHandler( "/etc/bluetooth/rfcomm.conf" ); @@ -48,92 +57,98 @@ RfcommAssignDialog::~RfcommAssignDialog() } -void RfcommAssignDialog::newDevice( const QString & mac ) +void RfcommAssignDialog::newDevice(const QString & mac, int channel) { for ( int i = 0 ; i < m_range; i++ ) { - QMap::Iterator it; - it = confHandler->foundEntries().find( QString("%1").arg( i ) ); + it = confHandler->foundEntries().find(QString::number(i)); // make sure that rfcommX is not assigned yet - if ( it == confHandler->foundEntries().end() ) + if ( it == confHandler->foundEntries().end() ) { QDialog dialog( this, "newdevice", true, WStyle_ContextHelp ); dialog.setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)7, (QSizePolicy::SizeType)7, sizePolicy().hasHeightForWidth())); - - RfcommDialogItem *newDev = new RfcommDialogItem( &dialog ); - newDev->setIdent( i ); - newDev->setMac( mac ); + QVBoxLayout layout(&dialog); + layout.setSpacing( 0 ); + layout.setMargin( 0 ); + + RfcommDialogItem newDev(&dialog); + newDev.setIdent( i ); + newDev.setMac( mac ); + newDev.setChannel( channel ); + layout.addWidget(&newDev); if ( QPEApplication::execDialog( &dialog ) == QDialog::Accepted ) { - RfcommDialogItem *rfcomm = new RfcommDialogItem( m_box ); - m_itemList.insert( i , rfcomm ); + QMap::Iterator it; + it = m_itemList.find( i ); + RfcommDialogItem *rfcomm = it.data(); rfcomm->setIdent( i ); rfcomm->setMac( mac ); - rfcomm->setChannel( newDev->channel() ); - rfcomm->setComment( newDev->comment() ); + rfcomm->setChannel( newDev.channel() ); + rfcomm->setComment( newDev.comment() ); + rfcomm->setBind( newDev.isBind() ); odebug << "New device set up" << oendl; } + break; } } } +/* + * Load rfcomm bind configuration + */ void RfcommAssignDialog::loadConfig() { - - //Config cfg( "bluetoothmanager-rfcommbind" ); - for ( int i = 0 ; i < m_range; i++ ) { - // cfg.setGroup( QString("%1").arg( i ) ); RfcommDialogItem *rfcomm = new RfcommDialogItem( m_box ); - m_itemList.insert( i , rfcomm ); - rfcomm->setIdent( i ); + m_itemList.insert(i, rfcomm); + rfcomm->setIdent(i); QMap::Iterator it; - it = confHandler->foundEntries().find( QString("%1").arg( i ) ); - if ( it != confHandler->foundEntries().end() ) + it = confHandler->foundEntries().find(QString::number(i)); + if (it != confHandler->foundEntries().end()) { - odebug << "Found key in foundEntries() " << oendl; - rfcomm->setMac( it.data()->mac() ); - rfcomm->setChannel( it.data()->channel() ); - rfcomm->setComment( it.data()->comment() ); + rfcomm->setMac(it.data()->mac()); + rfcomm->setChannel(it.data()->channel()); + rfcomm->setComment(it.data()->comment()); + rfcomm->setBind(it.data()->isBind()); } - /* Use rfcomm.conf directly for now - * rfcomm->setMac( cfg.readEntry( "mac", "" ) ); - * rfcomm->setChannel( cfg.readNumEntry( "channel", 1 ) ); - * rfcomm->setComment( cfg.readEntry( "comment", "" ) ); - */ } } +/* + * Save rfcomm bind configuration + */ void RfcommAssignDialog::saveConfig() { - - //Config cfg( "bluetoothmanager-rfcommbind" ); - QMap< int, RfcommDialogItem*>::Iterator it; - QMap< QString, RfCommConfObject*> outMap; for( it = m_itemList.begin(); it != m_itemList.end(); ++it ) { - - //cfg.setGroup( QString("%1").arg( it.key() ) ); RfcommDialogItem *rfcomm = it.data(); - - - outMap.insert( QString( "%1").arg( it.key() ), new RfCommConfObject( it.key(), rfcomm->mac(), rfcomm->channel(), rfcomm->comment() ) ); - - - //cfg.writeEntry( "mac", rfcomm->mac() ); - //cfg.writeEntry( "channel", rfcomm->channel() ); - //cfg.writeEntry( "comment", rfcomm->comment() ); + if (rfcomm->mac().isEmpty()) + continue; + outMap.insert(QString::number(it.key()), + new RfCommConfObject(it.key(), + rfcomm->mac(), rfcomm->channel(), rfcomm->comment(), + rfcomm->isBind())); } + confHandler->save(outMap); +} - confHandler->save( outMap ); - +/* + * Reaction on the OK button + */ +void RfcommAssignDialog::accept() +{ + odebug << "save configuration" << oendl; + saveConfig(); + RfcommAssignDialogBase::accept(); } + +//eof diff --git a/noncore/net/opietooth/manager/rfcommassigndialogimpl.h b/noncore/net/opietooth/manager/rfcommassigndialogimpl.h index 9983632..12cde0e 100644 --- a/noncore/net/opietooth/manager/rfcommassigndialogimpl.h +++ b/noncore/net/opietooth/manager/rfcommassigndialogimpl.h @@ -1,3 +1,13 @@ +/* $Id$ */ +/* RFCOMM binding table edit dialog */ +/*************************************************************************** + * * + * 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 RFCOMMASSIGN #define RFCOMMASSIGN @@ -12,26 +22,26 @@ namespace OpieTooth { class RfcommAssignDialog: public RfcommAssignDialogBase { - - Q_OBJECT - + Q_OBJECT public: + RfcommAssignDialog(QWidget* parent = 0, const char* name = 0, + bool modal = 0, WFlags fl = 0); + ~RfcommAssignDialog(); - RfcommAssignDialog( QWidget* parent = 0, const char* name = 0,bool modal = 0, WFlags fl = 0 ); - ~RfcommAssignDialog(); - - void loadConfig(); - void saveConfig(); + void loadConfig(); + void saveConfig(); - void newDevice( const QString & mac ); + void newDevice( const QString & mac, int channel ); private: - QScrollView *m_scrollView; - // how many rfcomm devices are possible - int m_range; - QMap< int, RfcommDialogItem* > m_itemList; - QVBox *m_box; - RfCommConfHandler *confHandler; + QScrollView *m_scrollView; + // how many rfcomm devices are possible + int m_range; + QMap< int, RfcommDialogItem* > m_itemList; + QVBox *m_box; + RfCommConfHandler *confHandler; + protected slots: + virtual void accept(); }; } diff --git a/noncore/net/opietooth/manager/rfcommassigndialogitem.cpp b/noncore/net/opietooth/manager/rfcommassigndialogitem.cpp index a41f304..472b86c 100644 --- a/noncore/net/opietooth/manager/rfcommassigndialogitem.cpp +++ b/noncore/net/opietooth/manager/rfcommassigndialogitem.cpp @@ -4,6 +4,7 @@ #include #include #include +#include using namespace OpieTooth; @@ -33,6 +34,10 @@ QString RfcommDialogItem::comment() { return m_commentLine->text(); } +bool RfcommDialogItem::isBind() { + return m_bind->isChecked(); +} + void RfcommDialogItem::setIdent( int ident ) { m_ident = ident; m_identLabel->setTitle( QString( "rfcomm%1").arg( ident ) ); @@ -50,4 +55,8 @@ void RfcommDialogItem::setComment( const QString &comment ) { m_commentLine->setText( comment ); } +void RfcommDialogItem::setBind( bool dobind ) { + m_bind->setChecked( dobind ); +} +//eof diff --git a/noncore/net/opietooth/manager/rfcommassigndialogitem.h b/noncore/net/opietooth/manager/rfcommassigndialogitem.h index 34a794f..cc9c8db 100644 --- a/noncore/net/opietooth/manager/rfcommassigndialogitem.h +++ b/noncore/net/opietooth/manager/rfcommassigndialogitem.h @@ -21,11 +21,13 @@ namespace OpieTooth { QString mac(); int channel(); QString comment(); + bool isBind(); - void setIdent( int ident ); + void setIdent( int ident ); void setMac( const QString& mac ); void setChannel( int channel ); void setComment( const QString& comment ); + void setBind(bool dobind); private: diff --git a/noncore/net/opietooth/manager/rfcommconfhandler.cpp b/noncore/net/opietooth/manager/rfcommconfhandler.cpp index f82d2c8..054b446 100644 --- a/noncore/net/opietooth/manager/rfcommconfhandler.cpp +++ b/noncore/net/opietooth/manager/rfcommconfhandler.cpp @@ -11,12 +11,13 @@ using namespace OpieTooth; // move to lib -RfCommConfObject::RfCommConfObject( int number, QString mac, int channel, QString comment ) { +RfCommConfObject::RfCommConfObject(int number, QString mac, int channel, + QString comment, bool bind) { m_number = number; m_mac = mac; m_channel = channel; m_comment = comment; - // m_foundEntries = 0; + m_doBind = bind; } void RfCommConfObject::setNumber( int number ) { @@ -41,7 +42,6 @@ RfCommConfObject::~RfCommConfObject() { RfCommConfHandler::RfCommConfHandler( const QString & filename ) { - m_filename = filename; load(); } @@ -52,19 +52,32 @@ RfCommConfHandler::~RfCommConfHandler() { void RfCommConfHandler::save( QMap devices ) { - QFile rfCommConf( "/tmp/test" ); +//// For debugging purposes +//// QFile rfCommConf( "/mnt/net/opie/bin/rfcomm.conf" ); + QFile rfCommConf( m_filename ); QTextStream outStream( &rfCommConf ); if ( rfCommConf.open( IO_WriteOnly ) ) { - QMap::Iterator it; + outStream << "#\n"; + outStream << "# RFCOMM configuration file.\n"; + outStream << "#\n"; + outStream << "# $Id$\n"; + outStream << "#\n\n"; for( it = devices.begin(); it != devices.end(); ++it ) { outStream << "rfcomm" + QString("%1").arg( it.data()->number() ) + " {\n"; - outStream << " device " + it.data()->mac() + ";\n"; - outStream << " channel " + QString( "%1" ).arg( it.data()->channel() ) + ";\n"; - outStream << " comment \"" + it.data()->comment() + "\";\n"; + outStream << "\t# Automatically bind the device at startup\n"; + outStream << "\tbind " << ((it.data()->isBind())? "yes": "no") << ";\n"; + outStream << "\n"; + outStream << "\t# Bluetooth address of the device\n"; + outStream << "\tdevice " + it.data()->mac() + ";\n"; + outStream << "\n"; + outStream << "\t# RFCOMM channel for the connection\n"; + outStream << "\tchannel\t" + QString( "%1" ).arg( it.data()->channel() ) + ";\n"; + outStream << "\n"; + outStream << "\t# Description of the connection\n"; + outStream << "\tcomment \"" + it.data()->comment() + "\";\n"; outStream << "}\n\n"; } - rfCommConf.close(); } } @@ -75,42 +88,73 @@ QMap RfCommConfHandler::foundEntries() { } void RfCommConfHandler::load() { + //Keywords + QCString k_rfcomm("rfcomm"); + QCString k_device("device "); + QCString k_channel("channel "); + QCString k_comment("comment "); + QCString k_bind("bind "); - QFile rfCommConf( m_filename ); - if ( rfCommConf.open( IO_ReadOnly ) ) { + m_foundEntries.clear(); + QFile rfCommConf(m_filename); //File we read + if (rfCommConf.open(IO_ReadOnly)) { QStringList list; QTextStream inStream( &rfCommConf ); list = QStringList::split( "\n", inStream.read() ); - QString number; QString mac; QString channel; QString comment; + QString bind; + bool bbind; + QString number; - for ( QStringList::Iterator line=list.begin(); line != list.end(); line++ ) { + for (QStringList::Iterator line = list.begin(); + line != list.end(); line++) { - QString tmpLine = ( *line ).stripWhiteSpace(); + QString tmpLine = (*line).simplifyWhiteSpace(); - if ( tmpLine.startsWith("rfcomm") ) { - QString number = tmpLine.mid( 6,1 ); + if (tmpLine.startsWith(k_rfcomm)) { + number = tmpLine.mid( k_rfcomm.length(), 1 ); odebug << tmpLine << oendl; - odebug << "TEST " + number << oendl; + odebug << "device " << number << oendl; } else if ( tmpLine.startsWith( "}" ) ) { - m_foundEntries.insert( number, new RfCommConfObject( number.toInt(), mac, channel.toInt(), comment ) ); - } else if ( tmpLine.startsWith( "device" ) ) { - mac = tmpLine.mid( 7, 17 ); - odebug << "mac" + mac << oendl; - } else if ( tmpLine.startsWith( "channel" ) ) { - channel = tmpLine.mid( 8, 1 ); - odebug << "Channel :" << channel << oendl; - } else if ( tmpLine.startsWith( "comment" ) ) { - comment = tmpLine.mid( 9, tmpLine.find( ';' ) - 9 - 1 ); + m_foundEntries.insert(number, + new RfCommConfObject(number.toInt(), mac, channel.toInt(), + comment, bbind)); + } else if ( tmpLine.startsWith(k_device) ) { + mac = tmpLine.mid(k_device.length(), + tmpLine.find(';') - k_device.length()); + odebug << "mac " + mac << oendl; + } else if ( tmpLine.startsWith(k_channel) ) { + channel = tmpLine.mid(k_channel.length(), + tmpLine.find(';') - k_channel.length()); + odebug << "Channel: " << channel << oendl; + } else if ( tmpLine.startsWith(k_comment) ) { + comment = tmpLine.mid(k_comment.length(), + tmpLine.find(';') - k_comment.length()); + if (comment.left(1) == "\"") + comment.remove(0, 1); + if (comment.right(1) == "\"") + comment.remove(comment.length() - 1, 1); odebug << "Comment: " + comment << oendl; + } else if ( tmpLine.startsWith(k_bind) ) { + bind = tmpLine.mid(k_bind.length(), + tmpLine.find(';') - k_bind.length()); + if (bind == "no") + bbind = false; + else if (bind == "yes") + bbind = true; + else + bbind = true; + odebug << "bind: " + bind << oendl; } } rfCommConf.close(); } - save( m_foundEntries ); + save(m_foundEntries); odebug << QString( "ENTries: %1").arg( m_foundEntries.count() ) << oendl; } + +//eof diff --git a/noncore/net/opietooth/manager/rfcommconfhandler.h b/noncore/net/opietooth/manager/rfcommconfhandler.h index e13c833..46aaa26 100644 --- a/noncore/net/opietooth/manager/rfcommconfhandler.h +++ b/noncore/net/opietooth/manager/rfcommconfhandler.h @@ -11,7 +11,8 @@ namespace OpieTooth { class RfCommConfObject { public: - RfCommConfObject( int number, QString mac, int channel, QString comment ); + RfCommConfObject( int number, QString mac, int channel, QString comment, + bool bind); ~RfCommConfObject(); void setNumber( int number ); @@ -22,9 +23,11 @@ namespace OpieTooth { int channel() { return m_channel; }; void setComment( QString comment ); QString comment() { return m_comment; }; - + bool isBind() { return m_doBind; } + void doBind(bool arg) { m_doBind = arg; } private: + bool m_doBind; int m_number; QString m_mac; int m_channel; diff --git a/noncore/net/opietooth/manager/rfcommdialogitembase.ui b/noncore/net/opietooth/manager/rfcommdialogitembase.ui index dd8f121..43f3269 100644 --- a/noncore/net/opietooth/manager/rfcommdialogitembase.ui +++ b/noncore/net/opietooth/manager/rfcommdialogitembase.ui @@ -11,7 +11,7 @@ 0 0 - 239 + 235 95 @@ -44,177 +44,211 @@ layoutSpacing - + margin - 5 + 0 spacing - 5 + 2 - + QLayoutWidget name Layout3 - + + layoutSpacing + + margin 0 spacing - 6 + 2 - QLabel + QCheckBox name - TextLabel4 + m_bind text - Mac - - - - QLineEdit - - name - m_macAddress + bind automatically - QLabel + QLayoutWidget name - TextLabel5 + Layout3 - - text - Channel + + layoutSpacing - - - QComboBox - - - text - 0 - - - - - text - 1 - - - - - text - 2 + + + margin + 0 - - - - text - 3 + + spacing + 6 - - - - text - 4 - - - - - text - 5 - - - - - text - 6 - - - - - text - 7 - - - - - text - 8 - - - - - text - 9 - - - - - text - 10 - - - - name - m_channelDropdown - - - - - - QLayoutWidget - - name - Layout4 - - - - margin - 0 - - - spacing - 6 - - - QLabel - - name - TextLabel3 - - - sizePolicy - - 1 - 1 - - - - text - Comment: - + + QLabel + + name + TextLabel4 + + + text + Mac + + + + QLineEdit + + name + m_macAddress + + + + QLabel + + name + TextLabel5 + + + text + Channel + + + + QComboBox + + + text + 0 + + + + + text + 1 + + + + + text + 2 + + + + + text + 3 + + + + + text + 4 + + + + + text + 5 + + + + + text + 6 + + + + + text + 7 + + + + + text + 8 + + + + + text + 9 + + + + + text + 10 + + + + name + m_channelDropdown + + + - QLineEdit + QLayoutWidget name - m_commentLine + Layout4 + + + margin + 0 + + + spacing + 6 + + + QLabel + + name + TextLabel3 + + + sizePolicy + + 1 + 1 + + + + text + Comment: + + + + QLineEdit + + name + m_commentLine + + + - + - + diff --git a/noncore/net/opietooth/manager/rfcpopup.cpp b/noncore/net/opietooth/manager/rfcpopup.cpp index 7711f0a..04da19f 100644 --- a/noncore/net/opietooth/manager/rfcpopup.cpp +++ b/noncore/net/opietooth/manager/rfcpopup.cpp @@ -105,7 +105,8 @@ void RfcCommPopup::slotBind() { RfcommAssignDialog rfcommAssign ( this, "RfcommAssignDialog", true, WStyle_ContextHelp ); - rfcommAssign.newDevice( m_item->mac() ); + rfcommAssign.newDevice( m_item->mac(), + m_service.protocolDescriptorList().last().port()); if ( QPEApplication::execDialog( &rfcommAssign ) == QDialog::Accepted ) { -- cgit v0.9.0.2