zip.h

Go to the documentation of this file.
00001 /****************************************************************************
00002 ** Filename: zip.h
00003 ** Last updated [dd/mm/yyyy]: 01/02/2007
00004 **
00005 ** pkzip 2.0 file compression.
00006 **
00007 ** Some of the code has been inspired by other open source projects,
00008 ** (mainly Info-Zip and Gilles Vollant's minizip).
00009 ** Compression and decompression actually uses the zlib library.
00010 **
00011 ** Copyright (C) 2007 Angius Fabrizio. All rights reserved.
00012 **
00013 ** This file is part of the OSDaB project (http://osdab.sourceforge.net/).
00014 **
00015 ** This file may be distributed and/or modified under the terms of the
00016 ** GNU General Public License version 2 as published by the Free Software
00017 ** Foundation and appearing in the file LICENSE.GPL included in the
00018 ** packaging of this file.
00019 **
00020 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00021 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00022 **
00023 ** See the file LICENSE.GPL that came with this software distribution or
00024 ** visit http://www.gnu.org/copyleft/gpl.html for GPL licensing information.
00025 **
00026 **********************************************************************/
00027 
00028 #ifndef OSDAB_ZIP__H
00029 #define OSDAB_ZIP__H
00030 
00031 #include <QtGlobal>
00032 #include <QMap>
00033 
00034 #include <zlib.h>
00035 
00036 class ZipPrivate;
00037 
00038 class QIODevice;
00039 class QFile;
00040 class QDir;
00041 class QStringList;
00042 class QString;
00043 
00044 
00045 class Zip
00046 {
00047 public:
00048     enum ErrorCode
00049     {
00050         Ok,
00051         ZlibInit,
00052         ZlibError,
00053         FileExists,
00054         OpenFailed,
00055         NoOpenArchive,
00056         FileNotFound,
00057         ReadFailed,
00058         WriteFailed,
00059         SeekFailed
00060     };
00061 
00062     enum CompressionLevel
00063     {
00064         Store,
00065         Deflate1 = 1, Deflate2, Deflate3, Deflate4,
00066         Deflate5, Deflate6, Deflate7, Deflate8, Deflate9,
00067         AutoCPU, AutoMIME, AutoFull
00068     };
00069 
00070     enum CompressionOption
00071     {
00073         RelativePaths = 0x0001,
00075         AbsolutePaths = 0x0002,
00077         IgnorePaths = 0x0004
00078     };
00079     Q_DECLARE_FLAGS(CompressionOptions, CompressionOption)
00080 
00081     Zip();
00082     virtual ~Zip();
00083 
00084     bool isOpen() const;
00085 
00086     void setPassword(const QString& pwd);
00087     void clearPassword();
00088     QString password() const;
00089 
00090     ErrorCode createArchive(const QString& file, bool overwrite = true);
00091     ErrorCode createArchive(QIODevice* device);
00092 
00093     QString archiveComment() const;
00094     void setArchiveComment(const QString& comment);
00095 
00096     ErrorCode addDirectoryContents(const QString& path, CompressionLevel level = AutoFull);
00097     ErrorCode addDirectoryContents(const QString& path, const QString& root, CompressionLevel level = AutoFull);
00098 
00099     ErrorCode addDirectory(const QString& path, CompressionOptions options = RelativePaths, CompressionLevel level = AutoFull);
00100     ErrorCode addDirectory(const QString& path, const QString& root, CompressionLevel level = AutoFull);
00101     ErrorCode addDirectory(const QString& path, const QString& root, CompressionOptions options = RelativePaths, CompressionLevel level = AutoFull);
00102 
00103     ErrorCode closeArchive();
00104 
00105     QString formatError(ErrorCode c) const;
00106 
00107 private:
00108     ZipPrivate* d;
00109 };
00110 
00111 Q_DECLARE_OPERATORS_FOR_FLAGS(Zip::CompressionOptions)
00112 
00113 #endif // OSDAB_ZIP__H