summaryrefslogtreecommitdiff
path: root/noncore/net/opietooth/manager/rfcommconfhandler.cpp
authormickeyl <mickeyl>2003-10-29 18:18:19 (UTC)
committer mickeyl <mickeyl>2003-10-29 18:18:19 (UTC)
commit1af1f1d9f398d38a2bc666cd2edff5725da7a770 (patch) (side-by-side diff)
treeb3bb0d90cafc1e933b5b9297a7b2669ce3b184ea /noncore/net/opietooth/manager/rfcommconfhandler.cpp
parent35615947e11575a61456c8483e7f6d67fe59d5ed (diff)
downloadopie-1af1f1d9f398d38a2bc666cd2edff5725da7a770.zip
opie-1af1f1d9f398d38a2bc666cd2edff5725da7a770.tar.gz
opie-1af1f1d9f398d38a2bc666cd2edff5725da7a770.tar.bz2
mrege noncore/net/*
Diffstat (limited to 'noncore/net/opietooth/manager/rfcommconfhandler.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/net/opietooth/manager/rfcommconfhandler.cpp114
1 files changed, 114 insertions, 0 deletions
diff --git a/noncore/net/opietooth/manager/rfcommconfhandler.cpp b/noncore/net/opietooth/manager/rfcommconfhandler.cpp
new file mode 100644
index 0000000..20453e8
--- a/dev/null
+++ b/noncore/net/opietooth/manager/rfcommconfhandler.cpp
@@ -0,0 +1,114 @@
+
+#include <qtextstream.h>
+
+#include "rfcommconfhandler.h"
+
+
+using namespace OpieTooth;
+
+// move to lib
+
+
+RfCommConfObject::RfCommConfObject( int number, QString mac, int channel, QString comment ) {
+ m_number = number;
+ m_mac = mac;
+ m_channel = channel;
+ m_comment = comment;
+ // m_foundEntries = 0;
+}
+
+void RfCommConfObject::setNumber( int number ) {
+ m_number = number;
+}
+
+void RfCommConfObject::setMac( QString mac ) {
+ m_mac = mac;
+}
+
+void RfCommConfObject::setChannel( int channel ) {
+ m_channel = channel;
+}
+
+void RfCommConfObject::setComment( QString comment ) {
+ m_comment = comment;
+}
+
+
+RfCommConfObject::~RfCommConfObject() {
+}
+
+
+RfCommConfHandler::RfCommConfHandler( const QString & filename ) {
+
+ m_filename = filename;
+ load();
+}
+
+RfCommConfHandler::~RfCommConfHandler() {
+
+}
+
+void RfCommConfHandler::save( QMap<QString, RfCommConfObject*> devices ) {
+
+ QFile rfCommConf( "/tmp/test" );
+ QTextStream outStream( &rfCommConf );
+ if ( rfCommConf.open( IO_WriteOnly ) ) {
+
+ QMap<QString, RfCommConfObject*>::Iterator it;
+ 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 << "}\n\n";
+ }
+
+ rfCommConf.close();
+ }
+}
+
+
+QMap<QString, RfCommConfObject*> RfCommConfHandler::foundEntries() {
+ return m_foundEntries;
+}
+
+void RfCommConfHandler::load() {
+
+ QFile rfCommConf( m_filename );
+ if ( rfCommConf.open( IO_ReadOnly ) ) {
+
+ QStringList list;
+ QTextStream inStream( &rfCommConf );
+ list = QStringList::split( "\n", inStream.read() );
+
+ QString number;
+ QString mac;
+ QString channel;
+ QString comment;
+
+ for ( QStringList::Iterator line=list.begin(); line != list.end(); line++ ) {
+
+ QString tmpLine = ( *line ).stripWhiteSpace();
+
+ if ( tmpLine.startsWith("rfcomm") ) {
+ QString number = tmpLine.mid( 6,1 );
+ qDebug( tmpLine );
+ qDebug( "TEST " + number );
+ } 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 );
+ qDebug( "mac" + mac );
+ } else if ( tmpLine.startsWith( "channel" ) ) {
+ channel = tmpLine.mid( 8, 1 );
+ qDebug ( "Channel :" + channel );
+ } else if ( tmpLine.startsWith( "comment" ) ) {
+ comment = tmpLine.mid( 9, tmpLine.find( ';' ) - 9 - 1 );
+ qDebug( "Comment: " + comment );
+ }
+ }
+ rfCommConf.close();
+ }
+ save( m_foundEntries );
+ qDebug( QString( "ENTries: %1").arg( m_foundEntries.count() ) );
+}