00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef __kzip_h
00019 #define __kzip_h
00020
00021 #include <sys/stat.h>
00022 #include <sys/types.h>
00023
00024 #include <qdatetime.h>
00025 #include <qstring.h>
00026 #include <qstringlist.h>
00027 #include <qdict.h>
00028 #include <qvaluelist.h>
00029 #include <karchive.h>
00030
00031 class KZipFileEntry;
00053 class KIO_EXPORT KZip : public KArchive
00054 {
00055 public:
00062 KZip( const QString& filename );
00063
00071 KZip( QIODevice * dev );
00072
00077 virtual ~KZip();
00078
00084 QString fileName() { return m_filename; }
00085
00089 enum ExtraField { NoExtraField = 0,
00090 ModificationTime = 1,
00091 DefaultExtraField = 1
00092 };
00093
00100 void setExtraField( ExtraField ef );
00101
00107 ExtraField extraField() const;
00108
00112 enum Compression { NoCompression = 0,
00113 DeflateCompression = 1
00114 };
00115
00116
00123 void setCompression( Compression c );
00124
00130 Compression compression() const;
00131
00143 virtual bool writeFile( const QString& name, const QString& user, const QString& group, uint size, const char* data );
00144
00154 virtual bool prepareWriting( const QString& name, const QString& user, const QString& group, uint size );
00155
00156
00157 bool writeSymLink(const QString &name, const QString &target,
00158 const QString &user, const QString &group,
00159 mode_t perm, time_t atime, time_t mtime, time_t ctime);
00160
00161 bool prepareWriting( const QString& name, const QString& user,
00162 const QString& group, uint size, mode_t perm,
00163 time_t atime, time_t mtime, time_t ctime );
00164
00165 bool writeFile( const QString& name, const QString& user, const QString& group,
00166 uint size, mode_t perm, time_t atime, time_t mtime,
00167 time_t ctime, const char* data );
00174 bool writeData( const char* data, uint size );
00175
00181 virtual bool doneWriting( uint size );
00182
00183 protected:
00190 virtual bool openArchive( int mode );
00192 virtual bool closeArchive();
00193
00194 virtual bool writeDir(const QString& name, const QString& user, const QString& group);
00195
00196
00197
00198
00199 protected:
00200 virtual void virtual_hook( int id, void* data );
00202
00203 bool writeData_impl( const char* data, uint size );
00204 bool prepareWriting_impl(const QString& name, const QString& user,
00205 const QString& group, uint size, mode_t perm,
00206 time_t atime, time_t mtime, time_t ctime);
00207 bool writeSymLink_impl(const QString &name, const QString &target,
00208 const QString &user, const QString &group,
00209 mode_t perm, time_t atime, time_t mtime, time_t ctime);
00210 private:
00211 void abort();
00212
00213 private:
00214 QString m_filename;
00215 class KZipPrivate;
00216 KZipPrivate * d;
00217 };
00218
00219
00223 class KIO_EXPORT KZipFileEntry : public KArchiveFile
00224 {
00225 public:
00226
00227
00228 KZipFileEntry( KZip* zip, const QString& name, int access, int date,
00229 const QString& user, const QString& group, const QString& symlink,
00230 const QString& path, Q_LONG start, Q_LONG uncompressedSize,
00231 int encoding, Q_LONG compressedSize) :
00232 KArchiveFile( zip, name, access, date, user, group, symlink,
00233 start, uncompressedSize ),
00234 m_crc(0),
00235 m_compressedSize(compressedSize),
00236 m_headerStart(0),
00237 m_encoding(encoding),
00238 m_path( path )
00239 {}
00240 int encoding() const { return m_encoding; }
00241 Q_LONG compressedSize() const { return m_compressedSize; }
00242
00244 void setCompressedSize(Q_LONG compressedSize) { m_compressedSize = compressedSize; }
00245
00247 void setHeaderStart(Q_LONG headerstart) { m_headerStart = headerstart; }
00248 Q_LONG headerStart() const {return m_headerStart; }
00249
00251 unsigned long crc32() const { return m_crc; }
00252 void setCRC32(unsigned long crc32) { m_crc=crc32; }
00253
00255 QString path() const { return m_path; }
00256
00261 virtual QByteArray data() const;
00262
00270 QIODevice* device() const;
00271
00272 private:
00273 unsigned long m_crc;
00274 Q_LONG m_compressedSize;
00275 Q_LONG m_headerStart;
00276 int m_encoding;
00277 QString m_path;
00278
00279 };
00280
00281 #endif