Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

rfcommconfhandler.cpp

Go to the documentation of this file.
00001 
00002 #include <qtextstream.h>
00003 #include <opie2/odebug.h>
00004 using namespace Opie::Core;
00005 
00006 #include "rfcommconfhandler.h"
00007 
00008 
00009 using namespace OpieTooth;
00010 
00011 // move to lib
00012 
00013 
00014 RfCommConfObject::RfCommConfObject( int number, QString mac, int channel, QString comment ) {
00015     m_number = number;
00016     m_mac = mac;
00017     m_channel = channel;
00018     m_comment = comment;
00019     // m_foundEntries = 0;
00020 }
00021 
00022 void RfCommConfObject::setNumber( int number )  {
00023     m_number = number;
00024 }
00025 
00026 void RfCommConfObject::setMac( QString mac )  {
00027     m_mac = mac;
00028 }
00029 
00030 void RfCommConfObject::setChannel( int channel )  {
00031     m_channel = channel;
00032 }
00033 
00034 void RfCommConfObject::setComment( QString comment )  {
00035     m_comment = comment;
00036 }
00037 
00038 
00039 RfCommConfObject::~RfCommConfObject()  {
00040 }
00041 
00042 
00043 RfCommConfHandler::RfCommConfHandler( const QString & filename ) {
00044 
00045     m_filename = filename;
00046     load();
00047 }
00048 
00049 RfCommConfHandler::~RfCommConfHandler() {
00050 
00051 }
00052 
00053 void RfCommConfHandler::save( QMap<QString, RfCommConfObject*> devices )  {
00054 
00055     QFile rfCommConf( "/tmp/test" );
00056     QTextStream outStream( &rfCommConf );
00057     if (  rfCommConf.open( IO_WriteOnly ) )  {
00058 
00059         QMap<QString,  RfCommConfObject*>::Iterator it;
00060         for( it = devices.begin(); it != devices.end(); ++it )  {
00061             outStream << "rfcomm" + QString("%1").arg( it.data()->number() ) + " {\n";
00062             outStream << "  device " + it.data()->mac() + ";\n";
00063             outStream << "  channel " + QString( "%1" ).arg( it.data()->channel() ) + ";\n";
00064             outStream << "  comment \"" + it.data()->comment() + "\";\n";
00065             outStream << "}\n\n";
00066         }
00067 
00068         rfCommConf.close();
00069     }
00070 }
00071 
00072 
00073 QMap<QString, RfCommConfObject*> RfCommConfHandler::foundEntries()  {
00074     return m_foundEntries;
00075 }
00076 
00077 void RfCommConfHandler::load()  {
00078 
00079     QFile rfCommConf( m_filename );
00080     if ( rfCommConf.open( IO_ReadOnly ) )  {
00081 
00082         QStringList list;
00083         QTextStream inStream( &rfCommConf );
00084         list = QStringList::split( "\n", inStream.read() );
00085 
00086         QString number;
00087         QString mac;
00088         QString channel;
00089         QString comment;
00090 
00091         for ( QStringList::Iterator line=list.begin(); line != list.end(); line++ )  {
00092 
00093             QString tmpLine = ( *line ).stripWhiteSpace();
00094 
00095             if ( tmpLine.startsWith("rfcomm") )  {
00096                 QString number = tmpLine.mid( 6,1 );
00097                 odebug << tmpLine << oendl;
00098                 odebug << "TEST " + number << oendl;
00099             } else if ( tmpLine.startsWith( "}" ) ) {
00100                 m_foundEntries.insert( number, new RfCommConfObject( number.toInt(), mac, channel.toInt(),  comment ) );
00101             } else if ( tmpLine.startsWith( "device" ) )  {
00102                 mac = tmpLine.mid( 7, 17 );
00103                 odebug << "mac" + mac << oendl;
00104             } else if ( tmpLine.startsWith( "channel" ) ) {
00105                 channel = tmpLine.mid( 8, 1 );
00106                 odebug << "Channel :" << channel << oendl;
00107             } else if ( tmpLine.startsWith( "comment" ) ) {
00108                 comment = tmpLine.mid( 9, tmpLine.find( ';' ) - 9 - 1 );
00109                 odebug << "Comment: " + comment << oendl;
00110             }
00111         }
00112         rfCommConf.close();
00113     }
00114     save( m_foundEntries );
00115     odebug << QString( "ENTries: %1").arg( m_foundEntries.count() ) << oendl;
00116 }

Generated on Sat Nov 5 16:17:44 2005 for OPIE by  doxygen 1.4.2