1
/****************************************************************************
2
**
3
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
4
** All rights reserved.
5
** Contact: Nokia Corporation (qt-info@nokia.com)
6
**
7
** This file is part of the QtCore module of the Qt Toolkit.
8
**
9
** $QT_BEGIN_LICENSE:LGPL$
10
** No Commercial Usage
11
** This file contains pre-release code and may not be distributed.
12
** You may use this file in accordance with the terms and conditions
13
** contained in the Technology Preview License Agreement accompanying
14
** this package.
15
**
16
** GNU Lesser General Public License Usage
17
** Alternatively, this file may be used under the terms of the GNU Lesser
18
** General Public License version 2.1 as published by the Free Software
19
** Foundation and appearing in the file LICENSE.LGPL included in the
20
** packaging of this file.  Please review the following information to
21
** ensure the GNU Lesser General Public License version 2.1 requirements
22
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
23
**
24
** In addition, as a special exception, Nokia gives you certain additional
25
** rights.  These rights are described in the Nokia Qt LGPL Exception
26
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
27
**
28
** If you have questions regarding the use of this file, please contact
29
** Nokia at qt-info@nokia.com.
30
**
31
**
32
**
33
**
34
**
35
**
36
**
37
**
38
** $QT_END_LICENSE$
39
**
40
****************************************************************************/
41
42
#ifndef QDIR_H
43
#define QDIR_H
44
45
#include <QtCore/qstring.h>
46
#include <QtCore/qfileinfo.h>
47
#include <QtCore/qstringlist.h>
48
49
QT_BEGIN_HEADER
50
51
QT_BEGIN_NAMESPACE
52
53
QT_MODULE(Core)
54
55
class QDirPrivate;
56
57
class Q_CORE_EXPORT QDir
58
{
59
protected:
60
    QDirPrivate *d_ptr;
61
private:
62
    Q_DECLARE_PRIVATE(QDir)
63
public:
64
    enum Filter { Dirs        = 0x001,
65
                  Files       = 0x002,
66
                  Drives      = 0x004,
67
                  NoSymLinks  = 0x008,
68
                  AllEntries  = Dirs | Files | Drives,
69
                  TypeMask    = 0x00f,
70
#ifdef QT3_SUPPORT
71
                  All         = AllEntries,
72
#endif
73
74
                  Readable    = 0x010,
75
                  Writable    = 0x020,
76
                  Executable  = 0x040,
77
                  PermissionMask    = 0x070,
78
#ifdef QT3_SUPPORT
79
                  RWEMask     = 0x070,
80
#endif
81
82
                  Modified    = 0x080,
83
                  Hidden      = 0x100,
84
                  System      = 0x200,
85
                 
86
                  AccessMask  = 0x3F0,
87
88
                  AllDirs       = 0x400,
89
                  CaseSensitive = 0x800,
90
                  NoDotAndDotDot = 0x1000,
91
92
                  NoFilter = -1
93
#ifdef QT3_SUPPORT
94
                  ,DefaultFilter = NoFilter
95
#endif
96
    };
97
    Q_DECLARE_FLAGS(Filters, Filter)
98
#ifdef QT3_SUPPORT
99
    typedef Filters FilterSpec;
100
#endif
101
102
    enum SortFlag { Name        = 0x00,
103
                    Time        = 0x01,
104
                    Size        = 0x02,
105
                    Unsorted    = 0x03,
106
                    SortByMask  = 0x03,
107
108
                    DirsFirst   = 0x04,
109
                    Reversed    = 0x08,
110
                    IgnoreCase  = 0x10,
111
                    DirsLast    = 0x20,
112
                    LocaleAware = 0x40, 
113
                    Type        = 0x80,
114
                    NoSort = -1
115
#ifdef QT3_SUPPORT
116
                  ,DefaultSort = NoSort
117
#endif
118
    };
119
    Q_DECLARE_FLAGS(SortFlags, SortFlag)
120
121
    QDir(const QDir &);
122
    QDir(const QString &path = QString());
123
    QDir(const QString &path, const QString &nameFilter,
124
         SortFlags sort = SortFlags(Name | IgnoreCase), Filters filter = AllEntries);
125
    ~QDir();
126
127
    QDir &operator=(const QDir &);
128
    QDir &operator=(const QString &path);
129
130
    void setPath(const QString &path);
131
    QString path() const;
132
    QString absolutePath() const;
133
    QString canonicalPath() const;
134
135
    static void addResourceSearchPath(const QString &path);
136
137
    static void setSearchPaths(const QString &prefix, const QStringList &searchPaths);
138
    static void addSearchPath(const QString &prefix, const QString &path);
139
    static QStringList searchPaths(const QString &prefix);
140
141
    QString dirName() const;
142
    QString filePath(const QString &fileName) const;
143
    QString absoluteFilePath(const QString &fileName) const;
144
    QString relativeFilePath(const QString &fileName) const;
145
146
#ifdef QT_DEPRECATED
147
    QT_DEPRECATED static QString convertSeparators(const QString &pathName);
148
#endif
149
    static QString toNativeSeparators(const QString &pathName);
150
    static QString fromNativeSeparators(const QString &pathName);
151
152
    bool cd(const QString &dirName);
153
    bool cdUp();
154
155
    QStringList nameFilters() const;
156
    void setNameFilters(const QStringList &nameFilters);
157
158
    Filters filter() const;
159
    void setFilter(Filters filter);
160
    SortFlags sorting() const;
161
    void setSorting(SortFlags sort);
162
163
    uint count() const;
164
    QString operator[](int) const;
165
166
    static QStringList nameFiltersFromString(const QString &nameFilter);
167
168
    QStringList entryList(Filters filters = NoFilter, SortFlags sort = NoSort) const;
169
    QStringList entryList(const QStringList &nameFilters, Filters filters = NoFilter,
170
                          SortFlags sort = NoSort) const;
171
172
    QFileInfoList entryInfoList(Filters filters = NoFilter, SortFlags sort = NoSort) const;
173
    QFileInfoList entryInfoList(const QStringList &nameFilters, Filters filters = NoFilter,
174
                                SortFlags sort = NoSort) const;
175
176
    bool mkdir(const QString &dirName) const;
177
    bool rmdir(const QString &dirName) const;
178
    bool mkpath(const QString &dirPath) const;
179
    bool rmpath(const QString &dirPath) const;
180
181
    bool isReadable() const;
182
    bool exists() const;
183
    bool isRoot() const;
184
185
    static bool isRelativePath(const QString &path);
186
    inline static bool isAbsolutePath(const QString &path) { return !isRelativePath(path); }
187
    bool isRelative() const;
188
    inline bool isAbsolute() const { return !isRelative(); }
189
    bool makeAbsolute();
190
191
    bool operator==(const QDir &dir) const;
192
    inline bool operator!=(const QDir &dir) const {  return !operator==(dir); }
193
194
    bool remove(const QString &fileName);
195
    bool rename(const QString &oldName, const QString &newName);
196
    bool exists(const QString &name) const;
197
198
    static QFileInfoList drives();
199
200
    static QChar separator();
201
202
    static bool setCurrent(const QString &path);
203
    static inline QDir current() { return QDir(currentPath()); }
204
    static QString currentPath();
205
206
    static inline QDir home() { return QDir(homePath()); }
207
    static QString homePath();
208
    static inline QDir root() { return QDir(rootPath()); }
209
    static QString rootPath();
210
    static inline QDir temp() { return QDir(tempPath()); }
211
    static QString tempPath();
212
213
#ifndef QT_NO_REGEXP
214
    static bool match(const QStringList &filters, const QString &fileName);
215
    static bool match(const QString &filter, const QString &fileName);
216
#endif
217
    static QString cleanPath(const QString &path);
218
    void refresh() const;
219
220
#ifdef QT3_SUPPORT
221
    typedef SortFlags SortSpec;
222
    inline QT3_SUPPORT QString absPath() const { return absolutePath(); }
223
    inline QT3_SUPPORT QString absFilePath(const QString &fileName, bool acceptAbsPath = true) const
224
       { Q_UNUSED(acceptAbsPath); return absoluteFilePath(fileName); }
225
    QT3_SUPPORT bool matchAllDirs() const;
226
    QT3_SUPPORT void setMatchAllDirs(bool on);
227
    inline QT3_SUPPORT QStringList entryList(const QString &nameFilter, Filters filters = NoFilter,
228
                                           SortFlags sort = NoSort) const
229
    { return entryList(nameFiltersFromString(nameFilter), filters, sort); }
230
    inline QT3_SUPPORT QFileInfoList entryInfoList(const QString &nameFilter,
231
                                                 Filters filters = NoFilter,
232
                                                 SortFlags sort = NoSort) const
233
    { return entryInfoList(nameFiltersFromString(nameFilter), filters, sort); }
234
235
    QT3_SUPPORT QString nameFilter() const;
236
    QT3_SUPPORT void setNameFilter(const QString &nameFilter);
237
238
    inline QT3_SUPPORT bool mkdir(const QString &dirName, bool acceptAbsPath) const
239
        { Q_UNUSED(acceptAbsPath); return mkdir(dirName); }
240
    inline QT3_SUPPORT bool rmdir(const QString &dirName, bool acceptAbsPath) const
241
        { Q_UNUSED(acceptAbsPath); return rmdir(dirName); }
242
243
    inline QT3_SUPPORT void convertToAbs() { makeAbsolute(); }
244
    inline QT3_SUPPORT static QString currentDirPath() { return currentPath(); }
245
    inline QT3_SUPPORT static QString homeDirPath() { return homePath(); }
246
    inline QT3_SUPPORT static QString rootDirPath() { return rootPath(); }
247
    inline QT3_SUPPORT static QString cleanDirPath(const QString &name) { return cleanPath(name); }
248
#endif
249
};
250
251
Q_DECLARE_OPERATORS_FOR_FLAGS(QDir::Filters)
252
Q_DECLARE_OPERATORS_FOR_FLAGS(QDir::SortFlags)
253
254
#ifndef QT_NO_DEBUG_STREAM
255
class QDebug;
256
Q_CORE_EXPORT QDebug operator<<(QDebug debug, QDir::Filters filters);
257
Q_CORE_EXPORT QDebug operator<<(QDebug debug, const QDir &dir);
258
#endif
259
260
QT_END_NAMESPACE
261
262
QT_END_HEADER
263
264
#endif // QDIR_H