summaryrefslogtreecommitdiffabout
path: root/kabc
Unidiff
Diffstat (limited to 'kabc') (more/less context) (ignore whitespace changes)
-rw-r--r--kabc/addressbook.cpp2
-rw-r--r--kabc/plugins/file/resourcefile.cpp8
-rw-r--r--kabc/stdaddressbook.cpp2
3 files changed, 6 insertions, 6 deletions
diff --git a/kabc/addressbook.cpp b/kabc/addressbook.cpp
index 97bd3ef..0838157 100644
--- a/kabc/addressbook.cpp
+++ b/kabc/addressbook.cpp
@@ -222,65 +222,65 @@ AddressBook::AddressBook()
222AddressBook::AddressBook( const QString &config ) 222AddressBook::AddressBook( const QString &config )
223{ 223{
224 init(config); 224 init(config);
225} 225}
226 226
227void AddressBook::init(const QString &config) 227void AddressBook::init(const QString &config)
228{ 228{
229 d = new AddressBookData; 229 d = new AddressBookData;
230 if (config != 0) { 230 if (config != 0) {
231 d->mConfig = new KConfig( config ); 231 d->mConfig = new KConfig( config );
232// qDebug("AddressBook::init 1 config=%s",config.latin1() ); 232// qDebug("AddressBook::init 1 config=%s",config.latin1() );
233 } 233 }
234 else { 234 else {
235 d->mConfig = 0; 235 d->mConfig = 0;
236// qDebug("AddressBook::init 1 config=0"); 236// qDebug("AddressBook::init 1 config=0");
237 } 237 }
238 238
239//US d->mErrorHandler = 0; 239//US d->mErrorHandler = 0;
240 d->mManager = new KRES::Manager<Resource>( "contact" ); 240 d->mManager = new KRES::Manager<Resource>( "contact" );
241 d->mManager->readConfig( d->mConfig ); 241 d->mManager->readConfig( d->mConfig );
242} 242}
243 243
244AddressBook::~AddressBook() 244AddressBook::~AddressBook()
245{ 245{
246 delete d->mConfig; d->mConfig = 0; 246 delete d->mConfig; d->mConfig = 0;
247 delete d->mManager; d->mManager = 0; 247 delete d->mManager; d->mManager = 0;
248//US delete d->mErrorHandler; d->mErrorHandler = 0; 248//US delete d->mErrorHandler; d->mErrorHandler = 0;
249 delete d; d = 0; 249 delete d; d = 0;
250} 250}
251 251
252bool AddressBook::load() 252bool AddressBook::load()
253{ 253{
254 kdDebug(5700) << "AddressBook::load()" << endl; 254
255 255
256 clear(); 256 clear();
257 257
258 KRES::Manager<Resource>::ActiveIterator it; 258 KRES::Manager<Resource>::ActiveIterator it;
259 bool ok = true; 259 bool ok = true;
260 for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) 260 for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it )
261 if ( !(*it)->load() ) { 261 if ( !(*it)->load() ) {
262 error( i18n("Unable to load resource '%1'").arg( (*it)->resourceName() ) ); 262 error( i18n("Unable to load resource '%1'").arg( (*it)->resourceName() ) );
263 ok = false; 263 ok = false;
264 } 264 }
265 265
266 // mark all addressees as unchanged 266 // mark all addressees as unchanged
267 Addressee::List::Iterator addrIt; 267 Addressee::List::Iterator addrIt;
268 for ( addrIt = d->mAddressees.begin(); addrIt != d->mAddressees.end(); ++addrIt ) 268 for ( addrIt = d->mAddressees.begin(); addrIt != d->mAddressees.end(); ++addrIt )
269 (*addrIt).setChanged( false ); 269 (*addrIt).setChanged( false );
270 270
271 return ok; 271 return ok;
272} 272}
273 273
274bool AddressBook::save( Ticket *ticket ) 274bool AddressBook::save( Ticket *ticket )
275{ 275{
276 kdDebug(5700) << "AddressBook::save()"<< endl; 276 kdDebug(5700) << "AddressBook::save()"<< endl;
277 277
278 if ( ticket->resource() ) { 278 if ( ticket->resource() ) {
279 deleteRemovedAddressees(); 279 deleteRemovedAddressees();
280 280
281 return ticket->resource()->save( ticket ); 281 return ticket->resource()->save( ticket );
282 } 282 }
283 283
284 return false; 284 return false;
285} 285}
286 286
diff --git a/kabc/plugins/file/resourcefile.cpp b/kabc/plugins/file/resourcefile.cpp
index 80af841..3920f69 100644
--- a/kabc/plugins/file/resourcefile.cpp
+++ b/kabc/plugins/file/resourcefile.cpp
@@ -165,139 +165,139 @@ bool ResourceFile::doOpen()
165{ 165{
166 QFile file( mFileName ); 166 QFile file( mFileName );
167 167
168 if ( !file.exists() ) { 168 if ( !file.exists() ) {
169 // try to create the file 169 // try to create the file
170 bool ok = file.open( IO_WriteOnly ); 170 bool ok = file.open( IO_WriteOnly );
171 if ( ok ) 171 if ( ok )
172 file.close(); 172 file.close();
173 173
174 return ok; 174 return ok;
175 } else { 175 } else {
176 if ( !file.open( IO_ReadWrite ) ) 176 if ( !file.open( IO_ReadWrite ) )
177 return false; 177 return false;
178 178
179 if ( file.size() == 0 ) { 179 if ( file.size() == 0 ) {
180 file.close(); 180 file.close();
181 return true; 181 return true;
182 } 182 }
183 183
184 bool ok = mFormat->checkFormat( &file ); 184 bool ok = mFormat->checkFormat( &file );
185 file.close(); 185 file.close();
186 186
187 return ok; 187 return ok;
188 } 188 }
189} 189}
190 190
191void ResourceFile::doClose() 191void ResourceFile::doClose()
192{ 192{
193} 193}
194 194
195bool ResourceFile::load() 195bool ResourceFile::load()
196{ 196{
197 kdDebug(5700) << "ResourceFile::load(): '" << mFileName << "'" << endl; 197
198 198
199 QFile file( mFileName ); 199 QFile file( mFileName );
200 if ( !file.open( IO_ReadOnly ) ) { 200 if ( !file.open( IO_ReadOnly ) ) {
201 addressBook()->error( i18n( "Unable to open file '%1'." ).arg( mFileName ) ); 201 addressBook()->error( i18n( "Unable to open file '%1'." ).arg( mFileName ) );
202 return false; 202 return false;
203 } 203 }
204 204
205// qDebug("ResourceFile::load format %s, %s", mFileName.latin1(), mFormatName.latin1()); 205// qDebug("ResourceFile::load format %s, %s", mFileName.latin1(), mFormatName.latin1());
206 206
207 return mFormat->loadAll( addressBook(), this, &file ); 207 return mFormat->loadAll( addressBook(), this, &file );
208} 208}
209 209
210bool ResourceFile::save( Ticket *ticket ) 210bool ResourceFile::save( Ticket *ticket )
211{ 211{
212// qDebug("ResourceFile::save format %s, %s", mFileName.latin1(), mFormatName.latin1()); 212// qDebug("ResourceFile::save format %s, %s", mFileName.latin1(), mFormatName.latin1());
213 kdDebug(5700) << "ResourceFile::save()" << endl; 213
214 214
215 // create backup file 215 // create backup file
216 QString extension = "_" + QString::number( QDate::currentDate().dayOfWeek() ); 216 QString extension = "_" + QString::number( QDate::currentDate().dayOfWeek() );
217 217
218/*US we use a simpler method to create a backupfile 218/*US we use a simpler method to create a backupfile
219 219
220 (void) KSaveFile::backupFile( mFileName, QString::null 220 (void) KSaveFile::backupFile( mFileName, QString::null
221 ,extension ); 221 ,extension );
222 222
223 KSaveFile saveFile( mFileName ); 223 KSaveFile saveFile( mFileName );
224 bool ok = false; 224 bool ok = false;
225 if ( saveFile.status() == 0 && saveFile.file() ) 225 if ( saveFile.status() == 0 && saveFile.file() )
226 { 226 {
227 mFormat->saveAll( addressBook(), this, saveFile.file() ); 227 mFormat->saveAll( addressBook(), this, saveFile.file() );
228 ok = saveFile.close(); 228 ok = saveFile.close();
229 } 229 }
230*/ 230*/
231 231
232//US ToDo: write backupfile 232//US ToDo: write backupfile
233 QFile info; 233 QFile info;
234 info.setName( mFileName ); 234 info.setName( mFileName );
235 bool ok = info.open( IO_WriteOnly ); 235 bool ok = info.open( IO_WriteOnly );
236 if ( ok ) { 236 if ( ok ) {
237 mFormat->saveAll( addressBook(), this, &info ); 237 mFormat->saveAll( addressBook(), this, &info );
238 238
239 info.close(); 239 info.close();
240 ok = true; 240 ok = true;
241 } 241 }
242 else { 242 else {
243 243
244 } 244 }
245 245
246 if ( !ok ) 246 if ( !ok )
247 addressBook()->error( i18n( "Unable to save file '%1'." ).arg( mFileName ) ); 247 addressBook()->error( i18n( "Unable to save file '%1'." ).arg( mFileName ) );
248 248
249 delete ticket; 249 delete ticket;
250 unlock( mFileName ); 250 unlock( mFileName );
251 251
252 return ok; 252 return ok;
253 253
254 qDebug("ResourceFile::save has to be changed"); 254 qDebug("ResourceFile::save has to be changed");
255 return true; 255 return true;
256} 256}
257 257
258bool ResourceFile::lock( const QString &fileName ) 258bool ResourceFile::lock( const QString &fileName )
259{ 259{
260 kdDebug(5700) << "ResourceFile::lock()" << endl; 260
261 261
262 QString fn = fileName; 262 QString fn = fileName;
263 263
264//US change the implementation how the lockfilename is getting created 264//US change the implementation how the lockfilename is getting created
265//US fn.replace( QRegExp("/"), "_" ); 265//US fn.replace( QRegExp("/"), "_" );
266//US QString lockName = locateLocal( "data", "kabc/lock/" + fn + ".lock" ); 266//US QString lockName = locateLocal( "data", "kabc/lock/" + fn + ".lock" );
267 267
268 KURL url(fn); 268 KURL url(fn);
269 QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); 269 QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" );
270 270
271 kdDebug(5700) << "-- lock name: " << lockName << endl; 271
272 272
273 if (QFile::exists( lockName )) return false; 273 if (QFile::exists( lockName )) return false;
274 274
275 QString lockUniqueName; 275 QString lockUniqueName;
276 lockUniqueName = fn + KApplication::randomString( 8 ); 276 lockUniqueName = fn + KApplication::randomString( 8 );
277 277
278 url = lockUniqueName; 278 url = lockUniqueName;
279//US mLockUniqueName = locateLocal( "data", "kabc/lock/" + lockUniqueName ); 279//US mLockUniqueName = locateLocal( "data", "kabc/lock/" + lockUniqueName );
280 mLockUniqueName = locateLocal( "data", "kabc/lock/" + url.fileName() ); 280 mLockUniqueName = locateLocal( "data", "kabc/lock/" + url.fileName() );
281 kdDebug(5700) << "-- lock unique name: " << mLockUniqueName << endl; 281 kdDebug(5700) << "-- lock unique name: " << mLockUniqueName << endl;
282 282
283 // Create unique file 283 // Create unique file
284 QFile file( mLockUniqueName ); 284 QFile file( mLockUniqueName );
285 file.open( IO_WriteOnly ); 285 file.open( IO_WriteOnly );
286 file.close(); 286 file.close();
287 287
288 // Create lock file 288 // Create lock file
289 int result = ::link( QFile::encodeName( mLockUniqueName ), 289 int result = ::link( QFile::encodeName( mLockUniqueName ),
290 QFile::encodeName( lockName ) ); 290 QFile::encodeName( lockName ) );
291 291
292 if ( result == 0 ) { 292 if ( result == 0 ) {
293 addressBook()->emitAddressBookLocked(); 293 addressBook()->emitAddressBookLocked();
294 return true; 294 return true;
295 } 295 }
296 296
297 // TODO: check stat 297 // TODO: check stat
298 298
299 return false; 299 return false;
300} 300}
301 301
302void ResourceFile::unlock( const QString &fileName ) 302void ResourceFile::unlock( const QString &fileName )
303{ 303{
diff --git a/kabc/stdaddressbook.cpp b/kabc/stdaddressbook.cpp
index 075f12f..1e00cc6 100644
--- a/kabc/stdaddressbook.cpp
+++ b/kabc/stdaddressbook.cpp
@@ -123,65 +123,65 @@ StdAddressBook::StdAddressBook( bool onlyFastResources )
123//US : AddressBook( "kabcrc" ) 123//US : AddressBook( "kabcrc" )
124 : AddressBook( locateLocal( "config", "kabcrc") ) 124 : AddressBook( locateLocal( "config", "kabcrc") )
125{ 125{
126 126
127 init( onlyFastResources ); 127 init( onlyFastResources );
128} 128}
129 129
130StdAddressBook::~StdAddressBook() 130StdAddressBook::~StdAddressBook()
131{ 131{
132 if ( mAutomaticSave ) 132 if ( mAutomaticSave )
133 save(); 133 save();
134} 134}
135 135
136void StdAddressBook::init( bool ) 136void StdAddressBook::init( bool )
137{ 137{
138 KRES::Manager<Resource> *manager = resourceManager(); 138 KRES::Manager<Resource> *manager = resourceManager();
139 KRES::Manager<Resource>::ActiveIterator it; 139 KRES::Manager<Resource>::ActiveIterator it;
140 140
141 for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) { 141 for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) {
142 (*it)->setAddressBook( this ); 142 (*it)->setAddressBook( this );
143 if ( !(*it)->open() ) 143 if ( !(*it)->open() )
144 error( QString( "Unable to open resource '%1'!" ).arg( (*it)->resourceName() ) ); 144 error( QString( "Unable to open resource '%1'!" ).arg( (*it)->resourceName() ) );
145 } 145 }
146 146
147 Resource *res = standardResource(); 147 Resource *res = standardResource();
148 if ( !res ) { 148 if ( !res ) {
149 res = manager->createResource( "file" ); 149 res = manager->createResource( "file" );
150 if ( res ) 150 if ( res )
151 { 151 {
152 addResource( res ); 152 addResource( res );
153 } 153 }
154 else 154 else
155 kdDebug(5700) << "No resource available!!!" << endl; 155 qDebug(" No resource available!!!");
156 } 156 }
157 157
158 setStandardResource( res ); 158 setStandardResource( res );
159 manager->writeConfig(); 159 manager->writeConfig();
160 160
161 load(); 161 load();
162} 162}
163 163
164bool StdAddressBook::save() 164bool StdAddressBook::save()
165{ 165{
166 kdDebug(5700) << "StdAddressBook::save()" << endl; 166 kdDebug(5700) << "StdAddressBook::save()" << endl;
167 167
168 bool ok = true; 168 bool ok = true;
169 AddressBook *ab = self(); 169 AddressBook *ab = self();
170 170
171 ab->deleteRemovedAddressees(); 171 ab->deleteRemovedAddressees();
172 172
173 KRES::Manager<Resource>::ActiveIterator it; 173 KRES::Manager<Resource>::ActiveIterator it;
174 KRES::Manager<Resource> *manager = ab->resourceManager(); 174 KRES::Manager<Resource> *manager = ab->resourceManager();
175 for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) { 175 for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) {
176 if ( !(*it)->readOnly() && (*it)->isOpen() ) { 176 if ( !(*it)->readOnly() && (*it)->isOpen() ) {
177 Ticket *ticket = ab->requestSaveTicket( *it ); 177 Ticket *ticket = ab->requestSaveTicket( *it );
178// qDebug("StdAddressBook::save '%s'", (*it)->resourceName().latin1() ); 178// qDebug("StdAddressBook::save '%s'", (*it)->resourceName().latin1() );
179 if ( !ticket ) { 179 if ( !ticket ) {
180 ab->error( i18n( "Unable to save to resource '%1'. It is locked." ) 180 ab->error( i18n( "Unable to save to resource '%1'. It is locked." )
181 .arg( (*it)->resourceName() ) ); 181 .arg( (*it)->resourceName() ) );
182 return false; 182 return false;
183 } 183 }
184 184
185 if ( !ab->save( ticket ) ) 185 if ( !ab->save( ticket ) )
186 ok = false; 186 ok = false;
187 } 187 }