-rw-r--r-- | kabc/addressbook.cpp | 11 | ||||
-rw-r--r-- | kabc/addressbook.h | 1 | ||||
-rw-r--r-- | kabc/addressee.cpp | 2 | ||||
-rw-r--r-- | kabc/plugins/sharpdtm/resourcesharpdtm.cpp | 215 | ||||
-rw-r--r-- | kabc/tmpaddressbook.cpp | 9 |
5 files changed, 61 insertions, 177 deletions
diff --git a/kabc/addressbook.cpp b/kabc/addressbook.cpp index 4c4ae09..8487ff3 100644 --- a/kabc/addressbook.cpp +++ b/kabc/addressbook.cpp | |||
@@ -1162,2 +1162,13 @@ bool AddressBook::addResource( Resource *resource ) | |||
1162 | } | 1162 | } |
1163 | void AddressBook::removeResources() | ||
1164 | { | ||
1165 | //remove all possible resources. This should cleanup the configfile. | ||
1166 | QPtrList<KABC::Resource> mResources = resources(); | ||
1167 | |||
1168 | QPtrListIterator<KABC::Resource> it(mResources); | ||
1169 | for ( ; it.current(); ++it ) { | ||
1170 | KABC::Resource *res = it.current(); | ||
1171 | removeResource(res); | ||
1172 | } | ||
1173 | } | ||
1163 | 1174 | ||
diff --git a/kabc/addressbook.h b/kabc/addressbook.h index 75f8b51..2351add 100644 --- a/kabc/addressbook.h +++ b/kabc/addressbook.h | |||
@@ -276,2 +276,3 @@ class AddressBook : public QObject | |||
276 | */ | 276 | */ |
277 | void removeResources(); | ||
277 | bool removeResource( Resource * ); | 278 | bool removeResource( Resource * ); |
diff --git a/kabc/addressee.cpp b/kabc/addressee.cpp index 3d4992c..028d3bb 100644 --- a/kabc/addressee.cpp +++ b/kabc/addressee.cpp | |||
@@ -274,3 +274,3 @@ void Addressee::computeCsum(const QString &dev) | |||
274 | uint cs = getCsum4List(l); | 274 | uint cs = getCsum4List(l); |
275 | #if 1 | 275 | #if 0 |
276 | for ( iii = 0; iii < l.count(); ++iii) | 276 | for ( iii = 0; iii < l.count(); ++iii) |
diff --git a/kabc/plugins/sharpdtm/resourcesharpdtm.cpp b/kabc/plugins/sharpdtm/resourcesharpdtm.cpp index ba17c50..48b7d91 100644 --- a/kabc/plugins/sharpdtm/resourcesharpdtm.cpp +++ b/kabc/plugins/sharpdtm/resourcesharpdtm.cpp | |||
@@ -69,5 +69,5 @@ ResourceSharpDTM::ResourceSharpDTM( const KConfig *config ) | |||
69 | // we can not choose the filename. Therefore use the default to display | 69 | // we can not choose the filename. Therefore use the default to display |
70 | 70 | mAccess = 0; | |
71 | QString fileName = SlZDataBase::addressbookFileName(); | 71 | QString fileName = SlZDataBase::addressbookFileName(); |
72 | init( fileName ); | 72 | init( fileName ); |
73 | } | 73 | } |
@@ -77,3 +77,4 @@ ResourceSharpDTM::ResourceSharpDTM( const QString &fileName ) | |||
77 | { | 77 | { |
78 | init( fileName ); | 78 | mAccess = 0; |
79 | init( fileName ); | ||
79 | } | 80 | } |
@@ -82,7 +83,2 @@ void ResourceSharpDTM::init( const QString &fileName ) | |||
82 | { | 83 | { |
83 | |||
84 | connect( &mDirWatch, SIGNAL( dirty(const QString&) ), SLOT( fileChanged() ) ); | ||
85 | connect( &mDirWatch, SIGNAL( created(const QString&) ), SLOT( fileChanged() ) ); | ||
86 | connect( &mDirWatch, SIGNAL( deleted(const QString&) ), SLOT( fileChanged() ) ); | ||
87 | |||
88 | setFileName( fileName ); | 84 | setFileName( fileName ); |
@@ -106,3 +102,2 @@ Ticket *ResourceSharpDTM::requestSaveTicket() | |||
106 | { | 102 | { |
107 | |||
108 | 103 | ||
@@ -111,9 +106,2 @@ Ticket *ResourceSharpDTM::requestSaveTicket() | |||
111 | if ( !addressBook() ) return 0; | 106 | if ( !addressBook() ) return 0; |
112 | |||
113 | #ifdef ALLOW_LOCKING | ||
114 | if ( !lock( fileName() ) ) { | ||
115 | qDebug("ResourceSharpDTM::requestSaveTicket(): Unable to lock file "); | ||
116 | return 0; | ||
117 | } | ||
118 | #endif | ||
119 | return createTicket( this ); | 107 | return createTicket( this ); |
@@ -124,30 +112,27 @@ bool ResourceSharpDTM::doOpen() | |||
124 | { | 112 | { |
125 | qDebug("ResourceSharpDTM::doOpen: %s", fileName().latin1()); | 113 | qDebug("%xResourceSharpDTM::doOpen: %s", this,fileName().latin1()); |
126 | |||
127 | // the last parameter in the SlZDataBase constructor means "readonly" | ||
128 | mAccess = new SlZDataBase(fileName(), | ||
129 | SlZDataBase::addressbookItems(), | ||
130 | NULL, false); | ||
131 | 114 | ||
132 | if ( !mAccess ) { | 115 | if ( ! mAccess ) { |
133 | qDebug("Unable to load file() %s", fileName().latin1()); | 116 | // the last parameter in the SlZDataBase constructor means "readonly" |
134 | return false; | 117 | mAccess = new SlZDataBase(fileName(), |
135 | } | 118 | SlZDataBase::addressbookItems(), |
136 | 119 | NULL, false); | |
137 | if (mConverter == 0) | ||
138 | { | ||
139 | mConverter = new SharpDTMConverter(); | ||
140 | bool res = mConverter->init(); | ||
141 | if ( !res ) | ||
142 | { | ||
143 | QString msg("Unable to initialize sharp converter. Most likely a problem with the category file"); | ||
144 | |||
145 | qDebug(msg); | ||
146 | delete mAccess; | ||
147 | mAccess = 0; | ||
148 | return false; | ||
149 | } | 120 | } |
150 | } | 121 | if ( !mAccess ) { |
151 | 122 | qDebug("Unable to load file() %s", fileName().latin1()); | |
152 | return true; | 123 | return false; |
124 | } | ||
125 | if (mConverter == 0) { | ||
126 | mConverter = new SharpDTMConverter(); | ||
127 | bool res = mConverter->init(); | ||
128 | if ( !res ) | ||
129 | { | ||
130 | QString msg("Unable to initialize sharp converter. Most likely a problem with the category file"); | ||
131 | qDebug(msg); | ||
132 | delete mAccess; | ||
133 | mAccess = 0; | ||
134 | return false; | ||
135 | } | ||
136 | } | ||
137 | return true; | ||
153 | } | 138 | } |
@@ -156,12 +141,2 @@ void ResourceSharpDTM::doClose() | |||
156 | { | 141 | { |
157 | qDebug("ResourceSharpDTM::doClose: %s", fileName().latin1()); | ||
158 | |||
159 | if(mAccess) | ||
160 | { | ||
161 | delete mAccess; | ||
162 | mAccess = 0; | ||
163 | } | ||
164 | // it seems so, that deletion of access deletes backend as well | ||
165 | //delete backend; | ||
166 | |||
167 | return; | 142 | return; |
@@ -171,24 +146,17 @@ bool ResourceSharpDTM::load() | |||
171 | { | 146 | { |
172 | qDebug("ResourceSharpDTM::load: %s", fileName().latin1()); | 147 | qDebug("%xResourceSharpDTM::load: %s",this, fileName().latin1()); |
173 | 148 | bool res = false; | |
174 | bool res = false; | 149 | CardId id; |
175 | 150 | for (bool res=mAccess->first(); res == true; res=mAccess->next()) | |
176 | CardId id; | 151 | { |
177 | 152 | id = mAccess->cardId(); | |
178 | for (bool res=mAccess->first(); res == true; res=mAccess->next()) | 153 | KABC::Addressee addressee; |
179 | { | 154 | res = mConverter->sharpToAddressee( id, mAccess, addressee ); |
180 | id = mAccess->cardId(); | 155 | if ( !addressee.isEmpty() && res ) |
181 | 156 | { | |
182 | KABC::Addressee addressee; | 157 | addressee.setResource( this ); |
183 | 158 | addressBook()->insertAddressee( addressee ); | |
184 | res = mConverter->sharpToAddressee( id, mAccess, addressee ); | 159 | } |
185 | 160 | } | |
186 | if ( !addressee.isEmpty() && res ) | 161 | return true; |
187 | { | ||
188 | addressee.setResource( this ); | ||
189 | addressBook()->insertAddressee( addressee ); | ||
190 | } | ||
191 | } | ||
192 | |||
193 | return true; | ||
194 | } | 162 | } |
@@ -198,5 +166,2 @@ bool ResourceSharpDTM::save( Ticket *ticket ) | |||
198 | qDebug("ResourceSharpDTM::save: %s", fileName().latin1()); | 166 | qDebug("ResourceSharpDTM::save: %s", fileName().latin1()); |
199 | |||
200 | mDirWatch.stopScan(); | ||
201 | |||
202 | KABC::AddressBook::Iterator it; | 167 | KABC::AddressBook::Iterator it; |
@@ -207,3 +172,2 @@ bool ResourceSharpDTM::save( Ticket *ticket ) | |||
207 | CardId id ; | 172 | CardId id ; |
208 | |||
209 | for ( it = addressBook()->begin(); it != addressBook()->end(); ++it ) { | 173 | for ( it = addressBook()->begin(); it != addressBook()->end(); ++it ) { |
@@ -225,6 +189,3 @@ bool ResourceSharpDTM::save( Ticket *ticket ) | |||
225 | { | 189 | { |
226 | res = mAccess->finishEditCard(&id); | 190 | res = mAccess->finishEditCard(&id);; |
227 | //(*it).setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); | ||
228 | //(*it).setExternalUID( QString::number( id ) ); | ||
229 | //(*it).setOriginalExternalUID( QString::number( id ) ); | ||
230 | map.insert(id,(*it).uid()); | 191 | map.insert(id,(*it).uid()); |
@@ -256,7 +217,5 @@ bool ResourceSharpDTM::save( Ticket *ticket ) | |||
256 | res = mAccess->finishEditCard(&id); | 217 | res = mAccess->finishEditCard(&id); |
257 | //(*it).setTempSyncStat( SYNC_TEMPSTATE_NEW_CSUM ); | ||
258 | map.insert(id,(*it).uid()); | 218 | map.insert(id,(*it).uid()); |
259 | if (res == false) | 219 | if (res == false) |
260 | qDebug("Unable to append Contact: %s", addressee.formattedName().latin1()); | 220 | qDebug("Unable to append Contact: %s", addressee.formattedName().latin1()); |
261 | |||
262 | } | 221 | } |
@@ -291,8 +250,3 @@ bool ResourceSharpDTM::save( Ticket *ticket ) | |||
291 | } | 250 | } |
292 | |||
293 | //US mAccess->save(); | ||
294 | |||
295 | mDirWatch.startScan(); | ||
296 | delete ticket; | 251 | delete ticket; |
297 | unlock( fileName() ); | ||
298 | 252 | ||
@@ -303,51 +257,2 @@ bool ResourceSharpDTM::lock( const QString &lockfileName ) | |||
303 | { | 257 | { |
304 | #ifdef ALLOW_LOCKING | ||
305 | qDebug("ResourceSharpDTM::lock: %s", fileName().latin1()); | ||
306 | |||
307 | kdDebug(5700) << "ResourceSharpDTM::lock()" << endl; | ||
308 | |||
309 | QString fn = lockfileName; | ||
310 | |||
311 | KURL url(fn); | ||
312 | QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); | ||
313 | |||
314 | kdDebug(5700) << "-- lock name: " << lockName << endl; | ||
315 | |||
316 | if (QFile::exists( lockName )) | ||
317 | { | ||
318 | qDebug("ResourceSharpDTM::lock: lockfile %s already exists. (Delete it before continuing if nobody else is accessing the resourcefile %s)", lockName.latin1(), fileName()); | ||
319 | return false; | ||
320 | } | ||
321 | |||
322 | |||
323 | QString lockUniqueName; | ||
324 | lockUniqueName = fn + KApplication::randomString( 8 ); | ||
325 | |||
326 | url = lockUniqueName; | ||
327 | //US mLockUniqueName = locateLocal( "data", "kabc/lock/" + lockUniqueName ); | ||
328 | mLockUniqueName = locateLocal( "data", "kabc/lock/" + url.fileName() ); | ||
329 | kdDebug(5700) << "-- lock unique name: " << mLockUniqueName << endl; | ||
330 | |||
331 | // Create unique file | ||
332 | QFile file( mLockUniqueName ); | ||
333 | file.open( IO_WriteOnly ); | ||
334 | file.close(); | ||
335 | |||
336 | // Create lock file | ||
337 | int result = 0; | ||
338 | #ifndef _WIN32_ | ||
339 | result = ::link( QFile::encodeName( mLockUniqueName ), | ||
340 | QFile::encodeName( lockName ) ); | ||
341 | #endif | ||
342 | if ( result == 0 ) { | ||
343 | addressBook()->emitAddressBookLocked(); | ||
344 | return true; | ||
345 | } | ||
346 | |||
347 | // TODO: check stat | ||
348 | |||
349 | return false; | ||
350 | #else | ||
351 | return true; | ||
352 | #endif | ||
353 | } | 258 | } |
@@ -356,13 +261,3 @@ void ResourceSharpDTM::unlock( const QString &fileName ) | |||
356 | { | 261 | { |
357 | #ifdef ALLOW_LOCKING | ||
358 | qDebug("ResourceSharpDTM::unlock() %s", fileName.latin1()); | ||
359 | 262 | ||
360 | QString fn = fileName; | ||
361 | KURL url(fn); | ||
362 | QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); | ||
363 | |||
364 | QFile::remove( lockName ); | ||
365 | QFile::remove( mLockUniqueName ); | ||
366 | addressBook()->emitAddressBookUnlocked(); | ||
367 | #endif | ||
368 | } | 263 | } |
@@ -371,10 +266,3 @@ void ResourceSharpDTM::setFileName( const QString &newFileName ) | |||
371 | { | 266 | { |
372 | mDirWatch.stopScan(); | 267 | Resource::setFileName( newFileName ); |
373 | mDirWatch.removeFile( fileName() ); | ||
374 | |||
375 | Resource::setFileName( newFileName ); | ||
376 | |||
377 | mDirWatch.addFile( fileName() ); | ||
378 | mDirWatch.startScan(); | ||
379 | |||
380 | } | 268 | } |
@@ -383,12 +271,3 @@ void ResourceSharpDTM::fileChanged() | |||
383 | { | 271 | { |
384 | // There is a small theoretical chance that KDirWatch calls us before | 272 | |
385 | // we are fully constructed | ||
386 | if (!addressBook()) | ||
387 | return; | ||
388 | |||
389 | QString text( i18n( "Sharp DTM resource '%1'<br> has been changed by third party.<br>Do you want to reload?").arg( fileName() ) ); | ||
390 | if ( readOnly() || KMessageBox::questionYesNo( 0, text ) == KMessageBox::Yes ) { | ||
391 | load(); | ||
392 | addressBook()->emitAddressBookChanged(); | ||
393 | } | ||
394 | } | 273 | } |
diff --git a/kabc/tmpaddressbook.cpp b/kabc/tmpaddressbook.cpp index 6e24302..cfa57e3 100644 --- a/kabc/tmpaddressbook.cpp +++ b/kabc/tmpaddressbook.cpp | |||
@@ -46,10 +46,3 @@ TmpAddressBook::~TmpAddressBook() | |||
46 | { | 46 | { |
47 | //remove all possible resources. This should cleanup the configfile. | 47 | removeResources(); |
48 | QPtrList<KABC::Resource> mResources = resources(); | ||
49 | |||
50 | QPtrListIterator<KABC::Resource> it(mResources); | ||
51 | for ( ; it.current(); ++it ) { | ||
52 | KABC::Resource *res = it.current(); | ||
53 | removeResource(res); | ||
54 | } | ||
55 | } | 48 | } |