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 | |
parent | 9607d7d0953b0fbb128d23d3cb2effa9fe0657c4 (diff) | |
download | opie-ffcfdb4e932dcbd147b0294aeb70762927cdbc5f.zip opie-ffcfdb4e932dcbd147b0294aeb70762927cdbc5f.tar.gz opie-ffcfdb4e932dcbd147b0294aeb70762927cdbc5f.tar.bz2 |
wrapper for hcid.conf
-rw-r--r-- | noncore/net/opietooth/manager/hciconfwrapper.cpp | 115 | ||||
-rw-r--r-- | noncore/net/opietooth/manager/hciconfwrapper.h | 30 |
2 files changed, 145 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 | } | ||
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 @@ | |||
1 | #ifndef HCICONFWRAPPER_H | ||
2 | #define HCICONFWRAPPER_H | ||
3 | |||
4 | #include <qstring.h> | ||
5 | |||
6 | namespace OpieTooth { | ||
7 | |||
8 | class HciConfWrapper { | ||
9 | |||
10 | public: | ||
11 | HciConfWrapper( const QString &fileName ); | ||
12 | ~HciConfWrapper(); | ||
13 | |||
14 | void setPinHelper( QString app ); | ||
15 | void setName( QString name ); | ||
16 | void setIscan( bool enable ); | ||
17 | void setPscan( bool enable ); | ||
18 | void setAuth( bool enable); | ||
19 | void setEncrypt( bool enable); | ||
20 | |||
21 | private: | ||
22 | |||
23 | void setValue(const QString &entry, const QString &value ); | ||
24 | |||
25 | QString m_fileName; | ||
26 | }; | ||
27 | |||
28 | } | ||
29 | |||
30 | #endif | ||