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
@@ -206,97 +206,97 @@ AddressBook::ConstIterator &AddressBook::ConstIterator::operator--(int)
206bool AddressBook::ConstIterator::operator==( const ConstIterator &it ) 206bool AddressBook::ConstIterator::operator==( const ConstIterator &it )
207{ 207{
208 return ( d->mIt == it.d->mIt ); 208 return ( d->mIt == it.d->mIt );
209} 209}
210 210
211bool AddressBook::ConstIterator::operator!=( const ConstIterator &it ) 211bool AddressBook::ConstIterator::operator!=( const ConstIterator &it )
212{ 212{
213 return ( d->mIt != it.d->mIt ); 213 return ( d->mIt != it.d->mIt );
214} 214}
215 215
216 216
217AddressBook::AddressBook() 217AddressBook::AddressBook()
218{ 218{
219 init(0); 219 init(0);
220} 220}
221 221
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
287AddressBook::Iterator AddressBook::begin() 287AddressBook::Iterator AddressBook::begin()
288{ 288{
289 Iterator it = Iterator(); 289 Iterator it = Iterator();
290 it.d->mIt = d->mAddressees.begin(); 290 it.d->mIt = d->mAddressees.begin();
291 return it; 291 return it;
292} 292}
293 293
294AddressBook::ConstIterator AddressBook::begin() const 294AddressBook::ConstIterator AddressBook::begin() const
295{ 295{
296 ConstIterator it = ConstIterator(); 296 ConstIterator it = ConstIterator();
297 it.d->mIt = d->mAddressees.begin(); 297 it.d->mIt = d->mAddressees.begin();
298 return it; 298 return it;
299} 299}
300 300
301AddressBook::Iterator AddressBook::end() 301AddressBook::Iterator AddressBook::end()
302{ 302{
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
@@ -149,171 +149,171 @@ void ResourceFile::writeConfig( KConfig *config )
149Ticket *ResourceFile::requestSaveTicket() 149Ticket *ResourceFile::requestSaveTicket()
150{ 150{
151 kdDebug(5700) << "ResourceFile::requestSaveTicket()" << endl; 151 kdDebug(5700) << "ResourceFile::requestSaveTicket()" << endl;
152 152
153 if ( !addressBook() ) return 0; 153 if ( !addressBook() ) return 0;
154 154
155 if ( !lock( mFileName ) ) { 155 if ( !lock( mFileName ) ) {
156 kdDebug(5700) << "ResourceFile::requestSaveTicket(): Unable to lock file '" 156 kdDebug(5700) << "ResourceFile::requestSaveTicket(): Unable to lock file '"
157 << mFileName << "'" << endl; 157 << mFileName << "'" << endl;
158 return 0; 158 return 0;
159 } 159 }
160 return createTicket( this ); 160 return createTicket( this );
161} 161}
162 162
163 163
164bool ResourceFile::doOpen() 164bool 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{
304 QString fn = fileName; 304 QString fn = fileName;
305//US change the implementation how the lockfilename is getting created 305//US change the implementation how the lockfilename is getting created
306//US fn.replace( QRegExp( "/" ), "_" ); 306//US fn.replace( QRegExp( "/" ), "_" );
307//US QString lockName = locateLocal( "data", "kabc/lock/" + fn + ".lock" ); 307//US QString lockName = locateLocal( "data", "kabc/lock/" + fn + ".lock" );
308//US QString lockName = fn + ".lock"; 308//US QString lockName = fn + ".lock";
309 KURL url(fn); 309 KURL url(fn);
310 QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); 310 QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" );
311 311
312 QFile::remove( lockName ); 312 QFile::remove( lockName );
313 QFile::remove( mLockUniqueName ); 313 QFile::remove( mLockUniqueName );
314 addressBook()->emitAddressBookUnlocked(); 314 addressBook()->emitAddressBookUnlocked();
315} 315}
316 316
317void ResourceFile::setFileName( const QString &fileName ) 317void ResourceFile::setFileName( const QString &fileName )
318{ 318{
319/*US ToDo: no synchronization so far. Has to be changed in the future 319/*US ToDo: no synchronization so far. Has to be changed in the future
diff --git a/kabc/stdaddressbook.cpp b/kabc/stdaddressbook.cpp
index 075f12f..1e00cc6 100644
--- a/kabc/stdaddressbook.cpp
+++ b/kabc/stdaddressbook.cpp
@@ -107,97 +107,97 @@ StdAddressBook *StdAddressBook::self( bool onlyFastResources )
107 addressBookDeleter.setObject( mSelf, new StdAddressBook( onlyFastResources ) ); 107 addressBookDeleter.setObject( mSelf, new StdAddressBook( onlyFastResources ) );
108#endif //KAB_EMBEDDED 108#endif //KAB_EMBEDDED
109 KStandardDirs::setAppDir( appdir ); 109 KStandardDirs::setAppDir( appdir );
110 } 110 }
111 return mSelf; 111 return mSelf;
112} 112}
113 113
114StdAddressBook::StdAddressBook() 114StdAddressBook::StdAddressBook()
115//US : AddressBook( "kabcrc" ) 115//US : AddressBook( "kabcrc" )
116 : AddressBook( locateLocal( "config", "kabcrc") ) 116 : AddressBook( locateLocal( "config", "kabcrc") )
117{ 117{
118 118
119 init( false ); 119 init( false );
120} 120}
121 121
122StdAddressBook::StdAddressBook( bool onlyFastResources ) 122StdAddressBook::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 }
188 } 188 }
189 189
190 return ok; 190 return ok;
191} 191}
192 192
193void StdAddressBook::close() 193void StdAddressBook::close()
194{ 194{
195//US destructObject is not defined on my system???. Is setObject(0) the same ??? 195//US destructObject is not defined on my system???. Is setObject(0) the same ???
196//US addressBookDeleter.destructObject(); 196//US addressBookDeleter.destructObject();
197 addressBookDeleter.setObject(0); 197 addressBookDeleter.setObject(0);
198 198
199} 199}
200 200
201void StdAddressBook::setAutomaticSave( bool enable ) 201void StdAddressBook::setAutomaticSave( bool enable )
202{ 202{
203 mAutomaticSave = enable; 203 mAutomaticSave = enable;