Diffstat (limited to 'noncore/net/opietooth/manager/hciconfwrapper.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/net/opietooth/manager/hciconfwrapper.cpp | 74 |
1 files changed, 51 insertions, 23 deletions
diff --git a/noncore/net/opietooth/manager/hciconfwrapper.cpp b/noncore/net/opietooth/manager/hciconfwrapper.cpp index 5f74fee..46eed42 100644 --- a/noncore/net/opietooth/manager/hciconfwrapper.cpp +++ b/noncore/net/opietooth/manager/hciconfwrapper.cpp | |||
@@ -57,56 +57,84 @@ namespace OpieTooth { | |||
57 | void HciConfWrapper::setEncrypt( bool enable) { | 57 | void HciConfWrapper::setEncrypt( bool enable) { |
58 | 58 | ||
59 | if ( enable ) { | 59 | if ( enable ) { |
60 | setValue( "encrypt" , "enable" ); | 60 | setValue( "encrypt" , "enable" ); |
61 | } else { | 61 | } else { |
62 | setValue( "encrypt" , "disable" ); | 62 | setValue( "encrypt" , "disable" ); |
63 | } | 63 | } |
64 | } | 64 | } |
65 | 65 | ||
66 | 66 | ||
67 | void HciConfWrapper::setValue(const QString &key, const QString &value ) { | 67 | void HciConfWrapper::setValue(const QString &key, const QString &value ) { |
68 | 68 | ||
69 | QFile f( m_fileName ); | 69 | if (m_file.isEmpty() ) // load first |
70 | QFile f2( m_fileName ); | ||
71 | |||
72 | if ( !f.open( IO_ReadOnly) ) { | ||
73 | qDebug("Could not open readonly"); | ||
74 | return; | 70 | return; |
75 | } | ||
76 | |||
77 | if ( !f2.open( IO_ReadWrite ) ) { | ||
78 | qDebug("Just readonly - not enough"); | ||
79 | return; | ||
80 | } | ||
81 | 71 | ||
82 | QStringList list; | 72 | QStringList::Iterator it; |
83 | qDebug(m_fileName); | ||
84 | QTextStream stream ( &f); | ||
85 | QTextStream outstream (&f2); | ||
86 | 73 | ||
87 | QString str; | 74 | QString str; |
88 | while ( !(str=stream.readLine()).isNull() ) { | 75 | for (it = m_file.begin(); it != m_file.end(); ++it ) { |
89 | 76 | str = (*it); | |
90 | |||
91 | //qDebug(str); | ||
92 | if( (str.contains(key)) > 0 ) { | 77 | if( (str.contains(key)) > 0 ) { |
93 | qDebug("Found"); | 78 | qDebug("Found"); |
94 | // still need to look if its commented out!!! | 79 | // still need to look if its commented out!!! |
95 | str.simplifyWhiteSpace(); | 80 | str.simplifyWhiteSpace(); |
96 | qDebug( key ); | 81 | qDebug( key ); |
97 | if (str.startsWith("#")) { | 82 | if (str.startsWith("#")) { |
98 | str = (key + " " + value + ";"); | 83 | str = (key + " " + value + ";"); |
99 | } else { | 84 | } else { |
100 | str = str.replace( QRegExp( "\\s*"+key+"\\s+[^\\s][^;]*;" ), key + " " + value + ";"); | 85 | str = str.replace( QRegExp( "\\s*"+key+"\\s+[^\\s][^;]*;" ), key + " " + value + ";"); |
101 | } | 86 | } |
102 | qDebug( str ); | 87 | qDebug( str ); |
88 | it = m_file.remove( it ); | ||
89 | it = m_file.insert( it, str ); | ||
90 | //return; the regexp is too wide -zecke // all set | ||
103 | } | 91 | } |
104 | outstream << str << endl; | ||
105 | } | 92 | } |
106 | 93 | ||
107 | f.close(); | ||
108 | 94 | ||
109 | f2.flush(); | ||
110 | f2.close(); | ||
111 | } | 95 | } |
96 | |||
97 | /** | ||
98 | * This loads the config file and stores it inside | ||
99 | * the m_file | ||
100 | */ | ||
101 | void HciConfWrapper::load() { | ||
102 | qWarning("loaded"); | ||
103 | m_file.clear(); | ||
104 | QFile file( m_fileName ); | ||
105 | if (!file.open( IO_ReadOnly ) ) { | ||
106 | qDebug("Could not open"); | ||
107 | return; | ||
108 | } | ||
109 | |||
110 | /** | ||
111 | * readAll() into a QByteArray | ||
112 | * QStringList::split('\n', array ) | ||
113 | * would this be faster? -zecke | ||
114 | */ | ||
115 | QTextStream stream(&file ); | ||
116 | QString tmp; | ||
117 | while ( !stream.atEnd() ) { | ||
118 | tmp = stream.readLine(); | ||
119 | m_file.append( tmp ); | ||
120 | } | ||
121 | } | ||
122 | void HciConfWrapper::save() { | ||
123 | qWarning("save"); | ||
124 | if (m_file.isEmpty() ) // load first | ||
125 | return; | ||
126 | |||
127 | QFile file( m_fileName ); | ||
128 | if ( !file.open(IO_WriteOnly ) ) { | ||
129 | qWarning("could not open %s", m_fileName.latin1() ); | ||
130 | return; | ||
131 | } | ||
132 | |||
133 | QTextStream stream(&file ); | ||
134 | QStringList::Iterator it; | ||
135 | for ( it = m_file.begin(); it != m_file.end(); ++it ) { | ||
136 | stream << (*it) << endl; | ||
137 | } | ||
138 | qWarning("saved"); | ||
139 | }; | ||
112 | } | 140 | } |