author | korovkin <korovkin> | 2006-03-25 18:10:13 (UTC) |
---|---|---|
committer | korovkin <korovkin> | 2006-03-25 18:10:13 (UTC) |
commit | c4f82599db775f52c7e04cce09c7c45ecc89ccfd (patch) (side-by-side diff) | |
tree | 81d48e5363a2135bb6820510ae7f5dee9999e8f2 | |
parent | da3c4a6231882bc56266162415a8d1a2a1bf0293 (diff) | |
download | opie-c4f82599db775f52c7e04cce09c7c45ecc89ccfd.zip opie-c4f82599db775f52c7e04cce09c7c45ecc89ccfd.tar.gz opie-c4f82599db775f52c7e04cce09c7c45ecc89ccfd.tar.bz2 |
Added RFCOMM binding table functionality.
10 files changed, 197 insertions, 80 deletions
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,7 +32,6 @@ 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 ); @@ -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<QString, RfCommConfObject*>::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() ) { QDialog dialog( this, "newdevice", true, WStyle_ContextHelp ); dialog.setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)7, (QSizePolicy::SizeType)7, sizePolicy().hasHeightForWidth())); + QVBoxLayout layout(&dialog); + layout.setSpacing( 0 ); + layout.setMargin( 0 ); - RfcommDialogItem *newDev = new RfcommDialogItem( &dialog ); - newDev->setIdent( i ); - newDev->setMac( mac ); + 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<int, RfcommDialogItem*>::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 ); QMap<QString, RfCommConfObject*>::Iterator it; - it = confHandler->foundEntries().find( QString("%1").arg( i ) ); + 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->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 ); +} +/* + * 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,18 +22,16 @@ namespace OpieTooth { class RfcommAssignDialog: public RfcommAssignDialogBase { - Q_OBJECT - public: - - RfcommAssignDialog( QWidget* parent = 0, const char* name = 0,bool modal = 0, WFlags fl = 0 ); + RfcommAssignDialog(QWidget* parent = 0, const char* name = 0, + bool modal = 0, WFlags fl = 0); ~RfcommAssignDialog(); void loadConfig(); void saveConfig(); - void newDevice( const QString & mac ); + void newDevice( const QString & mac, int channel ); private: QScrollView *m_scrollView; @@ -32,6 +40,8 @@ namespace OpieTooth { 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 <qlineedit.h> #include <qcombobox.h> #include <qgroupbox.h> +#include <qcheckbox.h> 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 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<QString, RfCommConfObject*> 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<QString, RfCommConfObject*>::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,38 +88,67 @@ QMap<QString, RfCommConfObject*> RfCommConfHandler::foundEntries() { } void RfCommConfHandler::load() { - - QFile rfCommConf( m_filename ); + //Keywords + QCString k_rfcomm("rfcomm"); + QCString k_device("device "); + QCString k_channel("channel "); + QCString k_comment("comment "); + QCString k_bind("bind "); + + 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 ); + 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( "channel" ) ) { - channel = tmpLine.mid( 8, 1 ); + } 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( "comment" ) ) { - comment = tmpLine.mid( 9, tmpLine.find( ';' ) - 9 - 1 ); + } 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(); @@ -114,3 +156,5 @@ void RfCommConfHandler::load() { 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 @@ <rect> <x>0</x> <y>0</y> - <width>239</width> + <width>235</width> <height>95</height> </rect> </property> @@ -44,21 +44,53 @@ <property> <name>layoutSpacing</name> </property> - <grid> + <vbox> <property stdset="1"> <name>margin</name> - <number>5</number> + <number>0</number> </property> <property stdset="1"> <name>spacing</name> - <number>5</number> + <number>2</number> </property> - <widget row="0" column="0" > + <widget> <class>QLayoutWidget</class> <property stdset="1"> <name>name</name> <cstring>Layout3</cstring> </property> + <property> + <name>layoutSpacing</name> + </property> + <vbox> + <property stdset="1"> + <name>margin</name> + <number>0</number> + </property> + <property stdset="1"> + <name>spacing</name> + <number>2</number> + </property> + <widget> + <class>QCheckBox</class> + <property stdset="1"> + <name>name</name> + <cstring>m_bind</cstring> + </property> + <property stdset="1"> + <name>text</name> + <string>bind automatically</string> + </property> + </widget> + <widget> + <class>QLayoutWidget</class> + <property stdset="1"> + <name>name</name> + <cstring>Layout3</cstring> + </property> + <property> + <name>layoutSpacing</name> + </property> <hbox> <property stdset="1"> <name>margin</name> @@ -172,7 +204,7 @@ </widget> </hbox> </widget> - <widget row="1" column="0" > + <widget> <class>QLayoutWidget</class> <property stdset="1"> <name>name</name> @@ -214,7 +246,9 @@ </widget> </hbox> </widget> - </grid> + </vbox> + </widget> + </vbox> </widget> </vbox> </widget> 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 ) { |