kaddressbook Library API Documentation

kablock.cpp

00001 /* 00002 This file is part of KAddressBook. 00003 Copyright (c) 2003 Tobias Koenig <tokoe@kde.org> 00004 00005 This program is free software; you can redistribute it and/or modify 00006 it under the terms of the GNU General Public License as published by 00007 the Free Software Foundation; either version 2 of the License, or 00008 (at your option) any later version. 00009 00010 This program is distributed in the hope that it will be useful, 00011 but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 GNU General Public License for more details. 00014 00015 You should have received a copy of the GNU General Public License 00016 along with this program; if not, write to the Free Software 00017 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00018 00019 As a special exception, permission is given to link this program 00020 with any edition of Qt, and distribute the resulting executable, 00021 without including the source code for Qt in the source distribution. 00022 */ 00023 00024 #include <klocale.h> 00025 #include <kmessagebox.h> 00026 #include <kstaticdeleter.h> 00027 00028 #include "kablock.h" 00029 00030 KABLock *KABLock::mSelf = 0; 00031 00032 static KStaticDeleter<KABLock> kabLockDeleter; 00033 00034 KABLock::KABLock( KABC::AddressBook *ab ) 00035 : mAddressBook( ab ) 00036 { 00037 } 00038 00039 KABLock::~KABLock() 00040 { 00041 } 00042 00043 KABLock *KABLock::self( KABC::AddressBook *ab ) 00044 { 00045 if ( !mSelf ) 00046 kabLockDeleter.setObject( mSelf, new KABLock( ab ) ); 00047 00048 return mSelf; 00049 } 00050 00051 bool KABLock::lock( KABC::Resource *resource ) 00052 { 00053 if ( mLocks.find( resource ) == mLocks.end() ) { // not locked yet 00054 KABC::Ticket *ticket = mAddressBook->requestSaveTicket( resource ); 00055 if ( !ticket ) { 00056 return false; 00057 } else { 00058 LockEntry entry; 00059 entry.ticket = ticket; 00060 entry.counter = 1; 00061 mLocks.insert( resource, entry ); 00062 } 00063 } else { 00064 LockEntry &entry = mLocks[ resource ]; 00065 entry.counter++; 00066 } 00067 00068 return true; 00069 } 00070 00071 bool KABLock::unlock( KABC::Resource *resource ) 00072 { 00073 if ( mLocks.find( resource ) == mLocks.end() ) { // hmm, not good... 00074 return false; 00075 } else { 00076 LockEntry &entry = mLocks[ resource ]; 00077 entry.counter--; 00078 00079 if ( entry.counter == 0 ) { 00080 mAddressBook->save( entry.ticket ); 00081 // # Activate in KDE 4.0 00082 // mAddressBook->releaseSaveTicket( entry.ticket ); 00083 00084 mLocks.remove( resource ); 00085 } 00086 } 00087 00088 return true; 00089 }
KDE Logo
This file is part of the documentation for kaddressbook Library Version 3.2.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Wed Jul 28 23:58:08 2004 by doxygen 1.3.7 written by Dimitri van Heesch, © 1997-2003