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,4 +1,3 @@ -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. 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 @@ -9,3 +9,3 @@ BTDeviceItem::BTDeviceItem( QListView* parent, const RemoteDevice& dev ) - setText( 0, dev.name() ); + setText( 0, dev.name().utf8() ); m_device = dev; 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 +1,11 @@ +/* $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. * + * * + ***************************************************************************/ @@ -24,3 +34,2 @@ RfcommAssignDialog::RfcommAssignDialog( QWidget* parent, const char* name, bool { - m_range = 5; @@ -50,3 +59,3 @@ RfcommAssignDialog::~RfcommAssignDialog() -void RfcommAssignDialog::newDevice( const QString & mac ) +void RfcommAssignDialog::newDevice(const QString & mac, int channel) { @@ -55,5 +64,4 @@ void RfcommAssignDialog::newDevice( const QString & mac ) { - 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 @@ -64,6 +72,11 @@ void RfcommAssignDialog::newDevice( const QString & mac ) (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); @@ -71,10 +84,13 @@ void RfcommAssignDialog::newDevice( const QString & mac ) { - 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; } @@ -83,10 +99,9 @@ void RfcommAssignDialog::newDevice( const QString & mac ) +/* + * 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 ); @@ -95,6 +110,5 @@ void RfcommAssignDialog::loadConfig() 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() ); @@ -102,8 +116,4 @@ void RfcommAssignDialog::loadConfig() 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", "" ) ); - */ } @@ -112,9 +122,8 @@ void RfcommAssignDialog::loadConfig() +/* + * Save rfcomm bind configuration + */ void RfcommAssignDialog::saveConfig() { - - //Config cfg( "bluetoothmanager-rfcommbind" ); - QMap< int, RfcommDialogItem*>::Iterator it; - QMap< QString, RfCommConfObject*> outMap; @@ -123,17 +132,23 @@ void RfcommAssignDialog::saveConfig() { - - //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 +1,11 @@ +/* $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 @@ -14,8 +24,6 @@ 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(); @@ -25,3 +33,3 @@ namespace OpieTooth { - void newDevice( const QString & mac ); + void newDevice( const QString & mac, int channel ); @@ -34,2 +42,4 @@ namespace OpieTooth { 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 @@ -6,2 +6,3 @@ #include <qgroupbox.h> +#include <qcheckbox.h> @@ -35,2 +36,6 @@ QString RfcommDialogItem::comment() { +bool RfcommDialogItem::isBind() { + return m_bind->isChecked(); +} + void RfcommDialogItem::setIdent( int ident ) { @@ -52,2 +57,6 @@ void RfcommDialogItem::setComment( const QString &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 @@ -23,2 +23,3 @@ namespace OpieTooth { QString comment(); + bool isBind(); @@ -28,2 +29,3 @@ namespace OpieTooth { void setComment( const QString& comment ); + void setBind(bool dobind); 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 @@ -13,3 +13,4 @@ using namespace OpieTooth; -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; @@ -18,3 +19,3 @@ RfCommConfObject::RfCommConfObject( int number, QString mac, int channel, QStrin m_comment = comment; - // m_foundEntries = 0; + m_doBind = bind; } @@ -43,3 +44,2 @@ RfCommConfObject::~RfCommConfObject() { RfCommConfHandler::RfCommConfHandler( const QString & filename ) { - m_filename = filename; @@ -54,15 +54,28 @@ 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(); @@ -77,4 +90,11 @@ 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 ) ) { @@ -85,3 +105,2 @@ void RfCommConfHandler::load() { - QString number; QString mac; @@ -89,22 +108,45 @@ void RfCommConfHandler::load() { 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; } @@ -116 +158,3 @@ void RfCommConfHandler::load() { } + +//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 @@ -13,3 +13,4 @@ namespace OpieTooth { public: - RfCommConfObject( int number, QString mac, int channel, QString comment ); + RfCommConfObject( int number, QString mac, int channel, QString comment, + bool bind); ~RfCommConfObject(); @@ -24,5 +25,7 @@ namespace OpieTooth { QString comment() { return m_comment; }; - + bool isBind() { return m_doBind; } + void doBind(bool arg) { m_doBind = arg; } private: + bool m_doBind; int m_number; 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 @@ -13,3 +13,3 @@ <y>0</y> - <width>239</width> + <width>235</width> <height>95</height> @@ -46,6 +46,6 @@ </property> - <grid> + <vbox> <property stdset="1"> <name>margin</name> - <number>5</number> + <number>0</number> </property> @@ -53,5 +53,5 @@ <name>spacing</name> - <number>5</number> + <number>2</number> </property> - <widget row="0" column="0" > + <widget> <class>QLayoutWidget</class> @@ -61,2 +61,34 @@ </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> @@ -174,3 +206,3 @@ </widget> - <widget row="1" column="0" > + <widget> <class>QLayoutWidget</class> @@ -216,3 +248,5 @@ </widget> - </grid> + </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 @@ -107,3 +107,4 @@ void RfcCommPopup::slotBind() - rfcommAssign.newDevice( m_item->mac() ); + rfcommAssign.newDevice( m_item->mac(), + m_service.protocolDescriptorList().last().port()); |