summaryrefslogtreecommitdiff
path: root/noncore/net/opietooth/manager/hciconfwrapper.cpp
Unidiff
Diffstat (limited to 'noncore/net/opietooth/manager/hciconfwrapper.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/net/opietooth/manager/hciconfwrapper.cpp74
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
@@ -68,25 +68,10 @@ namespace OpieTooth {
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 ) {
@@ -102,11 +87,54 @@ namespace OpieTooth {
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}