author | zautrix <zautrix> | 2004-10-20 21:49:51 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2004-10-20 21:49:51 (UTC) |
commit | bb235c5a639b914574e1e247d2de6e479517585f (patch) (unidiff) | |
tree | 0f074ec87d93b6f5fb81b6893f0174cabc52c1df /kabc/plugins/qtopia/resourceqtopia.cpp | |
parent | 8e00329a4a5f0b66d26d20f067ab6aefca17f17a (diff) | |
download | kdepimpi-bb235c5a639b914574e1e247d2de6e479517585f.zip kdepimpi-bb235c5a639b914574e1e247d2de6e479517585f.tar.gz kdepimpi-bb235c5a639b914574e1e247d2de6e479517585f.tar.bz2 |
qtopia resource fixes
Diffstat (limited to 'kabc/plugins/qtopia/resourceqtopia.cpp') (more/less context) (show whitespace changes)
-rw-r--r-- | kabc/plugins/qtopia/resourceqtopia.cpp | 96 |
1 files changed, 22 insertions, 74 deletions
diff --git a/kabc/plugins/qtopia/resourceqtopia.cpp b/kabc/plugins/qtopia/resourceqtopia.cpp index b7263bb..4ee3c3c 100644 --- a/kabc/plugins/qtopia/resourceqtopia.cpp +++ b/kabc/plugins/qtopia/resourceqtopia.cpp | |||
@@ -75,17 +75,17 @@ ResourceQtopia::ResourceQtopia( const QString &fileName ) | |||
75 | { | 75 | { |
76 | init( fileName ); | 76 | init( fileName ); |
77 | } | 77 | } |
78 | 78 | ||
79 | void ResourceQtopia::init( const QString &fileName ) | 79 | void ResourceQtopia::init( const QString &fileName ) |
80 | { | 80 | { |
81 | 81 | #ifdef _USE_DIRWATCH_ | |
82 | connect( &mDirWatch, SIGNAL( dirty(const QString&) ), SLOT( fileChanged() ) ); | 82 | connect( &mDirWatch, SIGNAL( dirty(const QString&) ), SLOT( fileChanged() ) ); |
83 | connect( &mDirWatch, SIGNAL( created(const QString&) ), SLOT( fileChanged() ) ); | 83 | connect( &mDirWatch, SIGNAL( created(const QString&) ), SLOT( fileChanged() ) ); |
84 | connect( &mDirWatch, SIGNAL( deleted(const QString&) ), SLOT( fileChanged() ) ); | 84 | connect( &mDirWatch, SIGNAL( deleted(const QString&) ), SLOT( fileChanged() ) ); |
85 | 85 | #endif | |
86 | setFileName( fileName ); | 86 | setFileName( fileName ); |
87 | } | 87 | } |
88 | 88 | ||
89 | ResourceQtopia::~ResourceQtopia() | 89 | ResourceQtopia::~ResourceQtopia() |
90 | { | 90 | { |
91 | if (mConverter != 0) | 91 | if (mConverter != 0) |
@@ -162,13 +162,13 @@ bool ResourceQtopia::load() | |||
162 | bool res; | 162 | bool res; |
163 | QDomElement docElem = doc.documentElement( ); | 163 | QDomElement docElem = doc.documentElement( ); |
164 | QDomNode n = docElem.firstChild(); | 164 | QDomNode n = docElem.firstChild(); |
165 | while ( !n.isNull() ) { | 165 | while ( !n.isNull() ) { |
166 | QDomElement e = n.toElement(); | 166 | QDomElement e = n.toElement(); |
167 | if ( !e.isNull() ) { | 167 | if ( !e.isNull() ) { |
168 | if ( e.tagName() == QString::fromLatin1( "Contacts" ) ) { // we're looking for them | 168 | if ( e.tagName() == QString::fromLatin1( "Contacts" ) ) { |
169 | QDomNode no = e.firstChild(); | 169 | QDomNode no = e.firstChild(); |
170 | while ( !no.isNull() ) { | 170 | while ( !no.isNull() ) { |
171 | QDomElement el = no.toElement(); | 171 | QDomElement el = no.toElement(); |
172 | if ( !el.isNull() ) { | 172 | if ( !el.isNull() ) { |
173 | KABC::Addressee addressee; | 173 | KABC::Addressee addressee; |
174 | res = mConverter->qtopiaToAddressee( el, addressee ); | 174 | res = mConverter->qtopiaToAddressee( el, addressee ); |
@@ -183,47 +183,28 @@ bool ResourceQtopia::load() | |||
183 | } | 183 | } |
184 | } | 184 | } |
185 | } | 185 | } |
186 | 186 | ||
187 | n = n.nextSibling(); | 187 | n = n.nextSibling(); |
188 | } | 188 | } |
189 | |||
190 | #if 0 | ||
191 | / old code | ||
192 | qDebug("ResourceQtopia::load: %s", fileName().latin1()); | ||
193 | |||
194 | AddressBookIterator it(*mAccess); | ||
195 | const PimContact* contact; | ||
196 | bool res; | ||
197 | |||
198 | for (contact=it.toFirst(); it.current(); ++it) | ||
199 | { | ||
200 | contact = it.current(); | ||
201 | |||
202 | KABC::Addressee addressee; | ||
203 | |||
204 | //LRres = mConverter->qtopiaToAddressee( (*contact), addressee ); | ||
205 | |||
206 | if ( !addressee.isEmpty() && res ) | ||
207 | { | ||
208 | addressee.setResource( this ); | ||
209 | addressBook()->insertAddressee( addressee ); | ||
210 | } | ||
211 | } | ||
212 | #endif | ||
213 | return true; | 189 | return true; |
214 | } | 190 | } |
215 | 191 | ||
216 | bool ResourceQtopia::save( Ticket *ticket ) | 192 | bool ResourceQtopia::save( Ticket *ticket ) |
217 | { | 193 | { |
218 | 194 | #ifdef _USE_DIRWATCH_ | |
219 | mDirWatch.stopScan(); | 195 | mDirWatch.stopScan(); |
196 | #endif | ||
220 | KABC::AddressBook::Iterator it; | 197 | KABC::AddressBook::Iterator it; |
221 | bool res; | 198 | bool res; |
222 | //pending open file for stream | 199 | QFile file( fileName() ); |
223 | QTextStream *stream;// = tempFile->textStream(); | 200 | if (!file.open( IO_WriteOnly ) ) { |
201 | return false; | ||
202 | } | ||
203 | QTextStream ts( &file ); | ||
204 | QTextStream *stream = &ts; | ||
224 | stream->setEncoding( QTextStream::UnicodeUTF8 ); | 205 | stream->setEncoding( QTextStream::UnicodeUTF8 ); |
225 | *stream << "<?xml version=\"1.0\" encoding=\"UTF-8\"?><!DOCTYPE Addressbook ><AddressBook>" << endl; | 206 | *stream << "<?xml version=\"1.0\" encoding=\"UTF-8\"?><!DOCTYPE Addressbook ><AddressBook>" << endl; |
226 | *stream << " <Groups>" << endl; | 207 | *stream << " <Groups>" << endl; |
227 | *stream << " </Groups>" << endl; | 208 | *stream << " </Groups>" << endl; |
228 | *stream << " <Contacts> " << endl; | 209 | *stream << " <Contacts> " << endl; |
229 | // for all entries | 210 | // for all entries |
@@ -233,72 +214,33 @@ bool ResourceQtopia::save( Ticket *ticket ) | |||
233 | res = mConverter->addresseeToQtopia( addressee, stream ); | 214 | res = mConverter->addresseeToQtopia( addressee, stream ); |
234 | if (!res == true) | 215 | if (!res == true) |
235 | { | 216 | { |
236 | qDebug("Unable to convert Addressee %s", addressee.formattedName().latin1()); | 217 | qDebug("Unable to convert Addressee %s", addressee.formattedName().latin1()); |
237 | } | 218 | } |
238 | } | 219 | } |
239 | |||
240 | |||
241 | *stream << "</Contacts>" << endl; | 220 | *stream << "</Contacts>" << endl; |
242 | *stream << "</AddressBook>" << endl; | 221 | *stream << "</AddressBook>" << endl; |
243 | //pending close file | 222 | file.close(); |
244 | mDirWatch.startScan(); | 223 | #ifdef _USE_DIRWATCH_ |
245 | |||
246 | delete ticket; | ||
247 | unlock( fileName() ); | ||
248 | |||
249 | |||
250 | #if 0 | ||
251 | //old code | ||
252 | qDebug("ResourceQtopia::save: %s", fileName().latin1()); | ||
253 | |||
254 | mDirWatch.stopScan(); | ||
255 | |||
256 | KABC::AddressBook::Iterator it; | ||
257 | bool res; | ||
258 | |||
259 | for ( it = addressBook()->begin(); it != addressBook()->end(); ++it ) { | ||
260 | PimContact c; | ||
261 | KABC::Addressee addressee = (*it); | ||
262 | |||
263 | //res = mConverter->addresseeToQtopia( *it, c ); | ||
264 | if (res == true) | ||
265 | { | ||
266 | mAccess->addContact(c); | ||
267 | // if (res == false) | ||
268 | // qDebug("Unable to append Contact %s", c.fullName().latin1()); | ||
269 | } | ||
270 | else | ||
271 | { | ||
272 | qDebug("Unable to convert Addressee %s", addressee.formattedName().latin1()); | ||
273 | } | ||
274 | } | ||
275 | |||
276 | // mAccess->addressBookUpdated(); | ||
277 | |||
278 | mDirWatch.startScan(); | 224 | mDirWatch.startScan(); |
279 | 225 | #endif | |
280 | delete ticket; | 226 | delete ticket; |
281 | unlock( fileName() ); | 227 | unlock( fileName() ); |
282 | #endif | ||
283 | return true; | 228 | return true; |
284 | } | 229 | } |
285 | 230 | ||
286 | bool ResourceQtopia::lock( const QString &lockfileName ) | 231 | bool ResourceQtopia::lock( const QString &lockfileName ) |
287 | { | 232 | { |
233 | //disabled | ||
234 | return true; | ||
288 | qDebug("ResourceQtopia::lock: %s", fileName().latin1()); | 235 | qDebug("ResourceQtopia::lock: %s", fileName().latin1()); |
289 | |||
290 | kdDebug(5700) << "ResourceQtopia::lock()" << endl; | ||
291 | |||
292 | QString fn = lockfileName; | 236 | QString fn = lockfileName; |
293 | 237 | ||
294 | KURL url(fn); | 238 | KURL url(fn); |
295 | QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); | 239 | QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); |
296 | 240 | ||
297 | kdDebug(5700) << "-- lock name: " << lockName << endl; | ||
298 | |||
299 | if (QFile::exists( lockName )) | 241 | if (QFile::exists( lockName )) |
300 | { | 242 | { |
301 | qDebug("ResourceOpie::lock: lockfile %s already exists. (Delete it before continuing if nobody else is accessing the resourcefile %s)", lockName.latin1(), fileName().latin1()); | 243 | qDebug("ResourceOpie::lock: lockfile %s already exists. (Delete it before continuing if nobody else is accessing the resourcefile %s)", lockName.latin1(), fileName().latin1()); |
302 | return false; | 244 | return false; |
303 | } | 245 | } |
304 | 246 | ||
@@ -330,12 +272,14 @@ bool ResourceQtopia::lock( const QString &lockfileName ) | |||
330 | 272 | ||
331 | return false; | 273 | return false; |
332 | } | 274 | } |
333 | 275 | ||
334 | void ResourceQtopia::unlock( const QString &fileName ) | 276 | void ResourceQtopia::unlock( const QString &fileName ) |
335 | { | 277 | { |
278 | //disabled | ||
279 | return; | ||
336 | qDebug("ResourceQtopia::unlock() %s", fileName.latin1()); | 280 | qDebug("ResourceQtopia::unlock() %s", fileName.latin1()); |
337 | 281 | ||
338 | QString fn = fileName; | 282 | QString fn = fileName; |
339 | KURL url(fn); | 283 | KURL url(fn); |
340 | QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); | 284 | QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); |
341 | 285 | ||
@@ -343,19 +287,23 @@ void ResourceQtopia::unlock( const QString &fileName ) | |||
343 | QFile::remove( mLockUniqueName ); | 287 | QFile::remove( mLockUniqueName ); |
344 | addressBook()->emitAddressBookUnlocked(); | 288 | addressBook()->emitAddressBookUnlocked(); |
345 | } | 289 | } |
346 | 290 | ||
347 | void ResourceQtopia::setFileName( const QString &newFileName ) | 291 | void ResourceQtopia::setFileName( const QString &newFileName ) |
348 | { | 292 | { |
293 | #ifdef _USE_DIRWATCH_ | ||
349 | mDirWatch.stopScan(); | 294 | mDirWatch.stopScan(); |
295 | #endif | ||
350 | mDirWatch.removeFile( fileName() ); | 296 | mDirWatch.removeFile( fileName() ); |
351 | 297 | ||
352 | Resource::setFileName( newFileName ); | 298 | Resource::setFileName( newFileName ); |
353 | 299 | ||
354 | mDirWatch.addFile( fileName() ); | 300 | mDirWatch.addFile( fileName() ); |
301 | #ifdef _USE_DIRWATCH_ | ||
355 | mDirWatch.startScan(); | 302 | mDirWatch.startScan(); |
303 | #endif | ||
356 | } | 304 | } |
357 | 305 | ||
358 | 306 | ||
359 | void ResourceQtopia::fileChanged() | 307 | void ResourceQtopia::fileChanged() |
360 | { | 308 | { |
361 | // There is a small theoretical chance that KDirWatch calls us before | 309 | // There is a small theoretical chance that KDirWatch calls us before |