kzip.h
/* This file is part of the KDE libraries
Copyright (C) 2002 Holger Schroeder <holger-kde@holgis.net>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License version 2 as published by the Free Software Foundation.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#ifndef __kzip_h
#define __kzip_h
#include <sys/stat.h>
#include <sys/types.h>
#include <qdatetime.h>
#include <qstring.h>
#include <qstringlist.h>
#include <qdict.h>
#include <qvaluelist.h>
#include <karchive.h>
class KZipFileEntry;
class KIO_EXPORT KZip : public KArchive
{
public:
KZip( const QString& filename );
KZip( QIODevice * dev );
virtual ~KZip();
QString fileName() { return m_filename; }
enum ExtraField { NoExtraField = 0,
ModificationTime = 1,
DefaultExtraField = 1
};
void setExtraField( ExtraField ef );
ExtraField extraField() const;
enum Compression { NoCompression = 0,
DeflateCompression = 1
};
void setCompression( Compression c );
Compression compression() const;
virtual bool writeFile( const QString& name, const QString& user, const QString& group, uint size, const char* data ); // BC: remove reimplementation for KDE-4.0
virtual bool prepareWriting( const QString& name, const QString& user, const QString& group, uint size );
// TODO(BIC) make virtual. For now it must be implemented by virtual_hook.
bool writeSymLink(const QString &name, const QString &target,
const QString &user, const QString &group,
mode_t perm, time_t atime, time_t mtime, time_t ctime);
// TODO(BIC) make virtual. For now it must be implemented by virtual_hook.
bool prepareWriting( const QString& name, const QString& user,
const QString& group, uint size, mode_t perm,
time_t atime, time_t mtime, time_t ctime );
// TODO(BIC) make virtual. For now it must be implemented by virtual_hook.
bool writeFile( const QString& name, const QString& user, const QString& group,
uint size, mode_t perm, time_t atime, time_t mtime,
time_t ctime, const char* data );
bool writeData( const char* data, uint size ); // TODO make virtual
virtual bool doneWriting( uint size );
protected:
virtual bool openArchive( int mode );
virtual bool closeArchive();
virtual bool writeDir( const QString& name, const QString& user, const QString& group) { Q_UNUSED(name); Q_UNUSED(user); Q_UNUSED(group); return true; }
// TODO(BIC) uncomment and make virtual for KDE 4.
// bool writeDir( const QString& name, const QString& user, const QString& group,
// mode_t perm, time_t atime, time_t mtime, time_t ctime );
protected:
virtual void virtual_hook( int id, void* data );
// from KArchive
bool writeData_impl( const char* data, uint size );
bool prepareWriting_impl(const QString& name, const QString& user,
const QString& group, uint size, mode_t perm,
time_t atime, time_t mtime, time_t ctime);
bool writeSymLink_impl(const QString &name, const QString &target,
const QString &user, const QString &group,
mode_t perm, time_t atime, time_t mtime, time_t ctime);
private:
void abort();
private:
QString m_filename;
class KZipPrivate;
KZipPrivate * d;
};
class KIO_EXPORT KZipFileEntry : public KArchiveFile
{
public:
/*KZipFileEntry() : st(-1)
{}*/
KZipFileEntry( KZip* zip, const QString& name, int access, int date,
const QString& user, const QString& group, const QString& symlink,
const QString& path, Q_LONG start, Q_LONG uncompressedSize,
int encoding, Q_LONG compressedSize) :
KArchiveFile( zip, name, access, date, user, group, symlink,
start, uncompressedSize ),
m_crc(0),
m_compressedSize(compressedSize),
m_headerStart(0),
m_encoding(encoding),
m_path( path )
{}
int encoding() const { return m_encoding; }
Q_LONG compressedSize() const { return m_compressedSize; }
void setCompressedSize(Q_LONG compressedSize) { m_compressedSize = compressedSize; }
void setHeaderStart(Q_LONG headerstart) { m_headerStart = headerstart; }
Q_LONG headerStart() const {return m_headerStart; }
unsigned long crc32() const { return m_crc; }
void setCRC32(unsigned long crc32) { m_crc=crc32; }
QString path() const { return m_path; }
virtual QByteArray data() const;
QIODevice* device() const; // WARNING, not virtual!
private:
unsigned long m_crc;
Q_LONG m_compressedSize;
Q_LONG m_headerStart;
int m_encoding;
QString m_path;
// KDE4: d pointer or at least some int for future extensions
};
#endif
KZip::ExtraField
ExtraField
Describes the contents of the "extra field" for a given file in the Zip archive.
Definition: kzip.h:89
KZip::writeDir
virtual bool writeDir(const QString &name, const QString &user, const QString &group)
If an archive is opened for writing then you can add new directories using this function.
Definition: kzip.h:197
KArchive
KArchive is a base class for reading and writing archives.
Definition: karchive.h:42
KArchive::writeData
bool writeData(const char *data, uint size)
Write data into the current file - to be called after calling prepareWriting.
Definition: karchive.cpp:353
KArchive::doneWriting
virtual bool doneWriting(uint size)=0
Call doneWriting after writing the data.
KArchive::openArchive
virtual bool openArchive(int mode)=0
Opens an archive for reading or writing.
KArchiveFile::device
QIODevice * device() const
This method returns QIODevice (internal class: KLimitedIODevice) on top of the underlying QIODevice...
Definition: karchive.cpp:509
KArchive::writeFile
virtual bool writeFile(const QString &name, const QString &user, const QString &group, uint size, const char *data)
If an archive is opened for writing then you can add a new file using this function.
Definition: karchive.cpp:228
KZip
This class implements a kioslave to access zip files from KDE.
Definition: kzip.h:53
KZip::Compression
Compression
Describes the compression type for a given file in the Zip archive.
Definition: kzip.h:112
KArchive::writeSymLink
bool writeSymLink(const QString &name, const QString &target, const QString &user, const QString &group, mode_t perm, time_t atime, time_t mtime, time_t ctime)
Writes a symbolic link to the archive if the archive must be opened for writing.
Definition: karchive.cpp:327
KArchive::closeArchive
virtual bool closeArchive()=0
Closes the archive.
KZip::fileName
QString fileName()
The name of the zip file, as passed to the constructor.
Definition: kzip.h:84
KArchiveFile
Represents a file entry in a KArchive.
Definition: karchive.h:490
KArchiveFile::data
virtual QByteArray data() const
Returns the data of the file.
Definition: karchive.cpp:492
KArchive::prepareWriting
virtual bool prepareWriting(const QString &name, const QString &user, const QString &group, uint size)=0
Here's another way of writing a file into an archive: Call prepareWriting, then call writeData() as m...

KDE Home | KDE Accessibility Home | Description of Access Keys