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

hciconfwrapper.cpp

Go to the documentation of this file.
00001 #include "hciconfwrapper.h"
00002 
00003 #include <qfile.h>
00004 #include <qtextstream.h>
00005 #include <qregexp.h>
00006 
00007 #include <opie2/odebug.h>
00008 using namespace Opie::Core;
00009 
00010 namespace OpieTooth {
00011 
00012 
00013     HciConfWrapper::HciConfWrapper( const QString &fileName) {
00014         m_fileName = fileName;
00015     }
00016 
00017     HciConfWrapper::~HciConfWrapper() {
00018     }
00019 
00020 
00021     void HciConfWrapper::setPinHelper( const QString& app  ) {
00022         setValue( "pin_helper"  , app  );
00023     }
00024 
00025     void HciConfWrapper::setName( const QString &name ) {
00026         odebug << "NAME : " << name << oendl;
00027         setValue( "name" , "\"" +  name + "\"" );
00028     }
00029 
00030     void HciConfWrapper::setIscan( bool enable) {
00031 
00032         if ( enable ) {
00033             setValue( "iscan" , "enable" );
00034         } else {
00035             setValue( "iscan" , "disable" );
00036         }
00037     }
00038 
00039     void HciConfWrapper::setPscan( bool enable) {
00040 
00041         if ( enable ) {
00042             setValue( "pscan" , "enable" );
00043         } else {
00044             setValue( "pscan" , "disable" );
00045         }
00046     }
00047 
00048 
00049     void HciConfWrapper::setAuth( bool enable) {
00050 
00051         if ( enable ) {
00052             setValue( "auth" , "enable" );
00053         } else {
00054             setValue( "auth" , "disable" );
00055         }
00056     }
00057 
00058 
00059     void HciConfWrapper::setEncrypt( bool enable) {
00060 
00061         if ( enable ) {
00062             setValue( "encrypt" , "enable" );
00063         } else {
00064             setValue( "encrypt" , "disable" );
00065         }
00066     }
00067 
00068 
00069     void HciConfWrapper::setValue(const QString &key, const  QString &value ) {
00070 
00071         if (m_file.isEmpty() ) // load first
00072             return;
00073 
00074         QStringList::Iterator it;
00075 
00076         QString str;
00077         for (it = m_file.begin(); it != m_file.end(); ++it ) {
00078             str = (*it);
00079             if( (str.contains(key)) > 0 ) {
00080                 odebug << "Found" << oendl;
00081                 // still need to look if its commented out!!!
00082                 str.simplifyWhiteSpace();
00083                 odebug << key << oendl;
00084                 if (str.startsWith("#")) {
00085                     str = (key + " " + value + ";");
00086                 } else {
00087                     str = str.replace( QRegExp( "\\s*"+key+"\\s+[^\\s][^;]*;" ),  key + " " + value + ";");
00088                 }
00089                 odebug << str << oendl;
00090                 it = m_file.remove( it );
00091                 it = m_file.insert( it,  str );
00092                 //return; the regexp is too wide  -zecke // all set
00093             }
00094         }
00095 
00096 
00097     }
00098 
00103     void HciConfWrapper::load() {
00104         owarn << "loaded" << oendl;
00105         m_file.clear();
00106         QFile file( m_fileName );
00107         if (!file.open( IO_ReadOnly ) ) {
00108             odebug << "Could not open" << oendl;
00109             return;
00110         }
00111 
00117             QTextStream stream(&file );
00118             QString tmp;
00119             while ( !stream.atEnd() ) {
00120                 tmp = stream.readLine();
00121                 m_file.append( tmp );
00122             }
00123     }
00124     void HciConfWrapper::save() {
00125         owarn << "save" << oendl;
00126         if (m_file.isEmpty() ) // load first
00127             return;
00128 
00129         QFile file( m_fileName );
00130         if ( !file.open(IO_WriteOnly ) ) {
00131             owarn << "could not open " << m_fileName.latin1() << "" << oendl;
00132             return;
00133         }
00134 
00135         QTextStream stream(&file );
00136         QStringList::Iterator it;
00137         for ( it = m_file.begin(); it != m_file.end(); ++it ) {
00138             stream << (*it) << endl;
00139         }
00140         owarn << "saved" << oendl;
00141     };
00142 }

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