• Skip to content
  • Skip to link menu
KDE 4.2 API Reference
  • KDE API Reference
  • kdepim
  • Sitemap
  • Contact Us
 

kaddressbook

kablock.cpp

Go to the documentation of this file.
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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 <kabc/addressbook.h>
00025 #include <kabc/resource.h>
00026 #include <klocale.h>
00027 #include <kmessagebox.h>
00028 
00029 #include "kablock.h"
00030 
00031 class KABLockHelper {
00032   public:
00033     KABLockHelper() : q( 0 ) {}
00034     ~KABLockHelper() { delete q; }
00035     KABLock *q;
00036 };
00037 
00038 K_GLOBAL_STATIC( KABLockHelper, s_globalKABLock )
00039 
00040 class AddressBookWrapper : public KABC::AddressBook
00041 {
00042   public:
00043     AddressBookWrapper( KABC::AddressBook* );
00044 
00045     KABC::Resource* getStandardResource()
00046     {
00047       return standardResource();
00048     }
00049 };
00050 
00051 KABLock::KABLock( KABC::AddressBook *ab )
00052   : mAddressBook( ab )
00053 {
00054   Q_ASSERT( !( s_globalKABLock->q ) );
00055   s_globalKABLock->q = this;
00056 }
00057 
00058 KABLock::~KABLock()
00059 {
00060 }
00061 
00062 KABLock *KABLock::self( KABC::AddressBook *ab )
00063 {
00064   if ( !s_globalKABLock->q )
00065     new KABLock( ab );
00066   else
00067     s_globalKABLock->q->mAddressBook = ab;
00068 
00069   return s_globalKABLock->q;
00070 }
00071 
00072 bool KABLock::lock( KABC::Resource *resource )
00073 {
00074   if ( mLocks.find( resource ) == mLocks.end() ) { // not locked yet
00075     KABC::Ticket *ticket = mAddressBook->requestSaveTicket( resource );
00076     if ( !ticket ) {
00077       return false;
00078     } else {
00079       LockEntry entry;
00080       entry.ticket = ticket;
00081       entry.counter = 1;
00082       mLocks.insert( resource, entry );
00083     }
00084   } else {
00085     LockEntry &entry = mLocks[ resource ];
00086     entry.counter++;
00087   }
00088 
00089   return true;
00090 }
00091 
00092 bool KABLock::unlock( KABC::Resource *resource )
00093 {
00094   AddressBookWrapper *wrapper = static_cast<AddressBookWrapper*>( mAddressBook );
00095   if ( resource == 0 )
00096     resource = wrapper->getStandardResource();
00097 
00098   if ( mLocks.find( resource ) == mLocks.end() ) { // hmm, not good...
00099     return false;
00100   } else {
00101     LockEntry &entry = mLocks[ resource ];
00102     entry.counter--;
00103 
00104     if ( entry.counter == 0 ) {
00105       mAddressBook->save( entry.ticket );
00106 //      # Activate in KDE 4.0
00107 //      mAddressBook->releaseSaveTicket( entry.ticket );
00108 
00109       mLocks.remove( resource );
00110     }
00111   }
00112 
00113   return true;
00114 }

kaddressbook

Skip menu "kaddressbook"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Class Members
  • Related Pages

kdepim

Skip menu "kdepim"
  • akonadi
  •   clients
  •   kabc
  •   kcal
  •   kcm
  • akregator
  • console
  •   kabcclient
  •   konsolekalendar
  • kaddressbook
  • kalarm
  •   lib
  • kdgantt
  • kdgantt1
  • kjots
  • kleopatra
  • kmail
  • kmobiletools
  • knode
  • knotes
  • kontact
  • kontactinterfaces
  • korganizer
  •   korgac
  • kpilot
  • ktimetracker
  •   doc
  • libkdepim
  • libkholidays
  • libkleo
  • libkpgp
  • maildir
Generated for kdepim by doxygen 1.5.4
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal