libkdepim

kabcresourcecached.h

00001 /*
00002     This file is part of libkdepim.
00003     Copyright (c) 2004 Tobias Koenig <tokoe@kde.org>
00004 
00005     This library is free software; you can redistribute it and/or
00006     modify it under the terms of the GNU Library General Public
00007     License as published by the Free Software Foundation; either
00008     version 2 of the License, or (at your option) any later version.
00009 
00010     This library 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 GNU
00013     Library General Public License for more details.
00014 
00015     You should have received a copy of the GNU Library General Public License
00016     along with this library; see the file COPYING.LIB.  If not, write to
00017     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00018     Boston, MA 02110-1301, USA.
00019 */
00020 
00021 #ifndef KABC_RESOURCECACHED_H
00022 #define KABC_RESOURCECACHED_H
00023 
00024 #include <kabc/resource.h>
00025 #include <kdepimmacros.h>
00026 
00027 #include <tqdatetime.h>
00028 #include <tqtimer.h>
00029 
00030 #include "libemailfunctions/idmapper.h"
00031 
00032 namespace KABC {
00033 
00034 class KDE_EXPORT ResourceCached : public Resource
00035 {
00036   Q_OBJECT
00037 
00038   public:
00044     enum { ReloadNever, ReloadOnStartup, ReloadInterval };
00050     enum { SaveNever, SaveOnExit, SaveInterval, SaveDelayed, SaveAlways };
00051 
00052     ResourceCached( const KConfig* );
00053     ~ResourceCached();
00054 
00062     void setReloadPolicy( int policy );
00068     int reloadPolicy() const;
00069 
00074     void setReloadInterval( int minutes );
00075 
00079     int reloadInterval() const;
00080 
00090     void setSavePolicy( int policy );
00096     int savePolicy() const;
00097 
00102     void setSaveInterval( int minutes );
00103 
00107     int saveInterval() const;
00108 
00109     void setupSaveTimer();
00110     void setupReloadTimer();
00111 
00115    virtual void readConfig( KConfig *config );
00116 
00120     virtual void writeConfig( KConfig *config );
00121 
00125     virtual void insertAddressee( const Addressee& );
00126 
00130     virtual void removeAddressee( const Addressee& addr );
00131 
00132     void loadCache();
00133     void saveCache();
00134     void clearCache();
00135     void cleanUpCache( const KABC::Addressee::List &list );
00136 
00140     KPIM::IdMapper& idMapper();
00141 
00142     bool hasChanges() const;
00143     void clearChanges();
00144     void clearChange( const KABC::Addressee& );
00145     void clearChange( const TQString& );
00146 
00147     KABC::Addressee::List addedAddressees() const;
00148     KABC::Addressee::List changedAddressees() const;
00149     KABC::Addressee::List deletedAddressees() const;
00150 
00151   protected:
00152     virtual TQString cacheFile() const;
00153 
00157     virtual TQString changesCacheFile( const TQString& ) const;
00158     void loadChangesCache( TQMap<TQString, KABC::Addressee>&, const TQString& );
00159     void loadChangesCache();
00160     void saveChangesCache( const TQMap<TQString, KABC::Addressee>&, const TQString& );
00161     void saveChangesCache();
00162 
00163     void setIdMapperIdentifier();
00164 
00165   private:
00166     TQMap<TQString, KABC::Addressee> mAddedAddressees;
00167     TQMap<TQString, KABC::Addressee> mChangedAddressees;
00168     TQMap<TQString, KABC::Addressee> mDeletedAddressees;
00169 
00170     KPIM::IdMapper mIdMapper;
00171 
00172     class ResourceCachedPrivate;
00173     ResourceCachedPrivate *d;
00174 
00175     int mReloadPolicy;
00176     int mReloadInterval;
00177     TQTimer mKABCReloadTimer;
00178     bool mReloaded;
00179 
00180     int mSavePolicy;
00181     int mSaveInterval;
00182     TQTimer mKABCSaveTimer;
00183 
00184     TQDateTime mLastLoad;
00185     TQDateTime mLastSave;
00186 
00187   protected slots:
00188     void slotKABCReload();
00189     void slotKABCSave();
00190 };
00191 
00192 }
00193 
00194 #endif