24 #include <tdeabc/addressbook.h>
25 #include <tdeabc/resource.h>
26 #include <tdelocale.h>
27 #include <tdemessagebox.h>
28 #include <kstaticdeleter.h>
32 class AddressBookWrapper :
public TDEABC::AddressBook
35 AddressBookWrapper( TDEABC::AddressBook* );
37 TDEABC::Resource* getStandardResource()
39 return standardResource();
43 KABLock *KABLock::mSelf = 0;
45 static KStaticDeleter<KABLock> kabLockDeleter;
47 KABLock::KABLock( TDEABC::AddressBook *ab )
56 KABLock *KABLock::self( TDEABC::AddressBook *ab )
59 kabLockDeleter.setObject( mSelf,
new KABLock( ab ) );
61 mSelf->mAddressBook = ab;
66 bool KABLock::lock( TDEABC::Resource *resource )
68 if ( mLocks.find( resource ) == mLocks.end() ) {
69 TDEABC::Ticket *ticket = mAddressBook->requestSaveTicket( resource );
74 entry.ticket = ticket;
76 mLocks.insert( resource, entry );
79 LockEntry &entry = mLocks[ resource ];
86 bool KABLock::unlock( TDEABC::Resource *resource )
88 AddressBookWrapper *wrapper =
static_cast<AddressBookWrapper*
>( mAddressBook );
90 resource = wrapper->getStandardResource();
92 if ( mLocks.find( resource ) == mLocks.end() ) {
95 LockEntry &entry = mLocks[ resource ];
98 if ( entry.counter == 0 ) {
99 mAddressBook->save( entry.ticket );
103 mLocks.remove( resource );