libtdepim

tdeabcresourcecached.h
1/*
2 This file is part of libtdepim.
3 Copyright (c) 2004 Tobias Koenig <tokoe@kde.org>
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
19*/
20
21#ifndef TDEABC_RESOURCECACHED_H
22#define TDEABC_RESOURCECACHED_H
23
24#include <tdeabc/resource.h>
25#include <tdemacros.h>
26
27#include <tqdatetime.h>
28#include <tqtimer.h>
29
30#include "libemailfunctions/idmapper.h"
31
32namespace TDEABC {
33
34class TDE_EXPORT ResourceCached : public Resource
35{
36 TQ_OBJECT
37
38
39 public:
45 enum { ReloadNever, ReloadOnStartup, ReloadInterval };
51 enum { SaveNever, SaveOnExit, SaveInterval, SaveDelayed, SaveAlways };
52
53 ResourceCached( const TDEConfig* );
54 ~ResourceCached();
55
63 void setReloadPolicy( int policy );
69 int reloadPolicy() const;
70
75 void setReloadInterval( int minutes );
76
80 int reloadInterval() const;
81
91 void setSavePolicy( int policy );
97 int savePolicy() const;
98
103 void setSaveInterval( int minutes );
104
108 int saveInterval() const;
109
110 void setupSaveTimer();
111 void setupReloadTimer();
112
116 virtual void readConfig( TDEConfig *config );
117
121 virtual void writeConfig( TDEConfig *config );
122
126 virtual void insertAddressee( const Addressee& );
127
131 virtual void removeAddressee( const Addressee& addr );
132
133 void loadCache();
134 void saveCache();
135 void clearCache();
136 void cleanUpCache( const TDEABC::Addressee::List &list );
137
141 KPIM::IdMapper& idMapper();
142
143 bool hasChanges() const;
144 void clearChanges();
145 void clearChange( const TDEABC::Addressee& );
146 void clearChange( const TQString& );
147
148 TDEABC::Addressee::List addedAddressees() const;
149 TDEABC::Addressee::List changedAddressees() const;
150 TDEABC::Addressee::List deletedAddressees() const;
151
152 protected:
153 virtual TQString cacheFile() const;
154
158 virtual TQString changesCacheFile( const TQString& ) const;
159 void loadChangesCache( TQMap<TQString, TDEABC::Addressee>&, const TQString& );
160 void loadChangesCache();
161 void saveChangesCache( const TQMap<TQString, TDEABC::Addressee>&, const TQString& );
162 void saveChangesCache();
163
164 void setIdMapperIdentifier();
165
166 private:
167 TQMap<TQString, TDEABC::Addressee> mAddedAddressees;
168 TQMap<TQString, TDEABC::Addressee> mChangedAddressees;
169 TQMap<TQString, TDEABC::Addressee> mDeletedAddressees;
170
171 KPIM::IdMapper mIdMapper;
172
173 class ResourceCachedPrivate;
174 ResourceCachedPrivate *d;
175
176 int mReloadPolicy;
177 int mReloadInterval;
178 TQTimer mKABCReloadTimer;
179 bool mReloaded;
180
181 int mSavePolicy;
182 int mSaveInterval;
183 TQTimer mKABCSaveTimer;
184
185 TQDateTime mLastLoad;
186 TQDateTime mLastSave;
187
188 protected slots:
189 void slotKABCReload();
190 void slotKABCSave();
191};
192
193}
194
195#endif