author | Michael Krelin <hacker@klever.net> | 2007-07-04 11:23:42 (UTC) |
---|---|---|
committer | Michael Krelin <hacker@klever.net> | 2007-07-04 11:23:42 (UTC) |
commit | a08aff328d4393031d5ba7d622c2b05705a89d73 (patch) (unidiff) | |
tree | 8ee90d686081c52e7c69b5ce946e9b1a7d690001 /kabc/plugins/file/resourcefile.cpp | |
parent | 11edc920afe4f274c0964436633aa632c8288a40 (diff) | |
download | kdepimpi-a08aff328d4393031d5ba7d622c2b05705a89d73.zip kdepimpi-a08aff328d4393031d5ba7d622c2b05705a89d73.tar.gz kdepimpi-a08aff328d4393031d5ba7d622c2b05705a89d73.tar.bz2 |
initial public commit of qt4 portp1
Diffstat (limited to 'kabc/plugins/file/resourcefile.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | kabc/plugins/file/resourcefile.cpp | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/kabc/plugins/file/resourcefile.cpp b/kabc/plugins/file/resourcefile.cpp index dad4571..3ed850c 100644 --- a/kabc/plugins/file/resourcefile.cpp +++ b/kabc/plugins/file/resourcefile.cpp | |||
@@ -188,62 +188,62 @@ Ticket *ResourceFile::requestSaveTicket() | |||
188 | if ( !lock( mFileName ) ) { | 188 | if ( !lock( mFileName ) ) { |
189 | qDebug("unablt to lock file "); | 189 | qDebug("unablt to lock file "); |
190 | return 0; | 190 | return 0; |
191 | } | 191 | } |
192 | #endif | 192 | #endif |
193 | return createTicket( this ); | 193 | return createTicket( this ); |
194 | } | 194 | } |
195 | 195 | ||
196 | 196 | ||
197 | bool ResourceFile::doOpen() | 197 | bool ResourceFile::doOpen() |
198 | { | 198 | { |
199 | QFile file( fileName() ); | 199 | QFile file( fileName() ); |
200 | qDebug("ResourceFile::openfile %s ", fileName().latin1()); | 200 | qDebug("ResourceFile::openfile %s ", fileName().latin1()); |
201 | 201 | ||
202 | if ( !file.exists() ) { | 202 | if ( !file.exists() ) { |
203 | // try to create the file | 203 | // try to create the file |
204 | bool ok = file.open( IO_WriteOnly ); | 204 | bool ok = file.open( QIODevice::WriteOnly ); |
205 | if ( ok ) | 205 | if ( ok ) |
206 | file.close(); | 206 | file.close(); |
207 | 207 | ||
208 | return ok; | 208 | return ok; |
209 | } else { | 209 | } else { |
210 | if ( !file.open( IO_ReadWrite ) ) | 210 | if ( !file.open( QIODevice::ReadWrite ) ) |
211 | return false; | 211 | return false; |
212 | 212 | ||
213 | if ( file.size() < 10 ) { | 213 | if ( file.size() < 10 ) { |
214 | file.close(); | 214 | file.close(); |
215 | return true; | 215 | return true; |
216 | } | 216 | } |
217 | 217 | ||
218 | bool ok = mFormat->checkFormat( &file ); | 218 | bool ok = mFormat->checkFormat( &file ); |
219 | file.close(); | 219 | file.close(); |
220 | 220 | ||
221 | return ok; | 221 | return ok; |
222 | } | 222 | } |
223 | } | 223 | } |
224 | 224 | ||
225 | void ResourceFile::doClose() | 225 | void ResourceFile::doClose() |
226 | { | 226 | { |
227 | } | 227 | } |
228 | 228 | ||
229 | bool ResourceFile::load() | 229 | bool ResourceFile::load() |
230 | { | 230 | { |
231 | 231 | ||
232 | QFile file( fileName() ); | 232 | QFile file( fileName() ); |
233 | if ( !file.open( IO_ReadOnly ) ) { | 233 | if ( !file.open( QIODevice::ReadOnly ) ) { |
234 | addressBook()->error( i18n( "Unable to open file '%1'." ).arg( fileName() ) ); | 234 | addressBook()->error( i18n( "Unable to open file '%1'." ).arg( fileName() ) ); |
235 | return false; | 235 | return false; |
236 | } | 236 | } |
237 | 237 | ||
238 | // qDebug("ResourceFile::load format %s, %s", mFileName.latin1(), mFormatName.latin1()); | 238 | // qDebug("ResourceFile::load format %s, %s", mFileName.latin1(), mFormatName.latin1()); |
239 | 239 | ||
240 | return mFormat->loadAll( addressBook(), this, &file ); | 240 | return mFormat->loadAll( addressBook(), this, &file ); |
241 | } | 241 | } |
242 | 242 | ||
243 | bool ResourceFile::save( Ticket *ticket ) | 243 | bool ResourceFile::save( Ticket *ticket ) |
244 | { | 244 | { |
245 | // qDebug("ResourceFile::save format %s, %s", mFileName.latin1(), mFormatName.latin1()); | 245 | // qDebug("ResourceFile::save format %s, %s", mFileName.latin1(), mFormatName.latin1()); |
246 | 246 | ||
247 | 247 | ||
248 | // create backup file | 248 | // create backup file |
249 | QString extension = "_" + QString::number( QDate::currentDate().dayOfWeek() ); | 249 | QString extension = "_" + QString::number( QDate::currentDate().dayOfWeek() ); |
@@ -298,33 +298,33 @@ bool ResourceFile::save( Ticket *ticket ) | |||
298 | // backup globally cancelled | 298 | // backup globally cancelled |
299 | b_enabled = false; | 299 | b_enabled = false; |
300 | } | 300 | } |
301 | if ( !b_enabled ) { | 301 | if ( !b_enabled ) { |
302 | conf.writeEntry( "mBackupEnabled", false ); | 302 | conf.writeEntry( "mBackupEnabled", false ); |
303 | } | 303 | } |
304 | if ( saveDate ) { | 304 | if ( saveDate ) { |
305 | KConfig config ( locateLocal("config","kabcrc") ); | 305 | KConfig config ( locateLocal("config","kabcrc") ); |
306 | config.setGroup( "Resource_" + identifier() ); | 306 | config.setGroup( "Resource_" + identifier() ); |
307 | config.writeEntry( "LastBackupDate", mLastBackupDate ); | 307 | config.writeEntry( "LastBackupDate", mLastBackupDate ); |
308 | } | 308 | } |
309 | } | 309 | } |
310 | } | 310 | } |
311 | } | 311 | } |
312 | QFile info; | 312 | QFile info; |
313 | info.setName( fileName() ); | 313 | info.setName( fileName() ); |
314 | bool ok = info.open( IO_WriteOnly ); | 314 | bool ok = info.open( QIODevice::WriteOnly ); |
315 | if ( ok ) { | 315 | if ( ok ) { |
316 | mFormat->saveAll( addressBook(), this, &info ); | 316 | mFormat->saveAll( addressBook(), this, &info ); |
317 | 317 | ||
318 | info.close(); | 318 | info.close(); |
319 | ok = true; | 319 | ok = true; |
320 | } | 320 | } |
321 | else { | 321 | else { |
322 | 322 | ||
323 | } | 323 | } |
324 | 324 | ||
325 | if ( !ok ) | 325 | if ( !ok ) |
326 | addressBook()->error( i18n( "Unable to save file '%1'." ).arg( fileName() ) ); | 326 | addressBook()->error( i18n( "Unable to save file '%1'." ).arg( fileName() ) ); |
327 | #ifndef NO_DIRWATCH | 327 | #ifndef NO_DIRWATCH |
328 | mDirWatch.startScan(); | 328 | mDirWatch.startScan(); |
329 | #endif | 329 | #endif |
330 | delete ticket; | 330 | delete ticket; |
@@ -350,33 +350,33 @@ bool ResourceFile::lock( const QString &fileName ) | |||
350 | QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); | 350 | QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); |
351 | 351 | ||
352 | 352 | ||
353 | 353 | ||
354 | if (QFile::exists( lockName )) return false; | 354 | if (QFile::exists( lockName )) return false; |
355 | 355 | ||
356 | QString lockUniqueName; | 356 | QString lockUniqueName; |
357 | lockUniqueName = fn + KApplication::randomString( 8 ); | 357 | lockUniqueName = fn + KApplication::randomString( 8 ); |
358 | 358 | ||
359 | url = lockUniqueName; | 359 | url = lockUniqueName; |
360 | //US mLockUniqueName = locateLocal( "data", "kabc/lock/" + lockUniqueName ); | 360 | //US mLockUniqueName = locateLocal( "data", "kabc/lock/" + lockUniqueName ); |
361 | mLockUniqueName = locateLocal( "data", "kabc/lock/" + url.fileName() ); | 361 | mLockUniqueName = locateLocal( "data", "kabc/lock/" + url.fileName() ); |
362 | kdDebug(5700) << "-- lock unique name: " << mLockUniqueName << endl; | 362 | kdDebug(5700) << "-- lock unique name: " << mLockUniqueName << endl; |
363 | 363 | ||
364 | // Create unique file | 364 | // Create unique file |
365 | QFile file( mLockUniqueName ); | 365 | QFile file( mLockUniqueName ); |
366 | file.open( IO_WriteOnly ); | 366 | file.open( QIODevice::WriteOnly ); |
367 | file.close(); | 367 | file.close(); |
368 | 368 | ||
369 | // Create lock file | 369 | // Create lock file |
370 | int result = 0; | 370 | int result = 0; |
371 | #ifndef _WIN32_ | 371 | #ifndef _WIN32_ |
372 | result = ::link( QFile::encodeName( mLockUniqueName ), | 372 | result = ::link( QFile::encodeName( mLockUniqueName ), |
373 | QFile::encodeName( lockName ) ); | 373 | QFile::encodeName( lockName ) ); |
374 | #endif | 374 | #endif |
375 | if ( result == 0 ) { | 375 | if ( result == 0 ) { |
376 | addressBook()->emitAddressBookLocked(); | 376 | addressBook()->emitAddressBookLocked(); |
377 | return true; | 377 | return true; |
378 | } | 378 | } |
379 | 379 | ||
380 | // TODO: check stat | 380 | // TODO: check stat |
381 | 381 | ||
382 | return false; | 382 | return false; |