Diffstat (limited to 'noncore/net/opietooth/manager/hciconfwrapper.cpp') (more/less context) (show 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 | |||
@@ -66,29 +66,14 @@ namespace OpieTooth { | |||
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!!! |
@@ -100,13 +85,56 @@ namespace OpieTooth { | |||
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 | ||
91 | } | ||
103 | } | 92 | } |
104 | outstream << str << endl; | 93 | |
94 | |||
105 | } | 95 | } |
106 | 96 | ||
107 | f.close(); | 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 | } | ||
108 | 132 | ||
109 | f2.flush(); | 133 | QTextStream stream(&file ); |
110 | f2.close(); | 134 | QStringList::Iterator it; |
135 | for ( it = m_file.begin(); it != m_file.end(); ++it ) { | ||
136 | stream << (*it) << endl; | ||
111 | } | 137 | } |
138 | qWarning("saved"); | ||
139 | }; | ||
112 | } | 140 | } |