-rw-r--r-- | noncore/net/opietooth/manager/hciconfwrapper.cpp | 45 | ||||
-rw-r--r-- | noncore/net/opietooth/manager/hciconfwrapper.h | 10 |
2 files changed, 43 insertions, 12 deletions
diff --git a/noncore/net/opietooth/manager/hciconfwrapper.cpp b/noncore/net/opietooth/manager/hciconfwrapper.cpp index 47e170e..2413f2b 100644 --- a/noncore/net/opietooth/manager/hciconfwrapper.cpp +++ b/noncore/net/opietooth/manager/hciconfwrapper.cpp | |||
@@ -1,8 +1,18 @@ | |||
1 | /* $Id$ */ | ||
2 | /* hcid.conf parser */ | ||
3 | /*************************************************************************** | ||
4 | * * | ||
5 | * This program is free software; you can redistribute it and/or modify * | ||
6 | * it under the terms of the GNU General Public License as published by * | ||
7 | * the Free Software Foundation; either version 2 of the License, or * | ||
8 | * (at your option) any later version. * | ||
9 | * * | ||
10 | ***************************************************************************/ | ||
1 | #include "hciconfwrapper.h" | 11 | #include "hciconfwrapper.h" |
2 | 12 | ||
3 | #include <qfile.h> | 13 | #include <qfile.h> |
4 | #include <qtextstream.h> | 14 | #include <qtextstream.h> |
5 | #include <qregexp.h> | 15 | #include <qregexp.h> |
6 | 16 | ||
7 | #include <opie2/odebug.h> | 17 | #include <opie2/odebug.h> |
8 | using namespace Opie::Core; | 18 | using namespace Opie::Core; |
@@ -45,18 +55,20 @@ namespace OpieTooth { | |||
45 | } | 55 | } |
46 | } | 56 | } |
47 | 57 | ||
48 | 58 | ||
49 | void HciConfWrapper::setAuth( bool enable) { | 59 | void HciConfWrapper::setAuth( bool enable) { |
50 | 60 | ||
51 | if ( enable ) { | 61 | if ( enable ) { |
52 | setValue( "auth" , "enable" ); | 62 | setValue( "auth" , "enable" ); |
63 | setValue( "security" , "auto" ); | ||
53 | } else { | 64 | } else { |
54 | setValue( "auth" , "disable" ); | 65 | setValue( "auth" , "disable" ); |
66 | setValue( "security" , "none" ); | ||
55 | } | 67 | } |
56 | } | 68 | } |
57 | 69 | ||
58 | 70 | ||
59 | void HciConfWrapper::setEncrypt( bool enable) { | 71 | void HciConfWrapper::setEncrypt( bool enable) { |
60 | 72 | ||
61 | if ( enable ) { | 73 | if ( enable ) { |
62 | setValue( "encrypt" , "enable" ); | 74 | setValue( "encrypt" , "enable" ); |
@@ -69,36 +81,45 @@ namespace OpieTooth { | |||
69 | void HciConfWrapper::setValue(const QString &key, const QString &value ) { | 81 | void HciConfWrapper::setValue(const QString &key, const QString &value ) { |
70 | 82 | ||
71 | if (m_file.isEmpty() ) // load first | 83 | if (m_file.isEmpty() ) // load first |
72 | return; | 84 | return; |
73 | 85 | ||
74 | QStringList::Iterator it; | 86 | QStringList::Iterator it; |
75 | 87 | ||
76 | QString str; | 88 | QString str; |
89 | QString tmpLine; | ||
90 | bool wasCommented = false; //If the optin string was commented out | ||
91 | QRegExp rx1("^" + key + "[ ]+"); //Regexp fo key searching | ||
92 | QRegExp rx2(";[ ]*" + key + "[ ]+"); //Regexp fo key searching | ||
77 | for (it = m_file.begin(); it != m_file.end(); ++it ) { | 93 | for (it = m_file.begin(); it != m_file.end(); ++it ) { |
94 | wasCommented = false; | ||
78 | str = (*it); | 95 | str = (*it); |
79 | if( (str.contains(key)) > 0 ) { | 96 | tmpLine = str.simplifyWhiteSpace(); |
80 | odebug << "Found" << oendl; | 97 | //If it's commented out, remove the comment and check again |
81 | // still need to look if its commented out!!! | 98 | //Now, let's check if this is a real keyword (not word_keyword) |
82 | str.simplifyWhiteSpace(); | 99 | if (tmpLine.startsWith("#")) { |
83 | odebug << key << oendl; | 100 | tmpLine.remove(0, 1); |
84 | if (str.startsWith("#")) { | 101 | tmpLine = tmpLine.simplifyWhiteSpace(); |
85 | str = (key + " " + value + ";"); | 102 | wasCommented = true; |
86 | } else { | 103 | } |
87 | str = str.replace( QRegExp( "\\s*"+key+"\\s+[^\\s][^;]*;" ), key + " " + value + ";"); | 104 | if( (tmpLine.contains(rx1)) > 0 || (tmpLine.contains(rx2)) > 0) { |
88 | } | 105 | odebug << "Found " + key << oendl; |
106 | |||
107 | if (wasCommented) | ||
108 | str = ("\t" + key + " " + value + ";"); | ||
109 | else | ||
110 | str = str.replace(QRegExp("\\s*" + key + "\\s+[^\\s][^;]*;"), | ||
111 | "\t" + key + " " + value + ";"); | ||
89 | odebug << str << oendl; | 112 | odebug << str << oendl; |
90 | it = m_file.remove( it ); | 113 | it = m_file.remove( it ); |
91 | it = m_file.insert( it, str ); | 114 | it = m_file.insert( it, str ); |
92 | //return; the regexp is too wide -zecke // all set | 115 | //return; the regexp is too wide -zecke // all set |
93 | } | 116 | } |
94 | } | 117 | } |
95 | |||
96 | |||
97 | } | 118 | } |
98 | 119 | ||
99 | /** | 120 | /** |
100 | * This loads the config file and stores it inside | 121 | * This loads the config file and stores it inside |
101 | * the m_file | 122 | * the m_file |
102 | */ | 123 | */ |
103 | void HciConfWrapper::load() { | 124 | void HciConfWrapper::load() { |
104 | owarn << "loaded" << oendl; | 125 | owarn << "loaded" << oendl; |
diff --git a/noncore/net/opietooth/manager/hciconfwrapper.h b/noncore/net/opietooth/manager/hciconfwrapper.h index 0c4b290..5bf483c 100644 --- a/noncore/net/opietooth/manager/hciconfwrapper.h +++ b/noncore/net/opietooth/manager/hciconfwrapper.h | |||
@@ -1,8 +1,18 @@ | |||
1 | /* $Id$ */ | ||
2 | /* hcid.conf parser */ | ||
3 | /*************************************************************************** | ||
4 | * * | ||
5 | * This program is free software; you can redistribute it and/or modify * | ||
6 | * it under the terms of the GNU General Public License as published by * | ||
7 | * the Free Software Foundation; either version 2 of the License, or * | ||
8 | * (at your option) any later version. * | ||
9 | * * | ||
10 | ***************************************************************************/ | ||
1 | #ifndef HCICONFWRAPPER_H | 11 | #ifndef HCICONFWRAPPER_H |
2 | #define HCICONFWRAPPER_H | 12 | #define HCICONFWRAPPER_H |
3 | 13 | ||
4 | #include <qstring.h> | 14 | #include <qstring.h> |
5 | #include <qstringlist.h> | 15 | #include <qstringlist.h> |
6 | 16 | ||
7 | namespace OpieTooth { | 17 | namespace OpieTooth { |
8 | 18 | ||