libtdepim

tdeabcresourcecached.h

00001 /*
00002     This file is part of libtdepim.
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 TDEABC_RESOURCECACHED_H
00022 #define TDEABC_RESOURCECACHED_H
00023 
00024 #include <tdeabc/resource.h>
00025 #include <tdepimmacros.h>
00026 
00027 #include <tqdatetime.h>
00028 #include <tqtimer.h>
00029 
00030 #include "libemailfunctions/idmapper.h"
00031 
00032 namespace TDEABC {
00033 
00034 class KDE_EXPORT ResourceCached : public Resource
00035 {
00036   Q_OBJECT
00037   
00038 
00039   public:
00045     enum { ReloadNever, ReloadOnStartup, ReloadInterval };
00051     enum { SaveNever, SaveOnExit, SaveInterval, SaveDelayed, SaveAlways };
00052 
00053     ResourceCached( const TDEConfig* );
00054     ~ResourceCached();
00055 
00063     void setReloadPolicy( int policy );
00069     int reloadPolicy() const;
00070 
00075     void setReloadInterval( int minutes );
00076 
00080     int reloadInterval() const;
00081 
00091     void setSavePolicy( int policy );
00097     int savePolicy() const;
00098 
00103     void setSaveInterval( int minutes );
00104 
00108     int saveInterval() const;
00109 
00110     void setupSaveTimer();
00111     void setupReloadTimer();
00112 
00116    virtual void readConfig( TDEConfig *config );
00117 
00121     virtual void writeConfig( TDEConfig *config );
00122 
00126     virtual void insertAddressee( const Addressee& );
00127 
00131     virtual void removeAddressee( const Addressee& addr );
00132 
00133     void loadCache();
00134     void saveCache();
00135     void clearCache();
00136     void cleanUpCache( const TDEABC::Addressee::List &list );
00137 
00141     KPIM::IdMapper& idMapper();
00142 
00143     bool hasChanges() const;
00144     void clearChanges();
00145     void clearChange( const TDEABC::Addressee& );
00146     void clearChange( const TQString& );
00147 
00148     TDEABC::Addressee::List addedAddressees() const;
00149     TDEABC::Addressee::List changedAddressees() const;
00150     TDEABC::Addressee::List deletedAddressees() const;
00151 
00152   protected:
00153     virtual TQString cacheFile() const;
00154 
00158     virtual TQString changesCacheFile( const TQString& ) const;
00159     void loadChangesCache( TQMap<TQString, TDEABC::Addressee>&, const TQString& );
00160     void loadChangesCache();
00161     void saveChangesCache( const TQMap<TQString, TDEABC::Addressee>&, const TQString& );
00162     void saveChangesCache();
00163 
00164     void setIdMapperIdentifier();
00165 
00166   private:
00167     TQMap<TQString, TDEABC::Addressee> mAddedAddressees;
00168     TQMap<TQString, TDEABC::Addressee> mChangedAddressees;
00169     TQMap<TQString, TDEABC::Addressee> mDeletedAddressees;
00170 
00171     KPIM::IdMapper mIdMapper;
00172 
00173     class ResourceCachedPrivate;
00174     ResourceCachedPrivate *d;
00175 
00176     int mReloadPolicy;
00177     int mReloadInterval;
00178     TQTimer mKABCReloadTimer;
00179     bool mReloaded;
00180 
00181     int mSavePolicy;
00182     int mSaveInterval;
00183     TQTimer mKABCSaveTimer;
00184 
00185     TQDateTime mLastLoad;
00186     TQDateTime mLastSave;
00187 
00188   protected slots:
00189     void slotKABCReload();
00190     void slotKABCSave();
00191 };
00192 
00193 }
00194 
00195 #endif