summaryrefslogtreecommitdiffabout
path: root/kabc/plugins/dir/resourcedir.cpp
Unidiff
Diffstat (limited to 'kabc/plugins/dir/resourcedir.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--kabc/plugins/dir/resourcedir.cpp8
1 files changed, 4 insertions, 4 deletions
diff --git a/kabc/plugins/dir/resourcedir.cpp b/kabc/plugins/dir/resourcedir.cpp
index c61664b..cc4afee 100644
--- a/kabc/plugins/dir/resourcedir.cpp
+++ b/kabc/plugins/dir/resourcedir.cpp
@@ -161,25 +161,25 @@ Ticket *ResourceDir::requestSaveTicket()
161 161
162bool ResourceDir::doOpen() 162bool ResourceDir::doOpen()
163{ 163{
164 QDir dir( mPath ); 164 QDir dir( mPath );
165 if ( !dir.exists() ) { // no directory available 165 if ( !dir.exists() ) { // no directory available
166 return dir.mkdir( dir.path() ); 166 return dir.mkdir( dir.path() );
167 } else { 167 } else {
168 QString testName = dir.entryList( QDir::Files )[0]; 168 QString testName = dir.entryList( QDir::Files )[0];
169 if ( testName.isNull() || testName.isEmpty() ) // no file in directory 169 if ( testName.isNull() || testName.isEmpty() ) // no file in directory
170 return true; 170 return true;
171 171
172 QFile file( mPath + "/" + testName ); 172 QFile file( mPath + "/" + testName );
173 if ( file.open( IO_ReadOnly ) ) 173 if ( file.open( QIODevice::ReadOnly ) )
174 return true; 174 return true;
175 175
176 if ( file.size() == 0 ) 176 if ( file.size() == 0 )
177 return true; 177 return true;
178 178
179 bool ok = mFormat->checkFormat( &file ); 179 bool ok = mFormat->checkFormat( &file );
180 file.close(); 180 file.close();
181 return ok; 181 return ok;
182 } 182 }
183} 183}
184 184
185void ResourceDir::doClose() 185void ResourceDir::doClose()
@@ -187,25 +187,25 @@ void ResourceDir::doClose()
187} 187}
188 188
189bool ResourceDir::load() 189bool ResourceDir::load()
190{ 190{
191 QDir dir( mPath ); 191 QDir dir( mPath );
192 QStringList files = dir.entryList( QDir::Files ); 192 QStringList files = dir.entryList( QDir::Files );
193 193
194 QStringList::Iterator it; 194 QStringList::Iterator it;
195 bool ok = true; 195 bool ok = true;
196 for ( it = files.begin(); it != files.end(); ++it ) { 196 for ( it = files.begin(); it != files.end(); ++it ) {
197 QFile file( mPath + "/" + (*it) ); 197 QFile file( mPath + "/" + (*it) );
198 198
199 if ( !file.open( IO_ReadOnly ) ) { 199 if ( !file.open( QIODevice::ReadOnly ) ) {
200 addressBook()->error( i18n( "Unable to open file '%1' for reading" ).arg( file.name() ) ); 200 addressBook()->error( i18n( "Unable to open file '%1' for reading" ).arg( file.name() ) );
201 ok = false; 201 ok = false;
202 continue; 202 continue;
203 } 203 }
204 204
205 if ( !mFormat->loadAll( addressBook(), this, &file ) ) 205 if ( !mFormat->loadAll( addressBook(), this, &file ) )
206 ok = false; 206 ok = false;
207 207
208 file.close(); 208 file.close();
209 } 209 }
210 210
211 return ok; 211 return ok;
@@ -214,25 +214,25 @@ bool ResourceDir::load()
214bool ResourceDir::save( Ticket *ticket ) 214bool ResourceDir::save( Ticket *ticket )
215{ 215{
216 AddressBook::Iterator it; 216 AddressBook::Iterator it;
217 bool ok = true; 217 bool ok = true;
218#ifndef NO_DIRWATCH 218#ifndef NO_DIRWATCH
219 mDirWatch.stopScan(); 219 mDirWatch.stopScan();
220#endif 220#endif
221 for ( it = addressBook()->begin(); it != addressBook()->end(); ++it ) { 221 for ( it = addressBook()->begin(); it != addressBook()->end(); ++it ) {
222 if ( (*it).resource() != this || !(*it).changed() ) 222 if ( (*it).resource() != this || !(*it).changed() )
223 continue; 223 continue;
224 224
225 QFile file( mPath + "/" + (*it).uid() ); 225 QFile file( mPath + "/" + (*it).uid() );
226 if ( !file.open( IO_WriteOnly ) ) { 226 if ( !file.open( QIODevice::WriteOnly ) ) {
227 addressBook()->error( i18n( "Unable to open file '%1' for writing" ).arg( file.name() ) ); 227 addressBook()->error( i18n( "Unable to open file '%1' for writing" ).arg( file.name() ) );
228 continue; 228 continue;
229 } 229 }
230 230
231 mFormat->save( *it, &file ); 231 mFormat->save( *it, &file );
232 232
233 // mark as unchanged 233 // mark as unchanged
234 (*it).setChanged( false ); 234 (*it).setChanged( false );
235 235
236 file.close(); 236 file.close();
237 } 237 }
238#ifndef NO_DIRWATCH 238#ifndef NO_DIRWATCH
@@ -258,25 +258,25 @@ bool ResourceDir::lock( const QString &path )
258 258
259 if ( QFile::exists( lockName ) ) return false; 259 if ( QFile::exists( lockName ) ) return false;
260 260
261 QString lockUniqueName; 261 QString lockUniqueName;
262 lockUniqueName = p + KApplication::randomString( 8 ); 262 lockUniqueName = p + KApplication::randomString( 8 );
263 263
264 url = lockUniqueName; 264 url = lockUniqueName;
265//US mLockUniqueName = locateLocal( "data", "kabc/lock/" + lockUniqueName ); 265//US mLockUniqueName = locateLocal( "data", "kabc/lock/" + lockUniqueName );
266 mLockUniqueName = locateLocal( "data", "kabc/lock/" + url.fileName() ); 266 mLockUniqueName = locateLocal( "data", "kabc/lock/" + url.fileName() );
267 267
268 // Create unique file 268 // Create unique file
269 QFile file( mLockUniqueName ); 269 QFile file( mLockUniqueName );
270 file.open( IO_WriteOnly ); 270 file.open( QIODevice::WriteOnly );
271 file.close(); 271 file.close();
272 272
273 // Create lock file 273 // Create lock file
274 int result = 0; 274 int result = 0;
275#ifndef _WIN32_ 275#ifndef _WIN32_
276 result = ::link( QFile::encodeName( mLockUniqueName ), 276 result = ::link( QFile::encodeName( mLockUniqueName ),
277 QFile::encodeName( lockName ) ); 277 QFile::encodeName( lockName ) );
278#endif 278#endif
279 if ( result == 0 ) { 279 if ( result == 0 ) {
280 addressBook()->emitAddressBookLocked(); 280 addressBook()->emitAddressBookLocked();
281 return true; 281 return true;
282 } 282 }