From ffcfdb4e932dcbd147b0294aeb70762927cdbc5f Mon Sep 17 00:00:00 2001 From: harlekin Date: Fri, 28 Jun 2002 12:35:13 +0000 Subject: wrapper for hcid.conf --- diff --git a/noncore/net/opietooth/manager/hciconfwrapper.cpp b/noncore/net/opietooth/manager/hciconfwrapper.cpp new file mode 100644 index 0000000..db6a326 --- a/dev/null +++ b/noncore/net/opietooth/manager/hciconfwrapper.cpp @@ -0,0 +1,115 @@ +#include "hciconfwrapper.h" + +#include +#include +#include +#include + +namespace OpieTooth { + + + HciConfWrapper::HciConfWrapper( const QString &fileName) { + m_fileName = fileName; + } + + HciConfWrapper::~HciConfWrapper() { + } + + + void HciConfWrapper::setPinHelper( QString app ) { + setValue( "pin_helper" , app ); + } + + void HciConfWrapper::setName( QString name ) { + qDebug ("NAME : " + name); + setValue( "name" , "\"" + name + "\"" ); + } + + void HciConfWrapper::setIscan( bool enable) { + + if ( enable ) { + setValue( "iscan" , "enable" ); + } else { + setValue( "iscan" , "disable" ); + } + } + + void HciConfWrapper::setPscan( bool enable) { + + if ( enable ) { + setValue( "pscan" , "enable" ); + } else { + setValue( "pscan" , "disable" ); + } + } + + + void HciConfWrapper::setAuth( bool enable) { + + if ( enable ) { + setValue( "auth" , "enable" ); + } else { + setValue( "auth" , "disable" ); + } + } + + + void HciConfWrapper::setEncrypt( bool enable) { + + if ( enable ) { + setValue( "encrypt" , "enable" ); + } else { + setValue( "encrypt" , "disable" ); + } + } + + + void HciConfWrapper::setValue(const QString &key, const QString &value ) { + + QFile f( m_fileName ); + QFile f2( m_fileName ); + + if ( !f.open( IO_ReadOnly) ) { + qDebug("Could not open readonly"); + return; + } + + if ( !f2.open( IO_ReadWrite ) ) { + qDebug("Just readonly - not enough"); + return; + } + + QStringList list; + qDebug(m_fileName); + QTextStream stream ( &f); + QTextStream outstream (&f2); + + QString str; + while ( !(str=stream.readLine()).isNull() ) { + + + //qDebug(str); + if( (str.contains(key)) > 0 ) { + qDebug("Found"); + // still need look if its commented out!!! + str.simplifyWhiteSpace(); + qDebug( key ); + if (str.startsWith("#")) { + outstream << (key + " " + value + ";\n"); + } else { + str.replace( QRegExp( "\\s*"+key+"\\s+[^\\s][^;]*;" ), key + " " + value + ";\n"); + } + + qDebug( str ); + outstream << str; + } else { + outstream << str + "\n"; + } + } + + f.close(); + f2.flush(); + f2.close(); + } + +} diff --git a/noncore/net/opietooth/manager/hciconfwrapper.h b/noncore/net/opietooth/manager/hciconfwrapper.h new file mode 100644 index 0000000..10738c0 --- a/dev/null +++ b/noncore/net/opietooth/manager/hciconfwrapper.h @@ -0,0 +1,30 @@ +#ifndef HCICONFWRAPPER_H +#define HCICONFWRAPPER_H + +#include + +namespace OpieTooth { + + class HciConfWrapper { + + public: + HciConfWrapper( const QString &fileName ); + ~HciConfWrapper(); + + void setPinHelper( QString app ); + void setName( QString name ); + void setIscan( bool enable ); + void setPscan( bool enable ); + void setAuth( bool enable); + void setEncrypt( bool enable); + + private: + + void setValue(const QString &entry, const QString &value ); + + QString m_fileName; + }; + +} + +#endif -- cgit v0.9.0.2