1 #ifndef QUAZIP_QUAZIPDIR_H 2 #define QUAZIP_QUAZIPDIR_H 3 4 class QuaZipDirPrivate; 5 6 #include "quazip.h" 7 #include "quazipfileinfo.h" 8 #include <QDir> 9 #include <QList> 10 #include <QSharedDataPointer> 11 12 /// Provides ZIP archive navigation. 13 /** 14 * This class is modelled after QDir, and is designed to provide similar 15 * features for ZIP archives. 16 * 17 * The only significant difference from QDir is that the root path is not 18 * '/', but an empty string since that's how the file paths are stored in 19 * the archive. However, QuaZipDir understands the paths starting with 20 * '/'. It is important in a few places: 21 * 22 * - In the cd() function. 23 * - In the constructor. 24 * - In the exists() function. 25 * 26 * Note that since ZIP uses '/' on all platforms, the '\' separator is 27 * not supported. 28 */ 29 class QUAZIP_EXPORT QuaZipDir 30 { 31 private: 32 QSharedDataPointer<QuaZipDirPrivate> d; 33 public: 34 /// The copy constructor. 35 QuaZipDir(const QuaZipDir &that); 36 /// Constructs a QuaZipDir instance pointing to the specified directory. 37 /** 38 If \a dir is not specified, points to the root of the archive. 39 The same happens if the \a dir is "/". 40 */ 41 QuaZipDir(QuaZip *zip, const QString &dir = QString()); 42 /// Destructor. 43 ~QuaZipDir(); 44 /// The assignment operator. 45 bool operator==(const QuaZipDir &that); 46 /// operator!= 47 /** 48 \return \c true if either this and \a that use different QuaZip 49 instances or if they point to different directories. 50 */ 51 inline bool operator!=(const QuaZipDir &that) 52 { 53 return !operator==(that); 54 } 55 /// operator== 56 /** 57 \return \c true if both this and \a that use the same QuaZip 58 instance and point to the same directory. 59 */ 60 QuaZipDir& operator=(const QuaZipDir &that); 61 /// Returns the name of the entry at the specified position. 62 QString operator[](int pos) const; 63 /// Returns the current case sensitivity mode. 64 QuaZip::CaseSensitivity caseSensitivity() const; 65 /// Changes the 'current' directory. 66 /** 67 * If the path starts with '/', it is interpreted as an absolute 68 * path from the root of the archive. Otherwise, it is interpreted 69 * as a path relative to the current directory as was set by the 70 * previous cd() or the constructor. 71 * 72 * Note that the subsequent path() call will not return a path 73 * starting with '/' in all cases. 74 */ 75 bool cd(const QString &dirName); 76 /// Goes up. 77 bool cdUp(); 78 /// Returns the number of entries in the directory. 79 unsigned int count() const; 80 /// Returns the current directory name. 81 /** 82 The name doesn't include the path. 83 */ 84 QString dirName() const; 85 /// Returns the list of the entries in the directory. 86 /** 87 \param nameFilters The list of file patterns to list, uses the same 88 syntax as QDir. 89 \param filters The entry type filters, only Files and Dirs are 90 accepted. 91 \param sort Sorting mode (not supported yet). 92 */ 93 QList<QuaZipFileInfo> entryInfoList(const QStringList &nameFilters, 94 QDir::Filters filters = QDir::NoFilter, 95 QDir::SortFlags sort = QDir::NoSort) const; 96 /// Returns the list of the entries in the directory. 97 /** 98 \overload 99 100 The same as entryInfoList(QStringList(), filters, sort). 101 */ 102 QList<QuaZipFileInfo> entryInfoList(QDir::Filters filters = QDir::NoFilter, 103 QDir::SortFlags sort = QDir::NoSort) const; 104 /// Returns the list of the entry names in the directory. 105 /** 106 The same as entryInfoList(nameFilters, filters, sort), but only 107 returns entry names. 108 */ 109 QStringList entryList(const QStringList &nameFilters, 110 QDir::Filters filters = QDir::NoFilter, 111 QDir::SortFlags sort = QDir::NoSort) const; 112 /// Returns the list of the entry names in the directory. 113 /** 114 \overload 115 116 The same as entryList(QStringList(), filters, sort). 117 */ 118 QStringList entryList(QDir::Filters filters = QDir::NoFilter, 119 QDir::SortFlags sort = QDir::NoSort) const; 120 /// Returns \c true if the entry with the specified name exists. 121 /** 122 The ".." is considered to exist if the current directory 123 is not root. The "." and "/" are considered to 124 always exist. Paths starting with "/" are relative to 125 the archive root, other paths are relative to the current dir. 126 */ 127 bool exists(const QString &fileName) const; 128 /// Return \c true if the directory pointed by this QuaZipDir exists. 129 bool exists() const; 130 /// Returns the full path to the specified file. 131 /** 132 Doesn't check if the file actually exists. 133 */ 134 QString filePath(const QString &fileName) const; 135 /// Returns the default filter. 136 QDir::Filters filter(); 137 /// Returns if the QuaZipDir points to the root of the archive. 138 /** 139 Not that the root path is the empty string, not '/'. 140 */ 141 bool isRoot() const; 142 /// Return the default name filter. 143 QStringList nameFilters() const; 144 /// Returns the path to the current dir. 145 /** 146 The path never starts with '/', and the root path is an empty 147 string. 148 */ 149 QString path() const; 150 /// Returns the path to the specified file relative to the current dir. 151 QString relativeFilePath(const QString &fileName) const; 152 /// Sets the default case sensitivity mode. 153 void setCaseSensitivity(QuaZip::CaseSensitivity caseSensitivity); 154 /// Sets the default filter. 155 void setFilter(QDir::Filters filters); 156 /// Sets the default name filter. 157 void setNameFilters(const QStringList &nameFilters); 158 /// Goes to the specified path. 159 /** 160 The difference from cd() is that this function never checks if the 161 path actually exists and doesn't use relative paths, so it's 162 possible to go to the root directory with setPath(""). 163 164 Note that this function still chops the trailing and/or leading 165 '/' and treats a single '/' as the root path (path() will still 166 return an empty string). 167 */ 168 void setPath(const QString &path); 169 /// Sets the default sorting mode. 170 void setSorting(QDir::SortFlags sort); 171 /// Returns the default sorting mode. 172 QDir::SortFlags sorting() const; 173 }; 174 175 #endif // QUAZIP_QUAZIPDIR_H 176