00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef KABC_RESOURCEFILE_H
00022 #define KABC_RESOURCEFILE_H
00023
00024 #include "kabc/kabc_export.h"
00025 #include "kabc/resource.h"
00026
00027 #include <kconfig.h>
00028 #include <kdirwatch.h>
00029
00030 #include <sys/types.h>
00031
00032 class QFile;
00033 class KTemporaryFile;
00034
00035 class KJob;
00036
00037 namespace KABC {
00038
00039 class Format;
00040 class Lock;
00041
00045 class KABC_FILE_CORE_EXPORT ResourceFile : public Resource
00046 {
00047 Q_OBJECT
00048
00049 public:
00053 ResourceFile();
00059 explicit ResourceFile( const KConfigGroup &group );
00060
00067 explicit ResourceFile( const QString &fileName,
00068 const QString &formatName = QLatin1String( "vcard" ) );
00069
00073 ~ResourceFile();
00074
00078 virtual void writeConfig( KConfigGroup &group );
00079
00084 virtual bool doOpen();
00085
00089 virtual void doClose();
00090
00094 virtual Ticket *requestSaveTicket();
00095
00096 virtual void releaseSaveTicket( Ticket *ticket );
00097
00102 virtual bool load();
00103
00104 virtual bool asyncLoad();
00105
00112 virtual bool save( Ticket *ticket );
00113
00114 virtual bool asyncSave( Ticket *ticket );
00115
00119 void setFileName( const QString & );
00120
00124 QString fileName() const;
00125
00129 void setFormat( const QString &name );
00130
00134 QString format() const;
00135
00144 virtual void removeAddressee( const Addressee &addr );
00145
00146 private Q_SLOTS:
00147 void emitLoadingFinished();
00148 void emitSavingFinished();
00149
00150 protected Q_SLOTS:
00151 void fileChanged( const QString &path );
00152
00153 protected:
00154 void init( const QString &fileName, const QString &format );
00155
00156 bool lock( const QString &fileName );
00157 void unlock( const QString &fileName );
00158
00159 private:
00160 bool clearAndLoad( QFile *file );
00161 void saveToFile( QFile *file );
00162 bool createLocalTempFile();
00163 void deleteLocalTempFile();
00164 void deleteStaleTempFile();
00165 bool hasTempFile() const { return mTempFile != 0; }
00166 bool loadDistributionLists();
00167 void saveDistributionLists();
00168
00169 QString mFileName;
00170 QString mFormatName;
00171
00172 Format *mFormat;
00173
00174 Lock *mLock;
00175
00176 KDirWatch mDirWatch;
00177
00178 KTemporaryFile *mTempFile;
00179
00180 bool mAsynchronous;
00181
00182 class ResourceFilePrivate;
00183 ResourceFilePrivate *d;
00184 };
00185
00186 }
00187
00188 #endif