summaryrefslogtreecommitdiff
path: root/noncore/net/opietooth/manager/rfcommconfhandler.cpp
Side-by-side diff
Diffstat (limited to 'noncore/net/opietooth/manager/rfcommconfhandler.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/net/opietooth/manager/rfcommconfhandler.cpp98
1 files changed, 71 insertions, 27 deletions
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,42 +88,73 @@ QMap<QString, RfCommConfObject*> 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