summaryrefslogtreecommitdiffstats
path: root/depends/quazip/quazipdir.h
blob: e2d70bc88844af47dfefef4a6ea25ec3b0cfe319 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
#ifndef QUAZIP_QUAZIPDIR_H
#define QUAZIP_QUAZIPDIR_H

class QuaZipDirPrivate;

#include "quazip.h"
#include "quazipfileinfo.h"
#include <QDir>
#include <QList>
#include <QSharedDataPointer>

/// Provides ZIP archive navigation.
/**
* This class is modelled after QDir, and is designed to provide similar
* features for ZIP archives.
*
* The only significant difference from QDir is that the root path is not
* '/', but an empty string since that's how the file paths are stored in
* the archive. However, QuaZipDir understands the paths starting with
* '/'. It is important in a few places:
*
* - In the cd() function.
* - In the constructor.
* - In the exists() function.
*
* Note that since ZIP uses '/' on all platforms, the '\' separator is
* not supported.
*/
class QUAZIP_EXPORT QuaZipDir {
private:
    QSharedDataPointer<QuaZipDirPrivate> d;
public:
    /// The copy constructor.
    QuaZipDir(const QuaZipDir &that);
    /// Constructs a QuaZipDir instance pointing to the specified directory.
    /**
       If \a dir is not specified, points to the root of the archive.
       The same happens if the \a dir is &quot;/&quot;.
     */
    QuaZipDir(QuaZip *zip, const QString &dir = QString());
    /// Destructor.
    ~QuaZipDir();
    /// The assignment operator.
    bool operator==(const QuaZipDir &that);
    /// operator!=
    /**
      \return \c true if either this and \a that use different QuaZip
      instances or if they point to different directories.
      */
    inline bool operator!=(const QuaZipDir &that) {return !operator==(that);}
    /// operator==
    /**
      \return \c true if both this and \a that use the same QuaZip
      instance and point to the same directory.
      */
    QuaZipDir& operator=(const QuaZipDir &that);
    /// Returns the name of the entry at the specified position.
    QString operator[](int pos) const;
    /// Returns the current case sensitivity mode.
    QuaZip::CaseSensitivity caseSensitivity() const;
    /// Changes the 'current' directory.
    /**
      * If the path starts with '/', it is interpreted as an absolute
      * path from the root of the archive. Otherwise, it is interpreted
      * as a path relative to the current directory as was set by the
      * previous cd() or the constructor.
      * 
      * Note that the subsequent path() call will not return a path
      * starting with '/' in all cases.
      */
    bool cd(const QString &dirName);
    /// Goes up.
    bool cdUp();
    /// Returns the number of entries in the directory.
    uint count() const;
    /// Returns the current directory name.
    /**
      The name doesn't include the path.
      */
    QString dirName() const;
    /// Returns the list of the entries in the directory.
    /**
      \param nameFilters The list of file patterns to list, uses the same
      syntax as QDir.
      \param filters The entry type filters, only Files and Dirs are
      accepted.
      \param sort Sorting mode (not supported yet).
      */
    QList<QuaZipFileInfo> entryInfoList(const QStringList &nameFilters,
        QDir::Filters filters = QDir::NoFilter,
        QDir::SortFlags sort = QDir::NoSort) const;
    /// Returns the list of the entries in the directory.
    /**
      \overload

      The same as entryInfoList(QStringList(), filters, sort).
      */
    QList<QuaZipFileInfo> entryInfoList(QDir::Filters filters = QDir::NoFilter,
        QDir::SortFlags sort = QDir::NoSort) const;
    /// Returns the list of the entry names in the directory.
    /**
      The same as entryInfoList(nameFilters, filters, sort), but only
      returns entry names.
      */
    QStringList entryList(const QStringList &nameFilters,
        QDir::Filters filters = QDir::NoFilter,
        QDir::SortFlags sort = QDir::NoSort) const;
    /// Returns the list of the entry names in the directory.
    /**
      \overload

      The same as entryList(QStringList(), filters, sort).
      */
    QStringList entryList(QDir::Filters filters = QDir::NoFilter,
        QDir::SortFlags sort = QDir::NoSort) const;
    /// Returns \c true if the entry with the specified name exists.
    /**
      The &quot;..&quot; is considered to exist if the current directory
      is not root. The &quot;.&quot; and &quot;/&quot; are considered to
      always exist. Paths starting with &quot;/&quot; are relative to
      the archive root, other paths are relative to the current dir.
      */
    bool exists(const QString &fileName) const;
    /// Return \c true if the directory pointed by this QuaZipDir exists.
    bool exists() const;
    /// Returns the full path to the specified file.
    /**
      Doesn't check if the file actually exists.
      */
    QString filePath(const QString &fileName) const;
    /// Returns the default filter.
    QDir::Filters filter();
    /// Returns if the QuaZipDir points to the root of the archive.
    /**
      Not that the root path is the empty string, not '/'.
     */
    bool isRoot() const;
    /// Return the default name filter.
    QStringList nameFilters() const;
    /// Returns the path to the current dir.
    /**
      The path never starts with '/', and the root path is an empty
      string.
      */
    QString path() const;
    /// Returns the path to the specified file relative to the current dir.
    QString relativeFilePath(const QString &fileName) const;
    /// Sets the default case sensitivity mode.
    void setCaseSensitivity(QuaZip::CaseSensitivity caseSensitivity);
    /// Sets the default filter.
    void setFilter(QDir::Filters filters);
    /// Sets the default name filter.
    void setNameFilters(const QStringList &nameFilters);
    /// Goes to the specified path.
    /**
      The difference from cd() is that this function never checks if the
      path actually exists and doesn't use relative paths, so it's
      possible to go to the root directory with setPath(&quot;&quot;).

      Note that this function still chops the trailing and/or leading
      '/' and treats a single '/' as the root path (path() will still
      return an empty string).
      */
    void setPath(const QString &path);
    /// Sets the default sorting mode.
    void setSorting(QDir::SortFlags sort);
    /// Returns the default sorting mode.
    QDir::SortFlags sorting() const;
};

#endif // QUAZIP_QUAZIPDIR_H