Diffstat (limited to 'kabc/plugins/file/resourcefile.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | kabc/plugins/file/resourcefile.cpp | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/kabc/plugins/file/resourcefile.cpp b/kabc/plugins/file/resourcefile.cpp index da2e4d7..fa6bc49 100644 --- a/kabc/plugins/file/resourcefile.cpp +++ b/kabc/plugins/file/resourcefile.cpp | |||
@@ -183,92 +183,93 @@ bool ResourceFile::doOpen() | |||
183 | } | 183 | } |
184 | } | 184 | } |
185 | 185 | ||
186 | void ResourceFile::doClose() | 186 | void ResourceFile::doClose() |
187 | { | 187 | { |
188 | } | 188 | } |
189 | 189 | ||
190 | bool ResourceFile::load() | 190 | bool ResourceFile::load() |
191 | { | 191 | { |
192 | 192 | ||
193 | 193 | ||
194 | QFile file( mFileName ); | 194 | QFile file( mFileName ); |
195 | if ( !file.open( IO_ReadOnly ) ) { | 195 | if ( !file.open( IO_ReadOnly ) ) { |
196 | addressBook()->error( i18n( "Unable to open file '%1'." ).arg( mFileName ) ); | 196 | addressBook()->error( i18n( "Unable to open file '%1'." ).arg( mFileName ) ); |
197 | return false; | 197 | return false; |
198 | } | 198 | } |
199 | 199 | ||
200 | // qDebug("ResourceFile::load format %s, %s", mFileName.latin1(), mFormatName.latin1()); | 200 | // qDebug("ResourceFile::load format %s, %s", mFileName.latin1(), mFormatName.latin1()); |
201 | 201 | ||
202 | return mFormat->loadAll( addressBook(), this, &file ); | 202 | return mFormat->loadAll( addressBook(), this, &file ); |
203 | } | 203 | } |
204 | 204 | ||
205 | bool ResourceFile::save( Ticket *ticket ) | 205 | bool ResourceFile::save( Ticket *ticket ) |
206 | { | 206 | { |
207 | // qDebug("ResourceFile::save format %s, %s", mFileName.latin1(), mFormatName.latin1()); | 207 | // qDebug("ResourceFile::save format %s, %s", mFileName.latin1(), mFormatName.latin1()); |
208 | 208 | ||
209 | 209 | ||
210 | // create backup file | 210 | // create backup file |
211 | QString extension = "_" + QString::number( QDate::currentDate().dayOfWeek() ); | 211 | QString extension = "_" + QString::number( QDate::currentDate().dayOfWeek() ); |
212 | 212 | ||
213 | /*US we use a simpler method to create a backupfile | 213 | /*US we use a simpler method to create a backupfile |
214 | 214 | ||
215 | (void) KSaveFile::backupFile( mFileName, QString::null | 215 | (void) KSaveFile::backupFile( mFileName, QString::null |
216 | ,extension ); | 216 | ,extension ); |
217 | 217 | ||
218 | KSaveFile saveFile( mFileName ); | 218 | KSaveFile saveFile( mFileName ); |
219 | bool ok = false; | 219 | bool ok = false; |
220 | if ( saveFile.status() == 0 && saveFile.file() ) | 220 | if ( saveFile.status() == 0 && saveFile.file() ) |
221 | { | 221 | { |
222 | mFormat->saveAll( addressBook(), this, saveFile.file() ); | 222 | mFormat->saveAll( addressBook(), this, saveFile.file() ); |
223 | ok = saveFile.close(); | 223 | ok = saveFile.close(); |
224 | } | 224 | } |
225 | */ | 225 | */ |
226 | 226 | ||
227 | //US ToDo: write backupfile | 227 | //US ToDo: write backupfile |
228 | mDirWatch.stopScan(); | ||
229 | |||
228 | QFile info; | 230 | QFile info; |
229 | info.setName( mFileName ); | 231 | info.setName( mFileName ); |
230 | bool ok = info.open( IO_WriteOnly ); | 232 | bool ok = info.open( IO_WriteOnly ); |
231 | if ( ok ) { | 233 | if ( ok ) { |
232 | mFormat->saveAll( addressBook(), this, &info ); | 234 | mFormat->saveAll( addressBook(), this, &info ); |
233 | 235 | ||
234 | info.close(); | 236 | info.close(); |
235 | ok = true; | 237 | ok = true; |
236 | } | 238 | } |
237 | else { | 239 | else { |
238 | 240 | ||
239 | } | 241 | } |
240 | 242 | ||
241 | if ( !ok ) | 243 | if ( !ok ) |
242 | addressBook()->error( i18n( "Unable to save file '%1'." ).arg( mFileName ) ); | 244 | addressBook()->error( i18n( "Unable to save file '%1'." ).arg( mFileName ) ); |
243 | 245 | ||
246 | mDirWatch.startScan(); | ||
247 | |||
244 | delete ticket; | 248 | delete ticket; |
245 | unlock( mFileName ); | 249 | unlock( mFileName ); |
246 | 250 | ||
247 | return ok; | 251 | return ok; |
248 | |||
249 | qDebug("ResourceFile::save has to be changed"); | ||
250 | return true; | ||
251 | } | 252 | } |
252 | 253 | ||
253 | bool ResourceFile::lock( const QString &fileName ) | 254 | bool ResourceFile::lock( const QString &fileName ) |
254 | { | 255 | { |
255 | 256 | ||
256 | 257 | ||
257 | QString fn = fileName; | 258 | QString fn = fileName; |
258 | 259 | ||
259 | //US change the implementation how the lockfilename is getting created | 260 | //US change the implementation how the lockfilename is getting created |
260 | //US fn.replace( QRegExp("/"), "_" ); | 261 | //US fn.replace( QRegExp("/"), "_" ); |
261 | //US QString lockName = locateLocal( "data", "kabc/lock/" + fn + ".lock" ); | 262 | //US QString lockName = locateLocal( "data", "kabc/lock/" + fn + ".lock" ); |
262 | 263 | ||
263 | KURL url(fn); | 264 | KURL url(fn); |
264 | QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); | 265 | QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); |
265 | 266 | ||
266 | 267 | ||
267 | 268 | ||
268 | if (QFile::exists( lockName )) return false; | 269 | if (QFile::exists( lockName )) return false; |
269 | 270 | ||
270 | QString lockUniqueName; | 271 | QString lockUniqueName; |
271 | lockUniqueName = fn + KApplication::randomString( 8 ); | 272 | lockUniqueName = fn + KApplication::randomString( 8 ); |
272 | 273 | ||
273 | url = lockUniqueName; | 274 | url = lockUniqueName; |
274 | //US mLockUniqueName = locateLocal( "data", "kabc/lock/" + lockUniqueName ); | 275 | //US mLockUniqueName = locateLocal( "data", "kabc/lock/" + lockUniqueName ); |