Scribus
Open source desktop publishing at your fingertips
zip.h
1 /****************************************************************************
2 ** Filename: zip.h
3 ** Last updated [dd/mm/yyyy]: 27/03/2011
4 **
5 ** pkzip 2.0 file compression.
6 **
7 ** Some of the code has been inspired by other open source projects,
8 ** (mainly Info-Zip and Gilles Vollant's minizip).
9 ** Compression and decompression actually uses the zlib library.
10 **
11 ** Copyright (C) 2007-2012 Angius Fabrizio. All rights reserved.
12 **
13 ** This file is part of the OSDaB project (http://osdab.42cows.org/).
14 **
15 ** This file may be distributed and/or modified under the terms of the
16 ** GNU General Public License version 2 as published by the Free Software
17 ** Foundation and appearing in the file LICENSE.GPL included in the
18 ** packaging of this file.
19 **
20 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
21 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
22 **
23 ** See the file LICENSE.GPL that came with this software distribution or
24 ** visit http://www.gnu.org/copyleft/gpl.html for GPL licensing information.
25 **
26 **********************************************************************/
27 
28 #ifndef OSDAB_ZIP__H
29 #define OSDAB_ZIP__H
30 
31 #include "zipglobal.h"
32 
33 #include <QtCore/QMap>
34 #include <QtCore/QtGlobal>
35 
36 #include <zlib.h>
37 //#include <zlib/zlib.h>
38 
39 class QIODevice;
40 class QFile;
41 class QDir;
42 class QStringList;
43 class QString;
44 
45 OSDAB_BEGIN_NAMESPACE(Zip)
46 
47 class ZipPrivate;
48 
49 class /*OSDAB_ZIP_EXPORT*/ Zip
50 {
51 public:
52  enum ErrorCode
53  {
54  Ok,
55  ZlibInit,
56  ZlibError,
57  FileExists,
58  OpenFailed,
59  NoOpenArchive,
60  FileNotFound,
61  ReadFailed,
62  WriteFailed,
63  SeekFailed,
64  InternalError
65  };
66 
68  {
69  Store,
70  Deflate1 = 1, Deflate2, Deflate3, Deflate4,
71  Deflate5, Deflate6, Deflate7, Deflate8, Deflate9,
72  AutoCPU, AutoMIME, AutoFull
73  };
74 
76  {
79  RelativePaths = 0x0001,
81  AbsolutePaths = 0x0002,
84  IgnorePaths = 0x0004,
88  IgnoreRoot = 0x0008,
92  SkipBadFiles = 0x0020,
98  CheckForDuplicates = 0x0040
99  };
100  Q_DECLARE_FLAGS(CompressionOptions, CompressionOption)
101 
102  Zip();
103  virtual ~Zip();
104 
105  bool isOpen() const;
106 
107  void setPassword(const QString& pwd);
108  void clearPassword();
109  QString password() const;
110 
111  ErrorCode createArchive(const QString& file, bool overwrite = true);
112  ErrorCode createArchive(QIODevice* device);
113 
114  QString archiveComment() const;
115  void setArchiveComment(const QString& comment);
116 
117  ErrorCode addDirectoryContents(const QString& path,
118  CompressionLevel level = AutoFull);
119  ErrorCode addDirectoryContents(const QString& path, const QString& root,
120  CompressionLevel level = AutoFull);
121 
122  ErrorCode addDirectory(const QString& path,
123  CompressionLevel level = AutoFull);
124  ErrorCode addDirectory(const QString& path, const QString& root,
125  CompressionLevel level = AutoFull);
126  ErrorCode addDirectory(const QString& path, const QString& root,
127  CompressionOptions options, CompressionLevel level = AutoFull,
128  int* addedFiles = 0);
129 
130  ErrorCode addFile(const QString& path,
131  CompressionLevel level = AutoFull);
132  ErrorCode addFile(const QString& path, const QString& root,
133  CompressionLevel level = AutoFull);
134  ErrorCode addFile(const QString& path, const QString& root,
135  CompressionOptions options,
136  CompressionLevel level = AutoFull);
137 
138  ErrorCode addFiles(const QStringList& paths,
139  CompressionLevel level = AutoFull);
140  ErrorCode addFiles(const QStringList& paths, const QString& root,
141  CompressionLevel level = AutoFull);
142  ErrorCode addFiles(const QStringList& paths, const QString& root,
143  CompressionOptions options,
144  CompressionLevel level = AutoFull,
145  int* addedFiles = 0);
146 
147  ErrorCode closeArchive();
148 
149  QString formatError(ErrorCode c) const;
150 
151 private:
152  ZipPrivate* d;
153 };
154 
155 Q_DECLARE_OPERATORS_FOR_FLAGS(Zip::CompressionOptions)
156 
157 OSDAB_END_NAMESPACE
158 
159 #endif // OSDAB_ZIP__H
CompressionLevel
Definition: zip.h:67
Zip file compression.
Definition: zip.h:49
Definition: zip_p.h:60
ErrorCode
Definition: zip.h:52
CompressionOption
Definition: zip.h:75