-rw-r--r-- | noncore/net/opietooth/manager/hciconfwrapper.cpp | 18 | ||||
-rw-r--r-- | noncore/net/opietooth/manager/rfcommconfhandler.cpp | 12 |
2 files changed, 15 insertions, 15 deletions
diff --git a/noncore/net/opietooth/manager/hciconfwrapper.cpp b/noncore/net/opietooth/manager/hciconfwrapper.cpp index ca2e7bd..47e170e 100644 --- a/noncore/net/opietooth/manager/hciconfwrapper.cpp +++ b/noncore/net/opietooth/manager/hciconfwrapper.cpp | |||
@@ -2,49 +2,49 @@ | |||
2 | 2 | ||
3 | #include <qfile.h> | 3 | #include <qfile.h> |
4 | #include <qtextstream.h> | 4 | #include <qtextstream.h> |
5 | #include <qregexp.h> | 5 | #include <qregexp.h> |
6 | 6 | ||
7 | #include <opie2/odebug.h> | 7 | #include <opie2/odebug.h> |
8 | using namespace Opie::Core; | 8 | using namespace Opie::Core; |
9 | 9 | ||
10 | namespace OpieTooth { | 10 | namespace OpieTooth { |
11 | 11 | ||
12 | 12 | ||
13 | HciConfWrapper::HciConfWrapper( const QString &fileName) { | 13 | HciConfWrapper::HciConfWrapper( const QString &fileName) { |
14 | m_fileName = fileName; | 14 | m_fileName = fileName; |
15 | } | 15 | } |
16 | 16 | ||
17 | HciConfWrapper::~HciConfWrapper() { | 17 | HciConfWrapper::~HciConfWrapper() { |
18 | } | 18 | } |
19 | 19 | ||
20 | 20 | ||
21 | void HciConfWrapper::setPinHelper( const QString& app ) { | 21 | void HciConfWrapper::setPinHelper( const QString& app ) { |
22 | setValue( "pin_helper" , app ); | 22 | setValue( "pin_helper" , app ); |
23 | } | 23 | } |
24 | 24 | ||
25 | void HciConfWrapper::setName( const QString &name ) { | 25 | void HciConfWrapper::setName( const QString &name ) { |
26 | qDebug ("NAME : " + name); | 26 | odebug << "NAME : " << name << oendl; |
27 | setValue( "name" , "\"" + name + "\"" ); | 27 | setValue( "name" , "\"" + name + "\"" ); |
28 | } | 28 | } |
29 | 29 | ||
30 | void HciConfWrapper::setIscan( bool enable) { | 30 | void HciConfWrapper::setIscan( bool enable) { |
31 | 31 | ||
32 | if ( enable ) { | 32 | if ( enable ) { |
33 | setValue( "iscan" , "enable" ); | 33 | setValue( "iscan" , "enable" ); |
34 | } else { | 34 | } else { |
35 | setValue( "iscan" , "disable" ); | 35 | setValue( "iscan" , "disable" ); |
36 | } | 36 | } |
37 | } | 37 | } |
38 | 38 | ||
39 | void HciConfWrapper::setPscan( bool enable) { | 39 | void HciConfWrapper::setPscan( bool enable) { |
40 | 40 | ||
41 | if ( enable ) { | 41 | if ( enable ) { |
42 | setValue( "pscan" , "enable" ); | 42 | setValue( "pscan" , "enable" ); |
43 | } else { | 43 | } else { |
44 | setValue( "pscan" , "disable" ); | 44 | setValue( "pscan" , "disable" ); |
45 | } | 45 | } |
46 | } | 46 | } |
47 | 47 | ||
48 | 48 | ||
49 | void HciConfWrapper::setAuth( bool enable) { | 49 | void HciConfWrapper::setAuth( bool enable) { |
50 | 50 | ||
@@ -56,87 +56,87 @@ namespace OpieTooth { | |||
56 | } | 56 | } |
57 | 57 | ||
58 | 58 | ||
59 | void HciConfWrapper::setEncrypt( bool enable) { | 59 | void HciConfWrapper::setEncrypt( bool enable) { |
60 | 60 | ||
61 | if ( enable ) { | 61 | if ( enable ) { |
62 | setValue( "encrypt" , "enable" ); | 62 | setValue( "encrypt" , "enable" ); |
63 | } else { | 63 | } else { |
64 | setValue( "encrypt" , "disable" ); | 64 | setValue( "encrypt" , "disable" ); |
65 | } | 65 | } |
66 | } | 66 | } |
67 | 67 | ||
68 | 68 | ||
69 | void HciConfWrapper::setValue(const QString &key, const QString &value ) { | 69 | void HciConfWrapper::setValue(const QString &key, const QString &value ) { |
70 | 70 | ||
71 | if (m_file.isEmpty() ) // load first | 71 | if (m_file.isEmpty() ) // load first |
72 | return; | 72 | return; |
73 | 73 | ||
74 | QStringList::Iterator it; | 74 | QStringList::Iterator it; |
75 | 75 | ||
76 | QString str; | 76 | QString str; |
77 | for (it = m_file.begin(); it != m_file.end(); ++it ) { | 77 | for (it = m_file.begin(); it != m_file.end(); ++it ) { |
78 | str = (*it); | 78 | str = (*it); |
79 | if( (str.contains(key)) > 0 ) { | 79 | if( (str.contains(key)) > 0 ) { |
80 | odebug << "Found" << oendl; | 80 | odebug << "Found" << oendl; |
81 | // still need to look if its commented out!!! | 81 | // still need to look if its commented out!!! |
82 | str.simplifyWhiteSpace(); | 82 | str.simplifyWhiteSpace(); |
83 | odebug << key << oendl; | 83 | odebug << key << oendl; |
84 | if (str.startsWith("#")) { | 84 | if (str.startsWith("#")) { |
85 | str = (key + " " + value + ";"); | 85 | str = (key + " " + value + ";"); |
86 | } else { | 86 | } else { |
87 | str = str.replace( QRegExp( "\\s*"+key+"\\s+[^\\s][^;]*;" ), key + " " + value + ";"); | 87 | str = str.replace( QRegExp( "\\s*"+key+"\\s+[^\\s][^;]*;" ), key + " " + value + ";"); |
88 | } | 88 | } |
89 | odebug << str << oendl; | 89 | odebug << str << oendl; |
90 | it = m_file.remove( it ); | 90 | it = m_file.remove( it ); |
91 | it = m_file.insert( it, str ); | 91 | it = m_file.insert( it, str ); |
92 | //return; the regexp is too wide -zecke // all set | 92 | //return; the regexp is too wide -zecke // all set |
93 | } | 93 | } |
94 | } | 94 | } |
95 | 95 | ||
96 | 96 | ||
97 | } | 97 | } |
98 | 98 | ||
99 | /** | 99 | /** |
100 | * This loads the config file and stores it inside | 100 | * This loads the config file and stores it inside |
101 | * the m_file | 101 | * the m_file |
102 | */ | 102 | */ |
103 | void HciConfWrapper::load() { | 103 | void HciConfWrapper::load() { |
104 | owarn << "loaded" << oendl; | 104 | owarn << "loaded" << oendl; |
105 | m_file.clear(); | 105 | m_file.clear(); |
106 | QFile file( m_fileName ); | 106 | QFile file( m_fileName ); |
107 | if (!file.open( IO_ReadOnly ) ) { | 107 | if (!file.open( IO_ReadOnly ) ) { |
108 | odebug << "Could not open" << oendl; | 108 | odebug << "Could not open" << oendl; |
109 | return; | 109 | return; |
110 | } | 110 | } |
111 | 111 | ||
112 | /** | 112 | /** |
113 | * readAll() into a QByteArray | 113 | * readAll() into a QByteArray |
114 | * QStringList::split('\n', array ) | 114 | * QStringList::split('\n', array ) |
115 | * would this be faster? -zecke | 115 | * would this be faster? -zecke |
116 | */ | 116 | */ |
117 | QTextStream stream(&file ); | 117 | QTextStream stream(&file ); |
118 | QString tmp; | 118 | QString tmp; |
119 | while ( !stream.atEnd() ) { | 119 | while ( !stream.atEnd() ) { |
120 | tmp = stream.readLine(); | 120 | tmp = stream.readLine(); |
121 | m_file.append( tmp ); | 121 | m_file.append( tmp ); |
122 | } | 122 | } |
123 | } | 123 | } |
124 | void HciConfWrapper::save() { | 124 | void HciConfWrapper::save() { |
125 | owarn << "save" << oendl; | 125 | owarn << "save" << oendl; |
126 | if (m_file.isEmpty() ) // load first | 126 | if (m_file.isEmpty() ) // load first |
127 | return; | 127 | return; |
128 | 128 | ||
129 | QFile file( m_fileName ); | 129 | QFile file( m_fileName ); |
130 | if ( !file.open(IO_WriteOnly ) ) { | 130 | if ( !file.open(IO_WriteOnly ) ) { |
131 | owarn << "could not open " << m_fileName.latin1() << "" << oendl; | 131 | owarn << "could not open " << m_fileName.latin1() << "" << oendl; |
132 | return; | 132 | return; |
133 | } | 133 | } |
134 | 134 | ||
135 | QTextStream stream(&file ); | 135 | QTextStream stream(&file ); |
136 | QStringList::Iterator it; | 136 | QStringList::Iterator it; |
137 | for ( it = m_file.begin(); it != m_file.end(); ++it ) { | 137 | for ( it = m_file.begin(); it != m_file.end(); ++it ) { |
138 | stream << (*it) << endl; | 138 | stream << (*it) << endl; |
139 | } | 139 | } |
140 | owarn << "saved" << oendl; | 140 | owarn << "saved" << oendl; |
141 | }; | 141 | }; |
142 | } | 142 | } |
diff --git a/noncore/net/opietooth/manager/rfcommconfhandler.cpp b/noncore/net/opietooth/manager/rfcommconfhandler.cpp index 1f7ba65..f82d2c8 100644 --- a/noncore/net/opietooth/manager/rfcommconfhandler.cpp +++ b/noncore/net/opietooth/manager/rfcommconfhandler.cpp | |||
@@ -73,44 +73,44 @@ void RfCommConfHandler::save( QMap<QString, RfCommConfObject*> devices ) { | |||
73 | QMap<QString, RfCommConfObject*> RfCommConfHandler::foundEntries() { | 73 | QMap<QString, RfCommConfObject*> RfCommConfHandler::foundEntries() { |
74 | return m_foundEntries; | 74 | return m_foundEntries; |
75 | } | 75 | } |
76 | 76 | ||
77 | void RfCommConfHandler::load() { | 77 | void RfCommConfHandler::load() { |
78 | 78 | ||
79 | QFile rfCommConf( m_filename ); | 79 | QFile rfCommConf( m_filename ); |
80 | if ( rfCommConf.open( IO_ReadOnly ) ) { | 80 | if ( rfCommConf.open( IO_ReadOnly ) ) { |
81 | 81 | ||
82 | QStringList list; | 82 | QStringList list; |
83 | QTextStream inStream( &rfCommConf ); | 83 | QTextStream inStream( &rfCommConf ); |
84 | list = QStringList::split( "\n", inStream.read() ); | 84 | list = QStringList::split( "\n", inStream.read() ); |
85 | 85 | ||
86 | QString number; | 86 | QString number; |
87 | QString mac; | 87 | QString mac; |
88 | QString channel; | 88 | QString channel; |
89 | QString comment; | 89 | QString comment; |
90 | 90 | ||
91 | for ( QStringList::Iterator line=list.begin(); line != list.end(); line++ ) { | 91 | for ( QStringList::Iterator line=list.begin(); line != list.end(); line++ ) { |
92 | 92 | ||
93 | QString tmpLine = ( *line ).stripWhiteSpace(); | 93 | QString tmpLine = ( *line ).stripWhiteSpace(); |
94 | 94 | ||
95 | if ( tmpLine.startsWith("rfcomm") ) { | 95 | if ( tmpLine.startsWith("rfcomm") ) { |
96 | QString number = tmpLine.mid( 6,1 ); | 96 | QString number = tmpLine.mid( 6,1 ); |
97 | odebug << tmpLine << oendl; | 97 | odebug << tmpLine << oendl; |
98 | odebug << "TEST " + number << oendl; | 98 | odebug << "TEST " + number << oendl; |
99 | } else if ( tmpLine.startsWith( "}" ) ) { | 99 | } else if ( tmpLine.startsWith( "}" ) ) { |
100 | m_foundEntries.insert( number, new RfCommConfObject( number.toInt(), mac, channel.toInt(), comment ) ); | 100 | m_foundEntries.insert( number, new RfCommConfObject( number.toInt(), mac, channel.toInt(), comment ) ); |
101 | } else if ( tmpLine.startsWith( "device" ) ) { | 101 | } else if ( tmpLine.startsWith( "device" ) ) { |
102 | mac = tmpLine.mid( 7, 17 ); | 102 | mac = tmpLine.mid( 7, 17 ); |
103 | odebug << "mac" + mac << oendl; | 103 | odebug << "mac" + mac << oendl; |
104 | } else if ( tmpLine.startsWith( "channel" ) ) { | 104 | } else if ( tmpLine.startsWith( "channel" ) ) { |
105 | channel = tmpLine.mid( 8, 1 ); | 105 | channel = tmpLine.mid( 8, 1 ); |
106 | qDebug ( "Channel :" + channel ); | 106 | odebug << "Channel :" << channel << oendl; |
107 | } else if ( tmpLine.startsWith( "comment" ) ) { | 107 | } else if ( tmpLine.startsWith( "comment" ) ) { |
108 | comment = tmpLine.mid( 9, tmpLine.find( ';' ) - 9 - 1 ); | 108 | comment = tmpLine.mid( 9, tmpLine.find( ';' ) - 9 - 1 ); |
109 | odebug << "Comment: " + comment << oendl; | 109 | odebug << "Comment: " + comment << oendl; |
110 | } | 110 | } |
111 | } | 111 | } |
112 | rfCommConf.close(); | 112 | rfCommConf.close(); |
113 | } | 113 | } |
114 | save( m_foundEntries ); | 114 | save( m_foundEntries ); |
115 | odebug << QString( "ENTries: %1").arg( m_foundEntries.count() ) << oendl; | 115 | odebug << QString( "ENTries: %1").arg( m_foundEntries.count() ) << oendl; |
116 | } | 116 | } |