Quark  0.1
ZipFile.h++
Go to the documentation of this file.
1 #ifndef __libquark_zipfile_ZipFile_hxx
2 #define __libquark_zipfile_ZipFile_hxx
3 
4 #include <QDateTime>
5 #include <QIODevice>
6 #include <QString>
7 
8 namespace quark {
9 namespace zipfile {
10 
11 class ZipEntry;
12 
19 class ZipFile
20 {
21  friend class ZipEntry;
22 
23  public:
24 
26  ZipFile(const QString &file);
27 
29  virtual ~ZipFile();
30 
40  bool open(QIODevice::OpenMode openMode,
41  const QString &password = QString());
42 
51  bool close();
52 
54  bool isOpen() const;
55 
57  QString archiveComment();
58 
66  bool setArchiveComment(const QString &comment);
67 
69  qint64 numEntries();
70 
77  QString getEntryPath(qint64 index);
78 
88  bool getEntry(qint64 index, ZipEntry &entry);
89 
101  bool getEntry(const QString &path, ZipEntry &entry, bool ignoreCase = false);
102 
111  QString getEntryComment(qint64 index);
112 
122  bool setEntryComment(qint64 index, const QString &comment);
123 
131  bool removeEntry(qint64 index);
132 
142  bool renameEntry(qint64 index, const QString &newPath);
143 
153  bool openEntry(qint64 index);
154 
156  bool isEntryOpen() const;
157 
164  int readEntry(char *buf, int count);
165 
167  void closeEntry();
168 
178  bool extractEntry(const ZipEntry &entry, const QString &outputPath);
179 
187  bool addDirectory(const QString &zipPath);
188 
198  bool addFile(const QString &path, const QString &zipPath);
199 
201  QString error() const
202  { return(_error); }
203 
204  private:
205 
206  void saveErrorString(int zipError);
207  bool checkOpen();
208  bool checkReadMode();
209  bool checkWriteMode();
210  void decodeZipEntry(ZipEntry *entry, void *stat);
211 
212  void *handle() const
213  { return(_handle); }
214 
215  QString _file;
216  QString _error;
217  void *_handle;
218  void *_entryHandle;
219  QString _password;
220  bool _writeMode;
221 
222  Q_DISABLE_COPY(ZipFile);
223 };
224 
225 } // namespace zipfile
226 } // namespace quark
227 
228 #endif // __libquark_zipfile_ZipFile_hxx
bool setEntryComment(qint64 index, const QString &comment)
Sets the comment for the entry at the specified index in the Zip archive.
bool isOpen() const
Tests if the Zip archive is currently open.
bool addDirectory(const QString &zipPath)
Adds a directory entry to the Zip archive.
bool removeEntry(qint64 index)
Removes the entry at the specified index from the Zip archive.
QString archiveComment()
Returns the Zip archive&#39;s comment.
void closeEntry()
Closes the currently opened entry, if any.
Definition: BarChartView.h++:6
bool extractEntry(const ZipEntry &entry, const QString &outputPath)
Extracts the contents of a file entry from the Zip archive.
A class representing a Zip archive.
Definition: ZipFile.h++:19
bool getEntry(qint64 index, ZipEntry &entry)
Retrieves the entry at the specified index in the Zip archive.
bool addFile(const QString &path, const QString &zipPath)
Adds a file entry to the Zip archive.
bool renameEntry(qint64 index, const QString &newPath)
Changes the file path of the entry at the specified index in the Zip archive.
bool setArchiveComment(const QString &comment)
Sets the Zip archive&#39;s comment.
int readEntry(char *buf, int count)
Reads (and decompresses) data from the currently opened entry.
bool open(QIODevice::OpenMode openMode, const QString &password=QString())
Opens the Zip archive.
ZipFile(const QString &file)
Constructs a new ZipFile for the given file path.
virtual ~ZipFile()
Destructor.
QString getEntryComment(qint64 index)
Retrieves the comment for the entry at the specified index in the Zip archive.
bool openEntry(qint64 index)
Opens the entry at the specified index in the Zip archive.
bool close()
Closes the Zip archive.
qint64 numEntries()
Returns the number of entries in the Zip archive.
A class representing an entry in a Zip archive.
Definition: ZipEntry.h++:17
bool isEntryOpen() const
Tests if an entry is currently opened.
QString getEntryPath(qint64 index)
Returns the file path for the entry at the specified index.
QString error() const
Returns the most recently generated Zip error message.
Definition: ZipFile.h++:201