author | harlekin <harlekin> | 2002-06-28 12:35:13 (UTC) |
---|---|---|
committer | harlekin <harlekin> | 2002-06-28 12:35:13 (UTC) |
commit | ffcfdb4e932dcbd147b0294aeb70762927cdbc5f (patch) (unidiff) | |
tree | 702174c68e4ab9bceee5e445febd4d9d4baa0661 /noncore/net/opietooth/manager/hciconfwrapper.cpp | |
parent | 9607d7d0953b0fbb128d23d3cb2effa9fe0657c4 (diff) | |
download | opie-ffcfdb4e932dcbd147b0294aeb70762927cdbc5f.zip opie-ffcfdb4e932dcbd147b0294aeb70762927cdbc5f.tar.gz opie-ffcfdb4e932dcbd147b0294aeb70762927cdbc5f.tar.bz2 |
wrapper for hcid.conf
Diffstat (limited to 'noncore/net/opietooth/manager/hciconfwrapper.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/net/opietooth/manager/hciconfwrapper.cpp | 115 |
1 files changed, 115 insertions, 0 deletions
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 @@ | |||
1 | #include "hciconfwrapper.h" | ||
2 | |||
3 | #include <qfile.h> | ||
4 | #include <qtextstream.h> | ||
5 | #include <qstringlist.h> | ||
6 | #include <qregexp.h> | ||
7 | |||
8 | namespace OpieTooth { | ||
9 | |||
10 | |||
11 | HciConfWrapper::HciConfWrapper( const QString &fileName) { | ||
12 | m_fileName = fileName; | ||
13 | } | ||
14 | |||
15 | HciConfWrapper::~HciConfWrapper() { | ||
16 | } | ||
17 | |||
18 | |||
19 | void HciConfWrapper::setPinHelper( QString app ) { | ||
20 | setValue( "pin_helper" , app ); | ||
21 | } | ||
22 | |||
23 | void HciConfWrapper::setName( QString name ) { | ||
24 | qDebug ("NAME : " + name); | ||
25 | setValue( "name" , "\"" + name + "\"" ); | ||
26 | } | ||
27 | |||
28 | void HciConfWrapper::setIscan( bool enable) { | ||
29 | |||
30 | if ( enable ) { | ||
31 | setValue( "iscan" , "enable" ); | ||
32 | } else { | ||
33 | setValue( "iscan" , "disable" ); | ||
34 | } | ||
35 | } | ||
36 | |||
37 | void HciConfWrapper::setPscan( bool enable) { | ||
38 | |||
39 | if ( enable ) { | ||
40 | setValue( "pscan" , "enable" ); | ||
41 | } else { | ||
42 | setValue( "pscan" , "disable" ); | ||
43 | } | ||
44 | } | ||
45 | |||
46 | |||
47 | void HciConfWrapper::setAuth( bool enable) { | ||
48 | |||
49 | if ( enable ) { | ||
50 | setValue( "auth" , "enable" ); | ||
51 | } else { | ||
52 | setValue( "auth" , "disable" ); | ||
53 | } | ||
54 | } | ||
55 | |||
56 | |||
57 | void HciConfWrapper::setEncrypt( bool enable) { | ||
58 | |||
59 | if ( enable ) { | ||
60 | setValue( "encrypt" , "enable" ); | ||
61 | } else { | ||
62 | setValue( "encrypt" , "disable" ); | ||
63 | } | ||
64 | } | ||
65 | |||
66 | |||
67 | void HciConfWrapper::setValue(const QString &key, const QString &value ) { | ||
68 | |||
69 | QFile f( m_fileName ); | ||
70 | QFile f2( m_fileName ); | ||
71 | |||
72 | if ( !f.open( IO_ReadOnly) ) { | ||
73 | qDebug("Could not open readonly"); | ||
74 | return; | ||
75 | } | ||
76 | |||
77 | if ( !f2.open( IO_ReadWrite ) ) { | ||
78 | qDebug("Just readonly - not enough"); | ||
79 | return; | ||
80 | } | ||
81 | |||
82 | QStringList list; | ||
83 | qDebug(m_fileName); | ||
84 | QTextStream stream ( &f); | ||
85 | QTextStream outstream (&f2); | ||
86 | |||
87 | QString str; | ||
88 | while ( !(str=stream.readLine()).isNull() ) { | ||
89 | |||
90 | |||
91 | //qDebug(str); | ||
92 | if( (str.contains(key)) > 0 ) { | ||
93 | qDebug("Found"); | ||
94 | // still need look if its commented out!!! | ||
95 | str.simplifyWhiteSpace(); | ||
96 | qDebug( key ); | ||
97 | if (str.startsWith("#")) { | ||
98 | outstream << (key + " " + value + ";\n"); | ||
99 | } else { | ||
100 | str.replace( QRegExp( "\\s*"+key+"\\s+[^\\s][^;]*;" ), key + " " + value + ";\n"); | ||
101 | } | ||
102 | |||
103 | qDebug( str ); | ||
104 | outstream << str; | ||
105 | } else { | ||
106 | outstream << str + "\n"; | ||
107 | } | ||
108 | } | ||
109 | |||
110 | f.close(); | ||
111 | f2.flush(); | ||
112 | f2.close(); | ||
113 | } | ||
114 | |||
115 | } | ||