TaurusZIPLibrary  $VERSION$
qtziphlp.h
Go to the documentation of this file.
1 //
2 // Description: Zip helper, base class
3 //
4 
5 /* Copyright (c) 2013 Konrad Rosenbaum <konrad@silmor.de>
6 
7 Permission is hereby granted, free of charge, to any person obtaining a copy
8 of this software and associated documentation files (the "Software"), to deal
9 in the Software without restriction, including without limitation the rights
10 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 copies of the Software, and to permit persons to whom the Software is
12 furnished to do so, subject to the following conditions:
13 
14 The above copyright notice and this permission notice shall be included in
15 all copies or substantial portions of the Software.
16 
17 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23 THE SOFTWARE. */
24 
25 #ifndef ZIPHELPER_QTZIPHLP_H
26 #define ZIPHELPER_QTZIPHLP_H
27 
28 #include "qtzipbase.h"
29 #include <QDateTime>
30 
31 class QIODevice;
32 
33 namespace QtZipHelper {
34 
35 class Zip;
36 class Unzip;
37 
40 {
41  public:
43  ZipFileInfo();
45  ZipFileInfo(const ZipFileInfo&);
47  ZipFileInfo& operator=(const ZipFileInfo&);
48 
50  bool isValid()const{return !mName.isEmpty();}
51 
54  operator bool()const{return !mName.isEmpty();}
55 
57  QString fileName()const{return mName;}
59  QDateTime createTime()const{return mTime;}
61  int rawCompressionMethod()const{return mMethod;}
63  ulong fileCRC()const{return mCRC;}
65  ulong uncompressedSize()const{return mUSize;}
66 
67  private:
68  friend class Zip;
69  friend class Unzip;
71  ZipFileInfo(const QString&,const QDateTime&,int,ulong,ulong);
72 
73  QDateTime mTime;
74  QString mName;
75  int mMethod;
76  ulong mCRC,mUSize;
77 };
78 
81 {
82  Q_OBJECT
83  friend class Unzip;
84  public:
86  explicit Zip(QObject* parent = 0);
88  virtual ~Zip();
89 
91  enum OpenMode {
93  OpenTruncate=0,
95  OpenAppend=1
96  };
98  bool isOpen() const;
99  public slots:
102  virtual bool open(QIODevice *d, OpenMode mode=OpenTruncate);
105  virtual void close();
110  virtual bool storeFile(const QString &name, QIODevice &file,
111  const QDateTime &time = QDateTime::currentDateTime());
113  virtual bool storeFile(const QString&name, QByteArray content,
114  const QDateTime &time = QDateTime::currentDateTime());
117  virtual bool storeRawFile(const ZipFileInfo&info, QIODevice &file);
120  virtual bool storeRawFile(const ZipFileInfo&info, QByteArray content);
121 };
122 
125 {
126  Q_OBJECT
127  public:
129  explicit Unzip(QObject*parent=0);
131  virtual ~Unzip();
133  virtual bool isOpen() const;
134  public slots:
137  virtual bool open(QIODevice *d);
140  virtual void close();
142  virtual int fileCount()const;
144  virtual ZipFileInfo firstFile();
146  virtual ZipFileInfo nextFile();
148  virtual ZipFileInfo locateFile(const QString &name, Qt::CaseSensitivity cs = Qt::CaseSensitive);
150  virtual ZipFileInfo currentFile()const;
153  virtual ZipFileInfo currentFile(QIODevice &d)const;
156  virtual ZipFileInfo currentFile(QByteArray&)const;
158  virtual QByteArray currentFileContent()const;
161  virtual ZipFileInfo currentFileRaw(QIODevice &d)const;
164  virtual ZipFileInfo currentFileRaw(QByteArray&)const;
166  virtual QByteArray currentFileRawContent()const;
168  virtual QString currentFileName()const;
170  virtual bool copyCurrentFile(Zip&)const;
171 };
172 
173 //end of namespace
174 };
175 
176 using namespace QtZipHelper;
177 
178 #endif
Base class of Zip and Unzip, see those for details.
Definition: qtzipbase.h:39
ulong uncompressedSize() const
returns the uncompressed file size stored for this file
Definition: qtziphlp.h:65
QString fileName() const
returns the file name of the stored file
Definition: qtziphlp.h:57
Definition: qtzipbase.h:37
ulong fileCRC() const
returns the CRC32 stored for this file
Definition: qtziphlp.h:63
#define ZIPHLP_EXPORT
Definition: qtzipbase.h:34
bool isValid() const
returns true if this is a valid info object
Definition: qtziphlp.h:50
QDateTime createTime() const
returns the creation time of the file stored in the ZIP
Definition: qtziphlp.h:59
This class represents a ZIP file being assembled.
Definition: qtziphlp.h:80
Helper class: reports information about a specific file entry in the ZIP archive. ...
Definition: qtziphlp.h:39
int rawCompressionMethod() const
returns the code of the compression method used with this file
Definition: qtziphlp.h:61
This class represents a ZIP file being read.
Definition: qtziphlp.h:124
OpenMode
Defines how the ZIP file is opened.
Definition: qtziphlp.h:91